summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2016-10-14 13:10:26 +1000
committerDave Airlie <airlied@redhat.com>2016-10-19 09:05:25 +1000
commit78bce52f9a57ea020ef7b9386216efe151be9542 (patch)
tree52a93a0beed3a6327537fa80bc861465b141acd5 /src/util
parentf5daaba0fdd842bf04ede903aea3e63d10a27c6e (diff)
downloadexternal_mesa3d-78bce52f9a57ea020ef7b9386216efe151be9542.zip
external_mesa3d-78bce52f9a57ea020ef7b9386216efe151be9542.tar.gz
external_mesa3d-78bce52f9a57ea020ef7b9386216efe151be9542.tar.bz2
util: move min/max/clamp macros to util macros.h
Although the vulkan drivers include mesa macros.h, for radv I'd like to move away from that. Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com> Acked-by: Jason Ekstrand <jason@jlekstrand.net> Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/macros.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/util/macros.h b/src/util/macros.h
index 9dea2a0..27d1b62 100644
--- a/src/util/macros.h
+++ b/src/util/macros.h
@@ -229,4 +229,17 @@ do { \
/** Compute ceiling of integer quotient of A divided by B. */
#define DIV_ROUND_UP( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
+/** Clamp X to [MIN,MAX] */
+#define CLAMP( X, MIN, MAX ) ( (X)<(MIN) ? (MIN) : ((X)>(MAX) ? (MAX) : (X)) )
+
+/** Minimum of two values: */
+#define MIN2( A, B ) ( (A)<(B) ? (A) : (B) )
+
+/** Maximum of two values: */
+#define MAX2( A, B ) ( (A)>(B) ? (A) : (B) )
+
+/** Minimum and maximum of three values: */
+#define MIN3( A, B, C ) ((A) < (B) ? MIN2(A, C) : MIN2(B, C))
+#define MAX3( A, B, C ) ((A) > (B) ? MAX2(A, C) : MAX2(B, C))
+
#endif /* UTIL_MACROS_H */