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