From: Linus Torvalds <torvalds@linux-foundation.org>
To: Yury Norov <yury.norov@gmail.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Tariq Toukan <tariqt@nvidia.com>,
Valentin Schneider <vschneid@redhat.com>,
linux-rdma@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [GIT PULL] bitmap changes for v6.2-rc1
Date: Fri, 23 Dec 2022 11:07:03 -0800 [thread overview]
Message-ID: <CAHk-=wgrzisX2_MCcw3Qqa0J3d7mL14aab9F0JkjGF=VfAk5Ow@mail.gmail.com> (raw)
In-Reply-To: <CAHk-=wj_4xsWxLqPvkCV6eOJt7quXS8DyXn3zWw3W94wN=6yig@mail.gmail.com>
On Fri, Dec 23, 2022 at 10:44 AM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> Honestly, in this case, I think the logical thing to do is "check that
> the upper bits are the same". The way you do that is probably
> something like
>
> !((off) ^ ((nbits)-1) & ~(BITS_PER_LONG-1))
Note that while the above is probably correct (but you always need to
double-check my emailed "something like this" code - I literally write
it in the MUA, and I make mistakes too), I'd never want to see that as
part of one big complex macro.
In fact, I think I am missing a set of parentheses, because '&' has a
higher precedence than '^', so the above is actually buggy.
So I'd much rather see something like this
#define COMPILE_TIME_TRUE(x) (__builtin_constant_p(x) && (x))
#define bits_in_same_word(x,y) \
(!(((x)^(y))&~(BITS_PER_LONG-1)))
#define bitmap_off_in_last_word(nbits,off) \
bits_in_same_word((nbits)-1,off)
#define small_const_nbits_off(nbits, off) \
(__builtin_constant_p(nbits) && (nbits) > 0 && \
COMPILE_TIME_TRUE(bitmap_off_in_last_word(nbits,off)))
where each step does one thing and one thing only, and you don't have
one complicated thing that is hard to read.
And again, don't take my word blindly for the above. I *think* the
above may be correct, but there's a "think" and a "may" there.
Plus I'd still like to hear about where the above would actually
matter and make a code generation difference in real life (compared to
just the simple "optimize the single-word bitmap" case).
Linus
next prev parent reply other threads:[~2022-12-23 19:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-15 23:11 [GIT PULL] bitmap changes for v6.2-rc1 Yury Norov
2022-12-23 18:44 ` Linus Torvalds
2022-12-23 19:07 ` Linus Torvalds [this message]
2023-01-10 7:24 ` Yury Norov
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='CAHk-=wgrzisX2_MCcw3Qqa0J3d7mL14aab9F0JkjGF=VfAk5Ow@mail.gmail.com' \
--to=torvalds@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=netdev@vger.kernel.org \
--cc=tariqt@nvidia.com \
--cc=vschneid@redhat.com \
--cc=yury.norov@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;
as well as URLs for NNTP newsgroup(s).