Re: 64bit/64bit fixed point division?
- From: "Maarten Kronenburg" <spamtrap@xxxxxxxxxx>
- Date: Wed, 23 Aug 2006 16:43:54 +0200
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:[snip]
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
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./.
.
- Follow-Ups:
- Re: 64bit/64bit fixed point division?
- From: Phil Carmody
- Re: 64bit/64bit fixed point division?
- 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
- 64bit/64bit fixed point division?
- Prev by Date: Is there any forum for [BIOS] ?
- Next by Date: Re: C++
- Previous by thread: Re: 64bit/64bit fixed point division?
- Next by thread: Re: 64bit/64bit fixed point division?
- Index(es):
Relevant Pages
|