Enabling strict floating point mode in GCC

前端 未结 3 1565
醉话见心
醉话见心 2020-12-01 13:30

I haven\'t yet created a program to see whether GCC will need it passed, When I do I\'d like to know how I\'d go about enabling strict floating point mode which will allow r

相关标签:
3条回答
  • 2020-12-01 13:47

    Compiling with -msse2 on an Intel/AMD processor that supports it will get you almost there. Do not let any library put the FPU in FTZ/DNZ mode, and you will be mostly set (processor bugs notwithstanding).

    For other architectures, the answer would be different. Those achitectures that do not offer any convenient way to get exact IEEE 754 semantics (for instance, pre-SSE2 IA32 CPUs) would require the use of a floating-point emulation library to get the result you want, at a very high performance penalty.

    If your target architecture supports the fmadd (multiplication and addition without intermediate rounding) instruction, make sure your compiler does not use it when you have explicit multiplications and additions in the source code. GCC is not supposed to do this unless you use the -ffast-math option.

    0 讨论(0)
  • 2020-12-01 13:55

    If you use -ffloat-store and always store intermediate values to variables or apply (explicit) casts to the desired type/precision, you should be at least 90% to your goal, and maybe more. I'd welcome comments on whether there are cases this approach still misses. Note that I claim this works even without any SSE options.

    0 讨论(0)
  • 2020-12-01 14:01

    You can also use GCC's option -mpc64 on i386 / ia32 target to force double precision computation even on x87 FPU. See GCC manual.

    You can also modify the x87 FPU behavor at runtime, see Deterministic cross-platform floating point arithmetics and also An Introduction to GCC.

    0 讨论(0)
提交回复
热议问题