1*e415d488SLionel Sambuc /* $NetBSD: flt_rounds.c,v 1.5 2012/03/23 09:34:09 skrll Exp $ */ 22fe8fb19SBen Gras 32fe8fb19SBen Gras /* $OpenBSD: flt_rounds.c,v 1.3 2002/10/21 18:41:05 mickey Exp $ */ 42fe8fb19SBen Gras 52fe8fb19SBen Gras /* 62fe8fb19SBen Gras * Written by Miodrag Vallat. Public domain. 72fe8fb19SBen Gras */ 82fe8fb19SBen Gras 92fe8fb19SBen Gras #include <sys/cdefs.h> 102fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint) 11*e415d488SLionel Sambuc __RCSID("$NetBSD: flt_rounds.c,v 1.5 2012/03/23 09:34:09 skrll Exp $"); 122fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */ 132fe8fb19SBen Gras 142fe8fb19SBen Gras #include <sys/types.h> 152fe8fb19SBen Gras #include <machine/float.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)252fe8fb19SBen Gras__flt_rounds(void) 262fe8fb19SBen Gras { 272fe8fb19SBen Gras uint64_t fpsr; 282fe8fb19SBen Gras 292fe8fb19SBen Gras __asm volatile("fstd %%fr0,0(%1)" : "=m" (fpsr) : "r" (&fpsr)); 30*e415d488SLionel Sambuc return map[(unsigned int)(fpsr >> 41) & 0x03]; 312fe8fb19SBen Gras } 32