Re: 64bit/64bit fixed point division?



Phil,
The mantissa for extended precision 80-bit floating point
is the full 64-bit, only bit number 63 is always 1.
The sign bit is bit number 79, see for example
http://babbage.cs.qc.edu/courses/cs341/IEEE-754references.html
and the book The Intel Microprocessors by Barry Brey.
So you can put a 64-bit integer into an extended precision
80-bit floating point without loss of precision.
Regards, Maarten.

"Phil Carmody" <thefatphil_demunged@xxxxxxxxxxx> wrote in message
news:87hd04gztz.fsf@xxxxxxxxxxxxxxxxxxxxxxx
Terje Mathisen <spamtrap@xxxxxxxxxx> writes:
Robert Redelmeier wrote:
spamtrap@xxxxxxxxxx wrote in part:
I wrote a C++ class for a 64bit fixed point numeric format,
32bit integral and 32bit fractional. I wrote addition,
subtraction and multiplication operator routines (the latter
in inline assembly). Now I need an assembly routine to inline
to compute division, but I'm having many problems finding
[snip]
Division is always messy business. There are two main
algorithms: long-division (shift, compare, subtract) and
Newton-Raphson for 1/SQRT. Historically, integer division
is done via long-division, and floating point is done via
Newton-Raphson (which is faster at 32 bits, and even more
advantaged at more). Both of these done in CPU microcode.
For 64bit fixed-point with an emphasis on speed (accuracy is
always lost in fractional parts), I'd go Newton-Raphson.

Since you do have both an integer and a floating point divisor
available, I'd look into using them to advantage:

I'd be curious how to use an integer divisor...

Dividing a fixed-point 32:32 number by another number in the same
format, is identical to dividing a 64-bit number by another, by
shifting both operands 32 bits left first, then shifting the result
left and storing as integer:

This means that you can use the 80-bit fp format to get exact results:

; Make sure that the x87 part is set to extended precision first!

FILD qword ptr [a]
FILD qword ptr [b]
FDIVP st(1),st
FMUL [two_to_32] ; Do a 32-bit left shift to convert fraction
FISTP qword ptr [result]

.... and I'm still interested quite how you'd use an integer divisor.

This is about 50-60 cycles on anything from a classic Pentium and up.

And only works if the integer is 63 bits precision, /not/ 64.
That damn sign bit can be a pain in the arse sometimes...

Phil
--
"Home taping is killing big business profits. We left this side blank
so you can help." -- Dead Kennedys, written upon the B-side of tapes of
/In God We Trust, Inc./.


.



Relevant Pages

  • Re: 64bit/64bit fixed point division?
    ... The mantissa for extended precision 80-bit floating point ... So you can put a 64-bit integer into an extended precision ... fild qword ptr ...
    (comp.lang.asm.x86)
  • Re: 64bit/64bit fixed point division?
    ... and use fld tword where edx is the address. ... Only then you must also write/read the exponent, ... The mantissa for extended precision 80-bit floating point ...
    (comp.lang.asm.x86)
  • Re: comparison on non-integer types
    ... of x gets pushed into a floating point register and the second copy ... That's an operating system bug, ...
    (comp.lang.c)
  • Re: 64bit/64bit fixed point division?
    ... The mantissa for extended precision 80-bit floating point ... So you can put a 64-bit integer into an extended precision ... "Home taping is killing big business profits. ...
    (comp.lang.asm.x86)