From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id C58B111A4 for ; Sat, 16 Mar 2019 08:03:39 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2G705QX014645; Sat, 16 Mar 2019 00:03:38 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt0818; bh=RYbZDw3pMHAh+yFYNcUMP11AQZ7C3nFCFBa7aL3Vqco=; b=SGQcTZQKtaFl7SOx6N6p4MoJ1dI+NqKrVVQNzxvtNZNOHCDEbQXd6rtD1RBc8ANrRgCr D27jmdqDvehOsVIfoMKzF5jJkOM4sG58D2GpG8vp0sEhsPmpslOQW4HvTy+KuJTFtUNl lclP+LfTTSElEl+m0i/hSTq4tdz/0BNVN6yCcDCxy+3iAXBX0O+R+FwZc/kWvYvJxjF8 o4KNjsbtAkHItf36gj55ooJRZcz4/USUUj1xNNtqbDHbgeTLWG0VY8r+eTdHkMVI+3wm wCHYxgqmw68vQxHtnT8Lkm1bMTjP25vuN8AoNkPIsDxnTpYKXG/OvZcDNqnDBxDKZl44 6Q== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 2r8kaa0y6b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 16 Mar 2019 00:03:38 -0700 Received: from SC-EXCH04.marvell.com (10.93.176.84) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sat, 16 Mar 2019 00:03:37 -0700 Received: from NAM01-BN3-obe.outbound.protection.outlook.com (104.47.33.55) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Sat, 16 Mar 2019 00:03:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RYbZDw3pMHAh+yFYNcUMP11AQZ7C3nFCFBa7aL3Vqco=; b=sq4bagkmfDSSJsQUxKm55lGNaP+eKFiU00GftsTtcKeJV+zw6cvP2frKYFoDnHXvE09oJQeImTFXnyQVi/zjoSF0Mgc4gjt/2Hcd/NU5ZTlzc6Xzh/LbqivBbtsYgmA3TLYe6MCD0BOAGwlh1T/MMvgtj2QyPYIo69Jco4zcHNU= Received: from CY4PR1801MB1863.namprd18.prod.outlook.com (10.171.255.14) by CY4PR1801MB1815.namprd18.prod.outlook.com (10.165.88.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1686.19; Sat, 16 Mar 2019 07:03:32 +0000 Received: from CY4PR1801MB1863.namprd18.prod.outlook.com ([fe80::286d:5e93:974e:8bfa]) by CY4PR1801MB1863.namprd18.prod.outlook.com ([fe80::286d:5e93:974e:8bfa%2]) with mapi id 15.20.1709.011; Sat, 16 Mar 2019 07:03:32 +0000 From: Pavan Nikhilesh Bhagavatula To: Jerin Jacob Kollanukkaran , "stephen@networkplumber.org" , "thomas@monjalon.net" CC: "dev@dpdk.org" , Pavan Nikhilesh Bhagavatula Thread-Topic: [dpdk-dev] [PATCH v2 1/2] eal: add macro to align value to the nearest multiple Thread-Index: AQHU28ZdKrl1SaFjp0W1uP/EC2epDw== Date: Sat, 16 Mar 2019 07:03:31 +0000 Message-ID: <20190316070302.32432-1-pbhagavatula@marvell.com> References: <20181129083138.23029-1-pbhagavatula@caviumnetworks.com> In-Reply-To: <20181129083138.23029-1-pbhagavatula@caviumnetworks.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MA1PR01CA0072.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00::12) To CY4PR1801MB1863.namprd18.prod.outlook.com (2603:10b6:910:7a::14) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [122.167.180.250] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3a690654-85fc-416f-5d13-08d6a9dd7fa7 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(2017052603328)(7153060)(7193020); SRVR:CY4PR1801MB1815; x-ms-traffictypediagnostic: CY4PR1801MB1815: x-microsoft-exchange-diagnostics: =?iso-8859-1?Q?1; CY4PR1801MB1815; 23:hW4HJPRNTBeZRoGEm4gVkiPLnxcbvWdSLKGBn?= =?iso-8859-1?Q?+/tZgUwhzCrrpPwq0RfIHl+EsURDgUdjd3g0/KUQBubFHL0TUJ8Eg7LT2b?= =?iso-8859-1?Q?JVkUv3wMwTtOEVzDqnwLYyHLMnjd7/JrttBRHGPCxT1owoXKdmNKBgOroX?= =?iso-8859-1?Q?yUu6SLvEWm3TU63lPy4gSr8wBSKnEAALcwqyFC68S7c41oLIXkFLgNFzas?= =?iso-8859-1?Q?TbD4GqXid7KbMoBSE6ZL2eifhqwadyVV1MOnlqO7FD4TBp/6a2y9jJUFGd?= =?iso-8859-1?Q?evJV2TZytBzPqEPDL7W86h1N5KiTIX48+VqzbhXaXjePP4JM9OaFF5Hcu6?= =?iso-8859-1?Q?pf9flemM0B0J38pKUUvzn9QLul3TfpmgcSk6BVuUdmAF8OSqONFN/G5I+O?= =?iso-8859-1?Q?AjCgV6cu90pVD4yOJY0w+lWciJNwbBRIjBRKinRT1UBPJCU8mkrpvAaVOA?= =?iso-8859-1?Q?eOIiF7kXWjqHAmXX6zc9E+jQroGtiVpJIrUOWZ64WdEsUFJjOfM7ktXKpl?= =?iso-8859-1?Q?+AAX+eF+Gu0K1loXyBhs/i1UMQCCfKPU7QU9DJeXfk13zk1Fnp82+v9Hjc?= =?iso-8859-1?Q?nxxNcfXfzCqbPTlt8jaoemmNK1Wt1Yc9RF8v24AUP5tJ0UWhR0NVbHq4/6?= =?iso-8859-1?Q?ownUl2C7s15n/ps4bOsJ8tn1dD6mbq/dlpeFy4uuQ1VsgJxFCecDvtK3+Z?= =?iso-8859-1?Q?zXK38hdfGOcHh364ksZVwVvFxpMEbH3uFjEec9UTjwq6c9rG5nZJUx44cn?= =?iso-8859-1?Q?X9AhYinFr2z+VcsIxhO6ZuhzWgwPChvAUzzrU7Togm2KQGm24kdEncGLHk?= =?iso-8859-1?Q?jugMEI4RdxJgfTm4tEWpkprzIUia7xcp2cwwzV7ezNZyRsKFpCqYZitPxG?= =?iso-8859-1?Q?uDjXfbOMKvYLBSFyIXU7ukM03swRJiYXo6DasCBxr/gmR4NBsO5EZQ4F/Q?= =?iso-8859-1?Q?DJrYtGj4eS3hscaAlq6/h8xgrDPLpFTiOYynTRSlkn2h4FgSlBl+u7v5Yi?= =?iso-8859-1?Q?gHQXMPhtAfv6QCbT1KlQhaLNVLNjX3UoVIlnDYWSKytRTV/XFq1uFzbGb0?= =?iso-8859-1?Q?kIYmuSdQMxJHMuJ8fa9tl2Pcc2P9H7y7x61S6HGIlcDNNPpLMy7sDE2Hz+?= =?iso-8859-1?Q?mBKqIRSYGO/PihsQtVgrrkBvGI1JNUfvxm1Lp7vadU+9qYOmV38VCSfWFn?= =?iso-8859-1?Q?QylvJmjrJyrneGsjauUQ4/qjNjeMPGh5/qYS7Vva+YE3Vm+D1MQbkHUOcy?= =?iso-8859-1?Q?jGp/3dRQzqPof0/2oGM5OtiqpUyZffPA1GWPc8DvpOc8YoT6c09qv8qNGa?= =?iso-8859-1?Q?OO6gXV5Pa9mUFL3ASrJamPxaJ9uGhdhYYBKgO4szF3zDKO/HgvXPxfz2mE?= =?iso-8859-1?Q?MHYssMsshcoWHFChYCA0uMIAiKD22kFVq07z04jeQdlcJAoqQz8WiBpn0/?= =?iso-8859-1?Q?Wopgk4sO7k3mMudEDIlnarRRAwAO39l6C+wGI?= x-microsoft-antispam-prvs: x-forefront-prvs: 09781D4C35 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(979002)(136003)(366004)(346002)(376002)(396003)(39860400002)(199004)(189003)(1076003)(81156014)(305945005)(6506007)(316002)(386003)(2501003)(8676002)(476003)(105586002)(106356001)(102836004)(99286004)(11346002)(7736002)(256004)(14444005)(6486002)(26005)(54906003)(71190400001)(478600001)(86362001)(97736004)(71200400001)(5660300002)(14454004)(2201001)(2616005)(6436002)(53936002)(52116002)(6512007)(8936002)(486006)(68736007)(446003)(36756003)(4326008)(107886003)(50226002)(3846002)(110136005)(76176011)(2906002)(6116002)(78486014)(186003)(66066001)(25786009)(81166006)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1801MB1815; H:CY4PR1801MB1863.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: cYitiFvGYA4RrLHnqW7pMbVhTgWX3sNvxxXwFvbTXQfwn1HHI4fbqFiMw/WCf54Y1P42djLV+/9PGNt3jaGnUeR2HM9gQnc9+hKtm2whqDwU/dtb9rH62pGsr6IFjtr8Mzo7yD0zj06jHyEeqFQ2Mb2A2zeIRRk6t4RBfeYABmGD68XTkeDhfh7WvvVD5+hpUtAyC4GkhiNioz+g1B/loOsMsE6HY+ak3NK/R2tSLL4awOTZOVMJskpqlz99gqRlIaemewdj/4eMQQ6GXCvk8sjC+7lTZdB56JMlF7gew0Io4rXhJyLetP9HsF9Y/xU8jXe74+zyefFEOWIrLVZsaP+HcQk/Rxv+LWjMqQ26rDRr8fHo+6ug2I8Qro1p7kMdNr3LaV2NR+/QWDLDHoG0jvsA0ke95IjT99YLAhSJA/Y= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 3a690654-85fc-416f-5d13-08d6a9dd7fa7 X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Mar 2019 07:03:32.5293 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1801MB1815 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-03-16_05:, , signatures=0 Subject: [dpdk-dev] [PATCH v2 1/2] eal: add macro to align value to the nearest multiple 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: Sat, 16 Mar 2019 07:03:40 -0000 From: Pavan Nikhilesh Add macro to align value to the nearest multiple of the given value, resultant value might be greater than or less than the first parameter whichever difference is the lowest. Update unit test to include the new macro. Signed-off-by: Pavan Nikhilesh --- v2 Changes: - Spilt patch and add unit test for the new macro. app/test/test_common.c | 4 ++++ lib/librte_eal/common/include/rte_common.h | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/test/test_common.c b/app/test/test_common.c index 94d367471..2b856f8ba 100644 --- a/app/test/test_common.c +++ b/app/test/test_common.c @@ -199,6 +199,10 @@ test_align(void) val =3D RTE_ALIGN_MUL_FLOOR(i, p); if (val % p !=3D 0 || val > i) FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p); + val =3D RTE_ALIGN_MUL_NEAR(i, p); + if (val % p !=3D 0 || ((val !=3D RTE_ALIGN_MUL_CEIL(i, p)) + & (val !=3D RTE_ALIGN_MUL_FLOOR(i, p)))) + FAIL_ALIGN("RTE_ALIGN_MUL_NEAR", i, p); } } diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/co= mmon/include/rte_common.h index 7178ba1e9..bcf8afd39 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -248,6 +248,18 @@ static void __attribute__((destructor(RTE_PRIO(prio)),= used)) func(void) #define RTE_ALIGN_MUL_FLOOR(v, mul) \ ((v / ((typeof(v))(mul))) * (typeof(v))(mul)) +/** + * Macro to align value to the nearest multiple of the given value. + * The resultant value might be greater than or less than the first parame= ter + * whichever difference is the lowest. + */ +#define RTE_ALIGN_MUL_NEAR(v, mul) \ + ({ \ + typeof(v) ceil =3D RTE_ALIGN_MUL_CEIL(v, mul); \ + typeof(v) floor =3D RTE_ALIGN_MUL_FLOOR(v, mul); \ + (ceil - v) > (v - floor) ? floor : ceil; \ + }) + /** * Checks if a pointer is aligned to a given power-of-two value * -- 2.21.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 48A19A0096 for ; Sat, 16 Mar 2019 08:03:42 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 01A811BE0; Sat, 16 Mar 2019 08:03:41 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id C58B111A4 for ; Sat, 16 Mar 2019 08:03:39 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2G705QX014645; Sat, 16 Mar 2019 00:03:38 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt0818; bh=RYbZDw3pMHAh+yFYNcUMP11AQZ7C3nFCFBa7aL3Vqco=; b=SGQcTZQKtaFl7SOx6N6p4MoJ1dI+NqKrVVQNzxvtNZNOHCDEbQXd6rtD1RBc8ANrRgCr D27jmdqDvehOsVIfoMKzF5jJkOM4sG58D2GpG8vp0sEhsPmpslOQW4HvTy+KuJTFtUNl lclP+LfTTSElEl+m0i/hSTq4tdz/0BNVN6yCcDCxy+3iAXBX0O+R+FwZc/kWvYvJxjF8 o4KNjsbtAkHItf36gj55ooJRZcz4/USUUj1xNNtqbDHbgeTLWG0VY8r+eTdHkMVI+3wm wCHYxgqmw68vQxHtnT8Lkm1bMTjP25vuN8AoNkPIsDxnTpYKXG/OvZcDNqnDBxDKZl44 6Q== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 2r8kaa0y6b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 16 Mar 2019 00:03:38 -0700 Received: from SC-EXCH04.marvell.com (10.93.176.84) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sat, 16 Mar 2019 00:03:37 -0700 Received: from NAM01-BN3-obe.outbound.protection.outlook.com (104.47.33.55) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Sat, 16 Mar 2019 00:03:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RYbZDw3pMHAh+yFYNcUMP11AQZ7C3nFCFBa7aL3Vqco=; b=sq4bagkmfDSSJsQUxKm55lGNaP+eKFiU00GftsTtcKeJV+zw6cvP2frKYFoDnHXvE09oJQeImTFXnyQVi/zjoSF0Mgc4gjt/2Hcd/NU5ZTlzc6Xzh/LbqivBbtsYgmA3TLYe6MCD0BOAGwlh1T/MMvgtj2QyPYIo69Jco4zcHNU= Received: from CY4PR1801MB1863.namprd18.prod.outlook.com (10.171.255.14) by CY4PR1801MB1815.namprd18.prod.outlook.com (10.165.88.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1686.19; Sat, 16 Mar 2019 07:03:32 +0000 Received: from CY4PR1801MB1863.namprd18.prod.outlook.com ([fe80::286d:5e93:974e:8bfa]) by CY4PR1801MB1863.namprd18.prod.outlook.com ([fe80::286d:5e93:974e:8bfa%2]) with mapi id 15.20.1709.011; Sat, 16 Mar 2019 07:03:32 +0000 From: Pavan Nikhilesh Bhagavatula To: Jerin Jacob Kollanukkaran , "stephen@networkplumber.org" , "thomas@monjalon.net" CC: "dev@dpdk.org" , Pavan Nikhilesh Bhagavatula Thread-Topic: [dpdk-dev] [PATCH v2 1/2] eal: add macro to align value to the nearest multiple Thread-Index: AQHU28ZdKrl1SaFjp0W1uP/EC2epDw== Date: Sat, 16 Mar 2019 07:03:31 +0000 Message-ID: <20190316070302.32432-1-pbhagavatula@marvell.com> References: <20181129083138.23029-1-pbhagavatula@caviumnetworks.com> In-Reply-To: <20181129083138.23029-1-pbhagavatula@caviumnetworks.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MA1PR01CA0072.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00::12) To CY4PR1801MB1863.namprd18.prod.outlook.com (2603:10b6:910:7a::14) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [122.167.180.250] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3a690654-85fc-416f-5d13-08d6a9dd7fa7 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(2017052603328)(7153060)(7193020); SRVR:CY4PR1801MB1815; x-ms-traffictypediagnostic: CY4PR1801MB1815: x-microsoft-exchange-diagnostics: =?iso-8859-1?Q?1; CY4PR1801MB1815; 23:hW4HJPRNTBeZRoGEm4gVkiPLnxcbvWdSLKGBn?= =?iso-8859-1?Q?+/tZgUwhzCrrpPwq0RfIHl+EsURDgUdjd3g0/KUQBubFHL0TUJ8Eg7LT2b?= =?iso-8859-1?Q?JVkUv3wMwTtOEVzDqnwLYyHLMnjd7/JrttBRHGPCxT1owoXKdmNKBgOroX?= =?iso-8859-1?Q?yUu6SLvEWm3TU63lPy4gSr8wBSKnEAALcwqyFC68S7c41oLIXkFLgNFzas?= =?iso-8859-1?Q?TbD4GqXid7KbMoBSE6ZL2eifhqwadyVV1MOnlqO7FD4TBp/6a2y9jJUFGd?= =?iso-8859-1?Q?evJV2TZytBzPqEPDL7W86h1N5KiTIX48+VqzbhXaXjePP4JM9OaFF5Hcu6?= =?iso-8859-1?Q?pf9flemM0B0J38pKUUvzn9QLul3TfpmgcSk6BVuUdmAF8OSqONFN/G5I+O?= =?iso-8859-1?Q?AjCgV6cu90pVD4yOJY0w+lWciJNwbBRIjBRKinRT1UBPJCU8mkrpvAaVOA?= =?iso-8859-1?Q?eOIiF7kXWjqHAmXX6zc9E+jQroGtiVpJIrUOWZ64WdEsUFJjOfM7ktXKpl?= =?iso-8859-1?Q?+AAX+eF+Gu0K1loXyBhs/i1UMQCCfKPU7QU9DJeXfk13zk1Fnp82+v9Hjc?= =?iso-8859-1?Q?nxxNcfXfzCqbPTlt8jaoemmNK1Wt1Yc9RF8v24AUP5tJ0UWhR0NVbHq4/6?= =?iso-8859-1?Q?ownUl2C7s15n/ps4bOsJ8tn1dD6mbq/dlpeFy4uuQ1VsgJxFCecDvtK3+Z?= =?iso-8859-1?Q?zXK38hdfGOcHh364ksZVwVvFxpMEbH3uFjEec9UTjwq6c9rG5nZJUx44cn?= =?iso-8859-1?Q?X9AhYinFr2z+VcsIxhO6ZuhzWgwPChvAUzzrU7Togm2KQGm24kdEncGLHk?= =?iso-8859-1?Q?jugMEI4RdxJgfTm4tEWpkprzIUia7xcp2cwwzV7ezNZyRsKFpCqYZitPxG?= =?iso-8859-1?Q?uDjXfbOMKvYLBSFyIXU7ukM03swRJiYXo6DasCBxr/gmR4NBsO5EZQ4F/Q?= =?iso-8859-1?Q?DJrYtGj4eS3hscaAlq6/h8xgrDPLpFTiOYynTRSlkn2h4FgSlBl+u7v5Yi?= =?iso-8859-1?Q?gHQXMPhtAfv6QCbT1KlQhaLNVLNjX3UoVIlnDYWSKytRTV/XFq1uFzbGb0?= =?iso-8859-1?Q?kIYmuSdQMxJHMuJ8fa9tl2Pcc2P9H7y7x61S6HGIlcDNNPpLMy7sDE2Hz+?= =?iso-8859-1?Q?mBKqIRSYGO/PihsQtVgrrkBvGI1JNUfvxm1Lp7vadU+9qYOmV38VCSfWFn?= =?iso-8859-1?Q?QylvJmjrJyrneGsjauUQ4/qjNjeMPGh5/qYS7Vva+YE3Vm+D1MQbkHUOcy?= =?iso-8859-1?Q?jGp/3dRQzqPof0/2oGM5OtiqpUyZffPA1GWPc8DvpOc8YoT6c09qv8qNGa?= =?iso-8859-1?Q?OO6gXV5Pa9mUFL3ASrJamPxaJ9uGhdhYYBKgO4szF3zDKO/HgvXPxfz2mE?= =?iso-8859-1?Q?MHYssMsshcoWHFChYCA0uMIAiKD22kFVq07z04jeQdlcJAoqQz8WiBpn0/?= =?iso-8859-1?Q?Wopgk4sO7k3mMudEDIlnarRRAwAO39l6C+wGI?= x-microsoft-antispam-prvs: x-forefront-prvs: 09781D4C35 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(979002)(136003)(366004)(346002)(376002)(396003)(39860400002)(199004)(189003)(1076003)(81156014)(305945005)(6506007)(316002)(386003)(2501003)(8676002)(476003)(105586002)(106356001)(102836004)(99286004)(11346002)(7736002)(256004)(14444005)(6486002)(26005)(54906003)(71190400001)(478600001)(86362001)(97736004)(71200400001)(5660300002)(14454004)(2201001)(2616005)(6436002)(53936002)(52116002)(6512007)(8936002)(486006)(68736007)(446003)(36756003)(4326008)(107886003)(50226002)(3846002)(110136005)(76176011)(2906002)(6116002)(78486014)(186003)(66066001)(25786009)(81166006)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1801MB1815; H:CY4PR1801MB1863.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: cYitiFvGYA4RrLHnqW7pMbVhTgWX3sNvxxXwFvbTXQfwn1HHI4fbqFiMw/WCf54Y1P42djLV+/9PGNt3jaGnUeR2HM9gQnc9+hKtm2whqDwU/dtb9rH62pGsr6IFjtr8Mzo7yD0zj06jHyEeqFQ2Mb2A2zeIRRk6t4RBfeYABmGD68XTkeDhfh7WvvVD5+hpUtAyC4GkhiNioz+g1B/loOsMsE6HY+ak3NK/R2tSLL4awOTZOVMJskpqlz99gqRlIaemewdj/4eMQQ6GXCvk8sjC+7lTZdB56JMlF7gew0Io4rXhJyLetP9HsF9Y/xU8jXe74+zyefFEOWIrLVZsaP+HcQk/Rxv+LWjMqQ26rDRr8fHo+6ug2I8Qro1p7kMdNr3LaV2NR+/QWDLDHoG0jvsA0ke95IjT99YLAhSJA/Y= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 3a690654-85fc-416f-5d13-08d6a9dd7fa7 X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Mar 2019 07:03:32.5293 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1801MB1815 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-03-16_05:, , signatures=0 Subject: [dpdk-dev] [PATCH v2 1/2] eal: add macro to align value to the nearest multiple 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Message-ID: <20190316070331.UDH-Ksko23HZt3nIfcJxRrGSo-eiFomP6TpFoU70Mig@z> From: Pavan Nikhilesh Add macro to align value to the nearest multiple of the given value, resultant value might be greater than or less than the first parameter whichever difference is the lowest. Update unit test to include the new macro. Signed-off-by: Pavan Nikhilesh --- v2 Changes: - Spilt patch and add unit test for the new macro. app/test/test_common.c | 4 ++++ lib/librte_eal/common/include/rte_common.h | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/test/test_common.c b/app/test/test_common.c index 94d367471..2b856f8ba 100644 --- a/app/test/test_common.c +++ b/app/test/test_common.c @@ -199,6 +199,10 @@ test_align(void) val =3D RTE_ALIGN_MUL_FLOOR(i, p); if (val % p !=3D 0 || val > i) FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p); + val =3D RTE_ALIGN_MUL_NEAR(i, p); + if (val % p !=3D 0 || ((val !=3D RTE_ALIGN_MUL_CEIL(i, p)) + & (val !=3D RTE_ALIGN_MUL_FLOOR(i, p)))) + FAIL_ALIGN("RTE_ALIGN_MUL_NEAR", i, p); } } diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/co= mmon/include/rte_common.h index 7178ba1e9..bcf8afd39 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -248,6 +248,18 @@ static void __attribute__((destructor(RTE_PRIO(prio)),= used)) func(void) #define RTE_ALIGN_MUL_FLOOR(v, mul) \ ((v / ((typeof(v))(mul))) * (typeof(v))(mul)) +/** + * Macro to align value to the nearest multiple of the given value. + * The resultant value might be greater than or less than the first parame= ter + * whichever difference is the lowest. + */ +#define RTE_ALIGN_MUL_NEAR(v, mul) \ + ({ \ + typeof(v) ceil =3D RTE_ALIGN_MUL_CEIL(v, mul); \ + typeof(v) floor =3D RTE_ALIGN_MUL_FLOOR(v, mul); \ + (ceil - v) > (v - floor) ? floor : ceil; \ + }) + /** * Checks if a pointer is aligned to a given power-of-two value * -- 2.21.0