xref: /openbsd-src/lib/libc/arch/hppa/gen/flt_rounds.c (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /*	$OpenBSD: flt_rounds.c,v 1.3 2002/10/21 18:41:05 mickey Exp $	*/
2 
3 /*
4  * Written by Miodrag Vallat.  Public domain.
5  */
6 
7 #include <sys/types.h>
8 #include <machine/float.h>
9 
10 static const int map[] = {
11 	1,	/* round to nearest */
12 	0,	/* round to zero */
13 	2,	/* round to positive infinity */
14 	3	/* round to negative infinity */
15 };
16 
17 int
18 __flt_rounds()
19 {
20 	u_int64_t fpsr;
21 
22 	__asm__ __volatile__("fstd %%fr0,0(%1)" : "=m" (fpsr) : "r" (&fpsr));
23 	return map[(fpsr >> 41) & 0x03];
24 }
25