flt_rounds.c revision 1.2
11.2Slukem/* $NetBSD: flt_rounds.c,v 1.2 2005/06/12 05:21:25 lukem 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.2Slukem__RCSID("$NetBSD: flt_rounds.c,v 1.2 2005/06/12 05:21:25 lukem 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.1Schs __asm__ __volatile__("fstd %%fr0,0(%1)" : "=m" (fpsr) : "r" (&fpsr)); 301.1Schs return map[(fpsr >> 41) & 0x03]; 311.1Schs} 32