7c0489
commit e68b1151f7460d5fa88c3a567c13f66052da79a7
7c0489
Author: Paul A. Clarke <pc@us.ibm.com>
7c0489
Date:   Thu Sep 19 11:39:44 2019 -0500
7c0489
7c0489
    [powerpc] __fesetround_inline optimizations
7c0489
    
7c0489
    On POWER9, use more efficient means to update the 2-bit rounding mode
7c0489
    via the 'mffscrn' instruction (instead of two 'mtfsb0/1' instructions
7c0489
    or one 'mtfsfi' instruction that modifies 4 bits).
7c0489
    
7c0489
    Suggested-by: Paul E. Murphy  <murphyp@linux.ibm.com>
7c0489
    Reviewed-By: Paul E Murphy <murphyp@linux.ibm.com>
7c0489
7c0489
diff --git a/sysdeps/powerpc/fpu/fenv_libc.h b/sysdeps/powerpc/fpu/fenv_libc.h
7c0489
index 86ae7fda016abd8b..c3f541c08440b20e 100644
7c0489
--- a/sysdeps/powerpc/fpu/fenv_libc.h
7c0489
+++ b/sysdeps/powerpc/fpu/fenv_libc.h
7c0489
@@ -149,7 +149,12 @@ typedef union
7c0489
 static inline int
7c0489
 __fesetround_inline (int round)
7c0489
 {
7c0489
-  if ((unsigned int) round < 2)
7c0489
+#ifdef _ARCH_PWR9
7c0489
+  __fe_mffscrn (round);
7c0489
+#else
7c0489
+  if (__glibc_likely (GLRO(dl_hwcap2) & PPC_FEATURE2_ARCH_3_00))
7c0489
+    __fe_mffscrn (round);
7c0489
+  else if ((unsigned int) round < 2)
7c0489
     {
7c0489
        asm volatile ("mtfsb0 30");
7c0489
        if ((unsigned int) round == 0)
7c0489
@@ -165,7 +170,7 @@ __fesetround_inline (int round)
7c0489
        else
7c0489
          asm volatile ("mtfsb1 31");
7c0489
     }
7c0489
-
7c0489
+#endif
7c0489
   return 0;
7c0489
 }
7c0489
 
7c0489
@@ -174,7 +179,14 @@ __fesetround_inline (int round)
7c0489
 static inline void
7c0489
 __fesetround_inline_nocheck (const int round)
7c0489
 {
7c0489
-  asm volatile ("mtfsfi 7,%0" : : "i" (round));
7c0489
+#ifdef _ARCH_PWR9
7c0489
+  __fe_mffscrn (round);
7c0489
+#else
7c0489
+  if (__glibc_likely (GLRO(dl_hwcap2) & PPC_FEATURE2_ARCH_3_00))
7c0489
+    __fe_mffscrn (round);
7c0489
+  else
7c0489
+    asm volatile ("mtfsfi 7,%0" : : "i" (round));
7c0489
+#endif
7c0489
 }
7c0489
 
7c0489
 #define FPSCR_MASK(bit) (1 << (31 - (bit)))