1 1.9 joerg /* $NetBSD: flt_rounds.c,v 1.9 2015/03/19 21:22:59 joerg 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.9 joerg __RCSID("$NetBSD: flt_rounds.c,v 1.9 2015/03/19 21:22:59 joerg Exp $"); 11 1.4 lukem #endif /* LIBC_SCCS and not lint */ 12 1.4 lukem 13 1.9 joerg #include "namespace.h" 14 1.3 jonathan #include <machine/float.h> 15 1.6 matt #include <ieeefp.h> 16 1.1 jtc 17 1.1 jtc static const int map[] = { 18 1.1 jtc 1, /* round to nearest */ 19 1.1 jtc 0, /* round to zero */ 20 1.1 jtc 2, /* round to positive infinity */ 21 1.1 jtc 3 /* round to negative infinity */ 22 1.1 jtc }; 23 1.1 jtc 24 1.1 jtc int 25 1.7 christos __flt_rounds(void) 26 1.1 jtc { 27 1.6 matt #ifdef SOFTFLOAT_FOR_GCC 28 1.6 matt return map[fpgetround()]; 29 1.6 matt #else 30 1.1 jtc int x; 31 1.1 jtc 32 1.8 joerg __asm(".set push; .set noat; cfc1 %0,$31; .set pop" : "=r" (x)); 33 1.1 jtc return map[x & 0x03]; 34 1.6 matt #endif 35 1.1 jtc } 36