1 1.7 christos /* $NetBSD: flt_rounds.c,v 1.7 2012/06/24 15:26:02 christos Exp $ */ 2 1.2 jonathan 3 1.1 jtc /* 4 1.1 jtc * Written by J.T. Conklin, Apr 11, 1995 5 1.1 jtc * Public domain. 6 1.1 jtc */ 7 1.3 jonathan 8 1.4 lukem #include <sys/cdefs.h> 9 1.4 lukem #if defined(LIBC_SCCS) && !defined(lint) 10 1.7 christos __RCSID("$NetBSD: flt_rounds.c,v 1.7 2012/06/24 15:26:02 christos Exp $"); 11 1.4 lukem #endif /* LIBC_SCCS and not lint */ 12 1.4 lukem 13 1.3 jonathan #include <machine/float.h> 14 1.6 matt #include <ieeefp.h> 15 1.1 jtc 16 1.1 jtc static const int map[] = { 17 1.1 jtc 1, /* round to nearest */ 18 1.1 jtc 0, /* round to zero */ 19 1.1 jtc 2, /* round to positive infinity */ 20 1.1 jtc 3 /* round to negative infinity */ 21 1.1 jtc }; 22 1.1 jtc 23 1.1 jtc int 24 1.7 christos __flt_rounds(void) 25 1.1 jtc { 26 1.6 matt #ifdef SOFTFLOAT_FOR_GCC 27 1.6 matt return map[fpgetround()]; 28 1.6 matt #else 29 1.1 jtc int x; 30 1.1 jtc 31 1.6 matt __asm("cfc1\t%0,$31" : "=r" (x)); 32 1.1 jtc return map[x & 0x03]; 33 1.6 matt #endif 34 1.1 jtc } 35