diff mbox series

eal: add macro to swap two numbers

Message ID 921c4cfaa08605cac9dd1f63b52139c0860cd622.1627485542.git.sthotton@marvell.com (mailing list archive)
State Accepted
Delegated to: Thomas Monjalon
Headers show
Series eal: add macro to swap two numbers | expand

Checks

Context Check Description
ci/iol-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/github-robot success github build: passed
ci/Intel-compilation success Compilation OK
ci/checkpatch warning coding style issues

Commit Message

Shijith Thotton July 28, 2021, 3:21 p.m. UTC
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

Jerin Jacob Sept. 6, 2021, 8:17 a.m. UTC | #1
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
>
Thomas Monjalon Sept. 27, 2021, 4:32 p.m. UTC | #2
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.
diff mbox series

Patch

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