OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <list> |
| 6 |
| 7 #include "test/compiler-unittests/instruction-selector-unittest.h" |
| 8 |
| 9 #include "test/cctest/compiler/instruction-selector-tester.h" |
| 10 |
| 11 namespace v8 { |
| 12 namespace internal { |
| 13 namespace compiler { |
| 14 |
| 15 namespace { |
| 16 |
| 17 typedef Node* (RawMachineAssembler::*Constructor)(Node*, Node*); |
| 18 |
| 19 struct DPI { |
| 20 Constructor constructor; |
| 21 const char* constructor_name; |
| 22 ArchOpcode arch_opcode; |
| 23 }; |
| 24 |
| 25 |
| 26 std::ostream& operator<<(std::ostream& os, const DPI& dpi) { |
| 27 return os << dpi.constructor_name; |
| 28 } |
| 29 |
| 30 |
| 31 // ARM64 Logical instructions. |
| 32 static const DPI kLogicalInstructions[] = { |
| 33 {&RawMachineAssembler::Word32And, "Word32And", kArm64And32}, |
| 34 {&RawMachineAssembler::Word64And, "Word64And", kArm64And}, |
| 35 {&RawMachineAssembler::Word32Or, "Word32Or", kArm64Or32}, |
| 36 {&RawMachineAssembler::Word64Or, "Word64Or", kArm64Or}, |
| 37 {&RawMachineAssembler::Word32Xor, "Word32Xor", kArm64Xor32}, |
| 38 {&RawMachineAssembler::Word64Xor, "Word64Xor", kArm64Xor}}; |
| 39 |
| 40 |
| 41 // ARM64 Arithmetic instructions. |
| 42 static const DPI kAddSubInstructions[] = { |
| 43 {&RawMachineAssembler::Int32Add, "Int32Add", kArm64Add32}, |
| 44 {&RawMachineAssembler::Int64Add, "Int64Add", kArm64Add}, |
| 45 {&RawMachineAssembler::Int32Sub, "Int32Sub", kArm64Sub32}, |
| 46 {&RawMachineAssembler::Int64Sub, "Int64Sub", kArm64Sub}}; |
| 47 |
| 48 |
| 49 // ARM64 Add/Sub immediates. |
| 50 // TODO(all): Test only a subset of the immediates, similar to what we do for |
| 51 // arm. Unit tests should be really fast! |
| 52 class AddSubImmediates V8_FINAL : public std::list<int32_t> { |
| 53 public: |
| 54 AddSubImmediates() { |
| 55 for (int32_t imm12 = 0; imm12 < 4096; ++imm12) { |
| 56 CHECK(Assembler::IsImmAddSub(imm12)); |
| 57 CHECK(Assembler::IsImmAddSub(imm12 << 12)); |
| 58 push_back(imm12); |
| 59 push_back(imm12 << 12); |
| 60 } |
| 61 } |
| 62 }; |
| 63 |
| 64 |
| 65 // ARM64 Mul/Div instructions. |
| 66 static const DPI kMulDivInstructions[] = { |
| 67 {&RawMachineAssembler::Int32Mul, "Int32Mul", kArm64Mul32}, |
| 68 {&RawMachineAssembler::Int64Mul, "Int64Mul", kArm64Mul}, |
| 69 {&RawMachineAssembler::Int32Div, "Int32Div", kArm64Idiv32}, |
| 70 {&RawMachineAssembler::Int64Div, "Int64Div", kArm64Idiv}, |
| 71 {&RawMachineAssembler::Int32UDiv, "Int32UDiv", kArm64Udiv32}, |
| 72 {&RawMachineAssembler::Int64UDiv, "Int64UDiv", kArm64Udiv}}; |
| 73 |
| 74 } // namespace |
| 75 |
| 76 |
| 77 // TODO(all): Use TEST_P, see instruction-selector-arm-unittest.cc. |
| 78 TEST_F(InstructionSelectorTest, LogicalWithParameter) { |
| 79 TRACED_FOREACH(DPI, dpi, kLogicalInstructions) { |
| 80 StreamBuilder m(this, kMachineWord32, kMachineWord32, kMachineWord32); |
| 81 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1))); |
| 82 Stream s = m.Build(); |
| 83 ASSERT_EQ(1U, s.size()); |
| 84 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode()); |
| 85 } |
| 86 } |
| 87 |
| 88 |
| 89 // TODO(all): Use TEST_P, see instruction-selector-arm-unittest.cc. |
| 90 TEST_F(InstructionSelectorTest, AddSubWithParameter) { |
| 91 TRACED_FOREACH(DPI, dpi, kAddSubInstructions) { |
| 92 StreamBuilder m(this, kMachineWord32, kMachineWord32, kMachineWord32); |
| 93 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1))); |
| 94 Stream s = m.Build(); |
| 95 ASSERT_EQ(1U, s.size()); |
| 96 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode()); |
| 97 } |
| 98 } |
| 99 |
| 100 |
| 101 // TODO(all): Use TEST_P, see instruction-selector-arm-unittest.cc. |
| 102 TEST_F(InstructionSelectorTest, AddSubWithImmediate) { |
| 103 AddSubImmediates immediates; |
| 104 TRACED_FOREACH(DPI, dpi, kAddSubInstructions) { |
| 105 for (AddSubImmediates::const_iterator j = immediates.begin(); |
| 106 j != immediates.end(); ++j) { |
| 107 int32_t imm = *j; |
| 108 SCOPED_TRACE(::testing::Message() << "imm = " << imm); |
| 109 StreamBuilder m(this, kMachineWord32, kMachineWord32); |
| 110 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Int32Constant(imm))); |
| 111 Stream s = m.Build(); |
| 112 ASSERT_EQ(1U, s.size()); |
| 113 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode()); |
| 114 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate()); |
| 115 } |
| 116 } |
| 117 } |
| 118 |
| 119 |
| 120 // TODO(all): Use TEST_P, see instruction-selector-arm-unittest.cc. |
| 121 TEST_F(InstructionSelectorTest, MulDivWithParameter) { |
| 122 TRACED_FOREACH(DPI, dpi, kMulDivInstructions) { |
| 123 StreamBuilder m(this, kMachineWord32, kMachineWord32, kMachineWord32); |
| 124 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1))); |
| 125 Stream s = m.Build(); |
| 126 ASSERT_EQ(1U, s.size()); |
| 127 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode()); |
| 128 } |
| 129 } |
| 130 |
| 131 } // namespace compiler |
| 132 } // namespace internal |
| 133 } // namespace v8 |
OLD | NEW |