From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0067.outbound.protection.outlook.com [104.47.32.67]) by dpdk.org (Postfix) with ESMTP id 0499D1C09C for ; Wed, 4 Apr 2018 12:16:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=a77cSneMSkuRm7306FbwPMn1O31lJS2JN3kMrI9oASY=; b=BAtySmIDSXbzdEzd7vPH9mj2VilyC4NaUNka69v+pNrogx7fongMWHo4hXw+lUlPSSufbG5OOK5woGSYg+A6Nl7sbfS2VZp7mL0OcoVgjd4cSZajVuphiPzCpD3dcqYVLyAbk9L1SZFCSjW4ycYLKXTUpqgtP8awQ92pvJsSAtA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Pavan.Bhagavatula@cavium.com; Received: from ltp-pvn.caveonetworks.com (111.93.218.67) by CY4PR07MB3462.namprd07.prod.outlook.com (2603:10b6:910:75::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.631.10; Wed, 4 Apr 2018 10:16:49 +0000 From: Pavan Nikhilesh To: jerin.jacob@caviumnetworks.com, matan@mellanox.com, keith.wiles@intel.com, thomas@monjalon.net Cc: dev@dpdk.org, Pavan Nikhilesh Date: Wed, 4 Apr 2018 15:46:05 +0530 Message-Id: <20180404101606.5156-1-pbhagavatula@caviumnetworks.com> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180217104934.17291-1-pbhagavatula@caviumnetworks.com> References: <20180217104934.17291-1-pbhagavatula@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: CO2PR04CA0107.namprd04.prod.outlook.com (2603:10b6:104:6::33) To CY4PR07MB3462.namprd07.prod.outlook.com (2603:10b6:910:75::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 43658c6d-6a15-434a-c54f-08d59a152edd X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603328)(7153060)(7193020); SRVR:CY4PR07MB3462; X-Microsoft-Exchange-Diagnostics: 1; CY4PR07MB3462; 3:eeYOw54qlw0KrzOBKpMnuibZtfjH7euwIHfcUm17CLljyyh6wv2NG8+U7GWwX3bHYoRn3mAnbzVUPbb616UW5amU/8kfYPdXoYlsNx8qjBdSopIYzJ9/YVF/wkl5ta/3VcmCaN/nm+2M6QXowCg0Et+FdgAG8QQGEPVV5+j7T3btEhFHgmwvQjuqBHRlrz41dWv5vTMnSdJiM0ii7RhYjMJN1cP3wqW7mhcFdm+BgKXD6hri1Z8g5DfSzhbBL2YG; 25:v9YbHaa/LbEy7RiKlbySG/DnQm96r10KIG+rvX3OE018RndBe71DO9HtsRQM9ljCYwo/ZtOXLQMC6yTAGrLXisIRdZMK3+fuzA3YjpiAsVCHepzMVxUFVBd4ueE+M/mtLetXo8x0WZdLeSii66DQLZQtkZbUu5hVNs+lH+1LMZ3dGJ8fDpFTUELM10bwGWl7iTIQZoyIV4bxlrIb69gMgRu2NzZJZfVE1k+VY9sD7wbM/4dQC3kqricPCC+ZGEEeObXDdy8H25lW/ZWOa5rMunaSWK0Ih8Z5XRSu/GFxuLoTHFBYUR+IvBNuDVQnPuTykh4j6GiyL6kOAjtS/rqghQ==; 31:MrqaThgd4agoTT90XDaqby8L/gwC2sQozCHT4X8dVUZLqqpwLLD2+H4Xp2NZWsKX1Px5aNq/bmwgnLF33ndUddBK4OJaEZlAjrbecxjk42acy3v0WPn2NGtROVojfkQ9ECaKv+o3pa1lbQC7ol/Z0EdlqTlZ31uLzy4sfGtDwTJXU41sQEP8EI8RQNFiYTOBeQSdKYs6IdYjF1EueW/tu2oJoT9tvCsN14BRO9qboC4= X-MS-TrafficTypeDiagnostic: CY4PR07MB3462: X-Microsoft-Exchange-Diagnostics: 1; CY4PR07MB3462; 20:uTbCpnrYfLnRMnW5Y3jwUR6Cf1iM6yQSKdQqrtDOOuSWejm50sZ2NLUeRcS1ejQzQnT9k/kamxNn6VKWMwl2o+7bqCs3QuNs//oAhpZ5mPWSvAo0maHw6pxLCIIsRWSi7AsPQLoagDYkAIZctB7i7eWm715I2iMgq8VXxbZPaHYkpY2vyK+0//JD7NGbSVjiAhM9Uawxbx1Z8tCWwY56w398kEtJ9pjp544DpYVNkFtsonmUP7m5IcOL0c+I1paaAnGisLg6ioKrNCOFVsfDuwvuK1pn06jIFkYtmHXcDB9x4D5cXU6VRKq2aZe56QJd1hkiUW66ThPv2mzuSE/fjknovh0kZneTzT+/ZTQyGKzb3KIX8d+6zSDFuSHvI5HaQyRnsHZI/Hlv1rz28K5AHDJduc8drV4Q5gRyZSeEKtIwP2C+WVScnIomGBihyPLhuq+RyxqXtQ2b0+8ExvL1IYeBlYCSFwxZRYp86gRxR7fPiftALpVWGRaYAmfeWytXnzCz5YXEd5vB0yFYMOpygamVgcPEJ00z1W9D3mQHgDDZGaxqYonNe5RIT7xrcGvdcBiJNJK4VRRylg7ShyXQvyBnuKLAvkYuolfF9EYLcFY=; 4:mbdr0eRD0Xv/qtB0vzA6l0GYrrkodtNaPigRxgAtqPCV0hsm/bWvPY+4Ny4nHNd5UaFTamopzYcwr0I1qldjqN/USqmCy6s3eFFPY93y+5PzEr0Z5QzIIyQew+RRW5VzCz9aPbkAVhMkbF8iSl7cj0ztfq+0SaSbU1hA1+s9v1cU+rDOXVnwtyshwIJLxmdkXJgaRm2IKpJffhdHgJ+XQcNUxOgkeGBdEC69Wxhn6J1co9rB3ttwGwlsggk3HDfWJJIclO9JlO76SsWGsRwB5Q== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(3231221)(944501327)(52105095)(6041310)(20161123564045)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011); SRVR:CY4PR07MB3462; BCL:0; PCL:0; RULEID:; SRVR:CY4PR07MB3462; X-Forefront-PRVS: 0632519F33 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(396003)(346002)(39860400002)(366004)(39380400002)(189003)(199004)(81156014)(76176011)(3846002)(5660300001)(6666003)(1857600001)(2906002)(8936002)(81166006)(16526019)(1076002)(50226002)(25786009)(105586002)(486006)(446003)(6116002)(26005)(106356001)(69596002)(36756003)(386003)(316002)(72206003)(68736007)(476003)(51416003)(6512007)(42882007)(5009440100003)(305945005)(7736002)(6506007)(50466002)(2616005)(52116002)(48376002)(6486002)(66066001)(53416004)(11346002)(47776003)(478600001)(53936002)(8676002)(956004)(97736004)(16586007)(107886003)(4326008)(42262002)(357404004); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR07MB3462; H:ltp-pvn.caveonetworks.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR07MB3462; 23:SNu3yoalrC+jUULsCOKaQMkMjCEuSuxD2KT67j6Lw?= =?us-ascii?Q?fcS0ZdUPa22AUaAP/HT232Mm7C5fH+PERP9DHkHQYr9XPZwt/ZndcNUztTxN?= =?us-ascii?Q?13f1Ququw/D890T/xtai8kjdoM1+lzDLMxGb5CwnfD8/9h+GEyPEWEBqEDTc?= =?us-ascii?Q?9Rb/+bwZKVmUhYM6WaN19eJ1t5nZj+Ci9xPnkTVXx1l+UqrhJYe9fdmS+c8m?= =?us-ascii?Q?KRSh/r8l2dxwmt6k9Z3abIg4mHLZL1FPCx0XCL8W7/k2rYxDQFsxHSS4zCDW?= =?us-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VD+vmatIUkUDscq4Vp0Y0Qup8Bd+Tl0B1hLac+z+yCe8vKThtCxAeIl0a5UtQL47EWxx34v/otnqfQvtGEuEWU/jyNfl+8Df9e5p4imvjk=; 24:WrsoYv+uiieky0zwokV+u5GpKJyto/Ia7jTYbtqVD5Z6T8xgokieiDx7BRE8DtCdWOrq/gM+4PLEAiyotOdlEFmKWoxScRdrcwCbwACtpkc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR07MB3462; 7:L5HKjrFYCbxPbB57cvuZayPHa42r+zYJcnz4Vp3OocU2ANlzjmB+2Ln/0Hd3md6WQi5KwGDPUFx2WGMTZwmhZHfVFXauF7aAL5tLNRfGHvGm+18B2BGdjDfAgQXIZOBzGfJEJLbYl56U/AqPckPEmPtFoYgaPQaQgr15U+cJ1ygteSSxZa07ZBZDZeFF304N6ZceK99eQOZQIs8n3zmWfFdQbaop8D1VmUf5xswJpMt/8Mq83e4UMnJfg1EtLgcH X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2018 10:16:49.3132 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 43658c6d-6a15-434a-c54f-08d59a152edd X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR07MB3462 Subject: [dpdk-dev] [PATCH v3 1/2] eal: add API to align integer to previous power of 2 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Apr 2018 10:16:53 -0000 Add 32b and 64b API's to align the given integer to the previous power of 2. Signed-off-by: Pavan Nikhilesh --- v3 Changes: - Move commonly used code to rte_combine(32/64)ms1b so that it can be reused. v2 Changes: - Modified api name to `rte_align(32/64)prevpow2` from `rte_align(32/64)lowpow2`. - corrected fuction to return if the integer is already aligned to power of 2. lib/librte_eal/common/include/rte_common.h | 92 ++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 11 deletions(-) diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index c7803e41c..7e147dcf2 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -223,6 +223,51 @@ extern int RTE_BUILD_BUG_ON_detected_error; } while(0) #endif +/** + * Combines 32b inputs most significant set bits into the least + * significant bits to construct a value with the same MSBs as x + * but all 1's under it. + * + * @param x + * The integer whose MSBs need to be combined with its LSBs + * @return + * The combined value. + */ +static inline uint32_t +rte_combine32ms1b(register uint32_t x) +{ + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + + return x; +} + +/** + * Combines 64b inputs most significant set bits into the least + * significant bits to construct a value with the same MSBs as x + * but all 1's under it. + * + * @param v + * The integer whose MSBs need to be combined with its LSBs + * @return + * The combined value. + */ +static inline uint64_t +rte_combine64ms1b(register uint64_t v) +{ + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v |= v >> 32; + + return v; +} + /*********** Macros to work with powers of 2 ********/ /** @@ -250,15 +295,28 @@ static inline uint32_t rte_align32pow2(uint32_t x) { x--; - x |= x >> 1; - x |= x >> 2; - x |= x >> 4; - x |= x >> 8; - x |= x >> 16; + x = rte_combine32ms1b(x); return x + 1; } +/** + * Aligns input parameter to the previous power of 2 + * + * @param x + * The integer value to algin + * + * @return + * Input parameter aligned to the previous power of 2 + */ +static inline uint32_t +rte_align32prevpow2(uint32_t x) +{ + x = rte_combine32ms1b(x); + + return x - (x >> 1); +} + /** * Aligns 64b input parameter to the next power of 2 * @@ -272,16 +330,28 @@ static inline uint64_t rte_align64pow2(uint64_t v) { v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - v |= v >> 32; + v = rte_combine64ms1b(v); return v + 1; } +/** + * Aligns 64b input parameter to the previous power of 2 + * + * @param v + * The 64b value to align + * + * @return + * Input parameter aligned to the previous power of 2 + */ +static inline uint64_t +rte_align64prevpow2(uint64_t v) +{ + v = rte_combine64ms1b(v); + + return v - (v >> 1); +} + /*********** Macros for calculating min and max **********/ /** -- 2.16.3