Module Name: src
Committed By: chs
Date: Mon Feb 27 06:57:16 UTC 2017
Modified Files:
src/sys/arch/mips/include: fenv.h
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/mips/include/fenv.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/mips/include/fenv.h
diff -u src/sys/arch/mips/include/fenv.h:1.2 src/sys/arch/mips/include/fenv.h:1.3
--- src/sys/arch/mips/include/fenv.h:1.2 Fri Jan 13 19:10:14 2017
+++ src/sys/arch/mips/include/fenv.h Mon Feb 27 06:57:16 2017
@@ -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 <[email protected]>
@@ -67,9 +67,21 @@ extern const fenv_t __fe_dfl_env;
#define _ENABLE_MASK (FE_ALL_EXCEPT << _ENABLE_SHIFT)
#define _ENABLE_SHIFT 5
+static inline fpu_control_t
+__rfs(void)
+{
+ fpu_control_t __fpsr;
+
+ __asm __volatile("cfc1 %0,$31" : "=r" (__fpsr));
+ return __fpsr;
+}
-#define __rfs(__fpsr) __asm __volatile("cfc1 %0,$31" : "=r" ((*__fpsr)))
-#define __wfs(__fpsr) __asm __volatile("ctc1 %0,$31" : : "r" (__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 @@ feclearexcept(int __excepts)
fexcept_t __fpsr;
__excepts &= FE_ALL_EXCEPT;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
__fpsr &= ~(__excepts | (__excepts << _ENABLE_SHIFT));
__wfs(__fpsr);
return 0;
@@ -88,7 +100,7 @@ fegetexceptflag(fexcept_t *__flagp, int
{
fexcept_t __fpsr;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
*__flagp = __fpsr & __excepts;
return (0);
}
@@ -98,7 +110,7 @@ fesetexceptflag(const fexcept_t *__flagp
{
fexcept_t __fpsr;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
__fpsr &= ~__excepts;
__fpsr |= *__flagp & __excepts;
__wfs(__fpsr);
@@ -119,7 +131,7 @@ fetestexcept(int __excepts)
{
fexcept_t __fpsr;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
return (__fpsr & __excepts);
}
@@ -128,7 +140,7 @@ fegetround(void)
{
fexcept_t __fpsr;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
return __fpsr & _ROUND_MASK;
}
@@ -139,10 +151,10 @@ fesetround(int __round)
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 @@ __fenv_static inline int
fegetenv(fenv_t *__envp)
{
- __rfs(__envp);
+ *__envp = __rfs();
return (0);
}
@@ -160,7 +172,7 @@ feholdexcept(fenv_t *__envp)
{
fenv_t __env;
- __rfs(&__env);
+ __env = __rfs();
*__envp = __env;
__env &= ~(FE_ALL_EXCEPT | _ENABLE_MASK);
__wfs(__env);
@@ -180,7 +192,7 @@ feupdateenv(const fenv_t *__envp)
{
fexcept_t __fpsr;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
__wfs(*__envp);
feraiseexcept(__fpsr & FE_ALL_EXCEPT);
return (0);
@@ -195,7 +207,7 @@ feenableexcept(int __excepts)
{
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 @@ fedisableexcept(int __excepts)
{
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 @@ fegetexcept(void)
{
fenv_t __fpsr;
- __rfs(&__fpsr);
+ __fpsr = __rfs();
return ((__fpsr & _ENABLE_MASK) >> _ENABLE_SHIFT);
}