flt_rounds.c revision 1.1
1/*	$NetBSD: flt_rounds.c,v 1.1 2004/07/24 19:09:29 chs Exp $	*/
2
3/*	$OpenBSD: flt_rounds.c,v 1.3 2002/10/21 18:41:05 mickey Exp $	*/
4
5/*
6 * Written by Miodrag Vallat.  Public domain.
7 */
8
9#include <sys/types.h>
10#include <machine/float.h>
11
12static const int map[] = {
13	1,	/* round to nearest */
14	0,	/* round to zero */
15	2,	/* round to positive infinity */
16	3	/* round to negative infinity */
17};
18
19int
20__flt_rounds(void)
21{
22	uint64_t fpsr;
23
24	__asm__ __volatile__("fstd %%fr0,0(%1)" : "=m" (fpsr) : "r" (&fpsr));
25	return map[(fpsr >> 41) & 0x03];
26}
27