xref: /minix3/lib/libc/arch/hppa/gen/fpsetround.c (revision e415d488727a332a2c69df018aa35e2cecf4148a)
1*e415d488SLionel Sambuc /*	$NetBSD: fpsetround.c,v 1.6 2012/03/23 09:34:09 skrll Exp $	*/
22fe8fb19SBen Gras 
32fe8fb19SBen Gras /*	$OpenBSD: fpsetround.c,v 1.3 2002/10/21 18:41:05 mickey Exp $	*/
42fe8fb19SBen Gras 
52fe8fb19SBen Gras /*
62fe8fb19SBen Gras  * Written by Miodrag Vallat.  Public domain
72fe8fb19SBen Gras  */
82fe8fb19SBen Gras 
92fe8fb19SBen Gras #include <sys/cdefs.h>
102fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint)
11*e415d488SLionel Sambuc __RCSID("$NetBSD: fpsetround.c,v 1.6 2012/03/23 09:34:09 skrll Exp $");
122fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */
132fe8fb19SBen Gras 
142fe8fb19SBen Gras #include <sys/types.h>
152fe8fb19SBen Gras #include <ieeefp.h>
162fe8fb19SBen Gras 
172fe8fb19SBen Gras fp_rnd
fpsetround(fp_rnd rnd_dir)182fe8fb19SBen Gras fpsetround(fp_rnd rnd_dir)
192fe8fb19SBen Gras {
202fe8fb19SBen Gras 	uint64_t fpsr;
212fe8fb19SBen Gras 	fp_rnd old;
222fe8fb19SBen Gras 
232fe8fb19SBen Gras 	__asm volatile("fstd %%fr0,0(%1)" : "=m" (fpsr) : "r" (&fpsr) : "memory");
24*e415d488SLionel Sambuc 	old = (fp_rnd)(fpsr >> 41) & 0x03;
252fe8fb19SBen Gras 	fpsr = (fpsr & 0xfffff9ff00000000LL) |
262fe8fb19SBen Gras 	    ((uint64_t)(rnd_dir & 0x03) << 41);
272fe8fb19SBen Gras 	__asm volatile("fldd 0(%0),%%fr0" : : "r" (&fpsr) : "memory");
282fe8fb19SBen Gras 	return (old);
292fe8fb19SBen Gras }
30