Reviewers: ulan,

Message:
PTAL

Description:
Replace log2 with MostSignificantBit

Please review this at https://chromiumcodereview.appspot.com/15994015/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/hydrogen-instructions.cc
  M src/utils.h


Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index 1943cce372367efd65f79bbdf586058cece1bc03..4b1093e205b515219824ed9850fdf64370844bc5 100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -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;
Index: src/utils.h
diff --git a/src/utils.h b/src/utils.h
index b16730b8c46d750c1e264ad07713868c2b32d804..5680384196d2c870cd519f420d34bb84337fb881 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -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:


--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to