eal: add macro to swap two variables
authorShijith Thotton <sthotton@marvell.com>
Wed, 28 Jul 2021 15:21:42 +0000 (20:51 +0530)
committerThomas Monjalon <thomas@monjalon.net>
Mon, 27 Sep 2021 16:33:45 +0000 (18:33 +0200)
Add a macro to swap two variables
and updat common autotest for the same.

Signed-off-by: Shijith Thotton <sthotton@marvell.com>
Acked-by: Jerin Jacob <jerinj@marvell.com>
app/test/test_common.c
lib/eal/include/rte_common.h

index 12bd1ca..ef177ce 100644 (file)
@@ -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)
index 99eb5f1..4a399cc 100644 (file)
@@ -778,6 +778,14 @@ rte_log2_u64(uint64_t v)
                })
 #endif
 
+/** Swap two variables. */
+#define RTE_SWAP(a, b) \
+       __extension__ ({ \
+               typeof (a) _a = a; \
+               a = b; \
+               b = _a; \
+       })
+
 /**
  * Get the size of a field in a structure.
  *