From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3D2DAA00C2; Thu, 5 Jan 2023 08:09:22 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D3C7C400D4; Thu, 5 Jan 2023 08:09:21 +0100 (CET) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id AB6BB40041 for ; Thu, 5 Jan 2023 08:09:20 +0100 (CET) Content-class: urn:content-classes:message Subject: RE: [PATCH v2 1/2] eal: provide leading and trailing zero bit count abstraction MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Thu, 5 Jan 2023 08:09:19 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.5 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35D87624@smartserver.smartshare.dk> In-Reply-To: <1669246997-30592-2-git-send-email-roretzla@linux.microsoft.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH v2 1/2] eal: provide leading and trailing zero bit count abstraction Thread-Index: Adj/lWPrRXHkECmlQXGtGPhvxsVEnQhPoOiA References: <1669241687-18810-1-git-send-email-roretzla@linux.microsoft.com> <1669246997-30592-1-git-send-email-roretzla@linux.microsoft.com> <1669246997-30592-2-git-send-email-roretzla@linux.microsoft.com> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "Tyler Retzlaff" , Cc: , X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org > From: Tyler Retzlaff [mailto:roretzla@linux.microsoft.com] > Sent: Thursday, 24 November 2022 00.43 >=20 > Provide an abstraction for leading and trailing zero bit counting > functions to hide compiler specific intrinsics and builtins. >=20 > Signed-off-by: Tyler Retzlaff > --- > lib/eal/include/meson.build | 1 + > lib/eal/include/rte_bitcount.h | 265 > +++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 266 insertions(+) > create mode 100644 lib/eal/include/rte_bitcount.h >=20 > diff --git a/lib/eal/include/meson.build b/lib/eal/include/meson.build > index cfcd40a..8ff1d65 100644 > --- a/lib/eal/include/meson.build > +++ b/lib/eal/include/meson.build > @@ -5,6 +5,7 @@ includes +=3D include_directories('.') >=20 > headers +=3D files( > 'rte_alarm.h', > + 'rte_bitcount.h', > 'rte_bitmap.h', > 'rte_bitops.h', > 'rte_branch_prediction.h', > diff --git a/lib/eal/include/rte_bitcount.h > b/lib/eal/include/rte_bitcount.h > new file mode 100644 > index 0000000..587de52 > --- /dev/null > +++ b/lib/eal/include/rte_bitcount.h > @@ -0,0 +1,265 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright (C) 2022 Microsoft Corporation > + */ > + > +#ifndef _RTE_BITCOUNT_H_ > +#define _RTE_BITCOUNT_H_ > + > +#include > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +#ifdef RTE_TOOLCHAIN_MSVC > + > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change, or be removed, without prior > notice > + * > + * Get the count of leading 0-bits in v. > + * > + * @param v > + * The value. > + * @return > + * The count of leading zero bits. > + */ > +__rte_experimental > +static inline unsigned int > +rte_clz(unsigned int v) > +{ > + unsigned long rv; > + > + (void)_BitScanReverse(&rv, v); > + > + return (unsigned int)rv; > +} > + > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change, or be removed, without prior > notice > + * > + * Get the count of leading 0-bits in v. > + * > + * @param v > + * The value. > + * @return > + * The count of leading zero bits. > + */ > +__rte_experimental > +static inline unsigned int > +rte_clzl(unsigned long v) Don't use l (long) and ll (long long) for names (and types), use = explicit bit lengths, 32 and 64. E.g.: rte_clz32(uint32_t v) > +{ > + unsigned long rv; > + > + (void)_BitScanReverse(&rv, v); > + > + return (unsigned int)rv; > +} > + > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change, or be removed, without prior > notice > + * > + * Get the count of leading 0-bits in v. > + * > + * @param v > + * The value. > + * @return > + * The count of leading zero bits. > + */ > +__rte_experimental > +static inline unsigned int > +rte_clzll(unsigned long long v) Same comment as above: e.g. rte_clz64(uint64_t v)