the questionable Code is the following:
float32_t f = someValueFromSomewhere;
f = f * 4;
will compiler optimize this?
According to C-Standard (if i understood it correctly) the second operand has to be promoted to float32_t
;
So the multiplication has to be done using the FPU (or fp emulation).
Theoretically the operation could be done in a normal hardware register by just adding an immediate (and may be overflow checking ). Are compiler allowed to do this optimization? Are there compiler known to do so? And if so, would they also recognize the expression
f = f * 4.0f;
that is required to avoid static code checker warnings about implicit conversions?
Some addition: I know that from the standards point of view both lines are equivalent. But clearly the compiler can distinguish them. So the question is at which time the optimizer is allowed to see the code (or better its internal representation) the first time.