From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0076.outbound.protection.outlook.com [104.47.41.76]) by dpdk.org (Postfix) with ESMTP id 2767B1BE0 for ; Wed, 7 Nov 2018 07:59:06 +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:X-MS-Exchange-SenderADCheck; bh=QpbgJmgg95me+uo9mV1h9QkjK823xbTxx504qYjDfgY=; b=KPPRxRE0Tzl22JGtsWS6f8yFcGIfm1lpKd8KmQhDpEH2mMuo7S4szrZFqeMAc8FEbUZrEFNJiSch+PDGNKxDZZkycWLpllX2nhfutj2ZAEne1KdIdoZ4txyWIJh+QJVhcpnSWe2VWMM5olA6YO6wGH0LCuOb7PXJSLj9nSJ95Ak= Received: from BYAPR07MB4997.namprd07.prod.outlook.com (52.135.238.214) by BYAPR07MB5080.namprd07.prod.outlook.com (20.176.254.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.33; Wed, 7 Nov 2018 06:59:03 +0000 Received: from BYAPR07MB4997.namprd07.prod.outlook.com ([fe80::2d56:eab:242f:fdfc]) by BYAPR07MB4997.namprd07.prod.outlook.com ([fe80::2d56:eab:242f:fdfc%3]) with mapi id 15.20.1294.034; Wed, 7 Nov 2018 06:59:03 +0000 From: Jerin Jacob To: "dev@dpdk.org" CC: "thomas@monjalon.net" , "sthemmin@microsoft.com" , "shaopeng.he@intel.com" , "Jacob, Jerin" Thread-Topic: [dpdk-dev] [PATCH v2 1/2] eal: introduce rte version of fls Thread-Index: AQHUdmdeTP7wYurd902jLmSYivVLcw== Date: Wed, 7 Nov 2018 06:59:03 +0000 Message-ID: <20181107065833.16756-1-jerin.jacob@caviumnetworks.com> References: <20181106114435.14770-1-jerin.jacob@caviumnetworks.com> In-Reply-To: <20181106114435.14770-1-jerin.jacob@caviumnetworks.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [106.200.201.67] x-clientproxiedby: SG2PR06CA0203.apcprd06.prod.outlook.com (2603:1096:4:1::35) To BYAPR07MB4997.namprd07.prod.outlook.com (2603:10b6:a03:5b::22) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Jerin.JacobKollanukkaran@cavium.com; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; BYAPR07MB5080; 6:poEs+OTIXsKgM8O/I6BF1qHbi8aXZ0D5xTiiYS/setnT9CtU69Kedc9OMegM9TXxP2i4RVjvR+9bSjnrdjjxXC5yPJWmjpxM6PyOAkN3/vRfeUbOzLjotsKqOlsMRL0rk1RSIFPSoSHT7HBSpfwq6GQmo0CClr0rcKHgmXC2jKBnJtaj0/CHSbSiq3Z4kJ7fyc58Lpft+DXJMPPn9MLpixWJS6WZ3G/3Q9sMe9U9LizGkAT5r1Jcy43qmH8KLMZZtDNwVOMOeB03ucDcCjjcCXQ9K6kO8z7ZS1xMgUbEjKYvZK7RCHsnebZEiwemawevI4JzNXO37hzyZBypZ3FMYgASEVva6A1Mx9SwjSP+7nf5oovulze73tcuvpNkwHT7Q3Bjjbay7Sye/IoNJxhdwi/rxExquTwlEjLv1UnWNWd0sjadb8xk95CRp4xmzw9L57EJBnU3P1X1Zakgpe7g0Q==; 5:FWPMi6yGzJqHi/hCtfcrWlriyPTEvM/Gz+AS+d/4vB/HCU7xACAfgM9aOIlX2ZhV5JAWevT0aLjQcBcRqStidLzviyZxnEWuvwBlfbqreRR1I0V/axFaK3ICKGKesPAkPFh3gLmnQExEWPeLcC0omsZAzoeCGFGtWQXJyZiqCJo=; 7:TlXhcn+i3oxLW653u6V6c8K5iHeIVkOv9lvd0lOPLE4xW9vFjGAXWcAVWzJQaySzR1BoyYhSTwIkg6MejCZiU+dX9Gc4QXaobYmMNA6zay09XyE9I85pvdmeCadA79sTp6W3NOmwgi+s0pbvrInJ9A== x-ms-office365-filtering-correlation-id: e6e5afea-6568-4d4e-f414-08d6447e8055 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:BYAPR07MB5080; x-ms-traffictypediagnostic: BYAPR07MB5080: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231382)(944501410)(52105095)(3002001)(10201501046)(93006095)(148016)(149066)(150057)(6041310)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(201708071742011)(7699051)(76991095); SRVR:BYAPR07MB5080; BCL:0; PCL:0; RULEID:; SRVR:BYAPR07MB5080; x-forefront-prvs: 08497C3D99 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(396003)(136003)(366004)(346002)(376002)(189003)(199004)(1076002)(256004)(446003)(486006)(6116002)(4326008)(6916009)(6486002)(3846002)(2351001)(97736004)(53936002)(52116002)(25786009)(6512007)(105586002)(6436002)(71190400001)(71200400001)(107886003)(76176011)(14444005)(1730700003)(54906003)(575784001)(81166006)(26005)(316002)(8936002)(81156014)(7736002)(1857600001)(5640700003)(42882007)(6506007)(305945005)(106356001)(8676002)(186003)(36756003)(2900100001)(386003)(102836004)(5660300001)(2616005)(478600001)(72206003)(11346002)(68736007)(99286004)(2906002)(14454004)(476003)(66066001)(2501003); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR07MB5080; H:BYAPR07MB4997.namprd07.prod.outlook.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-antispam-message-info: 8p9eQdkx1iKu3HkD/9OUCAb61fyhDqnykaBFTc32x3oE4iDgYacJKKtvkq1ihKYUeXbGI2v7euKuC6sIwe5OQtEDqZ3VofzDHI7JwTZEXLh9+7fxmT1x1XCEDq8nrxUfvNZd6HCYyerc32epnshfz/GqomcgdplXlGjeceC36Ub7CHFv9rZNNMzMo4Yzmduo/S3GUappHcp2/W+VPsXYa5zMEL3dGlU7sg8AlnvthBK53iISRcg6xV/vCMAE7hYvfGJyWR1fbOJr9hj6ajhCdIPkjwzfocv3ZBRj5nBIpWPQ9RtPh99a2vVZ0hy4e+/cW9IPwLfeonYOoq1QBRArkRNkALYf9Cn34HcEFjfXYTA= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-Network-Message-Id: e6e5afea-6568-4d4e-f414-08d6447e8055 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Nov 2018 06:59:03.4742 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR07MB5080 Subject: [dpdk-dev] [PATCH v2 1/2] eal: introduce rte version of fls 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, 07 Nov 2018 06:59:06 -0000 The function returns the last (most-significant) bit set. Added unit testcase to verify rte_fls_u32(). Signed-off-by: Jerin Jacob --- v2: - Introduce rte_fls_u32() --- lib/librte_eal/common/include/rte_common.h | 19 +++++++++++++ test/test/test_common.c | 32 ++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/co= mmon/include/rte_common.h index cba7bbc1d..87f0f6302 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -473,6 +473,25 @@ rte_log2_u32(uint32_t v) return rte_bsf32(v); } =20 + +/** + * Return the last (most-significant) bit set. + * + * @note The last (most significant) bit is at position 32. + * @note rte_fls_u32(0) =3D 0, rte_fls_u32(1) =3D 1, rte_fls_u32(0x8000000= 0) =3D 32 + * + * @param x + * The input parameter. + * @return + * The last (most-significant) bit set, or 0 if the input is 0. + */ +static inline int +rte_fls_u32(uint32_t x) +{ + return (x =3D=3D 0) ? 0 : 32 - __builtin_clz(x); +} + + #ifndef offsetof /** Return the offset of a field in a structure. */ #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) diff --git a/test/test/test_common.c b/test/test/test_common.c index 7a67e458e..c6d17baae 100644 --- a/test/test/test_common.c +++ b/test/test/test_common.c @@ -188,6 +188,37 @@ test_log2(void) return 0; } =20 +static int +test_fls(void) +{ + struct fls_test_vector { + uint32_t arg; + int rc; + }; + int expected, rc; + uint32_t i, arg; + + const struct fls_test_vector test[] =3D { + {0x0, 0}, + {0x1, 1}, + {0x4000, 15}, + {0x80000000, 32}, + }; + + for (i =3D 0; i < RTE_DIM(test); i++) { + arg =3D test[i].arg; + rc =3D rte_fls_u32(arg); + expected =3D test[i].rc; + if (rc !=3D expected) { + printf("Wrong rte_fls_u32(0x%x) rc=3D%d, expected=3D%d\n", + arg, rc, expected); + return TEST_FAILED; + } + } + + return 0; +} + static int test_common(void) { @@ -196,6 +227,7 @@ test_common(void) ret |=3D test_macros(0); ret |=3D test_misc(); ret |=3D test_log2(); + ret |=3D test_fls(); =20 return ret; } --=20 2.19.1