1031 return ((x != NoLongBits) && (mask_long_bits(x, x - 1) == NoLongBits));
1032 }
1033
1034 // Returns largest i such that 2^i <= x.
1035 // If x < 0, the function returns 31 on a 32-bit machine and 63 on a 64-bit machine.
1036 // If x == 0, the function returns -1.
1037 inline int log2_intptr(uintptr_t x) {
1038 int i = -1;
1039 uintptr_t p = 1;
1040 while (p != 0 && p <= x) {
1041 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
1042 i++; p *= 2;
1043 }
1044 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))
1045 // If p = 0, overflow has occurred and i = 31 or i = 63 (depending on the machine word size).
1046 return i;
1047 }
1048
1049 //* largest i such that 2^i <= x
1050 // A negative value of 'x' will return '63'
1051 inline int log2_long(unsigned long x) {
1052 int i = -1;
1053 julong p = 1;
1054 while (p != 0 && p <= x) {
1055 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
1056 i++; p *= 2;
1057 }
1058 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))
1059 // (if p = 0 then overflow occurred and i = 63)
1060 return i;
1061 }
1062
1063 inline int log2_intptr(intptr_t x) {
1064 return log2_intptr((uintptr_t)x);
1065 }
1066
1067 inline int log2_intptr(int x) {
1068 return log2_intptr((uintptr_t)x);
1069 }
1070
1071 inline int log2_intptr(uint x) {
1072 return log2_intptr((uintptr_t)x);
1073 }
1074
1075 inline int log2_long(jlong x) {
1076 return log2_long((unsigned long)x);
1077 }
1078
1079 //* the argument must be exactly a power of 2
1080 inline int exact_log2(intptr_t x) {
1081 assert(is_power_of_2(x), "x must be a power of 2: " INTPTR_FORMAT, x);
1082 return log2_intptr(x);
1083 }
1084
1085 //* the argument must be exactly a power of 2
1086 inline int exact_log2_long(jlong x) {
1087 assert(is_power_of_2_long(x), "x must be a power of 2: " JLONG_FORMAT, x);
1088 return log2_long(x);
1089 }
1090
1091 inline bool is_odd (intx x) { return x & 1; }
1092 inline bool is_even(intx x) { return !is_odd(x); }
1093
1094 // abs methods which cannot overflow and so are well-defined across
1095 // the entire domain of integer types.
1096 static inline unsigned int uabs(unsigned int n) {
|
1031 return ((x != NoLongBits) && (mask_long_bits(x, x - 1) == NoLongBits));
1032 }
1033
1034 // Returns largest i such that 2^i <= x.
1035 // If x < 0, the function returns 31 on a 32-bit machine and 63 on a 64-bit machine.
1036 // If x == 0, the function returns -1.
1037 inline int log2_intptr(uintptr_t x) {
1038 int i = -1;
1039 uintptr_t p = 1;
1040 while (p != 0 && p <= x) {
1041 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
1042 i++; p *= 2;
1043 }
1044 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))
1045 // If p = 0, overflow has occurred and i = 31 or i = 63 (depending on the machine word size).
1046 return i;
1047 }
1048
1049 //* largest i such that 2^i <= x
1050 // A negative value of 'x' will return '63'
1051 inline int log2_long(unsigned long long x) {
1052 int i = -1;
1053 julong p = 1;
1054 while (p != 0 && p <= x) {
1055 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
1056 i++; p *= 2;
1057 }
1058 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))
1059 // (if p = 0 then overflow occurred and i = 63)
1060 return i;
1061 }
1062
1063 inline int log2_intptr(intptr_t x) {
1064 assert(x >= 0, "sanity");
1065 return log2_intptr((uintptr_t)x);
1066 }
1067
1068 inline int log2_int(int x) {
1069 STATIC_ASSERT(sizeof(int) <= sizeof(uintptr_t));
1070 assert(x >= 0, "sanity");
1071 return log2_intptr((uintptr_t)x);
1072 }
1073
1074 inline int log2_jint(jint x) {
1075 STATIC_ASSERT(sizeof(jint) <= sizeof(uintptr_t));
1076 assert(x >= 0, "sanity");
1077 return log2_intptr((uintptr_t)x);
1078 }
1079
1080 inline int log2_uint(uint x) {
1081 STATIC_ASSERT(sizeof(uint) <= sizeof(uintptr_t));
1082 return log2_intptr((uintptr_t)x);
1083 }
1084
1085 inline int log2_jlong(jlong x) {
1086 STATIC_ASSERT(sizeof(jlong) <= sizeof(unsigned long long));
1087 assert(x >= 0, "sanity");
1088 return log2_long((unsigned long long)x);
1089 }
1090
1091 inline int log2_ulong(unsigned long x) {
1092 STATIC_ASSERT(sizeof(unsigned long) <= sizeof(unsigned long long));
1093 return log2_long((unsigned long long)x);
1094 }
1095
1096 //* the argument must be exactly a power of 2
1097 inline int exact_log2(intptr_t x) {
1098 assert(is_power_of_2(x), "x must be a power of 2: " INTPTR_FORMAT, x);
1099 return log2_intptr(x);
1100 }
1101
1102 //* the argument must be exactly a power of 2
1103 inline int exact_log2_long(jlong x) {
1104 assert(is_power_of_2_long(x), "x must be a power of 2: " JLONG_FORMAT, x);
1105 return log2_long(x);
1106 }
1107
1108 inline bool is_odd (intx x) { return x & 1; }
1109 inline bool is_even(intx x) { return !is_odd(x); }
1110
1111 // abs methods which cannot overflow and so are well-defined across
1112 // the entire domain of integer types.
1113 static inline unsigned int uabs(unsigned int n) {
|