]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
ARM: Improve fenv implementation
authorWilco <wdijkstr@arm.com>
Thu, 15 May 2014 14:21:55 +0000 (15:21 +0100)
committerMarcus Shawcroft <marcus.shawcroft@arm.com>
Thu, 15 May 2014 14:23:27 +0000 (15:23 +0100)
13 files changed:
ChangeLog
sysdeps/arm/fclrexcpt.c
sysdeps/arm/fedisblxcpt.c
sysdeps/arm/feenablxcpt.c
sysdeps/arm/fegetround.c
sysdeps/arm/feholdexcpt.c
sysdeps/arm/fesetenv.c
sysdeps/arm/fesetround.c
sysdeps/arm/feupdateenv.c
sysdeps/arm/fgetexcptflg.c
sysdeps/arm/fsetexcptflg.c
sysdeps/arm/ftestexcept.c
sysdeps/arm/setfpucw.c

index 83719ed4502671cd0e68e153445581d84c68dd11..29ffc2d621a97838d058577decddf9ea374f79f6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
        * nptl/sysdeps/unix/sysv/linux/s390/bits/pthreadtypes.h
        (pthread_mutex_t): Add lock elision support for s390.
 
+2014-05-14  Wilco  <wdijkstr@arm.com>
+
+       * sysdeps/arm/fclrexcpt.c: Optimize to avoid unnecessary FPSCR writes.
+       * sysdeps/arm/fedisblxcpt.c: Likewise.
+       * sysdeps/arm/feenablxcpt.c: Likewise.
+       * sysdeps/arm/fegetround.c: Call (get_rounding_mode).
+       * sysdeps/arm/feholdexcpt.c: Call optimized (libc_feholdexcept_vfp).
+       * sysdeps/arm/fesetenv.c: Special case FE_DFL_ENV and FE_NOMASK_ENV.
+       Call optimized (libc_fesetenv_vfp).
+       * sysdeps/arm/fesetround.c: Call optimized (libc_fesetround_vfp).
+       * sysdeps/arm/feupdateenv.c: Special case FE_DFL_ENV and FE_NOMASK_ENV.
+       Call optimized (libc_feupdateenv_vfp).
+       * sysdeps/arm/fgetexcptflg.c: Call optimized (libc_fetestexcept_vfp).
+       * sysdeps/arm/fsetexcptflg.c: Optimize to avoid unnecessary FPSCR
+       writes.
+       * sysdeps/arm/ftestexcept.c: Call optimized (libc_fetestexcept_vfp).
+       * sysdeps/arm/setfpucw.c: Optimize to avoid unnecessary FPSCR writes.
+
 2014-05-14  Wilco  <wdijkstr@arm.com>
 
        * sysdeps/arm/fclrexcpt.c: Cleanup.
index cbf61a6f4a133794d2c8f317aa38982d621697bd..31420ed3c74a81835ade20ce54235233ab728ebc 100644 (file)
@@ -24,7 +24,7 @@
 int
 feclearexcept (int excepts)
 {
-  fpu_control_t fpscr;
+  fpu_control_t fpscr, new_fpscr;
 
   /* Fail if a VFP unit isn't present unless nothing needs to be done.  */
   if (!ARM_HAVE_VFP)
@@ -32,11 +32,11 @@ feclearexcept (int excepts)
 
   _FPU_GETCW (fpscr);
   excepts &= FE_ALL_EXCEPT;
+  new_fpscr = fpscr & ~excepts;
 
-  /* Clear the relevant bits.  */
-  fpscr = (fpscr & ~FE_ALL_EXCEPT) | (fpscr & FE_ALL_EXCEPT & ~excepts);
-
-  _FPU_SETCW (fpscr);
+  /* Write new exception flags if changed.  */
+  if (new_fpscr != fpscr)
+    _FPU_SETCW (new_fpscr);
 
   return 0;
 }
