www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - NetBSD amd64: which way is the best for supporting 80 bits

reply Nikolay <sibnick gmail.com> writes:
I am porting LDC to NetBSD amd64, and I ask advice how to handle 
real type. NetBSD has limited support for this type. 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.
May 10
parent reply Joakim <dlang joakim.fea.st> writes:
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: https://github.com/dlang/dmd/blob/master/src/ddmd/root/longdouble.c#L428
May 11
next sibling parent reply Dominikus Dittes Scherkl <Dominikus.Scherkl continental-corporation.com> writes:
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. Hey, it's a system language! I want to be able to use the hardware I have to its fullest! 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.
May 11
parent reply Joakim <dlang joakim.fea.st> writes:
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.
May 11
parent reply Nikolay <sibnick gmail.com> writes:
On Thursday, 11 May 2017 at 11:10:50 UTC, Joakim wrote:
 Well, if you don't like what's available and NetBSD doesn't 
 provide them... up to you to decide where that leads.
In any case it was not my decision. LDC does not use x87 for math functions on other OS's.
May 11
parent kinke <kinke gmx.net> writes:
On Thursday, 11 May 2017 at 11:31:58 UTC, Nikolay wrote:
 On Thursday, 11 May 2017 at 11:10:50 UTC, Joakim wrote:
 Well, if you don't like what's available and NetBSD doesn't 
 provide them... up to you to decide where that leads.
In any case it was not my decision. LDC does not use x87 for math functions on other OS's.
LDC does use x87 reals on x86, the only exception I'm aware of being Windows (MSVC targets, MinGW would use x87), as the MS C runtimes don't support x87 at all (and they also define a 64-bit `long double` type, so the choice was pretty obvious). I don't have a strong opinion on whether the NetBSD x86 real should be 80 bits with a lot of tweaked tests or 64 bits. The latter is surely the simpler approach though.
May 11
prev sibling parent Nikolay <sibnick gmail.com> writes:
 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 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.
May 11