| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "test/cctest/cctest.h" | 7 #include "test/cctest/cctest.h" |
| 8 #include "test/cctest/compiler/codegen-tester.h" | 8 #include "test/cctest/compiler/codegen-tester.h" |
| 9 #include "test/cctest/compiler/value-helper.h" | 9 #include "test/cctest/compiler/value-helper.h" |
| 10 | 10 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 virtual int32_t expected(int32_t a, int32_t b) { | 355 virtual int32_t expected(int32_t a, int32_t b) { |
| 356 if (invert) return !w.Int32Compare(a, b) ? eq_constant : ne_constant; | 356 if (invert) return !w.Int32Compare(a, b) ? eq_constant : ne_constant; |
| 357 return w.Int32Compare(a, b) ? eq_constant : ne_constant; | 357 return w.Int32Compare(a, b) ? eq_constant : ne_constant; |
| 358 } | 358 } |
| 359 }; | 359 }; |
| 360 | 360 |
| 361 | 361 |
| 362 TEST(BranchCombineInt32CmpAllInputShapes_materialized) { | 362 TEST(BranchCombineInt32CmpAllInputShapes_materialized) { |
| 363 for (size_t i = 0; i < ARRAY_SIZE(int32cmp_opcodes); i++) { | 363 for (size_t i = 0; i < arraysize(int32cmp_opcodes); i++) { |
| 364 CmpMaterializeBoolGen gen(int32cmp_opcodes[i], false); | 364 CmpMaterializeBoolGen gen(int32cmp_opcodes[i], false); |
| 365 Int32BinopInputShapeTester tester(&gen); | 365 Int32BinopInputShapeTester tester(&gen); |
| 366 tester.TestAllInputShapes(); | 366 tester.TestAllInputShapes(); |
| 367 } | 367 } |
| 368 } | 368 } |
| 369 | 369 |
| 370 | 370 |
| 371 TEST(BranchCombineInt32CmpAllInputShapes_inverted_materialized) { | 371 TEST(BranchCombineInt32CmpAllInputShapes_inverted_materialized) { |
| 372 for (size_t i = 0; i < ARRAY_SIZE(int32cmp_opcodes); i++) { | 372 for (size_t i = 0; i < arraysize(int32cmp_opcodes); i++) { |
| 373 CmpMaterializeBoolGen gen(int32cmp_opcodes[i], true); | 373 CmpMaterializeBoolGen gen(int32cmp_opcodes[i], true); |
| 374 Int32BinopInputShapeTester tester(&gen); | 374 Int32BinopInputShapeTester tester(&gen); |
| 375 tester.TestAllInputShapes(); | 375 tester.TestAllInputShapes(); |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 | 378 |
| 379 | 379 |
| 380 TEST(BranchCombineInt32CmpAllInputShapes_branch_true) { | 380 TEST(BranchCombineInt32CmpAllInputShapes_branch_true) { |
| 381 for (int i = 0; i < static_cast<int>(ARRAY_SIZE(int32cmp_opcodes)); i++) { | 381 for (int i = 0; i < static_cast<int>(arraysize(int32cmp_opcodes)); i++) { |
| 382 CmpBranchGen gen(int32cmp_opcodes[i], false, false, 995 + i, -1011 - i); | 382 CmpBranchGen gen(int32cmp_opcodes[i], false, false, 995 + i, -1011 - i); |
| 383 Int32BinopInputShapeTester tester(&gen); | 383 Int32BinopInputShapeTester tester(&gen); |
| 384 tester.TestAllInputShapes(); | 384 tester.TestAllInputShapes(); |
| 385 } | 385 } |
| 386 } | 386 } |
| 387 | 387 |
| 388 | 388 |
| 389 TEST(BranchCombineInt32CmpAllInputShapes_branch_false) { | 389 TEST(BranchCombineInt32CmpAllInputShapes_branch_false) { |
| 390 for (int i = 0; i < static_cast<int>(ARRAY_SIZE(int32cmp_opcodes)); i++) { | 390 for (int i = 0; i < static_cast<int>(arraysize(int32cmp_opcodes)); i++) { |
| 391 CmpBranchGen gen(int32cmp_opcodes[i], false, true, 795 + i, -2011 - i); | 391 CmpBranchGen gen(int32cmp_opcodes[i], false, true, 795 + i, -2011 - i); |
| 392 Int32BinopInputShapeTester tester(&gen); | 392 Int32BinopInputShapeTester tester(&gen); |
| 393 tester.TestAllInputShapes(); | 393 tester.TestAllInputShapes(); |
| 394 } | 394 } |
| 395 } | 395 } |
| 396 | 396 |
| 397 | 397 |
| 398 TEST(BranchCombineInt32CmpAllInputShapes_inverse_branch_true) { | 398 TEST(BranchCombineInt32CmpAllInputShapes_inverse_branch_true) { |
| 399 for (int i = 0; i < static_cast<int>(ARRAY_SIZE(int32cmp_opcodes)); i++) { | 399 for (int i = 0; i < static_cast<int>(arraysize(int32cmp_opcodes)); i++) { |
| 400 CmpBranchGen gen(int32cmp_opcodes[i], true, false, 695 + i, -3011 - i); | 400 CmpBranchGen gen(int32cmp_opcodes[i], true, false, 695 + i, -3011 - i); |
| 401 Int32BinopInputShapeTester tester(&gen); | 401 Int32BinopInputShapeTester tester(&gen); |
| 402 tester.TestAllInputShapes(); | 402 tester.TestAllInputShapes(); |
| 403 } | 403 } |
| 404 } | 404 } |
| 405 | 405 |
| 406 | 406 |
| 407 TEST(BranchCombineInt32CmpAllInputShapes_inverse_branch_false) { | 407 TEST(BranchCombineInt32CmpAllInputShapes_inverse_branch_false) { |
| 408 for (int i = 0; i < static_cast<int>(ARRAY_SIZE(int32cmp_opcodes)); i++) { | 408 for (int i = 0; i < static_cast<int>(arraysize(int32cmp_opcodes)); i++) { |
| 409 CmpBranchGen gen(int32cmp_opcodes[i], true, true, 595 + i, -4011 - i); | 409 CmpBranchGen gen(int32cmp_opcodes[i], true, true, 595 + i, -4011 - i); |
| 410 Int32BinopInputShapeTester tester(&gen); | 410 Int32BinopInputShapeTester tester(&gen); |
| 411 tester.TestAllInputShapes(); | 411 tester.TestAllInputShapes(); |
| 412 } | 412 } |
| 413 } | 413 } |
| 414 | 414 |
| 415 | 415 |
| 416 TEST(BranchCombineFloat64Compares) { | 416 TEST(BranchCombineFloat64Compares) { |
| 417 double inf = V8_INFINITY; | 417 double inf = V8_INFINITY; |
| 418 double nan = v8::base::OS::nan_value(); | 418 double nan = v8::base::OS::nan_value(); |
| 419 double inputs[] = {0.0, 1.0, -1.0, -inf, inf, nan}; | 419 double inputs[] = {0.0, 1.0, -1.0, -inf, inf, nan}; |
| 420 | 420 |
| 421 int32_t eq_constant = -1733; | 421 int32_t eq_constant = -1733; |
| 422 int32_t ne_constant = 915118; | 422 int32_t ne_constant = 915118; |
| 423 | 423 |
| 424 double input_a = 0.0; | 424 double input_a = 0.0; |
| 425 double input_b = 0.0; | 425 double input_b = 0.0; |
| 426 | 426 |
| 427 CompareWrapper cmps[] = {CompareWrapper(IrOpcode::kFloat64Equal), | 427 CompareWrapper cmps[] = {CompareWrapper(IrOpcode::kFloat64Equal), |
| 428 CompareWrapper(IrOpcode::kFloat64LessThan), | 428 CompareWrapper(IrOpcode::kFloat64LessThan), |
| 429 CompareWrapper(IrOpcode::kFloat64LessThanOrEqual)}; | 429 CompareWrapper(IrOpcode::kFloat64LessThanOrEqual)}; |
| 430 | 430 |
| 431 for (size_t c = 0; c < ARRAY_SIZE(cmps); c++) { | 431 for (size_t c = 0; c < arraysize(cmps); c++) { |
| 432 CompareWrapper cmp = cmps[c]; | 432 CompareWrapper cmp = cmps[c]; |
| 433 for (int invert = 0; invert < 2; invert++) { | 433 for (int invert = 0; invert < 2; invert++) { |
| 434 RawMachineAssemblerTester<int32_t> m; | 434 RawMachineAssemblerTester<int32_t> m; |
| 435 Node* a = m.LoadFromPointer(&input_a, kMachFloat64); | 435 Node* a = m.LoadFromPointer(&input_a, kMachFloat64); |
| 436 Node* b = m.LoadFromPointer(&input_b, kMachFloat64); | 436 Node* b = m.LoadFromPointer(&input_b, kMachFloat64); |
| 437 | 437 |
| 438 MLabel blocka, blockb; | 438 MLabel blocka, blockb; |
| 439 Node* cond = cmp.MakeNode(&m, a, b); | 439 Node* cond = cmp.MakeNode(&m, a, b); |
| 440 if (invert) cond = m.Word32Equal(cond, m.Int32Constant(0)); | 440 if (invert) cond = m.Word32Equal(cond, m.Int32Constant(0)); |
| 441 m.Branch(cond, &blocka, &blockb); | 441 m.Branch(cond, &blocka, &blockb); |
| 442 m.Bind(&blocka); | 442 m.Bind(&blocka); |
| 443 m.Return(m.Int32Constant(eq_constant)); | 443 m.Return(m.Int32Constant(eq_constant)); |
| 444 m.Bind(&blockb); | 444 m.Bind(&blockb); |
| 445 m.Return(m.Int32Constant(ne_constant)); | 445 m.Return(m.Int32Constant(ne_constant)); |
| 446 | 446 |
| 447 for (size_t i = 0; i < ARRAY_SIZE(inputs); i++) { | 447 for (size_t i = 0; i < arraysize(inputs); i++) { |
| 448 for (size_t j = 0; j < ARRAY_SIZE(inputs); j += 2) { | 448 for (size_t j = 0; j < arraysize(inputs); j += 2) { |
| 449 input_a = inputs[i]; | 449 input_a = inputs[i]; |
| 450 input_b = inputs[i]; | 450 input_b = inputs[i]; |
| 451 int32_t expected = | 451 int32_t expected = |
| 452 invert ? (cmp.Float64Compare(input_a, input_b) ? ne_constant | 452 invert ? (cmp.Float64Compare(input_a, input_b) ? ne_constant |
| 453 : eq_constant) | 453 : eq_constant) |
| 454 : (cmp.Float64Compare(input_a, input_b) ? eq_constant | 454 : (cmp.Float64Compare(input_a, input_b) ? eq_constant |
| 455 : ne_constant); | 455 : ne_constant); |
| 456 CHECK_EQ(expected, m.Call()); | 456 CHECK_EQ(expected, m.Call()); |
| 457 } | 457 } |
| 458 } | 458 } |
| 459 } | 459 } |
| 460 } | 460 } |
| 461 } | 461 } |
| 462 #endif // V8_TURBOFAN_TARGET | 462 #endif // V8_TURBOFAN_TARGET |
| OLD | NEW |