Page 1 of 1

platform provided FMA operations might be non-deterministic

Posted: Thu Sep 03, 2026 12:57 pm
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 ;)

Re: platform provided FMA operations might be non-deterministic

Posted: Thu Sep 03, 2026 7:10 pm
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.

Re: platform provided FMA operations might be non-deterministic

Posted: Fri Sep 04, 2026 1:30 pm
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.