Mesa (master): util: make macros MIN3, MAX3, MIN4, MAX4 little more efficient

Marek Olšák mareko at kemper.freedesktop.org
Wed Apr 27 04:17:53 PDT 2011


Module: Mesa
Branch: master
Commit: b8de75d53760fb359d10d6f4794f28097210cef4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b8de75d53760fb359d10d6f4794f28097210cef4

Author: Marek Olšák <maraeo at gmail.com>
Date:   Wed Apr 27 12:54:24 2011 +0200

util: make macros MIN3, MAX3, MIN4, MAX4 little more efficient

---

 src/gallium/auxiliary/util/u_math.h |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index e3d4c06..dad6a10 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -581,11 +581,11 @@ util_bswap16(uint16_t n)
 #define MIN2( A, B )   ( (A)<(B) ? (A) : (B) )
 #define MAX2( A, B )   ( (A)>(B) ? (A) : (B) )
 
-#define MIN3( A, B, C ) MIN2( MIN2( A, B ), C )
-#define MAX3( A, B, C ) MAX2( MAX2( A, B ), C )
+#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))
 
-#define MIN4( A, B, C, D ) MIN2( MIN2( A, B ), MIN2(C, D) )
-#define MAX4( A, B, C, D ) MAX2( MAX2( A, B ), MAX2(C, D) )
+#define MIN4( A, B, C, D ) ((A) < (B) ? MIN3(A, C, D) : MIN3(B, C, D))
+#define MAX4( A, B, C, D ) ((A) > (B) ? MAX3(A, C, D) : MAX3(B, C, D))
 
 
 /**



More information about the mesa-commit mailing list