From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E56F6C43334 for ; Fri, 3 Jun 2022 16:48:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344076AbiFCQs3 convert rfc822-to-8bit (ORCPT ); Fri, 3 Jun 2022 12:48:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238986AbiFCQs0 (ORCPT ); Fri, 3 Jun 2022 12:48:26 -0400 Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F5A54D62E for ; Fri, 3 Jun 2022 09:48:24 -0700 (PDT) Received: from omf16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 839042171B; Fri, 3 Jun 2022 16:48:22 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf16.hostedemail.com (Postfix) with ESMTPA id 2C8C620018; Fri, 3 Jun 2022 16:48:20 +0000 (UTC) Message-ID: <495f2924138069abaf49269b2c3bd1e4f5f4362e.camel@perches.com> Subject: Re: [PATCH v2] libbpf: Fix is_pow_of_2 From: Joe Perches To: Ian Rogers , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yuze Chi Date: Fri, 03 Jun 2022 09:48:19 -0700 In-Reply-To: References: <20220603055156.2830463-1-irogers@google.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.1-0ubuntu1 MIME-Version: 1.0 X-Stat-Signature: rzbx35joaqpa7bowsa6rnrkez3mwwwaa X-Rspamd-Server: rspamout06 X-Rspamd-Queue-Id: 2C8C620018 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1984zn9Oltf4R7aHUeyWpSPbJhORpgNnjg= X-HE-Tag: 1654274900-542024 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2022-06-02 at 22:57 -0700, Ian Rogers wrote: > On Thu, Jun 2, 2022 at 10:52 PM Ian Rogers wrote: > > From: Yuze Chi [] > > 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