xref: /minix3/lib/libc/arch/sparc/gen/fpsetround.c (revision e415d488727a332a2c69df018aa35e2cecf4148a)
1 /*	$NetBSD: fpsetround.c,v 1.6 2012/03/21 00:38:35 christos Exp $	*/
2 
3 /*
4  * Written by J.T. Conklin, Apr 10, 1995
5  * Public domain.
6  */
7 
8 #include <sys/cdefs.h>
9 #if defined(LIBC_SCCS) && !defined(lint)
10 __RCSID("$NetBSD: fpsetround.c,v 1.6 2012/03/21 00:38:35 christos Exp $");
11 #endif /* LIBC_SCCS and not lint */
12 
13 #include "namespace.h"
14 
15 #include <ieeefp.h>
16 
17 #ifdef __weak_alias
__weak_alias(fpsetround,_fpsetround)18 __weak_alias(fpsetround,_fpsetround)
19 #endif
20 
21 fp_rnd
22 fpsetround(fp_rnd rnd_dir)
23 {
24 	fp_rnd old;
25 	fp_rnd new;
26 
27 	__asm("st %%fsr,%0" : "=m" (*&old));
28 
29 	new = old;
30 	new &= ~(0x03 << 30);
31 	new |= ((rnd_dir & 0x03) << 30);
32 
33 	__asm("ld %0,%%fsr" : : "m" (*&new));
34 
35 	return ((unsigned int)old >> 30) & 0x03;
36 }
37