[01/12] eal: introduce more macro for bit definition
Checks
Commit Message
Introduce macros: RTE_MBIT64/RTE_MBIT32, RTE_GENMASK64/RTE_GENMASK32,
and RTE_FIELD_GET64/RTE_FIELD_GET32.
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
lib/eal/include/rte_bitops.h | 64 ++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
Comments
22/01/2024 04:57, Chengwen Feng:
> Introduce macros: RTE_MBIT64/RTE_MBIT32, RTE_GENMASK64/RTE_GENMASK32,
> and RTE_FIELD_GET64/RTE_FIELD_GET32.
A bit of context and description would help.
> +/**
> + * Get the uint64_t value for a multiple bits set.
> + *
> + * @param val
> + * The value may not all 1s.
> + * @param nr
> + * The bit number in range of 0 to (64 - width of val).
> + */
> +#define RTE_MBIT64(val, nr) (UINT64_C(val) << (nr))
I don't understand this macro.
I think you mean that val is shifted by nr.
Please revise the description.
@@ -39,6 +39,70 @@ extern "C" {
*/
#define RTE_BIT32(nr) (UINT32_C(1) << (nr))
+/**
+ * Get the uint64_t value for a multiple bits set.
+ *
+ * @param val
+ * The value may not all 1s.
+ * @param nr
+ * The bit number in range of 0 to (64 - width of val).
+ */
+#define RTE_MBIT64(val, nr) (UINT64_C(val) << (nr))
+
+/**
+ * Get the uint32_t value for a multiple bits set.
+ *
+ * @param val
+ * The value may not all 1s.
+ * @param nr
+ * The bit number in range of 0 to (32 - width of val).
+ */
+#define RTE_MBIT32(val, nr) (UINT32_C(val) << (nr))
+
+/**
+ * Generate a contiguous 64bit bitmask starting at bit position low
+ * and ending at position high.
+ *
+ * @param high
+ * High bit position.
+ * @param low
+ * Low bit position.
+ */
+#define RTE_GENMASK64(high, low) (((~UINT64_C(0)) << (low)) & (~UINT64_C(0) >> (63u - (high))))
+
+/**
+ * Generate a contiguous 32bit bitmask starting at bit position low
+ * and ending at position high.
+ *
+ * @param high
+ * High bit position.
+ * @param low
+ * Low bit position.
+ */
+#define RTE_GENMASK32(high, low) (((~UINT32_C(0)) << (low)) & (~UINT32_C(0) >> (31u - (high))))
+
+/**
+ * Extract a 64bit field element.
+ *
+ * @param mask
+ * shifted mask.
+ * @param reg
+ * value of entire bitfield.
+ */
+#define RTE_FIELD_GET64(mask, reg) \
+ (typeof(mask))(((reg) & (mask)) >> rte_ctz64(mask))
+
+/**
+ * Extract a 32bit field element.
+ *
+ * @param mask
+ * shifted mask.
+ * @param reg
+ * value of entire bitfield.
+ */
+#define RTE_FIELD_GET32(mask, reg) \
+ (typeof(mask))(((reg) & (mask)) >> rte_ctz32(mask))
+
/*------------------------ 32-bit relaxed operations ------------------------*/
/**