xref: /minix3/lib/libc/arch/sparc64/gen/fpsetsticky.c (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc /*	$NetBSD: fpsetsticky.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: fpsetsticky.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
192fe8fb19SBen Gras __weak_alias(fpsetsticky,_fpsetsticky)
202fe8fb19SBen Gras #endif
212fe8fb19SBen Gras 
22e415d488SLionel Sambuc #ifdef EXCEPTIONS_WITH_SOFTFLOAT
23e415d488SLionel Sambuc extern fp_except _softfloat_float_exception_flags;
24e415d488SLionel Sambuc #endif
25e415d488SLionel Sambuc 
262fe8fb19SBen Gras fp_except
fpsetsticky(fp_except sticky)27*84d9c625SLionel Sambuc fpsetsticky(fp_except sticky)
282fe8fb19SBen Gras {
292fe8fb19SBen Gras 	fp_except old;
302fe8fb19SBen Gras 	fp_except new;
312fe8fb19SBen Gras 
322fe8fb19SBen Gras 	__asm("st %%fsr,%0" : "=m" (*&old));
332fe8fb19SBen Gras 
342fe8fb19SBen Gras 	new = old;
352fe8fb19SBen Gras 	new &= ~(0x1f << 5);
362fe8fb19SBen Gras 	new |= ((sticky & 0x1f) << 5);
372fe8fb19SBen Gras 
382fe8fb19SBen Gras 	__asm("ld %0,%%fsr" : : "m" (*&new));
392fe8fb19SBen Gras 
40e415d488SLionel Sambuc 	old = ((uint32_t)old >> 5) & 0x1f;
41e415d488SLionel Sambuc 
42e415d488SLionel Sambuc #ifdef EXCEPTIONS_WITH_SOFTFLOAT
43e415d488SLionel Sambuc 	old |= _softfloat_float_exception_flags;
44e415d488SLionel Sambuc 	_softfloat_float_exception_flags = sticky;
45e415d488SLionel Sambuc #endif
46e415d488SLionel Sambuc 	return old;
472fe8fb19SBen Gras }
48