BPF List
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Matt Bobrowski" <mattbobrowski@google.com>,
	"Emil Tsalapatis" <emil@etsalapatis.com>
Cc: <bpf@vger.kernel.org>, <ast@kernel.org>, <andrii@kernel.org>,
	<memxor@gmail.com>, <daniel@iogearbox.net>, <eddyz87@gmail.com>,
	<song@kernel.org>
Subject: Re: [PATCH bpf-next v8 2/8] selftests/bpf: Add basic libarena scaffolding
Date: Sun, 26 Apr 2026 11:42:09 -0700	[thread overview]
Message-ID: <DI3B2QZ8TA16.V0ZDKK2KS7MB@gmail.com> (raw)
In-Reply-To: <aenXSvDSN98azW_T@google.com>

On Thu Apr 23, 2026 at 1:24 AM PDT, Matt Bobrowski wrote:
>> +
>> +int arena_fls(__u64 word)
>> +{
>> +	unsigned int num = 0;
>> +
>> +	if (!word)
>> +		return 0;
>> +
>> +	if (word & 0xffffffff00000000ULL) {
>> +		num += 32;
>> +		word >>= 32;
>> +	}
>> +
>> +	if (word & 0xffff0000) {
>> +		num += 16;
>> +		word >>= 16;
>> +	}
>> +
>> +	if (word & 0xff00) {
>> +		num += 8;
>> +		word >>= 8;
>> +	}
>> +
>> +	if (word & 0xf0) {
>> +		num += 4;
>> +		word >>= 4;
>> +	}
>> +
>> +	if (word & 0xc) {
>> +		num += 2;
>> +		word >>= 2;
>> +	}
>> +
>> +	if (word & 0x2)
>> +		num += 1;
>> +
>> +	return num + 1;
>> +}
>
> What's your reason for not using something like __builtin_clzll()
> instead here, for example:
>
> int arena_fls(u64 word)
> {
> 	if (!word)
> 		return 0;
>
> 	return 64 - __builtin_clzll(word);
> }

Great suggestion. If it works, let's adopt __builtin_*

  reply	other threads:[~2026-04-26 18:42 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-21 16:50 [PATCH bpf-next v8 0/8] Introduce arena library and runtime Emil Tsalapatis
2026-04-21 16:50 ` [PATCH bpf-next v8 1/8] selftests/bpf: Add ifdef guard for WRITE_ONCE macro in bpf_atomic.h Emil Tsalapatis
2026-04-23  8:27   ` Matt Bobrowski
2026-04-21 16:50 ` [PATCH bpf-next v8 2/8] selftests/bpf: Add basic libarena scaffolding Emil Tsalapatis
2026-04-21 20:08   ` sashiko-bot
2026-04-23  8:24   ` Matt Bobrowski
2026-04-26 18:42     ` Alexei Starovoitov [this message]
2026-04-26 18:58       ` Emil Tsalapatis
2026-04-21 16:50 ` [PATCH bpf-next v8 3/8] selftests/bpf: Move arena-related headers into libarena Emil Tsalapatis
2026-04-21 16:50 ` [PATCH bpf-next v8 4/8] selftests/bpf: Add arena ASAN runtime to libarena Emil Tsalapatis
2026-04-21 20:48   ` sashiko-bot
2026-04-21 16:50 ` [PATCH bpf-next v8 5/8] selftests/bpf: Add ASAN support for libarena selftests Emil Tsalapatis
2026-04-21 21:15   ` sashiko-bot
2026-04-21 16:50 ` [PATCH bpf-next v8 6/8] selftests/bpf: Add buddy allocator for libarena Emil Tsalapatis
2026-04-21 17:52   ` bot+bpf-ci
2026-04-21 17:56     ` Emil Tsalapatis
2026-04-21 21:42   ` sashiko-bot
2026-04-23  8:44   ` Matt Bobrowski
2026-04-23 14:00     ` Kumar Kartikeya Dwivedi
2026-04-23 16:43       ` Emil Tsalapatis
2026-04-23 20:24         ` Matt Bobrowski
2026-04-24 15:25           ` Emil Tsalapatis
2026-04-21 16:50 ` [PATCH bpf-next v8 7/8] selftests/bpf: Add selftests for libarena buddy allocator Emil Tsalapatis
2026-04-21 21:57   ` sashiko-bot
2026-04-21 16:50 ` [PATCH bpf-next v8 8/8] selftests/bpf: Reuse stderr parsing for libarena ASAN tests Emil Tsalapatis
2026-04-21 22:16   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DI3B2QZ8TA16.V0ZDKK2KS7MB@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=mattbobrowski@google.com \
    --cc=memxor@gmail.com \
    --cc=song@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox