flt_rounds.c revision 1.7
11.7Schristos/* $NetBSD: flt_rounds.c,v 1.7 2012/03/21 00:38:34 christos Exp $ */ 21.3Sperry 31.1Sjtc/* 41.1Sjtc * Written by J.T. Conklin, Apr 10, 1995 51.1Sjtc * Public domain. 61.1Sjtc */ 71.1Sjtc 81.5Slukem#include <sys/cdefs.h> 91.5Slukem#if defined(LIBC_SCCS) && !defined(lint) 101.7Schristos__RCSID("$NetBSD: flt_rounds.c,v 1.7 2012/03/21 00:38:34 christos Exp $"); 111.5Slukem#endif /* LIBC_SCCS and not lint */ 121.5Slukem 131.2Sthorpej#include <sys/types.h> 141.2Sthorpej#include <machine/float.h> 151.2Sthorpej 161.1Sjtcstatic const int map[] = { 171.1Sjtc 1, /* round to nearest */ 181.1Sjtc 0, /* round to zero */ 191.4Snakayama 2, /* round to positive infinity */ 201.4Snakayama 3 /* round to negative infinity */ 211.1Sjtc}; 221.1Sjtc 231.1Sjtcint 241.7Schristos__flt_rounds(void) 251.1Sjtc{ 261.7Schristos unsigned int x; 271.1Sjtc 281.6Sperry __asm("st %%fsr,%0" : "=m" (*&x)); 291.1Sjtc return map[(x >> 30) & 0x03]; 301.1Sjtc} 31