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

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

Issue 487163004: [turbofan] Add ARM64 tests and fix shift bug (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 | « src/compiler/arm64/instruction-selector-arm64.cc ('k') | 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 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
(...skipping 19 matching lines...) Expand all
30 // ARM64 Logical instructions. 30 // ARM64 Logical instructions.
31 static const DPI kLogicalInstructions[] = { 31 static const DPI kLogicalInstructions[] = {
32 {&RawMachineAssembler::Word32And, "Word32And", kArm64And32, kMachInt32}, 32 {&RawMachineAssembler::Word32And, "Word32And", kArm64And32, kMachInt32},
33 {&RawMachineAssembler::Word64And, "Word64And", kArm64And, kMachInt64}, 33 {&RawMachineAssembler::Word64And, "Word64And", kArm64And, kMachInt64},
34 {&RawMachineAssembler::Word32Or, "Word32Or", kArm64Or32, kMachInt32}, 34 {&RawMachineAssembler::Word32Or, "Word32Or", kArm64Or32, kMachInt32},
35 {&RawMachineAssembler::Word64Or, "Word64Or", kArm64Or, kMachInt64}, 35 {&RawMachineAssembler::Word64Or, "Word64Or", kArm64Or, kMachInt64},
36 {&RawMachineAssembler::Word32Xor, "Word32Xor", kArm64Xor32, kMachInt32}, 36 {&RawMachineAssembler::Word32Xor, "Word32Xor", kArm64Xor32, kMachInt32},
37 {&RawMachineAssembler::Word64Xor, "Word64Xor", kArm64Xor, kMachInt64}}; 37 {&RawMachineAssembler::Word64Xor, "Word64Xor", kArm64Xor, kMachInt64}};
38 38
39 39
40 // ARM64 logical immediates: contiguous set bits, rotated about a power of two
41 // sized block. The block is then duplicated across the word. Below is a random
42 // subset of the 32-bit immediates.
43 static const uint32_t kLogicalImmediates[] = {
44 0x00000002, 0x00000003, 0x00000070, 0x00000080, 0x00000100, 0x000001c0,
45 0x00000300, 0x000007e0, 0x00003ffc, 0x00007fc0, 0x0003c000, 0x0003f000,
46 0x0003ffc0, 0x0003fff8, 0x0007ff00, 0x0007ffe0, 0x000e0000, 0x001e0000,
47 0x001ffffc, 0x003f0000, 0x003f8000, 0x00780000, 0x007fc000, 0x00ff0000,
48 0x01800000, 0x01800180, 0x01f801f8, 0x03fe0000, 0x03ffffc0, 0x03fffffc,
49 0x06000000, 0x07fc0000, 0x07ffc000, 0x07ffffc0, 0x07ffffe0, 0x0ffe0ffe,
50 0x0ffff800, 0x0ffffff0, 0x0fffffff, 0x18001800, 0x1f001f00, 0x1f801f80,
51 0x30303030, 0x3ff03ff0, 0x3ff83ff8, 0x3fff0000, 0x3fff8000, 0x3fffffc0,
52 0x70007000, 0x7f7f7f7f, 0x7fc00000, 0x7fffffc0, 0x8000001f, 0x800001ff,
53 0x81818181, 0x9fff9fff, 0xc00007ff, 0xc0ffffff, 0xdddddddd, 0xe00001ff,
54 0xe00003ff, 0xe007ffff, 0xefffefff, 0xf000003f, 0xf001f001, 0xf3fff3ff,
55 0xf800001f, 0xf80fffff, 0xf87ff87f, 0xfbfbfbfb, 0xfc00001f, 0xfc0000ff,
56 0xfc0001ff, 0xfc03fc03, 0xfe0001ff, 0xff000001, 0xff03ff03, 0xff800000,
57 0xff800fff, 0xff801fff, 0xff87ffff, 0xffc0003f, 0xffc007ff, 0xffcfffcf,
58 0xffe00003, 0xffe1ffff, 0xfff0001f, 0xfff07fff, 0xfff80007, 0xfff87fff,
59 0xfffc00ff, 0xfffe07ff, 0xffff00ff, 0xffffc001, 0xfffff007, 0xfffff3ff,
60 0xfffff807, 0xfffff9ff, 0xfffffc0f, 0xfffffeff};
61
62
40 // ARM64 Arithmetic instructions. 63 // ARM64 Arithmetic instructions.
41 static const DPI kAddSubInstructions[] = { 64 static const DPI kAddSubInstructions[] = {
42 {&RawMachineAssembler::Int32Add, "Int32Add", kArm64Add32, kMachInt32}, 65 {&RawMachineAssembler::Int32Add, "Int32Add", kArm64Add32, kMachInt32},
43 {&RawMachineAssembler::Int64Add, "Int64Add", kArm64Add, kMachInt64}, 66 {&RawMachineAssembler::Int64Add, "Int64Add", kArm64Add, kMachInt64},
44 {&RawMachineAssembler::Int32Sub, "Int32Sub", kArm64Sub32, kMachInt32}, 67 {&RawMachineAssembler::Int32Sub, "Int32Sub", kArm64Sub32, kMachInt32},
45 {&RawMachineAssembler::Int64Sub, "Int64Sub", kArm64Sub, kMachInt64}}; 68 {&RawMachineAssembler::Int64Sub, "Int64Sub", kArm64Sub, kMachInt64}};
46 69
47 70
48 // ARM64 Add/Sub immediates: 12-bit immediate optionally shifted by 12. 71 // ARM64 Add/Sub immediates: 12-bit immediate optionally shifted by 12.
49 // Below is a combination of a random subset and some edge values. 72 // Below is a combination of a random subset and some edge values.
50 static const int32_t kAddSubImmediates[] = { 73 static const int32_t kAddSubImmediates[] = {
51 0, 1, 69, 493, 599, 701, 719, 74 0, 1, 69, 493, 599, 701, 719,
52 768, 818, 842, 945, 1246, 1286, 1429, 75 768, 818, 842, 945, 1246, 1286, 1429,
53 1669, 2171, 2179, 2182, 2254, 2334, 2338, 76 1669, 2171, 2179, 2182, 2254, 2334, 2338,
54 2343, 2396, 2449, 2610, 2732, 2855, 2876, 77 2343, 2396, 2449, 2610, 2732, 2855, 2876,
55 2944, 3377, 3458, 3475, 3476, 3540, 3574, 78 2944, 3377, 3458, 3475, 3476, 3540, 3574,
56 3601, 3813, 3871, 3917, 4095, 4096, 16384, 79 3601, 3813, 3871, 3917, 4095, 4096, 16384,
57 364544, 462848, 970752, 1523712, 1863680, 2363392, 3219456, 80 364544, 462848, 970752, 1523712, 1863680, 2363392, 3219456,
58 3280896, 4247552, 4526080, 4575232, 4960256, 5505024, 5894144, 81 3280896, 4247552, 4526080, 4575232, 4960256, 5505024, 5894144,
59 6004736, 6193152, 6385664, 6795264, 7114752, 7233536, 7348224, 82 6004736, 6193152, 6385664, 6795264, 7114752, 7233536, 7348224,
60 7499776, 7573504, 7729152, 8634368, 8937472, 9465856, 10354688, 83 7499776, 7573504, 7729152, 8634368, 8937472, 9465856, 10354688,
61 10682368, 11059200, 11460608, 13168640, 13176832, 14336000, 15028224, 84 10682368, 11059200, 11460608, 13168640, 13176832, 14336000, 15028224,
62 15597568, 15892480, 16773120}; 85 15597568, 15892480, 16773120};
63 86
64 87
88 // ARM64 shift instructions.
89 static const DPI kShiftInstructions[] = {
90 {&RawMachineAssembler::Word32Shl, "Word32Shl", kArm64Shl32, kMachInt32},
91 {&RawMachineAssembler::Word64Shl, "Word64Shl", kArm64Shl, kMachInt64},
92 {&RawMachineAssembler::Word32Shr, "Word32Shr", kArm64Shr32, kMachInt32},
93 {&RawMachineAssembler::Word64Shr, "Word64Shr", kArm64Shr, kMachInt64},
94 {&RawMachineAssembler::Word32Sar, "Word32Sar", kArm64Sar32, kMachInt32},
95 {&RawMachineAssembler::Word64Sar, "Word64Sar", kArm64Sar, kMachInt64},
96 {&RawMachineAssembler::Word32Ror, "Word32Ror", kArm64Ror32, kMachInt32},
97 {&RawMachineAssembler::Word64Ror, "Word64Ror", kArm64Ror, kMachInt64}};
98
99
65 // ARM64 Mul/Div instructions. 100 // ARM64 Mul/Div instructions.
66 static const DPI kMulDivInstructions[] = { 101 static const DPI kMulDivInstructions[] = {
67 {&RawMachineAssembler::Int32Mul, "Int32Mul", kArm64Mul32, kMachInt32}, 102 {&RawMachineAssembler::Int32Mul, "Int32Mul", kArm64Mul32, kMachInt32},
68 {&RawMachineAssembler::Int64Mul, "Int64Mul", kArm64Mul, kMachInt64}, 103 {&RawMachineAssembler::Int64Mul, "Int64Mul", kArm64Mul, kMachInt64},
69 {&RawMachineAssembler::Int32Div, "Int32Div", kArm64Idiv32, kMachInt32}, 104 {&RawMachineAssembler::Int32Div, "Int32Div", kArm64Idiv32, kMachInt32},
70 {&RawMachineAssembler::Int64Div, "Int64Div", kArm64Idiv, kMachInt64}, 105 {&RawMachineAssembler::Int64Div, "Int64Div", kArm64Idiv, kMachInt64},
71 {&RawMachineAssembler::Int32UDiv, "Int32UDiv", kArm64Udiv32, kMachInt32}, 106 {&RawMachineAssembler::Int32UDiv, "Int32UDiv", kArm64Udiv32, kMachInt32},
72 {&RawMachineAssembler::Int64UDiv, "Int64UDiv", kArm64Udiv, kMachInt64}}; 107 {&RawMachineAssembler::Int64UDiv, "Int64UDiv", kArm64Udiv, kMachInt64}};
73 108
74 } // namespace 109 } // namespace
(...skipping 11 matching lines...) Expand all
86 StreamBuilder m(this, type, type, type); 121 StreamBuilder m(this, type, type, type);
87 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1))); 122 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1)));
88 Stream s = m.Build(); 123 Stream s = m.Build();
89 ASSERT_EQ(1U, s.size()); 124 ASSERT_EQ(1U, s.size());
90 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode()); 125 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
91 EXPECT_EQ(2U, s[0]->InputCount()); 126 EXPECT_EQ(2U, s[0]->InputCount());
92 EXPECT_EQ(1U, s[0]->OutputCount()); 127 EXPECT_EQ(1U, s[0]->OutputCount());
93 } 128 }
94 129
95 130
96 // TODO(all): add immediate tests. 131 TEST_P(InstructionSelectorLogicalTest, Immediate) {
132 const DPI dpi = GetParam();
133 const MachineType type = dpi.machine_type;
134 // TODO(all): Add support for testing 64-bit immediates.
135 if (type == kMachInt32) {
136 // Immediate on the right.
137 TRACED_FOREACH(uint32_t, imm, kLogicalImmediates) {
138 StreamBuilder m(this, type, type);
139 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Int32Constant(imm)));
140 Stream s = m.Build();
141 ASSERT_EQ(1U, s.size());
142 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
143 ASSERT_EQ(2U, s[0]->InputCount());
144 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate());
145 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1)));
146 EXPECT_EQ(1U, s[0]->OutputCount());
147 }
148
149 // Immediate on the left; all logical ops should commute.
150 TRACED_FOREACH(uint32_t, imm, kLogicalImmediates) {
151 StreamBuilder m(this, type, type);
152 m.Return((m.*dpi.constructor)(m.Int32Constant(imm), m.Parameter(0)));
153 Stream s = m.Build();
154 ASSERT_EQ(1U, s.size());
155 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
156 ASSERT_EQ(2U, s[0]->InputCount());
157 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate());
158 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1)));
159 EXPECT_EQ(1U, s[0]->OutputCount());
160 }
161 }
162 }
97 163
98 164
99 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorLogicalTest, 165 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorLogicalTest,
100 ::testing::ValuesIn(kLogicalInstructions)); 166 ::testing::ValuesIn(kLogicalInstructions));
101 167
102 168
103 // ----------------------------------------------------------------------------- 169 // -----------------------------------------------------------------------------
104 // Add and Sub instructions. 170 // Add and Sub instructions.
105 171
106 typedef InstructionSelectorTestWithParam<DPI> InstructionSelectorAddSubTest; 172 typedef InstructionSelectorTestWithParam<DPI> InstructionSelectorAddSubTest;
(...skipping 26 matching lines...) Expand all
133 EXPECT_EQ(1U, s[0]->OutputCount()); 199 EXPECT_EQ(1U, s[0]->OutputCount());
134 } 200 }
135 } 201 }
136 202
137 203
138 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorAddSubTest, 204 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorAddSubTest,
139 ::testing::ValuesIn(kAddSubInstructions)); 205 ::testing::ValuesIn(kAddSubInstructions));
140 206
141 207
142 // ----------------------------------------------------------------------------- 208 // -----------------------------------------------------------------------------
209 // Shift instructions.
210
211
212 typedef InstructionSelectorTestWithParam<DPI> InstructionSelectorShiftTest;
213
214 TEST_P(InstructionSelectorShiftTest, Parameter) {
215 const DPI dpi = GetParam();
216 const MachineType type = dpi.machine_type;
217 StreamBuilder m(this, type, type, type);
218 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1)));
219 Stream s = m.Build();
220 ASSERT_EQ(1U, s.size());
221 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
222 EXPECT_EQ(2U, s[0]->InputCount());
223 EXPECT_EQ(1U, s[0]->OutputCount());
224 }
225
226
227 TEST_P(InstructionSelectorShiftTest, Immediate) {
228 const DPI dpi = GetParam();
229 const MachineType type = dpi.machine_type;
230 TRACED_FORRANGE(int32_t, imm, 0, (ElementSizeOf(type) * 8) - 1) {
231 StreamBuilder m(this, type, type);
232 m.Return((m.*dpi.constructor)(m.Parameter(0), m.Int32Constant(imm)));
233 Stream s = m.Build();
234 ASSERT_EQ(1U, s.size());
235 EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
236 EXPECT_EQ(2U, s[0]->InputCount());
237 EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate());
238 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1)));
239 EXPECT_EQ(1U, s[0]->OutputCount());
240 }
241 }
242
243
244 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorShiftTest,
245 ::testing::ValuesIn(kShiftInstructions));
246
247
248 // -----------------------------------------------------------------------------
143 // Mul and Div instructions. 249 // Mul and Div instructions.
144 250
145 251
146 typedef InstructionSelectorTestWithParam<DPI> InstructionSelectorMulDivTest; 252 typedef InstructionSelectorTestWithParam<DPI> InstructionSelectorMulDivTest;
147 253
148 254
149 TEST_P(InstructionSelectorMulDivTest, Parameter) { 255 TEST_P(InstructionSelectorMulDivTest, Parameter) {
150 const DPI dpi = GetParam(); 256 const DPI dpi = GetParam();
151 const MachineType type = dpi.machine_type; 257 const MachineType type = dpi.machine_type;
152 StreamBuilder m(this, type, type, type); 258 StreamBuilder m(this, type, type, type);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 StreamBuilder m(this, kMachInt32, kMachInt64); 294 StreamBuilder m(this, kMachInt32, kMachInt64);
189 m.Return(m.TruncateInt64ToInt32(m.Parameter(0))); 295 m.Return(m.TruncateInt64ToInt32(m.Parameter(0)));
190 Stream s = m.Build(); 296 Stream s = m.Build();
191 ASSERT_EQ(1U, s.size()); 297 ASSERT_EQ(1U, s.size());
192 EXPECT_EQ(kArm64Mov32, s[0]->arch_opcode()); 298 EXPECT_EQ(kArm64Mov32, s[0]->arch_opcode());
193 } 299 }
194 300
195 } // namespace compiler 301 } // namespace compiler
196 } // namespace internal 302 } // namespace internal
197 } // namespace v8 303 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/arm64/instruction-selector-arm64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698