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

Unified Diff: src/js/math.js

Issue 1425693006: Store RNG state on function context. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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/bootstrapper.cc ('k') | src/js/prologue.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/math.js
diff --git a/src/js/math.js b/src/js/math.js
index 4d0b1f7282a4caae07f7cc7d4abc908bc1ac011b..ba2b2186f4aebc56396c56ecb349f9ae33739825 100644
--- a/src/js/math.js
+++ b/src/js/math.js
@@ -14,12 +14,19 @@ var GlobalMath = global.Math;
var GlobalObject = global.Object;
var InternalArray = utils.InternalArray;
var NaN = %GetRootNaN();
-var rngstate;
+var rngstate_0;
+var rngstate_1;
+var rngstate_2;
+var rngstate_3;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
-utils.SetupTypedArray(function(arg1, arg2, arg3) {
- rngstate = arg1;
-});
+utils.InitializeRNG = function() {
+ var rngstate = %InitializeRNG();
+ rngstate_0 = rngstate[0];
+ rngstate_1 = rngstate[1];
+ rngstate_2 = rngstate[2];
+ rngstate_3 = rngstate[3];
+};
//-------------------------------------------------------------------
@@ -134,22 +141,25 @@ function MathPowJS(x, y) {
// ECMA 262 - 15.8.2.14
function MathRandom() {
- var r0 = (MathImul(18030, rngstate[0] & 0xFFFF) + (rngstate[0] >>> 16)) | 0;
- rngstate[0] = r0;
- var r1 = (MathImul(36969, rngstate[1] & 0xFFFF) + (rngstate[1] >>> 16)) | 0;
- rngstate[1] = r1;
- var x = ((r0 << 16) + (r1 & 0xFFFF)) | 0;
- // Division by 0x100000000 through multiplication by reciprocal.
- return (x < 0 ? (x + 0x100000000) : x) * 2.3283064365386962890625e-10;
+ var r0 = (MathImul(18030, rngstate_0) + rngstate_1) | 0;
+ var r1 = (MathImul(36969, rngstate_2) + rngstate_3) | 0;
+ rngstate_0 = r0 & 0xFFFF;
+ rngstate_1 = r0 >>> 16;
+ rngstate_2 = r1 & 0xFFFF;
+ rngstate_3 = r1 >>> 16;
+ // Construct a double number 1.<32-bits of randomness> and subtract 1.
+ return %_ConstructDouble(0x3FF00000 | (r0 & 0x000FFFFF), r1 & 0xFFF00000) - 1;
}
function MathRandomRaw() {
- var r0 = (MathImul(18030, rngstate[0] & 0xFFFF) + (rngstate[0] >>> 16)) | 0;
- rngstate[0] = r0;
- var r1 = (MathImul(36969, rngstate[1] & 0xFFFF) + (rngstate[1] >>> 16)) | 0;
- rngstate[1] = r1;
+ var r0 = (MathImul(18030, rngstate_0) + rngstate_1) | 0;
+ var r1 = (MathImul(36969, rngstate_2) + rngstate_3) | 0;
+ rngstate_0 = r0 & 0xFFFF;
+ rngstate_1 = r0 >>> 16;
+ rngstate_2 = r1 & 0xFFFF;
+ rngstate_3 = r1 >>> 16;
var x = ((r0 << 16) + (r1 & 0xFFFF)) | 0;
- return x & 0x3fffffff;
+ return x & 0x3FFFFFFF;
}
// ECMA 262 - 15.8.2.15
« no previous file with comments | « src/bootstrapper.cc ('k') | src/js/prologue.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698