From patchwork Sat Jul 4 16:37:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 39912 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B9FD33844041; Sat, 4 Jul 2020 16:37:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B9FD33844041 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1593880667; bh=HRBv6audavG0ZlWWGuuDmgEfTitDtplNevnWqNgySGo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=nk6t4fV9+6htdjP4qCa5M92/GS/pk0DSE0Semks3nzaTgE4esVlArhUdEn2b0wr2L AMNRbHLxXjEvc76XdPlgp7naEPDh0ZWXSfsKZ1Vx7HPkirffOEQe72OtfD7Mq5uyUr 8H8Gs+2TPEYstc0fv3JoOe+81KpzSi8klW4cvbkA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by sourceware.org (Postfix) with ESMTPS id 778923851C1C; Sat, 4 Jul 2020 16:37:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 778923851C1C Received: by mail-pl1-x641.google.com with SMTP id d10so13714608pls.5; Sat, 04 Jul 2020 09:37:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HRBv6audavG0ZlWWGuuDmgEfTitDtplNevnWqNgySGo=; b=fou5WLP7QGSITuYGv77qQqwu76C46y4Z9EMe2cTOepy88CA3EMjhUN4LGOBg7uNy4l 5uvhcaxYbqDJ1oeAhL6Zyj4hdU2Z1TxbQESAahyem7WfVjULybpfhL82yQHya/2792aL G7JORMKqahp0xNDYWOPcE902geeRhir4EeeyVCG/OrS8lU1dyvDvq9gWvRpOGUDxvjI1 1GeGNUa9e5G1MkKSagGHeYoL2ay6N9Y4dImikox+jFen4MONd1blDRX3pJGA4nxhhbBY RFlyGbkaBMkpo3DQ71Fvkjc3S3C6ahRXmEEZxSRYmuMR/aRg8Poe1tF6ja09/+rujEY8 tULQ== X-Gm-Message-State: AOAM533RfUGvfefkTLvSOC9kEMUGblRS6HnxuzUUgtGvlaboXX1FsEPe a3lemMEmgaC2N5ucC1PaxCqwhlT/ X-Google-Smtp-Source: ABdhPJyA2IOiBCNRIQxhrGMSYQ+ZLgm1CXHbT8rgSw3DyMM9r0AswpVr6sigw4Hf2VwLMmyV0f9tig== X-Received: by 2002:a17:902:e901:: with SMTP id k1mr28483027pld.130.1593880663595; Sat, 04 Jul 2020 09:37:43 -0700 (PDT) Received: from gnu-cfl-2.localdomain (c-69-181-90-243.hsd1.ca.comcast.net. [69.181.90.243]) by smtp.gmail.com with ESMTPSA id m1sm13753967pjr.56.2020.07.04.09.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jul 2020 09:37:43 -0700 (PDT) Received: from gnu-cfl-2.localdomain (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 518001A0117; Sat, 4 Jul 2020 09:37:42 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [2.31/2.30/2.29] [PATCH] Fix avx2 strncmp offset compare condition check [BZ #25933] Date: Sat, 4 Jul 2020 09:37:42 -0700 Message-Id: <20200704163742.3347595-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Spam-Status: No, score=-13.0 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.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: libc-stable@sourceware.org, Sunil K Pandey Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" From: Sunil K Pandey strcmp-avx2.S: In avx2 strncmp function, strings are compared in chunks of 4 vector size(i.e. 32x4=128 byte for avx2). After first 4 vector size comparison, code must check whether it already passed the given offset. This patch implement avx2 offset check condition for strncmp function, if both string compare same for first 4 vector size. (cherry picked from commit 75870237ff3bb363447b03f4b0af100227570910) --- sysdeps/x86_64/multiarch/strcmp-avx2.S | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sysdeps/x86_64/multiarch/strcmp-avx2.S b/sysdeps/x86_64/multiarch/strcmp-avx2.S index 48d03a9f46..ee82fa3e19 100644 --- a/sysdeps/x86_64/multiarch/strcmp-avx2.S +++ b/sysdeps/x86_64/multiarch/strcmp-avx2.S @@ -591,7 +591,14 @@ L(loop_cross_page_2_vec): movl $(PAGE_SIZE / (VEC_SIZE * 4) - 1), %esi testq %rdi, %rdi +# ifdef USE_AS_STRNCMP + /* At this point, if %rdi value is 0, it already tested + VEC_SIZE*4+%r10 byte starting from %rax. This label + checks whether strncmp maximum offset reached or not. */ + je L(string_nbyte_offset_check) +# else je L(back_to_loop) +# endif tzcntq %rdi, %rcx addq %r10, %rcx /* Adjust for number of bytes skipped. */ @@ -627,6 +634,14 @@ L(loop_cross_page_2_vec): VZEROUPPER ret +# ifdef USE_AS_STRNCMP +L(string_nbyte_offset_check): + leaq (VEC_SIZE * 4)(%r10), %r10 + cmpq %r10, %r11 + jbe L(zero) + jmp L(back_to_loop) +# endif + .p2align 4 L(cross_page_loop): /* Check one byte/dword at a time. */