index f2956cd32aa5a2794e38dadfb51834e04c9cef8d..d5e0f0031aa6b8cace48a4f095b89d76875aa9c7 100644 (file)
@@ -35,7 +35,9 @@ fedisableexcept (int excepts)
   excepts &= FE_ALL_EXCEPT;
   new_fpscr = fpscr & ~(excepts << FE_EXCEPT_SHIFT);
 
-  _FPU_SETCW (new_fpscr);
+  /* Write new exceptions if changed.  */
+  if (new_fpscr != fpscr)
+    _FPU_SETCW (new_fpscr);
 
   return (fpscr >> FE_EXCEPT_SHIFT) & FE_ALL_EXCEPT;
 }
index afd8943638da014bb33226511a08fb9e99c38465..e649b2f1e17e8256f6b10e48fe78f9480a540aea 100644 (file)
@@ -35,15 +35,15 @@ feenableexcept (int excepts)
   excepts &= FE_ALL_EXCEPT;
   new_fpscr = fpscr | (excepts << FE_EXCEPT_SHIFT);
 
-  _FPU_SETCW (new_fpscr);
-
-  if (excepts != 0)
+  if (new_fpscr != fpscr)
     {
+      _FPU_SETCW (new_fpscr);
+
       /* Not all VFP architectures support trapping exceptions, so
         test whether the relevant bits were set and fail if not.  */
       _FPU_GETCW (new_fpscr);
-      if ((new_fpscr & (excepts << FE_EXCEPT_SHIFT))
-         != (excepts << FE_EXCEPT_SHIFT))
+
+      if (((new_fpscr >> FE_EXCEPT_SHIFT) & excepts) != excepts)
        return -1;
     }
 
index 1c9c151a16b1f30134b324d2222bf13b65998609..fbad0b30785bd961598ede8fa63e7f5fc044619f 100644 (file)
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <fenv.h>
-#include <fpu_control.h>
-#include <arm-features.h>
+#include <get-rounding-mode.h>
 
 
 int
 fegetround (void)
 {
-  fpu_control_t fpscr;
-
-  /* FE_TONEAREST is the only supported rounding mode
-     if a VFP unit isn't present.  */
-  if (!ARM_HAVE_VFP)
-    return FE_TONEAREST;
-
-  _FPU_GETCW (fpscr);
-  return fpscr & FE_TOWARDZERO;
+  return get_rounding_mode ();
 }
 libm_hidden_def (fegetround)
index 258ba6637f3d7ef93462fbd1a40c9499a89e1c86..2d79e0c46d9be670841a2be6d25b12aae5482cc9 100644 (file)
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <fenv.h>
-#include <fpu_control.h>
+#include <fenv_private.h>
 #include <arm-features.h>
 
 
 int
 feholdexcept (fenv_t *envp)
 {
-  fpu_control_t fpscr;
-
   /* Fail if a VFP unit isn't present.  */
   if (!ARM_HAVE_VFP)
     return 1;
 
-  _FPU_GETCW (fpscr);
-  envp->__cw = fpscr;
-
-  /* Now set all exceptions to non-stop.  */
-  fpscr &= ~(FE_ALL_EXCEPT << FE_EXCEPT_SHIFT);
-
-  /* And clear all exception flags.  */
-  fpscr &= ~FE_ALL_EXCEPT;
-
-  _FPU_SETCW (fpscr);
+  libc_feholdexcept_vfp (envp);
   return 0;
 }
 
