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