eal: add macro to swap two numbers
Checks
Commit Message
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(+)
Comments
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
>
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.
@@ -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)
@@ -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