Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp67915iof; Sun, 5 Jun 2022 21:20:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy16KTA0iqNmei6D/hBV+0KSlGTG9xG702Pz1MaxxNEKy5f65BgctKwYTOayQuzeAhxi0ma X-Received: by 2002:a63:6a43:0:b0:3fd:913e:9b02 with SMTP id f64-20020a636a43000000b003fd913e9b02mr6072107pgc.540.1654489249683; Sun, 05 Jun 2022 21:20:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654489249; cv=none; d=google.com; s=arc-20160816; b=JeJPUFMzfiP13tLuN9K0f96+kaQI77XYX+FEmSQ0HtENvgnzxuNBIesyZHlgrT5Lmp FibJrUD3eJgs1zSYG2gRwUBly7twTCxjqoqP1azYKR9p/nN7Pl3j6DX4LEh9hM5Lg6ze QjVLvw0KibV7bgAxksN2qa4smY3kN2BdVdgkhJn/7dZ1uPE0JTGpyb/Q7b2570ns0Js6 DlMHTKZIYVyxjJMtsNLh3/dQI3kUMC5HTex8d59oYDuDjolz9PqoIQcPSVi7/jDcLHq5 59rMrNJQT34wMoxRayklkTuzGFHyhTu+QF4nSoEqFIDmF2eAZLpRtPiB2GQ6gvrMg89m aiDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=yxT+ni5tlR9y2W/oI/aA8lUIzM7BIGmHKuZzxCt578Y=; b=X7J+uC3YzaKW92tEEF/0FB0I7hD2f2b9uWLoXezGfz+WHP0tshUTncuFeUXSItXwtp 9YpM/ex1Z4DOhlMAyPsbKSgbj07GE0vQzZLJaPbwpMVAPqiIACYiK9TQAX8sgoHOsoK1 IbGUF2eP9uGD6AXjA07vESqSiRKjU6MW/zzAEVE5LvTtQfZDHknyUbWLcdAs/wiQ6wHD g+32XbKOkIMCvs34yYM9mBQsKl+BXZUifdwmj12a8+jOU0KiCGslUgtAHR7HecvcMZYZ nsPJLjUacarnhXvNf89Mc8pgBmBX6kEkz73NcJuU0Qc/uxvCzJXZWhyAQCINF8rh5jHy 0Klg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 19-20020a631753000000b003f9f41da8casi19857886pgx.14.2022.06.05.21.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 21:20:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1676F85ECF; Sun, 5 Jun 2022 20:53:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235680AbiFCQs2 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 3 Jun 2022 12:48:28 -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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 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 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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