OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/js-builtin-reducer.h" | 5 #include "src/compiler/js-builtin-reducer.h" |
6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/node-properties.h" | 7 #include "src/compiler/node-properties.h" |
8 #include "src/compiler/typer.h" | 8 #include "src/compiler/typer.h" |
9 #include "test/unittests/compiler/graph-unittest.h" | 9 #include "test/unittests/compiler/graph-unittest.h" |
10 #include "test/unittests/compiler/node-test-utils.h" | 10 #include "test/unittests/compiler/node-test-utils.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 Type* const kNumberTypes[] = { | 55 Type* const kNumberTypes[] = { |
56 Type::UnsignedSmall(), Type::Negative32(), Type::Unsigned31(), | 56 Type::UnsignedSmall(), Type::Negative32(), Type::Unsigned31(), |
57 Type::SignedSmall(), Type::Signed32(), Type::Unsigned32(), | 57 Type::SignedSmall(), Type::Signed32(), Type::Unsigned32(), |
58 Type::Integral32(), Type::MinusZero(), Type::NaN(), | 58 Type::Integral32(), Type::MinusZero(), Type::NaN(), |
59 Type::OrderedNumber(), Type::PlainNumber(), Type::Number()}; | 59 Type::OrderedNumber(), Type::PlainNumber(), Type::Number()}; |
60 | 60 |
61 } // namespace | 61 } // namespace |
62 | 62 |
63 | 63 |
64 // ----------------------------------------------------------------------------- | 64 // ----------------------------------------------------------------------------- |
65 // Math.abs | |
66 | |
67 | |
68 TEST_F(JSBuiltinReducerTest, MathAbs) { | |
69 Handle<JSFunction> f = MathFunction("abs"); | |
70 | |
71 TRACED_FOREACH(Type*, t0, kNumberTypes) { | |
72 Node* p0 = Parameter(t0, 0); | |
73 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); | |
74 Node* call = | |
75 graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS), | |
76 fun, UndefinedConstant(), p0); | |
77 Reduction r = Reduce(call); | |
78 | |
79 if (t0->Is(Type::Unsigned32())) { | |
80 ASSERT_TRUE(r.Changed()); | |
81 EXPECT_THAT(r.replacement(), p0); | |
82 } else { | |
83 Capture<Node*> branch; | |
84 ASSERT_TRUE(r.Changed()); | |
85 EXPECT_THAT( | |
86 r.replacement(), | |
87 IsSelect(kMachNone, | |
88 IsNumberLessThan(IsNumberConstant(BitEq(0.0)), p0), p0, | |
89 IsNumberSubtract(IsNumberConstant(BitEq(0.0)), p0))); | |
90 } | |
91 } | |
92 } | |
93 | |
94 | |
95 // ----------------------------------------------------------------------------- | |
96 // Math.sqrt | |
97 | |
98 | |
99 TEST_F(JSBuiltinReducerTest, MathSqrt) { | |
100 Handle<JSFunction> f = MathFunction("sqrt"); | |
101 | |
102 TRACED_FOREACH(Type*, t0, kNumberTypes) { | |
103 Node* p0 = Parameter(t0, 0); | |
104 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); | |
105 Node* call = | |
106 graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS), | |
107 fun, UndefinedConstant(), p0); | |
108 Reduction r = Reduce(call); | |
109 | |
110 ASSERT_TRUE(r.Changed()); | |
111 EXPECT_THAT(r.replacement(), IsFloat64Sqrt(p0)); | |
112 } | |
113 } | |
114 | |
115 | |
116 // ----------------------------------------------------------------------------- | |
117 // Math.max | 65 // Math.max |
118 | 66 |
119 | 67 |
120 TEST_F(JSBuiltinReducerTest, MathMax0) { | 68 TEST_F(JSBuiltinReducerTest, MathMax0) { |
121 Handle<JSFunction> f = MathFunction("max"); | 69 Handle<JSFunction> f = MathFunction("max"); |
122 | 70 |
123 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); | 71 Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f)); |
124 Node* call = | 72 Node* call = |
125 graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS), | 73 graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS), |
126 fun, UndefinedConstant()); | 74 fun, UndefinedConstant()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 Reduction r = Reduce(call); | 167 Reduction r = Reduce(call); |
220 | 168 |
221 ASSERT_TRUE(r.Changed()); | 169 ASSERT_TRUE(r.Changed()); |
222 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0)); | 170 EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0)); |
223 } | 171 } |
224 } | 172 } |
225 | 173 |
226 } // namespace compiler | 174 } // namespace compiler |
227 } // namespace internal | 175 } // namespace internal |
228 } // namespace v8 | 176 } // namespace v8 |
OLD | NEW |