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