From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout05.his.huawei.com (canpmsgout05.his.huawei.com [113.46.200.220]) (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 B67F92030A for ; Wed, 15 Apr 2026 07:39:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.220 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776238768; cv=none; b=kWTm/DszSOK2TJZihQZPlNOCtdWsFPUNZC+o0KkResldymRCToA05ri/SiPZD+6p/+ENJvtT7ugK6vCQSUH/aoorRhhmITlhQpaiH10IhzlksY5fiqVHzs0Z2730LhaWlxbL3v6nTjuQZLWWcXnq15NqhczkvI89LbrRNoT3z+8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776238768; c=relaxed/simple; bh=96IOML1iwMAGe8Z3LmotSH3S7/2UQnT2kxcTn98nH3M=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=fFLXaaBxfz/ZbqycLMHDDSmXGpr8EbTDM0hIni/lhWWwLlYLUli0S1cPMj+RIPUnhlVPfaBdaDa6Zh0hImhPLGgzhSyqektqemfGyLsmUOcY0bYymDrlj3fEJGx3WguflxL91vgDZ0rNyFR/6RVGoHQ+Nd1d7kZRCHqz7HbOqxg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=Spq8wimf; arc=none smtp.client-ip=113.46.200.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="Spq8wimf" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=xAWH0vekplqg9nKMnqwmGFbsAKMeVxmaVE/r2NQ6tWM=; b=Spq8wimfX+GEz3itMSWWENVE0jwLWbCxck9n4vTjj73DCnsqBFzZZz+uXAq+QJZdmILzLO5ET acBpYA9cbA8Bu6uV6BViDS2W0Iwz8n2EXzxZhBL7DZLoc9w84Ns+hpWtpRrBOcjNBnMPrykKxgo tJn4MH/ywgvLXqGbtwHVMEg= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout05.his.huawei.com (SkyGuard) with ESMTPS id 4fwXtM00F7z12LJC; Wed, 15 Apr 2026 15:32:58 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 0812640576; Wed, 15 Apr 2026 15:39:17 +0800 (CST) Received: from [10.67.109.254] (10.67.109.254) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 15 Apr 2026 15:39:16 +0800 Message-ID: <87e0da16-2953-47b6-b6d7-329873c22248@huawei.com> Date: Wed, 15 Apr 2026 15:39:12 +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] arch/riscv: Add bitrev.h file to support rev8 and brev8 To: CC: , , , , , , References: <150bfb90-ec49-7209-b841-2e48ca12b370@huawei.com> <20260413122817.122787-1-cp0613@linux.alibaba.com> From: Jinjie Ruan In-Reply-To: <20260413122817.122787-1-cp0613@linux.alibaba.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To dggpemf500011.china.huawei.com (7.185.36.131) On 4/13/2026 8:28 PM, cp0613@linux.alibaba.com wrote: > On Sat, 11 Apr 2026 10:48:17 +0800, ruanjinjie@huawei.com wrote: > >>>> +#include >>>> +#include >>>> +#include >>>> + >>>> +extern u8 const byte_rev_table[256]; >>>> +static __always_inline __attribute_const__ u32 __arch_bitrev32(u32 x) >>>> +{ >>>> + if (IS_ENABLED(CONFIG_RISCV_ISA_ZBKB) && >>>> + riscv_has_extension_likely(RISCV_ISA_EXT_ZBKB)) { >>>> + unsigned long result = x; >>>> + >>>> + asm volatile( >>>> + ".option push\n" >>>> + ".option arch,+zbkb\n" >>>> + "rev8 %0, %0\n" >>>> + "brev8 %0, %0\n" >>>> + ".option pop" >>>> + : "+r" (result) >>>> + ); >>>> + >>>> + if (__riscv_xlen == 64) >>>> + return (u32)(result >> 32); >>>> + >>>> + return (u32)result; >>>> + } >>>> + >>>> + return (u32)byte_rev_table[x & 0xff] << 24 | >>>> + (u32)byte_rev_table[(x >> 8) & 0xff] << 16 | >>>> + (u32)byte_rev_table[(x >> 16) & 0xff] << 8 | >>>> + (u32)byte_rev_table[x >> 24]; >>>> +} >>> >>> Hi Jinjie, >>> >>> Thanks for your patch. I have two suggestions. >>> 1. When ZBKB is not supported, is it simpler to directly use the generic >>> implementation __bitrev32 in . >> >> Actually, you can't simply use the default implementation from >> linux/bitrev.h. It includes asm/bitrev.h (the architecture-specific >> implementation), which would lead to compilation issues. Furthermore, >> when ZBKB is not supported, current implementation is identical to the >> default one. > > Understood. So, have you considered renaming the function to `generic_xxx`, > like `generic___ffs` in bitops? You are right! I'll try doing it this way. > >>> 2. Could you please provide a benchmark test case to illustrate the >>> performance comparison with and without this extension (refer to >>> test_bitops.c) and also provide the results by bloat-o-meter. >> >> I don't have access to RISC-V hardware at the moment, so I've only >> performed basic functional testing on QEMU, which completed without >> issues,could you please help run some benchmarks to verify the performance? > > I don't currently have the hardware that supports the corresponding extension, > but I can test it using an FPGA environment when I have the opportunity (it > will take some time). Thank you very much! > >> Thanks, >> Jinjie >> >>> >>> Thanks, >>> Pei > > Thanks, > Pei