xref: /dragonfly/lib/libc/x86_64/gen/flt_rounds.c (revision 8af44722)
1 /*
2  * Written by J.T. Conklin, Apr 10, 1995
3  * Public domain.
4  *
5  * $FreeBSD: head/lib/libc/amd64/gen/flt_rounds.c 132383 2004-07-19 08:17:25Z das $
6  */
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