* [dpdk-dev] [PATCH] eal: add macro to swap two numbers
@ 2021-07-28 15:21 Shijith Thotton
2021-09-06 8:17 ` Jerin Jacob
0 siblings, 1 reply; 3+ messages in thread
From: Shijith Thotton @ 2021-07-28 15:21 UTC (permalink / raw)
To: dev; +Cc: Shijith Thotton, thomas, jerinj, pbhagavatula
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dpdk-dev] [PATCH] eal: add macro to swap two numbers
2021-07-28 15:21 [dpdk-dev] [PATCH] eal: add macro to swap two numbers Shijith Thotton
@ 2021-09-06 8:17 ` Jerin Jacob
2021-09-27 16:32 ` Thomas Monjalon
0 siblings, 1 reply; 3+ messages in thread
From: Jerin Jacob @ 2021-09-06 8:17 UTC (permalink / raw)
To: Shijith Thotton; +Cc: dpdk-dev, Thomas Monjalon, Jerin Jacob, Pavan Nikhilesh
On Wed, Jul 28, 2021 at 8:52 PM Shijith Thotton <sthotton@marvell.com> wrote:
>
> Added a macro to swap two numbers and updated common autotest for the
> same.
>
> Signed-off-by: Shijith Thotton <sthotton@marvell.com>
Acked-by: Jerin Jacob <jerinj@marvell.com>
> ---
> Needed-for: drivers: add external clock support for cnxk timer
@Thomas Monjalon Could you merge this to the main tree if the patch
looks OK to you.
>
> 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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dpdk-dev] [PATCH] eal: add macro to swap two numbers
2021-09-06 8:17 ` Jerin Jacob
@ 2021-09-27 16:32 ` Thomas Monjalon
0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2021-09-27 16:32 UTC (permalink / raw)
To: Shijith Thotton; +Cc: dev, Jerin Jacob, Pavan Nikhilesh, Jerin Jacob
06/09/2021 10:17, Jerin Jacob:
> On Wed, Jul 28, 2021 at 8:52 PM Shijith Thotton <sthotton@marvell.com> wrote:
> >
> > Added a macro to swap two numbers and updated common autotest for the
> > same.
> >
> > Signed-off-by: Shijith Thotton <sthotton@marvell.com>
>
> Acked-by: Jerin Jacob <jerinj@marvell.com>
>
> > Needed-for: drivers: add external clock support for cnxk timer
>
> @Thomas Monjalon Could you merge this to the main tree if the patch
> looks OK to you.
>
> > --- a/lib/eal/include/rte_common.h
> > +++ b/lib/eal/include/rte_common.h
> > +/** Macro to swap two numbers. */
> > +#define RTE_SWAP(a, b) \
> > + __extension__ ({ \
> > + typeof (a) _a = a; \
> > + a = b; \
> > + b = _a; \
> > + })
Changing comment to:
/** Swap two variables. */
Applied, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-27 16:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28 15:21 [dpdk-dev] [PATCH] eal: add macro to swap two numbers Shijith Thotton
2021-09-06 8:17 ` Jerin Jacob
2021-09-27 16:32 ` Thomas Monjalon
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).