2014-09-23 11:26:49 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "src/compiler/js-builtin-reducer.h"
|
|
|
|
#include "src/compiler/js-graph.h"
|
2015-01-29 09:17:45 +00:00
|
|
|
#include "src/compiler/node-properties.h"
|
2015-10-19 08:05:05 +00:00
|
|
|
#include "src/compiler/simplified-operator.h"
|
2014-09-23 11:26:49 +00:00
|
|
|
#include "src/compiler/typer.h"
|
2015-09-01 09:25:19 +00:00
|
|
|
#include "src/isolate-inl.h"
|
2014-10-20 11:26:23 +00:00
|
|
|
#include "test/unittests/compiler/graph-unittest.h"
|
|
|
|
#include "test/unittests/compiler/node-test-utils.h"
|
2014-09-23 11:40:00 +00:00
|
|
|
#include "testing/gmock-support.h"
|
|
|
|
|
2015-01-05 12:29:04 +00:00
|
|
|
using testing::BitEq;
|
2014-09-23 11:40:00 +00:00
|
|
|
using testing::Capture;
|
2014-09-23 11:26:49 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
2014-10-15 11:38:04 +00:00
|
|
|
class JSBuiltinReducerTest : public TypedGraphTest {
|
2014-09-23 11:26:49 +00:00
|
|
|
public:
|
|
|
|
JSBuiltinReducerTest() : javascript_(zone()) {}
|
|
|
|
|
|
|
|
protected:
|
Add floor, ceil, round (truncate) instructions for ia32, x64 (if SSE4.1) and
add floor, ceil, round (truncate and away from zero) for arm64.
R=bmeurer@chromium.org, dcarney@chromium.org, mstarzinger@chromium.org, rodolph.perfetta@arm.com
TEST=test/mjsunit/asm/math-floor.js,test/mjsunit/asm/math-ceil.js,test/unittest/compiler/js-builtin-reducer-unittest.cc
Review URL: https://codereview.chromium.org/677433002
Cr-Commit-Position: refs/heads/master@{#25018}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@25018 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-10-30 14:15:20 +00:00
|
|
|
Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags =
|
|
|
|
MachineOperatorBuilder::Flag::kNoFlags) {
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineOperatorBuilder machine(zone(), MachineType::PointerRepresentation(),
|
|
|
|
flags);
|
2015-10-19 08:05:05 +00:00
|
|
|
SimplifiedOperatorBuilder simplified(zone());
|
|
|
|
JSGraph jsgraph(isolate(), graph(), common(), javascript(), &simplified,
|
2015-10-16 12:38:46 +00:00
|
|
|
&machine);
|
2015-06-05 12:37:43 +00:00
|
|
|
// TODO(titzer): mock the GraphReducer here for better unit testing.
|
|
|
|
GraphReducer graph_reducer(zone(), graph());
|
2016-08-11 13:13:05 +00:00
|
|
|
JSBuiltinReducer reducer(&graph_reducer, &jsgraph,
|
|
|
|
JSBuiltinReducer::kNoFlags, nullptr);
|
2014-09-23 11:26:49 +00:00
|
|
|
return reducer.Reduce(node);
|
|
|
|
}
|
|
|
|
|
2015-04-27 10:44:47 +00:00
|
|
|
Node* MathFunction(const char* name) {
|
2014-10-08 14:42:31 +00:00
|
|
|
Handle<Object> m =
|
|
|
|
JSObject::GetProperty(isolate()->global_object(),
|
|
|
|
isolate()->factory()->NewStringFromAsciiChecked(
|
|
|
|
"Math")).ToHandleChecked();
|
|
|
|
Handle<JSFunction> f = Handle<JSFunction>::cast(
|
2016-03-08 17:29:05 +00:00
|
|
|
Object::GetProperty(
|
2014-10-08 14:42:31 +00:00
|
|
|
m, isolate()->factory()->NewStringFromAsciiChecked(name))
|
|
|
|
.ToHandleChecked());
|
2015-08-31 08:24:52 +00:00
|
|
|
return HeapConstant(f);
|
2014-10-08 14:42:31 +00:00
|
|
|
}
|
|
|
|
|
2016-07-05 09:49:52 +00:00
|
|
|
Node* NumberFunction(const char* name) {
|
|
|
|
Handle<Object> m =
|
|
|
|
JSObject::GetProperty(
|
|
|
|
isolate()->global_object(),
|
|
|
|
isolate()->factory()->NewStringFromAsciiChecked("Number"))
|
|
|
|
.ToHandleChecked();
|
|
|
|
Handle<JSFunction> f = Handle<JSFunction>::cast(
|
|
|
|
Object::GetProperty(
|
|
|
|
m, isolate()->factory()->NewStringFromAsciiChecked(name))
|
|
|
|
.ToHandleChecked());
|
|
|
|
return HeapConstant(f);
|
|
|
|
}
|
|
|
|
|
2016-06-02 07:59:29 +00:00
|
|
|
Node* StringFunction(const char* name) {
|
|
|
|
Handle<Object> m =
|
|
|
|
JSObject::GetProperty(
|
|
|
|
isolate()->global_object(),
|
|
|
|
isolate()->factory()->NewStringFromAsciiChecked("String"))
|
|
|
|
.ToHandleChecked();
|
|
|
|
Handle<JSFunction> f = Handle<JSFunction>::cast(
|
|
|
|
Object::GetProperty(
|
|
|
|
m, isolate()->factory()->NewStringFromAsciiChecked(name))
|
|
|
|
.ToHandleChecked());
|
|
|
|
return HeapConstant(f);
|
|
|
|
}
|
|
|
|
|
2014-09-23 11:26:49 +00:00
|
|
|
JSOperatorBuilder* javascript() { return &javascript_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSOperatorBuilder javascript_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-04-27 10:44:47 +00:00
|
|
|
Type* const kIntegral32Types[] = {Type::UnsignedSmall(), Type::Negative32(),
|
|
|
|
Type::Unsigned31(), Type::SignedSmall(),
|
|
|
|
Type::Signed32(), Type::Unsigned32(),
|
|
|
|
Type::Integral32()};
|
|
|
|
|
|
|
|
|
2014-09-23 11:26:49 +00:00
|
|
|
Type* const kNumberTypes[] = {
|
2015-01-28 08:42:15 +00:00
|
|
|
Type::UnsignedSmall(), Type::Negative32(), Type::Unsigned31(),
|
|
|
|
Type::SignedSmall(), Type::Signed32(), Type::Unsigned32(),
|
|
|
|
Type::Integral32(), Type::MinusZero(), Type::NaN(),
|
|
|
|
Type::OrderedNumber(), Type::PlainNumber(), Type::Number()};
|
2014-09-23 11:26:49 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
2016-06-28 04:34:20 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.abs
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAbsWithNumber) {
|
|
|
|
Node* function = MathFunction("abs");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAbs(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAbsWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("abs");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAbs(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
[builtins] Unify most of the remaining Math builtins.
Import fdlibm versions of acos, acosh, asin and asinh, which are more
precise and produce the same result across platforms (we were using
libm versions for asin and acos so far, where both speed and precision
depended on the operating system so far). Introduce appropriate TurboFan
operators for these functions and use them both for inlining and for the
generic builtin.
Also migrate the Math.imul and Math.fround builtins to TurboFan builtins
to ensure that their behavior is always exactly the same as the inlined
TurboFan version (i.e. C++ truncation semantics for double to float
don't necessarily meet the JavaScript semantics).
For completeness, also migrate Math.sign, which can even get some nice
love in TurboFan.
Drive-by-fix: Some alpha-sorting on the Math related functions, and
cleanup the list of Math intrinsics that we have to export via the
native context currently.
BUG=v8:3266,v8:3496,v8:3509,v8:3952,v8:5169,v8:5170,v8:5171,v8:5172
TBR=rossberg@chromium.org
R=franzih@chromium.org
Review-Url: https://codereview.chromium.org/2116753002
Cr-Commit-Position: refs/heads/master@{#37476}
2016-07-01 11:11:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.acos
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAcosWithNumber) {
|
|
|
|
Node* function = MathFunction("acos");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAcos(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAcosWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("acos");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAcos(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.acosh
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAcoshWithNumber) {
|
|
|
|
Node* function = MathFunction("acosh");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAcosh(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAcoshWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("acosh");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAcosh(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.asin
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAsinWithNumber) {
|
|
|
|
Node* function = MathFunction("asin");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAsin(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAsinWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("asin");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAsin(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.asinh
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAsinhWithNumber) {
|
|
|
|
Node* function = MathFunction("asinh");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAsinh(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAsinhWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("asinh");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAsinh(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
2014-09-23 11:40:00 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-06-15 05:43:36 +00:00
|
|
|
// Math.atan
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAtanWithNumber) {
|
|
|
|
Node* function = MathFunction("atan");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAtan(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAtanWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("atan");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAtan(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
[builtins] Unify most of the remaining Math builtins.
Import fdlibm versions of acos, acosh, asin and asinh, which are more
precise and produce the same result across platforms (we were using
libm versions for asin and acos so far, where both speed and precision
depended on the operating system so far). Introduce appropriate TurboFan
operators for these functions and use them both for inlining and for the
generic builtin.
Also migrate the Math.imul and Math.fround builtins to TurboFan builtins
to ensure that their behavior is always exactly the same as the inlined
TurboFan version (i.e. C++ truncation semantics for double to float
don't necessarily meet the JavaScript semantics).
For completeness, also migrate Math.sign, which can even get some nice
love in TurboFan.
Drive-by-fix: Some alpha-sorting on the Math related functions, and
cleanup the list of Math intrinsics that we have to export via the
native context currently.
BUG=v8:3266,v8:3496,v8:3509,v8:3952,v8:5169,v8:5170,v8:5171,v8:5172
TBR=rossberg@chromium.org
R=franzih@chromium.org
Review-Url: https://codereview.chromium.org/2116753002
Cr-Commit-Position: refs/heads/master@{#37476}
2016-07-01 11:11:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.atanh
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAtanhWithNumber) {
|
|
|
|
Node* function = MathFunction("atanh");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAtanh(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAtanhWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("atanh");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAtanh(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.atan2
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAtan2WithNumber) {
|
|
|
|
Node* function = MathFunction("atan2");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
TRACED_FOREACH(Type*, t1, kNumberTypes) {
|
|
|
|
Node* p1 = Parameter(t1, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
|
|
|
|
UndefinedConstant(), p0, p1, context,
|
|
|
|
frame_state, effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAtan2(p0, p1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathAtan2WithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("atan2");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* p1 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
|
|
|
|
UndefinedConstant(), p0, p1, context,
|
|
|
|
frame_state, effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberAtan2(IsPlainPrimitiveToNumber(p0),
|
|
|
|
IsPlainPrimitiveToNumber(p1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.ceil
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathCeilWithNumber) {
|
|
|
|
Node* function = MathFunction("ceil");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberCeil(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathCeilWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("ceil");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberCeil(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.clz32
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathClz32WithUnsigned32) {
|
|
|
|
Node* function = MathFunction("clz32");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::Unsigned32(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberClz32(p0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathClz32WithNumber) {
|
|
|
|
Node* function = MathFunction("clz32");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::Number(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberClz32(IsNumberToUint32(p0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathClz32WithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("clz32");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(),
|
|
|
|
IsNumberClz32(IsNumberToUint32(IsPlainPrimitiveToNumber(p0))));
|
|
|
|
}
|
|
|
|
|
2016-06-17 05:19:35 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-06-17 15:21:48 +00:00
|
|
|
// Math.cos
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathCosWithNumber) {
|
|
|
|
Node* function = MathFunction("cos");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberCos(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathCosWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("cos");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberCos(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
2016-06-30 08:41:05 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.cosh
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathCoshWithNumber) {
|
|
|
|
Node* function = MathFunction("cosh");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberCosh(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathCoshWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("cosh");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberCosh(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
2016-06-17 15:21:48 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-06-17 05:19:35 +00:00
|
|
|
// Math.exp
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathExpWithNumber) {
|
|
|
|
Node* function = MathFunction("exp");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberExp(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathExpWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("exp");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberExp(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.floor
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathFloorWithNumber) {
|
|
|
|
Node* function = MathFunction("floor");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberFloor(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathFloorWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("floor");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberFloor(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.fround
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathFroundWithNumber) {
|
|
|
|
Node* function = MathFunction("fround");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberFround(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathFroundWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("fround");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberFround(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.imul
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathImulWithUnsigned32) {
|
|
|
|
Node* function = MathFunction("imul");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::Unsigned32(), 0);
|
|
|
|
Node* p1 = Parameter(Type::Unsigned32(), 1);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
|
|
|
|
UndefinedConstant(), p0, p1, context,
|
|
|
|
frame_state, effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberImul(p0, p1));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathImulWithNumber) {
|
|
|
|
Node* function = MathFunction("imul");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::Number(), 0);
|
|
|
|
Node* p1 = Parameter(Type::Number(), 1);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
|
|
|
|
UndefinedConstant(), p0, p1, context,
|
|
|
|
frame_state, effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(),
|
|
|
|
IsNumberImul(IsNumberToUint32(p0), IsNumberToUint32(p1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathImulWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("imul");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* p1 = Parameter(Type::PlainPrimitive(), 1);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
|
|
|
|
UndefinedConstant(), p0, p1, context,
|
|
|
|
frame_state, effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(),
|
|
|
|
IsNumberImul(IsNumberToUint32(IsPlainPrimitiveToNumber(p0)),
|
|
|
|
IsNumberToUint32(IsPlainPrimitiveToNumber(p1))));
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.log
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathLogWithNumber) {
|
|
|
|
Node* function = MathFunction("log");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberLog(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathLogWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("log");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberLog(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.log1p
|
2014-09-23 11:40:00 +00:00
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
TEST_F(JSBuiltinReducerTest, MathLog1pWithNumber) {
|
|
|
|
Node* function = MathFunction("log1p");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
2014-09-23 11:40:00 +00:00
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberLog1p(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathLog1pWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("log1p");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberLog1p(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.max
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathMaxWithNoArguments) {
|
2015-04-27 10:44:47 +00:00
|
|
|
Node* function = MathFunction("max");
|
2014-09-23 11:40:00 +00:00
|
|
|
|
2015-05-21 10:59:54 +00:00
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
2015-10-30 06:58:56 +00:00
|
|
|
Node* context = UndefinedConstant();
|
2015-05-21 10:59:54 +00:00
|
|
|
Node* frame_state = graph()->start();
|
2016-02-17 12:04:19 +00:00
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(2), function,
|
|
|
|
UndefinedConstant(), context, frame_state,
|
2016-06-02 08:02:28 +00:00
|
|
|
effect, control);
|
2016-02-17 12:04:19 +00:00
|
|
|
Reduction r = Reduce(call);
|
2014-09-23 11:40:00 +00:00
|
|
|
|
2016-02-17 12:04:19 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberConstant(-V8_INFINITY));
|
2014-09-23 11:40:00 +00:00
|
|
|
}
|
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
TEST_F(JSBuiltinReducerTest, MathMaxWithNumber) {
|
2015-04-27 10:44:47 +00:00
|
|
|
Node* function = MathFunction("max");
|
2014-09-23 11:40:00 +00:00
|
|
|
|
2015-05-21 10:59:54 +00:00
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
2015-10-30 06:58:56 +00:00
|
|
|
Node* context = UndefinedConstant();
|
2015-05-21 10:59:54 +00:00
|
|
|
Node* frame_state = graph()->start();
|
2016-02-17 12:04:19 +00:00
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
2016-06-02 08:02:28 +00:00
|
|
|
effect, control);
|
2016-02-17 12:04:19 +00:00
|
|
|
Reduction r = Reduce(call);
|
2014-09-23 11:40:00 +00:00
|
|
|
|
2016-02-17 12:04:19 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), p0);
|
2015-04-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
TEST_F(JSBuiltinReducerTest, MathMaxWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("max");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
2016-07-22 08:22:05 +00:00
|
|
|
Node* p1 = Parameter(Type::PlainPrimitive(), 1);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
|
|
|
|
UndefinedConstant(), p0, p1, context,
|
|
|
|
frame_state, effect, control);
|
2016-06-15 05:43:36 +00:00
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2016-07-22 08:22:05 +00:00
|
|
|
EXPECT_THAT(r.replacement(), IsNumberMax(IsPlainPrimitiveToNumber(p0),
|
|
|
|
IsPlainPrimitiveToNumber(p1)));
|
2014-09-23 11:40:00 +00:00
|
|
|
}
|
|
|
|
|
2014-09-23 11:26:49 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-06-15 05:43:36 +00:00
|
|
|
// Math.min
|
2014-09-23 11:26:49 +00:00
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
TEST_F(JSBuiltinReducerTest, MathMinWithNoArguments) {
|
|
|
|
Node* function = MathFunction("min");
|
2014-09-23 11:26:49 +00:00
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(2), function,
|
|
|
|
UndefinedConstant(), context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberConstant(V8_INFINITY));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathMinWithNumber) {
|
|
|
|
Node* function = MathFunction("min");
|
2015-04-27 10:44:47 +00:00
|
|
|
|
2015-05-21 10:59:54 +00:00
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
2015-10-30 06:58:56 +00:00
|
|
|
Node* context = UndefinedConstant();
|
2015-05-21 10:59:54 +00:00
|
|
|
Node* frame_state = graph()->start();
|
2016-05-12 18:42:13 +00:00
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
2016-06-15 05:43:36 +00:00
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), p0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathMinWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("min");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
2016-07-22 08:22:05 +00:00
|
|
|
Node* p1 = Parameter(Type::PlainPrimitive(), 1);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
|
|
|
|
UndefinedConstant(), p0, p1, context,
|
|
|
|
frame_state, effect, control);
|
2016-06-15 05:43:36 +00:00
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2016-07-22 08:22:05 +00:00
|
|
|
EXPECT_THAT(r.replacement(), IsNumberMin(IsPlainPrimitiveToNumber(p0),
|
|
|
|
IsPlainPrimitiveToNumber(p1)));
|
2014-09-23 11:26:49 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 14:55:13 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-06-15 05:43:36 +00:00
|
|
|
// Math.round
|
2014-09-24 14:55:13 +00:00
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
TEST_F(JSBuiltinReducerTest, MathRoundWithNumber) {
|
|
|
|
Node* function = MathFunction("round");
|
2014-09-24 14:55:13 +00:00
|
|
|
|
2015-05-21 10:59:54 +00:00
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
2015-10-30 06:58:56 +00:00
|
|
|
Node* context = UndefinedConstant();
|
2015-05-21 10:59:54 +00:00
|
|
|
Node* frame_state = graph()->start();
|
2016-02-17 12:04:19 +00:00
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
2016-06-02 08:02:28 +00:00
|
|
|
effect, control);
|
2016-02-17 12:04:19 +00:00
|
|
|
Reduction r = Reduce(call);
|
2015-04-27 10:44:47 +00:00
|
|
|
|
2016-02-17 12:04:19 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
2016-06-15 05:43:36 +00:00
|
|
|
EXPECT_THAT(r.replacement(), IsNumberRound(p0));
|
2014-09-24 14:55:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
TEST_F(JSBuiltinReducerTest, MathRoundWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("round");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberRound(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
2016-06-28 10:23:58 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.pow
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathPowWithNumber) {
|
|
|
|
Node* function = MathFunction("pow");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
TRACED_FOREACH(Type*, t1, kNumberTypes) {
|
|
|
|
Node* p1 = Parameter(t1, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
|
|
|
|
UndefinedConstant(), p0, p1, context,
|
|
|
|
frame_state, effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberPow(p0, p1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathPowWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("pow");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* p1 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
|
|
|
|
UndefinedConstant(), p0, p1, context,
|
|
|
|
frame_state, effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberPow(IsPlainPrimitiveToNumber(p0),
|
|
|
|
IsPlainPrimitiveToNumber(p1)));
|
|
|
|
}
|
|
|
|
|
[builtins] Unify most of the remaining Math builtins.
Import fdlibm versions of acos, acosh, asin and asinh, which are more
precise and produce the same result across platforms (we were using
libm versions for asin and acos so far, where both speed and precision
depended on the operating system so far). Introduce appropriate TurboFan
operators for these functions and use them both for inlining and for the
generic builtin.
Also migrate the Math.imul and Math.fround builtins to TurboFan builtins
to ensure that their behavior is always exactly the same as the inlined
TurboFan version (i.e. C++ truncation semantics for double to float
don't necessarily meet the JavaScript semantics).
For completeness, also migrate Math.sign, which can even get some nice
love in TurboFan.
Drive-by-fix: Some alpha-sorting on the Math related functions, and
cleanup the list of Math intrinsics that we have to export via the
native context currently.
BUG=v8:3266,v8:3496,v8:3509,v8:3952,v8:5169,v8:5170,v8:5171,v8:5172
TBR=rossberg@chromium.org
R=franzih@chromium.org
Review-Url: https://codereview.chromium.org/2116753002
Cr-Commit-Position: refs/heads/master@{#37476}
2016-07-01 11:11:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.sign
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathSignWithNumber) {
|
|
|
|
Node* function = MathFunction("sign");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberSign(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathSignWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("sign");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberSign(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
2016-06-20 05:51:37 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.sin
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathSinWithNumber) {
|
|
|
|
Node* function = MathFunction("sin");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberSin(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathSinWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("sin");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberSin(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
2016-06-30 08:41:05 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.sinh
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathSinhWithNumber) {
|
|
|
|
Node* function = MathFunction("sinh");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberSinh(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathSinhWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("sinh");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberSinh(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
2016-06-13 07:06:49 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-06-15 05:43:36 +00:00
|
|
|
// Math.sqrt
|
2016-06-13 07:06:49 +00:00
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
TEST_F(JSBuiltinReducerTest, MathSqrtWithNumber) {
|
|
|
|
Node* function = MathFunction("sqrt");
|
2016-06-13 07:06:49 +00:00
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2016-06-15 05:43:36 +00:00
|
|
|
EXPECT_THAT(r.replacement(), IsNumberSqrt(p0));
|
2016-06-13 07:06:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
TEST_F(JSBuiltinReducerTest, MathSqrtWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("sqrt");
|
2016-06-13 07:06:49 +00:00
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
2016-06-15 05:43:36 +00:00
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
2016-06-13 07:06:49 +00:00
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberSqrt(IsPlainPrimitiveToNumber(p0)));
|
2016-06-13 07:06:49 +00:00
|
|
|
}
|
|
|
|
|
2016-06-20 05:51:37 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.tan
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathTanWithNumber) {
|
|
|
|
Node* function = MathFunction("tan");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberTan(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathTanWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("tan");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberTan(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
2016-06-30 08:41:05 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Math.tanh
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathTanhWithNumber) {
|
|
|
|
Node* function = MathFunction("tanh");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberTanh(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, MathTanhWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("tanh");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberTanh(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
2016-06-13 05:46:38 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2016-06-15 05:43:36 +00:00
|
|
|
// Math.trunc
|
2016-06-13 05:46:38 +00:00
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
TEST_F(JSBuiltinReducerTest, MathTruncWithNumber) {
|
|
|
|
Node* function = MathFunction("trunc");
|
2016-06-13 05:46:38 +00:00
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2016-06-15 05:43:36 +00:00
|
|
|
EXPECT_THAT(r.replacement(), IsNumberTrunc(p0));
|
2016-06-13 05:46:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
TEST_F(JSBuiltinReducerTest, MathTruncWithPlainPrimitive) {
|
|
|
|
Node* function = MathFunction("trunc");
|
2016-06-13 05:46:38 +00:00
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
2016-06-15 05:43:36 +00:00
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
2016-06-13 05:46:38 +00:00
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberTrunc(IsPlainPrimitiveToNumber(p0)));
|
2016-06-13 05:46:38 +00:00
|
|
|
}
|
|
|
|
|
2016-07-05 09:49:52 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Number.parseInt
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, NumberParseIntWithIntegral32) {
|
|
|
|
Node* function = NumberFunction("parseInt");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kIntegral32Types) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberToInt32(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSBuiltinReducerTest, NumberParseIntWithIntegral32AndUndefined) {
|
|
|
|
Node* function = NumberFunction("parseInt");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kIntegral32Types) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* p1 = Parameter(Type::Undefined(), 1);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
|
|
|
|
UndefinedConstant(), p0, p1, context,
|
|
|
|
frame_state, effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsNumberToInt32(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-02 07:59:29 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// String.fromCharCode
|
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
TEST_F(JSBuiltinReducerTest, StringFromCharCodeWithNumber) {
|
2016-06-02 07:59:29 +00:00
|
|
|
Node* function = StringFunction("fromCharCode");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
TRACED_FOREACH(Type*, t0, kNumberTypes) {
|
|
|
|
Node* p0 = Parameter(t0, 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
2016-06-02 08:46:40 +00:00
|
|
|
effect, control);
|
2016-06-02 07:59:29 +00:00
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsStringFromCharCode(p0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 05:43:36 +00:00
|
|
|
TEST_F(JSBuiltinReducerTest, StringFromCharCodeWithPlainPrimitive) {
|
|
|
|
Node* function = StringFunction("fromCharCode");
|
|
|
|
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* context = UndefinedConstant();
|
|
|
|
Node* frame_state = graph()->start();
|
|
|
|
Node* p0 = Parameter(Type::PlainPrimitive(), 0);
|
|
|
|
Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
|
|
|
|
UndefinedConstant(), p0, context, frame_state,
|
|
|
|
effect, control);
|
|
|
|
Reduction r = Reduce(call);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(),
|
|
|
|
IsStringFromCharCode(IsPlainPrimitiveToNumber(p0)));
|
|
|
|
}
|
|
|
|
|
2014-09-23 11:26:49 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|