xref: /netbsd-src/lib/libc/arch/hppa/gen/flt_rounds.c (revision 5b9a421677efb9106380328eb6c45d66c997589f)
1*5b9a4216Sskrll /*	$NetBSD: flt_rounds.c,v 1.5 2012/03/23 09:34:09 skrll Exp $	*/
295a63d48Schs 
395a63d48Schs /*	$OpenBSD: flt_rounds.c,v 1.3 2002/10/21 18:41:05 mickey Exp $	*/
495a63d48Schs 
595a63d48Schs /*
695a63d48Schs  * Written by Miodrag Vallat.  Public domain.
795a63d48Schs  */
895a63d48Schs 
988c3eadbSlukem #include <sys/cdefs.h>
1088c3eadbSlukem #if defined(LIBC_SCCS) && !defined(lint)
11*5b9a4216Sskrll __RCSID("$NetBSD: flt_rounds.c,v 1.5 2012/03/23 09:34:09 skrll Exp $");
1288c3eadbSlukem #endif /* LIBC_SCCS and not lint */
1388c3eadbSlukem 
1495a63d48Schs #include <sys/types.h>
1595a63d48Schs #include <machine/float.h>
1695a63d48Schs 
1795a63d48Schs static const int map[] = {
1895a63d48Schs 	1,	/* round to nearest */
1995a63d48Schs 	0,	/* round to zero */
2095a63d48Schs 	2,	/* round to positive infinity */
2195a63d48Schs 	3	/* round to negative infinity */
2295a63d48Schs };
2395a63d48Schs 
2495a63d48Schs int
__flt_rounds(void)2595a63d48Schs __flt_rounds(void)
2695a63d48Schs {
2795a63d48Schs 	uint64_t fpsr;
2895a63d48Schs 
29d5e310b8Sperry 	__asm volatile("fstd %%fr0,0(%1)" : "=m" (fpsr) : "r" (&fpsr));
30*5b9a4216Sskrll 	return map[(unsigned int)(fpsr >> 41) & 0x03];
3195a63d48Schs }
32