xref: /minix3/lib/libc/arch/mips/gen/fpsetround.c (revision e415d488727a332a2c69df018aa35e2cecf4148a)
1*e415d488SLionel Sambuc /*	$NetBSD: fpsetround.c,v 1.6 2012/03/19 22:23:10 matt Exp $	*/
22fe8fb19SBen Gras 
32fe8fb19SBen Gras /*
42fe8fb19SBen Gras  * Written by J.T. Conklin, Apr 11, 1995
52fe8fb19SBen Gras  * Public domain.
62fe8fb19SBen Gras  */
72fe8fb19SBen Gras 
82fe8fb19SBen Gras #include <sys/cdefs.h>
92fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint)
10*e415d488SLionel Sambuc __RCSID("$NetBSD: fpsetround.c,v 1.6 2012/03/19 22:23:10 matt Exp $");
112fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */
122fe8fb19SBen Gras 
132fe8fb19SBen Gras #include "namespace.h"
142fe8fb19SBen Gras 
152fe8fb19SBen Gras #include <ieeefp.h>
162fe8fb19SBen Gras 
172fe8fb19SBen Gras #ifdef __weak_alias
182fe8fb19SBen Gras __weak_alias(fpsetround,_fpsetround)
192fe8fb19SBen Gras #endif
202fe8fb19SBen Gras 
212fe8fb19SBen Gras fp_rnd
22*e415d488SLionel Sambuc fpsetround(fp_rnd rnd_dir)
232fe8fb19SBen Gras {
242fe8fb19SBen Gras 	fp_rnd old;
252fe8fb19SBen Gras 	fp_rnd new;
262fe8fb19SBen Gras 
272fe8fb19SBen Gras 	__asm("cfc1 %0,$31" : "=r" (old));
282fe8fb19SBen Gras 
29*e415d488SLionel Sambuc 	new = old & ~0x03;
30*e415d488SLionel Sambuc 	new |= rnd_dir & 0x03;
312fe8fb19SBen Gras 
322fe8fb19SBen Gras 	__asm("ctc1 %0,$31" : : "r" (new));
332fe8fb19SBen Gras 
342fe8fb19SBen Gras 	return old & 0x03;
352fe8fb19SBen Gras }
36