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 07400428D4; Wed, 5 Apr 2023 17:51:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E1CC341156; Wed, 5 Apr 2023 17:51:54 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id 1A6D241153 for ; Wed, 5 Apr 2023 17:51:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680709912; x=1712245912; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=MZj0b9XX5IETwRodMDWsd+J+UfjrUtVvoE/wg0sThJc=; b=ccyjjUsVSwPiMZO/yHiZS97rcAMjHbjF44SLsvIjGePhn9aBLjI8HtTh bt2hnfbXwtSlSXHOOImueiaDqP04pMTWUbDFVQG5xqvijbc7CqPd71p7g G2fptbmVjzO3PpHgJamuvqW7/LjwynFBROImuaO4O+6C+rQGcFIEj290N TX/KZ9TG7YAWmj84IGtEmJHxdRGiZyVnO9wsadJ8LcM1XnRPO/pwcrX4T PZga+Tm8ikOmKCz+YQgk/CvalfifzpDiSemBS07yUIjBuhio5Z6yYWp4K zdpqtZKulDkyZ589aX9z0lkHglSF0cX5K6osh6Kl2FaRl3YAgSV67XJcu A==; X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="428776965" X-IronPort-AV: E=Sophos;i="5.98,321,1673942400"; d="scan'208";a="428776965" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2023 08:51:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10671"; a="719371787" X-IronPort-AV: E=Sophos;i="5.98,321,1673942400"; d="scan'208";a="719371787" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orsmga001.jf.intel.com with ESMTP; 05 Apr 2023 08:51:50 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX602.amr.corp.intel.com (10.22.229.15) 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 08:51:49 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx610.amr.corp.intel.com (10.22.229.23) 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 08:51:49 -0700 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.44) by edgegateway.intel.com (134.134.137.103) 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 08:51:49 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fSB1W1CBKhMsBHfVbU6OK18MKNgqqOTImNPNxPcUeck3xl+kUY5wILiNg3ybwh4uFOsVemT2xVhR5OqZb3ixLNIg+n6tBH82PgOPu4ruIocwNzG2oLosdAP4r9O+NQJtnQbWliH7tU66RL4C7Org+9J9dlOT3QrwZ6ALbxF9LFVqtYRYMiHW3jbQDKOKPaUjjeRS/nQi5WbqfeV9YUEYxk0W78z99fr1a8v51uMxzt49UJ2KCrUV3gbkv7z0TybeWo0O+TDFBIIq1bW2YCVrYzerVELO6f4fapkTb0RUbJmP6HGmwpbT3wvOnWWjdh/TcgBsWuCnYMNuTG6afBjjJw== 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=x5uMdIl/a1hRIz7snetm/HofcRD6SOKXiOaEi79dRrc=; b=SSN5UXXTlgJ7ROTCOCN7IrfMMpI6Xb5bJbs8fNF2mS7q5bR4R/eXcJzPX4ATR7p7oOZd6ItAUqWIAPdsTpi1fgkDVaaSnQasajhujvyXHCHYdNlFrQwGWLnvpTHB49jczjpH5gGmXf/oGRR/veqZsuU2K0OXDlspokDJJMn3Xoup/hsLJALgjTRSv/HcY1rqA4Hq0TJuYnxDUdgYd5DYEoW0Ei3TGusuVzhOjPVI6oegx1jK0cQEYKH2wz4ODJIzNRHMaJsCh49pnj8UxcigA0/b2wsiAHVbgE0ylPbiFpaJS9M71Cl8qnCZvqN6lLPEIPaMOaGE28nNIyQl3daVJw== 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 PH0PR11MB7472.namprd11.prod.outlook.com (2603:10b6:510:28c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.30; Wed, 5 Apr 2023 15:51:48 +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 15:51:48 +0000 Date: Wed, 5 Apr 2023 16:51:42 +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> <20230405152216.GA28418@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230405152216.GA28418@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> X-ClientProxiedBy: LO4P123CA0657.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:316::6) To DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7309:EE_|PH0PR11MB7472:EE_ X-MS-Office365-Filtering-Correlation-Id: a785217b-85fe-41a4-c145-08db35eda9e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Wv+tR6xb1y6izigVLqg6m6ttFf2wc1QBmBO8vYxCHwQkyb0cTzkfrOP09P4D2pMxDqQvXM6KWsLIfZgzRddfdIvMdLQD7nysZXEJ5x7gsVmUueF4AkezKiGTN4Bmi00T5dyCruuYtZUVqe+wXFLJjpR+5i1eIOGtSZ00rKR7t7T6asU1G1zmFfprkiXGwjSZYkSO8tDg31+0lvMkwxqOme4S7JEkjQ6fl4HBxT585cP2TRcX5uQMvR2PcqWxxd14L66+NqFtZhhNXtb1s8bzveapK1uTgnBPnSHLWpg7AdEVBBtdh6RD7LjUuA8mDESCYc1iiP3kXJOYqR8155uDn+mUSqKFkZkO1/BNLQMCX1s2iMMpzXc0nPRqDO/MS1VUqoECdIjjmYQ5bBbdhw1FVrBtV7P0e/Twi/5IPGusmCUlerTw75hF2Gfld1ll5sJN7DS8BP5coI0A/x5V6CukUUYEQtAb8b8XF9ftCcdd1BbBDjjJQ6gc/fFJNyEzYEq/kwhbWfHjmi2W3ACBZ9fOLTR3NERvI7D24w6RhZg1OxhfsL1TtyAP82YU0PmitL4U 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)(136003)(396003)(366004)(376002)(39860400002)(346002)(451199021)(83380400001)(316002)(38100700002)(45080400002)(41300700001)(82960400001)(8676002)(4326008)(478600001)(6916009)(5660300002)(8936002)(44832011)(186003)(66556008)(66476007)(66946007)(66574015)(26005)(6506007)(6486002)(2906002)(6512007)(86362001)(6666004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?7S67cJY966gOiUSsg3A7mr3rwGn9DQh0NobpWHQsK3sfaZSY0F1PGfwgkO?= =?iso-8859-1?Q?sWZQYa7/kreTA3c7f+XfR4veIoQKC7vD+YwssBO3eIYsNGbo1fh3+3ALgJ?= =?iso-8859-1?Q?8ioTye59EUkjq8XAXBG8VUdE0hmftjpu/Xhk2fk3CjmT3AqcolwGAmbGPD?= =?iso-8859-1?Q?zXtWjRSyES53sraY7/x01wXVblPG9rcvG8zafq6NnTFUM7hgebkAe7GONy?= =?iso-8859-1?Q?4QRuoTwLY4HJXqFAiE302wPoZfXjBZFGjGaeDgmU51IMK1cw65NT47ZJh/?= =?iso-8859-1?Q?pusKaeb0qGa9UEtlwnBmnFOJksQCiPffM1CRLk34QFGiyXro1F0d7455db?= =?iso-8859-1?Q?gvL9Da7AIpEhBmfuZuFbWCLv8GZiJysN5vHj4dcXINAQwH0+23S9nZt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it2eYbIVQurlcwlRz2dFOv+nWTbAOd?= =?iso-8859-1?Q?Ceq0ZpNuKt+mwJVfybtv2EALvgRzToD8KvjRvfPv572cvqNECbaJVNm3iI?= =?iso-8859-1?Q?L6JTv18cXYAJKD9FwHdqS1jfC595yu3LK71WFMZahRCnNa88/pjVtZndlt?= =?iso-8859-1?Q?uRE61rP2Bg8S+taixHjRzIbtzD9g+ohcRaA0R8H/zJ5tXmAgeft2QDbgjc?= =?iso-8859-1?Q?hU//NdPdljjdOxy0mjWR22IaQvmxi8b1RXyH3Jl7+UdFC11myn2NJWqX3g?= =?iso-8859-1?Q?NYCKk6SYiTEW138J1eJoHoqwHploa++GLTpm3co2pMfWmikaQ+j2pNkt9e?= =?iso-8859-1?Q?/TcsZzfLtnagzcl4TiIL7hGjK65cLc4wArRFgXxPj4qEpi6AvnQM3JIA?= =?iso-8859-1?Q?=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: a785217b-85fe-41a4-c145-08db35eda9e7 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7309.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2023 15:51:48.0091 (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: iutxfybixmIMvi9B7DMKXryGS9Pj0l8//UzI0PyKByo+GdDFSCAgzoCmGCxC9xhHbeS525GkfmO77VN/XMc63gnlfqwhtqJlreWwr1BUXhU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB7472 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 Wed, Apr 05, 2023 at 08:22:16AM -0700, Tyler Retzlaff wrote: > On Wed, Apr 05, 2023 at 09:44:54AM +0100, Bruce Richardson wrote: > > 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. > > here's an example in the code that would result in a bad calculation or > at least i believe so at a glance. switching to rte_clz32() would break > on 64-bit since it would truncate. > > lib/eal/common/malloc_elem.c > > -log2 = sizeof(size) * 8 - __builtin_clzl(size); > +log2 = sizeof(size) * 8 - rte_clz64(size); > > if i'm right you'd have to conditionally compile at the site. > > #ifdef 64-bit > rte_clz64() > #else > rte_clz32() > #endif > Why can clz64 not be used in both 32 and 64 bit cases? You know the result will always include zeros in high bits of a 64-bit value, and the result will still fit inside even an 8-bit variable? /Bruce