← Back to context

Comment by simonask

15 hours ago

Floating point hardware on different CPU architectures don’t produce bitwise identical results, unfortunately. That’s the big issue.

As far as I’m aware, they do produce semantically identical results, but something like the specific bit pattern of a NaN value can theoretically vary, and people might do fun things like encoding extra information in those bits.

About NaNs, you are right, because the standard does not mandate the use of a specific NaN for each kind of invalid operation.

Nonetheless, if you use a comparison function for which all NaNs are equivalent, different CPU architectures that are standard-compliant must produce bitwise identical results for the same sequence of operations.

Differences appear mainly when the compilers generate different operations or in a different order. Moreover, transcendental functions are computed using various approximations by the standard library, so if you use different libraries on different computers, you will get different results.

However, these are differences caused by software, not by hardware, and they happen even on the same computer when you use different versions of a compiler or of a standard library. Therefore such differences can be eliminated, if desired.

  • rsqrt differs between intel and amd, out-of-bounds conversions differ between x64 and arm (saturating vs sentinel), denormal handling also varies iirc (not 100% sure about that), x64 has FTZ/DAZ separately, ARM has a combined FZ flag and this list is probably not exhaustive...