diff options
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]); +} |