From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10074.outbound.protection.outlook.com [40.107.1.74]) by dpdk.org (Postfix) with ESMTP id 53C6B7CEF for ; Mon, 19 Feb 2018 13:09:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Nn6SkfBVzv3U494s9bkj5RpAwOE7DtCDGRGwdz9FSbQ=; b=wZ7I6QUfkN3Sb0Oi7JGx2EbW324GXZhwfKCJZWbFFDoDSBtW+pkXbeEoBJLvw0dhY+W8+998mLJff3DcOSYN2gAdc0AiXAFITaTFiiDv15HMl2Pkkxn3Qs9IF/LdN+MreKY43CXfnHIqi962+7LcOs2tRu2LmUX9hTOt9MDxdVc= Received: from AM4PR0501MB2657.eurprd05.prod.outlook.com (10.172.215.19) by AM4PR0501MB2835.eurprd05.prod.outlook.com (10.172.216.142) 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 12:09:46 +0000 Received: from AM4PR0501MB2657.eurprd05.prod.outlook.com ([fe80::80c6:df5:b1b0:ff05]) by AM4PR0501MB2657.eurprd05.prod.outlook.com ([fe80::80c6:df5:b1b0:ff05%17]) with mapi id 15.20.0506.021; Mon, 19 Feb 2018 12:09:46 +0000 From: Matan Azrad To: Pavan Nikhilesh , "jerin.jacob@caviumnetworks.com" , "keith.wiles@intel.com" , Thomas Monjalon CC: "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v2 1/2] eal: add API to align integer to previous power of 2 Thread-Index: AQHTqXYInsRxA9tL/US2y6QvecxbQqOroBPg Date: Mon, 19 Feb 2018 12:09:46 +0000 Message-ID: References: <20180217104934.17291-1-pbhagavatula@caviumnetworks.com> <20180219113643.10337-1-pbhagavatula@caviumnetworks.com> In-Reply-To: <20180219113643.10337-1-pbhagavatula@caviumnetworks.com> Accept-Language: en-US, he-IL Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; x-originating-ip: [193.47.165.251] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM4PR0501MB2835; 7:1ifU67ygJ4UXwFKvlg4O/jMyBbl7gHT2DPFH2VgfuQfD7is4UXOtz1To5nJIQuk3VeX1yBhGLZ1KCNEvUfqYqdJr4C+f07YKIaGO/zwdRLSAdF8NHd/cPon3YiiZopKGoQuNQZ4R/P7SoM9b67PYFAu6bf44zjw8hrhBcxNfOsoIOtt4EMk826ClqO5yTGGr5ncEO6ZoCKh92zjW2EWS8kiwEE747RGxkrD8aIwy+T3HvVTQG0wNUjM25UojiL49 x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 39ae5ab3-554b-4f10-6c02-08d57791aae3 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603307)(7153060)(7193020); SRVR:AM4PR0501MB2835; x-ms-traffictypediagnostic: AM4PR0501MB2835: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3231101)(944501161)(3002001)(6055026)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(6072148)(201708071742011); SRVR:AM4PR0501MB2835; BCL:0; PCL:0; RULEID:; SRVR:AM4PR0501MB2835; x-forefront-prvs: 0588B2BD96 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(39380400002)(39860400002)(396003)(376002)(346002)(189003)(199004)(76104003)(305945005)(74316002)(9686003)(7736002)(6436002)(8676002)(99286004)(81156014)(81166006)(8936002)(55016002)(97736004)(5660300001)(66066001)(316002)(2501003)(6246003)(106356001)(3280700002)(2906002)(53936002)(6116002)(5250100002)(3846002)(33656002)(25786009)(86362001)(2201001)(2900100001)(110136005)(478600001)(102836004)(14454004)(2950100002)(7696005)(26005)(105586002)(76176011)(6506007)(68736007)(229853002)(4326008)(186003)(3660700001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR0501MB2835; H:AM4PR0501MB2657.eurprd05.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: Hz3S3nQkHQuLcnHiq4S6u7xkiGQXQY3XZFeD6+hWpMdsbz3iYl1RPs+AFBIzsl0FTDe4gZBF+IGy/aNVMnAWWEGKVNMt7n9eytrk83xLhQOy5BBp4aljCFbXouYoWMtf6pT2EIyG4zoYC5xwImIkCJhWPOGvBcUm0uwyzuVxUpM= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 39ae5ab3-554b-4f10-6c02-08d57791aae3 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Feb 2018 12:09:46.2693 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0501MB2835 Subject: Re: [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 12:09:48 -0000 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. >=20 > 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 powe= r of 2. >=20 > lib/librte_eal/common/include/rte_common.h | 43 > ++++++++++++++++++++++++++++++ > 1 file changed, 43 insertions(+) >=20 > 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; > } >=20 > +/** > + * 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 |=3D x >> 1; > + x |=3D x >> 2; > + x |=3D x >> 4; > + x |=3D x >> 8; > + x |=3D 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? =20 > /** > * Aligns 64b input parameter to the next power of 2 > * > @@ -282,6 +303,28 @@ rte_align64pow2(uint64_t v) > return v + 1; > } >=20 > +/** > + * 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 |=3D v >> 1; > + v |=3D v >> 2; > + v |=3D v >> 4; > + v |=3D v >> 8; > + v |=3D v >> 16; > + v |=3D v >> 32; > + > + return v - (v >> 1); > +} > + > /*********** Macros for calculating min and max **********/ >=20 > /** > -- > 2.16.1