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