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 "src/v8.h" | 5 #include "src/v8.h" |
6 #include "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
7 | 7 |
8 #include "src/base/utils/random-number-generator.h" | 8 #include "src/base/utils/random-number-generator.h" |
9 #include "src/compiler/structured-machine-assembler.h" | 9 #include "src/compiler/structured-machine-assembler.h" |
10 #include "test/cctest/compiler/codegen-tester.h" | 10 #include "test/cctest/compiler/codegen-tester.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 Variable v1 = m.NewVariable(m.Int32Constant(constant)); | 44 Variable v1 = m.NewVariable(m.Int32Constant(constant)); |
45 Variable v2 = m.NewVariable(v1.Get()); | 45 Variable v2 = m.NewVariable(v1.Get()); |
46 m.Return(v2.Get()); | 46 m.Return(v2.Get()); |
47 | 47 |
48 CHECK_EQ(constant, m.Call()); | 48 CHECK_EQ(constant, m.Call()); |
49 } | 49 } |
50 | 50 |
51 | 51 |
52 TEST(RunSimpleIf) { | 52 TEST(RunSimpleIf) { |
53 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 53 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
54 | 54 |
55 int32_t constant = 0xc4a3e3a6; | 55 int32_t constant = 0xc4a3e3a6; |
56 { | 56 { |
57 IfBuilder cond(&m); | 57 IfBuilder cond(&m); |
58 cond.If(m.Parameter(0)).Then(); | 58 cond.If(m.Parameter(0)).Then(); |
59 m.Return(m.Int32Constant(constant)); | 59 m.Return(m.Int32Constant(constant)); |
60 } | 60 } |
61 m.Return(m.Word32Not(m.Int32Constant(constant))); | 61 m.Return(m.Word32Not(m.Int32Constant(constant))); |
62 | 62 |
63 CHECK_EQ(~constant, m.Call(0)); | 63 CHECK_EQ(~constant, m.Call(0)); |
64 CHECK_EQ(constant, m.Call(1)); | 64 CHECK_EQ(constant, m.Call(1)); |
65 } | 65 } |
66 | 66 |
67 | 67 |
68 TEST(RunSimpleIfVariable) { | 68 TEST(RunSimpleIfVariable) { |
69 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 69 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
70 | 70 |
71 int32_t constant = 0xdb6f20c2; | 71 int32_t constant = 0xdb6f20c2; |
72 Variable var = m.NewVariable(m.Int32Constant(constant)); | 72 Variable var = m.NewVariable(m.Int32Constant(constant)); |
73 { | 73 { |
74 IfBuilder cond(&m); | 74 IfBuilder cond(&m); |
75 cond.If(m.Parameter(0)).Then(); | 75 cond.If(m.Parameter(0)).Then(); |
76 var.Set(m.Word32Not(var.Get())); | 76 var.Set(m.Word32Not(var.Get())); |
77 } | 77 } |
78 m.Return(var.Get()); | 78 m.Return(var.Get()); |
79 | 79 |
80 CHECK_EQ(constant, m.Call(0)); | 80 CHECK_EQ(constant, m.Call(0)); |
81 CHECK_EQ(~constant, m.Call(1)); | 81 CHECK_EQ(~constant, m.Call(1)); |
82 } | 82 } |
83 | 83 |
84 | 84 |
85 TEST(RunSimpleElse) { | 85 TEST(RunSimpleElse) { |
86 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 86 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
87 | 87 |
88 int32_t constant = 0xfc5eadf4; | 88 int32_t constant = 0xfc5eadf4; |
89 { | 89 { |
90 IfBuilder cond(&m); | 90 IfBuilder cond(&m); |
91 cond.If(m.Parameter(0)).Else(); | 91 cond.If(m.Parameter(0)).Else(); |
92 m.Return(m.Int32Constant(constant)); | 92 m.Return(m.Int32Constant(constant)); |
93 } | 93 } |
94 m.Return(m.Word32Not(m.Int32Constant(constant))); | 94 m.Return(m.Word32Not(m.Int32Constant(constant))); |
95 | 95 |
96 CHECK_EQ(constant, m.Call(0)); | 96 CHECK_EQ(constant, m.Call(0)); |
97 CHECK_EQ(~constant, m.Call(1)); | 97 CHECK_EQ(~constant, m.Call(1)); |
98 } | 98 } |
99 | 99 |
100 | 100 |
101 TEST(RunSimpleIfElse) { | 101 TEST(RunSimpleIfElse) { |
102 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 102 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
103 | 103 |
104 int32_t constant = 0xaa9c8cd3; | 104 int32_t constant = 0xaa9c8cd3; |
105 { | 105 { |
106 IfBuilder cond(&m); | 106 IfBuilder cond(&m); |
107 cond.If(m.Parameter(0)).Then(); | 107 cond.If(m.Parameter(0)).Then(); |
108 m.Return(m.Int32Constant(constant)); | 108 m.Return(m.Int32Constant(constant)); |
109 cond.Else(); | 109 cond.Else(); |
110 m.Return(m.Word32Not(m.Int32Constant(constant))); | 110 m.Return(m.Word32Not(m.Int32Constant(constant))); |
111 } | 111 } |
112 | 112 |
113 CHECK_EQ(~constant, m.Call(0)); | 113 CHECK_EQ(~constant, m.Call(0)); |
114 CHECK_EQ(constant, m.Call(1)); | 114 CHECK_EQ(constant, m.Call(1)); |
115 } | 115 } |
116 | 116 |
117 | 117 |
118 TEST(RunSimpleIfElseVariable) { | 118 TEST(RunSimpleIfElseVariable) { |
119 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 119 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
120 | 120 |
121 int32_t constant = 0x67b6f39c; | 121 int32_t constant = 0x67b6f39c; |
122 Variable var = m.NewVariable(m.Int32Constant(constant)); | 122 Variable var = m.NewVariable(m.Int32Constant(constant)); |
123 { | 123 { |
124 IfBuilder cond(&m); | 124 IfBuilder cond(&m); |
125 cond.If(m.Parameter(0)).Then(); | 125 cond.If(m.Parameter(0)).Then(); |
126 var.Set(m.Word32Not(m.Word32Not(var.Get()))); | 126 var.Set(m.Word32Not(m.Word32Not(var.Get()))); |
127 cond.Else(); | 127 cond.Else(); |
128 var.Set(m.Word32Not(var.Get())); | 128 var.Set(m.Word32Not(var.Get())); |
129 } | 129 } |
130 m.Return(var.Get()); | 130 m.Return(var.Get()); |
131 | 131 |
132 CHECK_EQ(~constant, m.Call(0)); | 132 CHECK_EQ(~constant, m.Call(0)); |
133 CHECK_EQ(constant, m.Call(1)); | 133 CHECK_EQ(constant, m.Call(1)); |
134 } | 134 } |
135 | 135 |
136 | 136 |
137 TEST(RunSimpleIfNoThenElse) { | 137 TEST(RunSimpleIfNoThenElse) { |
138 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 138 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
139 | 139 |
140 int32_t constant = 0xd5e550ed; | 140 int32_t constant = 0xd5e550ed; |
141 { | 141 { |
142 IfBuilder cond(&m); | 142 IfBuilder cond(&m); |
143 cond.If(m.Parameter(0)); | 143 cond.If(m.Parameter(0)); |
144 } | 144 } |
145 m.Return(m.Int32Constant(constant)); | 145 m.Return(m.Int32Constant(constant)); |
146 | 146 |
147 CHECK_EQ(constant, m.Call(0)); | 147 CHECK_EQ(constant, m.Call(0)); |
148 CHECK_EQ(constant, m.Call(1)); | 148 CHECK_EQ(constant, m.Call(1)); |
149 } | 149 } |
150 | 150 |
151 | 151 |
152 TEST(RunSimpleConjunctionVariable) { | 152 TEST(RunSimpleConjunctionVariable) { |
153 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 153 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
154 | 154 |
155 int32_t constant = 0xf8fb9ec6; | 155 int32_t constant = 0xf8fb9ec6; |
156 Variable var = m.NewVariable(m.Int32Constant(constant)); | 156 Variable var = m.NewVariable(m.Int32Constant(constant)); |
157 { | 157 { |
158 IfBuilder cond(&m); | 158 IfBuilder cond(&m); |
159 cond.If(m.Int32Constant(1)).And(); | 159 cond.If(m.Int32Constant(1)).And(); |
160 var.Set(m.Word32Not(var.Get())); | 160 var.Set(m.Word32Not(var.Get())); |
161 cond.If(m.Parameter(0)).Then(); | 161 cond.If(m.Parameter(0)).Then(); |
162 var.Set(m.Word32Not(m.Word32Not(var.Get()))); | 162 var.Set(m.Word32Not(m.Word32Not(var.Get()))); |
163 cond.Else(); | 163 cond.Else(); |
164 var.Set(m.Word32Not(var.Get())); | 164 var.Set(m.Word32Not(var.Get())); |
165 } | 165 } |
166 m.Return(var.Get()); | 166 m.Return(var.Get()); |
167 | 167 |
168 CHECK_EQ(constant, m.Call(0)); | 168 CHECK_EQ(constant, m.Call(0)); |
169 CHECK_EQ(~constant, m.Call(1)); | 169 CHECK_EQ(~constant, m.Call(1)); |
170 } | 170 } |
171 | 171 |
172 | 172 |
173 TEST(RunSimpleDisjunctionVariable) { | 173 TEST(RunSimpleDisjunctionVariable) { |
174 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 174 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
175 | 175 |
176 int32_t constant = 0x118f6ffc; | 176 int32_t constant = 0x118f6ffc; |
177 Variable var = m.NewVariable(m.Int32Constant(constant)); | 177 Variable var = m.NewVariable(m.Int32Constant(constant)); |
178 { | 178 { |
179 IfBuilder cond(&m); | 179 IfBuilder cond(&m); |
180 cond.If(m.Int32Constant(0)).Or(); | 180 cond.If(m.Int32Constant(0)).Or(); |
181 var.Set(m.Word32Not(var.Get())); | 181 var.Set(m.Word32Not(var.Get())); |
182 cond.If(m.Parameter(0)).Then(); | 182 cond.If(m.Parameter(0)).Then(); |
183 var.Set(m.Word32Not(m.Word32Not(var.Get()))); | 183 var.Set(m.Word32Not(m.Word32Not(var.Get()))); |
184 cond.Else(); | 184 cond.Else(); |
185 var.Set(m.Word32Not(var.Get())); | 185 var.Set(m.Word32Not(var.Get())); |
186 } | 186 } |
187 m.Return(var.Get()); | 187 m.Return(var.Get()); |
188 | 188 |
189 CHECK_EQ(constant, m.Call(0)); | 189 CHECK_EQ(constant, m.Call(0)); |
190 CHECK_EQ(~constant, m.Call(1)); | 190 CHECK_EQ(~constant, m.Call(1)); |
191 } | 191 } |
192 | 192 |
193 | 193 |
194 TEST(RunIfElse) { | 194 TEST(RunIfElse) { |
195 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 195 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
196 | 196 |
197 { | 197 { |
198 IfBuilder cond(&m); | 198 IfBuilder cond(&m); |
199 bool first = true; | 199 bool first = true; |
200 FOR_INT32_INPUTS(i) { | 200 FOR_INT32_INPUTS(i) { |
201 Node* c = m.Int32Constant(*i); | 201 Node* c = m.Int32Constant(*i); |
202 if (first) { | 202 if (first) { |
203 cond.If(m.Word32Equal(m.Parameter(0), c)).Then(); | 203 cond.If(m.Word32Equal(m.Parameter(0), c)).Then(); |
204 m.Return(c); | 204 m.Return(c); |
205 first = false; | 205 first = false; |
(...skipping 12 matching lines...) Expand all Loading... |
218 | 218 |
219 enum IfBuilderBranchType { kSkipBranch, kBranchFallsThrough, kBranchReturns }; | 219 enum IfBuilderBranchType { kSkipBranch, kBranchFallsThrough, kBranchReturns }; |
220 | 220 |
221 | 221 |
222 static IfBuilderBranchType all_branch_types[] = { | 222 static IfBuilderBranchType all_branch_types[] = { |
223 kSkipBranch, kBranchFallsThrough, kBranchReturns}; | 223 kSkipBranch, kBranchFallsThrough, kBranchReturns}; |
224 | 224 |
225 | 225 |
226 static void RunIfBuilderDisjunction(size_t max, IfBuilderBranchType then_type, | 226 static void RunIfBuilderDisjunction(size_t max, IfBuilderBranchType then_type, |
227 IfBuilderBranchType else_type) { | 227 IfBuilderBranchType else_type) { |
228 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 228 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
229 | 229 |
230 std::vector<int32_t> inputs = ValueHelper::int32_vector(); | 230 std::vector<int32_t> inputs = ValueHelper::int32_vector(); |
231 std::vector<int32_t>::const_iterator i = inputs.begin(); | 231 std::vector<int32_t>::const_iterator i = inputs.begin(); |
232 int32_t hit = 0x8c723c9a; | 232 int32_t hit = 0x8c723c9a; |
233 int32_t miss = 0x88a6b9f3; | 233 int32_t miss = 0x88a6b9f3; |
234 { | 234 { |
235 Node* p0 = m.Parameter(0); | 235 Node* p0 = m.Parameter(0); |
236 IfBuilder cond(&m); | 236 IfBuilder cond(&m); |
237 for (size_t j = 0; j < max; j++, ++i) { | 237 for (size_t j = 0; j < max; j++, ++i) { |
238 CHECK(i != inputs.end()); // Thank you STL. | 238 CHECK(i != inputs.end()); // Thank you STL. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 RunIfBuilderDisjunction(size, all_branch_types[i], all_branch_types[j]); | 285 RunIfBuilderDisjunction(size, all_branch_types[i], all_branch_types[j]); |
286 } | 286 } |
287 RunIfBuilderDisjunction(len, all_branch_types[i], all_branch_types[j]); | 287 RunIfBuilderDisjunction(len, all_branch_types[i], all_branch_types[j]); |
288 } | 288 } |
289 } | 289 } |
290 } | 290 } |
291 | 291 |
292 | 292 |
293 static void RunIfBuilderConjunction(size_t max, IfBuilderBranchType then_type, | 293 static void RunIfBuilderConjunction(size_t max, IfBuilderBranchType then_type, |
294 IfBuilderBranchType else_type) { | 294 IfBuilderBranchType else_type) { |
295 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 295 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
296 | 296 |
297 std::vector<int32_t> inputs = ValueHelper::int32_vector(); | 297 std::vector<int32_t> inputs = ValueHelper::int32_vector(); |
298 std::vector<int32_t>::const_iterator i = inputs.begin(); | 298 std::vector<int32_t>::const_iterator i = inputs.begin(); |
299 int32_t hit = 0xa0ceb9ca; | 299 int32_t hit = 0xa0ceb9ca; |
300 int32_t miss = 0x226cafaa; | 300 int32_t miss = 0x226cafaa; |
301 { | 301 { |
302 IfBuilder cond(&m); | 302 IfBuilder cond(&m); |
303 Node* p0 = m.Parameter(0); | 303 Node* p0 = m.Parameter(0); |
304 for (size_t j = 0; j < max; j++, ++i) { | 304 for (size_t j = 0; j < max; j++, ++i) { |
305 if (j > 0) cond.And(); | 305 if (j > 0) cond.And(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 RunIfBuilderConjunction(size, all_branch_types[i], all_branch_types[j]); | 351 RunIfBuilderConjunction(size, all_branch_types[i], all_branch_types[j]); |
352 } | 352 } |
353 RunIfBuilderConjunction(len, all_branch_types[i], all_branch_types[j]); | 353 RunIfBuilderConjunction(len, all_branch_types[i], all_branch_types[j]); |
354 } | 354 } |
355 } | 355 } |
356 } | 356 } |
357 | 357 |
358 | 358 |
359 static void RunDisjunctionVariables(int disjunctions, bool explicit_then, | 359 static void RunDisjunctionVariables(int disjunctions, bool explicit_then, |
360 bool explicit_else) { | 360 bool explicit_else) { |
361 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 361 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
362 | 362 |
363 int32_t constant = 0x65a09535; | 363 int32_t constant = 0x65a09535; |
364 | 364 |
365 Node* cmp_val = m.Int32Constant(constant); | 365 Node* cmp_val = m.Int32Constant(constant); |
366 Node* one = m.Int32Constant(1); | 366 Node* one = m.Int32Constant(1); |
367 Variable var = m.NewVariable(m.Parameter(0)); | 367 Variable var = m.NewVariable(m.Parameter(0)); |
368 { | 368 { |
369 IfBuilder cond(&m); | 369 IfBuilder cond(&m); |
370 cond.If(m.Word32Equal(var.Get(), cmp_val)); | 370 cond.If(m.Word32Equal(var.Get(), cmp_val)); |
371 for (int i = 0; i < disjunctions; i++) { | 371 for (int i = 0; i < disjunctions; i++) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 RunDisjunctionVariables(disjunctions, false, false); | 405 RunDisjunctionVariables(disjunctions, false, false); |
406 RunDisjunctionVariables(disjunctions, false, true); | 406 RunDisjunctionVariables(disjunctions, false, true); |
407 RunDisjunctionVariables(disjunctions, true, false); | 407 RunDisjunctionVariables(disjunctions, true, false); |
408 RunDisjunctionVariables(disjunctions, true, true); | 408 RunDisjunctionVariables(disjunctions, true, true); |
409 } | 409 } |
410 } | 410 } |
411 | 411 |
412 | 412 |
413 static void RunConjunctionVariables(int conjunctions, bool explicit_then, | 413 static void RunConjunctionVariables(int conjunctions, bool explicit_then, |
414 bool explicit_else) { | 414 bool explicit_else) { |
415 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 415 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
416 | 416 |
417 int32_t constant = 0x2c7f4b45; | 417 int32_t constant = 0x2c7f4b45; |
418 Node* cmp_val = m.Int32Constant(constant); | 418 Node* cmp_val = m.Int32Constant(constant); |
419 Node* one = m.Int32Constant(1); | 419 Node* one = m.Int32Constant(1); |
420 Variable var = m.NewVariable(m.Parameter(0)); | 420 Variable var = m.NewVariable(m.Parameter(0)); |
421 { | 421 { |
422 IfBuilder cond(&m); | 422 IfBuilder cond(&m); |
423 cond.If(m.Word32NotEqual(var.Get(), cmp_val)); | 423 cond.If(m.Word32NotEqual(var.Get(), cmp_val)); |
424 for (int i = 0; i < conjunctions; i++) { | 424 for (int i = 0; i < conjunctions; i++) { |
425 cond.And(); | 425 cond.And(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 for (int conjunctions = 0; conjunctions < 10; conjunctions++) { | 457 for (int conjunctions = 0; conjunctions < 10; conjunctions++) { |
458 RunConjunctionVariables(conjunctions, false, false); | 458 RunConjunctionVariables(conjunctions, false, false); |
459 RunConjunctionVariables(conjunctions, false, true); | 459 RunConjunctionVariables(conjunctions, false, true); |
460 RunConjunctionVariables(conjunctions, true, false); | 460 RunConjunctionVariables(conjunctions, true, false); |
461 RunConjunctionVariables(conjunctions, true, true); | 461 RunConjunctionVariables(conjunctions, true, true); |
462 } | 462 } |
463 } | 463 } |
464 | 464 |
465 | 465 |
466 TEST(RunSimpleNestedIf) { | 466 TEST(RunSimpleNestedIf) { |
467 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32, kMachineWord32); | 467 StructuredMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); |
468 const size_t NUM_VALUES = 7; | 468 const size_t NUM_VALUES = 7; |
469 std::vector<int32_t> inputs = ValueHelper::int32_vector(); | 469 std::vector<int32_t> inputs = ValueHelper::int32_vector(); |
470 CHECK(inputs.size() >= NUM_VALUES); | 470 CHECK(inputs.size() >= NUM_VALUES); |
471 Node* values[NUM_VALUES]; | 471 Node* values[NUM_VALUES]; |
472 for (size_t j = 0; j < NUM_VALUES; j++) { | 472 for (size_t j = 0; j < NUM_VALUES; j++) { |
473 values[j] = m.Int32Constant(inputs[j]); | 473 values[j] = m.Int32Constant(inputs[j]); |
474 } | 474 } |
475 { | 475 { |
476 IfBuilder if_0(&m); | 476 IfBuilder if_0(&m); |
477 if_0.If(m.Word32Equal(m.Parameter(0), values[0])).Then(); | 477 if_0.If(m.Word32Equal(m.Parameter(0), values[0])).Then(); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 i.Set(m.Int32Add(i.Get(), one)); | 592 i.Set(m.Int32Add(i.Get(), one)); |
593 var.Set(m.Int32Add(var.Get(), i.Get())); | 593 var.Set(m.Int32Add(var.Get(), i.Get())); |
594 } | 594 } |
595 m.Return(var.Get()); | 595 m.Return(var.Get()); |
596 | 596 |
597 CHECK_EQ(constant + 10 + 9 * 5, m.Call()); | 597 CHECK_EQ(constant + 10 + 9 * 5, m.Call()); |
598 } | 598 } |
599 | 599 |
600 | 600 |
601 TEST(RunSimpleNestedLoop) { | 601 TEST(RunSimpleNestedLoop) { |
602 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 602 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
603 | 603 |
604 Node* zero = m.Int32Constant(0); | 604 Node* zero = m.Int32Constant(0); |
605 Node* one = m.Int32Constant(1); | 605 Node* one = m.Int32Constant(1); |
606 Node* two = m.Int32Constant(2); | 606 Node* two = m.Int32Constant(2); |
607 Node* three = m.Int32Constant(3); | 607 Node* three = m.Int32Constant(3); |
608 { | 608 { |
609 Loop l1(&m); | 609 Loop l1(&m); |
610 { | 610 { |
611 Loop l2(&m); | 611 Loop l2(&m); |
612 { | 612 { |
(...skipping 20 matching lines...) Expand all Loading... |
633 m.Return(zero); | 633 m.Return(zero); |
634 | 634 |
635 CHECK_EQ(0, m.Call(1)); | 635 CHECK_EQ(0, m.Call(1)); |
636 CHECK_EQ(1, m.Call(2)); | 636 CHECK_EQ(1, m.Call(2)); |
637 CHECK_EQ(2, m.Call(3)); | 637 CHECK_EQ(2, m.Call(3)); |
638 CHECK_EQ(3, m.Call(4)); | 638 CHECK_EQ(3, m.Call(4)); |
639 } | 639 } |
640 | 640 |
641 | 641 |
642 TEST(RunFib) { | 642 TEST(RunFib) { |
643 StructuredMachineAssemblerTester<int32_t> m(kMachineWord32); | 643 StructuredMachineAssemblerTester<int32_t> m(kMachInt32); |
644 | 644 |
645 // Constants. | 645 // Constants. |
646 Node* zero = m.Int32Constant(0); | 646 Node* zero = m.Int32Constant(0); |
647 Node* one = m.Int32Constant(1); | 647 Node* one = m.Int32Constant(1); |
648 Node* two = m.Int32Constant(2); | 648 Node* two = m.Int32Constant(2); |
649 // Variables. | 649 // Variables. |
650 // cnt = input | 650 // cnt = input |
651 Variable cnt = m.NewVariable(m.Parameter(0)); | 651 Variable cnt = m.NewVariable(m.Parameter(0)); |
652 // if (cnt < 2) return i | 652 // if (cnt < 2) return i |
653 { | 653 { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 m.Return(var.Get()); | 872 m.Return(var.Get()); |
873 | 873 |
874 CHECK_EQ(constant + 4, m.Call()); | 874 CHECK_EQ(constant + 4, m.Call()); |
875 } | 875 } |
876 | 876 |
877 | 877 |
878 class QuicksortHelper : public StructuredMachineAssemblerTester<int32_t> { | 878 class QuicksortHelper : public StructuredMachineAssemblerTester<int32_t> { |
879 public: | 879 public: |
880 QuicksortHelper() | 880 QuicksortHelper() |
881 : StructuredMachineAssemblerTester<int32_t>( | 881 : StructuredMachineAssemblerTester<int32_t>( |
882 MachineOperatorBuilder::pointer_rep(), kMachineWord32, | 882 MachineOperatorBuilder::pointer_rep(), kMachInt32, |
883 MachineOperatorBuilder::pointer_rep(), kMachineWord32), | 883 MachineOperatorBuilder::pointer_rep(), kMachInt32), |
884 input_(NULL), | 884 input_(NULL), |
885 stack_limit_(NULL), | 885 stack_limit_(NULL), |
886 one_(Int32Constant(1)), | 886 one_(Int32Constant(1)), |
887 stack_frame_size_(Int32Constant(kFrameVariables * 4)), | 887 stack_frame_size_(Int32Constant(kFrameVariables * 4)), |
888 left_offset_(Int32Constant(0 * 4)), | 888 left_offset_(Int32Constant(0 * 4)), |
889 right_offset_(Int32Constant(1 * 4)) { | 889 right_offset_(Int32Constant(1 * 4)) { |
890 Build(); | 890 Build(); |
891 } | 891 } |
892 | 892 |
893 int32_t DoCall(int32_t* input, int32_t input_length) { | 893 int32_t DoCall(int32_t* input, int32_t input_length) { |
894 int32_t stack_space[20]; | 894 int32_t stack_space[20]; |
895 // Do call. | 895 // Do call. |
896 int32_t return_val = Call(input, input_length, stack_space, | 896 int32_t return_val = Call(input, input_length, stack_space, |
897 static_cast<int32_t>(ARRAY_SIZE(stack_space))); | 897 static_cast<int32_t>(ARRAY_SIZE(stack_space))); |
898 // Ran out of stack space. | 898 // Ran out of stack space. |
899 if (return_val != 0) return return_val; | 899 if (return_val != 0) return return_val; |
900 // Check sorted. | 900 // Check sorted. |
901 int32_t last = input[0]; | 901 int32_t last = input[0]; |
902 for (int32_t i = 0; i < input_length; i++) { | 902 for (int32_t i = 0; i < input_length; i++) { |
903 CHECK(last <= input[i]); | 903 CHECK(last <= input[i]); |
904 last = input[i]; | 904 last = input[i]; |
905 } | 905 } |
906 return return_val; | 906 return return_val; |
907 } | 907 } |
908 | 908 |
909 private: | 909 private: |
910 void Inc32(const Variable& var) { var.Set(Int32Add(var.Get(), one_)); } | 910 void Inc32(const Variable& var) { var.Set(Int32Add(var.Get(), one_)); } |
911 Node* Index(Node* index) { return Word32Shl(index, Int32Constant(2)); } | 911 Node* Index(Node* index) { return Word32Shl(index, Int32Constant(2)); } |
912 Node* ArrayLoad(Node* index) { | 912 Node* ArrayLoad(Node* index) { |
913 return Load(kMachineWord32, input_, Index(index)); | 913 return Load(kMachInt32, input_, Index(index)); |
914 } | 914 } |
915 void Swap(Node* a_index, Node* b_index) { | 915 void Swap(Node* a_index, Node* b_index) { |
916 Node* a = ArrayLoad(a_index); | 916 Node* a = ArrayLoad(a_index); |
917 Node* b = ArrayLoad(b_index); | 917 Node* b = ArrayLoad(b_index); |
918 Store(kMachineWord32, input_, Index(a_index), b); | 918 Store(kMachInt32, input_, Index(a_index), b); |
919 Store(kMachineWord32, input_, Index(b_index), a); | 919 Store(kMachInt32, input_, Index(b_index), a); |
920 } | 920 } |
921 void AddToCallStack(const Variable& fp, Node* left, Node* right) { | 921 void AddToCallStack(const Variable& fp, Node* left, Node* right) { |
922 { | 922 { |
923 // Stack limit check. | 923 // Stack limit check. |
924 IfBuilder cond(this); | 924 IfBuilder cond(this); |
925 cond.If(IntPtrLessThanOrEqual(fp.Get(), stack_limit_)).Then(); | 925 cond.If(IntPtrLessThanOrEqual(fp.Get(), stack_limit_)).Then(); |
926 Return(Int32Constant(-1)); | 926 Return(Int32Constant(-1)); |
927 } | 927 } |
928 Store(kMachineWord32, fp.Get(), left_offset_, left); | 928 Store(kMachInt32, fp.Get(), left_offset_, left); |
929 Store(kMachineWord32, fp.Get(), right_offset_, right); | 929 Store(kMachInt32, fp.Get(), right_offset_, right); |
930 fp.Set(IntPtrAdd(fp.Get(), ConvertInt32ToIntPtr(stack_frame_size_))); | 930 fp.Set(IntPtrAdd(fp.Get(), ConvertInt32ToIntPtr(stack_frame_size_))); |
931 } | 931 } |
932 void Build() { | 932 void Build() { |
933 Variable left = NewVariable(Int32Constant(0)); | 933 Variable left = NewVariable(Int32Constant(0)); |
934 Variable right = | 934 Variable right = |
935 NewVariable(Int32Sub(Parameter(kInputLengthParameter), one_)); | 935 NewVariable(Int32Sub(Parameter(kInputLengthParameter), one_)); |
936 input_ = Parameter(kInputParameter); | 936 input_ = Parameter(kInputParameter); |
937 Node* top_of_stack = Parameter(kStackParameter); | 937 Node* top_of_stack = Parameter(kStackParameter); |
938 stack_limit_ = IntPtrSub( | 938 stack_limit_ = IntPtrSub( |
939 top_of_stack, ConvertInt32ToIntPtr(Parameter(kStackLengthParameter))); | 939 top_of_stack, ConvertInt32ToIntPtr(Parameter(kStackLengthParameter))); |
(...skipping 13 matching lines...) Expand all Loading... |
953 // Algorithm complete condition. | 953 // Algorithm complete condition. |
954 cond.If(WordEqual(top_of_stack, fp.Get())).And(); | 954 cond.If(WordEqual(top_of_stack, fp.Get())).And(); |
955 cond.If(Int32LessThanOrEqual(Int32Sub(right.Get(), one_), left.Get())) | 955 cond.If(Int32LessThanOrEqual(Int32Sub(right.Get(), one_), left.Get())) |
956 .Then(); | 956 .Then(); |
957 outermost.Break(); | 957 outermost.Break(); |
958 // 'Recursion' exit condition. Pop frame and continue. | 958 // 'Recursion' exit condition. Pop frame and continue. |
959 cond.Else(); | 959 cond.Else(); |
960 cond.If(Int32LessThanOrEqual(Int32Sub(right.Get(), one_), left.Get())) | 960 cond.If(Int32LessThanOrEqual(Int32Sub(right.Get(), one_), left.Get())) |
961 .Then(); | 961 .Then(); |
962 fp.Set(IntPtrSub(fp.Get(), ConvertInt32ToIntPtr(stack_frame_size_))); | 962 fp.Set(IntPtrSub(fp.Get(), ConvertInt32ToIntPtr(stack_frame_size_))); |
963 left.Set(Load(kMachineWord32, fp.Get(), left_offset_)); | 963 left.Set(Load(kMachInt32, fp.Get(), left_offset_)); |
964 right.Set(Load(kMachineWord32, fp.Get(), right_offset_)); | 964 right.Set(Load(kMachInt32, fp.Get(), right_offset_)); |
965 outermost.Continue(); | 965 outermost.Continue(); |
966 } | 966 } |
967 // Partition. | 967 // Partition. |
968 Variable store_index = NewVariable(left.Get()); | 968 Variable store_index = NewVariable(left.Get()); |
969 { | 969 { |
970 Node* pivot_index = | 970 Node* pivot_index = |
971 Int32Div(Int32Add(left.Get(), right.Get()), Int32Constant(2)); | 971 Int32Div(Int32Add(left.Get(), right.Get()), Int32Constant(2)); |
972 Node* pivot = ArrayLoad(pivot_index); | 972 Node* pivot = ArrayLoad(pivot_index); |
973 Swap(pivot_index, right.Get()); | 973 Swap(pivot_index, right.Get()); |
974 Variable i = NewVariable(left.Get()); | 974 Variable i = NewVariable(left.Get()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 for (int i = 0; i < 10; i++) { | 1046 for (int i = 0; i < 10; i++) { |
1047 IfBuilder b(&m); | 1047 IfBuilder b(&m); |
1048 b.If(m.Int32Constant(0)).Then(); | 1048 b.If(m.Int32Constant(0)).Then(); |
1049 m.NewVariable(m.Int32Constant(0)); | 1049 m.NewVariable(m.Int32Constant(0)); |
1050 } | 1050 } |
1051 m.Return(m.Int32Constant(0)); | 1051 m.Return(m.Int32Constant(0)); |
1052 CHECK_EQ(0, m.Call()); | 1052 CHECK_EQ(0, m.Call()); |
1053 } | 1053 } |
1054 | 1054 |
1055 #endif | 1055 #endif |
OLD | NEW |