DPDK patches and discussions
 help / color / mirror / Atom feed
From: Shijith Thotton <sthotton@marvell.com>
To: <dev@dpdk.org>
Cc: Shijith Thotton <sthotton@marvell.com>, <thomas@monjalon.net>,
	<jerinj@marvell.com>, <pbhagavatula@marvell.com>
Subject: [dpdk-dev] [PATCH] eal: add macro to swap two numbers
Date: Wed, 28 Jul 2021 20:51:42 +0530	[thread overview]
Message-ID: <921c4cfaa08605cac9dd1f63b52139c0860cd622.1627485542.git.sthotton@marvell.com> (raw)

Added a macro to swap two numbers and updated common autotest for the
same.

Signed-off-by: Shijith Thotton <sthotton@marvell.com>
---
Needed-for: drivers: add external clock support for cnxk timer

 app/test/test_common.c       | 4 ++++
 lib/eal/include/rte_common.h | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/app/test/test_common.c b/app/test/test_common.c
index 12bd1cad90..ef177cecb1 100644
--- a/app/test/test_common.c
+++ b/app/test/test_common.c
@@ -30,9 +30,13 @@ test_macros(int __rte_unused unused_parm)
 	return -1;}
 
 	uintptr_t unused = 0;
+	unsigned int smaller = SMALLER, bigger  = BIGGER;
 
 	RTE_SET_USED(unused);
 
+	RTE_SWAP(smaller, bigger);
+	if (smaller != BIGGER && bigger != SMALLER)
+		FAIL_MACRO(RTE_SWAP);
 	if ((uintptr_t)RTE_PTR_ADD(SMALLER, PTR_DIFF) != BIGGER)
 		FAIL_MACRO(RTE_PTR_ADD);
 	if ((uintptr_t)RTE_PTR_SUB(BIGGER, PTR_DIFF) != SMALLER)
diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index d5a32c66a5..09661a5469 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -810,6 +810,14 @@ rte_log2_u64(uint64_t v)
 /** Number of elements in the array. */
 #define	RTE_DIM(a)	(sizeof (a) / sizeof ((a)[0]))
 
+/** Macro to swap two numbers. */
+#define RTE_SWAP(a, b) \
+	__extension__ ({ \
+		typeof (a) _a = a; \
+		a = b; \
+		b = _a; \
+	})
+
 /**
  * Converts a numeric string to the equivalent uint64_t value.
  * As well as straight number conversion, also recognises the suffixes
-- 
2.25.1


             reply	other threads:[~2021-07-28 15:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-28 15:21 Shijith Thotton [this message]
2021-09-06  8:17 ` Jerin Jacob
2021-09-27 16:32   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=921c4cfaa08605cac9dd1f63b52139c0860cd622.1627485542.git.sthotton@marvell.com \
    --to=sthotton@marvell.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=pbhagavatula@marvell.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).