80 bit floating point emulation
IGotD-
nise at nise.com
Fri Jul 8 22:34:34 UTC 2022
On Friday, 8 July 2022 at 22:04:38 UTC, Walter Bright wrote:
> In order for DMD to become a proper cross compiler, it needs to
> be able to emulate 80 bit floating point. The full x87 doesn't
> need to be emulated, just
> add, sub, mul, div, cmp, neg, tst.
>
> This is eminently doable, and isn't too hard. The 80 bit real
> format has a 64 bit significand, meaning the emulation will
> need 128 bit integer arithmetic. And lo, we already have that
> in druntime:
>
> https://dlang.org/phobos/core_int128.html
>
> which is one of the reasons I pushed for that.
>
> For example, multiply consists of:
>
> 1. checking for special encodings (Nan, infinity)
> 2. multiplying the two 64 bit significands for a 128 bit result
> 3. correctly round it using guard and sticky bits
> 4. add the mantissas together
> 5. deal with overflow
> 6. re-encode the result
>
> Anyone want to take up the flag and do this? As a side effect,
> you'll learn in detail how floating point works, which will
> serve you well in the future.
>
> (We don't use other peoples' emulators because of licensing
> issues.)
Is this something that is important? Now DMD has native support
for the x87 80-bit floats but is this something worth porting and
emulating with other architectures. It's something that I think
is going to be hardly used so wouldn't be better to letting the
compiler emit an error instead telling the user that 80-bit
floats isn't supported?
Keep in mind that the 80-bit float is like an one off in floating
point history. Some other architectures supports 128-bit floats
which is more common. I would much rather that we emulate 128-bit
floats instead than the 80-bit float.
Also, Intel themselves have more or less deprecated their own x87
in favor of the newer SSE floating point instructions. That leads
to the question, shouldn't DMD do the same? Depreciate 80-bit
floats?
More information about the Digitalmars-d
mailing list