Home | History | Annotate | Line # | Download | only in gen
flt_rounds.c revision 1.5
      1  1.5     perry /*	$NetBSD: flt_rounds.c,v 1.5 2005/12/24 23:10:08 perry 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     perry __RCSID("$NetBSD: flt_rounds.c,v 1.5 2005/12/24 23:10:08 perry 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.1       jtc 
     15  1.1       jtc static const int map[] = {
     16  1.1       jtc 	1,	/* round to nearest */
     17  1.1       jtc 	0,	/* round to zero */
     18  1.1       jtc 	2,	/* round to positive infinity */
     19  1.1       jtc 	3	/* round to negative infinity */
     20  1.1       jtc };
     21  1.1       jtc 
     22  1.1       jtc int
     23  1.1       jtc __flt_rounds()
     24  1.1       jtc {
     25  1.1       jtc 	int x;
     26  1.1       jtc 
     27  1.5     perry 	__asm("cfc1 %0,$31" : "=r" (x));
     28  1.1       jtc 	return map[x & 0x03];
     29  1.1       jtc }
     30