tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: ocaml fails to build on netbsd-9/i386 and proposed fix



Hi,

> With this, ocaml builds, and unison builds and works.
...
> +# configure: error: fma does not work, enable emulation with --enable-imprecise-c99-float-ops
> +.if ${OPSYS} == "NetBSD" && ${MACHINE_ARCH} == "i386"
> +CONFIGURE_ARGS+=	--enable-imprecise-c99-float-ops
> +.endif
> +

I delved a bit into this.  Picked up the failing test program
from config.log, and did some debugging on NetBSD/i386 9.2.
First without optimization:

: {7} gcc -o fma-test -g fma-test.c -lm
: {8} gdb fma-test
GNU gdb (GDB) 8.3
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "i486--netbsdelf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from fma-test...
(gdb) l
1       #include <math.h>
2       int main (void) {
3         /* Tests 264-266 from testsuite/tests/fma/fma.ml. These tests trigger the
4            broken implementations of Cygwin64, mingw-w64 (x86_64) and VS2013-2017.
5            The static volatile variables aim to thwart GCC's constant folding. */
6         static volatile double x, y, z;
7         double t264, t265, t266;
8         x = 0x3.bd5b7dde5fddap-496;
9         y = 0x3.bd5b7dde5fddap-496;
10        z = -0xd.fc352bc352bap-992;
(gdb) l
11        t264 = fma(x, y, z);
12        x = 0x3.bd5b7dde5fddap-504;
13        y = 0x3.bd5b7dde5fddap-504;
14        z = -0xd.fc352bc352bap-1008;
15        t265 = fma(x, y, z);
16        x = 0x8p-540;
17        y = 0x4p-540;
18        z = 0x4p-1076;
19        t266 = fma(x, y, z);
20        return (!(t264 == 0x1.0989687cp-1044 ||
(gdb) l
21                  t264 == 0x0.000004277ca1fp-1022 || /* Acceptable emulated values */
22                  t264 == 0x0.00000428p-1022)
23             || !(t265 == 0x1.0988p-1060 ||
24                  t265 == 0x0.0000000004278p-1022 ||  /* Acceptable emulated values */
25                  t265 == 0x0.000000000428p-1022)
26             || !(t266 == 0x8p-1076));
27      }
28
(gdb) b 20
Breakpoint 1 at 0x8048980: file fma-test.c, line 20.
(gdb) r
Starting program: /usr/users/he/fma-test 

Breakpoint 1, main () at fma-test.c:20
20        return (!(t264 == 0x1.0989687cp-1044 ||
(gdb) p t264
$1 = 5.5095571555068341e-315
(gdb) p t265
$2 = 8.4070210296346512e-320
(gdb) p t266
$3 = 9.8813129168249309e-324
(gdb)   

Apparently, the i386 9.2 gdb can't print those hex floats, but it
can on amd64 9.2, so there's where I've printed the constants:

(the i386 gdb says:

(gdb) p 0x1.0989687cp-1044
Invalid number "0x1.0989687cp".
(gdb)

)

(gdb) p 0x1.0989687cp-1044
$22 = 5.5026158889100296e-315
(gdb) p 0x0.000004277ca1fp-1022
$23 = 5.5095571555068341e-315
(gdb) p 0x0.00000428p-1022
$24 = 5.5122156288746332e-315

So t264 looks an awful lot like $23:

 $1 = 5.5095571555068341e-315
$23 = 5.5095571555068341e-315

Likewise:

(gdb) p 0x1.0988p-1060
$25 = 8.3961515854261438e-320
(gdb) p 0x0.0000000004278p-1022
$26 = 8.4070210296346512e-320
(gdb) p 0x0.000000000428p-1022
$27 = 8.4109735548013812e-320

and t265 looks like $26:

 $2 = 8.4070210296346512e-320
$26 = 8.4070210296346512e-320

and lastly:

(gdb) p 0x8p-1076
$28 = 9.8813129168249309e-324
(gdb) 

looks an awful lot like t266:

 $3 = 9.8813129168249309e-324
$28 = 9.8813129168249309e-324

and ... the program exits normally:

(gdb) c 
Continuing.
[Inferior 1 (process 8720) exited normally]
(gdb) 

However, the -O2-compiled version behaves differently:

(gdb) p t264
$1 = 5.5095571555068341e-315
(gdb) p t265
$2 = 8.4070210296346512e-320
(gdb) p t266
$3 = <optimized out>
(gdb)
(gdb) c
Continuing.
[Inferior 1 (process 23779) exited with code 01]
(gdb)

Sigh!

Regards,

- Håvard


Home | Main Index | Thread Index | Old Index