From: Bruce Richardson Date: Tue, 11 Feb 2014 10:08:43 +0000 (+0000) Subject: eal: new common macros added X-Git-Tag: spdx-start~11046 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=a3fd610463291df1ce7dfdea60d74d8f9742dc13;p=dpdk.git eal: new common macros added Added the following new macros/inline functions, which are both generally useful and needed for later functionality: * rte_align64pow2: aligns a 64bit parameter to next power of 2 * RTE_LEN2MASK: create mask of type with the first bits * RTE_DIM: return the number of elements in an array. Signed-off-by: Bruce Richardson --- diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index 2d0c7945c2..0cf328ecd8 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -49,6 +49,7 @@ extern "C" { #include #include #include +#include /*********** Macros to eliminate unused variable warnings ********/ @@ -68,7 +69,7 @@ extern "C" { /** * add a byte-value offset from a pointer */ -#define RTE_PTR_ADD(ptr, x) ((typeof(ptr))((uintptr_t)ptr + (x))) +#define RTE_PTR_ADD(ptr, x) ((typeof(ptr))((uintptr_t)(ptr) + (x))) /** * subtract a byte-value offset from a pointer @@ -227,6 +228,29 @@ rte_align32pow2(uint32_t x) return x + 1; } +/** + * Aligns 64b input parameter to the next power of 2 + * + * @param x + * The 64b value to algin + * + * @return + * Input parameter aligned to the next power of 2 + */ +static inline uint64_t +rte_align64pow2(uint64_t v) +{ + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v |= v >> 32; + + return v + 1; +} + /*********** Macros for calculating min and max **********/ /** @@ -290,6 +314,13 @@ rte_bsf32(uint32_t v) /** Take a macro value and get a string version of it */ #define RTE_STR(x) _RTE_STR(x) +/** Mask value of type for the first bit set. */ +#define RTE_LEN2MASK(ln, tp) \ + ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln)))) + +/** Number of elements in the array. */ +#define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0])) + /** * Converts a numeric string to the equivalent uint64_t value. * As well as straight number conversion, also recognises the suffixes