From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout04.his.huawei.com (canpmsgout04.his.huawei.com [113.46.200.219]) (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 26CC19475 for ; Sat, 11 Apr 2026 02:48:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.219 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775875708; cv=none; b=myEXApD4UbumfO02muqi9+S4L6ifib9BfY2+WnE2MHbIxWzyr74rFHv0jBcrFOQNxdUOLwvhsTHeDjFCh2/iUr85dJaBB70d6FN+rAdmB4oSXxOazwfKO8DwkkG6w88T1s6Qr+vIOxKhAKI7x9pMh9IuvZkE218/mypX1l/oiQQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775875708; c=relaxed/simple; bh=Q4YHR4n8U8eVTTOgSjHzgvPrvK8LPy+Ek7dveGSDvNY=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=JDggvTq/8d1vIvMm+HObWyUceo+TIFbOmFPzY6tgXHs+5OH7wKZYG6DVUnEOudJHN0lHbXTV0TEK7Pdpr7KLtmBDKN5J4wFVpZ27TdT2Dp/WIxWcj1iKvbWdtx53E7OHsB+Bj1IF7/664ClE17ZyfQoxjbdeBHvw7NVQLcj81Bw= 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=cIsx1vgI; arc=none smtp.client-ip=113.46.200.219 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="cIsx1vgI" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=BuqkuhI7invXrca0LHnb6xj/OsMe2PYfRhrfO9jbiOE=; b=cIsx1vgIK1YFOSAUHvZ7V+SrcynrMmulInNp78TsSP05n1rGQM205Qv5h3aI+jE7A+iw7mp0D q2zpPVWa+p7Cp1SUQb7RNXESOMTlBMEw5KyLXgxV+giBKml/3lj4TozPxYgXQULvWN+kd1mnnO9 GZ57lvk6eacHajU5EYUrwqs= Received: from mail.maildlp.com (unknown [172.19.162.140]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4fsycX2y76z1prL5; Sat, 11 Apr 2026 10:42:04 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id F0AC8203BC; Sat, 11 Apr 2026 10:48:22 +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; Sat, 11 Apr 2026 10:48:22 +0800 Message-ID: <150bfb90-ec49-7209-b841-2e48ca12b370@huawei.com> Date: Sat, 11 Apr 2026 10:48:17 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH] arch/riscv: Add bitrev.h file to support rev8 and brev8 Content-Language: en-US To: CC: , , , , , , References: <20260311071344.3305640-1-ruanjinjie@huawei.com> <20260410113640.106730-1-cp0613@linux.alibaba.com> From: Jinjie Ruan In-Reply-To: <20260410113640.106730-1-cp0613@linux.alibaba.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To dggpemf500011.china.huawei.com (7.185.36.131) On 2026/4/10 19:36, cp0613@linux.alibaba.com wrote: > On Wed, 11 Mar 2026 15:13:44 +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. > 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? Thanks, Jinjie > > Thanks, > Pei