diff options
author | dp-arm <dimitris.papastamos@arm.com> | 2017-03-21 15:38:06 +0000 |
---|---|---|
committer | dp-arm <dimitris.papastamos@arm.com> | 2017-03-31 13:58:51 +0100 |
commit | 233d83d06c22adaefc82dcacbe8b29ab20d76c35 (patch) | |
tree | 63fb2994608db2896b645bc58fed235f4b2c54c4 /include/lib/utils.h | |
parent | 51faada71a219a8b94cd8d8e423f0f22e9da4d8f (diff) |
Introduce MIN()/MAX() macros in utils.h
Change-Id: If88270bc9edb32634a793b1e1be6c4829f39b9c5
Signed-off-by: dp-arm <dimitris.papastamos@arm.com>
Diffstat (limited to 'include/lib/utils.h')
-rw-r--r-- | include/lib/utils.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/include/lib/utils.h b/include/lib/utils.h index 69bbb430..279c9135 100644 --- a/include/lib/utils.h +++ b/include/lib/utils.h @@ -42,6 +42,20 @@ #define BIT(nr) (1UL << (nr)) +#define MIN(x, y) __extension__ ({ \ + __typeof__(x) _x = (x); \ + __typeof__(y) _y = (y); \ + (void)(&_x == &_y); \ + _x < _y ? _x : _y; \ +}) + +#define MAX(x, y) __extension__ ({ \ + __typeof__(x) _x = (x); \ + __typeof__(y) _y = (y); \ + (void)(&_x == &_y); \ + _x > _y ? _x : _y; \ +}) + /* * 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. |