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