a2cf7d
commit fec2bd2c2d31bc731cf61623e150d047746954bd
a2cf7d
Author: Paul A. Clarke <pc@us.ibm.com>
a2cf7d
Date:   Tue Aug 6 00:13:45 2019 -0400
a2cf7d
a2cf7d
    [powerpc] fesetenv: optimize FPSCR access
a2cf7d
    
a2cf7d
    fesetenv() reads the current value of the Floating-Point Status and Control
a2cf7d
    Register (FPSCR) to determine the difference between the current state of
a2cf7d
    exception enables and the newly requested state.  All of these bits are also
a2cf7d
    returned by the lighter weight 'mffsl' instruction used by fegetenv_status().
a2cf7d
    Use that instead.
a2cf7d
    
a2cf7d
    Also, remove a local macro _FPU_MASK_ALL in favor of a common macro,
a2cf7d
    FPU_ENABLES_MASK from fenv_libc.h.
a2cf7d
    
a2cf7d
    Finally, use a local variable ('new') in favor of a pointer dereference
a2cf7d
    ('*envp').
a2cf7d
a2cf7d
diff --git a/sysdeps/powerpc/fpu/fesetenv.c b/sysdeps/powerpc/fpu/fesetenv.c
a2cf7d
index ad9fda15b12f15e3..ac927c8f3ada40b4 100644
a2cf7d
--- a/sysdeps/powerpc/fpu/fesetenv.c
a2cf7d
+++ b/sysdeps/powerpc/fpu/fesetenv.c
a2cf7d
@@ -19,8 +19,6 @@
a2cf7d
 #include <fenv_libc.h>
a2cf7d
 #include <fpu_control.h>
a2cf7d
 
a2cf7d
-#define _FPU_MASK_ALL (_FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM | _FPU_MASK_XM | _FPU_MASK_IM)
a2cf7d
-
a2cf7d
 int
a2cf7d
 __fesetenv (const fenv_t *envp)
a2cf7d
 {
a2cf7d
@@ -28,25 +26,23 @@ __fesetenv (const fenv_t *envp)
a2cf7d
 
a2cf7d
   /* get the currently set exceptions.  */
a2cf7d
   new.fenv = *envp;
a2cf7d
-  old.fenv = fegetenv_register ();
a2cf7d
-  if (old.l == new.l)
a2cf7d
-    return 0;
a2cf7d
+  old.fenv = fegetenv_status ();
a2cf7d
 
a2cf7d
   /* If the old env has no enabled exceptions and the new env has any enabled
a2cf7d
      exceptions, then unmask SIGFPE in the MSR FE0/FE1 bits.  This will put the
a2cf7d
      hardware into "precise mode" and may cause the FPU to run slower on some
a2cf7d
      hardware.  */
a2cf7d
-  if ((old.l & _FPU_MASK_ALL) == 0 && (new.l & _FPU_MASK_ALL) != 0)
a2cf7d
+  if ((old.l & FPSCR_ENABLES_MASK) == 0 && (new.l & FPSCR_ENABLES_MASK) != 0)
a2cf7d
     (void) __fe_nomask_env_priv ();
a2cf7d
 
a2cf7d
   /* If the old env had any enabled exceptions and the new env has no enabled
a2cf7d
      exceptions, then mask SIGFPE in the MSR FE0/FE1 bits.  This may allow the
a2cf7d
      FPU to run faster because it always takes the default action and can not
a2cf7d
      generate SIGFPE. */
a2cf7d
-  if ((old.l & _FPU_MASK_ALL) != 0 && (new.l & _FPU_MASK_ALL) == 0)
a2cf7d
+  if ((old.l & FPSCR_ENABLES_MASK) != 0 && (new.l & FPSCR_ENABLES_MASK) == 0)
a2cf7d
     (void)__fe_mask_env ();
a2cf7d
 
a2cf7d
-  fesetenv_register (*envp);
a2cf7d
+  fesetenv_register (new.fenv);
a2cf7d
 
a2cf7d
   /* Success.  */
a2cf7d
   return 0;