From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 C94E01CF8B for ; Mon, 26 Jan 2026 03:05:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769396715; cv=none; b=DDoupIo2Kwg5qUy2N4+oR+f46E1xs0V+rRP7nSr85lbveWRnT3goq83Spj3dHkm2BU/SzB1QYY1unnpsXm4LCiWrvCb0P0Se84rEfh17DvhfYvd5WSphkIR+koPBobTfPIABE3W+wbzqMgT81U5ZdPxU+oimx65YR4En/XtEGGo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769396715; c=relaxed/simple; bh=IQFxMlv/zegY1t9DO7y6oXJX8G4HFWckDIi6L5PHcCU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=vBS0gqa9m+8M6wPwBWlE7GZ0akZwa8Zl2Urcg7cXcBbLeGqxswlyay+IHGO89UPrX8Agy3tvwDxxZKIXP0Bqm4Cu7ozz913vySXG0enpREurOeanYvV21wdOSTjJpy2p1EhnQv+T+v/d+iI+0AIDO3i3N2cBRxFzatqb8IjeRhE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: d2a721b4fa6311f0b0f03b4cfa9209d1-20260126 X-CID-CACHE: Type:Local,Time:202601261052+08,HitQuantity:1 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.6,REQID:76fa5b22-f881-489c-a107-7241c4d0a830,IP:0,UR L:25,TC:0,Content:2,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:27 X-CID-META: VersionHash:a9d874c,CLOUDID:76b9cc944f387dac074195358d40b1b8,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:80|81|82|83|102|898,TC:nil,Content:4|15| 50,EDM:-3,IP:nil,URL:11|83|1,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 ,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: d2a721b4fa6311f0b0f03b4cfa9209d1-20260126 X-User: jiangfeng@kylinos.cn Received: from [10.42.12.56] [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_128_GCM_SHA256 128/128) with ESMTP id 1839964530; Mon, 26 Jan 2026 11:05:09 +0800 Message-ID: <9ea5656b-2520-4057-9e4c-e4a8db947598@kylinos.cn> Date: Mon, 26 Jan 2026 11:05:06 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] riscv: lib: optimize strlen loop efficiency To: Paul Walmsley Cc: 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 References: <20251218032614.57356-1-jiangfeng@kylinos.cn> <581a8707-cb16-46d9-b6b5-8fa267383318@kylinos.cn> <4cd1d9d1-34da-7d96-46ac-a5470cfa85c3@kernel.org> Content-Language: en-US From: Feng Jiang In-Reply-To: <4cd1d9d1-34da-7d96-46ac-a5470cfa85c3@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2026/1/24 16:14, Paul Walmsley wrote: > 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? > Thanks for queuing this! I am definitely planning to study David's suggestions. He has also provided a lot of valuable feedback on my other patch series, and I will explore further improvements for a follow-up patch. -- With Best Regards, Feng Jiang