fpsetround.c revision 1.3
11.3Slukem/*	$NetBSD: fpsetround.c,v 1.3 2005/06/12 05:21:27 lukem 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.3Slukem__RCSID("$NetBSD: fpsetround.c,v 1.3 2005/06/12 05:21:27 lukem Exp $");
111.3Slukem#endif /* LIBC_SCCS and not lint */
121.2Sthorpej
131.2Sthorpej#include "namespace.h"
141.2Sthorpej
151.1Seeh#include <ieeefp.h>
161.2Sthorpej
171.2Sthorpej#ifdef __weak_alias
181.2Sthorpej__weak_alias(fpsetround,_fpsetround)
191.2Sthorpej#endif
201.1Seeh
211.1Seehfp_rnd
221.1Seehfpsetround(rnd_dir)
231.1Seeh	fp_rnd rnd_dir;
241.1Seeh{
251.1Seeh	fp_rnd old;
261.1Seeh	fp_rnd new;
271.1Seeh
281.1Seeh	__asm__("st %%fsr,%0" : "=m" (*&old));
291.1Seeh
301.1Seeh	new = old;
311.1Seeh	new &= ~(0x03 << 30);
321.1Seeh	new |= ((rnd_dir & 0x03) << 30);
331.1Seeh
341.1Seeh	__asm__("ld %0,%%fsr" : : "m" (*&new));
351.1Seeh
361.1Seeh	return (old >> 30) & 0x03;
371.1Seeh}
38