11.8Srillig/* $NetBSD: fpsetround.c,v 1.8 2024/04/02 20:42:12 rillig Exp $ */ 21.2Sperry 31.1Sjtc/* 41.1Sjtc * Written by J.T. Conklin, Apr 10, 1995 51.1Sjtc * Public domain. 61.1Sjtc */ 71.1Sjtc 81.3Sthorpej#include <sys/cdefs.h> 91.4Slukem#if defined(LIBC_SCCS) && !defined(lint) 101.8Srillig__RCSID("$NetBSD: fpsetround.c,v 1.8 2024/04/02 20:42:12 rillig Exp $"); 111.4Slukem#endif /* LIBC_SCCS and not lint */ 121.3Sthorpej 131.3Sthorpej#include "namespace.h" 141.3Sthorpej 151.1Sjtc#include <ieeefp.h> 161.3Sthorpej 171.3Sthorpej#ifdef __weak_alias 181.3Sthorpej__weak_alias(fpsetround,_fpsetround) 191.3Sthorpej#endif 201.1Sjtc 211.1Sjtcfp_rnd 221.6Schristosfpsetround(fp_rnd rnd_dir) 231.1Sjtc{ 241.1Sjtc fp_rnd old; 251.1Sjtc fp_rnd new; 261.1Sjtc 271.5Sperry __asm("st %%fsr,%0" : "=m" (*&old)); 281.1Sjtc 291.1Sjtc new = old; 301.8Srillig new &= ~(0x03U << 30); 311.8Srillig new |= ((rnd_dir & 0x03U) << 30); 321.1Sjtc 331.5Sperry __asm("ld %0,%%fsr" : : "m" (*&new)); 341.1Sjtc 351.6Schristos return ((unsigned int)old >> 30) & 0x03; 361.1Sjtc} 37