DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] eal: Pointer alignment check improvements
@ 2022-09-21 14:28 Morten Brørup
  2022-09-22 11:44 ` [PATCH v2] " Morten Brørup
  0 siblings, 1 reply; 11+ messages in thread
From: Morten Brørup @ 2022-09-21 14:28 UTC (permalink / raw)
  To: thomas, david.marchand; +Cc: dev, Morten Brørup

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 <mb@smartsharesystems.com>
---
 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 ********/
-- 
2.17.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-09-30  8:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-21 14:28 [PATCH] eal: Pointer alignment check improvements Morten Brørup
2022-09-22 11:44 ` [PATCH v2] " Morten Brørup
2022-09-22 11:52   ` Bruce Richardson
2022-09-22 11:59     ` Bruce Richardson
2022-09-22 13:00       ` Morten Brørup
2022-09-22 13:27         ` [PATCH v3] " Morten Brørup
2022-09-22 13:38           ` Bruce Richardson
2022-09-22 20:54             ` Morten Brørup
2022-09-23  8:24               ` Bruce Richardson
2022-09-23  8:25   ` [PATCH v2] " Bruce Richardson
2022-09-30  8:38     ` David Marchand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).