fpsetround.c revision 1.6
11.6Smartin/*	$NetBSD: fpsetround.c,v 1.6 2013/02/15 09:25:03 martin 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.6Smartin__RCSID("$NetBSD: fpsetround.c,v 1.6 2013/02/15 09:25:03 martin 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.1Seehfpsetround(rnd_dir)
241.1Seeh	fp_rnd rnd_dir;
251.1Seeh{
261.1Seeh	fp_rnd old;
271.1Seeh	fp_rnd new;
281.6Smartin#ifdef SOFTFLOATSPARC64_FOR_GCC
291.6Smartin	extern fp_rnd _softfloat_float_rounding_mode;
301.6Smartin#endif
311.1Seeh
321.4Sperry	__asm("st %%fsr,%0" : "=m" (*&old));
331.1Seeh
341.6Smartin#ifdef SOFTFLOATSPARC64_FOR_GCC
351.6Smartin	_softfloat_float_rounding_mode = rnd_dir;
361.6Smartin#endif
371.6Smartin
381.1Seeh	new = old;
391.1Seeh	new &= ~(0x03 << 30);
401.1Seeh	new |= ((rnd_dir & 0x03) << 30);
411.1Seeh
421.4Sperry	__asm("ld %0,%%fsr" : : "m" (*&new));
431.1Seeh
441.5Smartin	return ((uint32_t)old >> 30) & 0x03;
451.1Seeh}
46