From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (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 4F1F01DDC37 for ; Mon, 13 Apr 2026 12:28:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776083313; cv=none; b=RPTO+/QD6brsvfSFIKtF6o6XAQrMfTX/xpRv3Ph8GwM5eEAMEfs+78PMUGOQbAdGjA8Ydx/pN1lnek7cQf2OJxVCZ8LJ8/Dbs1n3we0iknCCA2l8VF5ISSMNE29Jo7sB7ZpZ5mxmpRNbzq/tFLbbVhtuESTa+P0rfgANjUZI/RE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776083313; c=relaxed/simple; bh=80ea9P6/mLI8JZ/fvKvsYRM+djn8vxfLU6xPJczEBsk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Rolk4Vh0ps1HV2IFFiD5RBdKXgm46pDBJfxHSPEBuk0RlFfxs37aAGxcMfLaqOHhxVkn08vK6hkodYRNU2MRAjs1bpdDOaopwjFxt0rwfcgqoPAL+S0pF/2MAbp3PPVDpZuu9Z13oT7QpsClQTjK1QOIPRuPp0T0/+1Pw//I7Ak= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=Vv6ZXiO+; arc=none smtp.client-ip=115.124.30.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="Vv6ZXiO+" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1776083301; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=wYII3Ksz2fg1G45RMgbv8mkA1HCfi+jV7DWNQ4c4WQM=; b=Vv6ZXiO+U0sGUH+o50XT1yOc5SrVGheiSefoAkmCjr20yfOWKbDrubZrqV9z0xOW2/yeXMGz7VDhJThQboM7lhAoxLpKxVRun5J4GdJ6bQTCt6hJLGqRSqH8A8l687nsNn2Vurez4p1tXKcLG0lEg6ZYvYZCrBfNurHHVdr19EI= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=cp0613@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0X0wlKvf_1776083296; Received: from DESKTOP-S9E58SO.localdomain(mailfrom:cp0613@linux.alibaba.com fp:SMTPD_---0X0wlKvf_1776083296 cluster:ay36) by smtp.aliyun-inc.com; Mon, 13 Apr 2026 20:28:20 +0800 From: cp0613@linux.alibaba.com To: ruanjinjie@huawei.com Cc: akpm@linux-foundation.org, alex@ghiti.fr, aou@eecs.berkeley.edu, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, palmer@dabbelt.com, pjw@kernel.org Subject: Re: [PATCH] arch/riscv: Add bitrev.h file to support rev8 and brev8 Date: Mon, 13 Apr 2026 20:28:08 +0800 Message-ID: <20260413122817.122787-1-cp0613@linux.alibaba.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <150bfb90-ec49-7209-b841-2e48ca12b370@huawei.com> References: <150bfb90-ec49-7209-b841-2e48ca12b370@huawei.com> 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=y Content-Transfer-Encoding: 8bit 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? > > 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). > Thanks, > Jinjie > > > > > Thanks, > > Pei Thanks, Pei