[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <495f2924138069abaf49269b2c3bd1e4f5f4362e.camel@perches.com>
Date: Fri, 03 Jun 2022 09:48:19 -0700
From: Joe Perches <joe@...ches.com>
To: Ian Rogers <irogers@...gle.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>, netdev@...r.kernel.org,
bpf@...r.kernel.org, linux-kernel@...r.kernel.org
Cc: Yuze Chi <chiyuze@...gle.com>
Subject: Re: [PATCH v2] libbpf: Fix is_pow_of_2
On Thu, 2022-06-02 at 22:57 -0700, Ian Rogers wrote:
> On Thu, Jun 2, 2022 at 10:52 PM Ian Rogers <irogers@...gle.com> wrote:
> > From: Yuze Chi <chiyuze@...gle.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
Powered by blists - more mailing lists