Compiler optimizations

Craig Black cblack at ara.com
Sun Apr 30 10:34:01 PDT 2006


> This doesn't really surprise me.  If I am reading it correctly, the
> major difference comes from only doing the division once.  If you did
> the division every time, the results might not be the same.

I don't think you realize what is happening here ... we are dealing with
integer division vs. floating point multiplication.  With the floating point
multiplication we have

1) conversion from int to a floating point
2) the floating point multiplication
3) convertion from floating point back to int

Although CPUs have gotten faster at converting to and from floating points,
the conversion is not trivial to performance.  What's suprising is that
these three operations are faster than a singe integer division.  This is
because integer division is essentially floating point division under the
hood.

-Craig





More information about the Digitalmars-d mailing list