Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/mips/include fix fesetround() to set the FPSR to th...
details: https://anonhg.NetBSD.org/src/rev/50a5ab5b7958
branches: trunk
changeset: 351794:50a5ab5b7958
user: chs <chs%NetBSD.org@localhost>
date: Mon Feb 27 06:57:16 2017 +0000
description:
fix fesetround() to set the FPSR to the desired value rather than
a pointer to a local variable. wrap the asm in inline functions so that
the compiler can do type checking for us.
diffstat:
sys/arch/mips/include/fenv.h | 44 ++++++++++++++++++++++++++++----------------
1 files changed, 28 insertions(+), 16 deletions(-)
diffs (145 lines):
diff -r d6db447c09d0 -r 50a5ab5b7958 sys/arch/mips/include/fenv.h
--- a/sys/arch/mips/include/fenv.h Mon Feb 27 06:56:32 2017 +0000
+++ b/sys/arch/mips/include/fenv.h Mon Feb 27 06:57:16 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fenv.h,v 1.2 2017/01/13 19:10:14 christos Exp $ */
+/* $NetBSD: fenv.h,v 1.3 2017/02/27 06:57:16 chs Exp $ */
/*-
* Copyright (c) 2004-2005 David Schultz <das%FreeBSD.ORG@localhost>
@@ -67,9 +67,21 @@
#define _ENABLE_MASK (FE_ALL_EXCEPT << _ENABLE_SHIFT)
#define _ENABLE_SHIFT 5
+static inline fpu_control_t
+__rfs(void)
+{
+ fpu_control_t __fpsr;
-#define __rfs(__fpsr) __asm __volatile("cfc1 %0,$31" : "=r" ((*__fpsr)))
-#define __wfs(__fpsr) __asm __volatile("ctc1 %0,$31" : : "r" (__fpsr))
+ __asm __volatile("cfc1 %0,$31" : "=r" (__fpsr));
+ return __fpsr;
+}
+
+static inline void
+__wfs(fpu_control_t __fpsr)
+{
+
+ __asm __volatile("ctc1 %0,$31" : : "r" (__fpsr));
+}
__fenv_static inline int
feclearexcept(int __excepts)
@@ -77,7 +89,7 @@
fexcept_t __fpsr;
__excepts &= FE_ALL_EXCEPT;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
__fpsr &= ~(__excepts | (__excepts << _ENABLE_SHIFT));
__wfs(__fpsr);
return 0;
@@ -88,7 +100,7 @@
{
fexcept_t __fpsr;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
*__flagp = __fpsr & __excepts;
return (0);
}
@@ -98,7 +110,7 @@
{
fexcept_t __fpsr;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
__fpsr &= ~__excepts;
__fpsr |= *__flagp & __excepts;
__wfs(__fpsr);
@@ -119,7 +131,7 @@
{
fexcept_t __fpsr;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
return (__fpsr & __excepts);
}
@@ -128,7 +140,7 @@
{
fexcept_t __fpsr;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
return __fpsr & _ROUND_MASK;
}
@@ -139,10 +151,10 @@
if (__round & ~_ROUND_MASK)
return 1;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
__fpsr &= ~_ROUND_MASK;
__fpsr |= __round;
- __wfs(&__fpsr);
+ __wfs(__fpsr);
return 0;
}
@@ -151,7 +163,7 @@
fegetenv(fenv_t *__envp)
{
- __rfs(__envp);
+ *__envp = __rfs();
return (0);
}
@@ -160,7 +172,7 @@
{
fenv_t __env;
- __rfs(&__env);
+ __env = __rfs();
*__envp = __env;
__env &= ~(FE_ALL_EXCEPT | _ENABLE_MASK);
__wfs(__env);
@@ -180,7 +192,7 @@
{
fexcept_t __fpsr;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
__wfs(*__envp);
feraiseexcept(__fpsr & FE_ALL_EXCEPT);
return (0);
@@ -195,7 +207,7 @@
{
fenv_t __old_fpsr, __new_fpsr;
- __rfs(&__new_fpsr);
+ __new_fpsr = __rfs();
__old_fpsr = (__new_fpsr & _ENABLE_MASK) >> _ENABLE_SHIFT;
__excepts &= FE_ALL_EXCEPT;
__new_fpsr |= __excepts << _ENABLE_SHIFT;
@@ -208,7 +220,7 @@
{
fenv_t __old_fpsr, __new_fpsr;
- __rfs(&__new_fpsr);
+ __new_fpsr = __rfs();
__old_fpsr = (__new_fpsr & _ENABLE_MASK) >> _ENABLE_SHIFT;
__excepts &= FE_ALL_EXCEPT;
__new_fpsr &= ~(__excepts << _ENABLE_SHIFT);
@@ -221,7 +233,7 @@
{
fenv_t __fpsr;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
return ((__fpsr & _ENABLE_MASK) >> _ENABLE_SHIFT);
}
Home |
Main Index |
Thread Index |
Old Index