[PATCH v4 01/31] eal: add more min/max helpers
Bruce Richardson
bruce.richardson at intel.com
Wed Jan 14 16:44:15 CET 2026
From: Stephen Hemminger <stephen at networkplumber.org>
Add RTE_MIN3() to handle case of RTE_MIN(RTE_MIN(...)), and similarly
add RTE_MAX3(). Change name of local temporary variables in existing
macros to allow for combinations of RTE_MIN(RTE_MAX(...)) without
causing shadow declaration warnings.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
Acked-by: Chengwen Feng <fengchengwen at huawei.com>
Acked-by: Morten Brørup <mb at smartsharesystems.com>
---
lib/eal/include/rte_common.h | 38 ++++++++++++++++++++++++++++++------
1 file changed, 32 insertions(+), 6 deletions(-)
diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index 9e7d84f929..3d013f5592 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -794,9 +794,22 @@ __extension__ typedef uint64_t RTE_MARKER64[0];
*/
#define RTE_MIN(a, b) \
__extension__ ({ \
- typeof (a) _a = (a); \
- typeof (b) _b = (b); \
- _a < _b ? _a : _b; \
+ typeof (a) _a_min = (a); \
+ typeof (b) _b_min = (b); \
+ _a_min < _b_min ? _a_min : _b_min; \
+ })
+
+/**
+ * Macro to return the minimum of three numbers
+ */
+#define RTE_MIN3(a, b, c) \
+ __extension__ ({ \
+ typeof (a) _a_min3 = (a); \
+ typeof (b) _b_min3 = (b); \
+ typeof (c) _c_min3 = (c); \
+ _a_min3 < _b_min3 ? \
+ (_a_min3 < _c_min3 ? _a_min3 : _c_min3) : \
+ (_b_min3 < _c_min3 ? _b_min3 : _c_min3); \
})
/**
@@ -814,9 +827,22 @@ __extension__ typedef uint64_t RTE_MARKER64[0];
*/
#define RTE_MAX(a, b) \
__extension__ ({ \
- typeof (a) _a = (a); \
- typeof (b) _b = (b); \
- _a > _b ? _a : _b; \
+ typeof (a) _a_max = (a); \
+ typeof (b) _b_max = (b); \
+ _a_max > _b_max ? _a_max : _b_max; \
+ })
+
+/**
+ * Macro to return the maximum of three numbers
+ */
+#define RTE_MAX3(a, b, c) \
+ __extension__ ({ \
+ typeof (a) _a_max3 = (a); \
+ typeof (b) _b_max3 = (b); \
+ typeof (c) _c_max3 = (c); \
+ _a_max3 > _b_max3 ? \
+ (_a_max3 > _c_max3 ? _a_max3 : _c_max3) : \
+ (_b_max3 > _c_max3 ? _b_max3 : _c_max3); \
})
/**
--
2.51.0
More information about the dev
mailing list