Introduce MIN()/MAX() macros in utils.h
authordp-arm <dimitris.papastamos@arm.com>
Tue, 21 Mar 2017 15:38:06 +0000 (15:38 +0000)
committerdp-arm <dimitris.papastamos@arm.com>
Fri, 31 Mar 2017 12:58:51 +0000 (13:58 +0100)
Change-Id: If88270bc9edb32634a793b1e1be6c4829f39b9c5
Signed-off-by: dp-arm <dimitris.papastamos@arm.com>
include/lib/utils.h

index 69bbb430a2c9874446bc5fc27f479ef0cee7e807..279c91351fc316d10766a6c707a68d6d52ee07c6 100644 (file)
 
 #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.