diff options
author | das <das@FreeBSD.org> | 2004-07-19 08:17:25 +0000 |
---|---|---|
committer | das <das@FreeBSD.org> | 2004-07-19 08:17:25 +0000 |
commit | 86c293bf54231dee13f45592a39a3f0d0cf19931 (patch) | |
tree | c9066d911af64f4a2b6d8c54df428e3e3cc5eb40 /lib/libc/amd64 | |
parent | 7aef999db62cfb1370a29fad2bbee5c489b660ec (diff) | |
download | FreeBSD-src-86c293bf54231dee13f45592a39a3f0d0cf19931.zip FreeBSD-src-86c293bf54231dee13f45592a39a3f0d0cf19931.tar.gz |
Make FLT_ROUNDS correctly reflect the dynamic rounding mode.
Diffstat (limited to 'lib/libc/amd64')
-rw-r--r-- | lib/libc/amd64/gen/Makefile.inc | 2 | ||||
-rw-r--r-- | lib/libc/amd64/gen/flt_rounds.c | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/libc/amd64/gen/Makefile.inc b/lib/libc/amd64/gen/Makefile.inc index 9f559e6..9cae7fa 100644 --- a/lib/libc/amd64/gen/Makefile.inc +++ b/lib/libc/amd64/gen/Makefile.inc @@ -4,5 +4,5 @@ SRCS+= _setjmp.S rfork_thread.S setjmp.S sigsetjmp.S \ fabs.S modf.S \ infinity.c ldexp.c makecontext.c signalcontext.c \ - fpgetmask.c fpsetmask.c fpgetprec.c fpsetprec.c \ + flt_rounds.c fpgetmask.c fpsetmask.c fpgetprec.c fpsetprec.c \ fpgetround.c fpsetround.c fpgetsticky.c fpsetsticky.c diff --git a/lib/libc/amd64/gen/flt_rounds.c b/lib/libc/amd64/gen/flt_rounds.c new file mode 100644 index 0000000..c0ce81f --- /dev/null +++ b/lib/libc/amd64/gen/flt_rounds.c @@ -0,0 +1,26 @@ +/* + * Written by J.T. Conklin, Apr 10, 1995 + * Public domain. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <float.h> + +static const int map[] = { + 1, /* round to nearest */ + 3, /* round to zero */ + 2, /* round to negative infinity */ + 0 /* round to positive infinity */ +}; + +int +__flt_rounds(void) +{ + int x; + + /* Assume that the x87 and the SSE unit agree on the rounding mode. */ + __asm("fnstcw %0" : "=m" (x)); + return (map[(x >> 10) & 0x03]); +} |