hotspot/src/share/vm/utilities/globalDefinitions.hpp
changeset 28650 772aaab2582f
parent 28372 ce0aad4b8c44
child 29193 3ede621e9262
equal deleted inserted replaced
28649:eb561bd1bc3c 28650:772aaab2582f
  1140 // long version of is_power_of_2
  1140 // long version of is_power_of_2
  1141 inline bool is_power_of_2_long(jlong x) {
  1141 inline bool is_power_of_2_long(jlong x) {
  1142   return ((x != NoLongBits) && (mask_long_bits(x, x - 1) == NoLongBits));
  1142   return ((x != NoLongBits) && (mask_long_bits(x, x - 1) == NoLongBits));
  1143 }
  1143 }
  1144 
  1144 
  1145 //* largest i such that 2^i <= x
  1145 // Returns largest i such that 2^i <= x.
  1146 //  A negative value of 'x' will return '31'
  1146 // If x < 0, the function returns 31 on a 32-bit machine and 63 on a 64-bit machine.
       
  1147 // If x == 0, the function returns -1.
  1147 inline int log2_intptr(intptr_t x) {
  1148 inline int log2_intptr(intptr_t x) {
  1148   int i = -1;
  1149   int i = -1;
  1149   uintptr_t p =  1;
  1150   uintptr_t p = 1;
  1150   while (p != 0 && p <= (uintptr_t)x) {
  1151   while (p != 0 && p <= (uintptr_t)x) {
  1151     // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
  1152     // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
  1152     i++; p *= 2;
  1153     i++; p *= 2;
  1153   }
  1154   }
  1154   // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))
  1155   // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))
  1155   // (if p = 0 then overflow occurred and i = 31)
  1156   // If p = 0, overflow has occurred and i = 31 or i = 63 (depending on the machine word size).
  1156   return i;
  1157   return i;
  1157 }
  1158 }
  1158 
  1159 
  1159 //* largest i such that 2^i <= x
  1160 //* largest i such that 2^i <= x
  1160 //  A negative value of 'x' will return '63'
  1161 //  A negative value of 'x' will return '63'