fpsetround.c revision 1.7
11.7Smrg/*	$NetBSD: fpsetround.c,v 1.7 2013/10/28 01:06:36 mrg Exp $	*/
21.1Seeh
31.1Seeh/*
41.1Seeh * Written by J.T. Conklin, Apr 10, 1995
51.1Seeh * Public domain.
61.1Seeh */
71.1Seeh
81.2Sthorpej#include <sys/cdefs.h>
91.3Slukem#if defined(LIBC_SCCS) && !defined(lint)
101.7Smrg__RCSID("$NetBSD: fpsetround.c,v 1.7 2013/10/28 01:06:36 mrg Exp $");
111.3Slukem#endif /* LIBC_SCCS and not lint */
121.2Sthorpej
131.2Sthorpej#include "namespace.h"
141.2Sthorpej
151.5Smartin#include <sys/types.h>
161.1Seeh#include <ieeefp.h>
171.2Sthorpej
181.2Sthorpej#ifdef __weak_alias
191.2Sthorpej__weak_alias(fpsetround,_fpsetround)
201.2Sthorpej#endif
211.1Seeh
221.1Seehfp_rnd
231.7Smrgfpsetround(fp_rnd rnd_dir)
241.1Seeh{
251.1Seeh	fp_rnd old;
261.1Seeh	fp_rnd new;
271.6Smartin#ifdef SOFTFLOATSPARC64_FOR_GCC
281.6Smartin	extern fp_rnd _softfloat_float_rounding_mode;
291.6Smartin#endif
301.1Seeh
311.4Sperry	__asm("st %%fsr,%0" : "=m" (*&old));
321.1Seeh
331.6Smartin#ifdef SOFTFLOATSPARC64_FOR_GCC
341.6Smartin	_softfloat_float_rounding_mode = rnd_dir;
351.6Smartin#endif
361.6Smartin
371.1Seeh	new = old;
381.1Seeh	new &= ~(0x03 << 30);
391.1Seeh	new |= ((rnd_dir & 0x03) << 30);
401.1Seeh
411.4Sperry	__asm("ld %0,%%fsr" : : "m" (*&new));
421.1Seeh
431.5Smartin	return ((uint32_t)old >> 30) & 0x03;
441.1Seeh}
45