From: Joe Perches <joe@perches.com>
To: Ian Rogers <irogers@google.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
netdev@vger.kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: Yuze Chi <chiyuze@google.com>
Subject: Re: [PATCH v2] libbpf: Fix is_pow_of_2
Date: Fri, 03 Jun 2022 09:48:19 -0700 [thread overview]
Message-ID: <495f2924138069abaf49269b2c3bd1e4f5f4362e.camel@perches.com> (raw)
In-Reply-To: <CAP-5=fVhVLWg+c=WJyOD8FByg_4n6V0SLSLnaw7K0J=-oNnuaA@mail.gmail.com>
On Thu, 2022-06-02 at 22:57 -0700, Ian Rogers wrote:
> On Thu, Jun 2, 2022 at 10:52 PM Ian Rogers <irogers@google.com> wrote:
> > From: Yuze Chi <chiyuze@google.com>
[]
> > diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
[]
> > @@ -580,4 +580,9 @@ struct bpf_link * usdt_manager_attach_usdt(struct usdt_manager *man,
> > const char *usdt_provider, const char *usdt_name,
> > __u64 usdt_cookie);
> >
> > +static inline bool is_pow_of_2(size_t x)
> > +{
> > + return x && (x & (x - 1)) == 0;
> > +}
> > +
> > #endif /* __LIBBPF_LIBBPF_INTERNAL_H */
If speed of execution is a potential issue, maybe:
#if __has_builtin(__builtin_popcount)
return __builtin_popcount(x) == 1;
#else
return x && (x & (x-1)) == 0;
#endif
next prev parent reply other threads:[~2022-06-03 16:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-03 5:51 Ian Rogers
2022-06-03 5:57 ` Ian Rogers
2022-06-03 16:48 ` Joe Perches [this message]
2022-06-03 18:19 ` Andrii Nakryiko
2022-06-03 18:30 ` patchwork-bot+netdevbpf
2022-06-14 20:40 ` Ian Rogers
2022-06-16 21:00 ` Andrii Nakryiko
2022-06-16 21:07 ` Ian Rogers
2022-06-16 23:55 ` Andrii Nakryiko
2022-06-17 1:25 ` Ian Rogers
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=495f2924138069abaf49269b2c3bd1e4f5f4362e.camel@perches.com \
--to=joe@perches.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chiyuze@google.com \
--cc=daniel@iogearbox.net \
--cc=irogers@google.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=yhs@fb.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
all inboxes | Powered by JetHome®