From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0044.outbound.protection.outlook.com [104.47.41.44]) by dpdk.org (Postfix) with ESMTP id 080834D3A for ; Tue, 20 Mar 2018 14:24:59 +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=iF4NF9PXfoJSU9mb3NdO9te6d4oJaHZptTKa/0BLnYw=; b=legIiUgneGS6hBTj9BeeN01+2T/LFfXVCg8fFjmNrPZC/BITw36fluulQrgt49Gd6xsGADTCyDPY/RAuw6Vl++HY3y6kutrr/vJomXHgXvoHv+Aem8UMJrXaqQ1Ea2ZsF5K5KI8RElynSxyguIwZ9HGBJDULxUjXEtJAh3KbLaY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Pavan.Bhagavatula@cavium.com; Received: from ltp-pvn.caveonetworks.com (111.93.218.67) by BN6PR07MB3459.namprd07.prod.outlook.com (10.161.153.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.588.14; Tue, 20 Mar 2018 13:24:54 +0000 From: Pavan Nikhilesh To: jerin.jacob@caviumnetworks.com, thomas@monjalon.net, konstantin.ananyev@intel.com Cc: dev@dpdk.org, Pavan Nikhilesh Date: Tue, 20 Mar 2018 18:54:34 +0530 Message-Id: <20180320132434.4825-1-pbhagavatula@caviumnetworks.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180314094100.12373-1-pbhagavatula@caviumnetworks.com> References: <20180314094100.12373-1-pbhagavatula@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: CO2PR04CA0127.namprd04.prod.outlook.com (10.165.95.29) To BN6PR07MB3459.namprd07.prod.outlook.com (10.161.153.22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3e60ca98-1c17-4485-2ee6-08d58e65f953 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603328)(7153060)(7193020); SRVR:BN6PR07MB3459; X-Microsoft-Exchange-Diagnostics: 1; BN6PR07MB3459; 3:BdyihqYbMwgq/AY09I4pQARZlcHEb1FtKiDz8GFo+l1jQir/lE18383d9BJcZGk0o4jxGePe6z7cg39WkrEWKWHlU50YdphL0P73aeMjEEdhVJBiUxHzYCZjrHGip3H+QGhDwp7BDKTnTex8/tHkMT90l+BVEnHqNH8mSpcuPzVLtgd8qBWJRSKbMb87MuBDuYIeGfEl62kuUx/bgBV86m4lR+i0XcYMPYtvR3bKVr6H1fmog37olkUCIdcl4m1U; 25:9ebsFQNO7wcqa3DyLS7lW2vt8BlYEzYxZqwF7rp1KzYe6turC4y4amutR2N5Nw3uBCnDpsmA2wN9y4cs4fHzC6PRRz3VTAJ1W20O7rq7yEwh0McoZWGoRF/mrjZ81oJIyxRPsZkukCb0LHKo2Vcobz5+koSV68rYwJJ3Ye+Pvbhg6GTZxoTS6wyOdSG9IfkG0X3TZ5nX7QHX3bec8qRmC6v2+sCGgXWp3X2ZLXow1abuH+hTVF3egEShbXPfr7kobgXRpCZZAdwyEmvn2oUgiFO7DJ61huVKlJEBtOm32r4yTilVbtVb7pH2eVj9l8ChtXfF9wsTN7WZ8WsqcMEGMA==; 31:Eq7h2ULFP5glOvVxhxbDknKXaJiS1pWgDlvgdn8+62BTo48d0CRNHDKaC9cdJCXpf+TbqQEAVfE//ahm6mQhl3Q5IF/amHX93Dep9JEJ7b+2H+TSwnORzrANB2dVlpUvOtCMp3adjGPdDAe37Wn7YkNFJ+n51DwiSkGr1Nid7qCsCJ1G1Ja4ubID4EsO3OsjzL0uR1VzP6s/Rg6+1XBjvXERukg5g4dZ6x1/ZWRMj+8= X-MS-TrafficTypeDiagnostic: BN6PR07MB3459: X-Microsoft-Exchange-Diagnostics: 1; BN6PR07MB3459; 20:+xZy7dTXUiok138tc/ZLN4mIXiUXrHK/g4M8kSsvZJWcq8PEiFI9/suG+Up5jYWJTWg2rEms7y7nro//94R6NYauCXpxCow5fPkQWp+XyM2SrZI6lsCYytWeCbkMLclH5cU1piR4RDbJ5ylaJqApUjfXN/D0PfREBa0zqGJcl/pJBC0wEgV576VASA+LzeFaBKl55oHus0DorGmuolYH/Dmk1+CLfLzL/6Mqe5mjyiAJFq0T4wXVeIkP/3EVZllU0ce8uBFvzupKJ/+JoOqKXTp1iMyOHa4yg23S7nve95SVE1BaAIokIApoN0xbDzKQbJ0KrPnF4YWVcxyA+bszd4cxiOwGGryO3LkGVmzgS78DotQ4G9UDmJH9Cw5ir5MP1EFAQw7NWuuzuPWEntJoiex4W64P31YvNlLwC/acQlDLKeJLQsP6uPIADCYFpJtU5okuG5GMQRK9GIMaNf/97ROeJodlkKdXcqjJswJHUNWkFXMTgmKvUPIB3xk045wnX1mLEmyoMgpOpv5sxilcRz6GbgL65LddMj41LmuoIzzd96v/Dt25R2NeHRRgjsnEDbVmu/814m16fAXd+RfqUEloFvj1gpBEBb8Geh7hdgk=; 4:F++6AQfWDN9OR47Egjis/XekFCVmBpZbR8oX06JB+npBx0Y7n+nfEfdr8oJM5wVImZRsGtgR7hQGfeLrAPEQCkz5YI0Sh3S62gNOetH8W2lnejRypSMDzAHLZiIF5DUp/pwi9gAXz0sCpQgJwGTwInVYKx6Y0hapgiNiesaG/ETYBAX47SL9tVPXQKdwqKW+0ZwRIcrNHY4k7I+2Kmnu9jvKc8NZ1H4YdzKbJ4EGdgIaJLY/EDXO2uacyCRezwOnXXULdC2LPb/ThBEHcb9/jQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(3231221)(944501311)(52105095)(3002001)(10201501046)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:BN6PR07MB3459; BCL:0; PCL:0; RULEID:; SRVR:BN6PR07MB3459; X-Forefront-PRVS: 061725F016 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(396003)(39380400002)(366004)(376002)(39850400004)(189003)(199004)(8676002)(26005)(16586007)(6486002)(72206003)(53416004)(50466002)(16526019)(316002)(42882007)(5009440100003)(105586002)(386003)(6666003)(6506007)(2950100002)(48376002)(1857600001)(69596002)(76176011)(6116002)(1076002)(3846002)(50226002)(81156014)(52116002)(51416003)(5660300001)(305945005)(7736002)(81166006)(36756003)(97736004)(68736007)(47776003)(66066001)(4326008)(25786009)(2906002)(8936002)(107886003)(53936002)(478600001)(6512007)(106356001)(42262002); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR07MB3459; H:ltp-pvn.caveonetworks.com; 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; BN6PR07MB3459; 23:sByC1tAs+6gPvnC3gQXMijCU8W1X6mPN5UyoJ96qR?= =?us-ascii?Q?jIO2XhMJFQzZqdf+Giv4uFsPHm/INRgDfK98GShT7WOoo0TwpIEKS5aAjSkB?= =?us-ascii?Q?0HUD4kNoMTO78dwYYBuXJ5jhe06PH0HFzPXPDuNBrwsux9xgm/TpL3k6vnML?= =?us-ascii?Q?KVsdsZalri1atYW0HbzZgAoRWxwbOxkdMr/casQowsHkX/itTXkcrdhtILNJ?= =?us-ascii?Q?+3whIRlJcJ37VeKixA2bz+ovF8lJhGuiobicEtqDWoYV7PLYGq3W3tukS55G?= =?us-ascii?Q?r5+VsK8XGXDwcLDo84Vpp1GxML8gaSILEdjSUGjViErLvd8euPE3bxyKYUPB?= =?us-ascii?Q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zZzLSRIKQ5M1+6YUXNLVNkbnw3GpWN4Bkk0WI6CaHzfGpQ17aWFmtu1zdk/kWGoxB+cVznsNI9P/p0sL7mKi2Y0Jup60Gz+pK2HL+S5KfsB8jZQb8nvm+PKVWYWrrbtCmlXgEHd SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Mar 2018 13:24:54.8299 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3e60ca98-1c17-4485-2ee6-08d58e65f953 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR07MB3459 Subject: [dpdk-dev] [PATCH v2] eal: add macros to align value to 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: Tue, 20 Mar 2018 13:24:59 -0000 Add macros to align given value to the multiple of the supplied integer. Signed-off-by: Pavan Nikhilesh --- Common code needed for OcteonTx event timer device. v2 Changes: - Use paranthesis around mul (Konstantin). - Squash test_common patch. lib/librte_eal/common/include/rte_common.h | 16 ++++++++++++++++ test/test/test_common.c | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index c7803e41c..4469affb9 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -190,6 +190,22 @@ static void __attribute__((constructor(prio), used)) func(void) */ #define RTE_ALIGN(val, align) RTE_ALIGN_CEIL(val, align) +/** + * Macro to align a value to the multiple of given value. The resultant + * value will be of the same type as the first parameter and will be no lower + * than the first parameter. + */ +#define RTE_ALIGN_MUL_CEIL(v, mul) \ + (((v + (typeof(v))(mul) - 1) / ((typeof(v))(mul))) * (typeof(v))(mul)) + +/** + * Macro to align a value to the multiple of given value. The resultant + * value will be of the same type as the first parameter and will be no higher + * than the first parameter. + */ +#define RTE_ALIGN_MUL_FLOOR(v, mul) \ + ((v / ((typeof(v))(mul))) * (typeof(v))(mul)) + /** * Checks if a pointer is aligned to a given power-of-two value * diff --git a/test/test/test_common.c b/test/test/test_common.c index d0342430f..e43cba49b 100644 --- a/test/test/test_common.c +++ b/test/test/test_common.c @@ -128,6 +128,18 @@ test_align(void) FAIL("rte_is_aligned"); } } + + for (p = 1; p <= MAX_NUM / 2; p++) { + for (i = 1; i <= MAX_NUM / 2; i++) { + val = RTE_ALIGN_MUL_CEIL(i, p); + if (val % p != 0 || val < i) + FAIL_ALIGN("RTE_ALIGN_MUL_CEIL", i, p); + val = RTE_ALIGN_MUL_FLOOR(i, p); + if (val % p != 0 || val > i) + FAIL_ALIGN("RTE_ALIGN_MUL_FLOOR", i, p); + } + } + return 0; } -- 2.16.2