Home | History | Annotate | Line # | Download | only in gen
flt_rounds.c revision 1.4.44.2
      1  1.4.44.2      yamt /*	$NetBSD: flt_rounds.c,v 1.4.44.2 2012/10/30 18:58:41 yamt 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.4.44.2      yamt __RCSID("$NetBSD: flt_rounds.c,v 1.4.44.2 2012/10/30 18:58:41 yamt 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.4.44.2      yamt __flt_rounds(void)
     25       1.1       eeh {
     26  1.4.44.1      yamt 	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