Commit 00addf5a authored by verwaest@chromium.org's avatar verwaest@chromium.org

Replace log2 with MostSignificantBit

R=ulan@chromium.org

Review URL: https://chromiumcodereview.appspot.com/15994015

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14937 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2380eff2
......@@ -2328,14 +2328,11 @@ Range* HBitwise::InferRange(Zone* zone) {
if (right_upper < 0) right_upper = ~right_upper;
if (right_lower < 0) right_lower = ~right_lower;
// Find the highest used bit.
int high = static_cast<int>(log2(left_upper));
high = Max(high, static_cast<int>(log2(left_lower)));
high = Max(high, static_cast<int>(log2(right_upper)));
high = Max(high, static_cast<int>(log2(right_lower)));
int high = MostSignificantBit(
left_upper | left_lower | right_upper | right_lower);
int64_t limit = 1;
limit <<= high + 1;
limit <<= high;
int32_t min = (left()->range()->CanBeNegative() ||
right()->range()->CanBeNegative())
? static_cast<int32_t>(-limit) : 0;
......
......@@ -86,6 +86,25 @@ inline int WhichPowerOf2(uint32_t x) {
}
inline int MostSignificantBit(uint32_t x) {
static const int msb4[] = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4};
int nibble = 0;
if (x & 0xffff0000) {
nibble += 16;
x >>= 16;
}
if (x & 0xff00) {
nibble += 8;
x >>= 8;
}
if (x & 0xf0) {
nibble += 4;
x >>= 4;
}
return nibble + msb4[x];
}
// Magic numbers for integer division.
// These are kind of 2's complement reciprocal of the divisors.
// Details and proofs can be found in:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment