xref: /minix3/lib/libc/arch/sparc/gen/flt_rounds.c (revision e415d488727a332a2c69df018aa35e2cecf4148a)
1*e415d488SLionel Sambuc /*	$NetBSD: flt_rounds.c,v 1.7 2012/03/21 00:38:34 christos Exp $	*/
22fe8fb19SBen Gras 
32fe8fb19SBen Gras /*
42fe8fb19SBen Gras  * Written by J.T. Conklin, Apr 10, 1995
52fe8fb19SBen Gras  * Public domain.
62fe8fb19SBen Gras  */
72fe8fb19SBen Gras 
82fe8fb19SBen Gras #include <sys/cdefs.h>
92fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint)
10*e415d488SLionel Sambuc __RCSID("$NetBSD: flt_rounds.c,v 1.7 2012/03/21 00:38:34 christos Exp $");
112fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */
122fe8fb19SBen Gras 
132fe8fb19SBen Gras #include <sys/types.h>
142fe8fb19SBen Gras #include <machine/float.h>
152fe8fb19SBen Gras 
162fe8fb19SBen Gras static const int map[] = {
172fe8fb19SBen Gras 	1,	/* round to nearest */
182fe8fb19SBen Gras 	0,	/* round to zero */
192fe8fb19SBen Gras 	2,	/* round to positive infinity */
202fe8fb19SBen Gras 	3	/* round to negative infinity */
212fe8fb19SBen Gras };
222fe8fb19SBen Gras 
232fe8fb19SBen Gras int
__flt_rounds(void)24*e415d488SLionel Sambuc __flt_rounds(void)
252fe8fb19SBen Gras {
26*e415d488SLionel Sambuc 	unsigned int x;
272fe8fb19SBen Gras 
282fe8fb19SBen Gras 	__asm("st %%fsr,%0" : "=m" (*&x));
292fe8fb19SBen Gras 	return map[(x >> 30) & 0x03];
302fe8fb19SBen Gras }
31