From bdebb244d66b6baa6a2a1c3650e18cb90f9400a4 Mon Sep 17 00:00:00 2001 From: Matias Elo Date: Fri, 11 Aug 2023 11:07:13 +0300 Subject: helper: macros: add new macros for min/max comparison operations Add new ODPH_MIN() and ODPH_MAX() helper macros. Signed-off-by: Matias Elo Reviewed-by: Tuomas Taipale Reviewed-by: Petri Savolainen --- helper/Makefile.am | 1 + helper/include/odp/helper/macros.h | 53 ++++++++++++++++++++++++++++++++++++ helper/include/odp/helper/odph_api.h | 1 + 3 files changed, 55 insertions(+) create mode 100644 helper/include/odp/helper/macros.h 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 #include #include +#include #include #include #include -- cgit v1.2.3