diff options
author | Luca Boccassi <luca.boccassi@gmail.com> | 2018-11-27 10:44:39 +0000 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2018-11-27 10:45:47 +0000 |
commit | a4f0fa29488e582ab8b5ef9db475b3d26ded690c (patch) | |
tree | de163f35a726d518a3f93ab6ee4ac25b8982635d /lib/librte_eal/common/include/rte_common.h | |
parent | 29058550643267a554e0368806dece63b047c5cb (diff) |
New upstream version 18.11upstream/18.11upstream
Change-Id: I6c63198045de1e34fda8a7b4665d89d5f4a20d20
Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
Diffstat (limited to 'lib/librte_eal/common/include/rte_common.h')
-rw-r--r-- | lib/librte_eal/common/include/rte_common.h | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index 87f0f630..66cdf60b 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -270,16 +270,7 @@ rte_is_aligned(void *ptr, unsigned align) /** * Triggers an error at compilation time if the condition is true. */ -#ifndef __OPTIMIZE__ #define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) -#else -extern int RTE_BUILD_BUG_ON_detected_error; -#define RTE_BUILD_BUG_ON(condition) do { \ - ((void)sizeof(char[1 - 2*!!(condition)])); \ - if (condition) \ - RTE_BUILD_BUG_ON_detected_error = 1; \ -} while(0) -#endif /** * Combines 32b inputs most significant set bits into the least @@ -491,6 +482,29 @@ rte_fls_u32(uint32_t x) return (x == 0) ? 0 : 32 - __builtin_clz(x); } +/** + * Searches the input parameter for the least significant set bit + * (starting from zero). Safe version (checks for input parameter being zero). + * + * @warning ``pos`` must be a valid pointer. It is not checked! + * + * @param v + * The input parameter. + * @param pos + * If ``v`` was not 0, this value will contain position of least significant + * bit within the input parameter. + * @return + * Returns 0 if ``v`` was 0, otherwise returns 1. + */ +static inline int +rte_bsf64_safe(uint64_t v, uint32_t *pos) +{ + if (v == 0) + return 0; + + *pos = __builtin_ctzll(v); + return 1; +} #ifndef offsetof /** Return the offset of a field in a structure. */ |