1*e415d488SLionel Sambuc /* $NetBSD: fpsetround.c,v 1.6 2012/03/21 00:38:35 christos Exp $ */ 22fe8fb19SBen Gras 32fe8fb19SBen Gras /* 42fe8fb19SBen Gras * Written by J.T. Conklin, Apr 10, 1995 52fe8fb19SBen Gras * Public domain. 62fe8fb19SBen Gras */ 72fe8fb19SBen Gras 82fe8fb19SBen Gras #include <sys/cdefs.h> 92fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint) 10*e415d488SLionel Sambuc __RCSID("$NetBSD: fpsetround.c,v 1.6 2012/03/21 00:38:35 christos Exp $"); 112fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */ 122fe8fb19SBen Gras 132fe8fb19SBen Gras #include "namespace.h" 142fe8fb19SBen Gras 152fe8fb19SBen Gras #include <ieeefp.h> 162fe8fb19SBen Gras 172fe8fb19SBen Gras #ifdef __weak_alias __weak_alias(fpsetround,_fpsetround)182fe8fb19SBen Gras__weak_alias(fpsetround,_fpsetround) 192fe8fb19SBen Gras #endif 202fe8fb19SBen Gras 212fe8fb19SBen Gras fp_rnd 22*e415d488SLionel Sambuc fpsetround(fp_rnd rnd_dir) 232fe8fb19SBen Gras { 242fe8fb19SBen Gras fp_rnd old; 252fe8fb19SBen Gras fp_rnd new; 262fe8fb19SBen Gras 272fe8fb19SBen Gras __asm("st %%fsr,%0" : "=m" (*&old)); 282fe8fb19SBen Gras 292fe8fb19SBen Gras new = old; 302fe8fb19SBen Gras new &= ~(0x03 << 30); 312fe8fb19SBen Gras new |= ((rnd_dir & 0x03) << 30); 322fe8fb19SBen Gras 332fe8fb19SBen Gras __asm("ld %0,%%fsr" : : "m" (*&new)); 342fe8fb19SBen Gras 35*e415d488SLionel Sambuc return ((unsigned int)old >> 30) & 0x03; 362fe8fb19SBen Gras } 37