Thanks in advance
Markus
--
/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
/ Markus Solbach <m.so...@qcont.ndh.com> ~~~~~~~~~~~~~~~~~~~~~~~~~~~\
\ Weberstrasse 1, 53844 Troisdorf, Germany Voice: +049-2241-409813 \
\_______________________________________________________________________/
Subtract 2^31 before storing the number out and add 2^31 after storing the
number.
John Keenleyside
VisualAge C++ Development
#include <std-disclaimer> Email: jkee...@vnet.ibm.com
I was going to say that you cannot, but then this post appeared:
>
>Subtract 2^31 before storing the number out and add 2^31 after storing the
>number.
This is of course correct, but it will cost you at least 4-5 cycles/conversion, even
on a Pentium, making the slow FIST opcode even worse.
A much faster way is to trick the fpu to do the job for you, avoiding the FIST opcode
totally:
; Input: St(0) has number which should be moved to register REG as unsigned long
; Output: St(0) popped, REG has 32-bit integer portion; no overflow checking!
.data
magic_double dq 4330000000000000h ; 2^52 as a double number!
temp_ulong label dword
temp_double dq ?
fp2ulong MACRO REG
fadd [magic_double]
fstp [temp_double]
mov REG,[temp_ulong]
ENDM
Since FADD is a pipeline-able instruction, this version of the code can be executed
in just 4 effective cycles, assuming you can insert some other instructions (FP or
Int) between the FADD and the FSTP.
If you do it by the book, you must either use FISTP qword ptr [temp], or the pre- and
post-conversion suggested by jkeenley, which will use at least 5 cycles more,
assuming perfect scheduling.
--
-Terje Mathisen (include std disclaimer) <Terje.M...@hda.hydro.com>
"almost all programming can be viewed as an exercise in caching"