fpsetround.c revision 1.7
1/*	$NetBSD: fpsetround.c,v 1.7 2013/10/28 01:06:36 mrg 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.7 2013/10/28 01:06:36 mrg Exp $");
11#endif /* LIBC_SCCS and not lint */
12
13#include "namespace.h"
14
15#include <sys/types.h>
16#include <ieeefp.h>
17
18#ifdef __weak_alias
19__weak_alias(fpsetround,_fpsetround)
20#endif
21
22fp_rnd
23fpsetround(fp_rnd rnd_dir)
24{
25	fp_rnd old;
26	fp_rnd new;
27#ifdef SOFTFLOATSPARC64_FOR_GCC
28	extern fp_rnd _softfloat_float_rounding_mode;
29#endif
30
31	__asm("st %%fsr,%0" : "=m" (*&old));
32
33#ifdef SOFTFLOATSPARC64_FOR_GCC
34	_softfloat_float_rounding_mode = rnd_dir;
35#endif
36
37	new = old;
38	new &= ~(0x03 << 30);
39	new |= ((rnd_dir & 0x03) << 30);
40
41	__asm("ld %0,%%fsr" : : "m" (*&new));
42
43	return ((uint32_t)old >> 30) & 0x03;
44}
45