# performance of icc main.cpp == g++ -ffast-math main.cpp

I have a program that has a nested loop, together with its parent running at $O(n^2)$ complexity performing floating point arithmetic.

I see that the performance of the code when compiled with icc is comparable to that of g++ -ffast-math.

Does this mean that icc is switching on an equivalent of the -ffast-math implicitly?

To first order approximation, icc does use -ffast-math by default.

If you run icc --help, it will show you its options. One of the sections is Floating Point, which begins like this:

Floating Point
--------------

-fp-model <name>
enable <name> floating point model variation
[no-]except - enable/disable floating point semantics
fast[=1|2]  - enables more aggressive floating point optimizations
precise     - allows value-safe optimizations
source      - enables intermediates in source precision
strict      - enables -fp-model precise -fp-model except, disables
contractions and enables pragma stdc fenv_access
double      - rounds intermediates in 53-bit (double) precision
extended    - rounds intermediates in 64-bit (extended) precision


It doesn't say it here, but in icc documentation here, it says that fast=1 is the default.

The other options similar to -ffast-math are:

-[no-]prec-sqrt
determine if certain square root optimizations are enabled
-[no-]prec-div
improve precision of FP divides (some speed impact)
-[no-]fast-transcendentals
generate a faster version of the transcendental functions
...
-[no-]ftz
enable/disable flush denormal results to zero
-[no-]fma
enable/disable the combining of floating point multiplies and

But the correspondence between -ffast-math and -fp-model fast=1 is probably not very precise - it could well be that some other specific options are included in fast-math (which can be seen here) but excluded in fp-model fast=1 or vice versa. It looks to me like among other things -ffast-math would disable non-finite floating-point arithmetic (inf, nan), which icc doesn't do by default.
• So does icc prioritise speed over accuracy ? – kesari Sep 27 '15 at 20:51
• @kesari Yes, but it is a choice of defaults - it is easy to pick -fp-model that suits you best. Given how common the flag -ffast-math is for gcc projects, I don't think it represents any kind of real difference between the two compilers. – Kirill Sep 28 '15 at 18:12