xref: /netbsd-src/lib/libc/arch/sparc64/gen/fpsetround.c (revision aabd8f68bab7dab89a501bb74b70467440f5c523)
1*aabd8f68Srillig /*	$NetBSD: fpsetround.c,v 1.9 2024/03/20 06:15:39 rillig Exp $	*/
2cf009bccSeeh 
3cf009bccSeeh /*
4cf009bccSeeh  * Written by J.T. Conklin, Apr 10, 1995
5cf009bccSeeh  * Public domain.
6cf009bccSeeh  */
7cf009bccSeeh 
85d3e8294Sthorpej #include <sys/cdefs.h>
988c3eadbSlukem #if defined(LIBC_SCCS) && !defined(lint)
10*aabd8f68Srillig __RCSID("$NetBSD: fpsetround.c,v 1.9 2024/03/20 06:15:39 rillig Exp $");
1188c3eadbSlukem #endif /* LIBC_SCCS and not lint */
125d3e8294Sthorpej 
135d3e8294Sthorpej #include "namespace.h"
145d3e8294Sthorpej 
150abf123aSmartin #include <sys/types.h>
16cf009bccSeeh #include <ieeefp.h>
17cf009bccSeeh 
185d3e8294Sthorpej #ifdef __weak_alias
195d3e8294Sthorpej __weak_alias(fpsetround,_fpsetround)
205d3e8294Sthorpej #endif
215d3e8294Sthorpej 
2208e65c02Schristos #ifdef SOFTFLOATSPARC64_FOR_GCC
2308e65c02Schristos extern fp_rnd _softfloat_float_rounding_mode;
2408e65c02Schristos #endif
2508e65c02Schristos 
26cf009bccSeeh fp_rnd
fpsetround(fp_rnd rnd_dir)27a078c856Smrg fpsetround(fp_rnd rnd_dir)
28cf009bccSeeh {
29cf009bccSeeh 	fp_rnd old;
30cf009bccSeeh 	fp_rnd new;
31cf009bccSeeh 
32ce666bb8Sperry 	__asm("st %%fsr,%0" : "=m" (*&old));
33cf009bccSeeh 
3438e436ceSmartin #ifdef SOFTFLOATSPARC64_FOR_GCC
3538e436ceSmartin 	_softfloat_float_rounding_mode = rnd_dir;
3638e436ceSmartin #endif
3738e436ceSmartin 
38cf009bccSeeh 	new = old;
3908e65c02Schristos 	new &= ~(0x03U << 30);
40*aabd8f68Srillig 	new |= ((rnd_dir & 0x03U) << 30);
41cf009bccSeeh 
42ce666bb8Sperry 	__asm("ld %0,%%fsr" : : "m" (*&new));
43cf009bccSeeh 
440abf123aSmartin 	return ((uint32_t)old >> 30) & 0x03;
45cf009bccSeeh }
46