[07/20] libcpu-rt-c/x86-64: Add memrchr

Message ID 20180612221939.19545-8-hjl.tools@gmail.com
State New
Headers show
Series
  • RFC: Add the CPU run-time library for C
Related show

Commit Message

H.J. Lu June 12, 2018, 10:19 p.m.
* sysdeps/x86_64/Makefile (cpu-rt-c-routines): Add memrchr.
	* sysdeps/x86_64/memrchr.S: Support libcpu-rt-c.
	* sysdeps/x86_64/multiarch/memrchr-avx2.S: Likewise.
	* sysdeps/x86_64/multiarch/memrchr-sse2.S: Likewise.
	* sysdeps/x86_64/multiarch/memrchr.c: Likewise.
	* sysdeps/x86_64/multiarch/Makefile
	(libcpu-rt-c-sysdep_routines): Add memrchr-sse2 and
	memrchr-avx2.
---
 sysdeps/x86_64/Makefile                 | 2 +-
 sysdeps/x86_64/memrchr.S                | 6 ++++++
 sysdeps/x86_64/multiarch/Makefile       | 3 ++-
 sysdeps/x86_64/multiarch/memrchr-avx2.S | 2 +-
 sysdeps/x86_64/multiarch/memrchr-sse2.S | 2 +-
 sysdeps/x86_64/multiarch/memrchr.c      | 8 +++++++-
 6 files changed, 18 insertions(+), 5 deletions(-)

Patch

diff --git a/sysdeps/x86_64/Makefile b/sysdeps/x86_64/Makefile
index 978cff6cba..da3264f27f 100644
--- a/sysdeps/x86_64/Makefile
+++ b/sysdeps/x86_64/Makefile
@@ -147,7 +147,7 @@  endif
 endif
 
 ifeq ($(subdir),cpu-rt-c)
-cpu-rt-c-routines += memchr memcmp memcpy memmove mempcpy
+cpu-rt-c-routines += memchr memcmp memcpy memmove mempcpy memrchr
 
 # For the CPU run-time tests.
 vpath %.c $(..)string
diff --git a/sysdeps/x86_64/memrchr.S b/sysdeps/x86_64/memrchr.S
index b8e3fa1d87..1488225145 100644
--- a/sysdeps/x86_64/memrchr.S
+++ b/sysdeps/x86_64/memrchr.S
@@ -20,6 +20,10 @@ 
 
 #include <sysdep.h>
 
+#if !defined __memrchr && IS_IN (libcpu_rt_c)
+# define __memrchr	memrchr
+#endif
+
 	.text
 ENTRY (__memrchr)
 	movd	%esi, %xmm1
@@ -377,4 +381,6 @@  L(length_less16_part2_return):
 	ret
 
 END (__memrchr)
+#if !IS_IN (libcpu_rt_c)
 weak_alias (__memrchr, memrchr)
+#endif
diff --git a/sysdeps/x86_64/multiarch/Makefile b/sysdeps/x86_64/multiarch/Makefile
index 8e86e44e33..582ca629d0 100644
--- a/sysdeps/x86_64/multiarch/Makefile
+++ b/sysdeps/x86_64/multiarch/Makefile
@@ -75,5 +75,6 @@  libcpu-rt-c-sysdep_routines += memchr-sse2 memchr-avx2 \
 			       memmove-ssse3 memmove-ssse3-back \
 			       memmove-avx-unaligned-erms \
 			       memmove-avx512-unaligned-erms \
-			       memmove-avx512-no-vzeroupper
+			       memmove-avx512-no-vzeroupper \
+			       memrchr-sse2 memrchr-avx2
 endif
diff --git a/sysdeps/x86_64/multiarch/memrchr-avx2.S b/sysdeps/x86_64/multiarch/memrchr-avx2.S
index b41a58bcba..ee4d461fe2 100644
--- a/sysdeps/x86_64/multiarch/memrchr-avx2.S
+++ b/sysdeps/x86_64/multiarch/memrchr-avx2.S
@@ -16,7 +16,7 @@ 
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#if IS_IN (libc)
+#if IS_IN (libc) || IS_IN (libcpu_rt_c)
 
 # include <sysdep.h>
 
diff --git a/sysdeps/x86_64/multiarch/memrchr-sse2.S b/sysdeps/x86_64/multiarch/memrchr-sse2.S
index 12281663ec..f0d0668262 100644
--- a/sysdeps/x86_64/multiarch/memrchr-sse2.S
+++ b/sysdeps/x86_64/multiarch/memrchr-sse2.S
@@ -16,7 +16,7 @@ 
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#if IS_IN (libc)
+#if IS_IN (libc) || IS_IN (libcpu_rt_c)
 # define __memrchr __memrchr_sse2
 
 # undef weak_alias
diff --git a/sysdeps/x86_64/multiarch/memrchr.c b/sysdeps/x86_64/multiarch/memrchr.c
index d227fe7819..da4cff9e22 100644
--- a/sysdeps/x86_64/multiarch/memrchr.c
+++ b/sysdeps/x86_64/multiarch/memrchr.c
@@ -18,7 +18,7 @@ 
    <http://www.gnu.org/licenses/>.  */
 
 /* Define multiple versions only for the definition in libc.  */
-#if IS_IN (libc)
+#if IS_IN (libc) || IS_IN (libcpu_rt_c)
 # define memrchr __redirect_memrchr
 # include <string.h>
 # undef memrchr
@@ -26,6 +26,12 @@ 
 # define SYMBOL_NAME memrchr
 # include "ifunc-avx2.h"
 
+# if IS_IN (libcpu_rt_c)
+#  define __memrchr memrchr
+# endif
+
 libc_ifunc_redirected (__redirect_memrchr, __memrchr, IFUNC_SELECTOR ());
+# if !IS_IN (libcpu_rt_c)
 weak_alias (__memrchr, memrchr)
+# endif
 #endif