diff options
author | 2017-08-07 20:56:46 +0000 | |
---|---|---|
committer | 2017-08-07 20:56:46 +0000 | |
commit | 1d8d17b82369fed2b89d739194dd44db4b18b11c (patch) | |
tree | 377420e88e289f0fd966bee4330e617ad444889c | |
parent | Add "machine exit" and "machine poweroff" commands to the arm64 and armv7 (diff) | |
download | wireguard-openbsd-1d8d17b82369fed2b89d739194dd44db4b18b11c.tar.xz wireguard-openbsd-1d8d17b82369fed2b89d739194dd44db4b18b11c.zip |
Clang does not support -ffloat-store, so libm fenv test failed on
i386. Gcc uses this option it to store x87 registers to memory.
This reduces precision and enforces rounding which this test checks.
The same effect can be achieved by using a volatile double variable
for the result. This works for both compilers.
OK kettenis@
-rw-r--r-- | regress/lib/libm/fenv/Makefile | 3 | ||||
-rw-r--r-- | regress/lib/libm/fenv/fenv.c | 16 |
2 files changed, 12 insertions, 7 deletions
diff --git a/regress/lib/libm/fenv/Makefile b/regress/lib/libm/fenv/Makefile index 556dcda29c9..9298ef93dfb 100644 --- a/regress/lib/libm/fenv/Makefile +++ b/regress/lib/libm/fenv/Makefile @@ -1,8 +1,7 @@ -# $OpenBSD: Makefile,v 1.3 2017/06/02 20:03:54 otto Exp $ +# $OpenBSD: Makefile,v 1.4 2017/08/07 20:56:46 bluhm Exp $ PROG=fenv -CFLAGS+=-ffloat-store LDADD=-lm DPADD=${LIBM} diff --git a/regress/lib/libm/fenv/fenv.c b/regress/lib/libm/fenv/fenv.c index d821c1babe7..038b2f9ef19 100644 --- a/regress/lib/libm/fenv/fenv.c +++ b/regress/lib/libm/fenv/fenv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fenv.c,v 1.2 2012/12/05 23:20:07 deraadt Exp $ */ +/* $OpenBSD: fenv.c,v 1.3 2017/08/07 20:56:46 bluhm Exp $ */ /*- * Copyright (c) 2004 David Schultz <das@FreeBSD.org> @@ -519,21 +519,27 @@ raiseexcept(int excepts) static int getround(void) { - volatile double d; + volatile double d, e; /* * This test works just as well with 0.0 - 0.0, except on ia64 * where 0.0 - 0.0 gives the wrong sign when rounding downwards. + * On i386 use two volatile variables d and e to retrieve the + * value out of the x87 and force rounding. + * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=204671 */ d = 1.0; d -= 1.0; - if (copysign(1.0, d) < 0.0) + e = copysign(1.0, d); + if (e < 0.0) return (FE_DOWNWARD); d = 1.0; - if (d + (DBL_EPSILON * 3.0 / 4.0) == 1.0) + e = d + (DBL_EPSILON * 3.0 / 4.0); + if (e == 1.0) return (FE_TOWARDZERO); - if (d + (DBL_EPSILON * 1.0 / 4.0) > 1.0) + e = d + (DBL_EPSILON * 1.0 / 4.0); + if (e > 1.0) return (FE_UPWARD); return (FE_TONEAREST); |