Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling strict floating point mode in GCC

Tags:

c

gcc

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 reproducible results between runs and computers, Thanks.

like image 318
Jordan Avatar asked Sep 03 '11 21:09

Jordan


People also ask

Does GCC use IEEE 754?

The GCC port for AArch64 only supports the IEEE 754-2008 format, and does not require use of the -mfp16-format command-line option.

Which option should be used with GCC to compile source files to the C99 standard?

The option -fno-gnu89-inline explicitly tells GCC to use the C99 semantics for inline when in C99 or gnu99 mode (i.e., it specifies the default behavior).

Which GCC option Undefines a preprocessor macro?

4. Which gcc option undefines a preprocessor macro? Explanation: None.

What is the default endian setting for the GCC compiler?

Generate code for a processor running in little-endian mode. This is the default for all standard configurations.


2 Answers

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.

like image 178
Pascal Cuoq Avatar answered Oct 03 '22 18:10

Pascal Cuoq


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.

like image 33
R.. GitHub STOP HELPING ICE Avatar answered Oct 03 '22 18:10

R.. GitHub STOP HELPING ICE