1*0a6a1f1dSLionel Sambuc /* $NetBSD: flt_rounds.c,v 1.9 2015/03/19 21:22:59 joerg Exp $ */ 22fe8fb19SBen Gras 32fe8fb19SBen Gras /* 42fe8fb19SBen Gras * Written by J.T. Conklin, Apr 11, 1995 52fe8fb19SBen Gras * Public domain. 62fe8fb19SBen Gras */ 72fe8fb19SBen Gras 82fe8fb19SBen Gras #include <sys/cdefs.h> 92fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint) 10*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: flt_rounds.c,v 1.9 2015/03/19 21:22:59 joerg Exp $"); 112fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */ 122fe8fb19SBen Gras 13*0a6a1f1dSLionel Sambuc #include "namespace.h" 142fe8fb19SBen Gras #include <machine/float.h> 152fe8fb19SBen Gras #include <ieeefp.h> 162fe8fb19SBen Gras 172fe8fb19SBen Gras static const int map[] = { 182fe8fb19SBen Gras 1, /* round to nearest */ 192fe8fb19SBen Gras 0, /* round to zero */ 202fe8fb19SBen Gras 2, /* round to positive infinity */ 212fe8fb19SBen Gras 3 /* round to negative infinity */ 222fe8fb19SBen Gras }; 232fe8fb19SBen Gras 242fe8fb19SBen Gras int __flt_rounds(void)25e415d488SLionel Sambuc__flt_rounds(void) 262fe8fb19SBen Gras { 272fe8fb19SBen Gras #ifdef SOFTFLOAT_FOR_GCC 282fe8fb19SBen Gras return map[fpgetround()]; 292fe8fb19SBen Gras #else 302fe8fb19SBen Gras int x; 312fe8fb19SBen Gras 32*0a6a1f1dSLionel Sambuc __asm(".set push; .set noat; cfc1 %0,$31; .set pop" : "=r" (x)); 332fe8fb19SBen Gras return map[x & 0x03]; 342fe8fb19SBen Gras #endif 352fe8fb19SBen Gras } 36