aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Elo <matias.elo@nokia.com>2023-08-11 11:07:13 +0300
committerMatias Elo <matias.elo@nokia.com>2023-10-23 10:59:18 +0300
commitbdebb244d66b6baa6a2a1c3650e18cb90f9400a4 (patch)
tree2c3102905b56ac6fb5fe1daa916ba18f0a2f719c
parent5182ce145834f70501ff707f4790399d8512bb00 (diff)
helper: macros: add new macros for min/max comparison operations
Add new ODPH_MIN() and ODPH_MAX() helper macros. Signed-off-by: Matias Elo <matias.elo@nokia.com> Reviewed-by: Tuomas Taipale <tuomas.taipale@nokia.com> Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
-rw-r--r--helper/Makefile.am1
-rw-r--r--helper/include/odp/helper/macros.h53
-rw-r--r--helper/include/odp/helper/odph_api.h1
3 files changed, 55 insertions, 0 deletions
diff --git a/helper/Makefile.am b/helper/Makefile.am
index 458a99f92..6e1ce583f 100644
--- a/helper/Makefile.am
+++ b/helper/Makefile.am
@@ -23,6 +23,7 @@ helperinclude_HEADERS = \
include/odp/helper/igmp.h\
include/odp/helper/ip.h\
include/odp/helper/ipsec.h\
+ include/odp/helper/macros.h\
include/odp/helper/odph_api.h\
include/odp/helper/odph_cuckootable.h\
include/odp/helper/odph_hashtable.h\
diff --git a/helper/include/odp/helper/macros.h b/helper/include/odp/helper/macros.h
new file mode 100644
index 000000000..bfcb768b1
--- /dev/null
+++ b/helper/include/odp/helper/macros.h
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2023 Nokia
+ */
+
+/**
+ * @file
+ *
+ * Common helper macros
+ */
+
+#ifndef ODPH_MACROS_H_
+#define ODPH_MACROS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup odph_macros ODPH MACROS
+ * Helper macros
+ *
+ * @{
+ */
+
+/**
+ * Return minimum of two numbers
+ */
+#define ODPH_MIN(a, b) \
+ __extension__ ({ \
+ __typeof__(a) tmp_a = (a); \
+ __typeof__(b) tmp_b = (b); \
+ tmp_a < tmp_b ? tmp_a : tmp_b; \
+ })
+
+/**
+ * Return maximum of two numbers
+ */
+#define ODPH_MAX(a, b) \
+ __extension__ ({ \
+ __typeof__(a) tmp_a = (a); \
+ __typeof__(b) tmp_b = (b); \
+ tmp_a > tmp_b ? tmp_a : tmp_b; \
+ })
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ODPH_MACROS_H_ */
diff --git a/helper/include/odp/helper/odph_api.h b/helper/include/odp/helper/odph_api.h
index b4e3985c8..94d43a61b 100644
--- a/helper/include/odp/helper/odph_api.h
+++ b/helper/include/odp/helper/odph_api.h
@@ -28,6 +28,7 @@ extern "C" {
#include <odp/helper/igmp.h>
#include <odp/helper/ip.h>
#include <odp/helper/ipsec.h>
+#include <odp/helper/macros.h>
#include <odp/helper/odph_lineartable.h>
#include <odp/helper/odph_iplookuptable.h>
#include <odp/helper/sctp.h>