flt_rounds.c revision 1.1
11.1Schs/*	$NetBSD: flt_rounds.c,v 1.1 2004/07/24 19:09:29 chs Exp $	*/
21.1Schs
31.1Schs/*	$OpenBSD: flt_rounds.c,v 1.3 2002/10/21 18:41:05 mickey Exp $	*/
41.1Schs
51.1Schs/*
61.1Schs * Written by Miodrag Vallat.  Public domain.
71.1Schs */
81.1Schs
91.1Schs#include <sys/types.h>
101.1Schs#include <machine/float.h>
111.1Schs
121.1Schsstatic const int map[] = {
131.1Schs	1,	/* round to nearest */
141.1Schs	0,	/* round to zero */
151.1Schs	2,	/* round to positive infinity */
161.1Schs	3	/* round to negative infinity */
171.1Schs};
181.1Schs
191.1Schsint
201.1Schs__flt_rounds(void)
211.1Schs{
221.1Schs	uint64_t fpsr;
231.1Schs
241.1Schs	__asm__ __volatile__("fstd %%fr0,0(%1)" : "=m" (fpsr) : "r" (&fpsr));
251.1Schs	return map[(fpsr >> 41) & 0x03];
261.1Schs}
27