Jump to page: 1 2 3
Thread overview
80 bit floating point emulation
Jul 08, 2022
Walter Bright
Jul 08, 2022
rikki cattermole
Jul 08, 2022
IGotD-
Jul 08, 2022
Walter Bright
Jul 09, 2022
H. S. Teoh
Jul 09, 2022
Walter Bright
Jul 09, 2022
Adam D Ruppe
Jul 09, 2022
Daniel N
Jul 09, 2022
Adam D Ruppe
Jul 09, 2022
jmh530
Jul 09, 2022
Bruce Carneal
Jul 09, 2022
Iain Buclaw
Jul 09, 2022
Salih Dincer
Jul 09, 2022
JG
Jul 09, 2022
Salih Dincer
Jul 09, 2022
Salih Dincer
Jul 09, 2022
Walter Bright
Jul 10, 2022
Walter Bright
Jul 10, 2022
Ali Çehreli
Jul 14, 2022
Walter Bright
Jul 15, 2022
max haughton
Jul 15, 2022
Walter Bright
July 08, 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.)
July 09, 2022
Certainly a good excuse for whoever wants to tackle this to buy The Art of Computer Programming!
July 08, 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?
July 08, 2022
On 7/8/2022 3:34 PM, IGotD- wrote:
> Is this something that is important?

For example, it'll get rid of all that ugly code in root/ and all the problems with VC's lack of support for 80 bits. It means dmd can be run on any platform. It makes 80 bits available to any D program that may need compatibility.

All this for a rather minor investment in coding, half of which has already been done (128 bit arithmetic).
July 09, 2022
On Friday, 8 July 2022 at 22:04:38 UTC, Walter Bright wrote:
> In order for DMD to become a proper cross compiler
>
>
> (We don't use other peoples' emulators because of licensing issues.)

Does ldc have an emulator you don't use for licensing? or does it manage to be a usable cross compiler without 80 bit reals?
July 08, 2022
On Fri, Jul 08, 2022 at 10:34:34PM +0000, IGotD- via Digitalmars-d wrote:
> 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.
[...]
> 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?

The keyword here is "cross compiler".  Suppose you're compiling on a platform that doesn't have 80-bit floats, but you're targeting x86. You'd want your CTFE float values to match the behavior of 80-bit floats, 'cos otherwise there would be a mismatch between what the compiler computes at compile-time vs. what the program would have produced when run on the target x86 platform.


> 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?

This is also a valid point. :-P  I've also been shying away from 80-bit floats recently because they are slow (80-bit hardware hasn't been improved since decades ago, 'cos nobody is invested in continuing to develop it anymore), and also non-standard (only useful for intermediate computations, not useful for transmission because the target system may not support it -- also, results are peculiar to x86 CPUs and differ from results obtained on other CPUs).


T

-- 
Time flies like an arrow. Fruit flies like a banana.
July 08, 2022

On 7/8/22 8:23 PM, H. S. Teoh wrote:

>

The keyword here is "cross compiler". Suppose you're compiling on a
platform that doesn't have 80-bit floats, but you're targeting x86.
You'd want your CTFE float values to match the behavior of 80-bit
floats, 'cos otherwise there would be a mismatch between what the
compiler computes at compile-time vs. what the program would have
produced when run on the target x86 platform.

Wait, so you think that the ultimate path here is that DMD becomes able to emulate 80-bit floats, and then is ported to another problem with the purpose of cross-compiling to x86?

I'm far from being the one to determine what path DMD development should take, but this strikes me as something nobody is asking for.

-Steve

July 08, 2022
On 7/8/2022 8:41 PM, Steven Schveighoffer wrote:
> I'm far from being the one to determine what path DMD development should take, but this strikes me as something nobody is asking for.

Ideally, the compiler should produce the same results regardless of the platform it is hosted on.
July 09, 2022
On Saturday, 9 July 2022 at 00:05:07 UTC, Adam D Ruppe wrote:
> On Friday, 8 July 2022 at 22:04:38 UTC, Walter Bright wrote:
>> In order for DMD to become a proper cross compiler
>>
>>
>> (We don't use other peoples' emulators because of licensing issues.)
>
> Does ldc have an emulator you don't use for licensing? or does it manage to be a usable cross compiler without 80 bit reals?

LDC always uses 64-bit double for real, no 80 bit support anywhere afaik.



July 09, 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.
>
> [...]

Thinking of spending a few hours later to get an idea of how long it will take to do. Any specification to work from?
« First   ‹ Prev
1 2 3