From patchwork Wed Sep 21 14:28:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Morten_Br=C3=B8rup?= X-Patchwork-Id: 116569 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4DF40A00C3; Wed, 21 Sep 2022 16:29:23 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2459B42B83; Wed, 21 Sep 2022 16:28:47 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 9712342B71 for ; Wed, 21 Sep 2022 16:28:46 +0200 (CEST) Received: from dkrd2.smartsharesys.local ([192.168.4.12]) by smartserver.smartsharesystems.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 21 Sep 2022 16:28:45 +0200 From: =?utf-8?q?Morten_Br=C3=B8rup?= To: thomas@monjalon.net, david.marchand@redhat.com Cc: dev@dpdk.org, =?utf-8?q?Morten_Br=C3=B8rup?= Subject: [PATCH] eal: Pointer alignment check improvements Date: Wed, 21 Sep 2022 16:28:30 +0200 Message-Id: <20220921142830.71272-1-mb@smartsharesystems.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-OriginalArrivalTime: 21 Sep 2022 14:28:46.0010 (UTC) FILETIME=[752669A0:01D8CDC6] X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Checking a const pointer for alignment would emit a warning about the const qualifier being discarded. No need to calculate the aligned pointer; just check the last bits of the pointer. Signed-off-by: Morten Brørup --- lib/eal/include/rte_common.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index 2e22c1b955..5c20d3a81a 100644 --- a/lib/eal/include/rte_common.h +++ b/lib/eal/include/rte_common.h @@ -403,10 +403,10 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) * @return * True(1) where the pointer is correctly aligned, false(0) otherwise */ -static inline int -rte_is_aligned(void *ptr, unsigned align) +static __rte_always_inline __attribute__ ((const)) int +rte_is_aligned(const void * const __rte_restrict ptr, unsigned int align) { - return RTE_PTR_ALIGN(ptr, align) == ptr; + return ((uintptr_t)ptr & (align - 1)) == 0; } /*********** Macros for compile type checks ********/