r/cpp • u/Little-Reflection986 • Feb 16 '26
Favorite optimizations ??
I'd love to hear stories about people's best feats of optimization, or something small you are able to use often!
134
Upvotes
View all comments
Show parent comment
2
u/James20k P2005R0 Feb 17 '26
nvc++ follows the spec just fine here
This is the specific segment of the spec that allows this behaviour:
https://eel.is/c++draft/expr#pre-6
This is the MSVC documentation:
https://learn.microsoft.com/en-us/cpp/preprocessor/fp-contract?view=msvc-170
The C/C++ spec permits floating point contraction to be on by default
If you pass
-fno-fast-mathinto clang, it sets:-ffp-contract=onhttps://clang.llvm.org/docs/UsersManual.html on x64, but:
-fno-fast-math sets -ffp-contract to on (fast for CUDA and HIP).Which is why you see divergence between nvcc (which is clang based), and clang. In fact, the clang docs say this:
on: enable C and C++ standard compliant fusion in the same statement unless dictated by pragmas (default for languages other than CUDA/HIP)GCC says this:
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
It is absolutely permitted by the spec, and the big 3 compilers