ce426f
    Backport of:
ce426f
    commit 487972aea52004f604c2878c8c9d3e77670f2c32
ce426f
    Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
ce426f
    Date:   Thu Feb 27 09:43:51 2014 -0600
ce426f
    
ce426f
        PowerPC: Optimized isnan/isnanf for POWER8
ce426f
    
ce426f
        This patch add a optimized isnan/isnanf implementation for POWER8
ce426f
        using the new Move From VSR Doubleword instruction to gains some
ce426f
        cycles from FP to GRP register move.
ce426f
    
ce426f
        ChangeLog:
ce426f
    	2014-02-27  Adhemerval Zanella  <azanella@linux.vnet.ibm.com>
ce426f
    
ce426f
    	* sysdeps/powerpc/powerpc32/power4/multiarch/init-arch.h (INIT_ARCH):
ce426f
    	Add hwcap2 initialization.
ce426f
    	* sysdeps/powerpc/powerpc64/fpu/multiarch/Makefile: Add isnan power8
ce426f
    	implementation.
ce426f
    	* sysdeps/powerpc/powerpc64/fpu/multiarch/s_isnan-power8.S: New file:
ce426f
    	POWER8 isnan ifunc implementation.
ce426f
    	* sysdeps/powerpc/powerpc64/fpu/multiarch/s_isnan.c (__isnan): Add
ce426f
    	POWER8 implementation.
ce426f
    	* sysdeps/powerpc/powerpc64/fpu/multiarch/s_isnanf.c (__isnanf):
ce426f
    	Likewise.
ce426f
    	* sysdeps/powerpc/powerpc64/power8/fpu/s_isnan.S: New file:
ce426f
    	POWER8 isnan implementation.
ce426f
    	* sysdeps/powerpc/powerpc64/power8/fpu/s_isnanf.S: New file.
ce426f
ce426f
diff --git a/sysdeps/powerpc/powerpc32/power4/multiarch/init-arch.h b/sysdeps/powerpc/powerpc32/power4/multiarch/init-arch.h
ce426f
index 51a34f2..72d720d 100644
ce426f
--- a/sysdeps/powerpc/powerpc32/power4/multiarch/init-arch.h
ce426f
+++ b/sysdeps/powerpc/powerpc32/power4/multiarch/init-arch.h
ce426f
@@ -36,6 +36,7 @@
ce426f
    and fills the previous ones.  */
ce426f
 #define INIT_ARCH() \
ce426f
   unsigned long int hwcap = __GLRO(dl_hwcap); 			\
ce426f
+  unsigned long int __attribute__((unused)) hwcap2 = __GLRO(dl_hwcap2); \
ce426f
   if (hwcap & PPC_FEATURE_ARCH_2_06)				\
ce426f
     hwcap |= PPC_FEATURE_ARCH_2_05 |				\
ce426f
 	     PPC_FEATURE_POWER5_PLUS |				\
ce426f
diff --git a/sysdeps/powerpc/powerpc64/fpu/multiarch/Makefile b/sysdeps/powerpc/powerpc64/fpu/multiarch/Makefile
ce426f
index 1e04f21..4cd1c5d 100644
ce426f
--- a/sysdeps/powerpc/powerpc64/fpu/multiarch/Makefile
ce426f
+++ b/sysdeps/powerpc/powerpc64/fpu/multiarch/Makefile
ce426f
@@ -4,7 +4,7 @@ sysdep_routines += s_isnan-power7 s_isnan-power6x s_isnan-power6 \
ce426f
                   s_copysign-ppc64 s_finite-power7 s_finite-ppc64 \
ce426f
                   s_finitef-ppc64 s_isinff-ppc64 s_isinf-power7 \
ce426f
                   s_isinf-ppc64 s_modf-power5+ s_modf-ppc64 \
ce426f
-                  s_modff-power5+ s_modff-ppc64
ce426f
+                  s_modff-power5+ s_modff-ppc64 s_isnan-power8
ce426f
 
ce426f
 libm-sysdep_routines += s_isnan-power7 s_isnan-power6x s_isnan-power6 \
ce426f
                        s_isnan-power5 s_isnan-ppc64 s_llround-power6x \
ce426f
@@ -21,7 +21,8 @@ libm-sysdep_routines += s_isnan-power7 s_isnan-power6x s_isnan-power6 \
ce426f
                        s_logbl-power7 s_logb-ppc64 s_logbf-ppc64 \
ce426f
                        s_logbl-ppc64 s_modf-power5+ s_modf-ppc64 \
ce426f
                        s_modff-power5+ s_modff-ppc64 e_hypot-ppc64 \
