11.5Sskrll/*	$NetBSD: flt_rounds.c,v 1.5 2012/03/23 09:34:09 skrll 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.2Slukem#include <sys/cdefs.h>
101.2Slukem#if defined(LIBC_SCCS) && !defined(lint)
111.5Sskrll__RCSID("$NetBSD: flt_rounds.c,v 1.5 2012/03/23 09:34:09 skrll Exp $");
121.2Slukem#endif /* LIBC_SCCS and not lint */
131.2Slukem
141.1Schs#include <sys/types.h>
151.1Schs#include <machine/float.h>
161.1Schs
171.1Schsstatic const int map[] = {
181.1Schs	1,	/* round to nearest */
191.1Schs	0,	/* round to zero */
201.1Schs	2,	/* round to positive infinity */
211.1Schs	3	/* round to negative infinity */
221.1Schs};
231.1Schs
241.1Schsint
251.1Schs__flt_rounds(void)
261.1Schs{
271.1Schs	uint64_t fpsr;
281.1Schs
291.4Sperry	__asm volatile("fstd %%fr0,0(%1)" : "=m" (fpsr) : "r" (&fpsr));
301.5Sskrll	return map[(unsigned int)(fpsr >> 41) & 0x03];
311.1Schs}
32