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 "test/cctest/cctest.h" | 5 #include "test/cctest/cctest.h" |
6 #include "test/cctest/compiler/codegen-tester.h" | 6 #include "test/cctest/compiler/codegen-tester.h" |
7 #include "test/cctest/compiler/value-helper.h" | 7 #include "test/cctest/compiler/value-helper.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 284 |
285 | 285 |
286 void Int32BinopInputShapeTester::TestAllInputShapes() { | 286 void Int32BinopInputShapeTester::TestAllInputShapes() { |
287 std::vector<int32_t> inputs = ValueHelper::int32_vector(); | 287 std::vector<int32_t> inputs = ValueHelper::int32_vector(); |
288 int num_int_inputs = static_cast<int>(inputs.size()); | 288 int num_int_inputs = static_cast<int>(inputs.size()); |
289 if (num_int_inputs > 16) num_int_inputs = 16; // limit to 16 inputs | 289 if (num_int_inputs > 16) num_int_inputs = 16; // limit to 16 inputs |
290 | 290 |
291 for (int i = -2; i < num_int_inputs; i++) { // for all left shapes | 291 for (int i = -2; i < num_int_inputs; i++) { // for all left shapes |
292 for (int j = -2; j < num_int_inputs; j++) { // for all right shapes | 292 for (int j = -2; j < num_int_inputs; j++) { // for all right shapes |
293 if (i >= 0 && j >= 0) break; // No constant/constant combos | 293 if (i >= 0 && j >= 0) break; // No constant/constant combos |
294 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); | 294 RawMachineAssemblerTester<int32_t> m(MachineType::Int32(), |
| 295 MachineType::Int32()); |
295 Node* p0 = m.Parameter(0); | 296 Node* p0 = m.Parameter(0); |
296 Node* p1 = m.Parameter(1); | 297 Node* p1 = m.Parameter(1); |
297 Node* n0; | 298 Node* n0; |
298 Node* n1; | 299 Node* n1; |
299 | 300 |
300 // left = Parameter | Load | Constant | 301 // left = Parameter | Load | Constant |
301 if (i == -2) { | 302 if (i == -2) { |
302 n0 = p0; | 303 n0 = p0; |
303 } else if (i == -1) { | 304 } else if (i == -1) { |
304 n0 = m.LoadFromPointer(&input_a, kMachInt32); | 305 n0 = m.LoadFromPointer(&input_a, MachineType::Int32()); |
305 } else { | 306 } else { |
306 n0 = m.Int32Constant(inputs[i]); | 307 n0 = m.Int32Constant(inputs[i]); |
307 } | 308 } |
308 | 309 |
309 // right = Parameter | Load | Constant | 310 // right = Parameter | Load | Constant |
310 if (j == -2) { | 311 if (j == -2) { |
311 n1 = p1; | 312 n1 = p1; |
312 } else if (j == -1) { | 313 } else if (j == -1) { |
313 n1 = m.LoadFromPointer(&input_b, kMachInt32); | 314 n1 = m.LoadFromPointer(&input_b, MachineType::Int32()); |
314 } else { | 315 } else { |
315 n1 = m.Int32Constant(inputs[j]); | 316 n1 = m.Int32Constant(inputs[j]); |
316 } | 317 } |
317 | 318 |
318 gen->gen(&m, n0, n1); | 319 gen->gen(&m, n0, n1); |
319 | 320 |
320 if (false) printf("Int32BinopInputShapeTester i=%d, j=%d\n", i, j); | 321 if (false) printf("Int32BinopInputShapeTester i=%d, j=%d\n", i, j); |
321 if (i >= 0) { | 322 if (i >= 0) { |
322 input_a = inputs[i]; | 323 input_a = inputs[i]; |
323 RunRight(&m); | 324 RunRight(&m); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 FOR_UINT32_INPUTS(i) { | 362 FOR_UINT32_INPUTS(i) { |
362 input_b = *i; | 363 input_b = *i; |
363 int32_t expect = gen->expected(input_a, input_b); | 364 int32_t expect = gen->expected(input_a, input_b); |
364 if (false) printf(" cmp(a=%d, b=%d) ?== %d\n", input_a, input_b, expect); | 365 if (false) printf(" cmp(a=%d, b=%d) ?== %d\n", input_a, input_b, expect); |
365 CHECK_EQ(expect, m->Call(input_a, input_b)); | 366 CHECK_EQ(expect, m->Call(input_a, input_b)); |
366 } | 367 } |
367 } | 368 } |
368 | 369 |
369 | 370 |
370 TEST(ParametersEqual) { | 371 TEST(ParametersEqual) { |
371 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); | 372 RawMachineAssemblerTester<int32_t> m(MachineType::Int32(), |
| 373 MachineType::Int32()); |
372 Node* p1 = m.Parameter(1); | 374 Node* p1 = m.Parameter(1); |
373 CHECK(p1); | 375 CHECK(p1); |
374 Node* p0 = m.Parameter(0); | 376 Node* p0 = m.Parameter(0); |
375 CHECK(p0); | 377 CHECK(p0); |
376 CHECK_EQ(p0, m.Parameter(0)); | 378 CHECK_EQ(p0, m.Parameter(0)); |
377 CHECK_EQ(p1, m.Parameter(1)); | 379 CHECK_EQ(p1, m.Parameter(1)); |
378 } | 380 } |
379 | 381 |
380 | 382 |
381 void RunSmiConstant(int32_t v) { | 383 void RunSmiConstant(int32_t v) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 TEST(RunHeapNumberConstant) { | 477 TEST(RunHeapNumberConstant) { |
476 RawMachineAssemblerTester<HeapObject*> m; | 478 RawMachineAssemblerTester<HeapObject*> m; |
477 Handle<HeapObject> number = m.isolate()->factory()->NewHeapNumber(100.5); | 479 Handle<HeapObject> number = m.isolate()->factory()->NewHeapNumber(100.5); |
478 m.Return(m.HeapConstant(number)); | 480 m.Return(m.HeapConstant(number)); |
479 HeapObject* result = m.Call(); | 481 HeapObject* result = m.Call(); |
480 CHECK_EQ(result, *number); | 482 CHECK_EQ(result, *number); |
481 } | 483 } |
482 | 484 |
483 | 485 |
484 TEST(RunParam1) { | 486 TEST(RunParam1) { |
485 RawMachineAssemblerTester<int32_t> m(kMachInt32); | 487 RawMachineAssemblerTester<int32_t> m(MachineType::Int32()); |
486 m.Return(m.Parameter(0)); | 488 m.Return(m.Parameter(0)); |
487 | 489 |
488 FOR_INT32_INPUTS(i) { | 490 FOR_INT32_INPUTS(i) { |
489 int32_t result = m.Call(*i); | 491 int32_t result = m.Call(*i); |
490 CHECK_EQ(*i, result); | 492 CHECK_EQ(*i, result); |
491 } | 493 } |
492 } | 494 } |
493 | 495 |
494 | 496 |
495 TEST(RunParam2_1) { | 497 TEST(RunParam2_1) { |
496 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); | 498 RawMachineAssemblerTester<int32_t> m(MachineType::Int32(), |
| 499 MachineType::Int32()); |
497 Node* p0 = m.Parameter(0); | 500 Node* p0 = m.Parameter(0); |
498 Node* p1 = m.Parameter(1); | 501 Node* p1 = m.Parameter(1); |
499 m.Return(p0); | 502 m.Return(p0); |
500 USE(p1); | 503 USE(p1); |
501 | 504 |
502 FOR_INT32_INPUTS(i) { | 505 FOR_INT32_INPUTS(i) { |
503 int32_t result = m.Call(*i, -9999); | 506 int32_t result = m.Call(*i, -9999); |
504 CHECK_EQ(*i, result); | 507 CHECK_EQ(*i, result); |
505 } | 508 } |
506 } | 509 } |
507 | 510 |
508 | 511 |
509 TEST(RunParam2_2) { | 512 TEST(RunParam2_2) { |
510 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); | 513 RawMachineAssemblerTester<int32_t> m(MachineType::Int32(), |
| 514 MachineType::Int32()); |
511 Node* p0 = m.Parameter(0); | 515 Node* p0 = m.Parameter(0); |
512 Node* p1 = m.Parameter(1); | 516 Node* p1 = m.Parameter(1); |
513 m.Return(p1); | 517 m.Return(p1); |
514 USE(p0); | 518 USE(p0); |
515 | 519 |
516 FOR_INT32_INPUTS(i) { | 520 FOR_INT32_INPUTS(i) { |
517 int32_t result = m.Call(-7777, *i); | 521 int32_t result = m.Call(-7777, *i); |
518 CHECK_EQ(*i, result); | 522 CHECK_EQ(*i, result); |
519 } | 523 } |
520 } | 524 } |
521 | 525 |
522 | 526 |
523 TEST(RunParam3) { | 527 TEST(RunParam3) { |
524 for (int i = 0; i < 3; i++) { | 528 for (int i = 0; i < 3; i++) { |
525 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32, kMachInt32); | 529 RawMachineAssemblerTester<int32_t> m( |
| 530 MachineType::Int32(), MachineType::Int32(), MachineType::Int32()); |
526 Node* nodes[] = {m.Parameter(0), m.Parameter(1), m.Parameter(2)}; | 531 Node* nodes[] = {m.Parameter(0), m.Parameter(1), m.Parameter(2)}; |
527 m.Return(nodes[i]); | 532 m.Return(nodes[i]); |
528 | 533 |
529 int p[] = {-99, -77, -88}; | 534 int p[] = {-99, -77, -88}; |
530 FOR_INT32_INPUTS(j) { | 535 FOR_INT32_INPUTS(j) { |
531 p[i] = *j; | 536 p[i] = *j; |
532 int32_t result = m.Call(p[0], p[1], p[2]); | 537 int32_t result = m.Call(p[0], p[1], p[2]); |
533 CHECK_EQ(*j, result); | 538 CHECK_EQ(*j, result); |
534 } | 539 } |
535 } | 540 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 | 578 |
574 #if V8_TARGET_ARCH_64_BIT | 579 #if V8_TARGET_ARCH_64_BIT |
575 // TODO(ahaas): run int64 tests on all platforms when supported. | 580 // TODO(ahaas): run int64 tests on all platforms when supported. |
576 TEST(RunBufferedRawMachineAssemblerTesterTester) { | 581 TEST(RunBufferedRawMachineAssemblerTesterTester) { |
577 { | 582 { |
578 BufferedRawMachineAssemblerTester<int64_t> m; | 583 BufferedRawMachineAssemblerTester<int64_t> m; |
579 m.Return(m.Int64Constant(0x12500000000)); | 584 m.Return(m.Int64Constant(0x12500000000)); |
580 CHECK_EQ(0x12500000000, m.Call()); | 585 CHECK_EQ(0x12500000000, m.Call()); |
581 } | 586 } |
582 { | 587 { |
583 BufferedRawMachineAssemblerTester<double> m(kMachFloat64); | 588 BufferedRawMachineAssemblerTester<double> m(MachineType::Float64()); |
584 m.Return(m.Parameter(0)); | 589 m.Return(m.Parameter(0)); |
585 FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(*i, m.Call(*i)); } | 590 FOR_FLOAT64_INPUTS(i) { CheckDoubleEq(*i, m.Call(*i)); } |
586 } | 591 } |
587 { | 592 { |
588 BufferedRawMachineAssemblerTester<int64_t> m(kMachInt64, kMachInt64); | 593 BufferedRawMachineAssemblerTester<int64_t> m(MachineType::Int64(), |
| 594 MachineType::Int64()); |
589 m.Return(m.Int64Add(m.Parameter(0), m.Parameter(1))); | 595 m.Return(m.Int64Add(m.Parameter(0), m.Parameter(1))); |
590 FOR_INT64_INPUTS(i) { | 596 FOR_INT64_INPUTS(i) { |
591 FOR_INT64_INPUTS(j) { | 597 FOR_INT64_INPUTS(j) { |
592 CHECK_EQ(*i + *j, m.Call(*i, *j)); | 598 CHECK_EQ(*i + *j, m.Call(*i, *j)); |
593 CHECK_EQ(*j + *i, m.Call(*j, *i)); | 599 CHECK_EQ(*j + *i, m.Call(*j, *i)); |
594 } | 600 } |
595 } | 601 } |
596 } | 602 } |
597 { | 603 { |
598 BufferedRawMachineAssemblerTester<int64_t> m(kMachInt64, kMachInt64, | 604 BufferedRawMachineAssemblerTester<int64_t> m( |
599 kMachInt64); | 605 MachineType::Int64(), MachineType::Int64(), MachineType::Int64()); |
600 m.Return( | 606 m.Return( |
601 m.Int64Add(m.Int64Add(m.Parameter(0), m.Parameter(1)), m.Parameter(2))); | 607 m.Int64Add(m.Int64Add(m.Parameter(0), m.Parameter(1)), m.Parameter(2))); |
602 FOR_INT64_INPUTS(i) { | 608 FOR_INT64_INPUTS(i) { |
603 FOR_INT64_INPUTS(j) { | 609 FOR_INT64_INPUTS(j) { |
604 CHECK_EQ(*i + *i + *j, m.Call(*i, *i, *j)); | 610 CHECK_EQ(*i + *i + *j, m.Call(*i, *i, *j)); |
605 CHECK_EQ(*i + *j + *i, m.Call(*i, *j, *i)); | 611 CHECK_EQ(*i + *j + *i, m.Call(*i, *j, *i)); |
606 CHECK_EQ(*j + *i + *i, m.Call(*j, *i, *i)); | 612 CHECK_EQ(*j + *i + *i, m.Call(*j, *i, *i)); |
607 } | 613 } |
608 } | 614 } |
609 } | 615 } |
610 { | 616 { |
611 BufferedRawMachineAssemblerTester<int64_t> m(kMachInt64, kMachInt64, | 617 BufferedRawMachineAssemblerTester<int64_t> m( |
612 kMachInt64, kMachInt64); | 618 MachineType::Int64(), MachineType::Int64(), MachineType::Int64(), |
| 619 MachineType::Int64()); |
613 m.Return(m.Int64Add( | 620 m.Return(m.Int64Add( |
614 m.Int64Add(m.Int64Add(m.Parameter(0), m.Parameter(1)), m.Parameter(2)), | 621 m.Int64Add(m.Int64Add(m.Parameter(0), m.Parameter(1)), m.Parameter(2)), |
615 m.Parameter(3))); | 622 m.Parameter(3))); |
616 FOR_INT64_INPUTS(i) { | 623 FOR_INT64_INPUTS(i) { |
617 FOR_INT64_INPUTS(j) { | 624 FOR_INT64_INPUTS(j) { |
618 CHECK_EQ(*i + *i + *i + *j, m.Call(*i, *i, *i, *j)); | 625 CHECK_EQ(*i + *i + *i + *j, m.Call(*i, *i, *i, *j)); |
619 CHECK_EQ(*i + *i + *j + *i, m.Call(*i, *i, *j, *i)); | 626 CHECK_EQ(*i + *i + *j + *i, m.Call(*i, *i, *j, *i)); |
620 CHECK_EQ(*i + *j + *i + *i, m.Call(*i, *j, *i, *i)); | 627 CHECK_EQ(*i + *j + *i + *i, m.Call(*i, *j, *i, *i)); |
621 CHECK_EQ(*j + *i + *i + *i, m.Call(*j, *i, *i, *i)); | 628 CHECK_EQ(*j + *i + *i + *i, m.Call(*j, *i, *i, *i)); |
622 } | 629 } |
623 } | 630 } |
624 } | 631 } |
625 { | 632 { |
626 BufferedRawMachineAssemblerTester<void> m; | 633 BufferedRawMachineAssemblerTester<void> m; |
627 int64_t result; | 634 int64_t result; |
628 m.Store(MachineTypeForC<int64_t>(), m.PointerConstant(&result), | 635 m.Store(MachineTypeForC<int64_t>(), m.PointerConstant(&result), |
629 m.Int64Constant(0x12500000000), kNoWriteBarrier); | 636 m.Int64Constant(0x12500000000), kNoWriteBarrier); |
630 m.Return(m.Int32Constant(0)); | 637 m.Return(m.Int32Constant(0)); |
631 m.Call(); | 638 m.Call(); |
632 CHECK_EQ(0x12500000000, result); | 639 CHECK_EQ(0x12500000000, result); |
633 } | 640 } |
634 { | 641 { |
635 BufferedRawMachineAssemblerTester<void> m(kMachFloat64); | 642 BufferedRawMachineAssemblerTester<void> m(MachineType::Float64()); |
636 double result; | 643 double result; |
637 m.Store(MachineTypeForC<double>(), m.PointerConstant(&result), | 644 m.Store(MachineTypeForC<double>(), m.PointerConstant(&result), |
638 m.Parameter(0), kNoWriteBarrier); | 645 m.Parameter(0), kNoWriteBarrier); |
639 m.Return(m.Int32Constant(0)); | 646 m.Return(m.Int32Constant(0)); |
640 FOR_FLOAT64_INPUTS(i) { | 647 FOR_FLOAT64_INPUTS(i) { |
641 m.Call(*i); | 648 m.Call(*i); |
642 CheckDoubleEq(*i, result); | 649 CheckDoubleEq(*i, result); |
643 } | 650 } |
644 } | 651 } |
645 { | 652 { |
646 BufferedRawMachineAssemblerTester<void> m(kMachInt64, kMachInt64); | 653 BufferedRawMachineAssemblerTester<void> m(MachineType::Int64(), |
| 654 MachineType::Int64()); |
647 int64_t result; | 655 int64_t result; |
648 m.Store(MachineTypeForC<int64_t>(), m.PointerConstant(&result), | 656 m.Store(MachineTypeForC<int64_t>(), m.PointerConstant(&result), |
649 m.Int64Add(m.Parameter(0), m.Parameter(1)), kNoWriteBarrier); | 657 m.Int64Add(m.Parameter(0), m.Parameter(1)), kNoWriteBarrier); |
650 m.Return(m.Int32Constant(0)); | 658 m.Return(m.Int32Constant(0)); |
651 FOR_INT64_INPUTS(i) { | 659 FOR_INT64_INPUTS(i) { |
652 FOR_INT64_INPUTS(j) { | 660 FOR_INT64_INPUTS(j) { |
653 m.Call(*i, *j); | 661 m.Call(*i, *j); |
654 CHECK_EQ(*i + *j, result); | 662 CHECK_EQ(*i + *j, result); |
655 | 663 |
656 m.Call(*j, *i); | 664 m.Call(*j, *i); |
657 CHECK_EQ(*j + *i, result); | 665 CHECK_EQ(*j + *i, result); |
658 } | 666 } |
659 } | 667 } |
660 } | 668 } |
661 { | 669 { |
662 BufferedRawMachineAssemblerTester<void> m(kMachInt64, kMachInt64, | 670 BufferedRawMachineAssemblerTester<void> m( |
663 kMachInt64); | 671 MachineType::Int64(), MachineType::Int64(), MachineType::Int64()); |
664 int64_t result; | 672 int64_t result; |
665 m.Store( | 673 m.Store( |
666 MachineTypeForC<int64_t>(), m.PointerConstant(&result), | 674 MachineTypeForC<int64_t>(), m.PointerConstant(&result), |
667 m.Int64Add(m.Int64Add(m.Parameter(0), m.Parameter(1)), m.Parameter(2)), | 675 m.Int64Add(m.Int64Add(m.Parameter(0), m.Parameter(1)), m.Parameter(2)), |
668 kNoWriteBarrier); | 676 kNoWriteBarrier); |
669 m.Return(m.Int32Constant(0)); | 677 m.Return(m.Int32Constant(0)); |
670 FOR_INT64_INPUTS(i) { | 678 FOR_INT64_INPUTS(i) { |
671 FOR_INT64_INPUTS(j) { | 679 FOR_INT64_INPUTS(j) { |
672 m.Call(*i, *i, *j); | 680 m.Call(*i, *i, *j); |
673 CHECK_EQ(*i + *i + *j, result); | 681 CHECK_EQ(*i + *i + *j, result); |
674 | 682 |
675 m.Call(*i, *j, *i); | 683 m.Call(*i, *j, *i); |
676 CHECK_EQ(*i + *j + *i, result); | 684 CHECK_EQ(*i + *j + *i, result); |
677 | 685 |
678 m.Call(*j, *i, *i); | 686 m.Call(*j, *i, *i); |
679 CHECK_EQ(*j + *i + *i, result); | 687 CHECK_EQ(*j + *i + *i, result); |
680 } | 688 } |
681 } | 689 } |
682 } | 690 } |
683 { | 691 { |
684 BufferedRawMachineAssemblerTester<void> m(kMachInt64, kMachInt64, | 692 BufferedRawMachineAssemblerTester<void> m( |
685 kMachInt64, kMachInt64); | 693 MachineType::Int64(), MachineType::Int64(), MachineType::Int64(), |
| 694 MachineType::Int64()); |
686 int64_t result; | 695 int64_t result; |
687 m.Store(MachineTypeForC<int64_t>(), m.PointerConstant(&result), | 696 m.Store(MachineTypeForC<int64_t>(), m.PointerConstant(&result), |
688 m.Int64Add(m.Int64Add(m.Int64Add(m.Parameter(0), m.Parameter(1)), | 697 m.Int64Add(m.Int64Add(m.Int64Add(m.Parameter(0), m.Parameter(1)), |
689 m.Parameter(2)), | 698 m.Parameter(2)), |
690 m.Parameter(3)), | 699 m.Parameter(3)), |
691 kNoWriteBarrier); | 700 kNoWriteBarrier); |
692 m.Return(m.Int32Constant(0)); | 701 m.Return(m.Int32Constant(0)); |
693 FOR_INT64_INPUTS(i) { | 702 FOR_INT64_INPUTS(i) { |
694 FOR_INT64_INPUTS(j) { | 703 FOR_INT64_INPUTS(j) { |
695 m.Call(*i, *i, *i, *j); | 704 m.Call(*i, *i, *i, *j); |
696 CHECK_EQ(*i + *i + *i + *j, result); | 705 CHECK_EQ(*i + *i + *i + *j, result); |
697 | 706 |
698 m.Call(*i, *i, *j, *i); | 707 m.Call(*i, *i, *j, *i); |
699 CHECK_EQ(*i + *i + *j + *i, result); | 708 CHECK_EQ(*i + *i + *j + *i, result); |
700 | 709 |
701 m.Call(*i, *j, *i, *i); | 710 m.Call(*i, *j, *i, *i); |
702 CHECK_EQ(*i + *j + *i + *i, result); | 711 CHECK_EQ(*i + *j + *i + *i, result); |
703 | 712 |
704 m.Call(*j, *i, *i, *i); | 713 m.Call(*j, *i, *i, *i); |
705 CHECK_EQ(*j + *i + *i + *i, result); | 714 CHECK_EQ(*j + *i + *i + *i, result); |
706 } | 715 } |
707 } | 716 } |
708 } | 717 } |
709 } | 718 } |
710 | 719 |
711 #endif | 720 #endif |
712 } // namespace compiler | 721 } // namespace compiler |
713 } // namespace internal | 722 } // namespace internal |
714 } // namespace v8 | 723 } // namespace v8 |
OLD | NEW |