5de29b
From 2d5b6d3bb4813306ba5aa9ba03a56fe686bc6d4c Mon Sep 17 00:00:00 2001
5de29b
From: Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com>
5de29b
Date: Wed, 30 Jul 2014 05:05:19 -0500
5de29b
Subject: [PATCH] PowerPC: multirach memcmp for PowerPC64
5de29b
5de29b
commit 07253fcf7b03535b26c81ee216d284ed7f1e250b
5de29b
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
5de29b
Date:   Fri Dec 13 14:32:31 2013 -0500
5de29b
---
5de29b
 string/memcmp.c                                    |  6 +++-
5de29b
 sysdeps/powerpc/powerpc64/multiarch/Makefile       |  3 +-
5de29b
 .../powerpc/powerpc64/multiarch/ifunc-impl-list.c  |  8 +++++
5de29b
 .../powerpc/powerpc64/multiarch/memcmp-power4.S    | 41 ++++++++++++++++++++++
5de29b
 .../powerpc/powerpc64/multiarch/memcmp-power7.S    | 41 ++++++++++++++++++++++
5de29b
 sysdeps/powerpc/powerpc64/multiarch/memcmp-ppc64.c | 33 +++++++++++++++++
5de29b
 sysdeps/powerpc/powerpc64/multiarch/memcmp.c       | 39 ++++++++++++++++++++
5de29b
 7 files changed, 169 insertions(+), 2 deletions(-)
5de29b
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/memcmp-power4.S
5de29b
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/memcmp-power7.S
5de29b
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/memcmp-ppc64.c
5de29b
 create mode 100644 sysdeps/powerpc/powerpc64/multiarch/memcmp.c
5de29b
5de29b
diff --git a/string/memcmp.c b/string/memcmp.c
5de29b
index a73cc19..4a3ef58 100644
5de29b
--- a/string/memcmp.c
5de29b
+++ b/string/memcmp.c
5de29b
@@ -30,6 +30,10 @@
5de29b
 
5de29b
 #undef memcmp
5de29b
 
5de29b
+#ifndef MEMCMP
5de29b
+# define MEMCMP memcmp
5de29b
+#endif
5de29b
+
5de29b
 #ifdef _LIBC
5de29b
 
5de29b
 # include <memcopy.h>
5de29b
@@ -308,7 +312,7 @@ memcmp_not_common_alignment (srcp1, srcp2, len)
5de29b
 }
5de29b
 
5de29b
 int
5de29b
-memcmp (s1, s2, len)
5de29b
+MEMCMP (s1, s2, len)
5de29b
      const __ptr_t s1;
5de29b
      const __ptr_t s2;
5de29b
      size_t len;
5de29b
diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile
5de29b
index 638c102..c0bc520 100644
5de29b
--- a/sysdeps/powerpc/powerpc64/multiarch/Makefile
5de29b
+++ b/sysdeps/powerpc/powerpc64/multiarch/Makefile
5de29b
@@ -1,4 +1,5 @@
5de29b
 ifeq ($(subdir),string)
5de29b
 sysdep_routines += memcpy-power7 memcpy-a2 memcpy-power6 memcpy-cell \
5de29b
-                  memcpy-power4 memcpy-ppc64
5de29b
+                  memcpy-power4 memcpy-ppc64 memcmp-power7 memcmp-power4 \
5de29b
+                  memcmp-ppc64
5de29b
 endif
5de29b
diff --git a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
5de29b
index 5090af4..295ebca 100644
5de29b
--- a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
5de29b
+++ b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
5de29b
@@ -62,5 +62,13 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
5de29b
              IFUNC_IMPL_ADD (array, i, memcpy, 1, __memcpy_ppc))
5de29b
 #endif
5de29b
 
5de29b
+  /* Support sysdeps/powerpc/powerpc64/multiarch/memcmp.c.  */
5de29b
+  IFUNC_IMPL (i, name, memcmp,
5de29b
+             IFUNC_IMPL_ADD (array, i, memcmp, hwcap & PPC_FEATURE_HAS_VSX,
5de29b
+                             __memcmp_power7)
5de29b
+             IFUNC_IMPL_ADD (array, i, memcmp, hwcap & PPC_FEATURE_POWER4,
5de29b
+                             __memcmp_power4)
5de29b
+             IFUNC_IMPL_ADD (array, i, memcmp, 1, __memcmp_ppc))
5de29b
+
5de29b
   return i;
5de29b
 }
