00db10
From 2d5b6d3bb4813306ba5aa9ba03a56fe686bc6d4c Mon Sep 17 00:00:00 2001
00db10
From: Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
00db10
Date: Wed, 30 Jul 2014 05:05:19 -0500
00db10
Subject: [PATCH] PowerPC: multirach memcmp for PowerPC64
00db10
00db10
commit 07253fcf7b03535b26c81ee216d284ed7f1e250b
00db10
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
00db10
Date:   Fri Dec 13 14:32:31 2013 -0500
00db10
---
00db10
 string/memcmp.c                                    |  6 +++-
00db10
 sysdeps/powerpc/powerpc64/multiarch/Makefile       |  3 +-
00db10
 .../powerpc/powerpc64/multiarch/ifunc-impl-list.c  |  8 +++++
00db10
 .../powerpc/powerpc64/multiarch/memcmp-power4.S    | 41 ++++++++++++++++++++++
00db10
 .../powerpc/powerpc64/multiarch/memcmp-power7.S    | 41 ++++++++++++++++++++++
00db10
 sysdeps/powerpc/powerpc64/multiarch/memcmp-ppc64.c | 33 +++++++++++++++++
00db10
 sysdeps/powerpc/powerpc64/multiarch/memcmp.c       | 39 ++++++++++++++++++++
00db10
 7 files changed, 169 insertions(+), 2 deletions(-)
00db10
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/memcmp-power4.S
00db10
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/memcmp-power7.S
00db10
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/memcmp-ppc64.c
00db10
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/memcmp.c
00db10
00db10
diff --git glibc-2.17-c758a686/string/memcmp.c glibc-2.17-c758a686/string/memcmp.c
00db10
index a73cc19..4a3ef58 100644
00db10
--- glibc-2.17-c758a686/string/memcmp.c
00db10
+++ glibc-2.17-c758a686/string/memcmp.c
00db10
@@ -30,6 +30,10 @@
00db10
 
00db10
 #undef memcmp
00db10
 
00db10
+#ifndef MEMCMP
00db10
+# define MEMCMP memcmp
00db10
+#endif
00db10
+
00db10
 #ifdef _LIBC
00db10
 
00db10
 # include <memcopy.h>
00db10
@@ -308,7 +312,7 @@ memcmp_not_common_alignment (srcp1, srcp2, len)
00db10
 }
00db10
 
00db10
 int
00db10
-memcmp (s1, s2, len)
00db10
+MEMCMP (s1, s2, len)
00db10
      const __ptr_t s1;
00db10
      const __ptr_t s2;
00db10
      size_t len;
00db10
diff --git glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/Makefile glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/Makefile
00db10
index 638c102..c0bc520 100644
00db10
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/Makefile
00db10
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/Makefile
00db10
@@ -1,4 +1,5 @@
00db10
 ifeq ($(subdir),string)
00db10
 sysdep_routines += memcpy-power7 memcpy-a2 memcpy-power6 memcpy-cell \
00db10
-                  memcpy-power4 memcpy-ppc64
00db10
+                  memcpy-power4 memcpy-ppc64 memcmp-power7 memcmp-power4 \
00db10
+                  memcmp-ppc64
00db10
 endif
00db10
diff --git glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
00db10
index 5090af4..295ebca 100644
00db10
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
00db10
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
00db10
@@ -62,5 +62,13 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
00db10
              IFUNC_IMPL_ADD (array, i, memcpy, 1, __memcpy_ppc))
00db10
 #endif
00db10
 
00db10
+  /* Support sysdeps/powerpc/powerpc64/multiarch/memcmp.c.  */
00db10
+  IFUNC_IMPL (i, name, memcmp,
00db10
+             IFUNC_IMPL_ADD (array, i, memcmp, hwcap & PPC_FEATURE_HAS_VSX,
00db10
+                             __memcmp_power7)
00db10
+             IFUNC_IMPL_ADD (array, i, memcmp, hwcap & PPC_FEATURE_POWER4,
00db10
+                             __memcmp_power4)
00db10
+             IFUNC_IMPL_ADD (array, i, memcmp, 1, __memcmp_ppc))
00db10
+
00db10
   return i;
00db10
 }
