xref: /openbsd/lib/libc/arch/sparc64/gen/fpsetround.c (revision de1699b1)
1*de1699b1Sart /*	$OpenBSD: fpsetround.c,v 1.1 2001/08/29 01:34:56 art Exp $	*/
2*de1699b1Sart 
3*de1699b1Sart /*
4*de1699b1Sart  * Written by J.T. Conklin, Apr 10, 1995
5*de1699b1Sart  * Public domain.
6*de1699b1Sart  */
7*de1699b1Sart 
8*de1699b1Sart #include <ieeefp.h>
9*de1699b1Sart 
10*de1699b1Sart fp_rnd
fpsetround(rnd_dir)11*de1699b1Sart fpsetround(rnd_dir)
12*de1699b1Sart 	fp_rnd rnd_dir;
13*de1699b1Sart {
14*de1699b1Sart 	fp_rnd old;
15*de1699b1Sart 	fp_rnd new;
16*de1699b1Sart 
17*de1699b1Sart 	__asm__("st %%fsr,%0" : "=m" (*&old));
18*de1699b1Sart 
19*de1699b1Sart 	new = old;
20*de1699b1Sart 	new &= ~(0x03 << 30);
21*de1699b1Sart 	new |= ((rnd_dir & 0x03) << 30);
22*de1699b1Sart 
23*de1699b1Sart 	__asm__("ld %0,%%fsr" : : "m" (*&new));
24*de1699b1Sart 
25*de1699b1Sart 	return (old >> 30) & 0x03;
26*de1699b1Sart }
27