947 template<class T> inline T MAX4(T a, T b, T c, T d) { return MAX2(MAX3(a, b, c), d); } |
947 template<class T> inline T MAX4(T a, T b, T c, T d) { return MAX2(MAX3(a, b, c), d); } |
948 template<class T> inline T MIN4(T a, T b, T c, T d) { return MIN2(MIN3(a, b, c), d); } |
948 template<class T> inline T MIN4(T a, T b, T c, T d) { return MIN2(MIN3(a, b, c), d); } |
949 |
949 |
950 template<class T> inline T ABS(T x) { return (x > 0) ? x : -x; } |
950 template<class T> inline T ABS(T x) { return (x > 0) ? x : -x; } |
951 |
951 |
|
952 // Return the given value clamped to the range [min ... max] |
|
953 template<typename T> |
|
954 inline T clamp(T value, T min, T max) { |
|
955 assert(min <= max, "must be"); |
|
956 return MIN2(MAX2(value, min), max); |
|
957 } |
|
958 |
952 // true if x is a power of 2, false otherwise |
959 // true if x is a power of 2, false otherwise |
953 inline bool is_power_of_2(intptr_t x) { |
960 inline bool is_power_of_2(intptr_t x) { |
954 return ((x != NoBits) && (mask_bits(x, x - 1) == NoBits)); |
961 return ((x != NoBits) && (mask_bits(x, x - 1) == NoBits)); |
955 } |
962 } |
956 |
963 |