11.9Srillig/* $NetBSD: fpsetround.c,v 1.9 2024/03/20 06:15:39 rillig Exp $ */ 21.1Seeh 31.1Seeh/* 41.1Seeh * Written by J.T. Conklin, Apr 10, 1995 51.1Seeh * Public domain. 61.1Seeh */ 71.1Seeh 81.2Sthorpej#include <sys/cdefs.h> 91.3Slukem#if defined(LIBC_SCCS) && !defined(lint) 101.9Srillig__RCSID("$NetBSD: fpsetround.c,v 1.9 2024/03/20 06:15:39 rillig Exp $"); 111.3Slukem#endif /* LIBC_SCCS and not lint */ 121.2Sthorpej 131.2Sthorpej#include "namespace.h" 141.2Sthorpej 151.5Smartin#include <sys/types.h> 161.1Seeh#include <ieeefp.h> 171.2Sthorpej 181.2Sthorpej#ifdef __weak_alias 191.2Sthorpej__weak_alias(fpsetround,_fpsetround) 201.2Sthorpej#endif 211.1Seeh 221.8Schristos#ifdef SOFTFLOATSPARC64_FOR_GCC 231.8Schristosextern fp_rnd _softfloat_float_rounding_mode; 241.8Schristos#endif 251.8Schristos 261.1Seehfp_rnd 271.7Smrgfpsetround(fp_rnd rnd_dir) 281.1Seeh{ 291.1Seeh fp_rnd old; 301.1Seeh fp_rnd new; 311.1Seeh 321.4Sperry __asm("st %%fsr,%0" : "=m" (*&old)); 331.1Seeh 341.6Smartin#ifdef SOFTFLOATSPARC64_FOR_GCC 351.6Smartin _softfloat_float_rounding_mode = rnd_dir; 361.6Smartin#endif 371.6Smartin 381.1Seeh new = old; 391.9Srillig new &= ~(0x03U << 30); 401.9Srillig new |= ((rnd_dir & 0x03U) << 30); 411.1Seeh 421.4Sperry __asm("ld %0,%%fsr" : : "m" (*&new)); 431.1Seeh 441.5Smartin return ((uint32_t)old >> 30) & 0x03; 451.1Seeh} 46