News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Fast float to integer conversion

Started by jj2007, June 11, 2011, 12:05:51 AM

Previous topic - Next topic

jj2007

I vaguely remember having seen somewhere that conversion between integers and floats is slow, so I was curious...

Intel(R) Celeron(R) M CPU        420  @ 1.60GHz (SSE3)
117     cycles for 100*cvtsd2si
97      cycles for 100*cvtsi2sd


One cycle on my good ol' slow Celeron...

qWord

hi jj,
the results varies on my i5 (a bit too strongly for my taste).
Intel(R) Core(TM) i5 CPU       M 520  @ 2.40GHz (SSE4)
82      cycles for 100*cvtsd2si
140     cycles for 100*cvtsi2sd

85      cycles for 100*cvtsd2si
143     cycles for 100*cvtsi2sd
...
108     cycles for 100*cvtsd2si
129     cycles for 100*cvtsi2sd

88      cycles for 100*cvtsd2si
94      cycles for 100*cvtsi2sd
...
79      cycles for 100*cvtsd2si
118     cycles for 100*cvtsi2sd

83      cycles for 100*cvtsd2si
116     cycles for 100*cvtsi2sd
...
113     cycles for 100*cvtsd2si
81      cycles for 100*cvtsi2sd

85      cycles for 100*cvtsd2si
82      cycles for 100*cvtsi2sd

you may need to change the repetitions and also convert more then one value.
FPU in a trice: SmplMath
It's that simple!

jj2007

Quote from: qWord on June 11, 2011, 12:57:52 AM
a bit too strongly for my taste

You have never owned a P4, it seems :green2

Still, it's roughly one cycle, or a bit less on your CPU. Not bad for such a conversion.

Twister

Intel(R) Pentium(R) 4 CPU 3.20GHz (SSE3)
606     cycles for 100*cvtsd2si
1312    cycles for 100*cvtsi2sd

695     cycles for 100*cvtsd2si
701     cycles for 100*cvtsi2sd