From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id 5D6323858D28 for ; Sat, 4 Dec 2021 03:50:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5D6323858D28 Received: by mail-pg1-x529.google.com with SMTP id r138so4914011pgr.13 for ; Fri, 03 Dec 2021 19:50:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zkyIzH2RygCO284VGqgdSNIK375MHLwaYIZdLMT8hKU=; b=Xo+Ed+l5SI9LPSQfL4CsTW8vGNReD5gx16Qm8y/3L1EPgwC6iXluTP0iLE9J1ttwei BIq0RA2jlLRnMOV+pn867oSl/8FRhvnNGEmdhdavgf4Q7Y7KHG/wkWk3RQFjkBPPXc0b HyDeM7wNtO4CyMeAj+8sd3PTXrJvCeV3VsVH/c9MOFw4KTQ+VDf3nzdO3wr+URUB32+E JbV0W0j2LV8tQ009ixN9F9VeNXnnzM1CpF7wdV4cYTYBxZr9ke0fNBLJheJwRFthAuJd q6aVqaOJW1NumK6Lh1+erPYcIz5kaTtPhBK9NOBQke1j+Kq3wabfVg2qVPh+/gTEKo2y wQNw== X-Gm-Message-State: AOAM531L+Wu+GZH2uNWq/3yjOePPGW1lREfPPcHfW2NWqUF7NPT4WMpt LOf3j7bKkcdxNokhZEPIZD+p5KaKY/zdsiBLzoo8j3rNmfg= X-Google-Smtp-Source: ABdhPJy/GT7tue9H1aSqOnA2JohzlBl1gMLVOYtF4TLnwXqM1KeEccqP6MB55Z8wOc+9itrLLvgTYKJFRFPzWdWAmdY= X-Received: by 2002:a05:6a00:1a8d:b0:49f:de63:d9c0 with SMTP id e13-20020a056a001a8d00b0049fde63d9c0mr22527572pfv.79.1638589815455; Fri, 03 Dec 2021 19:50:15 -0800 (PST) MIME-Version: 1.0 References: <20211204032420.3158-1-hjl.tools@gmail.com> In-Reply-To: <20211204032420.3158-1-hjl.tools@gmail.com> From: Noah Goldstein Date: Fri, 3 Dec 2021 21:50:04 -0600 Message-ID: Subject: Re: [PATCH] x86-64: Use notl in EVEX strcmp [BZ #28646] To: "H.J. Lu" Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Dec 2021 03:50:18 -0000 On Fri, Dec 3, 2021 at 9:24 PM H.J. Lu wrote: > > From: Noah Goldstein > > Must use notl %edi here as lower bits are for CHAR comparisons > potentially out of range thus can be 0 without indicating mismatch. > This fixes BZ #28646. > > Co-Authored-By: H.J. Lu > --- > string/test-strcmp.c | 28 ++++++++++++++++++++++++++ > sysdeps/x86_64/multiarch/strcmp-evex.S | 14 +++++++------ > 2 files changed, 36 insertions(+), 6 deletions(-) > > diff --git a/string/test-strcmp.c b/string/test-strcmp.c > index 77ae73110f..42178a260b 100644 > --- a/string/test-strcmp.c > +++ b/string/test-strcmp.c > @@ -23,6 +23,7 @@ > # define TEST_NAME "strcmp" > #endif > #include "test-string.h" > +#include > > #ifdef WIDE > # include > @@ -390,6 +391,32 @@ check2 (void) > } > } > > +static void > +check3 (void) > +{ > + size_t size = 0xd000 + 0x4000; > + CHAR *s1, *s2; > + CHAR *buffer1 = mmap (NULL, size, PROT_READ | PROT_WRITE, > + MAP_PRIVATE | MAP_ANON, -1, 0); > + CHAR *buffer2 = mmap (NULL, size, PROT_READ | PROT_WRITE, > + MAP_PRIVATE | MAP_ANON, -1, 0); > + if (buffer1 == MAP_FAILED || buffer1 == MAP_FAILED) > + error (EXIT_UNSUPPORTED, errno, "mmap failed"); > + > + s1 = (CHAR *) (buffer1 + 0x8f8 / sizeof (CHAR)); > + s2 = (CHAR *) (buffer2 + 0xcff3 / sizeof (CHAR)); > + > + STRCPY(s1, L("/export/redhat/rpms/BUILD/java-1.8.0-openjdk-1.8.0.312.b07-2.fc35.x86_64/openjdk/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/PathDocFileFactory.java")); > + STRCPY(s2, L("/export/redhat/rpms/BUILD/java-1.8.0-openjdk-1.8.0.312.b07-2.fc35.x86_64/openjdk/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ThrowsTaglet.java")); > + > + int exp_result = SIMPLE_STRCMP (s1, s2); > + FOR_EACH_IMPL (impl, 0) > + check_result (impl, s1, s2, exp_result); > + > + munmap ((void *) buffer1, size); > + munmap ((void *) buffer2, size); > +} > + > int > test_main (void) > { > @@ -398,6 +425,7 @@ test_main (void) > test_init (); > check(); > check2 (); > + check3 (); > > printf ("%23s", ""); > FOR_EACH_IMPL (impl, 0) > diff --git a/sysdeps/x86_64/multiarch/strcmp-evex.S b/sysdeps/x86_64/multiarch/strcmp-evex.S > index 0bea318abd..b68e1f7a1e 100644 > --- a/sysdeps/x86_64/multiarch/strcmp-evex.S > +++ b/sysdeps/x86_64/multiarch/strcmp-evex.S > @@ -646,12 +646,13 @@ L(loop_cross_page): > in YMM3 and 32 bytes at VEC_SIZE(%rdx, %r10). */ > VPCMP $0, VEC_SIZE(%rdx, %r10), %YMM3, %k3{%k4} > kmovd %k3, %edi > + /* Must use notl %edi here as lower bits are for CHAR > + comparisons potentially out of range thus can be 0 without > + indicating mismatch. */ > + notl %edi > # ifdef USE_AS_WCSCMP > /* Don't use subl since it is the upper 8 bits of EDI below. */ > - notl %edi > andl $0xff, %edi > -# else > - incl %edi > # endif > > # ifdef USE_AS_WCSCMP > @@ -733,12 +734,13 @@ L(loop_cross_page_2_vec): > in YMM1 and 32 bytes at (VEC_SIZE * 3)(%rdx, %r10). */ > VPCMP $0, (VEC_SIZE * 3)(%rdx, %r10), %YMM1, %k3{%k4} > kmovd %k3, %edi > + /* Must use notl %edi here as lower bits are for CHAR > + comparisons potentially out of range thus can be 0 without > + indicating mismatch. */ > + notl %edi > # ifdef USE_AS_WCSCMP > /* Don't use subl since it is the upper 8 bits of EDI below. */ > - notl %edi > andl $0xff, %edi > -# else > - incl %edi > # endif > > # ifdef USE_AS_WCSCMP > -- > 2.33.1 > LGTM