80 bit floating point emulation

Walter Bright newshound2 at digitalmars.com
Fri Jul 8 22:04:38 UTC 2022


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.)


More information about the Digitalmars-d mailing list