xref: /minix3/lib/libc/arch/sparc64/gen/fpsetround.c (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc /*	$NetBSD: fpsetround.c,v 1.7 2013/10/28 01:06:36 mrg 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*84d9c625SLionel Sambuc __RCSID("$NetBSD: fpsetround.c,v 1.7 2013/10/28 01:06:36 mrg Exp $");
112fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */
122fe8fb19SBen Gras 
132fe8fb19SBen Gras #include "namespace.h"
142fe8fb19SBen Gras 
15e415d488SLionel Sambuc #include <sys/types.h>
162fe8fb19SBen Gras #include <ieeefp.h>
172fe8fb19SBen Gras 
182fe8fb19SBen Gras #ifdef __weak_alias
__weak_alias(fpsetround,_fpsetround)192fe8fb19SBen Gras __weak_alias(fpsetround,_fpsetround)
202fe8fb19SBen Gras #endif
212fe8fb19SBen Gras 
222fe8fb19SBen Gras fp_rnd
23*84d9c625SLionel Sambuc fpsetround(fp_rnd rnd_dir)
242fe8fb19SBen Gras {
252fe8fb19SBen Gras 	fp_rnd old;
262fe8fb19SBen Gras 	fp_rnd new;
27*84d9c625SLionel Sambuc #ifdef SOFTFLOATSPARC64_FOR_GCC
28*84d9c625SLionel Sambuc 	extern fp_rnd _softfloat_float_rounding_mode;
29*84d9c625SLionel Sambuc #endif
302fe8fb19SBen Gras 
312fe8fb19SBen Gras 	__asm("st %%fsr,%0" : "=m" (*&old));
322fe8fb19SBen Gras 
33*84d9c625SLionel Sambuc #ifdef SOFTFLOATSPARC64_FOR_GCC
34*84d9c625SLionel Sambuc 	_softfloat_float_rounding_mode = rnd_dir;
35*84d9c625SLionel Sambuc #endif
36*84d9c625SLionel Sambuc 
372fe8fb19SBen Gras 	new = old;
382fe8fb19SBen Gras 	new &= ~(0x03 << 30);
392fe8fb19SBen Gras 	new |= ((rnd_dir & 0x03) << 30);
402fe8fb19SBen Gras 
412fe8fb19SBen Gras 	__asm("ld %0,%%fsr" : : "m" (*&new));
422fe8fb19SBen Gras 
43e415d488SLionel Sambuc 	return ((uint32_t)old >> 30) & 0x03;
442fe8fb19SBen Gras }
45