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

Side by Side Diff: test/compiler-unittests/arm64/instruction-selector-arm64-unittest.cc

Issue 475823002: ARM64: Refactor instruction selection unit tests. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <list> 5 #include <list>
6 6
7 #include "test/compiler-unittests/instruction-selector-unittest.h" 7 #include "test/compiler-unittests/instruction-selector-unittest.h"
8 8
9 #include "test/cctest/compiler/instruction-selector-tester.h" 9 #include "test/cctest/compiler/instruction-selector-tester.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 namespace compiler { 13 namespace compiler {
14 14
15 namespace { 15 namespace {
16 16
17 typedef Node* (RawMachineAssembler::*Constructor)(Node*, Node*); 17 typedef Node* (RawMachineAssembler::*Constructor)(Node*, Node*);
18 18
19 struct DPI { 19 struct DPI {
20 Constructor constructor; 20 Constructor constructor;
21 const char* constructor_name; 21 const char* constructor_name;
22 ArchOpcode arch_opcode; 22 ArchOpcode arch_opcode;
23 MachineType machine_type;
23 }; 24 };
24 25
25 26
26 std::ostream& operator<<(std::ostream& os, const DPI& dpi) { 27 std::ostream& operator<<(std::ostream& os, const DPI& dpi) {
27 return os << dpi.constructor_name; 28 return os << dpi.constructor_name;
28 } 29 }
29 30
30 31
31 // ARM64 Logical instructions. 32 // ARM64 Logical instructions.
32 static const DPI kLogicalInstructions[] = { 33 static const DPI kLogicalInstructions[] = {
33 {&RawMachineAssembler::Word32And, "Word32And", kArm64And32}, 34 {&RawMachineAssembler::Word32And, "Word32And", kArm64And32, kMachInt32},
34 {&RawMachineAssembler::Word64And, "Word64And", kArm64And}, 35 {&RawMachineAssembler::Word64And, "Word64And", kArm64And, kMachInt64},
35 {&RawMachineAssembler::Word32Or, "Word32Or", kArm64Or32}, 36 {&RawMachineAssembler::Word32Or, "Word32Or", kArm64Or32, kMachInt32},
36 {&RawMachineAssembler::Word64Or, "Word64Or", kArm64Or}, 37 {&RawMachineAssembler::Word64Or, "Word64Or", kArm64Or, kMachInt64},
37 {&RawMachineAssembler::Word32Xor, "Word32Xor", kArm64Xor32}, 38 {&RawMachineAssembler::Word32Xor, "Word32Xor", kArm64Xor32, kMachInt32},
38 {&RawMachineAssembler::Word64Xor, "Word64Xor", kArm64Xor}}; 39 {&RawMachineAssembler::Word64Xor, "Word64Xor", kArm64Xor, kMachInt64}};
39 40
40 41
41 // ARM64 Arithmetic instructions. 42 // ARM64 Arithmetic instructions.
42 static const DPI kAddSubInstructions[] = { 43 static const DPI kAddSubInstructions[] = {
43 {&RawMachineAssembler::Int32Add, "Int32Add", kArm64Add32}, 44 {&RawMachineAssembler::Int32Add, "Int32Add", kArm64Add32, kMachInt32},
44 {&RawMachineAssembler::Int64Add, "Int64Add", kArm64Add}, 45 {&RawMachineAssembler::Int64Add, "Int64Add", kArm64Add, kMachInt64},
45 {&RawMachineAssembler::Int32Sub, "Int32Sub", kArm64Sub32}, 46 {&RawMachineAssembler::Int32Sub, "Int32Sub", kArm64Sub32, kMachInt32},
46 {&RawMachineAssembler::Int64Sub, "Int64Sub", kArm64Sub}}; 47 {&RawMachineAssembler::Int64Sub, "Int64Sub", kArm64Sub, kMachInt64}};
47 48
48 49
49 // ARM64 Add/Sub immediates. 50 // ARM64 Add/Sub immediates: 12-bit immediate optionally shifted by 12.
50 // TODO(all): Test only a subset of the immediates, similar to what we do for 51 // Below is a combination of a random subset and some edge values.
51 // arm. Unit tests should be really fast! 52 static const int32_t kAddSubImmediates[] = {
52 class AddSubImmediates V8_FINAL : public std::list<int32_t> { 53 0, 1, 69, 493, 599, 701, 719,
53 public: 54 768, 818, 842, 945, 1246, 1286, 1429,
54 AddSubImmediates() { 55 1669, 2171, 2179, 2182, 2254, 2334, 2338,
55 for (int32_t imm12 = 0; imm12 < 4096; ++imm12) { 56 2343, 2396, 2449, 2610, 2732, 2855, 2876,
56 CHECK(Assembler::IsImmAddSub(imm12)); 57 2944, 3377, 3458, 3475, 3476, 3540, 3574,
57 CHECK(Assembler::IsImmAddSub(imm12 << 12)); 58 3601, 3813, 3871, 3917, 4095, 4096, 16384,
58 push_back(imm12); 59 364544, 462848, 970752, 1523712, 1863680, 2363392, 3219456,
59 push_back(imm12 << 12); 60 3280896, 4247552, 4526080, 4575232, 4960256, 5505024, 5894144,
60 } 61 6004736, 6193152, 6385664, 6795264, 7114752, 7233536, 7348224,
61 } 62 7499776, 7573504, 7729152, 8634368, 8937472, 9465856, 10354688,
62 }; 63 10682368, 11059200, 11460608, 13168640, 13176832, 14336000, 15028224,
64 15597568, 15892480, 16773120};
63 65
64 66
65 // ARM64 Mul/Div instructions. 67 // ARM64 Mul/Div instructions.
66 static const DPI kMulDivInstructions[] = { 68 static const DPI kMulDivInstructions[] = {
67 {&RawMachineAssembler::Int32Mul, "Int32Mul", kArm64Mul32}, 69 {&RawMachineAssembler::Int32Mul, "Int32Mul", kArm64Mul32, kMachInt32},
68 {&RawMachineAssembler::Int64Mul, "Int64Mul", kArm64Mul}, 70 {&RawMachineAssembler::Int64Mul, "Int64Mul", kArm64Mul, kMachInt64},
69 {&RawMachineAssembler::Int32Div, "Int32Div", kArm64Idiv32}, 71 {&RawMachineAssembler::Int32Div, "Int32Div", kArm64Idiv32, kMachInt32},
70 {&RawMachineAssembler::Int64Div, "Int64Div", kArm64Idiv}, 72 {&RawMachineAssembler::Int64Div, "Int64Div", kArm64Idiv, kMachInt64},
71 {&RawMachineAssembler::Int32UDiv, "Int32UDiv", kArm64Udiv32}, 73 {&RawMachineAssembler::Int32UDiv, "Int32UDiv", kArm64Udiv32, kMachInt32},
72 {&RawMachineAssembler::Int64UDiv, "Int64UDiv", kArm64Udiv}}; 74 {&RawMachineAssembler::Int64UDiv, "Int64UDiv", kArm64Udiv, kMachInt64}};
73 75
74 } // namespace 76 } // namespace
75 77
76 78
77 // TODO(all): Use TEST_P, see instruction-selector-arm-unittest.cc. 79 // -----------------------------------------------------------------------------
78 TEST_F(InstructionSelectorTest, LogicalWithParameter) { 80 // Logical instructions.
79 TRACED_FOREACH(DPI, dpi, kLogicalInstructions) { 81
80 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); 82 typedef InstructionSelectorTestWithParam<DPI> LogicalTest;
Benedikt Meurer 2014/08/14 17:58:31 s/LogicalTest/InstructionSelectorLogicalTest/ See
Rodolph Perfetta (ARM) 2014/08/15 10:06:56 Done.
81 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1))); 83
84
85 TEST_P(LogicalTest, Parameter) {
Benedikt Meurer 2014/08/14 17:58:31 Test names must be globally unique, so please alwa
Rodolph Perfetta 2014/08/14 18:29:44 My understanding was that the name will be concate
Rodolph Perfetta (ARM) 2014/08/15 10:06:56 Acknowledged.
86 const DPI dpi = GetParam();
87 const MachineType type = dpi.machine_type;
88 StreamBuilder m(this, type, type, type);
89 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1)));
90 Stream s = m.Build();
91 ASSERT_EQ(1U, s.size());
92 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
93 EXPECT_EQ(2U, s[0]->InputCount());
94 EXPECT_EQ(1U, s[0]->OutputCount());
95 }
96
97
98 // TODO(all): add immediate tests.
99
100 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, LogicalTest,
101 ::testing::ValuesIn(kLogicalInstructions));
102
103
104 // -----------------------------------------------------------------------------
105 // Add and Sub instructions.
106
107 typedef InstructionSelectorTestWithParam<DPI> AddSubTest;
108
109
110 TEST_P(AddSubTest, Parameter) {
111 const DPI dpi = GetParam();
112 const MachineType type = dpi.machine_type;
113 StreamBuilder m(this, type, type, type);
114 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1)));
115 Stream s = m.Build();
116 ASSERT_EQ(1U, s.size());
117 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
118 EXPECT_EQ(2U, s[0]->InputCount());
119 EXPECT_EQ(1U, s[0]->OutputCount());
120 }
121
122
123 TEST_P(AddSubTest, Immediate) {
124 const DPI dpi = GetParam();
125 const MachineType type = dpi.machine_type;
126 TRACED_FOREACH(int32_t, imm, kAddSubImmediates) {
127 StreamBuilder m(this, type, type);
128 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Int32Constant(imm)));
82 Stream s = m.Build(); 129 Stream s = m.Build();
83 ASSERT_EQ(1U, s.size()); 130 ASSERT_EQ(1U, s.size());
84 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode()); 131 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
132 ASSERT_EQ(2U, s[0]->InputCount());
133 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate());
134 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1)));
135 EXPECT_EQ(1U, s[0]->OutputCount());
85 } 136 }
86 } 137 }
87 138
88 139
89 // TODO(all): Use TEST_P, see instruction-selector-arm-unittest.cc. 140 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, AddSubTest,
90 TEST_F(InstructionSelectorTest, AddSubWithParameter) { 141 ::testing::ValuesIn(kAddSubInstructions));
91 TRACED_FOREACH(DPI, dpi, kAddSubInstructions) { 142
92 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); 143
93 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1))); 144 // -----------------------------------------------------------------------------
94 Stream s = m.Build(); 145 // Mul and Div instructions.
95 ASSERT_EQ(1U, s.size()); 146
96 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode()); 147 typedef InstructionSelectorTestWithParam<DPI> MulDivTest;
97 } 148
149
150 TEST_P(MulDivTest, Parameter) {
151 const DPI dpi = GetParam();
152 const MachineType type = dpi.machine_type;
153 StreamBuilder m(this, type, type, type);
154 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1)));
155 Stream s = m.Build();
156 ASSERT_EQ(1U, s.size());
157 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
158 EXPECT_EQ(2U, s[0]->InputCount());
159 EXPECT_EQ(1U, s[0]->OutputCount());
98 } 160 }
99 161
100 162
101 // TODO(all): Use TEST_P, see instruction-selector-arm-unittest.cc. 163 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, MulDivTest,
102 TEST_F(InstructionSelectorTest, AddSubWithImmediate) { 164 ::testing::ValuesIn(kMulDivInstructions));
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, kMachInt32, kMachInt32);
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, kMachInt32, kMachInt32, kMachInt32);
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 165
131 } // namespace compiler 166 } // namespace compiler
132 } // namespace internal 167 } // namespace internal
133 } // namespace v8 168 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698