Home | History | Annotate | Line # | Download | only in gen
      1 /*	$NetBSD: flt_rounds.c,v 1.9 2015/03/19 21:22:59 joerg Exp $	*/
      2 
      3 /*
      4  * Written by J.T. Conklin, Apr 11, 1995
      5  * Public domain.
      6  */
      7 
      8 #include <sys/cdefs.h>
      9 #if defined(LIBC_SCCS) && !defined(lint)
     10 __RCSID("$NetBSD: flt_rounds.c,v 1.9 2015/03/19 21:22:59 joerg Exp $");
     11 #endif /* LIBC_SCCS and not lint */
     12 
     13 #include "namespace.h"
     14 #include <machine/float.h>
     15 #include <ieeefp.h>
     16 
     17 static const int map[] = {
     18 	1,	/* round to nearest */
     19 	0,	/* round to zero */
     20 	2,	/* round to positive infinity */
     21 	3	/* round to negative infinity */
     22 };
     23 
     24 int
     25 __flt_rounds(void)
     26 {
     27 #ifdef SOFTFLOAT_FOR_GCC
     28 	return map[fpgetround()];
     29 #else
     30 	int x;
     31 
     32 	__asm(".set push; .set noat; cfc1 %0,$31; .set pop" : "=r" (x));
     33 	return map[x & 0x03];
     34 #endif
     35 }
     36