aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/sparc64/gen/fpsetround.c
blob: ea383b2f0bf01369384269bd8e22069c8f142474 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*	$NetBSD: fpsetround.c,v 1.2 2002/01/13 21:45:51 thorpej Exp $	*/

/*
 * Written by J.T. Conklin, Apr 10, 1995
 * Public domain.
 */

#include <sys/cdefs.h>
__FBSDID("$FreeBSD: src/lib/libc/sparc64/gen/fpsetround.c,v 1.1.36.1.2.1 2009/10/25 01:10:29 kensmith Exp $");

#include <machine/fsr.h>
#include <ieeefp.h>

fp_rnd_t
fpsetround(rnd_dir)
	fp_rnd_t rnd_dir;
{
	unsigned int old;
	unsigned int new;

	__asm__("st %%fsr,%0" : "=m" (old));

	new = old;
	new &= ~FSR_RD_MASK;
	new |= FSR_RD((unsigned int)rnd_dir & 0x03);

	__asm__("ld %0,%%fsr" : : "m" (new));

	return ((fp_rnd_t)FSR_GET_RD(old));
}