190885
From 820e5fe6c8c30693cde469829b482665c8129811 Mon Sep 17 00:00:00 2001
190885
From: Noah Goldstein <goldstein.w.n@gmail.com>
190885
Date: Wed, 23 Jun 2021 19:19:34 -0400
190885
Subject: [PATCH] x86: Remove unnecessary overflow check from wcsnlen-sse4_1.S
190885
190885
No bug. The way wcsnlen will check if near the end of maxlen
190885
is the following macro:
190885
190885
	mov	%r11, %rsi;	\
190885
	subq	%rax, %rsi;	\
190885
	andq	$-64, %rax;	\
190885
	testq	$-64, %rsi;	\
190885
	je	L(strnlen_ret)
190885
190885
Which words independently of s + maxlen overflowing. So the
190885
second overflow check is unnecissary for correctness and
190885
just extra overhead in the common no overflow case.
190885
190885
test-strlen.c, test-wcslen.c, test-strnlen.c and test-wcsnlen.c are
190885
all passing
190885
190885
Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
190885
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
190885
(cherry picked from commit 08cbcd4dbc686bb38ec3093aff2f919fbff5ec17)
190885
---
190885
 sysdeps/x86_64/multiarch/strlen-vec.S | 7 -------
190885
 1 file changed, 7 deletions(-)
190885
190885
diff --git a/sysdeps/x86_64/multiarch/strlen-vec.S b/sysdeps/x86_64/multiarch/strlen-vec.S
190885
index 439e486a..b7657282 100644
190885
--- a/sysdeps/x86_64/multiarch/strlen-vec.S
190885
+++ b/sysdeps/x86_64/multiarch/strlen-vec.S
190885
@@ -71,19 +71,12 @@ L(n_nonzero):
190885
    suffice.  */
190885
 	mov	%RSI_LP, %R10_LP
190885
 	sar	$62, %R10_LP
190885
-	test	%R10_LP, %R10_LP
190885
 	jnz	__wcslen_sse4_1
190885
 	sal	$2, %RSI_LP
190885
 # endif
190885
 
190885
-
190885
 /* Initialize long lived registers.  */
190885
-
190885
 	add	%RDI_LP, %RSI_LP
190885
-# ifdef AS_WCSLEN
190885
-/* Check for overflow again from s + maxlen * sizeof(wchar_t).  */
190885
-	jbe	__wcslen_sse4_1
190885
-# endif
190885
 	mov	%RSI_LP, %R10_LP
190885
 	and	$-64, %R10_LP
190885
 	mov	%RSI_LP, %R11_LP
190885
-- 
190885
GitLab
190885