OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/compiler/simd-scalar-lowering.h" | 5 #include "src/compiler/simd-scalar-lowering.h" |
6 #include "src/compiler/diamond.h" | 6 #include "src/compiler/diamond.h" |
7 #include "src/compiler/linkage.h" | 7 #include "src/compiler/linkage.h" |
8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 | 10 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 type == SimdType::kSimd1x4) { | 269 type == SimdType::kSimd1x4) { |
270 num_lanes = kNumLanes32; | 270 num_lanes = kNumLanes32; |
271 } else if (type == SimdType::kInt16x8 || type == SimdType::kSimd1x8) { | 271 } else if (type == SimdType::kInt16x8 || type == SimdType::kSimd1x8) { |
272 num_lanes = kNumLanes16; | 272 num_lanes = kNumLanes16; |
273 } else { | 273 } else { |
274 UNREACHABLE(); | 274 UNREACHABLE(); |
275 } | 275 } |
276 return num_lanes; | 276 return num_lanes; |
277 } | 277 } |
278 | 278 |
| 279 constexpr int SimdScalarLowering::kLaneOffsets[]; |
| 280 |
279 void SimdScalarLowering::GetIndexNodes(Node* index, Node** new_indices, | 281 void SimdScalarLowering::GetIndexNodes(Node* index, Node** new_indices, |
280 SimdType type) { | 282 SimdType type) { |
281 new_indices[0] = index; | |
282 int num_lanes = NumLanes(type); | 283 int num_lanes = NumLanes(type); |
283 int lane_width = kSimd128Size / num_lanes; | 284 int lane_width = kSimd128Size / num_lanes; |
| 285 int laneIndex = kLaneOffsets[0] / lane_width; |
| 286 new_indices[laneIndex] = index; |
284 for (int i = 1; i < num_lanes; ++i) { | 287 for (int i = 1; i < num_lanes; ++i) { |
285 new_indices[i] = graph()->NewNode(machine()->Int32Add(), index, | 288 laneIndex = kLaneOffsets[i * lane_width] / lane_width; |
286 graph()->NewNode(common()->Int32Constant( | 289 new_indices[laneIndex] = graph()->NewNode( |
287 static_cast<int>(i) * lane_width))); | 290 machine()->Int32Add(), index, |
| 291 graph()->NewNode( |
| 292 common()->Int32Constant(static_cast<int>(i) * lane_width))); |
288 } | 293 } |
289 } | 294 } |
290 | 295 |
291 void SimdScalarLowering::LowerLoadOp(MachineRepresentation rep, Node* node, | 296 void SimdScalarLowering::LowerLoadOp(MachineRepresentation rep, Node* node, |
292 const Operator* load_op, SimdType type) { | 297 const Operator* load_op, SimdType type) { |
293 if (rep == MachineRepresentation::kSimd128) { | 298 if (rep == MachineRepresentation::kSimd128) { |
294 Node* base = node->InputAt(0); | 299 Node* base = node->InputAt(0); |
295 Node* index = node->InputAt(1); | 300 Node* index = node->InputAt(1); |
296 int num_lanes = NumLanes(type); | 301 int num_lanes = NumLanes(type); |
297 Node** indices = zone()->NewArray<Node*>(num_lanes); | 302 Node** indices = zone()->NewArray<Node*>(num_lanes); |
298 GetIndexNodes(index, indices, type); | 303 GetIndexNodes(index, indices, type); |
299 Node** rep_nodes = zone()->NewArray<Node*>(num_lanes); | 304 Node** rep_nodes = zone()->NewArray<Node*>(num_lanes); |
300 rep_nodes[0] = node; | 305 rep_nodes[0] = node; |
| 306 rep_nodes[0]->ReplaceInput(1, indices[0]); |
301 NodeProperties::ChangeOp(rep_nodes[0], load_op); | 307 NodeProperties::ChangeOp(rep_nodes[0], load_op); |
302 if (node->InputCount() > 2) { | 308 if (node->InputCount() > 2) { |
303 DCHECK(node->InputCount() > 3); | 309 DCHECK(node->InputCount() > 3); |
304 Node* effect_input = node->InputAt(2); | 310 Node* effect_input = node->InputAt(2); |
305 Node* control_input = node->InputAt(3); | 311 Node* control_input = node->InputAt(3); |
306 for (int i = num_lanes - 1; i > 0; --i) { | 312 for (int i = num_lanes - 1; i > 0; --i) { |
307 rep_nodes[i] = graph()->NewNode(load_op, base, indices[i], effect_input, | 313 rep_nodes[i] = graph()->NewNode(load_op, base, indices[i], effect_input, |
308 control_input); | 314 control_input); |
309 effect_input = rep_nodes[i]; | 315 effect_input = rep_nodes[i]; |
310 } | 316 } |
(...skipping 18 matching lines...) Expand all Loading... |
329 int num_lanes = NumLanes(rep_type); | 335 int num_lanes = NumLanes(rep_type); |
330 Node** indices = zone()->NewArray<Node*>(num_lanes); | 336 Node** indices = zone()->NewArray<Node*>(num_lanes); |
331 GetIndexNodes(index, indices, rep_type); | 337 GetIndexNodes(index, indices, rep_type); |
332 DCHECK(node->InputCount() > 2); | 338 DCHECK(node->InputCount() > 2); |
333 Node* value = node->InputAt(2); | 339 Node* value = node->InputAt(2); |
334 DCHECK(HasReplacement(1, value)); | 340 DCHECK(HasReplacement(1, value)); |
335 Node** rep_nodes = zone()->NewArray<Node*>(num_lanes); | 341 Node** rep_nodes = zone()->NewArray<Node*>(num_lanes); |
336 rep_nodes[0] = node; | 342 rep_nodes[0] = node; |
337 Node** rep_inputs = GetReplacementsWithType(value, rep_type); | 343 Node** rep_inputs = GetReplacementsWithType(value, rep_type); |
338 rep_nodes[0]->ReplaceInput(2, rep_inputs[0]); | 344 rep_nodes[0]->ReplaceInput(2, rep_inputs[0]); |
| 345 rep_nodes[0]->ReplaceInput(1, indices[0]); |
339 NodeProperties::ChangeOp(node, store_op); | 346 NodeProperties::ChangeOp(node, store_op); |
340 if (node->InputCount() > 3) { | 347 if (node->InputCount() > 3) { |
341 DCHECK(node->InputCount() > 4); | 348 DCHECK(node->InputCount() > 4); |
342 Node* effect_input = node->InputAt(3); | 349 Node* effect_input = node->InputAt(3); |
343 Node* control_input = node->InputAt(4); | 350 Node* control_input = node->InputAt(4); |
344 for (int i = num_lanes - 1; i > 0; --i) { | 351 for (int i = num_lanes - 1; i > 0; --i) { |
345 rep_nodes[i] = | 352 rep_nodes[i] = |
346 graph()->NewNode(store_op, base, indices[i], rep_inputs[i], | 353 graph()->NewNode(store_op, base, indices[i], rep_inputs[i], |
347 effect_input, control_input); | 354 effect_input, control_input); |
348 effect_input = rep_nodes[i]; | 355 effect_input = rep_nodes[i]; |
349 } | 356 } |
350 rep_nodes[0]->ReplaceInput(3, rep_nodes[1]); | 357 rep_nodes[0]->ReplaceInput(3, rep_nodes[1]); |
351 | |
352 } else { | 358 } else { |
353 for (int i = 1; i < num_lanes; ++i) { | 359 for (int i = 1; i < num_lanes; ++i) { |
354 rep_nodes[i] = | 360 rep_nodes[i] = |
355 graph()->NewNode(store_op, base, indices[i], rep_inputs[i]); | 361 graph()->NewNode(store_op, base, indices[i], rep_inputs[i]); |
356 } | 362 } |
357 } | 363 } |
358 | |
359 ReplaceNode(node, rep_nodes, num_lanes); | 364 ReplaceNode(node, rep_nodes, num_lanes); |
360 } else { | 365 } else { |
361 DefaultLowering(node); | 366 DefaultLowering(node); |
362 } | 367 } |
363 } | 368 } |
364 | 369 |
365 void SimdScalarLowering::LowerBinaryOp(Node* node, SimdType input_rep_type, | 370 void SimdScalarLowering::LowerBinaryOp(Node* node, SimdType input_rep_type, |
366 const Operator* op, bool invert_inputs) { | 371 const Operator* op, bool invert_inputs) { |
367 DCHECK(node->InputCount() == 2); | 372 DCHECK(node->InputCount() == 2); |
368 Node** rep_left = GetReplacementsWithType(node->InputAt(0), input_rep_type); | 373 Node** rep_left = GetReplacementsWithType(node->InputAt(0), input_rep_type); |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 UNREACHABLE(); | 1153 UNREACHABLE(); |
1149 } | 1154 } |
1150 #undef PHI_CASE | 1155 #undef PHI_CASE |
1151 } | 1156 } |
1152 ReplaceNode(phi, rep_nodes, num_lanes); | 1157 ReplaceNode(phi, rep_nodes, num_lanes); |
1153 } | 1158 } |
1154 } | 1159 } |
1155 } // namespace compiler | 1160 } // namespace compiler |
1156 } // namespace internal | 1161 } // namespace internal |
1157 } // namespace v8 | 1162 } // namespace v8 |
OLD | NEW |