← Back to context

Comment by Earw0rm

8 hours ago

That's very much an issue with SIMD, especially where floating point numbers are concerned.

Matt Godbolt wrote about it recently.

https://xania.org/202512/21-vectorising-floats

TLDR, math notation and language specify particular orders in which floating point operations happen, and precision limits of IEEE float representation mean those have to be honoured by default.

Allowing compilers to reorder things in breach of that contract is an option, but it comes with risks.

I like that Zig allows using relaxed floating point rules with per block granularity to reduce the risk of breaking something else where IEEE compliance does matter. I think OpenMP simd pragmas can be used similarly for C/C++, but that's non-standard.

  • You can do the same thing with types or the wide crate. But it isn't always obvious when it will become a problem. Usung these types does make auto vectorization fairly reliable.