00db10
diff --git glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/memcmp-power4.S glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/memcmp-power4.S
00db10
new file mode 100644
00db10
index 0000000..12db42c
00db10
--- /dev/null
00db10
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/memcmp-power4.S
00db10
@@ -0,0 +1,41 @@
00db10
+/* Optimized memcmp implementation for PowerPC64/POWER4.
00db10
+   Copyright (C) 2013-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
+
00db10
+#undef EALIGN
00db10
+#define EALIGN(name, alignt, words)				\
00db10
+  .section ".text";						\
00db10
+  ENTRY_2(__memcmp_power4)					\
00db10
+  .align ALIGNARG(alignt);					\
00db10
+  EALIGN_W_##words;						\
00db10
+  BODY_LABEL(__memcmp_power4):					\
00db10
+  cfi_startproc;
00db10
+
00db10
+#undef END
00db10
+#define END(name)						\
00db10
+  cfi_endproc;							\
00db10
+  TRACEBACK(__memcmp_power4)					\
00db10
+  END_2(__memcmp_power4)
00db10
+
00db10
+#undef libc_hidden_builtin_def
00db10
+#define libc_hidden_builtin_def(name)
00db10
+#undef weak_alias
00db10
+#define weak_alias(name,alias)
00db10
+
00db10
+#include <sysdeps/powerpc/powerpc64/power4/memcmp.S>
00db10
diff --git glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/memcmp-power7.S glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/memcmp-power7.S
00db10
new file mode 100644
00db10
index 0000000..4898a88
00db10
--- /dev/null
00db10
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/memcmp-power7.S
00db10
@@ -0,0 +1,41 @@
00db10
+/* Optimized memcmp implementation for PowerPC64/POWER7.
00db10
+   Copyright (C) 2013-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
+
00db10
+#undef EALIGN
00db10
+#define EALIGN(name, alignt, words)				\
00db10
+  .section ".text";						\
00db10
+  ENTRY_2(__memcmp_power7)					\
00db10
+  .align ALIGNARG(alignt);					\
00db10
+  EALIGN_W_##words;						\
00db10
+  BODY_LABEL(__memcmp_power7):					\
00db10
+  cfi_startproc;
00db10
+
00db10
+#undef END
00db10
+#define END(name)						\
00db10
+  cfi_endproc;							\
00db10
+  TRACEBACK(__memcmp_power7)					\
00db10
+  END_2(__memcmp_power7)
00db10
+
00db10
+#undef libc_hidden_builtin_def
00db10
+#define libc_hidden_builtin_def(name)
00db10
+#undef weak_alias
00db10
+#define weak_alias(name,alias)
00db10
+
00db10
+#include <sysdeps/powerpc/powerpc64/power7/memcmp.S>
00db10
diff --git glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/memcmp-ppc64.c glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/memcmp-ppc64.c
00db10
new file mode 100644
00db10
index 0000000..1a39d4a
00db10
--- /dev/null
00db10
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/memcmp-ppc64.c
00db10
@@ -0,0 +1,33 @@
00db10
+/* Copyright (C) 2013-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 <string.h>
00db10
+
00db10
+#define MEMCMP __memcmp_ppc
00db10
+#undef weak_alias
00db10
+#define weak_alias(name, aliasname) \
00db10
+  extern __typeof (__memcmp_ppc) aliasname \
00db10
+    __attribute__ ((weak, alias ("__memcmp_ppc")));
00db10
+#if !defined(NOT_IN_libc) && defined(SHARED)
00db10
+# undef libc_hidden_builtin_def
00db10
+# define libc_hidden_builtin_def(name) \
00db10
+  __hidden_ver1(__memcmp_ppc, __GI_memcmp, __memcmp_ppc);
00db10
+#endif
00db10
+
00db10
+extern __typeof (memcmp) __memcmp_ppc attribute_hidden;
00db10
+
00db10
+#include <string/memcmp.c>
00db10
diff --git glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/memcmp.c glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/memcmp.c
00db10
new file mode 100644
00db10
index 0000000..af90f0a
00db10
--- /dev/null
00db10
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/multiarch/memcmp.c
00db10
@@ -0,0 +1,39 @@
00db10
+/* Multiple versions of memcmp. PowerPC64 version.
00db10
+   Copyright (C) 2013-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
+/* Define multiple versions only for definition in libc.  */
00db10
+#ifndef NOT_IN_libc
00db10
+# include <string.h>
00db10
+# include <shlib-compat.h>
00db10
+# include "init-arch.h"
00db10
+
00db10
+extern __typeof (memcmp) __memcmp_ppc attribute_hidden;
00db10
+extern __typeof (memcmp) __memcmp_power4 attribute_hidden;
00db10
+extern __typeof (memcmp) __memcmp_power7 attribute_hidden;
00db10
+
00db10
+/* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle
00db10
+   ifunc symbol properly.  */
00db10
+libc_ifunc (memcmp,
00db10
+            (hwcap & PPC_FEATURE_HAS_VSX)
00db10
+            ? __memcmp_power7 :
00db10
+	      (hwcap & PPC_FEATURE_POWER4)
00db10
+		? __memcmp_power4
00db10
+            : __memcmp_ppc);
00db10
+#else
00db10
+#include <string/memcmp.c>
00db10
+#endif
00db10
-- 
00db10
1.8.3.1
00db10