| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/assembler.h" | 5 #include "src/assembler.h" |
| 6 #include "src/codegen.h" | 6 #include "src/codegen.h" |
| 7 #include "src/compiler/linkage.h" | 7 #include "src/compiler/linkage.h" |
| 8 #include "src/compiler/raw-machine-assembler.h" | 8 #include "src/compiler/raw-machine-assembler.h" |
| 9 #include "src/machine-type.h" | 9 #include "src/machine-type.h" |
| 10 #include "src/register-configuration.h" | 10 #include "src/register-configuration.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 if (FLAG_print_opt_code) { | 263 if (FLAG_print_opt_code) { |
| 264 OFStream os(stdout); | 264 OFStream os(stdout); |
| 265 code->Disassemble(name, os); | 265 code->Disassemble(name, os); |
| 266 } | 266 } |
| 267 #endif | 267 #endif |
| 268 return code; | 268 return code; |
| 269 } | 269 } |
| 270 | 270 |
| 271 | 271 |
| 272 Handle<Code> WrapWithCFunction(Handle<Code> inner, CallDescriptor* desc) { | 272 Handle<Code> WrapWithCFunction(Handle<Code> inner, CallDescriptor* desc) { |
| 273 Zone zone; | 273 Zone zone(inner->GetIsolate()->allocator()); |
| 274 MachineSignature* msig = | 274 MachineSignature* msig = |
| 275 const_cast<MachineSignature*>(desc->GetMachineSignature()); | 275 const_cast<MachineSignature*>(desc->GetMachineSignature()); |
| 276 int param_count = static_cast<int>(msig->parameter_count()); | 276 int param_count = static_cast<int>(msig->parameter_count()); |
| 277 GraphAndBuilders caller(&zone); | 277 GraphAndBuilders caller(&zone); |
| 278 { | 278 { |
| 279 GraphAndBuilders& b = caller; | 279 GraphAndBuilders& b = caller; |
| 280 Node* start = b.graph()->NewNode(b.common()->Start(param_count + 3)); | 280 Node* start = b.graph()->NewNode(b.common()->Start(param_count + 3)); |
| 281 b.graph()->SetStart(start); | 281 b.graph()->SetStart(start); |
| 282 Node* target = b.graph()->NewNode(b.common()->HeapConstant(inner)); | 282 Node* target = b.graph()->NewNode(b.common()->HeapConstant(inner)); |
| 283 | 283 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 void (*build)(CallDescriptor*, RawMachineAssembler&), | 430 void (*build)(CallDescriptor*, RawMachineAssembler&), |
| 431 CType (*compute)(CallDescriptor*, CType* inputs), | 431 CType (*compute)(CallDescriptor*, CType* inputs), |
| 432 int seed = 1) { | 432 int seed = 1) { |
| 433 int num_params = ParamCount(desc); | 433 int num_params = ParamCount(desc); |
| 434 CHECK_LE(num_params, kMaxParamCount); | 434 CHECK_LE(num_params, kMaxParamCount); |
| 435 Isolate* isolate = CcTest::InitIsolateOnce(); | 435 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 436 HandleScope scope(isolate); | 436 HandleScope scope(isolate); |
| 437 Handle<Code> inner = Handle<Code>::null(); | 437 Handle<Code> inner = Handle<Code>::null(); |
| 438 { | 438 { |
| 439 // Build the graph for the computation. | 439 // Build the graph for the computation. |
| 440 Zone zone; | 440 Zone zone(isolate->allocator()); |
| 441 Graph graph(&zone); | 441 Graph graph(&zone); |
| 442 RawMachineAssembler raw(isolate, &graph, desc); | 442 RawMachineAssembler raw(isolate, &graph, desc); |
| 443 build(desc, raw); | 443 build(desc, raw); |
| 444 inner = CompileGraph("Compute", desc, &graph, raw.Export()); | 444 inner = CompileGraph("Compute", desc, &graph, raw.Export()); |
| 445 } | 445 } |
| 446 | 446 |
| 447 CSignature0<int32_t> csig; | 447 CSignature0<int32_t> csig; |
| 448 ArgsBuffer<CType> io(num_params, seed); | 448 ArgsBuffer<CType> io(num_params, seed); |
| 449 | 449 |
| 450 { | 450 { |
| 451 // constant mode. | 451 // constant mode. |
| 452 Handle<Code> wrapper = Handle<Code>::null(); | 452 Handle<Code> wrapper = Handle<Code>::null(); |
| 453 { | 453 { |
| 454 // Wrap the above code with a callable function that passes constants. | 454 // Wrap the above code with a callable function that passes constants. |
| 455 Zone zone; | 455 Zone zone(isolate->allocator()); |
| 456 Graph graph(&zone); | 456 Graph graph(&zone); |
| 457 CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, &csig); | 457 CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, &csig); |
| 458 RawMachineAssembler raw(isolate, &graph, cdesc); | 458 RawMachineAssembler raw(isolate, &graph, cdesc); |
| 459 Node* target = raw.HeapConstant(inner); | 459 Node* target = raw.HeapConstant(inner); |
| 460 Node** args = zone.NewArray<Node*>(num_params); | 460 Node** args = zone.NewArray<Node*>(num_params); |
| 461 for (int i = 0; i < num_params; i++) { | 461 for (int i = 0; i < num_params; i++) { |
| 462 args[i] = io.MakeConstant(raw, io.input[i]); | 462 args[i] = io.MakeConstant(raw, io.input[i]); |
| 463 } | 463 } |
| 464 | 464 |
| 465 Node* call = raw.CallN(desc, target, args); | 465 Node* call = raw.CallN(desc, target, args); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 477 int32_t check_seed = runnable.Call(); | 477 int32_t check_seed = runnable.Call(); |
| 478 CHECK_EQ(seed, check_seed); | 478 CHECK_EQ(seed, check_seed); |
| 479 CHECK_EQ(expected, io.output); | 479 CHECK_EQ(expected, io.output); |
| 480 } | 480 } |
| 481 | 481 |
| 482 { | 482 { |
| 483 // buffer mode. | 483 // buffer mode. |
| 484 Handle<Code> wrapper = Handle<Code>::null(); | 484 Handle<Code> wrapper = Handle<Code>::null(); |
| 485 { | 485 { |
| 486 // Wrap the above code with a callable function that loads from {input}. | 486 // Wrap the above code with a callable function that loads from {input}. |
| 487 Zone zone; | 487 Zone zone(isolate->allocator()); |
| 488 Graph graph(&zone); | 488 Graph graph(&zone); |
| 489 CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, &csig); | 489 CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, &csig); |
| 490 RawMachineAssembler raw(isolate, &graph, cdesc); | 490 RawMachineAssembler raw(isolate, &graph, cdesc); |
| 491 Node* base = raw.PointerConstant(io.input); | 491 Node* base = raw.PointerConstant(io.input); |
| 492 Node* target = raw.HeapConstant(inner); | 492 Node* target = raw.HeapConstant(inner); |
| 493 Node** args = zone.NewArray<Node*>(kMaxParamCount); | 493 Node** args = zone.NewArray<Node*>(kMaxParamCount); |
| 494 for (int i = 0; i < num_params; i++) { | 494 for (int i = 0; i < num_params; i++) { |
| 495 args[i] = io.LoadInput(raw, base, i); | 495 args[i] = io.LoadInput(raw, base, i); |
| 496 } | 496 } |
| 497 | 497 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 515 } | 515 } |
| 516 } | 516 } |
| 517 }; | 517 }; |
| 518 | 518 |
| 519 } // namespace | 519 } // namespace |
| 520 | 520 |
| 521 | 521 |
| 522 static void TestInt32Sub(CallDescriptor* desc) { | 522 static void TestInt32Sub(CallDescriptor* desc) { |
| 523 Isolate* isolate = CcTest::InitIsolateOnce(); | 523 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 524 HandleScope scope(isolate); | 524 HandleScope scope(isolate); |
| 525 Zone zone; | 525 Zone zone(isolate->allocator()); |
| 526 GraphAndBuilders inner(&zone); | 526 GraphAndBuilders inner(&zone); |
| 527 { | 527 { |
| 528 // Build the add function. | 528 // Build the add function. |
| 529 GraphAndBuilders& b = inner; | 529 GraphAndBuilders& b = inner; |
| 530 Node* start = b.graph()->NewNode(b.common()->Start(5)); | 530 Node* start = b.graph()->NewNode(b.common()->Start(5)); |
| 531 b.graph()->SetStart(start); | 531 b.graph()->SetStart(start); |
| 532 Node* p0 = b.graph()->NewNode(b.common()->Parameter(0), start); | 532 Node* p0 = b.graph()->NewNode(b.common()->Parameter(0), start); |
| 533 Node* p1 = b.graph()->NewNode(b.common()->Parameter(1), start); | 533 Node* p1 = b.graph()->NewNode(b.common()->Parameter(1), start); |
| 534 Node* add = b.graph()->NewNode(b.machine()->Int32Sub(), p0, p1); | 534 Node* add = b.graph()->NewNode(b.machine()->Int32Sub(), p0, p1); |
| 535 Node* ret = b.graph()->NewNode(b.common()->Return(), add, start, start); | 535 Node* ret = b.graph()->NewNode(b.common()->Return(), add, start, start); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 556 | 556 |
| 557 static void CopyTwentyInt32(CallDescriptor* desc) { | 557 static void CopyTwentyInt32(CallDescriptor* desc) { |
| 558 const int kNumParams = 20; | 558 const int kNumParams = 20; |
| 559 int32_t input[kNumParams]; | 559 int32_t input[kNumParams]; |
| 560 int32_t output[kNumParams]; | 560 int32_t output[kNumParams]; |
| 561 Isolate* isolate = CcTest::InitIsolateOnce(); | 561 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 562 HandleScope scope(isolate); | 562 HandleScope scope(isolate); |
| 563 Handle<Code> inner = Handle<Code>::null(); | 563 Handle<Code> inner = Handle<Code>::null(); |
| 564 { | 564 { |
| 565 // Writes all parameters into the output buffer. | 565 // Writes all parameters into the output buffer. |
| 566 Zone zone; | 566 Zone zone(isolate->allocator()); |
| 567 Graph graph(&zone); | 567 Graph graph(&zone); |
| 568 RawMachineAssembler raw(isolate, &graph, desc); | 568 RawMachineAssembler raw(isolate, &graph, desc); |
| 569 Node* base = raw.PointerConstant(output); | 569 Node* base = raw.PointerConstant(output); |
| 570 for (int i = 0; i < kNumParams; i++) { | 570 for (int i = 0; i < kNumParams; i++) { |
| 571 Node* offset = raw.Int32Constant(i * sizeof(int32_t)); | 571 Node* offset = raw.Int32Constant(i * sizeof(int32_t)); |
| 572 raw.Store(MachineRepresentation::kWord32, base, offset, raw.Parameter(i), | 572 raw.Store(MachineRepresentation::kWord32, base, offset, raw.Parameter(i), |
| 573 kNoWriteBarrier); | 573 kNoWriteBarrier); |
| 574 } | 574 } |
| 575 raw.Return(raw.Int32Constant(42)); | 575 raw.Return(raw.Int32Constant(42)); |
| 576 inner = CompileGraph("CopyTwentyInt32", desc, &graph, raw.Export()); | 576 inner = CompileGraph("CopyTwentyInt32", desc, &graph, raw.Export()); |
| 577 } | 577 } |
| 578 | 578 |
| 579 CSignature0<int32_t> csig; | 579 CSignature0<int32_t> csig; |
| 580 Handle<Code> wrapper = Handle<Code>::null(); | 580 Handle<Code> wrapper = Handle<Code>::null(); |
| 581 { | 581 { |
| 582 // Loads parameters from the input buffer and calls the above code. | 582 // Loads parameters from the input buffer and calls the above code. |
| 583 Zone zone; | 583 Zone zone(isolate->allocator()); |
| 584 Graph graph(&zone); | 584 Graph graph(&zone); |
| 585 CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, &csig); | 585 CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, &csig); |
| 586 RawMachineAssembler raw(isolate, &graph, cdesc); | 586 RawMachineAssembler raw(isolate, &graph, cdesc); |
| 587 Node* base = raw.PointerConstant(input); | 587 Node* base = raw.PointerConstant(input); |
| 588 Node* target = raw.HeapConstant(inner); | 588 Node* target = raw.HeapConstant(inner); |
| 589 Node** args = zone.NewArray<Node*>(kNumParams); | 589 Node** args = zone.NewArray<Node*>(kNumParams); |
| 590 for (int i = 0; i < kNumParams; i++) { | 590 for (int i = 0; i < kNumParams; i++) { |
| 591 Node* offset = raw.Int32Constant(i * sizeof(int32_t)); | 591 Node* offset = raw.Int32Constant(i * sizeof(int32_t)); |
| 592 args[i] = raw.Load(MachineType::Int32(), base, offset); | 592 args[i] = raw.Load(MachineType::Int32(), base, offset); |
| 593 } | 593 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 612 | 612 |
| 613 for (int j = 0; j < kNumParams; j++) { | 613 for (int j = 0; j < kNumParams; j++) { |
| 614 CHECK_EQ(input[j], output[j]); | 614 CHECK_EQ(input[j], output[j]); |
| 615 } | 615 } |
| 616 } | 616 } |
| 617 } | 617 } |
| 618 | 618 |
| 619 | 619 |
| 620 static void Test_RunInt32SubWithRet(int retreg) { | 620 static void Test_RunInt32SubWithRet(int retreg) { |
| 621 Int32Signature sig(2); | 621 Int32Signature sig(2); |
| 622 Zone zone; | 622 base::AccountingAllocator allocator; |
| 623 Zone zone(&allocator); |
| 623 RegisterPairs pairs; | 624 RegisterPairs pairs; |
| 624 while (pairs.More()) { | 625 while (pairs.More()) { |
| 625 int parray[2]; | 626 int parray[2]; |
| 626 int rarray[] = {retreg}; | 627 int rarray[] = {retreg}; |
| 627 pairs.Next(&parray[0], &parray[1], false); | 628 pairs.Next(&parray[0], &parray[1], false); |
| 628 Allocator params(parray, 2, nullptr, 0); | 629 Allocator params(parray, 2, nullptr, 0); |
| 629 Allocator rets(rarray, 1, nullptr, 0); | 630 Allocator rets(rarray, 1, nullptr, 0); |
| 630 RegisterConfig config(params, rets); | 631 RegisterConfig config(params, rets); |
| 631 CallDescriptor* desc = config.Create(&zone, &sig); | 632 CallDescriptor* desc = config.Create(&zone, &sig); |
| 632 TestInt32Sub(desc); | 633 TestInt32Sub(desc); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 663 TEST_INT32_SUB_WITH_RET(16) | 664 TEST_INT32_SUB_WITH_RET(16) |
| 664 TEST_INT32_SUB_WITH_RET(17) | 665 TEST_INT32_SUB_WITH_RET(17) |
| 665 TEST_INT32_SUB_WITH_RET(18) | 666 TEST_INT32_SUB_WITH_RET(18) |
| 666 TEST_INT32_SUB_WITH_RET(19) | 667 TEST_INT32_SUB_WITH_RET(19) |
| 667 | 668 |
| 668 | 669 |
| 669 TEST(Run_Int32Sub_all_allocatable_single) { | 670 TEST(Run_Int32Sub_all_allocatable_single) { |
| 670 Int32Signature sig(2); | 671 Int32Signature sig(2); |
| 671 RegisterPairs pairs; | 672 RegisterPairs pairs; |
| 672 while (pairs.More()) { | 673 while (pairs.More()) { |
| 673 Zone zone; | 674 base::AccountingAllocator allocator; |
| 675 Zone zone(&allocator); |
| 674 int parray[1]; | 676 int parray[1]; |
| 675 int rarray[1]; | 677 int rarray[1]; |
| 676 pairs.Next(&rarray[0], &parray[0], true); | 678 pairs.Next(&rarray[0], &parray[0], true); |
| 677 Allocator params(parray, 1, nullptr, 0); | 679 Allocator params(parray, 1, nullptr, 0); |
| 678 Allocator rets(rarray, 1, nullptr, 0); | 680 Allocator rets(rarray, 1, nullptr, 0); |
| 679 RegisterConfig config(params, rets); | 681 RegisterConfig config(params, rets); |
| 680 CallDescriptor* desc = config.Create(&zone, &sig); | 682 CallDescriptor* desc = config.Create(&zone, &sig); |
| 681 TestInt32Sub(desc); | 683 TestInt32Sub(desc); |
| 682 } | 684 } |
| 683 } | 685 } |
| 684 | 686 |
| 685 | 687 |
| 686 TEST(Run_CopyTwentyInt32_all_allocatable_pairs) { | 688 TEST(Run_CopyTwentyInt32_all_allocatable_pairs) { |
| 687 Int32Signature sig(20); | 689 Int32Signature sig(20); |
| 688 RegisterPairs pairs; | 690 RegisterPairs pairs; |
| 689 while (pairs.More()) { | 691 while (pairs.More()) { |
| 690 Zone zone; | 692 base::AccountingAllocator allocator; |
| 693 Zone zone(&allocator); |
| 691 int parray[2]; | 694 int parray[2]; |
| 692 int rarray[] = { | 695 int rarray[] = { |
| 693 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 696 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 694 ->GetAllocatableGeneralCode(0)}; | 697 ->GetAllocatableGeneralCode(0)}; |
| 695 pairs.Next(&parray[0], &parray[1], false); | 698 pairs.Next(&parray[0], &parray[1], false); |
| 696 Allocator params(parray, 2, nullptr, 0); | 699 Allocator params(parray, 2, nullptr, 0); |
| 697 Allocator rets(rarray, 1, nullptr, 0); | 700 Allocator rets(rarray, 1, nullptr, 0); |
| 698 RegisterConfig config(params, rets); | 701 RegisterConfig config(params, rets); |
| 699 CallDescriptor* desc = config.Create(&zone, &sig); | 702 CallDescriptor* desc = config.Create(&zone, &sig); |
| 700 CopyTwentyInt32(desc); | 703 CopyTwentyInt32(desc); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 result += static_cast<uint32_t>(input[i]) * coeff[i]; | 735 result += static_cast<uint32_t>(input[i]) * coeff[i]; |
| 733 } | 736 } |
| 734 return static_cast<int32_t>(result); | 737 return static_cast<int32_t>(result); |
| 735 } | 738 } |
| 736 | 739 |
| 737 | 740 |
| 738 static void Test_Int32_WeightedSum_of_size(int count) { | 741 static void Test_Int32_WeightedSum_of_size(int count) { |
| 739 Int32Signature sig(count); | 742 Int32Signature sig(count); |
| 740 for (int p0 = 0; p0 < Register::kNumRegisters; p0++) { | 743 for (int p0 = 0; p0 < Register::kNumRegisters; p0++) { |
| 741 if (Register::from_code(p0).IsAllocatable()) { | 744 if (Register::from_code(p0).IsAllocatable()) { |
| 742 Zone zone; | 745 base::AccountingAllocator allocator; |
| 746 Zone zone(&allocator); |
| 743 | 747 |
| 744 int parray[] = {p0}; | 748 int parray[] = {p0}; |
| 745 int rarray[] = { | 749 int rarray[] = { |
| 746 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 750 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 747 ->GetAllocatableGeneralCode(0)}; | 751 ->GetAllocatableGeneralCode(0)}; |
| 748 Allocator params(parray, 1, nullptr, 0); | 752 Allocator params(parray, 1, nullptr, 0); |
| 749 Allocator rets(rarray, 1, nullptr, 0); | 753 Allocator rets(rarray, 1, nullptr, 0); |
| 750 RegisterConfig config(params, rets); | 754 RegisterConfig config(params, rets); |
| 751 CallDescriptor* desc = config.Create(&zone, &sig); | 755 CallDescriptor* desc = config.Create(&zone, &sig); |
| 752 Run_Computation<int32_t>(desc, Build_Int32_WeightedSum, | 756 Run_Computation<int32_t>(desc, Build_Int32_WeightedSum, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 int parray[] = { | 804 int parray[] = { |
| 801 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 805 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 802 ->GetAllocatableGeneralCode(0)}; | 806 ->GetAllocatableGeneralCode(0)}; |
| 803 int rarray[] = { | 807 int rarray[] = { |
| 804 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 808 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 805 ->GetAllocatableGeneralCode(0)}; | 809 ->GetAllocatableGeneralCode(0)}; |
| 806 Allocator params(parray, 1, nullptr, 0); | 810 Allocator params(parray, 1, nullptr, 0); |
| 807 Allocator rets(rarray, 1, nullptr, 0); | 811 Allocator rets(rarray, 1, nullptr, 0); |
| 808 RegisterConfig config(params, rets); | 812 RegisterConfig config(params, rets); |
| 809 | 813 |
| 810 Zone zone; | 814 base::AccountingAllocator allocator; |
| 815 Zone zone(&allocator); |
| 811 | 816 |
| 812 for (int i = which + 1; i <= 64; i++) { | 817 for (int i = which + 1; i <= 64; i++) { |
| 813 Int32Signature sig(i); | 818 Int32Signature sig(i); |
| 814 CallDescriptor* desc = config.Create(&zone, &sig); | 819 CallDescriptor* desc = config.Create(&zone, &sig); |
| 815 RunSelect<int32_t, which>(desc); | 820 RunSelect<int32_t, which>(desc); |
| 816 } | 821 } |
| 817 } | 822 } |
| 818 | 823 |
| 819 | 824 |
| 820 // Separate tests for parallelization. | 825 // Separate tests for parallelization. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 842 ->num_allocatable_general_registers() < 2) | 847 ->num_allocatable_general_registers() < 2) |
| 843 return; | 848 return; |
| 844 if (kPointerSize < 8) return; // TODO(titzer): int64 on 32-bit platforms | 849 if (kPointerSize < 8) return; // TODO(titzer): int64 on 32-bit platforms |
| 845 | 850 |
| 846 int rarray[] = { | 851 int rarray[] = { |
| 847 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 852 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 848 ->GetAllocatableGeneralCode(0)}; | 853 ->GetAllocatableGeneralCode(0)}; |
| 849 ArgsBuffer<int64_t>::Sig sig(2); | 854 ArgsBuffer<int64_t>::Sig sig(2); |
| 850 | 855 |
| 851 RegisterPairs pairs; | 856 RegisterPairs pairs; |
| 852 Zone zone; | 857 base::AccountingAllocator allocator; |
| 858 Zone zone(&allocator); |
| 853 while (pairs.More()) { | 859 while (pairs.More()) { |
| 854 int parray[2]; | 860 int parray[2]; |
| 855 pairs.Next(&parray[0], &parray[1], false); | 861 pairs.Next(&parray[0], &parray[1], false); |
| 856 Allocator params(parray, 2, nullptr, 0); | 862 Allocator params(parray, 2, nullptr, 0); |
| 857 Allocator rets(rarray, 1, nullptr, 0); | 863 Allocator rets(rarray, 1, nullptr, 0); |
| 858 RegisterConfig config(params, rets); | 864 RegisterConfig config(params, rets); |
| 859 | 865 |
| 860 CallDescriptor* desc = config.Create(&zone, &sig); | 866 CallDescriptor* desc = config.Create(&zone, &sig); |
| 861 RunSelect<int64_t, 0>(desc); | 867 RunSelect<int64_t, 0>(desc); |
| 862 RunSelect<int64_t, 1>(desc); | 868 RunSelect<int64_t, 1>(desc); |
| 863 } | 869 } |
| 864 } | 870 } |
| 865 | 871 |
| 866 | 872 |
| 867 TEST(Float32Select_registers) { | 873 TEST(Float32Select_registers) { |
| 868 if (RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 874 if (RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 869 ->num_allocatable_double_registers() < 2) { | 875 ->num_allocatable_double_registers() < 2) { |
| 870 return; | 876 return; |
| 871 } | 877 } |
| 872 | 878 |
| 873 int rarray[] = { | 879 int rarray[] = { |
| 874 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 880 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 875 ->GetAllocatableDoubleCode(0)}; | 881 ->GetAllocatableDoubleCode(0)}; |
| 876 ArgsBuffer<float32>::Sig sig(2); | 882 ArgsBuffer<float32>::Sig sig(2); |
| 877 | 883 |
| 878 Float32RegisterPairs pairs; | 884 Float32RegisterPairs pairs; |
| 879 Zone zone; | 885 base::AccountingAllocator allocator; |
| 886 Zone zone(&allocator); |
| 880 while (pairs.More()) { | 887 while (pairs.More()) { |
| 881 int parray[2]; | 888 int parray[2]; |
| 882 pairs.Next(&parray[0], &parray[1], false); | 889 pairs.Next(&parray[0], &parray[1], false); |
| 883 Allocator params(nullptr, 0, parray, 2); | 890 Allocator params(nullptr, 0, parray, 2); |
| 884 Allocator rets(nullptr, 0, rarray, 1); | 891 Allocator rets(nullptr, 0, rarray, 1); |
| 885 RegisterConfig config(params, rets); | 892 RegisterConfig config(params, rets); |
| 886 | 893 |
| 887 CallDescriptor* desc = config.Create(&zone, &sig); | 894 CallDescriptor* desc = config.Create(&zone, &sig); |
| 888 RunSelect<float32, 0>(desc); | 895 RunSelect<float32, 0>(desc); |
| 889 RunSelect<float32, 1>(desc); | 896 RunSelect<float32, 1>(desc); |
| 890 } | 897 } |
| 891 } | 898 } |
| 892 | 899 |
| 893 | 900 |
| 894 TEST(Float64Select_registers) { | 901 TEST(Float64Select_registers) { |
| 895 if (RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 902 if (RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 896 ->num_allocatable_double_registers() < 2) | 903 ->num_allocatable_double_registers() < 2) |
| 897 return; | 904 return; |
| 898 if (RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 905 if (RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 899 ->num_allocatable_general_registers() < 2) | 906 ->num_allocatable_general_registers() < 2) |
| 900 return; | 907 return; |
| 901 int rarray[] = { | 908 int rarray[] = { |
| 902 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 909 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 903 ->GetAllocatableDoubleCode(0)}; | 910 ->GetAllocatableDoubleCode(0)}; |
| 904 ArgsBuffer<float64>::Sig sig(2); | 911 ArgsBuffer<float64>::Sig sig(2); |
| 905 | 912 |
| 906 Float64RegisterPairs pairs; | 913 Float64RegisterPairs pairs; |
| 907 Zone zone; | 914 base::AccountingAllocator allocator; |
| 915 Zone zone(&allocator); |
| 908 while (pairs.More()) { | 916 while (pairs.More()) { |
| 909 int parray[2]; | 917 int parray[2]; |
| 910 pairs.Next(&parray[0], &parray[1], false); | 918 pairs.Next(&parray[0], &parray[1], false); |
| 911 Allocator params(nullptr, 0, parray, 2); | 919 Allocator params(nullptr, 0, parray, 2); |
| 912 Allocator rets(nullptr, 0, rarray, 1); | 920 Allocator rets(nullptr, 0, rarray, 1); |
| 913 RegisterConfig config(params, rets); | 921 RegisterConfig config(params, rets); |
| 914 | 922 |
| 915 CallDescriptor* desc = config.Create(&zone, &sig); | 923 CallDescriptor* desc = config.Create(&zone, &sig); |
| 916 RunSelect<float64, 0>(desc); | 924 RunSelect<float64, 0>(desc); |
| 917 RunSelect<float64, 1>(desc); | 925 RunSelect<float64, 1>(desc); |
| 918 } | 926 } |
| 919 } | 927 } |
| 920 | 928 |
| 921 | 929 |
| 922 TEST(Float32Select_stack_params_return_reg) { | 930 TEST(Float32Select_stack_params_return_reg) { |
| 923 int rarray[] = { | 931 int rarray[] = { |
| 924 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 932 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 925 ->GetAllocatableDoubleCode(0)}; | 933 ->GetAllocatableDoubleCode(0)}; |
| 926 Allocator params(nullptr, 0, nullptr, 0); | 934 Allocator params(nullptr, 0, nullptr, 0); |
| 927 Allocator rets(nullptr, 0, rarray, 1); | 935 Allocator rets(nullptr, 0, rarray, 1); |
| 928 RegisterConfig config(params, rets); | 936 RegisterConfig config(params, rets); |
| 929 | 937 |
| 930 Zone zone; | 938 base::AccountingAllocator allocator; |
| 939 Zone zone(&allocator); |
| 931 for (int count = 1; count < 6; count++) { | 940 for (int count = 1; count < 6; count++) { |
| 932 ArgsBuffer<float32>::Sig sig(count); | 941 ArgsBuffer<float32>::Sig sig(count); |
| 933 CallDescriptor* desc = config.Create(&zone, &sig); | 942 CallDescriptor* desc = config.Create(&zone, &sig); |
| 934 RunSelect<float32, 0>(desc); | 943 RunSelect<float32, 0>(desc); |
| 935 RunSelect<float32, 1>(desc); | 944 RunSelect<float32, 1>(desc); |
| 936 RunSelect<float32, 2>(desc); | 945 RunSelect<float32, 2>(desc); |
| 937 RunSelect<float32, 3>(desc); | 946 RunSelect<float32, 3>(desc); |
| 938 RunSelect<float32, 4>(desc); | 947 RunSelect<float32, 4>(desc); |
| 939 RunSelect<float32, 5>(desc); | 948 RunSelect<float32, 5>(desc); |
| 940 } | 949 } |
| 941 } | 950 } |
| 942 | 951 |
| 943 | 952 |
| 944 TEST(Float64Select_stack_params_return_reg) { | 953 TEST(Float64Select_stack_params_return_reg) { |
| 945 int rarray[] = { | 954 int rarray[] = { |
| 946 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 955 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 947 ->GetAllocatableDoubleCode(0)}; | 956 ->GetAllocatableDoubleCode(0)}; |
| 948 Allocator params(nullptr, 0, nullptr, 0); | 957 Allocator params(nullptr, 0, nullptr, 0); |
| 949 Allocator rets(nullptr, 0, rarray, 1); | 958 Allocator rets(nullptr, 0, rarray, 1); |
| 950 RegisterConfig config(params, rets); | 959 RegisterConfig config(params, rets); |
| 951 | 960 |
| 952 Zone zone; | 961 base::AccountingAllocator allocator; |
| 962 Zone zone(&allocator); |
| 953 for (int count = 1; count < 6; count++) { | 963 for (int count = 1; count < 6; count++) { |
| 954 ArgsBuffer<float64>::Sig sig(count); | 964 ArgsBuffer<float64>::Sig sig(count); |
| 955 CallDescriptor* desc = config.Create(&zone, &sig); | 965 CallDescriptor* desc = config.Create(&zone, &sig); |
| 956 RunSelect<float64, 0>(desc); | 966 RunSelect<float64, 0>(desc); |
| 957 RunSelect<float64, 1>(desc); | 967 RunSelect<float64, 1>(desc); |
| 958 RunSelect<float64, 2>(desc); | 968 RunSelect<float64, 2>(desc); |
| 959 RunSelect<float64, 3>(desc); | 969 RunSelect<float64, 3>(desc); |
| 960 RunSelect<float64, 4>(desc); | 970 RunSelect<float64, 4>(desc); |
| 961 RunSelect<float64, 5>(desc); | 971 RunSelect<float64, 5>(desc); |
| 962 } | 972 } |
| 963 } | 973 } |
| 964 | 974 |
| 965 | 975 |
| 966 template <typename CType, int which> | 976 template <typename CType, int which> |
| 967 static void Build_Select_With_Call(CallDescriptor* desc, | 977 static void Build_Select_With_Call(CallDescriptor* desc, |
| 968 RawMachineAssembler& raw) { | 978 RawMachineAssembler& raw) { |
| 969 Handle<Code> inner = Handle<Code>::null(); | 979 Handle<Code> inner = Handle<Code>::null(); |
| 970 int num_params = ParamCount(desc); | 980 int num_params = ParamCount(desc); |
| 971 CHECK_LE(num_params, kMaxParamCount); | 981 CHECK_LE(num_params, kMaxParamCount); |
| 972 { | 982 { |
| 973 Isolate* isolate = CcTest::InitIsolateOnce(); | 983 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 974 // Build the actual select. | 984 // Build the actual select. |
| 975 Zone zone; | 985 Zone zone(isolate->allocator()); |
| 976 Graph graph(&zone); | 986 Graph graph(&zone); |
| 977 RawMachineAssembler raw(isolate, &graph, desc); | 987 RawMachineAssembler raw(isolate, &graph, desc); |
| 978 raw.Return(raw.Parameter(which)); | 988 raw.Return(raw.Parameter(which)); |
| 979 inner = CompileGraph("Select-indirection", desc, &graph, raw.Export()); | 989 inner = CompileGraph("Select-indirection", desc, &graph, raw.Export()); |
| 980 CHECK(!inner.is_null()); | 990 CHECK(!inner.is_null()); |
| 981 CHECK(inner->IsCode()); | 991 CHECK(inner->IsCode()); |
| 982 } | 992 } |
| 983 | 993 |
| 984 { | 994 { |
| 985 // Build a call to the function that does the select. | 995 // Build a call to the function that does the select. |
| 986 Node* target = raw.HeapConstant(inner); | 996 Node* target = raw.HeapConstant(inner); |
| 987 Node** args = raw.zone()->NewArray<Node*>(num_params); | 997 Node** args = raw.zone()->NewArray<Node*>(num_params); |
| 988 for (int i = 0; i < num_params; i++) { | 998 for (int i = 0; i < num_params; i++) { |
| 989 args[i] = raw.Parameter(i); | 999 args[i] = raw.Parameter(i); |
| 990 } | 1000 } |
| 991 | 1001 |
| 992 Node* call = raw.CallN(desc, target, args); | 1002 Node* call = raw.CallN(desc, target, args); |
| 993 raw.Return(call); | 1003 raw.Return(call); |
| 994 } | 1004 } |
| 995 } | 1005 } |
| 996 | 1006 |
| 997 | 1007 |
| 998 TEST(Float64StackParamsToStackParams) { | 1008 TEST(Float64StackParamsToStackParams) { |
| 999 int rarray[] = { | 1009 int rarray[] = { |
| 1000 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 1010 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 1001 ->GetAllocatableDoubleCode(0)}; | 1011 ->GetAllocatableDoubleCode(0)}; |
| 1002 Allocator params(nullptr, 0, nullptr, 0); | 1012 Allocator params(nullptr, 0, nullptr, 0); |
| 1003 Allocator rets(nullptr, 0, rarray, 1); | 1013 Allocator rets(nullptr, 0, rarray, 1); |
| 1004 | 1014 |
| 1005 Zone zone; | 1015 base::AccountingAllocator allocator; |
| 1016 Zone zone(&allocator); |
| 1006 ArgsBuffer<float64>::Sig sig(2); | 1017 ArgsBuffer<float64>::Sig sig(2); |
| 1007 RegisterConfig config(params, rets); | 1018 RegisterConfig config(params, rets); |
| 1008 CallDescriptor* desc = config.Create(&zone, &sig); | 1019 CallDescriptor* desc = config.Create(&zone, &sig); |
| 1009 | 1020 |
| 1010 Run_Computation<float64>(desc, Build_Select_With_Call<float64, 0>, | 1021 Run_Computation<float64>(desc, Build_Select_With_Call<float64, 0>, |
| 1011 Compute_Select<float64, 0>, 1098); | 1022 Compute_Select<float64, 0>, 1098); |
| 1012 | 1023 |
| 1013 Run_Computation<float64>(desc, Build_Select_With_Call<float64, 1>, | 1024 Run_Computation<float64>(desc, Build_Select_With_Call<float64, 1>, |
| 1014 Compute_Select<float64, 1>, 1099); | 1025 Compute_Select<float64, 1>, 1099); |
| 1015 } | 1026 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 1072 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 1062 ->GetAllocatableDoubleCode(1)}; | 1073 ->GetAllocatableDoubleCode(1)}; |
| 1063 int rarray_fp[] = { | 1074 int rarray_fp[] = { |
| 1064 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 1075 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 1065 ->GetAllocatableDoubleCode(0)}; | 1076 ->GetAllocatableDoubleCode(0)}; |
| 1066 Allocator palloc(parray_gp, 2, parray_fp, 2); | 1077 Allocator palloc(parray_gp, 2, parray_fp, 2); |
| 1067 Allocator ralloc(rarray_gp, 1, rarray_fp, 1); | 1078 Allocator ralloc(rarray_gp, 1, rarray_fp, 1); |
| 1068 RegisterConfig config(palloc, ralloc); | 1079 RegisterConfig config(palloc, ralloc); |
| 1069 | 1080 |
| 1070 for (int which = 0; which < num_params; which++) { | 1081 for (int which = 0; which < num_params; which++) { |
| 1071 Zone zone; | 1082 base::AccountingAllocator allocator; |
| 1083 Zone zone(&allocator); |
| 1072 HandleScope scope(isolate); | 1084 HandleScope scope(isolate); |
| 1073 MachineSignature::Builder builder(&zone, 1, num_params); | 1085 MachineSignature::Builder builder(&zone, 1, num_params); |
| 1074 builder.AddReturn(params[which]); | 1086 builder.AddReturn(params[which]); |
| 1075 for (int j = 0; j < num_params; j++) builder.AddParam(params[j]); | 1087 for (int j = 0; j < num_params; j++) builder.AddParam(params[j]); |
| 1076 MachineSignature* sig = builder.Build(); | 1088 MachineSignature* sig = builder.Build(); |
| 1077 CallDescriptor* desc = config.Create(&zone, sig); | 1089 CallDescriptor* desc = config.Create(&zone, sig); |
| 1078 | 1090 |
| 1079 Handle<Code> select; | 1091 Handle<Code> select; |
| 1080 { | 1092 { |
| 1081 // build the select. | 1093 // build the select. |
| 1082 Zone zone; | 1094 Zone zone(&allocator); |
| 1083 Graph graph(&zone); | 1095 Graph graph(&zone); |
| 1084 RawMachineAssembler raw(isolate, &graph, desc); | 1096 RawMachineAssembler raw(isolate, &graph, desc); |
| 1085 raw.Return(raw.Parameter(which)); | 1097 raw.Return(raw.Parameter(which)); |
| 1086 select = CompileGraph("Compute", desc, &graph, raw.Export()); | 1098 select = CompileGraph("Compute", desc, &graph, raw.Export()); |
| 1087 } | 1099 } |
| 1088 | 1100 |
| 1089 { | 1101 { |
| 1090 // call the select. | 1102 // call the select. |
| 1091 Handle<Code> wrapper = Handle<Code>::null(); | 1103 Handle<Code> wrapper = Handle<Code>::null(); |
| 1092 int32_t expected_ret; | 1104 int32_t expected_ret; |
| 1093 char bytes[kDoubleSize]; | 1105 char bytes[kDoubleSize]; |
| 1094 V8_ALIGNED(8) char output[kDoubleSize]; | 1106 V8_ALIGNED(8) char output[kDoubleSize]; |
| 1095 int expected_size = 0; | 1107 int expected_size = 0; |
| 1096 CSignature0<int32_t> csig; | 1108 CSignature0<int32_t> csig; |
| 1097 { | 1109 { |
| 1098 // Wrap the select code with a callable function that passes constants. | 1110 // Wrap the select code with a callable function that passes constants. |
| 1099 Zone zone; | 1111 Zone zone(&allocator); |
| 1100 Graph graph(&zone); | 1112 Graph graph(&zone); |
| 1101 CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, &csig); | 1113 CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, &csig); |
| 1102 RawMachineAssembler raw(isolate, &graph, cdesc); | 1114 RawMachineAssembler raw(isolate, &graph, cdesc); |
| 1103 Node* target = raw.HeapConstant(select); | 1115 Node* target = raw.HeapConstant(select); |
| 1104 Node** args = zone.NewArray<Node*>(num_params); | 1116 Node** args = zone.NewArray<Node*>(num_params); |
| 1105 int64_t constant = 0x0102030405060708; | 1117 int64_t constant = 0x0102030405060708; |
| 1106 for (int i = 0; i < num_params; i++) { | 1118 for (int i = 0; i < num_params; i++) { |
| 1107 MachineType param_type = sig->GetParam(i); | 1119 MachineType param_type = sig->GetParam(i); |
| 1108 Node* konst = nullptr; | 1120 Node* konst = nullptr; |
| 1109 if (param_type == MachineType::Int32()) { | 1121 if (param_type == MachineType::Int32()) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 ->GetAllocatableDoubleCode(0), | 1194 ->GetAllocatableDoubleCode(0), |
| 1183 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 1195 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 1184 ->GetAllocatableDoubleCode(1)}; | 1196 ->GetAllocatableDoubleCode(1)}; |
| 1185 int rarray_fp[] = { | 1197 int rarray_fp[] = { |
| 1186 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) | 1198 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN) |
| 1187 ->GetAllocatableDoubleCode(0)}; | 1199 ->GetAllocatableDoubleCode(0)}; |
| 1188 Allocator palloc(parray_gp, 2, parray_fp, 2); | 1200 Allocator palloc(parray_gp, 2, parray_fp, 2); |
| 1189 Allocator ralloc(rarray_gp, 1, rarray_fp, 1); | 1201 Allocator ralloc(rarray_gp, 1, rarray_fp, 1); |
| 1190 RegisterConfig config(palloc, ralloc); | 1202 RegisterConfig config(palloc, ralloc); |
| 1191 | 1203 |
| 1192 Zone zone; | 1204 Zone zone(isolate->allocator()); |
| 1193 HandleScope scope(isolate); | 1205 HandleScope scope(isolate); |
| 1194 MachineSignature::Builder builder(&zone, 1, 12); | 1206 MachineSignature::Builder builder(&zone, 1, 12); |
| 1195 builder.AddReturn(MachineType::Int32()); | 1207 builder.AddReturn(MachineType::Int32()); |
| 1196 for (int i = 0; i < 10; i++) { | 1208 for (int i = 0; i < 10; i++) { |
| 1197 builder.AddParam(MachineType::Int32()); | 1209 builder.AddParam(MachineType::Int32()); |
| 1198 } | 1210 } |
| 1199 builder.AddParam(slot_type); | 1211 builder.AddParam(slot_type); |
| 1200 builder.AddParam(MachineType::Pointer()); | 1212 builder.AddParam(MachineType::Pointer()); |
| 1201 MachineSignature* sig = builder.Build(); | 1213 MachineSignature* sig = builder.Build(); |
| 1202 CallDescriptor* desc = config.Create(&zone, sig); | 1214 CallDescriptor* desc = config.Create(&zone, sig); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 TestStackSlot(MachineType::Float32(), magic); | 1258 TestStackSlot(MachineType::Float32(), magic); |
| 1247 } | 1259 } |
| 1248 | 1260 |
| 1249 TEST(RunStackSlotFloat64) { | 1261 TEST(RunStackSlotFloat64) { |
| 1250 double magic = 3456.375; | 1262 double magic = 3456.375; |
| 1251 TestStackSlot(MachineType::Float64(), magic); | 1263 TestStackSlot(MachineType::Float64(), magic); |
| 1252 } | 1264 } |
| 1253 } // namespace compiler | 1265 } // namespace compiler |
| 1254 } // namespace internal | 1266 } // namespace internal |
| 1255 } // namespace v8 | 1267 } // namespace v8 |
| OLD | NEW |