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