NetBSD amd64: which way is the best for supporting 80 bits real/double?

Joakim via Digitalmars-d digitalmars-d at puremagic.com
Thu May 11 04:10:50 PDT 2017


On Thursday, 11 May 2017 at 10:22:29 UTC, Dominikus Dittes 
Scherkl wrote:
> On Thursday, 11 May 2017 at 10:07:32 UTC, Joakim wrote:
>> On Thursday, 11 May 2017 at 02:05:11 UTC, Nikolay wrote:
>>> I am porting LDC to NetBSD amd64, and I ask advice how to 
>>> handle real type. NetBSD has limited support for this type.
>>
>> What is long double on NetBSD/amd64, 64-bit or full 80-bit?  
>> We were talking about this when I was porting to Android/x86, 
>> where long double is 64-bit but the FPU should support 80-bit.
>>  Iain suggested just sticking to the ABI, ie using 64-bit if 
>> that's how long double is defined (see next three comments 
>> after linked comment):
>>
>> https://github.com/dlang/phobos/pull/2150#issuecomment-42731651
>>
>>> This type exists, but standard library does not provide full 
>>> set of math functions for it (e.g. sinus, cosinus, and etc). 
>>> Currently I just forward all function calls to 64 bits 
>>> version counterparts, but in this case a set of unit tests 
>>> are failing. I see following approaches to handle this issue:
>>>    - Totally remove 80 bit real type from NetBSD port (make 
>>> real==double)
>>>    - Change tests and skip asserts for NetBSD
>>>
>>> There is one additional approach: implement these functions 
>>> in druntime, but it is too big/massive work for me.
>>
>> I wouldn't worry about it too much.  If someone really needs 
>> this, they will have to chip in.  Dmd uses compiler intrinsics 
>> for those trig functions, and I notice that they seem to just 
>> call the native x86 asm instructions:
>
> I hate it if D doesn't fully support the hardware just to be 
> compatible to some bad designed C library.

This is not just "some... C library," we're talking about the 
system ABI here!

> Hey, it's a system language! I want to be able to use the 
> hardware I have to its fullest!

You can: I left real as 80-bit there, but it's irrelevant as 
Android/x86 is basically dead since Intel exited the mobile 
market.

> And for calling C functions you always have to fing the fitting 
> D-type by checking "mantdig" and map accordingly. Thats really 
> not so difficult.

The problem is that std.math depends on some basic C math 
functions for the native long double type, ie the D "real" 
equivalent, and if your system ABI defines long double to be less 
precise than what the hardware supports, those more precise math 
functions may not exist.  Hell, as Nikolay just said, they may 
not exist even if your ABI uses the same precision as the 
hardware!

In that case, where your platform doesn't provide such precise C 
math functions, it's tough for me to care.  If you really need 
the precision, roll up your sleeves and add it, whether in C or D.

On Thursday, 11 May 2017 at 10:33:21 UTC, Nikolay wrote:
>> What is long double on NetBSD/amd64, 64-bit or full 80-bit?
> 80 bit
> but function set is not full e.g.
>
> acos supports long double
> http://netbsd.gw.com/cgi-bin/man-cgi?acos+3+NetBSD-7.0
>
> cos does not support long double
> http://netbsd.gw.com/cgi-bin/man-cgi?cos+3+NetBSD-7.0

In that case, defining real as 80-bit and modifying some tests 
for NetBSD seems the way to go.  You may want to look at my last 
Phobos patch for Android/x86, from a couple years ago:

https://gist.github.com/joakim-noah/5d399fdcd5e484d6aaa2

> On Thursday, 11 May 2017 at 10:07:32 UTC, Joakim wrote:
>> Dmd uses compiler intrinsics for those trig functions, and I 
>> notice that they seem to just call the native x86 asm 
>> instructions:
>>
>> https://github.com/dlang/dmd/blob/master/src/ddmd/root/longdouble.c#L428
> As I know native x87 implementation of many math functions is 
> terrible, and it is rarely used in real world.

Well, if you don't like what's available and NetBSD doesn't 
provide them... up to you to decide where that leads.


More information about the Digitalmars-d mailing list