a2cf7d
commit de751ebc9efa97ce0115e42bd55fa1beeb614380
a2cf7d
Author: Paul A. Clarke <pc@us.ibm.com>
a2cf7d
Date:   Fri Mar 15 19:04:24 2019 -0400
a2cf7d
a2cf7d
    [powerpc] get_rounding_mode: utilize faster method to get rounding mode
a2cf7d
    
a2cf7d
    Add support to use 'mffsl' instruction if compiled for POWER9 (or later).
a2cf7d
    
a2cf7d
    Also, mask the result to avoid bleeding unrelated bits into the result of
a2cf7d
    _FPU_GET_RC().
a2cf7d
    
a2cf7d
    Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
a2cf7d
a2cf7d
diff --git a/sysdeps/powerpc/fpu/get-rounding-mode.h b/sysdeps/powerpc/fpu/get-rounding-mode.h
a2cf7d
new file mode 100644
a2cf7d
index 0000000000000000..e2fdbbbcce72bd66
a2cf7d
--- /dev/null
a2cf7d
+++ b/sysdeps/powerpc/fpu/get-rounding-mode.h
a2cf7d
@@ -0,0 +1,33 @@
a2cf7d
+/* Determine floating-point rounding mode within libc.  powerpc64 version.
a2cf7d
+   Copyright (C) 2019 Free Software Foundation, Inc.
a2cf7d
+   This file is part of the GNU C Library.
a2cf7d
+
a2cf7d
+   The GNU C Library is free software; you can redistribute it and/or
a2cf7d
+   modify it under the terms of the GNU Lesser General Public
a2cf7d
+   License as published by the Free Software Foundation; either
a2cf7d
+   version 2.1 of the License, or (at your option) any later version.
a2cf7d
+
a2cf7d
+   The GNU C Library is distributed in the hope that it will be useful,
a2cf7d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
a2cf7d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a2cf7d
+   Lesser General Public License for more details.
a2cf7d
+
a2cf7d
+   You should have received a copy of the GNU Lesser General Public
a2cf7d
+   License along with the GNU C Library; if not, see
a2cf7d
+   <http://www.gnu.org/licenses/>.  */
a2cf7d
+
a2cf7d
+#ifndef _POWERPC64_GET_ROUNDING_MODE_H
a2cf7d
+#define _POWERPC64_GET_ROUNDING_MODE_H	1
a2cf7d
+
a2cf7d
+#include <fenv.h>
a2cf7d
+#include <fpu_control.h>
a2cf7d
+
a2cf7d
+/* Return the floating-point rounding mode.  */
a2cf7d
+
a2cf7d
+static inline int
a2cf7d
+get_rounding_mode (void)
a2cf7d
+{
a2cf7d
+  return _FPU_GET_RC ();
a2cf7d
+}
a2cf7d
+
a2cf7d
+#endif /* get-rounding-mode.h */
a2cf7d
diff --git a/sysdeps/powerpc/fpu_control.h b/sysdeps/powerpc/fpu_control.h
a2cf7d
index 9d0698b4fc3eb595..62c478d72ae660cb 100644
a2cf7d
--- a/sysdeps/powerpc/fpu_control.h
a2cf7d
+++ b/sysdeps/powerpc/fpu_control.h
a2cf7d
@@ -71,6 +71,8 @@ extern fpu_control_t __fpu_control;
a2cf7d
 # define _FPU_RC_UP      0x02
a2cf7d
 # define _FPU_RC_ZERO    0x01
a2cf7d
 
a2cf7d
+# define _FPU_MASK_RC (_FPU_RC_NEAREST|_FPU_RC_DOWN|_FPU_RC_UP|_FPU_RC_ZERO)
a2cf7d
+
a2cf7d
 # define _FPU_MASK_NI  0x04 /* non-ieee mode */
a2cf7d
 
a2cf7d
 /* masking of interrupts */
a2cf7d
@@ -94,15 +96,36 @@ extern fpu_control_t __fpu_control;
a2cf7d
 typedef unsigned int fpu_control_t;
a2cf7d
 
a2cf7d
 /* Macros for accessing the hardware control word.  */
a2cf7d
+# define __FPU_MFFS()						\
a2cf7d
+  ({register double __fr;					\
a2cf7d
+    __asm__ ("mffs %0" : "=f" (__fr));				\
a2cf7d
+    __fr;							\
a2cf7d
+  })
a2cf7d
+
a2cf7d
 # define _FPU_GETCW(cw)						\
a2cf7d
   ({union { double __d; unsigned long long __ll; } __u;		\
a2cf7d
-    register double __fr;					\
a2cf7d
-    __asm__ ("mffs %0" : "=f" (__fr));				\
a2cf7d
-    __u.__d = __fr;						\
a2cf7d
+    __u.__d = __FPU_MFFS();					\
a2cf7d
     (cw) = (fpu_control_t) __u.__ll;				\
a2cf7d
     (fpu_control_t) __u.__ll;					\
a2cf7d
   })
a2cf7d
 
a2cf7d
+#ifdef _ARCH_PWR9
a2cf7d
+# define __FPU_MFFSL()						\
a2cf7d
+  ({register double __fr;					\
a2cf7d
+    __asm__ ("mffsl %0" : "=f" (__fr));				\
a2cf7d
+    __fr;							\
a2cf7d
+  })
a2cf7d
+#else
a2cf7d
+# define __FPU_MFFSL() __FPU_MFFS()
a2cf7d
+#endif
a2cf7d
+    
a2cf7d
+# define _FPU_GET_RC()						\
a2cf7d
+  ({union { double __d; unsigned long long __ll; } __u;		\
a2cf7d
+    __u.__d = __FPU_MFFSL();					\
a2cf7d
+    __u.__ll &= _FPU_MASK_RC;					\
a2cf7d
+    (fpu_control_t) __u.__ll;					\
a2cf7d
+  })
a2cf7d
+
a2cf7d
 # define _FPU_SETCW(cw)						\
a2cf7d
   { union { double __d; unsigned long long __ll; } __u;		\
a2cf7d
     register double __fr;					\