From: "Linus Probert" <linus.probert@gmail.com>
To: "Linus Probert" <linus.probert@gmail.com>,
"Robert P. J. Day" <rpjday@crashcourse.ca>,
"Kernel Janitors List" <kernel-janitors@vger.kernel.org>
Subject: Re: more potential janitor work: simplifying test for power of 2
Date: Thu, 02 Apr 2026 11:50:48 +0200 [thread overview]
Message-ID: <DHIKQUBU2MZS.IOSIJB5DJYJ0@gmail.com> (raw)
In-Reply-To: <DHHT7K60IORC.2DG3PT7PB2OSO@gmail.com>
I took a closer look at this. Many of the occurences here are actually
used to check if a binary flag has more then one bit set. This is quite
a common pattern.
Eg. 'if (a & (a - 1))' would pass if a = 0b100, not if a = 0b110. Since:
0b100 - 0b001 = 0b011 -> (0b100 & 0b011) => false
0b110 - 0b001 = 0b101 -> (0b100 & 0b101) => true
The power of two check would 'normally' use the negation:
'if (!(a & (a - 1)))'
Just a heads up so anyone else reading this doesn't go blindly swapping
out this pattern for 'is_power_of_2()'.
You need to apply some thinking. No 'sed' work.
Br,
Linus
next prev parent reply other threads:[~2026-04-02 9:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 11:49 more potential janitor work: simplifying test for power of 2 Robert P. J. Day
2026-04-01 12:16 ` Linus Probert
2026-04-02 9:50 ` Linus Probert [this message]
2026-04-02 10:07 ` Julia Lawall
2026-04-02 11:57 ` Linus Probert
2026-04-02 12:40 ` Robert P. J. Day
2026-04-02 13:04 ` Linus Probert
2026-04-02 13:21 ` Robert P. J. Day
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=DHIKQUBU2MZS.IOSIJB5DJYJ0@gmail.com \
--to=linus.probert@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=rpjday@crashcourse.ca \
/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