ce426f
-                       e_hypot-power7 e_hypotf-ppc64 e_hypotf-power7
ce426f
+                       e_hypot-power7 e_hypotf-ppc64 e_hypotf-power7 \
ce426f
+                       s_isnan-power8
ce426f
 
ce426f
 CFLAGS-s_logbf-power7.c = -mcpu=power7
ce426f
 CFLAGS-s_logbl-power7.c = -mcpu=power7
ce426f
diff --git a/sysdeps/powerpc/powerpc64/fpu/multiarch/s_isnan-power8.S b/sysdeps/powerpc/powerpc64/fpu/multiarch/s_isnan-power8.S
ce426f
new file mode 100644
ce426f
index 0000000..c176d5a
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/powerpc/powerpc64/fpu/multiarch/s_isnan-power8.S
ce426f
@@ -0,0 +1,33 @@
ce426f
+/* isnan().  PowerPC64/POWER7 version.
ce426f
+   Copyright (C) 2014 Free Software Foundation, Inc.
ce426f
+   This file is part of the GNU C Library.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library; if not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+#include <sysdep.h>
ce426f
+#include <math_ldbl_opt.h>
ce426f
+
ce426f
+#undef hidden_def
ce426f
+#define hidden_def(name)
ce426f
+#undef weak_alias
ce426f
+#define weak_alias(name, alias)
ce426f
+#undef strong_alias
ce426f
+#define strong_alias(name, alias)
ce426f
+#undef compat_symbol
ce426f
+#define compat_symbol(lib, name, symbol, ver)
ce426f
+
ce426f
+#define __isnan __isnan_power8
ce426f
+
ce426f
+#include <sysdeps/powerpc/powerpc64/power8/fpu/s_isnan.S>
ce426f
diff --git a/sysdeps/powerpc/powerpc64/fpu/multiarch/s_isnan.c b/sysdeps/powerpc/powerpc64/fpu/multiarch/s_isnan.c
ce426f
index 0de833e..65a5ca0 100644
ce426f
--- a/sysdeps/powerpc/powerpc64/fpu/multiarch/s_isnan.c
ce426f
+++ b/sysdeps/powerpc/powerpc64/fpu/multiarch/s_isnan.c
ce426f
@@ -26,16 +26,19 @@ extern __typeof (__isnan) __isnan_power5 attribute_hidden;
ce426f
 extern __typeof (__isnan) __isnan_power6 attribute_hidden;
ce426f
 extern __typeof (__isnan) __isnan_power6x attribute_hidden;
ce426f
 extern __typeof (__isnan) __isnan_power7 attribute_hidden;
ce426f
+extern __typeof (__isnan) __isnan_power8 attribute_hidden;
ce426f
 
ce426f
 libc_ifunc (__isnan,
ce426f
-	    (hwcap & PPC_FEATURE_ARCH_2_06)
ce426f
-	    ? __isnan_power7 :
ce426f
-	      (hwcap & PPC_FEATURE_POWER6_EXT)
ce426f
+	    (hwcap2 & PPC_FEATURE2_ARCH_2_07)
ce426f
+	    ? __isnan_power8 :
ce426f
+	      (hwcap & PPC_FEATURE_ARCH_2_06)
ce426f
+	      ? __isnan_power7 :
ce426f
+		(hwcap & PPC_FEATURE_POWER6_EXT)
ce426f
 		? __isnan_power6x :
ce426f
-		(hwcap & PPC_FEATURE_ARCH_2_05)
ce426f
-		  ? __isnan_power6 :
ce426f
-		  (hwcap & PPC_FEATURE_POWER5)
ce426f
-		    ? __isnan_power5
ce426f
+		  (hwcap & PPC_FEATURE_ARCH_2_05)
ce426f
+		    ? __isnan_power6 :
ce426f
+		    (hwcap & PPC_FEATURE_POWER5)
ce426f
+		      ? __isnan_power5
ce426f
             : __isnan_ppc64);
ce426f
 
ce426f
 weak_alias (__isnan, isnan)
ce426f
diff --git a/sysdeps/powerpc/powerpc64/fpu/multiarch/s_isnanf.c b/sysdeps/powerpc/powerpc64/fpu/multiarch/s_isnanf.c
ce426f
index b237455..eb68a50 100644
ce426f
--- a/sysdeps/powerpc/powerpc64/fpu/multiarch/s_isnanf.c
ce426f
+++ b/sysdeps/powerpc/powerpc64/fpu/multiarch/s_isnanf.c
ce426f
@@ -25,16 +25,19 @@ extern __typeof (__isnanf) __isnan_power5 attribute_hidden;
ce426f
 extern __typeof (__isnanf) __isnan_power6 attribute_hidden;
ce426f
 extern __typeof (__isnanf) __isnan_power6x attribute_hidden;
ce426f
 extern __typeof (__isnanf) __isnan_power7 attribute_hidden;
ce426f
+extern __typeof (__isnanf) __isnan_power8 attribute_hidden;
ce426f
 
ce426f
 libc_ifunc (__isnanf,
ce426f
-	    (hwcap & PPC_FEATURE_ARCH_2_06)
ce426f
-	    ? __isnan_power7 :
ce426f
-	      (hwcap & PPC_FEATURE_POWER6_EXT)
ce426f
-		? __isnan_power6x :
ce426f
-		(hwcap & PPC_FEATURE_ARCH_2_05)
ce426f
-		  ? __isnan_power6 :
ce426f
-		  (hwcap & PPC_FEATURE_POWER5)
ce426f
-		    ? __isnan_power5
ce426f
+	    (hwcap2 & PPC_FEATURE2_ARCH_2_07)
ce426f
+	    ? __isnan_power8 :
ce426f
+	      (hwcap & PPC_FEATURE_ARCH_2_06)
ce426f
+	      ? __isnan_power7 :
ce426f
+		(hwcap & PPC_FEATURE_POWER6_EXT)
ce426f
+		  ? __isnan_power6x :
ce426f
+		  (hwcap & PPC_FEATURE_ARCH_2_05)
ce426f
+		    ? __isnan_power6 :
ce426f
+		    (hwcap & PPC_FEATURE_POWER5)
ce426f
+		      ? __isnan_power5
ce426f
             : __isnan_ppc64);
ce426f
 
ce426f
 weak_alias (__isnanf, isnanf)
ce426f
diff --git a/sysdeps/powerpc/powerpc64/power8/fpu/s_isnan.S b/sysdeps/powerpc/powerpc64/power8/fpu/s_isnan.S
ce426f
new file mode 100644
ce426f
index 0000000..c1ca9a5
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/powerpc/powerpc64/power8/fpu/s_isnan.S
ce426f
@@ -0,0 +1,53 @@
ce426f
+/* isnan().  PowerPC64/POWER8 version.
ce426f
+   Copyright (C) 2014 Free Software Foundation, Inc.
ce426f
+   This file is part of the GNU C Library.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library; if not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+#include <sysdep.h>
ce426f
+#include <math_ldbl_opt.h>
ce426f
+
ce426f
+#define MFVSRD_R3_V1  .byte 0x7c,0x23,0x00,0x66     /* mfvsrd  r3,vs1  */
ce426f
+
ce426f
+/* int [r3] __isnan([f1] x)  */
ce426f
+
ce426f
+EALIGN (__isnan, 4, 0)
ce426f
+	CALL_MCOUNT 0
ce426f
+	MFVSRD_R3_V1
ce426f
+	lis     r9,0x7ff0
ce426f
+	clrldi  r3,r3,1       /* r3 = r3 & 0x8000000000000000  */
ce426f
+	rldicr  r9,r9,32,31   /* r9 = (r9 << 32) & 0xffffffff  */
ce426f
+	subf    r3,r3,r9
ce426f
+	rldicl  r3,r3,1,63
ce426f
+	blr
ce426f
+END (__isnan)
ce426f
+
ce426f
+/* It turns out that the 'double' version will also always work for
ce426f
+   single-precision.  */
ce426f
+strong_alias (__isnan, __isnanf)
ce426f
+hidden_def (__isnanf)
ce426f
+weak_alias (__isnanf, isnanf)
ce426f
+
ce426f
+#ifdef NO_LONG_DOUBLE
ce426f
+strong_alias (__isnan, __isnanl)
ce426f
+weak_alias (__isnan, isnanl)
ce426f
+#endif
ce426f
+
ce426f
+#ifndef IS_IN_libm
ce426f
+# if LONG_DOUBLE_COMPAT(libc, GLIBC_2_0)
ce426f
+compat_symbol (libc, __isnan, __isnanl, GLIBC_2_0);
ce426f
+compat_symbol (libc, isnan, isnanl, GLIBC_2_0);
ce426f
+# endif
ce426f
+#endif
ce426f
diff --git a/sysdeps/powerpc/powerpc64/power8/fpu/s_isnanf.S b/sysdeps/powerpc/powerpc64/power8/fpu/s_isnanf.S
ce426f
new file mode 100644
ce426f
index 0000000..b48c85e
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/powerpc/powerpc64/power8/fpu/s_isnanf.S
ce426f
@@ -0,0 +1 @@
ce426f
+/* This function uses the same code as s_isnan.S.  */