index 62031d596d7108283ff85760f0230e79cf771260..9e2aa81f9bc6bdb4f7b6fb398402f7e9183d5afe 100644 (file)
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <fenv.h>
-#include <fpu_control.h>
+#include <fenv_private.h>
 #include <arm-features.h>
 
 
 int
 fesetenv (const fenv_t *envp)
 {
-  fpu_control_t fpscr;
-
   /* Fail if a VFP unit isn't present.  */
   if (!ARM_HAVE_VFP)
     return 1;
 
-  _FPU_GETCW (fpscr);
+  if ((envp == FE_DFL_ENV) || (envp == FE_NOMASK_ENV))
+    {
+      fpu_control_t fpscr, new_fpscr;
+
+      _FPU_GETCW (fpscr);
 
-  /* Preserve the reserved FPSCR flags.  */
-  fpscr &= _FPU_RESERVED;
+      /* Preserve the reserved FPSCR flags.  */
+      new_fpscr = fpscr & _FPU_RESERVED;
 
-  if (envp == FE_DFL_ENV)
-    fpscr |= _FPU_DEFAULT;
-  else if (envp == FE_NOMASK_ENV)
-    fpscr |= _FPU_IEEE;
-  else
-    fpscr |= envp->__cw & ~_FPU_RESERVED;
+      if (envp == FE_DFL_ENV)
+       _FPU_SETCW (new_fpscr | _FPU_DEFAULT);
+      else
+       {
+         _FPU_SETCW (new_fpscr | _FPU_IEEE);
+         /* Not all VFP architectures support trapping exceptions, so
+            test whether the relevant bits were set and fail if not.  */
+         _FPU_GETCW (fpscr);
 
-  _FPU_SETCW (fpscr);
+         if ((fpscr & _FPU_IEEE) != _FPU_IEEE)
+           return 1;
+       }
 
-  if (envp == FE_NOMASK_ENV)
-    {
-      /* Not all VFP architectures support trapping exceptions, so
-        test whether the relevant bits were set and fail if not.  */
-      _FPU_GETCW (fpscr);
-      if ((fpscr & _FPU_IEEE) != _FPU_IEEE)
-       return 1;
+      return 0;
     }
 
+  libc_fesetenv_vfp (envp);
   return 0;
 }
 
index d1b92dc2557edceb6a095d5e7088e015d8e02640..f52c50aec483097fa88379d30ec66365f55a2cfa 100644 (file)
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <fenv.h>
-#include <fpu_control.h>
+#include <fenv_private.h>
 #include <arm-features.h>
 
 
 int
 fesetround (int round)
 {
-  fpu_control_t fpscr;
-
   /* FE_TONEAREST is the only supported rounding mode
      if a VFP unit isn't present.  */
   if (!ARM_HAVE_VFP)
     return (round == FE_TONEAREST) ? 0 : 1;
 
-  /* Fail if the rounding mode is not valid.  */
   if (round & ~FE_TOWARDZERO)
     return 1;
 
-  _FPU_GETCW (fpscr);
-  fpscr = (fpscr & ~FE_TOWARDZERO) | round;
-  _FPU_SETCW (fpscr);
+  libc_fesetround_vfp (round);
   return 0;
 }
 
index 55a15025c6da4986ecd51a7c592cb346ef38f846..2a7b3ec894e666eb438b18b3427ad2544f329b5a 100644 (file)
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <fenv.h>
-#include <fpu_control.h>
+#include <fenv_private.h>
 #include <arm-features.h>
 
 
 int
 feupdateenv (const fenv_t *envp)
 {
-  fpu_control_t fpscr;
+  fenv_t fenv;
 
   /* Fail if a VFP unit isn't present.  */
   if (!ARM_HAVE_VFP)
     return 1;
 
-  _FPU_GETCW (fpscr);
+  if ((envp == FE_DFL_ENV) || (envp == FE_NOMASK_ENV))
+    {
+      fpu_control_t fpscr;
 
-  /* Install new environment.  */
-  fesetenv (envp);
+      _FPU_GETCW (fpscr);
 
-  /* Raise the saved exceptions.  */
-  feraiseexcept (fpscr & FE_ALL_EXCEPT);
+      /* Preserve the reserved FPSCR flags.  */
+      fpscr &= _FPU_RESERVED;
+      fpscr |= (envp == FE_DFL_ENV) ? _FPU_DEFAULT : _FPU_IEEE;
+
+      /* Create a valid fenv to pass to libc_feupdateenv_vfp.  */
+      fenv.__cw = fpscr;
+      envp = &fenv;
+    }
+
+  libc_feupdateenv_vfp (envp);
   return 0;
 }
 libm_hidden_def (feupdateenv)
index 63fdfbf747a04072109d1cfcc1324fc572acaeeb..994555ca19392e4d0307880996536577545bb5e3 100644 (file)
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <fenv.h>
-#include <fpu_control.h>
+#include <fenv_private.h>
 #include <arm-features.h>
 
 
 int
 fegetexceptflag (fexcept_t *flagp, int excepts)
 {
-  fpu_control_t fpscr;
-
   /* Fail if a VFP unit isn't present.  */
   if (!ARM_HAVE_VFP)
     return 1;
 
-  _FPU_GETCW (fpscr);
-
-  *flagp = fpscr & excepts & FE_ALL_EXCEPT;
+  *flagp = libc_fetestexcept_vfp (excepts);
   return 0;
 }
index 1a610ff91265653d3a3536a85a4843c2bc0a916f..28810d3ec8c97181fb2c8938cbdacb10d0930fd5 100644 (file)
 int
 fesetexceptflag (const fexcept_t *flagp, int excepts)
 {
-  fpu_control_t fpscr;
+  fpu_control_t fpscr, new_fpscr;
 
   /* Fail if a VFP unit isn't present unless nothing needs to be done.  */
   if (!ARM_HAVE_VFP)
     return (excepts != 0);
 
   _FPU_GETCW (fpscr);
+  excepts &= FE_ALL_EXCEPT;
 
   /* Set the desired exception mask.  */
-  fpscr &= ~(excepts & FE_ALL_EXCEPT);
-  fpscr |= (*flagp & excepts & FE_ALL_EXCEPT);
+  new_fpscr = fpscr & ~excepts;
+  new_fpscr |= *flagp & excepts;
+
+  /* Write new exception flags if changed.  */
+  if (new_fpscr != fpscr)
+    _FPU_SETCW (new_fpscr);
 
-  /* Save state back to the FPU.  */
-  _FPU_SETCW (fpscr);
   return 0;
 }
index de082b281a3fa7904e06c78e64a7bf99d996d89e..6c5d3a828823635856aa72c358603345d34224fb 100644 (file)
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <fenv.h>
-#include <fpu_control.h>
+#include <fenv_private.h>
 #include <arm-features.h>
 
 
 int
 fetestexcept (int excepts)
 {
-  fpu_control_t fpscr;
-
   /* Return no exception flags if a VFP unit isn't present.  */
   if (!ARM_HAVE_VFP)
     return 0;
 
-  /* Get current exceptions.  */
-  _FPU_GETCW (fpscr);
-
-  return fpscr & excepts & FE_ALL_EXCEPT;
+  return libc_fetestexcept_vfp (excepts);
 }
+
 libm_hidden_def (fetestexcept)
index 7416377f9ede7f4129c3441007ecc969d05c020b..259b020f81d4a0873d1f4f68d96e249ff2c4ee4e 100644 (file)
 void
 __setfpucw (fpu_control_t set)
 {
-  fpu_control_t fpscr;
+  fpu_control_t fpscr, new_fpscr;
 
   /* Do nothing if a VFP unit isn't present.  */
   if (!ARM_HAVE_VFP)
     return;
 
-  /* Fetch the current control word.  */
   _FPU_GETCW (fpscr);
 
   /* Preserve the reserved bits, and set the rest as the user
      specified (or the default, if the user gave zero).  */
-  fpscr &= _FPU_RESERVED;
-  fpscr |= set & ~_FPU_RESERVED;
+  new_fpscr = fpscr & _FPU_RESERVED;
+  new_fpscr |= set & ~_FPU_RESERVED;
 
-  _FPU_SETCW (fpscr);
+  /* Write FPSCR if changed.  */
+  if (new_fpscr != fpscr)
+    _FPU_SETCW (fpscr);
 }