From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 ; 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 To: jerin.jacob@caviumnetworks.com, matan@mellanox.com, keith.wiles@intel.com, thomas@monjalon.net Cc: dev@dpdk.org, Pavan Nikhilesh 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:1JE6adXvOSoyT+nMXTfuU0CKK7gohjWDqPhD3t19SZbBY2fS3uFmAqyrqfWAWAjPv0nizaLKwc24yZUsmXNoGeiBawDDkprFltBA2xYqLugnK79oyyaXi+FivFobzH6bArSlfvXjhgpguypNdf4mYBmGQvrrLMgR7xuRXLgH3VagiFkDyl96pZDH1ja37W5/On7OJwpW0mCJdjbmJ/JOEvvwDw/IWE7aIXNrj5ststM= X-MS-TrafficTypeDiagnostic: MWHPR07MB3471: X-Microsoft-Exchange-Diagnostics: 1; MWHPR07MB3471; 20:hP+QlkgRI70IRKO+UIXI/JC20TtMsnmtfIzmayAckPa/7+ahxvmb4vijZPtQ/XYr+Qpr2PDUZDBcgoDpa3pNadbwgUX5Rrn8PcC8GMjGLRuhS1km/a0TJqpMAY1Q+aaIIve9HaFxyujyTBeiwtDqKD74TtcGqsrJS76xhlj5nrhgjlyv3R9ShTjf7+iwFMypJA/lKSOZiC7B6LLqsv7pVRcG5uip6hY7rMk7MhWyIUkNnZDf7+O4uHJLgUD5gbxyf/+n6qADqt6nfWaT26SIDYlDbuWB2lVqwJI0jHYSdrAeJ4G7fokLPxUoxyy1t4txiIrHtgQ+1yO5H/CjsZvqXlEdr/RviFx8DZZgp9+j7DhBnw4dV22ehpEJTeUrZptmFrmJW1pEERh+2NpOpRzihps5vNu0AtYfPlQgutIiLlG73Wnw2zcKThmlntwY/ez1fpk5DqdFo19JWMWHtKKLaeHpeTBmM4+aTy951LwNuc929cOfVHw0YrfbFm6qxmDxvQdwonEJk1xg30mnWVwHMSjpqcrpsbrH8H4KfKHcaA4zCY5gkAOsaAi2BzUKgnN73sC9NkKmeAuDsBVAXkdakKy65r+xLKQaTF7W9aLUGP8=; 4:KAe2Kai6tCedqYI2wMWB7SjF42cOmvIADmBBuioy01Y1i9csIB3j1iFFZaFvOI9zeed6Jk7ZhzpJA09O+0H1FduNSOrx+8D14G9LIs/xk4HgEb9aekbQytayEctooVYLUZJRbSW1qb79Bi9mjyEMhsSx+8++fyMRaCZhayTdlCHjwuY7muhTOymMT3DVsu+9ru6Z5QbPgLUxN5kDls2Yh3lgc9uZ3RgxzAJYQbGornQTBOB+uu1rujpwrm2r/Dho8zkRC/lBLnDO6vOfaoaHpg== X-Microsoft-Antispam-PRVS: 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?= =?us-ascii?Q?bEGlUEPhJ6dyDtoZz2iYp6AXEGx2C9K1lyxOYa6d+Crov99+8/iMAqv0Topd?= =?us-ascii?Q?opwHhdreJLEUcRtMwxkDbI32ANqh0ujPmW775M7fD3RnAMo3rMOatyZ0KCI3?= =?us-ascii?Q?0SLDz7s4CRRmS4tsPJ9X0/XBCT8ZWexfJQdm3a/twffCa6+XuFrEYR9SwWaq?= =?us-ascii?Q?1aRVZdarpsrx47K1jGNYgkxfcFo+s35z40WT28XaiKJSVYLmMdIkMQ9ukaes?= =?us-ascii?Q?y4yfWb6/t6GhnNWltQRnaytEDCrQ2sn5kbQne+JTsGCPKUt/J86udMF9Rewz?= =?us-ascii?Q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PkXZ4pW0Q=3D?= =?us-ascii?Q?=3D?= 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Feb 2018 11:37:30 -0000 Add 32b and 64b API's to align the given integer to the previous power of 2. Signed-off-by: Pavan Nikhilesh --- 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); +} + /** * 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