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

Unified Diff: src/harmony-math.js

Issue 169783002: Harmony: implement Math.clz32 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: renamed to Math.clz32 Created 6 years, 10 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 | « no previous file | test/mjsunit/harmony/math-clz32.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-math.js
diff --git a/src/harmony-math.js b/src/harmony-math.js
index ee426ef1191f417b2178b17581c1a516704ecaab..7b5883f8e93138301f1b5547baa6ad81460546e9 100644
--- a/src/harmony-math.js
+++ b/src/harmony-math.js
@@ -154,6 +154,20 @@ function MathHypot(x, y) { // Function length is 2.
}
+function MathClz32(x) {
Sven Panne 2014/02/18 07:21:24 What TC39 seems to intend is basically exposing so
+ x = ToUint32(TO_NUMBER_INLINE(x));
+ if (x == 0) return 32;
+ var result = 0;
+ // Binary search.
+ if ((x & 0xFFFF0000) === 0) { x <<= 16; result += 16; };
+ if ((x & 0xFF000000) === 0) { x <<= 8; result += 8; };
+ if ((x & 0xF0000000) === 0) { x <<= 4; result += 4; };
+ if ((x & 0xC0000000) === 0) { x <<= 2; result += 2; };
+ if ((x & 0x80000000) === 0) { x <<= 1; result += 1; };
+ return result;
+}
+
+
function ExtendMath() {
%CheckIsBootstrapping();
@@ -169,8 +183,10 @@ function ExtendMath() {
"atanh", MathAtanh,
"log10", MathLog10,
"log2", MathLog2,
- "hypot", MathHypot
+ "hypot", MathHypot,
+ "clz32", MathClz32
));
}
+
ExtendMath();
« no previous file with comments | « no previous file | test/mjsunit/harmony/math-clz32.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698