Home | History | Annotate | Line # | Download | only in gen
flt_rounds.c revision 1.5.34.1
      1  1.5.34.1      matt /*	$NetBSD: flt_rounds.c,v 1.5.34.1 2010/01/27 06:55:25 matt 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.5.34.1      matt __RCSID("$NetBSD: flt_rounds.c,v 1.5.34.1 2010/01/27 06:55:25 matt Exp $");
     11       1.4     lukem #endif /* LIBC_SCCS and not lint */
     12       1.4     lukem 
     13       1.3  jonathan #include <machine/float.h>
     14  1.5.34.1      matt #include <ieeefp.h>
     15       1.1       jtc 
     16       1.1       jtc static const int map[] = {
     17       1.1       jtc 	1,	/* round to nearest */
     18       1.1       jtc 	0,	/* round to zero */
     19       1.1       jtc 	2,	/* round to positive infinity */
     20       1.1       jtc 	3	/* round to negative infinity */
     21       1.1       jtc };
     22       1.1       jtc 
     23       1.1       jtc int
     24       1.1       jtc __flt_rounds()
     25       1.1       jtc {
     26  1.5.34.1      matt #ifdef SOFTFLOAT_FOR_GCC
     27  1.5.34.1      matt 	return map[fpgetround()];
     28  1.5.34.1      matt #else
     29       1.1       jtc 	int x;
     30       1.1       jtc 
     31  1.5.34.1      matt 	__asm("cfc1\t%0,$31" : "=r" (x));
     32       1.1       jtc 	return map[x & 0x03];
     33  1.5.34.1      matt #endif
     34       1.1       jtc }
     35