aboutsummaryrefslogtreecommitdiffstats
path: root/lib/librte_eal/common/include/rte_common.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/librte_eal/common/include/rte_common.h')
-rw-r--r--lib/librte_eal/common/include/rte_common.h32
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. */