xref: /netbsd-src/lib/libc/arch/sparc64/gen/flt_rounds.c (revision 3d365e7447a96c9a8d60ba350e9a77732c5aede8)
1*3d365e74Schristos /*	$NetBSD: flt_rounds.c,v 1.6 2012/06/24 15:26:02 christos Exp $	*/
2cf009bccSeeh 
3cf009bccSeeh /*
4cf009bccSeeh  * Written by J.T. Conklin, Apr 10, 1995
5cf009bccSeeh  * Public domain.
6cf009bccSeeh  */
7cf009bccSeeh 
888c3eadbSlukem #include <sys/cdefs.h>
988c3eadbSlukem #if defined(LIBC_SCCS) && !defined(lint)
10*3d365e74Schristos __RCSID("$NetBSD: flt_rounds.c,v 1.6 2012/06/24 15:26:02 christos Exp $");
1188c3eadbSlukem #endif /* LIBC_SCCS and not lint */
1288c3eadbSlukem 
13cf009bccSeeh #include <sys/types.h>
14cf009bccSeeh #include <machine/float.h>
15cf009bccSeeh 
16cf009bccSeeh static const int map[] = {
17cf009bccSeeh 	1,	/* round to nearest */
18cf009bccSeeh 	0,	/* round to zero */
198fc6819dSnakayama 	2,	/* round to positive infinity */
208fc6819dSnakayama 	3	/* round to negative infinity */
21cf009bccSeeh };
22cf009bccSeeh 
23cf009bccSeeh int
__flt_rounds(void)24*3d365e74Schristos __flt_rounds(void)
25cf009bccSeeh {
260abf123aSmartin 	uint32_t x;
27cf009bccSeeh 
28ce666bb8Sperry 	__asm("st %%fsr,%0" : "=m" (*&x));
29cf009bccSeeh 	return map[(x >> 30) & 0x03];
30cf009bccSeeh }
31