Message ID | 20180219113643.10337-1-pbhagavatula@caviumnetworks.com (mailing list archive) |
---|---|
State | Superseded, archived |
Delegated to: | Thomas Monjalon |
Headers |
Return-Path: <dev-bounces@dpdk.org> X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AC4DE12009; Mon, 19 Feb 2018 12:37:31 +0100 (CET) Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on0053.outbound.protection.outlook.com [104.47.37.53]) by dpdk.org (Postfix) with ESMTP id A4EFEA48F for <dev@dpdk.org>; Mon, 19 Feb 2018 12:37:29 +0100 (CET) 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=I7K/H9/4R0j6f/V8uIfnFyisUztrLTKe5BAu05MDPsU=; b=eMNHTj3eE1G5M/vGwOZexQ0eZZicdBd3+X9AMcbkd+JDBqlfPw9QeswlOPJroqSwoOltiB+3CBfL3MwCTTogNyzGfC1xnqIrthFUqH0ZahDeYmNdiTsq2hakXh6iovoaCyGQ2ics6jk2Ub95uVSIFk9MoZdij7GYs1zb1ZixBus= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Pavan.Bhagavatula@cavium.com; Received: from localhost.localdomain (111.93.218.67) by MWHPR07MB3471.namprd07.prod.outlook.com (10.164.192.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.506.18; Mon, 19 Feb 2018 11:37:24 +0000 From: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com> To: jerin.jacob@caviumnetworks.com, matan@mellanox.com, keith.wiles@intel.com, thomas@monjalon.net Cc: dev@dpdk.org, Pavan Nikhilesh <pbhagavatula@caviumnetworks.com> Date: Mon, 19 Feb 2018 17:06:42 +0530 Message-Id: <20180219113643.10337-1-pbhagavatula@caviumnetworks.com> X-Mailer: git-send-email 2.16.2 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: PN1PR01CA0086.INDPRD01.PROD.OUTLOOK.COM (10.174.144.154) To MWHPR07MB3471.namprd07.prod.outlook.com (10.164.192.22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f3043e3b-e469-447e-ff5d-08d5778d26d9 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:MWHPR07MB3471; X-Microsoft-Exchange-Diagnostics: 1; MWHPR07MB3471; 3:v/r/w9CorBLiHKW/uf/y5x+/+W4bJsDgEVFWknYxtbjx6YhfsTEbQDBaWx5ygvM5MYy7AZfp+AVFaVKwrl3wJzXO4q3SYEdikL7YO7qKUKAFnyei0YCylNv8xc/nuFDid6zW/1a35XV5DddXS7AceRrFIlBvXT51Ji3GEpuuQNWrIFb87DfXqMZL8v7QV6yFRMG0aWH73aaOIWwiFmY/THPj6f+W3vEkm/l2SojUHcfPx5GdxVQIfRiXX2lEQHLg; 25:x6v/4eXKj+aK42UDk5pfDExq7JKEdMaSu0+lS4X2qDkp05M6dxnNk4YggsDGMRxfB2o+7oWJX4bjpZhJsYbva8/OexRuaXwogzQ5DN8u8gLKNFNbsOv3+o4h1Nj9JN6wgJVbTxgMa0xwOPoqDh0Kf2XsY1KmA3IrApXknkDJwJJxWcrGXo/xZAsk29kkjaAJcXS/fC3XJnS7osqbMNWrxLY7Fqe1UWEJhumCPprcaFYBabFvZ0Qi2kvygXKblklDZwM2Fu/kYGeMmpSdIjHZ7tGAKYzDrTa18zRa17aWo5skFUOWQT+2ALs0klVrrnwPXW8K4ewwqEYkorrVAG/LFQ==; 31:1JE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hayTdlCHjwuY7muhTOymMT3DVsu+9ru6Z5QbPgLUxN5kDls2Yh3lgc9uZ3RgxzAJYQbGornQTBOB+uu1rujpwrm2r/Dho8zkRC/lBLnDO6vOfaoaHpg== X-Microsoft-Antispam-PRVS: <MWHPR07MB3471030EA7BF1456AEA2135180C80@MWHPR07MB3471.namprd07.prod.outlook.com> X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001056)(6040501)(2401047)(8121501046)(5005006)(3231101)(944501161)(93006095)(10201501046)(3002001)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(6072148)(201708071742011); SRVR:MWHPR07MB3471; BCL:0; PCL:0; RULEID:; SRVR:MWHPR07MB3471; X-Forefront-PRVS: 0588B2BD96 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(346002)(39850400004)(396003)(376002)(39380400002)(366004)(189003)(199004)(105586002)(5009440100003)(106356001)(1076002)(305945005)(7736002)(4326008)(36756003)(97736004)(107886003)(25786009)(81166006)(81156014)(8676002)(50226002)(8936002)(48376002)(68736007)(6486002)(6512007)(53936002)(76176011)(50466002)(16586007)(52116002)(6666003)(42882006)(2950100002)(6506007)(386003)(26005)(5660300001)(3846002)(6116002)(1857600001)(51416003)(316002)(16526019)(478600001)(72206003)(2906002)(47776003)(66066001)(42262002); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR07MB3471; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR07MB3471; 23:RVXMxlFxMtHxFWC+mWGY0Hf16CVrGkiaSGQTC0zos?= bEGlUEPhJ6dyDtoZz2iYp6AXEGx2C9K1lyxOYa6d+Crov99+8/iMAqv0TopdopwHhdreJL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skLrrKT7v3wSNdrYIBC/RtMh4v0HTZPkXZ4pW0Q== X-Microsoft-Exchange-Diagnostics: 1; MWHPR07MB3471; 6:18Dk6VkSLD3zmstvQQoC5LdH/cgWooq0O2DcMc2kGspRouYRofrgi7JqeTi/PoSV41OXrhnc4caQzs2l2UpfRzjOSA7f6BK1NYfGsNQ9Y3xT/dZycWfBtFMKiT0eCudCix4q8ehK88QCYeAMEM1FqDJXlQ8lsillA3KEoT7cNe1efUmFFHP9/ACfihTAyFKZhAXLJTn9odUKfahQzdaG0C5abdr113Cb4ojpM5M2NMa1cn1s2EtSAdOkEhXvAF3ygW/BODR14PpNFt1c3DhakubLwKGAcSdNtbn8dfY+zUTbK7+5NN0yDNO1Al8IUyOpJxRVCXKtMuTKCvFMt7kae5iJ2wFtRwmn3qlUQOUuoJU=; 5:e0X8UGLdLzuVtB7CS17C0wLQmODspmD6Zw2OSlYqLJK4Zoxksux5TEPwbSpk4sQI4Nplqx3JctW6rVmLnKBXTWqVYMJcmr3rd6cGASQx0bzr0H5Ei1WoY73fV/Gg/6To8LmtsjBNEftFuEsgXN01Qoy7Pvjspsphb4gi8sU8uSY=; 24:6RNzKoLj1yhrDajBtB4H89U1G14rt/07VYV8fhHj+z1r2HFVtmp45J/Ng2vjN9vihxqD6SXo4VMtn6FLi5+fdbETr2mD0IxyTu1UNeZ1SPE=; 7:kysMARZzNqP6mV3BBlVKXwXVzU/08jg3DUJM66lJ3rOrUJOP1Tb/PBlSsw1o5Nuc3RMKULdYyitb652/NWBntQViHhxCckMf+TT8EReaOBz/u51ssmKJaM8rLLyBwUX/7TTwaC0x3LDTea1c43yIUtowVB+P0NCWeXnZjy92b0VogLDhZGRMamDsoiqSKnZW/eoMLMfbYPhXrvbxgIh3kEuV8zivn4/3GYjK5PZ2Lgu/XaajIbLNZW32jWPX5R/v SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2018 11:37:24.4645 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f3043e3b-e469-447e-ff5d-08d5778d26d9 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR07MB3471 Subject: [dpdk-dev] [PATCH v2 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 <dev.dpdk.org> List-Unsubscribe: <https://dpdk.org/ml/options/dev>, <mailto:dev-request@dpdk.org?subject=unsubscribe> List-Archive: <http://dpdk.org/ml/archives/dev/> List-Post: <mailto:dev@dpdk.org> List-Help: <mailto:dev-request@dpdk.org?subject=help> List-Subscribe: <https://dpdk.org/ml/listinfo/dev>, <mailto:dev-request@dpdk.org?subject=subscribe> Errors-To: dev-bounces@dpdk.org Sender: "dev" <dev-bounces@dpdk.org> |
Checks
Context | Check | Description |
---|---|---|
ci/checkpatch | success | coding style OK |
ci/Intel-compilation | success | Compilation OK |
Commit Message
Pavan Nikhilesh
Feb. 19, 2018, 11:36 a.m. UTC
Add 32b and 64b API's to align the given integer to the previous power
of 2.
Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com>
---
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 | 43 ++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
--
2.16.1
Comments
Hi Pavan > From: Pavan Nikhilesh, Monday, February 19, 2018 1:37 PM > Add 32b and 64b API's to align the given integer to the previous power of 2. > > Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com> > --- > 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 | 43 > ++++++++++++++++++++++++++++++ > 1 file changed, 43 insertions(+) > > diff --git a/lib/librte_eal/common/include/rte_common.h > b/lib/librte_eal/common/include/rte_common.h > index c7803e41c..b2017ee5c 100644 > --- a/lib/librte_eal/common/include/rte_common.h > +++ b/lib/librte_eal/common/include/rte_common.h > @@ -259,6 +259,27 @@ rte_align32pow2(uint32_t 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 |= x >> 1; > + x |= x >> 2; > + x |= x >> 4; > + x |= x >> 8; > + x |= x >> 16; > + > + return x - (x >> 1); > +} Nice. Since you are using the same 5 lines from the rte_align32pow2() function, I think this part can be in a separate function to do reuse. Also the "fill ones 32" function can be used for other purpose. What do you think? > /** > * Aligns 64b input parameter to the next power of 2 > * > @@ -282,6 +303,28 @@ rte_align64pow2(uint64_t 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 |= v >> 1; > + v |= v >> 2; > + v |= v >> 4; > + v |= v >> 8; > + v |= v >> 16; > + v |= v >> 32; > + > + return v - (v >> 1); > +} > + > /*********** Macros for calculating min and max **********/ > > /** > -- > 2.16.1
Hi Matan, On Mon, Feb 19, 2018 at 12:09:46PM +0000, Matan Azrad wrote: > > Hi Pavan > > From: Pavan Nikhilesh, Monday, February 19, 2018 1:37 PM > > Add 32b and 64b API's to align the given integer to the previous power of 2. > > > > Signed-off-by: Pavan Nikhilesh <pbhagavatula@caviumnetworks.com> > > --- > > 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 | 43 > > ++++++++++++++++++++++++++++++ > > 1 file changed, 43 insertions(+) > > > > diff --git a/lib/librte_eal/common/include/rte_common.h > > b/lib/librte_eal/common/include/rte_common.h > > index c7803e41c..b2017ee5c 100644 > > --- a/lib/librte_eal/common/include/rte_common.h > > +++ b/lib/librte_eal/common/include/rte_common.h > > @@ -259,6 +259,27 @@ rte_align32pow2(uint32_t 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 |= x >> 1; > > + x |= x >> 2; > > + x |= x >> 4; > > + x |= x >> 8; > > + x |= x >> 16; > > + > > + return x - (x >> 1); > > +} > > Nice. > > Since you are using the same 5 lines from the rte_align32pow2() function, I think this part can be in a separate function to do reuse. > Also the "fill ones 32" function can be used for other purpose. > What do you think? I do agree that it would be cleaner to have a common function for both, but not able to decide on a appropriate function name "fill ones 32" doesn't convey what the function truly does. If you have a cleaner name do suggest, i will roll up a v3 adding the function and experimental tag. Thanks, Pavan > >
Hi Pavan From: Pavan Nikhilesh, Monday, February 26, 2018 9:10 PM > Hi Matan, > > On Mon, Feb 19, 2018 at 12:09:46PM +0000, Matan Azrad wrote: > > Since you are using the same 5 lines from the rte_align32pow2() function, I >> think this part can be in a separate function to do reuse. > > Also the "fill ones 32" function can be used for other purpose. > > What do you think? > > I do agree that it would be cleaner to have a common function for both, but > not able to decide on a appropriate function name "fill ones 32" doesn't > convey what the function truly does. If you have a cleaner name do suggest, i > will roll up a v3 adding the function and experimental tag. Sure. I'm suggesting next names: rte_combine32ms1b(register uint32_t x) rte_combine64ms1b(register uint64_t x) The description may be something like: combine the upper bits into the LSBs to construct a value with the same most significant 1 as x but all 1's under it. I would add the register keyword for each variables in all the align functions here just to hint for the compiler that it's better to save this variables in register and not in memory. Matan. > Thanks, > Pavan > > > > >
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index c7803e41c..b2017ee5c 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -259,6 +259,27 @@ rte_align32pow2(uint32_t 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 |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; + + return x - (x >> 1); +} + /** * Aligns 64b input parameter to the next power of 2 * @@ -282,6 +303,28 @@ rte_align64pow2(uint64_t 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 |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v |= v >> 32; + + return v - (v >> 1); +} + /*********** Macros for calculating min and max **********/ /**