From: Paul Chaignon <paul.chaignon@gmail.com>
To: Hao Sun <sunhao.th@gmail.com>
Cc: Shung-Hsi Yu <shung-hsi.yu@suse.com>,
Harishankar Vishwanathan <harishankar.vishwanathan@gmail.com>,
bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, eddyz87@gmail.com, john.fastabend@gmail.com,
martin.lau@linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] bpf: Simplify tnum_step()
Date: Thu, 19 Mar 2026 10:35:06 +0100 [thread overview]
Message-ID: <abvDSjl633b_Hb1O@mail.gmail.com> (raw)
In-Reply-To: <CACkBjsbcv4woDZZ0_BA4idBwfLPXNTX7BzJMXTH54zq_8F0BuA@mail.gmail.com>
On Thu, Mar 19, 2026 at 10:01:31AM +0100, Hao Sun wrote:
Thanks for the cc Shung-Hsi. We were discussing it with Hari who's
planning to double check soundness.
> [...]
> > > - res = w;
> > > - }
> > > - return res;
> > > + d = z - t.value;
> >
> > A bit of comment explaining would be nice.
> >
>
> The commit message is self-contained; anyone interested can git blame.
> But I am unsure. If a detailed description is preferred, I can add a
> comment to v2.
Not disagreeing about the role of git blame, but it's not a replacement
for code comments either. Having just the intuition in comments can help
a lot; as you mention below, it's one less indirection ;)
In its current form, I find the proof harder to follow than the
previous, very verbose version. Maybe there's a good middle ground?
>
> > > + carry_mask = (1ULL << fls64(d & ~t.mask)) - 1;
> > > + inc = ((d | carry_mask | ~t.mask) + 1) & t.mask;
> >
> > Maybe break out the calculation of inc, give it a name (next_submask?),
>
> Maybe we can break this down as:
>
> d = z - t.value;
> carry_mask = (1ULL << fls64(d & ~t.mask)) - 1;
> filled = d | carry_mask | ~t.mask;
> inc = (filled + 1) & t.mask;
>
> `next_submask` is not precise, as we ored `~t.mask` into it.
> It's always hard to name the intermediate result :)
>
> > and have it as preceding patch? It seems generic enough that I thought
> > would have been implemented already, but bitmap_scatter() was the
> > closest I could find.
> >
> > Perhaps could be submitted to include/linux/bitops.h in the future.
> >
>
> The calculation above is direct, adding a bitmap helper intros an indirection.
> For me, it means I would have to check out the meaning of the helper
> and then get back to understanding the algorithm.
I think I agree with Hao in this case. If we can reuse existing helpers,
great, but otherwise it's short enough that it's probably easier to keep
inlined here.
next prev parent reply other threads:[~2026-03-19 9:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-18 17:19 [PATCH] bpf: Simplify tnum_step() Hao Sun
2026-03-19 5:22 ` Shung-Hsi Yu
2026-03-19 9:01 ` Hao Sun
2026-03-19 9:35 ` Paul Chaignon [this message]
2026-03-19 13:12 ` Hao Sun
2026-03-19 13:24 ` Paul Chaignon
2026-03-20 2:04 ` Shung-Hsi Yu
2026-03-19 7:24 ` Eduard Zingerman
2026-03-19 9:02 ` Hao Sun
2026-03-19 8:17 ` Kumar Kartikeya Dwivedi
2026-03-19 9:06 ` Hao Sun
2026-03-19 17:38 ` Eduard Zingerman
2026-03-19 19:41 ` Hao Sun
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=abvDSjl633b_Hb1O@mail.gmail.com \
--to=paul.chaignon@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=harishankar.vishwanathan@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=shung-hsi.yu@suse.com \
--cc=sunhao.th@gmail.com \
/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