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

Side by Side Diff: test/unittests/compiler/js-builtin-reducer-unittest.cc

Issue 2116753002: [builtins] Unify most of the remaining Math builtins. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@2102223005
Patch Set: Created 4 years, 5 months 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 unified diff | Download patch
OLDNEW
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/simplified-operator.h" 8 #include "src/compiler/simplified-operator.h"
9 #include "src/compiler/typer.h" 9 #include "src/compiler/typer.h"
10 #include "src/isolate-inl.h" 10 #include "src/isolate-inl.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, 119 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
120 UndefinedConstant(), p0, context, frame_state, 120 UndefinedConstant(), p0, context, frame_state,
121 effect, control); 121 effect, control);
122 Reduction r = Reduce(call); 122 Reduction r = Reduce(call);
123 123
124 ASSERT_TRUE(r.Changed()); 124 ASSERT_TRUE(r.Changed());
125 EXPECT_THAT(r.replacement(), IsNumberAbs(IsPlainPrimitiveToNumber(p0))); 125 EXPECT_THAT(r.replacement(), IsNumberAbs(IsPlainPrimitiveToNumber(p0)));
126 } 126 }
127 127
128 // ----------------------------------------------------------------------------- 128 // -----------------------------------------------------------------------------
129 // Math.acos
130
131 TEST_F(JSBuiltinReducerTest, MathAcosWithNumber) {
132 Node* function = MathFunction("acos");
133
134 Node* effect = graph()->start();
135 Node* control = graph()->start();
136 Node* context = UndefinedConstant();
137 Node* frame_state = graph()->start();
138 TRACED_FOREACH(Type*, t0, kNumberTypes) {
139 Node* p0 = Parameter(t0, 0);
140 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
141 UndefinedConstant(), p0, context, frame_state,
142 effect, control);
143 Reduction r = Reduce(call);
144
145 ASSERT_TRUE(r.Changed());
146 EXPECT_THAT(r.replacement(), IsNumberAcos(p0));
147 }
148 }
149
150 TEST_F(JSBuiltinReducerTest, MathAcosWithPlainPrimitive) {
151 Node* function = MathFunction("acos");
152
153 Node* effect = graph()->start();
154 Node* control = graph()->start();
155 Node* context = UndefinedConstant();
156 Node* frame_state = graph()->start();
157 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
158 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
159 UndefinedConstant(), p0, context, frame_state,
160 effect, control);
161 Reduction r = Reduce(call);
162
163 ASSERT_TRUE(r.Changed());
164 EXPECT_THAT(r.replacement(), IsNumberAcos(IsPlainPrimitiveToNumber(p0)));
165 }
166
167 // -----------------------------------------------------------------------------
168 // Math.acosh
169
170 TEST_F(JSBuiltinReducerTest, MathAcoshWithNumber) {
171 Node* function = MathFunction("acosh");
172
173 Node* effect = graph()->start();
174 Node* control = graph()->start();
175 Node* context = UndefinedConstant();
176 Node* frame_state = graph()->start();
177 TRACED_FOREACH(Type*, t0, kNumberTypes) {
178 Node* p0 = Parameter(t0, 0);
179 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
180 UndefinedConstant(), p0, context, frame_state,
181 effect, control);
182 Reduction r = Reduce(call);
183
184 ASSERT_TRUE(r.Changed());
185 EXPECT_THAT(r.replacement(), IsNumberAcosh(p0));
186 }
187 }
188
189 TEST_F(JSBuiltinReducerTest, MathAcoshWithPlainPrimitive) {
190 Node* function = MathFunction("acosh");
191
192 Node* effect = graph()->start();
193 Node* control = graph()->start();
194 Node* context = UndefinedConstant();
195 Node* frame_state = graph()->start();
196 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
197 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
198 UndefinedConstant(), p0, context, frame_state,
199 effect, control);
200 Reduction r = Reduce(call);
201
202 ASSERT_TRUE(r.Changed());
203 EXPECT_THAT(r.replacement(), IsNumberAcosh(IsPlainPrimitiveToNumber(p0)));
204 }
205
206 // -----------------------------------------------------------------------------
207 // Math.asin
208
209 TEST_F(JSBuiltinReducerTest, MathAsinWithNumber) {
210 Node* function = MathFunction("asin");
211
212 Node* effect = graph()->start();
213 Node* control = graph()->start();
214 Node* context = UndefinedConstant();
215 Node* frame_state = graph()->start();
216 TRACED_FOREACH(Type*, t0, kNumberTypes) {
217 Node* p0 = Parameter(t0, 0);
218 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
219 UndefinedConstant(), p0, context, frame_state,
220 effect, control);
221 Reduction r = Reduce(call);
222
223 ASSERT_TRUE(r.Changed());
224 EXPECT_THAT(r.replacement(), IsNumberAsin(p0));
225 }
226 }
227
228 TEST_F(JSBuiltinReducerTest, MathAsinWithPlainPrimitive) {
229 Node* function = MathFunction("asin");
230
231 Node* effect = graph()->start();
232 Node* control = graph()->start();
233 Node* context = UndefinedConstant();
234 Node* frame_state = graph()->start();
235 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
236 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
237 UndefinedConstant(), p0, context, frame_state,
238 effect, control);
239 Reduction r = Reduce(call);
240
241 ASSERT_TRUE(r.Changed());
242 EXPECT_THAT(r.replacement(), IsNumberAsin(IsPlainPrimitiveToNumber(p0)));
243 }
244
245 // -----------------------------------------------------------------------------
246 // Math.asinh
247
248 TEST_F(JSBuiltinReducerTest, MathAsinhWithNumber) {
249 Node* function = MathFunction("asinh");
250
251 Node* effect = graph()->start();
252 Node* control = graph()->start();
253 Node* context = UndefinedConstant();
254 Node* frame_state = graph()->start();
255 TRACED_FOREACH(Type*, t0, kNumberTypes) {
256 Node* p0 = Parameter(t0, 0);
257 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
258 UndefinedConstant(), p0, context, frame_state,
259 effect, control);
260 Reduction r = Reduce(call);
261
262 ASSERT_TRUE(r.Changed());
263 EXPECT_THAT(r.replacement(), IsNumberAsinh(p0));
264 }
265 }
266
267 TEST_F(JSBuiltinReducerTest, MathAsinhWithPlainPrimitive) {
268 Node* function = MathFunction("asinh");
269
270 Node* effect = graph()->start();
271 Node* control = graph()->start();
272 Node* context = UndefinedConstant();
273 Node* frame_state = graph()->start();
274 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
275 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
276 UndefinedConstant(), p0, context, frame_state,
277 effect, control);
278 Reduction r = Reduce(call);
279
280 ASSERT_TRUE(r.Changed());
281 EXPECT_THAT(r.replacement(), IsNumberAsinh(IsPlainPrimitiveToNumber(p0)));
282 }
283
284 // -----------------------------------------------------------------------------
129 // Math.atan 285 // Math.atan
130 286
131 TEST_F(JSBuiltinReducerTest, MathAtanWithNumber) { 287 TEST_F(JSBuiltinReducerTest, MathAtanWithNumber) {
132 Node* function = MathFunction("atan"); 288 Node* function = MathFunction("atan");
133 289
134 Node* effect = graph()->start(); 290 Node* effect = graph()->start();
135 Node* control = graph()->start(); 291 Node* control = graph()->start();
136 Node* context = UndefinedConstant(); 292 Node* context = UndefinedConstant();
137 Node* frame_state = graph()->start(); 293 Node* frame_state = graph()->start();
138 TRACED_FOREACH(Type*, t0, kNumberTypes) { 294 TRACED_FOREACH(Type*, t0, kNumberTypes) {
(...skipping 19 matching lines...) Expand all
158 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, 314 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
159 UndefinedConstant(), p0, context, frame_state, 315 UndefinedConstant(), p0, context, frame_state,
160 effect, control); 316 effect, control);
161 Reduction r = Reduce(call); 317 Reduction r = Reduce(call);
162 318
163 ASSERT_TRUE(r.Changed()); 319 ASSERT_TRUE(r.Changed());
164 EXPECT_THAT(r.replacement(), IsNumberAtan(IsPlainPrimitiveToNumber(p0))); 320 EXPECT_THAT(r.replacement(), IsNumberAtan(IsPlainPrimitiveToNumber(p0)));
165 } 321 }
166 322
167 // ----------------------------------------------------------------------------- 323 // -----------------------------------------------------------------------------
324 // Math.atanh
325
326 TEST_F(JSBuiltinReducerTest, MathAtanhWithNumber) {
327 Node* function = MathFunction("atanh");
328
329 Node* effect = graph()->start();
330 Node* control = graph()->start();
331 Node* context = UndefinedConstant();
332 Node* frame_state = graph()->start();
333 TRACED_FOREACH(Type*, t0, kNumberTypes) {
334 Node* p0 = Parameter(t0, 0);
335 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
336 UndefinedConstant(), p0, context, frame_state,
337 effect, control);
338 Reduction r = Reduce(call);
339
340 ASSERT_TRUE(r.Changed());
341 EXPECT_THAT(r.replacement(), IsNumberAtanh(p0));
342 }
343 }
344
345 TEST_F(JSBuiltinReducerTest, MathAtanhWithPlainPrimitive) {
346 Node* function = MathFunction("atanh");
347
348 Node* effect = graph()->start();
349 Node* control = graph()->start();
350 Node* context = UndefinedConstant();
351 Node* frame_state = graph()->start();
352 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
353 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
354 UndefinedConstant(), p0, context, frame_state,
355 effect, control);
356 Reduction r = Reduce(call);
357
358 ASSERT_TRUE(r.Changed());
359 EXPECT_THAT(r.replacement(), IsNumberAtanh(IsPlainPrimitiveToNumber(p0)));
360 }
361
362 // -----------------------------------------------------------------------------
168 // Math.atan2 363 // Math.atan2
169 364
170 TEST_F(JSBuiltinReducerTest, MathAtan2WithNumber) { 365 TEST_F(JSBuiltinReducerTest, MathAtan2WithNumber) {
171 Node* function = MathFunction("atan2"); 366 Node* function = MathFunction("atan2");
172 367
173 Node* effect = graph()->start(); 368 Node* effect = graph()->start();
174 Node* control = graph()->start(); 369 Node* control = graph()->start();
175 Node* context = UndefinedConstant(); 370 Node* context = UndefinedConstant();
176 Node* frame_state = graph()->start(); 371 Node* frame_state = graph()->start();
177 TRACED_FOREACH(Type*, t0, kNumberTypes) { 372 TRACED_FOREACH(Type*, t0, kNumberTypes) {
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 UndefinedConstant(), p0, p1, context, 1063 UndefinedConstant(), p0, p1, context,
869 frame_state, effect, control); 1064 frame_state, effect, control);
870 Reduction r = Reduce(call); 1065 Reduction r = Reduce(call);
871 1066
872 ASSERT_TRUE(r.Changed()); 1067 ASSERT_TRUE(r.Changed());
873 EXPECT_THAT(r.replacement(), IsNumberPow(IsPlainPrimitiveToNumber(p0), 1068 EXPECT_THAT(r.replacement(), IsNumberPow(IsPlainPrimitiveToNumber(p0),
874 IsPlainPrimitiveToNumber(p1))); 1069 IsPlainPrimitiveToNumber(p1)));
875 } 1070 }
876 1071
877 // ----------------------------------------------------------------------------- 1072 // -----------------------------------------------------------------------------
1073 // Math.sign
1074
1075 TEST_F(JSBuiltinReducerTest, MathSignWithNumber) {
1076 Node* function = MathFunction("sign");
1077
1078 Node* effect = graph()->start();
1079 Node* control = graph()->start();
1080 Node* context = UndefinedConstant();
1081 Node* frame_state = graph()->start();
1082 TRACED_FOREACH(Type*, t0, kNumberTypes) {
1083 Node* p0 = Parameter(t0, 0);
1084 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
1085 UndefinedConstant(), p0, context, frame_state,
1086 effect, control);
1087 Reduction r = Reduce(call);
1088
1089 ASSERT_TRUE(r.Changed());
1090 EXPECT_THAT(r.replacement(), IsNumberSign(p0));
1091 }
1092 }
1093
1094 TEST_F(JSBuiltinReducerTest, MathSignWithPlainPrimitive) {
1095 Node* function = MathFunction("sign");
1096
1097 Node* effect = graph()->start();
1098 Node* control = graph()->start();
1099 Node* context = UndefinedConstant();
1100 Node* frame_state = graph()->start();
1101 Node* p0 = Parameter(Type::PlainPrimitive(), 0);
1102 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
1103 UndefinedConstant(), p0, context, frame_state,
1104 effect, control);
1105 Reduction r = Reduce(call);
1106
1107 ASSERT_TRUE(r.Changed());
1108 EXPECT_THAT(r.replacement(), IsNumberSign(IsPlainPrimitiveToNumber(p0)));
1109 }
1110
1111 // -----------------------------------------------------------------------------
878 // Math.sin 1112 // Math.sin
879 1113
880 TEST_F(JSBuiltinReducerTest, MathSinWithNumber) { 1114 TEST_F(JSBuiltinReducerTest, MathSinWithNumber) {
881 Node* function = MathFunction("sin"); 1115 Node* function = MathFunction("sin");
882 1116
883 Node* effect = graph()->start(); 1117 Node* effect = graph()->start();
884 Node* control = graph()->start(); 1118 Node* control = graph()->start();
885 Node* context = UndefinedConstant(); 1119 Node* context = UndefinedConstant();
886 Node* frame_state = graph()->start(); 1120 Node* frame_state = graph()->start();
887 TRACED_FOREACH(Type*, t0, kNumberTypes) { 1121 TRACED_FOREACH(Type*, t0, kNumberTypes) {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 Reduction r = Reduce(call); 1378 Reduction r = Reduce(call);
1145 1379
1146 ASSERT_TRUE(r.Changed()); 1380 ASSERT_TRUE(r.Changed());
1147 EXPECT_THAT(r.replacement(), 1381 EXPECT_THAT(r.replacement(),
1148 IsStringFromCharCode(IsPlainPrimitiveToNumber(p0))); 1382 IsStringFromCharCode(IsPlainPrimitiveToNumber(p0)));
1149 } 1383 }
1150 1384
1151 } // namespace compiler 1385 } // namespace compiler
1152 } // namespace internal 1386 } // namespace internal
1153 } // namespace v8 1387 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698