From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9DA986341 for ; Sat, 24 Jan 2026 08:15:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769242500; cv=none; b=AkYtd2nMxloUKyw/qNUIGJLNVUF2ZNz3QMYe1EEURHzWWVB8iioqCV7ss1IEdbqVjQgw+Q/uRShZUXpVGmcthJfgD96LKfAqkp78q9QCRi2BYVwBhqHUlTODNyBz4W7bA67xLqZdIf/MGDzYILXhGBm91PRmI0aee5HIJtEhtaU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769242500; c=relaxed/simple; bh=PywAw2DMbolvUVXsSOcJRpn47qYGaoGZYNder+ttOHk=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=CHtQ0TV7ZI5f9IePCeYghlRNAuTE4uWLyjcmR+Ru+MaWCb1y9dkZRl4yr4eofcthWrXliib2ioHGMKIbFdzzCORjZsGjyQZI5moLOqGvd0ucJyr9yt9kKYzc1QICvVEL/X+5qmOeFJZP4O8/Pvyy0nTqqCwGhztUD4TxS1Bc4/8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Fb+4nXLN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Fb+4nXLN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBB42C116D0; Sat, 24 Jan 2026 08:14:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769242500; bh=PywAw2DMbolvUVXsSOcJRpn47qYGaoGZYNder+ttOHk=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=Fb+4nXLNATw6Z4sPmcJml8tLbXrO1ZOBKCX+BPFUfdS/j9YDimTNTbzyUSraVZ9vc vPgaMT7ZSoZp+lue7HKA2KINXANR6h2ZY+MMDWND4tRBjYW9btlzNT5JyQxEpU8zpK tcP8Pqe0p9Bn1GfUkkdedRahayyFtBFvcxqm5YCrGnBpZBgPk6aedLR05voRcIgjEm 3zTD1gYenX/gsbKZcgQv84QRct+4Qg6ALx+1m+EYLqDRR7H9E9V/BZ0j0HhdQB6tI2 ZPyDHqtMf0Oqn0mtRRPLDo6iBhZyMmqGjkfmHrH6BvCvJ7F6mp74MbjGq1l4+2jqoa gwBcPyMjj+8dA== Date: Sat, 24 Jan 2026 01:14:58 -0700 (MST) From: Paul Walmsley To: Feng Jiang cc: Paul Walmsley , palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, samuel.holland@sifive.com, charlie@rivosinc.com, conor.dooley@microchip.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] riscv: lib: optimize strlen loop efficiency In-Reply-To: <581a8707-cb16-46d9-b6b5-8fa267383318@kylinos.cn> Message-ID: <4cd1d9d1-34da-7d96-46ac-a5470cfa85c3@kernel.org> References: <20251218032614.57356-1-jiangfeng@kylinos.cn> <581a8707-cb16-46d9-b6b5-8fa267383318@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Thu, 15 Jan 2026, Feng Jiang wrote: > On 2026/1/15 10:03, Paul Walmsley wrote: > > On Thu, 18 Dec 2025, Feng Jiang wrote: > > > >> Optimize the generic strlen implementation by using a pre-decrement > >> pointer. This reduces the loop body from 4 instructions to 3 and > >> eliminates the unconditional jump ('j'). > >> > >> Old loop (4 instructions, 2 branches): > >> 1: lbu t0, 0(t1); beqz t0, 2f; addi t1, t1, 1; j 1b > >> > >> New loop (3 instructions, 1 branch): > >> 1: addi t1, t1, 1; lbu t0, 0(t1); bnez t0, 1b > >> > >> This change improves execution efficiency and reduces branch pressure > >> for systems without the Zbb extension. > > > > Looks reasonable; do you have any benchmarks on hardware that you can > > share? Any reason why this patch stands alone and isn't rolled up as part > > of your "optimize string function" series? > > Thanks for the feedback. > > This patch predates the rest of the series, which is why it wasn't included > in the 'optimize string function' rollup. At the time, I focused on correctness > testing and observed the improvement through rdcycle instruction counts. > > Since the series still needs further refinement and may take a longer time to > complete, I was hoping this standalone optimization could be considered independently. Ok. Queued for v6.20. Might be worth taking a look at David's suggestions for a followup patch? - Paul