< prev index next >

src/share/vm/utilities/globalDefinitions.hpp

Print this page
rev 13049 : imported patch pre_globals_minmax_macros


1078 
1079 // returns the bitfield of x starting at start_bit_no with length field_length (no sign-extension!)
1080 inline intptr_t bitfield(intptr_t x, int start_bit_no, int field_length) {
1081   return mask_bits(x >> start_bit_no, right_n_bits(field_length));
1082 }
1083 
1084 
1085 //----------------------------------------------------------------------------------------------------
1086 // Utility functions for integers
1087 
1088 // Avoid use of global min/max macros which may cause unwanted double
1089 // evaluation of arguments.
1090 #ifdef max
1091 #undef max
1092 #endif
1093 
1094 #ifdef min
1095 #undef min
1096 #endif
1097 
1098 #define max(a,b) Do_not_use_max_use_MAX2_instead
1099 #define min(a,b) Do_not_use_min_use_MIN2_instead
1100 
1101 // It is necessary to use templates here. Having normal overloaded
1102 // functions does not work because it is necessary to provide both 32-
1103 // and 64-bit overloaded functions, which does not work, and having
1104 // explicitly-typed versions of these routines (i.e., MAX2I, MAX2L)
1105 // will be even more error-prone than macros.
1106 template<class T> inline T MAX2(T a, T b)           { return (a > b) ? a : b; }
1107 template<class T> inline T MIN2(T a, T b)           { return (a < b) ? a : b; }
1108 template<class T> inline T MAX3(T a, T b, T c)      { return MAX2(MAX2(a, b), c); }
1109 template<class T> inline T MIN3(T a, T b, T c)      { return MIN2(MIN2(a, b), c); }
1110 template<class T> inline T MAX4(T a, T b, T c, T d) { return MAX2(MAX3(a, b, c), d); }
1111 template<class T> inline T MIN4(T a, T b, T c, T d) { return MIN2(MIN3(a, b, c), d); }
1112 
1113 template<class T> inline T ABS(T x)                 { return (x > 0) ? x : -x; }
1114 
1115 // true if x is a power of 2, false otherwise
1116 inline bool is_power_of_2(intptr_t x) {
1117   return ((x != NoBits) && (mask_bits(x, x - 1) == NoBits));
1118 }
1119 




1078 
1079 // returns the bitfield of x starting at start_bit_no with length field_length (no sign-extension!)
1080 inline intptr_t bitfield(intptr_t x, int start_bit_no, int field_length) {
1081   return mask_bits(x >> start_bit_no, right_n_bits(field_length));
1082 }
1083 
1084 
1085 //----------------------------------------------------------------------------------------------------
1086 // Utility functions for integers
1087 
1088 // Avoid use of global min/max macros which may cause unwanted double
1089 // evaluation of arguments.
1090 #ifdef max
1091 #undef max
1092 #endif
1093 
1094 #ifdef min
1095 #undef min
1096 #endif
1097 
1098 #define max max
1099 #define min min
1100 
1101 // It is necessary to use templates here. Having normal overloaded
1102 // functions does not work because it is necessary to provide both 32-
1103 // and 64-bit overloaded functions, which does not work, and having
1104 // explicitly-typed versions of these routines (i.e., MAX2I, MAX2L)
1105 // will be even more error-prone than macros.
1106 template<class T> inline T MAX2(T a, T b)           { return (a > b) ? a : b; }
1107 template<class T> inline T MIN2(T a, T b)           { return (a < b) ? a : b; }
1108 template<class T> inline T MAX3(T a, T b, T c)      { return MAX2(MAX2(a, b), c); }
1109 template<class T> inline T MIN3(T a, T b, T c)      { return MIN2(MIN2(a, b), c); }
1110 template<class T> inline T MAX4(T a, T b, T c, T d) { return MAX2(MAX3(a, b, c), d); }
1111 template<class T> inline T MIN4(T a, T b, T c, T d) { return MIN2(MIN3(a, b, c), d); }
1112 
1113 template<class T> inline T ABS(T x)                 { return (x > 0) ? x : -x; }
1114 
1115 // true if x is a power of 2, false otherwise
1116 inline bool is_power_of_2(intptr_t x) {
1117   return ((x != NoBits) && (mask_bits(x, x - 1) == NoBits));
1118 }
1119 


< prev index next >