Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: src/utils.h

Issue 15994015: Replace log2 with MostSignificantBit (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/hydrogen-instructions.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:
« no previous file with comments | « src/hydrogen-instructions.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698