From patchwork Wed Feb 8 22:53:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Heiko_St=C3=BCbner?= X-Patchwork-Id: 54631 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3739195wrn; Wed, 8 Feb 2023 15:09:50 -0800 (PST) X-Google-Smtp-Source: AK7set/QYuQ7v3VmINAxgEA0az7yBIzxtwvIaI0MAC4t5erlgXMfquBevIuq/Dz+L5L9fC016shP X-Received: by 2002:a17:906:19b:b0:8ae:a4db:ba6e with SMTP id 27-20020a170906019b00b008aea4dbba6emr3420050ejb.2.1675897790818; Wed, 08 Feb 2023 15:09:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675897790; cv=none; d=google.com; s=arc-20160816; b=e6eaFJZZTqrAtpGG9rQfukJRvBCyJ4/UWyz3h104U6yCDao2r+LCmv+iwSlGeWwYmn vtM9+TXYx4MUC49Mt4ipXb5wNK/RfHJJCmqHRuERjlxoUALZnIYIynGqyV1REwHJLO5D qUi5+zkSSlJhDS1odGzpumEbgYwMWQfgghX6WAG+5rdRxWEYRUg86EJt+EDQMunGCR/O A/482BumM/kJPxiBEOM8tLvUg/iCFIFFm8NhTlo9OD+9YrMhdCJSWIUrOnKldhH00YOP 8xqBZc0l4+vLTtWteDhJvCBStoQdoAoeSq8oICGOESQG+6tRIrvdY2noWWmDcWt0mn3N T6UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=xIvM+90yK4zLk2/83eYeUQQzP4S2alawkYNOveBGpjg=; b=GRrmiucFow8a1q0EoWA7lU0F90+RPeP+qwa/ZWXAJrT5vPPlh/sONiQo4eDUEzDyJG drCJuOp+R0TgOp6WCPFXJchRIlf6UVpb73KjIbghayvMxaA9z3v+y3fvDbVAZ96XVZ8z Tt/63jO6yPZiP9fjsDxQJa9N2KNUF/GvRYDjyGCdUnC2PRmAaoQ8OBzKvDtCvV2YLBOA oIiDBDXGvEYP3cNEqjKf+21g+vbwerjTduWU8IONeDmE7tnmJbVv+kxac092+pwwiiXN BOVjWZkqh1EMbvJUBe7MirzwQpnM9YFtDy7rlTsyQpSvXk9oanse+Cyxxe2+na3UYV/r pSFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eu9-20020a170907298900b008787c8674b1si146253ejc.751.2023.02.08.15.09.27; Wed, 08 Feb 2023 15:09:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232097AbjBHWxj (ORCPT + 99 others); Wed, 8 Feb 2023 17:53:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231370AbjBHWxg (ORCPT ); Wed, 8 Feb 2023 17:53:36 -0500 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D236274A5 for ; Wed, 8 Feb 2023 14:53:33 -0800 (PST) Received: from ip5b412258.dynamic.kabel-deutschland.de ([91.65.34.88] helo=phil.lan) by gloria.sntech.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pPtJi-0003OP-Nr; Wed, 08 Feb 2023 23:53:30 +0100 From: Heiko Stuebner To: palmer@rivosinc.com Cc: conor@kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, christoph.muellner@vrull.eu, ajones@ventanamicro.com, Heiko Stuebner Subject: [PATCH 1/2] RISC-V: fix ordering of Zbb extension Date: Wed, 8 Feb 2023 23:53:27 +0100 Message-Id: <20230208225328.1636017-2-heiko@sntech.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230208225328.1636017-1-heiko@sntech.de> References: <20230208225328.1636017-1-heiko@sntech.de> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS, T_SPF_HELO_TEMPERROR autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757306201961731366?= X-GMAIL-MSGID: =?utf-8?q?1757306201961731366?= From: Heiko Stuebner As Andrew reported, Zb* comes after Zi* according 27.11 "Subset Naming Convention" so fix the ordering accordingly. Reported-by: Andrew Jones Signed-off-by: Heiko Stuebner Reviewed-by: Conor Dooley Reviewed-by: Andrew Jones --- arch/riscv/kernel/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c index 420228e219f7..8400f0cc9704 100644 --- a/arch/riscv/kernel/cpu.c +++ b/arch/riscv/kernel/cpu.c @@ -185,9 +185,9 @@ arch_initcall(riscv_cpuinfo_init); * New entries to this struct should follow the ordering rules described above. */ static struct riscv_isa_ext_data isa_ext_arr[] = { - __RISCV_ISA_EXT_DATA(zbb, RISCV_ISA_EXT_ZBB), __RISCV_ISA_EXT_DATA(zicbom, RISCV_ISA_EXT_ZICBOM), __RISCV_ISA_EXT_DATA(zihintpause, RISCV_ISA_EXT_ZIHINTPAUSE), + __RISCV_ISA_EXT_DATA(zbb, RISCV_ISA_EXT_ZBB), __RISCV_ISA_EXT_DATA(sscofpmf, RISCV_ISA_EXT_SSCOFPMF), __RISCV_ISA_EXT_DATA(sstc, RISCV_ISA_EXT_SSTC), __RISCV_ISA_EXT_DATA(svinval, RISCV_ISA_EXT_SVINVAL), From patchwork Wed Feb 8 22:53:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Heiko_St=C3=BCbner?= X-Patchwork-Id: 54630 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3738852wrn; Wed, 8 Feb 2023 15:09:10 -0800 (PST) X-Google-Smtp-Source: AK7set/JYaehw+z5kgEKpDFAiV/eZxr5ndhP/GABUrHtHSN/5WfQIzI7aSgH93hHp2uztyp3d/lT X-Received: by 2002:a17:906:d0:b0:882:bffc:f2d2 with SMTP id 16-20020a17090600d000b00882bffcf2d2mr8616513eji.2.1675897749866; Wed, 08 Feb 2023 15:09:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675897749; cv=none; d=google.com; s=arc-20160816; b=nIwQyVE72P5rpCV3xhoWhGfpZ080Y1lDG0ffVv/+1iZ2D/VKwq1gQpx8oaPf5qRBJ5 XD7xEy15zZjQk/Q9Ym/coFsspDTkBNfArKCmq56d7NRwFCNx46kg3zX95VroBPbNEiAw EOVdPafjODVxZ3voEUuQYiuJjfOZ212rHnM8deJuGxssp7XREI+7ABC1UqVuCRsvUizw Y2l2i8h1B5W6w1Jm/ctbcnA+Pt8bGDpeveXagIMnBUELDN1teLNJ79+KVUU1KWLMitzv MYBPC7zEtVNnbpbdNBLhAPaRt5Vht8Lcv62+6rA0t1ne6VCodlZvwoEDqT8dMGz666TT SB4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=dCRn2zOPDEiIR9sv4IXwLxfAn4PDb1UQLvWxCbflriA=; b=VO0QCV9HhRyWWCdfPJfJi7/XOuRJBw3mYEOgKBALuy2f0Ba8TuYDZo0iuU1S5LQKsU wJK0FUUG86qcpc55fDzxYp55wrBIGfTWWpRH5gCeOIpNr84j56itgXJ4th1+Yw8HG6J8 QDild81+cjw/MWZpKcNIo84ZFwHx/ivXydOVTKm8ULS4oQHCFGLzAvqjP6x5L2ayJbre EiYyb+4JisZaSnAZhO66RF424MqUC5dX0z6Rfm/tt0Qnxk22tKMnBOuViVw9J1Gpqyis hVnT9B9MZau0bM6n6PQHKMBHGvODxgJgJ/oEUXsFv2iEWysUPKlTJ5U0ukVOqDdrneHY eTDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 9-20020a170906020900b0087bdb5cd26esi228073ejd.451.2023.02.08.15.08.46; Wed, 08 Feb 2023 15:09:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232503AbjBHWxi (ORCPT + 99 others); Wed, 8 Feb 2023 17:53:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232355AbjBHWxg (ORCPT ); Wed, 8 Feb 2023 17:53:36 -0500 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D06525282 for ; Wed, 8 Feb 2023 14:53:33 -0800 (PST) Received: from ip5b412258.dynamic.kabel-deutschland.de ([91.65.34.88] helo=phil.lan) by gloria.sntech.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pPtJi-0003OP-Vu; Wed, 08 Feb 2023 23:53:31 +0100 From: Heiko Stuebner To: palmer@rivosinc.com Cc: conor@kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, christoph.muellner@vrull.eu, ajones@ventanamicro.com, Heiko Stuebner Subject: [PATCH 2/2] RISC-V: improve string-function assembly Date: Wed, 8 Feb 2023 23:53:28 +0100 Message-Id: <20230208225328.1636017-3-heiko@sntech.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230208225328.1636017-1-heiko@sntech.de> References: <20230208225328.1636017-1-heiko@sntech.de> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS, T_SPF_HELO_TEMPERROR autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757306158706047423?= X-GMAIL-MSGID: =?utf-8?q?1757306158706047423?= From: Heiko Stuebner Adapt the suggestions for the assembly string functions that Andrew suggested but that I didn't manage to include into the series that got applied. This includes improvements to two comments, removal of unneeded labels and moving one instruction slightly higher to contradict an explanatory comment. Suggested-by: Andrew Jones Signed-off-by: Heiko Stuebner Reviewed-by: Andrew Jones --- arch/riscv/lib/strcmp.S | 6 ++++-- arch/riscv/lib/strlen.S | 10 +++++----- arch/riscv/lib/strncmp.S | 16 +++++++--------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/arch/riscv/lib/strcmp.S b/arch/riscv/lib/strcmp.S index 8148b6418f61..fb186bf28f07 100644 --- a/arch/riscv/lib/strcmp.S +++ b/arch/riscv/lib/strcmp.S @@ -40,7 +40,9 @@ SYM_FUNC_START(strcmp) ret /* - * Variant of strcmp using the ZBB extension if available + * Variant of strcmp using the ZBB extension if available. + * The code was published as part of the bitmanip manual + * in Appendix A. */ #ifdef CONFIG_RISCV_ISA_ZBB strcmp_zbb: @@ -57,7 +59,7 @@ strcmp_zbb: * a1 - string2 * * Clobbers - * t0, t1, t2, t3, t4, t5 + * t0, t1, t2, t3, t4 */ or t2, a0, a1 diff --git a/arch/riscv/lib/strlen.S b/arch/riscv/lib/strlen.S index 0f9dbf93301a..898466f67000 100644 --- a/arch/riscv/lib/strlen.S +++ b/arch/riscv/lib/strlen.S @@ -96,7 +96,7 @@ strlen_zbb: * of valid bytes in this chunk. */ srli a0, t1, 3 - bgtu t3, a0, 3f + bgtu t3, a0, 2f /* Prepare for the word comparison loop. */ addi t2, t0, SZREG @@ -112,20 +112,20 @@ strlen_zbb: addi t0, t0, SZREG orc.b t1, t1 beq t1, t3, 1b -2: + not t1, t1 CZ t1, t1 + srli t1, t1, 3 - /* Get number of processed words. */ + /* Get number of processed bytes. */ sub t2, t0, t2 /* Add number of characters in the first word. */ add a0, a0, t2 - srli t1, t1, 3 /* Add number of characters in the last word. */ add a0, a0, t1 -3: +2: ret .option pop diff --git a/arch/riscv/lib/strncmp.S b/arch/riscv/lib/strncmp.S index 7940ddab2d48..e36f5a6e1b16 100644 --- a/arch/riscv/lib/strncmp.S +++ b/arch/riscv/lib/strncmp.S @@ -70,7 +70,7 @@ strncmp_zbb: li t5, -1 and t2, t2, SZREG-1 add t4, a0, a2 - bnez t2, 4f + bnez t2, 3f /* Adjust limit for fast-path. */ andi t6, t4, -SZREG @@ -114,23 +114,21 @@ strncmp_zbb: ret /* Simple loop for misaligned strings. */ -3: - /* Restore limit for slow-path. */ .p2align 3 -4: - bge a0, t4, 6f +3: + bge a0, t4, 5f lbu t0, 0(a0) lbu t1, 0(a1) addi a0, a0, 1 addi a1, a1, 1 - bne t0, t1, 5f - bnez t0, 4b + bne t0, t1, 4f + bnez t0, 3b -5: +4: sub a0, t0, t1 ret -6: +5: li a0, 0 ret