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 323DD428BC; Tue, 4 Apr 2023 23:23:26 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B7B6440EE3; Tue, 4 Apr 2023 23:23:25 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id AC90840A7E for ; Tue, 4 Apr 2023 23:23:23 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id EE62F210DDBA; Tue, 4 Apr 2023 14:23:22 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com EE62F210DDBA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1680643402; bh=4jpZW64BQSQqcZ0co+p8Lj42V6a1KFKfH/pAGK7LxnE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MTba9Hskz3G/cGuqOZDiZFcghYreymN2SGJgZmYGCvwpEzKZSjK0sRYkicXu25QGk h9j59eNoFvbuoir+v77SkI3feArfvOhvZEfwUXPkNsRsymrW9cLtqtRtGWd3Hi5ev7 B7roVxCDlanQB9Vh/SiL8ApSipx7i7kwamXPxr0I= Date: Tue, 4 Apr 2023 14:23:22 -0700 From: Tyler Retzlaff To: Morten =?iso-8859-1?Q?Br=F8rup?= Cc: dev@dpdk.org, david.marchand@redhat.com, thomas@monjalon.net Subject: Re: [PATCH v2 1/2] eal: provide leading and trailing zero bit count abstraction Message-ID: <20230404212322.GA3609@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> 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> <98CBD80474FA8B44BF855DF32C47DC35D87624@smartserver.smartshare.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35D87624@smartserver.smartshare.dk> User-Agent: Mutt/1.5.21 (2010-09-15) 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 On Thu, Jan 05, 2023 at 08:09:19AM +0100, Morten Brørup wrote: > > From: Tyler Retzlaff [mailto:roretzla@linux.microsoft.com] > > Sent: Thursday, 24 November 2022 00.43 > > > > Provide an abstraction for leading and trailing zero bit counting > > functions to hide compiler specific intrinsics and builtins. > > > > 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 > > > > 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 += include_directories('.') > > > > headers += 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) so i just noticed this, but sometimes these functions receive size_t so naming them specifically 32/64 bit becomes problematic because are going to end up with promotion on sizeof(size_t) == sizeof(long) == 4 platforms. i.e. size_t s = ...; x = rte_clz64(s); // assume 64-bit today this code is now broken because on 32-bit platform s will get promoted and the extra 32 zero-bits will be returned in the result breaking calculations. any thoughts? should we go back to l, ll? ty