fpsetround.c revision 1.3
11.3Sthorpej/*	$NetBSD: fpsetround.c,v 1.3 2002/01/13 21:45:49 thorpej Exp $	*/
21.2Sperry
31.1Sjtc/*
41.1Sjtc * Written by J.T. Conklin, Apr 10, 1995
51.1Sjtc * Public domain.
61.1Sjtc */
71.1Sjtc
81.3Sthorpej#include <sys/cdefs.h>
91.3Sthorpej
101.3Sthorpej#include "namespace.h"
111.3Sthorpej
121.1Sjtc#include <ieeefp.h>
131.3Sthorpej
141.3Sthorpej#ifdef __weak_alias
151.3Sthorpej__weak_alias(fpsetround,_fpsetround)
161.3Sthorpej#endif
171.1Sjtc
181.1Sjtcfp_rnd
191.1Sjtcfpsetround(rnd_dir)
201.1Sjtc	fp_rnd rnd_dir;
211.1Sjtc{
221.1Sjtc	fp_rnd old;
231.1Sjtc	fp_rnd new;
241.1Sjtc
251.1Sjtc	__asm__("st %%fsr,%0" : "=m" (*&old));
261.1Sjtc
271.1Sjtc	new = old;
281.1Sjtc	new &= ~(0x03 << 30);
291.1Sjtc	new |= ((rnd_dir & 0x03) << 30);
301.1Sjtc
311.1Sjtc	__asm__("ld %0,%%fsr" : : "m" (*&new));
321.1Sjtc
331.1Sjtc	return (old >> 30) & 0x03;
341.1Sjtc}
35