1 /*
2  * Copyright (c) 2010-2014 Wind River Systems, Inc.
3  * Copyright (c) 2023 Nordic Semiconductor ASA
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #ifndef NSI_COMMON_SRC_INCL_NSI_UTILS_H
9 #define NSI_COMMON_SRC_INCL_NSI_UTILS_H
10 
11 /* Remove brackets from around a single argument: */
12 #define NSI_DEBRACKET(...) __VA_ARGS__
13 
14 #define _NSI_STRINGIFY(x) #x
15 #define NSI_STRINGIFY(s) _NSI_STRINGIFY(s)
16 
17 /* concatenate the values of the arguments into one */
18 #define NSI_DO_CONCAT(x, y) x ## y
19 #define NSI_CONCAT(x, y) NSI_DO_CONCAT(x, y)
20 
21 #define NSI_MAX(a, b)  (((a) > (b)) ? (a) : (b))
22 #define NSI_MIN(a, b) (((a) < (b)) ? (a) : (b))
23 
24 #define NSI_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
25 
26 #ifndef NSI_ARG_UNUSED
27 #define NSI_ARG_UNUSED(x) (void)(x)
28 #endif
29 
30 #define NSI_CODE_UNREACHABLE __builtin_unreachable()
31 
32 #define NSI_FUNC_NORETURN __attribute__((__noreturn__))
33 #define NSI_WEAK __attribute__((__weak__))
34 #define NSI_INLINE static __attribute__((__always_inline__)) inline
35 
36 #if defined(__clang__)
37   /* The address sanitizer in llvm adds padding (redzones) after data
38    * But for those we are re-grouping using the linker script
39    * we cannot have that extra padding as we intend to iterate over them
40    */
41 #define NSI_NOASAN __attribute__((no_sanitize("address")))
42 #else
43 #define NSI_NOASAN
44 #endif
45 
46 #endif /* NSI_COMMON_SRC_INCL_NSI_UTILS_H */
47