Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3120005imm; Thu, 17 May 2018 03:50:19 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpNNvQffOZ6Io68LUrYWZEJ5p2Aox/K4uDuUzeLO/HE8MuyE757hVUSe1Ajspu3xDAELC2d X-Received: by 2002:a17:902:22cc:: with SMTP id o12-v6mr4886689plg.38.1526554219208; Thu, 17 May 2018 03:50:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526554219; cv=none; d=google.com; s=arc-20160816; b=O/n8m+iUECptIsneZ2/+1BVmhQMpj/LsSPn3vBYmm/frSUIBoi8G2M3q7swtLCwIRL t1ieCCCdh+XwfwC/+e/dlu43irQbE0G7pI2g2QVxYUJH4to5X/TKlgZLM2BnZH8upMXr N9ZbxwsNbHGEZKdsMSbMF6aOCs8EBKdKxqeyJOZ5Oy9dsZmn9Z9SFpOKjGebyz89/kLY FesSCXQ94FJygp/7OdgaY5dpGPTnJ8PgybqD8kGWw+JP0NNGe6OAkaotSgjUZyR96PA7 B7uWZRzYFUSgt+CjeKddNHjVGBnJiESgg4GW6PecunM2T5JFn5hbcbJ2o9C+8xQ0fv5W SmRA== 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=LGyp9PQe3+J1YCeYpqlVKSFQhgg0KRxJNG6v1CwpyTo=; b=YoNg+vYdcoSKlW27CnTX6Lc5zg8AMq+PpTsri/h6Ayoy2+sHYJjLm8jUwKRWbZs+E3 I4j/f+345ochZlTKCvai1BCvZAvcD2Mz7K0mSRslG74BnOFGS5nTeGKiSvdK6ToR6KvI J5ky1zi6MiMRYp67xnCoVzHSS19rxomqLZ5yE/GkwaCv4NSaUoW86U6A/hiez3Dvar4B iUHtTa52LQRqSOWHnqqEMRHlYj8D7dTy4vJGSesTEPM0PJP9BkyaDV+7a45wdnRBe+qq uboJrZP+F4J5icwIBjz6J281a0EUwf1OUrFq59gpBfguINv9VHDhYR6EoMb62vGJydhK CIYw== 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 l36-v6si4917578plg.82.2018.05.17.03.50.05; Thu, 17 May 2018 03:50:19 -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 S1752056AbeEQKt7 (ORCPT + 99 others); Thu, 17 May 2018 06:49:59 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:11084 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751097AbeEQKt4 (ORCPT ); Thu, 17 May 2018 06:49:56 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 40mp3P65GJz9v0kP; Thu, 17 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 TbTcoadyK8HJ; Thu, 17 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 40mp3P5YZRz9v0k0; Thu, 17 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 277AA8B987; Thu, 17 May 2018 12:49:55 +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 Zg-3I-ix07Ir; Thu, 17 May 2018 12:49:55 +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 075228B97E; Thu, 17 May 2018 12:49:55 +0200 (CEST) Received: by po14934vm.idsi0.si.c-s.fr (Postfix, from userid 0) id E35A66F937; Thu, 17 May 2018 12:49:54 +0200 (CEST) Message-Id: <0bb218e986cc117099c3900709adfd2f2ac97c41.1526553552.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v2 3/5] powerpc/lib: optimise PPC32 memcmp To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Thu, 17 May 2018 12:49:54 +0200 (CEST) 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 | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/lib/string_32.S b/arch/powerpc/lib/string_32.S index 2c11c2019b69..5c0e77baa9c7 100644 --- a/arch/powerpc/lib/string_32.S +++ b/arch/powerpc/lib/string_32.S @@ -20,13 +20,41 @@ _GLOBAL(memcmp) PPC_LCMPI 0,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: +#ifdef __LITTLE_ENDIAN__ + lwbrx r3, r6, r7 + lwbrx r0, r4, r7 +#else + lwzx r3, r6, r7 + lwzx r0, r4, r7 +#endif + addi r7, r7, 4 + subf. r3, r0, r3 + bdnzt eq, 1b + bnelr + andi. r5, r5, 3 + beqlr +3: cmplwi cr1, r5, 2 + blt- cr1, 4f +#ifdef __LITTLE_ENDIAN__ + lhbrx r3, r6, r7 + lhbrx r0, r4, r7 +#else + lhzx r3, r6, r7 + lhzx r0, r4, r7 +#endif + 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 blr -- 2.13.3