Hi, I am using gcc 14.2 on windows (mingw64).
I always gave for granted that any compiler would automatically turn constant
divisions into multiplications. Thus, I never cared of writing i.e
float x = a * 0.1f
but I always wrote
float x = a / 10.f
trusting the compiler.
Now I decided to inspect the asm, to be 100% sure, cos I was detecting abnormal
cpu consumption in some time-critical code, and I had a very bad surprise !!!
Here is how:
float Func(float x)
{
return x / 10.f;
}
gets resolved:
divss .LC12(%rip), %xmm0 !!!
This with:
-m64 -march=x86-64-v3 -O3
Does it make any sense ? Why doesn't it convert the division by 10 to a
multiplication by 0.1 ?? Has one to enable some specific option for that ?
Thx