DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] eal: avoid side effects in RTE_ALIGN_MUL_NEAR(v, mul) for v and mul
@ 2021-03-11 21:08 Tyler Retzlaff
  2021-03-12  0:40 ` Ranjit Menon
  2021-03-12  8:07 ` David Marchand
  0 siblings, 2 replies; 10+ messages in thread
From: Tyler Retzlaff @ 2021-03-11 21:08 UTC (permalink / raw)
  To: dev; +Cc: thomas

Avoid expanding v and mul parameters multiple times in the macro. based
on usage of the macro it seems like side effects were not intended.

For example:
  ``return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, CYC_PER_10MHZ);''

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 lib/librte_eal/include/rte_common.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/include/rte_common.h b/lib/librte_eal/include/rte_common.h
index 1b630baf1..640befee2 100644
--- a/lib/librte_eal/include/rte_common.h
+++ b/lib/librte_eal/include/rte_common.h
@@ -345,9 +345,11 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
  */
 #define RTE_ALIGN_MUL_NEAR(v, mul)				\
 	({							\
-		typeof(v) ceil = RTE_ALIGN_MUL_CEIL(v, mul);	\
-		typeof(v) floor = RTE_ALIGN_MUL_FLOOR(v, mul);	\
-		(ceil - (v)) > ((v) - floor) ? floor : ceil;	\
+		typeof(v) _v = (v);				\
+		typeof(v) _m = (mul);				\
+		typeof(v) ceil = RTE_ALIGN_MUL_CEIL(_v, _m);	\
+		typeof(v) floor = RTE_ALIGN_MUL_FLOOR(_v, _m);	\
+		(ceil - (_v)) > ((_v) - floor) ? floor : ceil;	\
 	})
 
 /**
-- 
2.30.0.vfs.0.2


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

end of thread, other threads:[~2021-05-06 12:24 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-11 21:08 [dpdk-dev] [PATCH] eal: avoid side effects in RTE_ALIGN_MUL_NEAR(v, mul) for v and mul Tyler Retzlaff
2021-03-12  0:40 ` Ranjit Menon
2021-03-12  1:34   ` Tyler Retzlaff
2021-03-12  4:41     ` Ranjit Menon
2021-03-12  6:28       ` Tyler Retzlaff
2021-03-12  8:07 ` David Marchand
2021-03-12 18:49   ` Tyler Retzlaff
2021-05-05 16:30   ` Tyler Retzlaff
2021-05-05 20:28     ` David Marchand
2021-05-06 12:24       ` [dpdk-dev] [EXT] " Pavan Nikhilesh Bhagavatula

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).