Re: 64bit/64bit fixed point division?
- From: Terje Mathisen <spamtrap@xxxxxxxxxx>
- Date: Sat, 26 Aug 2006 19:41:23 +0200
Maarten Kronenburg wrote:
But there is no need to use FIST/FILD.
You can also write/read an extended precision
floating point (10 bytes) in memory with a value,
and use fld tword [edx] where edx is the address.
(for Turbo Assembler it's fld [tbyte edx]),
and vice versa with fst.
Only then you must also write/read the exponent,
which will be a little slower.
This will indeed be a bit slower!
You have to load the 64-bit mantissa into a pair of registers, and the 16-bit sign+exponent field into another reg, then check the exponent to determine how much you need to shift the mantissa part...
fstp tword ptr [result]
mov eax,dword ptr [result]
mov edx,dword ptr [result+4]
movzx ecx, word ptr [result+8]
Since we want a fp 32:32-bit number which will fit into a 64-bit unsigned integer, we know that the result of the division should be multiplied by 2^32, i.e. shifted 32 bits, which is equal to adding 32 to the exponent. Since this exponent field is biased by 16384, we can correct this in one instruction:
sub ecx,16384-32
If the result is negative, the 64-bit value must be shifted right, if it is zero then the result will fit exactly into the 64-bit EDX:EAX pair, and if it is positive then we have an overflow situation. :-(
ja OverflowTrap
jz Done
Now we have to check the shift count:
neg ecx
cmp ecx, 32
jb DoTheShift
mov eax,edx
xor edx,edx
cmp ecx, 64
jb DoTheShift
The result underflows, so return zero!
xor eax,eax
jmp Done
The shift count in ECX will use the last 5 bits only!
DoTheShift:
shrd edx,eax,cl
shr edx,cl
Done:
return ; Result in EDX:EAX
Terje
--
- <Terje.Mathisen@xxxxxxxxxxxxx>
"almost all programming can be viewed as an exercise in caching"
***********************************************************************
NOTICE: This e-mail transmission, and any documents, files or previous
e-mail messages attached to it, may contain confidential or privileged
information. If you are not the intended recipient, or a person
responsible for delivering it to the intended recipient, you are
hereby notified that any disclosure, copying, distribution or use of
any of the information contained in or attached to this message is
STRICTLY PROHIBITED. If you have received this transmission in error,
please immediately notify the sender and delete the e-mail and attached
documents. Thank you.
***********************************************************************
- References:
- 64bit/64bit fixed point division?
- From: spamtrap
- Re: 64bit/64bit fixed point division?
- From: Robert Redelmeier
- Re: 64bit/64bit fixed point division?
- From: Terje Mathisen
- Re: 64bit/64bit fixed point division?
- From: Phil Carmody
- Re: 64bit/64bit fixed point division?
- From: Maarten Kronenburg
- Re: 64bit/64bit fixed point division?
- From: Phil Carmody
- Re: 64bit/64bit fixed point division?
- From: Maarten Kronenburg
- 64bit/64bit fixed point division?
- Prev by Date: Re: enabling x87 interrupts
- Next by Date: Re: I feel stupid... "Invalid combination of opcode and operand", was, now is FORTH question
- Previous by thread: Re: 64bit/64bit fixed point division?
- Next by thread: Re: Reversing bit order in delphi ?
- Index(es):
Relevant Pages
|