xref: /netbsd-src/lib/libc/arch/mips/gen/flt_rounds.c (revision 80d9064ac03cbb6a4174695f0d5b237c8766d3d0)
1 /*	$NetBSD: flt_rounds.c,v 1.8 2014/09/17 11:02:55 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.8 2014/09/17 11:02:55 joerg Exp $");
11 #endif /* LIBC_SCCS and not lint */
12 
13 #include <machine/float.h>
14 #include <ieeefp.h>
15 
16 static const int map[] = {
17 	1,	/* round to nearest */
18 	0,	/* round to zero */
19 	2,	/* round to positive infinity */
20 	3	/* round to negative infinity */
21 };
22 
23 int
24 __flt_rounds(void)
25 {
26 #ifdef SOFTFLOAT_FOR_GCC
27 	return map[fpgetround()];
28 #else
29 	int x;
30 
31 	__asm(".set push; .set noat; cfc1 %0,$31; .set pop" : "=r" (x));
32 	return map[x & 0x03];
33 #endif
34 }
35