xref: /freebsd/lib/libc/amd64/gen/flt_rounds.c (revision 1d386b48)
1 /*
2  * Written by J.T. Conklin, Apr 10, 1995
3  * Public domain.
4  */
5 
6 #include <sys/cdefs.h>
7 #include <float.h>
8 
9 static const int map[] = {
10 	1,	/* round to nearest */
11 	3,	/* round to zero */
12 	2,	/* round to negative infinity */
13 	0	/* round to positive infinity */
14 };
15 
16 int
17 __flt_rounds(void)
18 {
19 	int x;
20 
21         /* Assume that the x87 and the SSE unit agree on the rounding mode. */
22 	__asm("fnstcw %0" : "=m" (x));
23         return (map[(x >> 10) & 0x03]);
24 }
25