From patchwork Wed Apr 30 20:00:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Miller X-Patchwork-Id: 344308 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 959301400F8 for ; Thu, 1 May 2014 06:00:24 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:message-id:to:subject:from:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=Kqk 6E4WBmCwilgv+AGgNo71F/GSQFdx07JveQqW8Ca807BE78+335ip0cEv1awe3Kbf FPiVascd5WeBYWzpKw570ibRKjXHcMkj4v58Ul3VGLI9gW259qrpMYe/oUwWfuPj dKQX2VUGwXdlnJFBSolgrcc8tSPsUPZhriKqxShc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:message-id:to:subject:from:mime-version :content-type:content-transfer-encoding; s=default; bh=ib0c563pi dy1DCbhKhCl1X8xRSo=; b=ru4MtK/jbIzTAdfc1D+QMiw8bl9OsVo+/7sIqEoDq EhRVk2a90eRJCzPmqAW5rk8ev9ieXZe5lJS0uXGr+spjzH5YL2LCEs90+VzDnsKK fBFkAnfO5b6uC3w97uhwZdCaFG+eeUBJdd12cnrtcuEIgebmOTduvf9ndCbskWC+ +8= Received: (qmail 3014 invoked by alias); 30 Apr 2014 20:00:17 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 2998 invoked by uid 89); 30 Apr 2014 20:00:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: shards.monkeyblade.net Date: Wed, 30 Apr 2014 16:00:00 -0400 (EDT) Message-Id: <20140430.160000.1171411871854680001.davem@davemloft.net> To: libc-alpha@sourceware.org Subject: [PATCH] Fix v9/64-bit strcmp when string ends in multiple zero bytes. From: David Miller Mime-Version: 1.0 Can I get a quick ACK for the strcmp testcase change? I also plan to commit this also to the active release branches. Thanks! [BZ #16885] * sysdeps/sparc/sparc64/strcmp.S: Fix end comparison handling when multiple zero bytes exist at the end of a string. Reported by Aurelien Jarno * string/test-strcmp.c (check): Add explicit test for situations where there are multiple zero bytes after the first. --- ChangeLog | 8 ++++++++ string/test-strcmp.c | 29 +++++++++++++++++++++++++++++ sysdeps/sparc/sparc64/strcmp.S | 31 +++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/ChangeLog b/ChangeLog index a6ffe08..62f5fd1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2014-04-30 David S. Miller + [BZ #16885] + * sysdeps/sparc/sparc64/strcmp.S: Fix end comparison handling when + multiple zero bytes exist at the end of a string. + Reported by Aurelien Jarno + + * string/test-strcmp.c (check): Add explicit test for situations where + there are multiple zero bytes after the first. + * sysdeps/sparc/bits/string.h (_STRING_ARCH_unaligned): Define to 0. diff --git a/string/test-strcmp.c b/string/test-strcmp.c index b395dc7..d1c73a3 100644 --- a/string/test-strcmp.c +++ b/string/test-strcmp.c @@ -329,6 +329,35 @@ check (void) FOR_EACH_IMPL (impl, 0) check_result (impl, s1 + i1, s2 + i2, exp_result); } + + /* Test cases where there are multiple zero bytes after the first. */ + + for (size_t i = 0; i < 8; i++) + { + int exp_result; + + for (CHAR val = 0x01; val < 0x10; val++) + { + for (size_t j = 0; j < i; j++) + { + s1[j] = val; + s2[j] = val; + } + + s1[i] = 0x00; + s2[i] = val; + + for (size_t j = i + 1; j < 16; j++) + { + s1[j] = 0x00; + s2[j] = 0x00; + } + + exp_result = SIMPLE_STRCMP (s1, s2); + FOR_EACH_IMPL (impl, 0) + check_result (impl, s1, s2, exp_result); + } + } } diff --git a/sysdeps/sparc/sparc64/strcmp.S b/sysdeps/sparc/sparc64/strcmp.S index 8925396..312924a 100644 --- a/sysdeps/sparc/sparc64/strcmp.S +++ b/sysdeps/sparc/sparc64/strcmp.S @@ -121,6 +121,37 @@ ENTRY(strcmp) movleu %xcc, -1, %o0 srlx rTMP1, 7, rTMP1 + /* In order not to be influenced by bytes after the zero byte, we + * have to retain only the highest bit in the mask for the comparison + * with rSTRXOR to work properly. + */ + mov 0, rTMP2 + andcc rTMP1, 0x0100, %g0 + + movne %xcc, 8, rTMP2 + sllx rTMP1, 63 - 16, %o1 + + movrlz %o1, 16, rTMP2 + sllx rTMP1, 63 - 24, %o1 + + movrlz %o1, 24, rTMP2 + sllx rTMP1, 63 - 32, %o1 + + movrlz %o1, 32, rTMP2 + sllx rTMP1, 63 - 40, %o1 + + movrlz %o1, 40, rTMP2 + sllx rTMP1, 63 - 48, %o1 + + movrlz %o1, 48, rTMP2 + sllx rTMP1, 63 - 56, %o1 + + movrlz %o1, 56, rTMP2 + + srlx rTMP1, rTMP2, rTMP1 + + sllx rTMP1, rTMP2, rTMP1 + cmp rTMP1, rSTRXOR retl movgu %xcc, 0, %o0