879 while (p != 0 && p <= (uintptr_t)x) { |
879 while (p != 0 && p <= (uintptr_t)x) { |
880 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) |
880 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) |
881 i++; p *= 2; |
881 i++; p *= 2; |
882 } |
882 } |
883 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1)) |
883 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1)) |
884 // (if p = 0 then overflow occured and i = 31) |
884 // (if p = 0 then overflow occurred and i = 31) |
885 return i; |
885 return i; |
886 } |
886 } |
887 |
887 |
888 //* largest i such that 2^i <= x |
888 //* largest i such that 2^i <= x |
889 // A negative value of 'x' will return '63' |
889 // A negative value of 'x' will return '63' |
893 while (p != 0 && p <= (julong)x) { |
893 while (p != 0 && p <= (julong)x) { |
894 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) |
894 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) |
895 i++; p *= 2; |
895 i++; p *= 2; |
896 } |
896 } |
897 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1)) |
897 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1)) |
898 // (if p = 0 then overflow occured and i = 63) |
898 // (if p = 0 then overflow occurred and i = 63) |
899 return i; |
899 return i; |
900 } |
900 } |
901 |
901 |
902 //* the argument must be exactly a power of 2 |
902 //* the argument must be exactly a power of 2 |
903 inline int exact_log2(intptr_t x) { |
903 inline int exact_log2(intptr_t x) { |