: jsgraph_(jsgraph), simplified_(jsgraph->zone()) {}
-// ECMA-262, section 15.8.2.1.
-Reduction JSBuiltinReducer::ReduceMathAbs(Node* node) {
- JSCallReduction r(node);
- if (r.InputsMatchOne(Type::Unsigned32())) {
- // Math.abs(a:uint32) -> a
- return Replace(r.left());
- }
- if (r.InputsMatchOne(Type::Number())) {
- // Math.abs(a:number) -> (a > 0 ? a : 0 - a)
- Node* const value = r.left();
- Node* const zero = jsgraph()->ZeroConstant();
- return Replace(graph()->NewNode(
- common()->Select(kMachNone),
- graph()->NewNode(simplified()->NumberLessThan(), zero, value), value,
- graph()->NewNode(simplified()->NumberSubtract(), zero, value)));
- }
- return NoChange();
-}
-
-
-// ECMA-262, section 15.8.2.17.
-Reduction JSBuiltinReducer::ReduceMathSqrt(Node* node) {
- JSCallReduction r(node);
- if (r.InputsMatchOne(Type::Number())) {
- // Math.sqrt(a:number) -> Float64Sqrt(a)
- Node* value = graph()->NewNode(machine()->Float64Sqrt(), r.left());
- return Replace(value);
- }
- return NoChange();
-}
-
-
// ECMA-262, section 15.8.2.11.
Reduction JSBuiltinReducer::ReduceMathMax(Node* node) {
JSCallReduction r(node);
// Dispatch according to the BuiltinFunctionId if present.
if (!r.HasBuiltinFunctionId()) return NoChange();
switch (r.GetBuiltinFunctionId()) {
- case kMathAbs:
- return ReplaceWithPureReduction(node, ReduceMathAbs(node));
- case kMathSqrt:
- return ReplaceWithPureReduction(node, ReduceMathSqrt(node));
case kMathMax:
return ReplaceWithPureReduction(node, ReduceMathMax(node));
case kMathImul:
Reduction Reduce(Node* node) FINAL;
private:
- Reduction ReduceMathAbs(Node* node);
- Reduction ReduceMathSqrt(Node* node);
Reduction ReduceMathMax(Node* node);
Reduction ReduceMathImul(Node* node);
Reduction ReduceMathFround(Node* node);
return ReduceInlineIsInstanceType(node, JS_REGEXP_TYPE);
case Runtime::kInlineMathFloor:
return ReduceInlineMathFloor(node);
+ case Runtime::kInlineMathSqrt:
+ return ReduceInlineMathSqrt(node);
case Runtime::kInlineValueOf:
return ReduceInlineValueOf(node);
default:
}
+Reduction JSIntrinsicLowering::ReduceInlineMathSqrt(Node* node) {
+ return Change(node, machine()->Float64Sqrt());
+}
+
+
Reduction JSIntrinsicLowering::ReduceInlineValueOf(Node* node) {
// if (%_IsSmi(value)) {
// return value;
Reduction ReduceInlineDoubleLo(Node* node);
Reduction ReduceInlineDoubleHi(Node* node);
Reduction ReduceInlineMathFloor(Node* node);
+ Reduction ReduceInlineMathSqrt(Node* node);
Reduction ReduceInlineValueOf(Node* node);
Reduction Change(Node* node, const Operator* op);
return Bounds(Type::None(zone()), Type::Signed32());
case Runtime::kInlineConstructDouble:
case Runtime::kInlineMathFloor:
+ case Runtime::kInlineMathSqrt:
return Bounds(Type::None(zone()), Type::Number());
default:
break;
}
-void HOptimizedGraphBuilder::GenerateMathSqrtRT(CallRuntime* call) {
+void HOptimizedGraphBuilder::GenerateMathSqrt(CallRuntime* call) {
DCHECK(call->arguments()->length() == 1);
CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
HValue* value = Pop();
F(DoubleHi) \
F(DoubleLo) \
F(MathFloor) \
- F(MathSqrtRT) \
+ F(MathSqrt) \
F(MathLogRT) \
/* ES6 Collections */ \
F(MapClear) \
// ECMA 262 - 15.8.2.1
function MathAbs(x) {
- if (%_IsSmi(x)) return x >= 0 ? x : -x;
- x = TO_NUMBER_INLINE(x);
- if (x === 0) return 0; // To handle -0.
- return x > 0 ? x : -x;
+ x = +x;
+ if (x > 0) return x;
+ return 0 - x;
}
// ECMA 262 - 15.8.2.2
// ECMA 262 - 15.8.2.17
function MathSqrt(x) {
- return %_MathSqrtRT(TO_NUMBER_INLINE(x));
+ return %_MathSqrt(+x);
}
// Non-standard extension.
if (!IS_NUMBER(x)) x = NonNumberToNumber(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 + %_MathSqrt(x * x + 1));
// This is to prevent numerical errors caused by large negative x.
- return -MathLog(-x + MathSqrt(x * x + 1));
+ return -MathLog(-x + %_MathSqrt(x * x + 1));
}
// ES6 draft 09-27-13, section 20.2.2.3.
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 + %_MathSqrt(x + 1) * %_MathSqrt(x - 1));
}
// ES6 draft 09-27-13, section 20.2.2.7.
compensation = (preliminary - sum) - summand;
sum = preliminary;
}
- return MathSqrt(sum) * max;
+ return %_MathSqrt(sum) * max;
}
// ES6 draft 09-27-13, section 20.2.2.16.
"cbrt", MathCbrt
));
+%SetInlineBuiltinFlag(MathAbs);
%SetInlineBuiltinFlag(MathCeil);
%SetInlineBuiltinFlag(MathFloor);
%SetInlineBuiltinFlag(MathRandom);
+%SetInlineBuiltinFlag(MathSqrt);
// Expose to the global scope.
$abs = MathAbs;
}
-RUNTIME_FUNCTION(Runtime_MathSqrtRT) {
+RUNTIME_FUNCTION(Runtime_MathSqrt) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
isolate->counters()->math_sqrt()->Increment();
F(DoubleHi, 1, 1) \
F(DoubleLo, 1, 1) \
F(MathFloor, 1, 1) \
- F(MathSqrtRT, 1, 1) \
+ F(MathSqrt, 1, 1) \
F(MathLogRT, 1, 1) \
/* ES6 Collections */ \
F(MapClear, 1, 1) \
__ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
__ push(temp_result);
- __ CallRuntimeSaveDoubles(Runtime::kMathSqrtRT);
+ __ CallRuntimeSaveDoubles(Runtime::kMathSqrt);
RecordSafepointWithRegisters(instr->pointer_map(), 1,
Safepoint::kNoLazyDeopt);
__ StoreToSafepointRegisterSlot(temp_result, eax);
// -----------------------------------------------------------------------------
-// Math.abs
-
-
-TEST_F(JSBuiltinReducerTest, MathAbs) {
- Handle<JSFunction> f = MathFunction("abs");
-
- TRACED_FOREACH(Type*, t0, kNumberTypes) {
- Node* p0 = Parameter(t0, 0);
- Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
- Node* call =
- graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS),
- fun, UndefinedConstant(), p0);
- Reduction r = Reduce(call);
-
- if (t0->Is(Type::Unsigned32())) {
- ASSERT_TRUE(r.Changed());
- EXPECT_THAT(r.replacement(), p0);
- } else {
- Capture<Node*> branch;
- ASSERT_TRUE(r.Changed());
- EXPECT_THAT(
- r.replacement(),
- IsSelect(kMachNone,
- IsNumberLessThan(IsNumberConstant(BitEq(0.0)), p0), p0,
- IsNumberSubtract(IsNumberConstant(BitEq(0.0)), p0)));
- }
- }
-}
-
-
-// -----------------------------------------------------------------------------
-// Math.sqrt
-
-
-TEST_F(JSBuiltinReducerTest, MathSqrt) {
- Handle<JSFunction> f = MathFunction("sqrt");
-
- TRACED_FOREACH(Type*, t0, kNumberTypes) {
- Node* p0 = Parameter(t0, 0);
- Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
- Node* call =
- graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS),
- fun, UndefinedConstant(), p0);
- Reduction r = Reduce(call);
-
- ASSERT_TRUE(r.Changed());
- EXPECT_THAT(r.replacement(), IsFloat64Sqrt(p0));
- }
-}
-
-
-// -----------------------------------------------------------------------------
// Math.max