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 D25E7428AF; Wed, 5 Apr 2023 10:45:07 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 67AF741153; Wed, 5 Apr 2023 10:45:07 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id B577E41151 for ; Wed, 5 Apr 2023 10:45:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680684305; x=1712220305; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=jKvAY+zrRtCIqtsdpARg3UAYbNVD7zcjT0NXaAcvDds=; b=GXxe3xjLUWlsyd0G1Fw3p3/aJNxou67PJMa/+5u8jR/zz+ZX92GYButm zr9AEi/4k1t9r4+2EEFNBo0vbDC90wsjk10+o63HxfRtl6nsVnQxa7+D5 1eDhSNrOdhCOoQqXCYmKA63p7WyXUU0b/dtMW5dSFB3eszoXMoR78okgm KFTnmB0+tPQyUNm0F5L0hZDBlFpF1QEYxyPTkBLS/bAnwzjtuGbu+e6ph wasjaJrLgdB/ptPw6An728Kkel6s+q8+Bkms8bNMd4Px3bzRaW+lcDdYf 3si2XBKJ1RYlb/Z15NWKvtFa6iLNePLdmBLO4rYh2/9CDdzSZj9HgRrLv w==; X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="344115527" X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="344115527" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2023 01:45:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="1016398318" X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="1016398318" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmsmga005.fm.intel.com with ESMTP; 05 Apr 2023 01:45:04 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Wed, 5 Apr 2023 01:45:03 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Wed, 5 Apr 2023 01:45:03 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21 via Frontend Transport; Wed, 5 Apr 2023 01:45:03 -0700 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (104.47.56.48) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.21; Wed, 5 Apr 2023 01:45:03 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XTrBMLkU7CCtuFaQL5qW/FULWxWWaPibuY0E/jFrMJrnbQZv1yLOaaAY37A1ehT8WBKj3bRk9FmYxgyOA/eGuIqnBipTfV2R9l60RYAksxnoL51JwBsj6oLMGaL6qMgroBeWyu6/e1M4JWFKKcMzXX1bDCqwmHEmwI6gz2MAp7IKXLxQ1E9fhJPbC/aFxJmpmy3eYyHNvKDHpRk/iE6bMMNdvNyq/qzSjI+B60aHiJPXPv38mGdDvHTCyUfqAbZXAe2KnjFjRLFARXjlHBxpWm3Q26aaEP8xTKLv8bUPEQ4nOUllZFLBYo2vAInGDNBgWcQJ7jFz/CAZtRltYuecIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Y4clDqVke1UpstmuP39G2pa+m/R0PuxCoA5V3UGtfCU=; b=AuZ6JiKRi/cL3MTX+Hr3Niy0LHXpFOBrmWHQvXq80JSwD9J1uafr/G5M1RrPVK0NwKCmJPTeXnfLwHT8sO/YQM3R1tmoHrB5CKIhBzvsEIRJ7FDbehvp+wxDxJi89R7i0B47gtBMgPgv5vyD24pBzMJswBORokuB+6ZlkCfmRNJ4f1Uat4iQVGR5d6iOqFIf7Fhm1nblJ+lSdwYdX1p8wktFppUeOU4Eek3WvVgad1PEy0EH96cXcLKYWITNqMsXmqE6TbF6A2l8WZkXzw8fjrZHqWyui5g0rZaTFfSuD7PJ8pCdvhEfm5JUsCyA2TDkONwNsenzcvAhCejhsvZHiA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) by SJ2PR11MB7501.namprd11.prod.outlook.com (2603:10b6:a03:4d2::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.35; Wed, 5 Apr 2023 08:45:01 +0000 Received: from DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::18d0:ac53:aa1d:d19c]) by DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::18d0:ac53:aa1d:d19c%6]) with mapi id 15.20.6254.035; Wed, 5 Apr 2023 08:45:01 +0000 Date: Wed, 5 Apr 2023 09:44:54 +0100 From: Bruce Richardson To: Tyler Retzlaff CC: Morten =?iso-8859-1?Q?Br=F8rup?= , , , Subject: Re: [PATCH v2 1/2] eal: provide leading and trailing zero bit count abstraction Message-ID: 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> <20230404212322.GA3609@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230404212322.GA3609@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> X-ClientProxiedBy: LO4P123CA0420.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18b::11) To DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7309:EE_|SJ2PR11MB7501:EE_ X-MS-Office365-Filtering-Correlation-Id: fee460b8-e176-454d-6f8e-08db35b20b05 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7mXqL8YP+ycYYmdKk+tloFA53S/5iVMXhJAsURKsrqM+QsHjuDyWd9KEpNBpVgM+5ogxu+F+gR6e/e6EJPQQqJRffRgiDEel84BAHrHyA947gDBt0Rds3MAHhHXPysrHSi4HSHNZYUHvkj+GJyvI3/OfcTd10La/NSVX8RqV4sdLrydQHz1j9S29O8I74WHEmQ77KKfqlLIRB7z6Z1HQ5GTgDihfF3iQ2oNzEkoPRS+PL3SQBhJ9eJEmPeB7MHLw4w+ANeLMWyFADDSt/tA/s7XH04b7UlMGrJum+fy00qJcYEYfbsunNpMyisJ40mtt8dbYknCdyaKeltEm/oYsDrFH/B3igIf6wuZDavLcodLfRtKpBaOAllUqG96NzkYsVRuxGYW58JWXVsG7dg5S4qVEah30l15LgjPbx49SGP6Ex0bNd8IGmKl0U4SxJZ6QZJUpBZjw0p6W0XN/PZqclla72rDgDL4X6HrBaQ8529fDFULNj8NVBd5lHSDh2TgAGJ6h69Zqbc/GTasEX0R2S/CyObKFwvptSUwAJrVIcC6asq5XrSp8Eeau01K2TG3n X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7309.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(376002)(136003)(366004)(346002)(396003)(39860400002)(451199021)(83380400001)(82960400001)(5660300002)(38100700002)(66556008)(66476007)(66946007)(8676002)(4326008)(6916009)(66574015)(44832011)(8936002)(2906002)(41300700001)(478600001)(86362001)(45080400002)(186003)(316002)(6666004)(6512007)(6506007)(6486002)(26005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?N7c29cQzPgCSDNXhNYh5cAYlImq/3AyVsojPIwoU4YuPsBM1kbgCpvGznu?= =?iso-8859-1?Q?+8e6aVXOiTOntCpLArH3WtE/CTekmY+xoMK2BioMqgKs7Qqtd9PjkJJEuT?= =?iso-8859-1?Q?a/kS2n5j/Wnyofyd0CVKIdPq1mS3tLp+Gl8oBwZUmW35lu8R1KpTQn9Peb?= =?iso-8859-1?Q?YOWkfOBTolzUd6L/dnL2eqbN38Li5GaYaGC5oLP4IAMGO8rv4tKv54bl73?= =?iso-8859-1?Q?F1z70VJ5Vp+q5lGnWDjxZuaJCv9DYQePBsgIahs6ikf/iWDAtSdAKYKshj?= =?iso-8859-1?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HvvR5?= =?iso-8859-1?Q?Tm9m1EqKjB2TW8hbfbvfLrg0ncKEQL2mt9uLzbC+2VwIBDIdtWpXNjYSwj?= =?iso-8859-1?Q?Ua0I+h4Ay2LDYsqfohFm1ZwuldOXUM4zwLYq+Uzyokf5TCoOS/I37pNlxq?= =?iso-8859-1?Q?UiOtRrriLKxqji5nFntku2xy6edzOPRZAQ648BRedjZWVncFTpBZsIdRWr?= =?iso-8859-1?Q?K3vNnb3lI1N5x9jIjPtPkMFZ4vM3omTwRYtUQpbQj7UBgdMr1ciVvjOy3y?= =?iso-8859-1?Q?ElqpPaopkfbpc68CA4n8P0tIElNbMRY0/i4aps3b2AXr9eYukwkr5CI2Fg?= =?iso-8859-1?Q?T+xCDUMl/VtRD2pnZUjrRwEgTUAJz2crS5g5cTytYGTyTXI5HRQ0lUV4VZ?= =?iso-8859-1?Q?XbxUSLkHqFJMePe0JXi6eZssj59eRiwe9wXzh1sXG5iH2KtMup4+FEgErW?= =?iso-8859-1?Q?fRnVOMrY1Nbz0cWUmyOlFrR/MTPBrv278flqpchxhkeTy3IZrMl7cDLA?= =?iso-8859-1?Q?=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: fee460b8-e176-454d-6f8e-08db35b20b05 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7309.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2023 08:45:01.1082 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: MvGlg4tY0r2P/8aku57bVxzO1E77mhfLXYSqb6O6zFAzD5vnhUwUowGbC90hMN5D15Z6QmZ1ur54vcUK13aL8IFnHyo0UQCWxOfhI9+0Lfc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR11MB7501 X-OriginatorOrg: intel.com 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 Tue, Apr 04, 2023 at 02:23:22PM -0700, Tyler Retzlaff wrote: > 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? > Yes, promotion will happen, but I still think that the 32 and 64 versions are far clearer here in all cases. Anyone looking at the code will recognise that the result will be the leading zero count of a 64-bit number irrespective of the type actually passed in. It's less confusing now IMHO. /Bruce