Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2201548imm; Mon, 28 May 2018 03:50:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp1UpRmRr5z6Jqz5n5G7sCVMMJ4eHDHNtEbFMzYej5VuONWIbumud/ATPkO0x/j/9THf/+L X-Received: by 2002:a62:5fc5:: with SMTP id t188-v6mr12969185pfb.214.1527504638985; Mon, 28 May 2018 03:50:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527504638; cv=none; d=google.com; s=arc-20160816; b=aN1RCe9caqOCP5R7F5y0r7TQDdAHEIIqqaLnEfZt6n/CGSdrcVkMkOqfPCDNEBapqN MBdarN+p9zZktJpNY82fUjFrnk+hDRjHcs1u3jjtul6Aao7FR9e8D1IuBiY+ERxkrtQ1 jL4z5POzIYcY7zFJaU8Io1cSJqRpRnr/WO7z1NPctne8GoOxNs5JhzKeRlyrnmz/nl9/ OlIWrfZFIRkDxckCSjgdtY+R6l+R2CEQ9Z7FmM1+NpenRR2ZEDmUkNVqxg0b4OcnL5lK fnqmfTGVBPSGI9BmnADjthUQ0eqwTo9n/LMU4FEHELxp2XNOJaKrFyhvm6yaXPgA3NyM NPEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id:arc-authentication-results; bh=g4M0CaBeNaqyER5hTtVW9EhJySfhDG+F5sVKGxW+aV8=; b=pPq1SoHr8BgZ2nSM6XOUtobs4STbpu94cCzFPnHmcfym8ZiR0miXNCF5oRaR8Xepy2 QkPSURorpav4SWjLsu6shzI+9I1zQSXPMMVSkC/G4LOs/1eUfRXuAIRBOmhpth5WSzXf ZWiGpWQm7v/S256ZcBuQrHdWnYtHxAZdhnP/aKjoPprj+wQaDHLdXyup/F++u5IeCn3i H7+9MdcHqpmn9iuIe4ryqzCSt9jPmczRDU15uSMGZ/oizyrUna5YF6n06MMRoI44JOKG ldjjoA7PLpS+ETuSgHGevUGsAWmMK2Ts3myEvHNH9BLYiDejAGRebt45Ckrdpvr7mOzD gCpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w10-v6si2510375ply.482.2018.05.28.03.50.24; Mon, 28 May 2018 03:50:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1163654AbeE1KuR (ORCPT + 99 others); Mon, 28 May 2018 06:50:17 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:9789 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163605AbeE1KuG (ORCPT ); Mon, 28 May 2018 06:50:06 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 40vYXK0dQfz9ty73; Mon, 28 May 2018 12:49:53 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id JP1ch48ZD6Bp; Mon, 28 May 2018 12:49:53 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 40vYXK0B5cz9ty6Y; Mon, 28 May 2018 12:49:53 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 53D838B971; Mon, 28 May 2018 12:49:58 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id H8uNYEujrfrH; Mon, 28 May 2018 12:49:58 +0200 (CEST) Received: from po14934vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 330838B96E; Mon, 28 May 2018 12:49:58 +0200 (CEST) Received: by po14934vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 260876F10C; Mon, 28 May 2018 10:49:58 +0000 (UTC) Message-Id: <88c8cc033b4ea364d62d1d8ba811a8f8d56c297d.1527503958.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v5 3/3] powerpc/lib: optimise PPC32 memcmp To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , segher@kernel.crashing.org Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Mon, 28 May 2018 10:49:58 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At the time being, memcmp() compares two chunks of memory byte per byte. This patch optimises the comparison by comparing word by word. A small benchmark performed on an 8xx comparing two chuncks of 512 bytes performed 100000 times gives: Before : 5852274 TB ticks After: 1488638 TB ticks This is almost 4 times faster Signed-off-by: Christophe Leroy --- arch/powerpc/lib/string_32.S | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/lib/string_32.S b/arch/powerpc/lib/string_32.S index 40a576d56ac7..4fbaa046aa84 100644 --- a/arch/powerpc/lib/string_32.S +++ b/arch/powerpc/lib/string_32.S @@ -16,17 +16,34 @@ .text _GLOBAL(memcmp) - cmpwi cr0, r5, 0 - beq- 2f - mtctr r5 - addi r6,r3,-1 - addi r4,r4,-1 -1: lbzu r3,1(r6) - lbzu r0,1(r4) - subf. r3,r0,r3 - bdnzt 2,1b + srawi. r7, r5, 2 /* Divide len by 4 */ + mr r6, r3 + beq- 3f + mtctr r7 + li r7, 0 +1: lwzx r3, r6, r7 + lwzx r0, r4, r7 + addi r7, r7, 4 + cmplw cr0, r3, r0 + bdnzt eq, 1b + bne 5f +3: andi. r3, r5, 3 + beqlr + cmplwi cr1, r3, 2 + blt- cr1, 4f + lhzx r3, r6, r7 + lhzx r0, r4, r7 + addi r7, r7, 2 + subf. r3, r0, r3 + beqlr cr1 + bnelr +4: lbzx r3, r6, r7 + lbzx r0, r4, r7 + subf. r3, r0, r3 blr -2: li r3,0 +5: li r3, 1 + bgtlr + li r3, -1 blr EXPORT_SYMBOL(memcmp) -- 2.13.3