eal: add macro to swap two variables

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>
This commit is contained in:
Shijith Thotton 2021-07-28 20:51:42 +05:30 committed by Thomas Monjalon
parent 6ded44bce4
commit a0a388a897
2 changed files with 12 additions and 0 deletions

View 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)

View 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.
*