diff options
author | Lionel Debieve <lionel.debieve@st.com> | 2020-01-02 11:14:16 +0100 |
---|---|---|
committer | Lionel Debieve <lionel.debieve@st.com> | 2020-01-20 11:32:59 +0100 |
commit | e76d9fc422698a88cee13e960154e185670861dc (patch) | |
tree | bdde332ba0f91b44f2a11977287441b7fc0476ea /include/lib | |
parent | 162fc183cf439efe029a581fbde8e4f936815f6d (diff) | |
download | platform_external_arm-trusted-firmware-e76d9fc422698a88cee13e960154e185670861dc.tar.gz platform_external_arm-trusted-firmware-e76d9fc422698a88cee13e960154e185670861dc.tar.bz2 platform_external_arm-trusted-firmware-e76d9fc422698a88cee13e960154e185670861dc.zip |
lib: utils_def: add CLAMP macro
Add the standard CLAMP macro. It ensures that
x is between the limits set by low and high.
If low is greater than high the result is undefined.
Signed-off-by: Lionel Debieve <lionel.debieve@st.com>
Change-Id: Ia173bb9ca51bc8d9a8ec573bbc15636a94f881f4
Diffstat (limited to 'include/lib')
-rw-r--r-- | include/lib/utils_def.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/include/lib/utils_def.h b/include/lib/utils_def.h index 35ae33a68..23f59bdc3 100644 --- a/include/lib/utils_def.h +++ b/include/lib/utils_def.h @@ -77,6 +77,15 @@ _x > _y ? _x : _y; \ }) +#define CLAMP(x, min, max) __extension__ ({ \ + __typeof__(x) _x = (x); \ + __typeof__(min) _min = (min); \ + __typeof__(max) _max = (max); \ + (void)(&_x == &_min); \ + (void)(&_x == &_max); \ + (_x > _max ? _max : (_x < _min ? _min : _x)); \ +}) + /* * The round_up() macro rounds up a value to the given boundary in a * type-agnostic yet type-safe manner. The boundary must be a power of two. |