Compiler optimizations (I'm baffled)

Don Clugston dac at nospam.com.au
Thu May 4 05:03:10 PDT 2006


Bruno Medeiros wrote:
> Thomas Kuehne wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Bruno Medeiros schrieb am 2006-05-03:
>>> Walter Bright wrote:
>>>> Craig Black wrote:
>>>>>  This is
>>>>> because integer division is essentially floating point division 
>>>>> under the
>>>>> hood.
>>> I ran these tests and I got basicly the same results (the int 
>>> division is slower). I am very intrigued and confused. Can you (or 
>>> someone else) explain briefly why this is so?
>>> One would think it would be the other way around (float being slower) 
>>> or at least the same speed.

It's true.

For Pentium, IDIV takes 46 cycles, while FDIV takes 39.
For PPro, PII and PIII, DIV takes 39, while FDIV takes 38.
Not much difference.

However, for P4 (and probably Athlon XP is similar),
FDIV has a latency of 43 cycles, while DIV has a latency of 50, plus it 
executes 21 microcodes!

It's not quite a factor of two, but it's close.

In short -- Intel killed integer division on the P4.



More information about the Digitalmars-d mailing list