summaryrefslogtreecommitdiff
path: root/deps/v8/src/js/math.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/js/math.js')
-rw-r--r--deps/v8/src/js/math.js115
1 files changed, 22 insertions, 93 deletions
diff --git a/deps/v8/src/js/math.js b/deps/v8/src/js/math.js
index a698fd4285..f8ad6b1fe6 100644
--- a/deps/v8/src/js/math.js
+++ b/deps/v8/src/js/math.js
@@ -10,7 +10,6 @@
// -------------------------------------------------------------------
// Imports
-define kRandomBatchSize = 64;
// The first two slots are reserved to persist PRNG state.
define kRandomNumberStart = 2;
@@ -19,7 +18,7 @@ var GlobalMath = global.Math;
var GlobalObject = global.Object;
var InternalArray = utils.InternalArray;
var NaN = %GetRootNaN();
-var nextRandomIndex = kRandomBatchSize;
+var nextRandomIndex = 0;
var randomNumbers = UNDEFINED;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
@@ -31,33 +30,13 @@ function MathAbs(x) {
return (x > 0) ? x : 0 - x;
}
-// ECMA 262 - 15.8.2.2
-function MathAcosJS(x) {
- return %_MathAcos(+x);
-}
-
-// ECMA 262 - 15.8.2.3
-function MathAsinJS(x) {
- return %_MathAsin(+x);
-}
-
-// ECMA 262 - 15.8.2.4
-function MathAtanJS(x) {
- return %_MathAtan(+x);
-}
-
// ECMA 262 - 15.8.2.5
// The naming of y and x matches the spec, as does the order in which
// ToNumber (valueOf) is called.
function MathAtan2JS(y, x) {
y = +y;
x = +x;
- return %_MathAtan2(y, x);
-}
-
-// ECMA 262 - 15.8.2.6
-function MathCeil(x) {
- return -%_MathFloor(-x);
+ return %MathAtan2(y, x);
}
// ECMA 262 - 15.8.2.8
@@ -65,11 +44,6 @@ function MathExp(x) {
return %MathExpRT(TO_NUMBER(x));
}
-// ECMA 262 - 15.8.2.9
-function MathFloorJS(x) {
- return %_MathFloor(+x);
-}
-
// ECMA 262 - 15.8.2.10
function MathLog(x) {
return %_MathLogRT(TO_NUMBER(x));
@@ -82,34 +56,24 @@ function MathPowJS(x, y) {
// ECMA 262 - 15.8.2.14
function MathRandom() {
- if (nextRandomIndex >= kRandomBatchSize) {
+ // While creating a startup snapshot, %GenerateRandomNumbers returns a
+ // normal array containing a single random number, and has to be called for
+ // every new random number.
+ // Otherwise, it returns a pre-populated typed array of random numbers. The
+ // first two elements are reserved for the PRNG state.
+ if (nextRandomIndex <= kRandomNumberStart) {
randomNumbers = %GenerateRandomNumbers(randomNumbers);
- nextRandomIndex = kRandomNumberStart;
+ nextRandomIndex = randomNumbers.length;
}
- return randomNumbers[nextRandomIndex++];
+ return randomNumbers[--nextRandomIndex];
}
function MathRandomRaw() {
- if (nextRandomIndex >= kRandomBatchSize) {
+ if (nextRandomIndex <= kRandomNumberStart) {
randomNumbers = %GenerateRandomNumbers(randomNumbers);
- nextRandomIndex = kRandomNumberStart;
+ nextRandomIndex = randomNumbers.length;
}
- return %_DoubleLo(randomNumbers[nextRandomIndex++]) & 0x3FFFFFFF;
-}
-
-// ECMA 262 - 15.8.2.15
-function MathRound(x) {
- return %RoundNumber(TO_NUMBER(x));
-}
-
-// ECMA 262 - 15.8.2.17
-function MathSqrtJS(x) {
- return %_MathSqrt(+x);
-}
-
-// Non-standard extension.
-function MathImul(x, y) {
- return %NumberImul(TO_NUMBER(x), TO_NUMBER(y));
+ return %_DoubleLo(randomNumbers[--nextRandomIndex]) & 0x3FFFFFFF;
}
// ES6 draft 09-27-13, section 20.2.2.28.
@@ -121,23 +85,14 @@ function MathSign(x) {
return x;
}
-// ES6 draft 09-27-13, section 20.2.2.34.
-function MathTrunc(x) {
- x = +x;
- if (x > 0) return %_MathFloor(x);
- if (x < 0) return -%_MathFloor(-x);
- // -0, 0 or NaN.
- return x;
-}
-
// ES6 draft 09-27-13, section 20.2.2.5.
function MathAsinh(x) {
x = TO_NUMBER(x);
// Idempotent for NaN, +/-0 and +/-Infinity.
if (x === 0 || !NUMBER_IS_FINITE(x)) return x;
- if (x > 0) return MathLog(x + %_MathSqrt(x * x + 1));
+ if (x > 0) return MathLog(x + %math_sqrt(x * x + 1));
// This is to prevent numerical errors caused by large negative x.
- return -MathLog(-x + %_MathSqrt(x * x + 1));
+ return -MathLog(-x + %math_sqrt(x * x + 1));
}
// ES6 draft 09-27-13, section 20.2.2.3.
@@ -146,7 +101,7 @@ function MathAcosh(x) {
if (x < 1) return NaN;
// Idempotent for NaN and +Infinity.
if (!NUMBER_IS_FINITE(x)) return x;
- return MathLog(x + %_MathSqrt(x + 1) * %_MathSqrt(x - 1));
+ return MathLog(x + %math_sqrt(x + 1) * %math_sqrt(x - 1));
}
// ES6 draft 09-27-13, section 20.2.2.7.
@@ -185,17 +140,7 @@ function MathHypot(x, y) { // Function length is 2.
compensation = (preliminary - sum) - summand;
sum = preliminary;
}
- return %_MathSqrt(sum) * max;
-}
-
-// ES6 draft 09-27-13, section 20.2.2.16.
-function MathFroundJS(x) {
- return %MathFround(TO_NUMBER(x));
-}
-
-// ES6 draft 07-18-14, section 20.2.2.11
-function MathClz32JS(x) {
- return %_MathClz32(x >>> 0);
+ return %math_sqrt(sum) * max;
}
// ES6 draft 09-27-13, section 20.2.2.9.
@@ -213,7 +158,7 @@ macro NEWTON_ITERATION_CBRT(x, approx)
endmacro
function CubeRoot(x) {
- var approx_hi = MathFloorJS(%_DoubleHi(x) / 3) + 0x2A9F7893;
+ var approx_hi = %math_floor(%_DoubleHi(x) / 3) + 0x2A9F7893;
var approx = %_ConstructDouble(approx_hi | 0, 0);
approx = NEWTON_ITERATION_CBRT(x, approx);
approx = NEWTON_ITERATION_CBRT(x, approx);
@@ -223,6 +168,10 @@ function CubeRoot(x) {
// -------------------------------------------------------------------
+%InstallToContext([
+ "math_pow", MathPowJS,
+]);
+
%AddNamedProperty(GlobalMath, toStringTagSymbol, "Math", READ_ONLY | DONT_ENUM);
// Set up math constants.
@@ -246,41 +195,22 @@ utils.InstallConstants(GlobalMath, [
utils.InstallFunctions(GlobalMath, DONT_ENUM, [
"random", MathRandom,
"abs", MathAbs,
- "acos", MathAcosJS,
- "asin", MathAsinJS,
- "atan", MathAtanJS,
- "ceil", MathCeil,
"exp", MathExp,
- "floor", MathFloorJS,
"log", MathLog,
- "round", MathRound,
- "sqrt", MathSqrtJS,
"atan2", MathAtan2JS,
"pow", MathPowJS,
- "imul", MathImul,
"sign", MathSign,
- "trunc", MathTrunc,
"asinh", MathAsinh,
"acosh", MathAcosh,
"atanh", MathAtanh,
"hypot", MathHypot,
- "fround", MathFroundJS,
- "clz32", MathClz32JS,
"cbrt", MathCbrt
]);
%SetForceInlineFlag(MathAbs);
-%SetForceInlineFlag(MathAcosJS);
-%SetForceInlineFlag(MathAsinJS);
-%SetForceInlineFlag(MathAtanJS);
%SetForceInlineFlag(MathAtan2JS);
-%SetForceInlineFlag(MathCeil);
-%SetForceInlineFlag(MathClz32JS);
-%SetForceInlineFlag(MathFloorJS);
%SetForceInlineFlag(MathRandom);
%SetForceInlineFlag(MathSign);
-%SetForceInlineFlag(MathSqrtJS);
-%SetForceInlineFlag(MathTrunc);
// -------------------------------------------------------------------
// Exports
@@ -288,7 +218,6 @@ utils.InstallFunctions(GlobalMath, DONT_ENUM, [
utils.Export(function(to) {
to.MathAbs = MathAbs;
to.MathExp = MathExp;
- to.MathFloor = MathFloorJS;
to.IntRandom = MathRandomRaw;
});