5de29b
diff --git a/sysdeps/powerpc/powerpc64/multiarch/memcmp-power4.S b/sysdeps/powerpc/powerpc64/multiarch/memcmp-power4.S
5de29b
new file mode 100644
5de29b
index 0000000..12db42c
5de29b
--- /dev/null
5de29b
+++ b/sysdeps/powerpc/powerpc64/multiarch/memcmp-power4.S
5de29b
@@ -0,0 +1,41 @@
5de29b
+/* Optimized memcmp implementation for PowerPC64/POWER4.
5de29b
+   Copyright (C) 2013-2014 Free Software Foundation, Inc.
5de29b
+   This file is part of the GNU C Library.
5de29b
+
5de29b
+   The GNU C Library is free software; you can redistribute it and/or
5de29b
+   modify it under the terms of the GNU Lesser General Public
5de29b
+   License as published by the Free Software Foundation; either
5de29b
+   version 2.1 of the License, or (at your option) any later version.
5de29b
+
5de29b
+   The GNU C Library is distributed in the hope that it will be useful,
5de29b
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
5de29b
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5de29b
+   Lesser General Public License for more details.
5de29b
+
5de29b
+   You should have received a copy of the GNU Lesser General Public
5de29b
+   License along with the GNU C Library; if not, see
5de29b
+   <http://www.gnu.org/licenses/>.  */
5de29b
+
5de29b
+#include <sysdep.h>
5de29b
+
5de29b
+#undef EALIGN
5de29b
+#define EALIGN(name, alignt, words)				\
5de29b
+  .section ".text";						\
5de29b
+  ENTRY_2(__memcmp_power4)					\
5de29b
+  .align ALIGNARG(alignt);					\
5de29b
+  EALIGN_W_##words;						\
5de29b
+  BODY_LABEL(__memcmp_power4):					\
5de29b
+  cfi_startproc;
5de29b
+
5de29b
+#undef END
5de29b
+#define END(name)						\
5de29b
+  cfi_endproc;							\
5de29b
+  TRACEBACK(__memcmp_power4)					\
5de29b
+  END_2(__memcmp_power4)
5de29b
+
5de29b
+#undef libc_hidden_builtin_def
5de29b
+#define libc_hidden_builtin_def(name)
5de29b
+#undef weak_alias
5de29b
+#define weak_alias(name,alias)
5de29b
+
5de29b
+#include <sysdeps/powerpc/powerpc64/power4/memcmp.S>
5de29b
diff --git a/sysdeps/powerpc/powerpc64/multiarch/memcmp-power7.S b/sysdeps/powerpc/powerpc64/multiarch/memcmp-power7.S
5de29b
new file mode 100644
5de29b
index 0000000..4898a88
5de29b
--- /dev/null
5de29b
+++ b/sysdeps/powerpc/powerpc64/multiarch/memcmp-power7.S
5de29b
@@ -0,0 +1,41 @@
5de29b
+/* Optimized memcmp implementation for PowerPC64/POWER7.
5de29b
+   Copyright (C) 2013-2014 Free Software Foundation, Inc.
5de29b
+   This file is part of the GNU C Library.
5de29b
+
5de29b
+   The GNU C Library is free software; you can redistribute it and/or
5de29b
+   modify it under the terms of the GNU Lesser General Public
5de29b
+   License as published by the Free Software Foundation; either
5de29b
+   version 2.1 of the License, or (at your option) any later version.
5de29b
+
5de29b
+   The GNU C Library is distributed in the hope that it will be useful,
5de29b
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
5de29b
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5de29b
+   Lesser General Public License for more details.
5de29b
+
5de29b
+   You should have received a copy of the GNU Lesser General Public
5de29b
+   License along with the GNU C Library; if not, see
5de29b
+   <http://www.gnu.org/licenses/>.  */
5de29b
+
5de29b
+#include <sysdep.h>
5de29b
+
5de29b
+#undef EALIGN
5de29b
+#define EALIGN(name, alignt, words)				\
5de29b
+  .section ".text";						\
5de29b
+  ENTRY_2(__memcmp_power7)					\
5de29b
+  .align ALIGNARG(alignt);					\
5de29b
+  EALIGN_W_##words;						\
5de29b
+  BODY_LABEL(__memcmp_power7):					\
5de29b
+  cfi_startproc;
5de29b
+
5de29b
+#undef END
5de29b
+#define END(name)						\
5de29b
+  cfi_endproc;							\
5de29b
+  TRACEBACK(__memcmp_power7)					\
5de29b
+  END_2(__memcmp_power7)
5de29b
+
5de29b
+#undef libc_hidden_builtin_def
5de29b
+#define libc_hidden_builtin_def(name)
5de29b
+#undef weak_alias
5de29b
+#define weak_alias(name,alias)
5de29b
+
5de29b
+#include <sysdeps/powerpc/powerpc64/power7/memcmp.S>
5de29b
diff --git a/sysdeps/powerpc/powerpc64/multiarch/memcmp-ppc64.c b/sysdeps/powerpc/powerpc64/multiarch/memcmp-ppc64.c
5de29b
new file mode 100644
5de29b
index 0000000..1a39d4a
5de29b
--- /dev/null
5de29b
+++ b/sysdeps/powerpc/powerpc64/multiarch/memcmp-ppc64.c
5de29b
@@ -0,0 +1,33 @@
5de29b
+/* Copyright (C) 2013-2014 Free Software Foundation, Inc.
5de29b
+   This file is part of the GNU C Library.
5de29b
+
5de29b
+   The GNU C Library is free software; you can redistribute it and/or
5de29b
+   modify it under the terms of the GNU Lesser General Public
5de29b
+   License as published by the Free Software Foundation; either
5de29b
+   version 2.1 of the License, or (at your option) any later version.
5de29b
+
5de29b
+   The GNU C Library is distributed in the hope that it will be useful,
5de29b
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
5de29b
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5de29b
+   Lesser General Public License for more details.
5de29b
+
5de29b
+   You should have received a copy of the GNU Lesser General Public
5de29b
+   License along with the GNU C Library; if not, see
5de29b
+   <http://www.gnu.org/licenses/>.  */
5de29b
+
5de29b
+#include <string.h>
5de29b
+
5de29b
+#define MEMCMP __memcmp_ppc
5de29b
+#undef weak_alias
5de29b
+#define weak_alias(name, aliasname) \
5de29b
+  extern __typeof (__memcmp_ppc) aliasname \
5de29b
+    __attribute__ ((weak, alias ("__memcmp_ppc")));
5de29b
+#if !defined(NOT_IN_libc) && defined(SHARED)
5de29b
+# undef libc_hidden_builtin_def
5de29b
+# define libc_hidden_builtin_def(name) \
5de29b
+  __hidden_ver1(__memcmp_ppc, __GI_memcmp, __memcmp_ppc);
5de29b
+#endif
5de29b
+
5de29b
+extern __typeof (memcmp) __memcmp_ppc attribute_hidden;
5de29b
+
5de29b
+#include <string/memcmp.c>
5de29b
diff --git a/sysdeps/powerpc/powerpc64/multiarch/memcmp.c b/sysdeps/powerpc/powerpc64/multiarch/memcmp.c
5de29b
new file mode 100644
5de29b
index 0000000..af90f0a
5de29b
--- /dev/null
5de29b
+++ b/sysdeps/powerpc/powerpc64/multiarch/memcmp.c
5de29b
@@ -0,0 +1,39 @@
5de29b
+/* Multiple versions of memcmp. PowerPC64 version.
5de29b
+   Copyright (C) 2013-2014 Free Software Foundation, Inc.
5de29b
+   This file is part of the GNU C Library.
5de29b
+
5de29b
+   The GNU C Library is free software; you can redistribute it and/or
5de29b
+   modify it under the terms of the GNU Lesser General Public
5de29b
+   License as published by the Free Software Foundation; either
5de29b
+   version 2.1 of the License, or (at your option) any later version.
5de29b
+
5de29b
+   The GNU C Library is distributed in the hope that it will be useful,
5de29b
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
5de29b
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5de29b
+   Lesser General Public License for more details.
5de29b
+
5de29b
+   You should have received a copy of the GNU Lesser General Public
5de29b
+   License along with the GNU C Library; if not, see
5de29b
+   <http://www.gnu.org/licenses/>.  */
5de29b
+
5de29b
+/* Define multiple versions only for definition in libc.  */
5de29b
+#ifndef NOT_IN_libc
5de29b
+# include <string.h>
5de29b
+# include <shlib-compat.h>
5de29b
+# include "init-arch.h"
5de29b
+
5de29b
+extern __typeof (memcmp) __memcmp_ppc attribute_hidden;
5de29b
+extern __typeof (memcmp) __memcmp_power4 attribute_hidden;
5de29b
+extern __typeof (memcmp) __memcmp_power7 attribute_hidden;
5de29b
+
5de29b
+/* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle
5de29b
+   ifunc symbol properly.  */
5de29b
+libc_ifunc (memcmp,
5de29b
+            (hwcap & PPC_FEATURE_HAS_VSX)
5de29b
+            ? __memcmp_power7 :
5de29b
+	      (hwcap & PPC_FEATURE_POWER4)
5de29b
+		? __memcmp_power4
5de29b
+            : __memcmp_ppc);
5de29b
+#else
5de29b
+#include <string/memcmp.c>
5de29b
+#endif
5de29b
-- 
5de29b
1.8.3.1
5de29b