From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 13CE611A4 for ; Sat, 16 Mar 2019 20:01:58 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2GJ1wRA028185; Sat, 16 Mar 2019 12:01:58 -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=XdWFzKl2vK0mzte/PX+NtjFKefd7YLo+hjk5HkU251w=; b=Ala/65n5vVAAx6jjdGwcQzL5N+XUF1kc7GnJtUT7iLpuOk26LJn9Pt9FEtAJjLJ6RYjb KWIGmwYsEiprMTlXNmmh+UoufLX0pl2NY0TeSuE/eKfbLi6cDJQsGe80K9ykW9N3MjPK +Jc4OdQkce/GG2zofSNDEo7mH55SWGWMXcaUSPFVd+GQJit9lDBC7EngIhJmlc86P35L sH7sZz5fzexV6vsEavzbeE6CJfeCn2mjEdPOPdx7l81Bisp5U227ByCdQ//Sd9dQxLn6 349JSa6afPnmMwCF50X/ZTLpZP6GFaC/LjwIC5ugwNPodzhQnlwfDMxRAbsgeFJwcYrd 5w== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0b-0016f401.pphosted.com with ESMTP id 2r90njgrnx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 16 Mar 2019 12:01:58 -0700 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sat, 16 Mar 2019 12:01:55 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (104.47.38.57) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Sat, 16 Mar 2019 12:01:55 -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=XdWFzKl2vK0mzte/PX+NtjFKefd7YLo+hjk5HkU251w=; b=OjtMf2mFUtGYEgQ1MoJUIhFxXsSpbOCT9WZ3eu3vvoWTAvme3urNwvHNtC6Uz0DKXpEnpeRbvCpa7seFg4uV3FzL57mSi0QPKcsJtajI7DSrLK4hEmZihLhvzKLnWiiHpUjhQ4K8TVTi2wIfWuAMiZHESGX+V+ziX1oU+EbM804= Received: from CY4PR1801MB1863.namprd18.prod.outlook.com (10.171.255.14) by CY4PR1801MB1879.namprd18.prod.outlook.com (10.171.255.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.13; Sat, 16 Mar 2019 19:01:50 +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 19:01:50 +0000 From: Pavan Nikhilesh Bhagavatula To: Jerin Jacob Kollanukkaran , "keith.wiles@intel.com" , "stephen@networkplumber.org" , "thomas@monjalon.net" CC: "dev@dpdk.org" , Pavan Nikhilesh Bhagavatula Thread-Topic: [dpdk-dev] [PATCH v3 1/2] eal: add macro to align value to the nearest multiple Thread-Index: AQHU3Cq1ZZdqtyPLD0aA7uJCQBFjSg== Date: Sat, 16 Mar 2019 19:01:50 +0000 Message-ID: <20190316190119.6142-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: BM1PR01CA0160.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:68::30) 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: [115.113.156.3] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1e9e1b44-69dc-41b9-7c7a-08d6aa41d83c x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(2017052603328)(7153060)(7193020); SRVR:CY4PR1801MB1879; x-ms-traffictypediagnostic: CY4PR1801MB1879: x-microsoft-antispam-prvs: x-forefront-prvs: 09781D4C35 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(396003)(346002)(39850400004)(366004)(376002)(199004)(189003)(2616005)(476003)(6512007)(6436002)(446003)(11346002)(25786009)(86362001)(106356001)(99286004)(54906003)(66066001)(36756003)(186003)(6486002)(105586002)(76176011)(316002)(486006)(4326008)(26005)(55236004)(3846002)(102836004)(386003)(97736004)(6506007)(478600001)(8676002)(71190400001)(81156014)(6116002)(53936002)(68736007)(50226002)(110136005)(81166006)(14454004)(8936002)(52116002)(107886003)(2501003)(1076003)(5660300002)(305945005)(7736002)(2906002)(256004)(14444005)(2201001)(71200400001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1801MB1879; 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: HwPQEWpWJ72A/yExAquTQcVGu69aRQAB+9gX66XOpKx9QdW1mjO3rXUH54+ZT0JTDKnoiW6ubvtEWoqpl11bkILt2rU2UqfliCviwwVhXiVx4PF2iwXYqk6QUU+iH32r874lq1TlgwD73bZRub0E7Y3NAlMCjxzpcUSVyQHb5UVvuuRmuWXMRyLxXTIGJzNv9LDj2019O7Qj+l/C5QWPc4in3k+uzpa09LE75TIUjymKJIogwMUviLVSsfXchPYttaD582PPQQQxvB0McjzXpV77HyKy9co5xmRU+gbE6Ak0RbeYZZJo/XjL8O0ZFMb4z7qHoD03TmUn/cLo2Jym565lrudk151xkHTBtOMzRD+WHcjfoEGIWa5V4+I9BCN8IZbipH5a0KWbBZAXlTotkTka/CJxscG4f/rAAu45cVY= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 1e9e1b44-69dc-41b9-7c7a-08d6aa41d83c X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Mar 2019 19:01:50.1425 (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: CY4PR1801MB1879 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-03-16_15:, , signatures=0 Subject: [dpdk-dev] [PATCH v3 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 19:01:59 -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. v3 Changes: - Rebase to ToT. - Use macro instead of 1E7. 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 AF844A0096 for ; Sat, 16 Mar 2019 20:02:01 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A205011C5; Sat, 16 Mar 2019 20:02:00 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 13CE611A4 for ; Sat, 16 Mar 2019 20:01:58 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2GJ1wRA028185; Sat, 16 Mar 2019 12:01:58 -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=XdWFzKl2vK0mzte/PX+NtjFKefd7YLo+hjk5HkU251w=; b=Ala/65n5vVAAx6jjdGwcQzL5N+XUF1kc7GnJtUT7iLpuOk26LJn9Pt9FEtAJjLJ6RYjb KWIGmwYsEiprMTlXNmmh+UoufLX0pl2NY0TeSuE/eKfbLi6cDJQsGe80K9ykW9N3MjPK +Jc4OdQkce/GG2zofSNDEo7mH55SWGWMXcaUSPFVd+GQJit9lDBC7EngIhJmlc86P35L sH7sZz5fzexV6vsEavzbeE6CJfeCn2mjEdPOPdx7l81Bisp5U227ByCdQ//Sd9dQxLn6 349JSa6afPnmMwCF50X/ZTLpZP6GFaC/LjwIC5ugwNPodzhQnlwfDMxRAbsgeFJwcYrd 5w== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0b-0016f401.pphosted.com with ESMTP id 2r90njgrnx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 16 Mar 2019 12:01:58 -0700 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sat, 16 Mar 2019 12:01:55 -0700 Received: from NAM02-BL2-obe.outbound.protection.outlook.com (104.47.38.57) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Sat, 16 Mar 2019 12:01:55 -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=XdWFzKl2vK0mzte/PX+NtjFKefd7YLo+hjk5HkU251w=; b=OjtMf2mFUtGYEgQ1MoJUIhFxXsSpbOCT9WZ3eu3vvoWTAvme3urNwvHNtC6Uz0DKXpEnpeRbvCpa7seFg4uV3FzL57mSi0QPKcsJtajI7DSrLK4hEmZihLhvzKLnWiiHpUjhQ4K8TVTi2wIfWuAMiZHESGX+V+ziX1oU+EbM804= Received: from CY4PR1801MB1863.namprd18.prod.outlook.com (10.171.255.14) by CY4PR1801MB1879.namprd18.prod.outlook.com (10.171.255.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.13; Sat, 16 Mar 2019 19:01:50 +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 19:01:50 +0000 From: Pavan Nikhilesh Bhagavatula To: Jerin Jacob Kollanukkaran , "keith.wiles@intel.com" , "stephen@networkplumber.org" , "thomas@monjalon.net" CC: "dev@dpdk.org" , Pavan Nikhilesh Bhagavatula Thread-Topic: [dpdk-dev] [PATCH v3 1/2] eal: add macro to align value to the nearest multiple Thread-Index: AQHU3Cq1ZZdqtyPLD0aA7uJCQBFjSg== Date: Sat, 16 Mar 2019 19:01:50 +0000 Message-ID: <20190316190119.6142-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: BM1PR01CA0160.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:68::30) 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: [115.113.156.3] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1e9e1b44-69dc-41b9-7c7a-08d6aa41d83c x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(2017052603328)(7153060)(7193020); SRVR:CY4PR1801MB1879; x-ms-traffictypediagnostic: CY4PR1801MB1879: x-microsoft-antispam-prvs: x-forefront-prvs: 09781D4C35 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(396003)(346002)(39850400004)(366004)(376002)(199004)(189003)(2616005)(476003)(6512007)(6436002)(446003)(11346002)(25786009)(86362001)(106356001)(99286004)(54906003)(66066001)(36756003)(186003)(6486002)(105586002)(76176011)(316002)(486006)(4326008)(26005)(55236004)(3846002)(102836004)(386003)(97736004)(6506007)(478600001)(8676002)(71190400001)(81156014)(6116002)(53936002)(68736007)(50226002)(110136005)(81166006)(14454004)(8936002)(52116002)(107886003)(2501003)(1076003)(5660300002)(305945005)(7736002)(2906002)(256004)(14444005)(2201001)(71200400001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1801MB1879; 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: HwPQEWpWJ72A/yExAquTQcVGu69aRQAB+9gX66XOpKx9QdW1mjO3rXUH54+ZT0JTDKnoiW6ubvtEWoqpl11bkILt2rU2UqfliCviwwVhXiVx4PF2iwXYqk6QUU+iH32r874lq1TlgwD73bZRub0E7Y3NAlMCjxzpcUSVyQHb5UVvuuRmuWXMRyLxXTIGJzNv9LDj2019O7Qj+l/C5QWPc4in3k+uzpa09LE75TIUjymKJIogwMUviLVSsfXchPYttaD582PPQQQxvB0McjzXpV77HyKy9co5xmRU+gbE6Ak0RbeYZZJo/XjL8O0ZFMb4z7qHoD03TmUn/cLo2Jym565lrudk151xkHTBtOMzRD+WHcjfoEGIWa5V4+I9BCN8IZbipH5a0KWbBZAXlTotkTka/CJxscG4f/rAAu45cVY= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 1e9e1b44-69dc-41b9-7c7a-08d6aa41d83c X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Mar 2019 19:01:50.1425 (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: CY4PR1801MB1879 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-03-16_15:, , signatures=0 Subject: [dpdk-dev] [PATCH v3 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: <20190316190150.andgpbEXgdE0F8f4Y0JnV12TdfjmKQYHp5yRoAYAgjU@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. v3 Changes: - Rebase to ToT. - Use macro instead of 1E7. 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