platform provided FMA operations might be non-deterministic

Post all other topics which do not belong to any other category.
Fiorra
Burner Inserter
Burner Inserter
Posts: 15
Joined: Wed Jan 27, 2021 2:12 pm
Contact:

platform provided FMA operations might be non-deterministic

Post by Fiorra »

Hello,

more of a heads-up than an actual bug: software implementations of FMA (fused multiply add) on several platforms have been found to produce incorrect results on subnormal numbers; differing from hardware FMA. This could cause desyncs:

Implementing FMA and finding bugs in C and Rust standard libraries

A quick disassembly tells me that factorio uses FMA operations in a few places. If you rely on platform provided software fallbacks on cheaper or older CPUs, then this may affect some players.

Either way, the following testcase might be worth checking against every supported platform:
If FMA accuracy matters to you, check that fmaf(a, b, c) with these input bit patterns

a = 0x97000800
b = 0x1cfff001
c = 0x00010002

evaluates to bit pattern 0x00010001 (correct) rather than 0x00010002 (buggy).
I wouldn't be surprised if you had independently found this bug years ago and fixed it for yourself, but I'm reporting it just in case ;)
Rseding91
Factorio Staff
Factorio Staff
Posts: 17464
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: platform provided FMA operations might be non-deterministic

Post by Rseding91 »

I'd be interested to see where you've found it given I can't find a single line in the codebase that explicitly calls fma/fmaf.
If you want to get ahold of me I'm almost always on Discord.
Fiorra
Burner Inserter
Burner Inserter
Posts: 15
Joined: Wed Jan 27, 2021 2:12 pm
Contact:

Re: platform provided FMA operations might be non-deterministic

Post by Fiorra »

Nevermind, those were false positives.

I installed a random disassembler (zydis), picked a random hardware fma instruction (vfmadd*) and ran:

Code: Select all

ZydisDisasm -64 ~/factorio/bin/x64/factorio | grep -i 'vfmadd'
Attempting to trace those instructions to some readable symbols would land in .rodata and .gcc_except_table sections :? Apparently Zydis blindly disassembled data sections, randomly conjuring a few fma instructions.

Disassembling with the proper tool

Code: Select all

objdump --disassemble ~/factorio/bin/x64/factorio
turned up no vfmadd instructions.

Apologies for the noise.
Post Reply

Return to “General discussion”