Chromium Code Reviews

Side by Side Diff: src/compiler/simd-scalar-lowering.cc

Issue 2721223003: Revert of [wasm]implement simd lowering for simple F32x4 and I32x4 unops (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « src/compiler/simd-scalar-lowering.h ('k') | src/compiler/wasm-compiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 57 matching lines...)
68 state_.Set(input, State::kOnStack); 68 state_.Set(input, State::kOnStack);
69 } 69 }
70 } 70 }
71 } 71 }
72 } 72 }
73 73
74 #define FOREACH_INT32X4_OPCODE(V) \ 74 #define FOREACH_INT32X4_OPCODE(V) \
75 V(Int32x4Splat) \ 75 V(Int32x4Splat) \
76 V(Int32x4ExtractLane) \ 76 V(Int32x4ExtractLane) \
77 V(Int32x4ReplaceLane) \ 77 V(Int32x4ReplaceLane) \
78 V(Int32x4Neg) \
79 V(Simd128Not) \
80 V(Int32x4Add) \ 78 V(Int32x4Add) \
81 V(Int32x4Sub) \ 79 V(Int32x4Sub) \
82 V(Int32x4Mul) \ 80 V(Int32x4Mul) \
83 V(Simd128And) \ 81 V(Simd128And) \
84 V(Simd128Or) \ 82 V(Simd128Or) \
85 V(Simd128Xor) 83 V(Simd128Xor)
86 84
87 #define FOREACH_FLOAT32X4_OPCODE(V) \ 85 #define FOREACH_FLOAT32X4_OPCODE(V) \
88 V(Float32x4Splat) \ 86 V(Float32x4Splat) \
89 V(Float32x4ExtractLane) \ 87 V(Float32x4ExtractLane) \
90 V(Float32x4ReplaceLane) \ 88 V(Float32x4ReplaceLane) \
91 V(Float32x4Abs) \
92 V(Float32x4Neg) \
93 V(Float32x4Add) \ 89 V(Float32x4Add) \
94 V(Float32x4Sub) \ 90 V(Float32x4Sub) \
95 V(Float32x4Mul) \ 91 V(Float32x4Mul) \
96 V(Float32x4Div) \ 92 V(Float32x4Div) \
97 V(Float32x4Min) \ 93 V(Float32x4Min) \
98 V(Float32x4Max) \ 94 V(Float32x4Max)
99 V(Float32x4FromInt32x4) \
100 V(Float32x4FromUint32x4)
101 95
102 void SimdScalarLowering::SetLoweredType(Node* node, Node* output) { 96 void SimdScalarLowering::SetLoweredType(Node* node, Node* output) {
103 switch (node->opcode()) { 97 switch (node->opcode()) {
104 #define CASE_STMT(name) case IrOpcode::k##name: 98 #define CASE_STMT(name) case IrOpcode::k##name:
105 FOREACH_INT32X4_OPCODE(CASE_STMT) 99 FOREACH_INT32X4_OPCODE(CASE_STMT)
106 case IrOpcode::kReturn: 100 case IrOpcode::kReturn:
107 case IrOpcode::kParameter: 101 case IrOpcode::kParameter:
108 case IrOpcode::kCall: { 102 case IrOpcode::kCall: {
109 replacements_[node->id()].type = SimdType::kInt32; 103 replacements_[node->id()].type = SimdType::kInt32;
110 break; 104 break;
111 } 105 }
112 FOREACH_FLOAT32X4_OPCODE(CASE_STMT) { 106 FOREACH_FLOAT32X4_OPCODE(CASE_STMT) {
113 replacements_[node->id()].type = SimdType::kFloat32; 107 replacements_[node->id()].type = SimdType::kFloat32;
114 break; 108 break;
115 } 109 }
116 #undef CASE_STMT 110 #undef CASE_STMT
117 default: { 111 default:
118 if (output->opcode() == IrOpcode::kFloat32x4FromInt32x4 || 112 replacements_[node->id()].type = replacements_[output->id()].type;
119 output->opcode() == IrOpcode::kFloat32x4FromUint32x4) {
120 replacements_[node->id()].type = SimdType::kInt32;
121 } else {
122 replacements_[node->id()].type = replacements_[output->id()].type;
123 }
124 }
125 } 113 }
126 } 114 }
127 115
128 static int GetParameterIndexAfterLowering( 116 static int GetParameterIndexAfterLowering(
129 Signature<MachineRepresentation>* signature, int old_index) { 117 Signature<MachineRepresentation>* signature, int old_index) {
130 // In function calls, the simd128 types are passed as 4 Int32 types. The 118 // In function calls, the simd128 types are passed as 4 Int32 types. The
131 // parameters are typecast to the types as needed for various operations. 119 // parameters are typecast to the types as needed for various operations.
132 int result = old_index; 120 int result = old_index;
133 for (int i = 0; i < old_index; ++i) { 121 for (int i = 0; i < old_index; ++i) {
134 if (signature->GetParam(i) == MachineRepresentation::kSimd128) { 122 if (signature->GetParam(i) == MachineRepresentation::kSimd128) {
(...skipping 99 matching lines...)
234 graph()->NewNode(store_op, base, indices[i], rep_inputs[i]); 222 graph()->NewNode(store_op, base, indices[i], rep_inputs[i]);
235 } 223 }
236 } 224 }
237 225
238 ReplaceNode(node, rep_nodes); 226 ReplaceNode(node, rep_nodes);
239 } else { 227 } else {
240 DefaultLowering(node); 228 DefaultLowering(node);
241 } 229 }
242 } 230 }
243 231
244 void SimdScalarLowering::LowerBinaryOp(Node* node, SimdType input_rep_type, 232 void SimdScalarLowering::LowerBinaryOp(Node* node, SimdType rep_type,
245 const Operator* op) { 233 const Operator* op) {
246 DCHECK(node->InputCount() == 2); 234 DCHECK(node->InputCount() == 2);
247 Node** rep_left = GetReplacementsWithType(node->InputAt(0), input_rep_type); 235 Node** rep_left = GetReplacementsWithType(node->InputAt(0), rep_type);
248 Node** rep_right = GetReplacementsWithType(node->InputAt(1), input_rep_type); 236 Node** rep_right = GetReplacementsWithType(node->InputAt(1), rep_type);
249 Node* rep_node[kMaxLanes]; 237 Node* rep_node[kMaxLanes];
250 for (int i = 0; i < kMaxLanes; ++i) { 238 for (int i = 0; i < kMaxLanes; ++i) {
251 rep_node[i] = graph()->NewNode(op, rep_left[i], rep_right[i]); 239 rep_node[i] = graph()->NewNode(op, rep_left[i], rep_right[i]);
252 } 240 }
253 ReplaceNode(node, rep_node); 241 ReplaceNode(node, rep_node);
254 } 242 }
255
256 void SimdScalarLowering::LowerUnaryOp(Node* node, SimdType input_rep_type,
257 const Operator* op) {
258 DCHECK(node->InputCount() == 1);
259 Node** rep = GetReplacementsWithType(node->InputAt(0), input_rep_type);
260 Node* rep_node[kMaxLanes];
261 for (int i = 0; i < kMaxLanes; ++i) {
262 rep_node[i] = graph()->NewNode(op, rep[i]);
263 }
264 ReplaceNode(node, rep_node);
265 }
266 243
267 void SimdScalarLowering::LowerNode(Node* node) { 244 void SimdScalarLowering::LowerNode(Node* node) {
268 SimdType rep_type = ReplacementType(node); 245 SimdType rep_type = ReplacementType(node);
269 switch (node->opcode()) { 246 switch (node->opcode()) {
270 case IrOpcode::kStart: { 247 case IrOpcode::kStart: {
271 int parameter_count = GetParameterCountAfterLowering(); 248 int parameter_count = GetParameterCountAfterLowering();
272 // Only exchange the node if the parameter count actually changed. 249 // Only exchange the node if the parameter count actually changed.
273 if (parameter_count != static_cast<int>(signature()->parameter_count())) { 250 if (parameter_count != static_cast<int>(signature()->parameter_count())) {
274 int delta = 251 int delta =
275 parameter_count - static_cast<int>(signature()->parameter_count()); 252 parameter_count - static_cast<int>(signature()->parameter_count());
(...skipping 139 matching lines...)
415 LowerBinaryOp(node, rep_type, machine()->instruction()); \ 392 LowerBinaryOp(node, rep_type, machine()->instruction()); \
416 break; \ 393 break; \
417 } 394 }
418 I32X4_BINOP_CASE(kInt32x4Add, Int32Add) 395 I32X4_BINOP_CASE(kInt32x4Add, Int32Add)
419 I32X4_BINOP_CASE(kInt32x4Sub, Int32Sub) 396 I32X4_BINOP_CASE(kInt32x4Sub, Int32Sub)
420 I32X4_BINOP_CASE(kInt32x4Mul, Int32Mul) 397 I32X4_BINOP_CASE(kInt32x4Mul, Int32Mul)
421 I32X4_BINOP_CASE(kSimd128And, Word32And) 398 I32X4_BINOP_CASE(kSimd128And, Word32And)
422 I32X4_BINOP_CASE(kSimd128Or, Word32Or) 399 I32X4_BINOP_CASE(kSimd128Or, Word32Or)
423 I32X4_BINOP_CASE(kSimd128Xor, Word32Xor) 400 I32X4_BINOP_CASE(kSimd128Xor, Word32Xor)
424 #undef I32X4_BINOP_CASE 401 #undef I32X4_BINOP_CASE
425 case IrOpcode::kInt32x4Neg: {
426 DCHECK(node->InputCount() == 1);
427 Node** rep = GetReplacementsWithType(node->InputAt(0), rep_type);
428 Node* rep_node[kMaxLanes];
429 Node* zero = graph()->NewNode(common()->Int32Constant(0));
430 for (int i = 0; i < kMaxLanes; ++i) {
431 rep_node[i] = graph()->NewNode(machine()->Int32Sub(), zero, rep[i]);
432 }
433 ReplaceNode(node, rep_node);
434 break;
435 }
436 case IrOpcode::kSimd128Not: {
437 DCHECK(node->InputCount() == 1);
438 Node** rep = GetReplacementsWithType(node->InputAt(0), rep_type);
439 Node* rep_node[kMaxLanes];
440 Node* mask = graph()->NewNode(common()->Int32Constant(0xffffffff));
441 for (int i = 0; i < kMaxLanes; ++i) {
442 rep_node[i] = graph()->NewNode(machine()->Word32Xor(), rep[i], mask);
443 }
444 ReplaceNode(node, rep_node);
445 break;
446 }
447 #define F32X4_BINOP_CASE(name) \ 402 #define F32X4_BINOP_CASE(name) \
448 case IrOpcode::kFloat32x4##name: { \ 403 case IrOpcode::kFloat32x4##name: { \
449 LowerBinaryOp(node, rep_type, machine()->Float32##name()); \ 404 LowerBinaryOp(node, rep_type, machine()->Float32##name()); \
450 break; \ 405 break; \
451 } 406 }
452 F32X4_BINOP_CASE(Add) 407 F32X4_BINOP_CASE(Add)
453 F32X4_BINOP_CASE(Sub) 408 F32X4_BINOP_CASE(Sub)
454 F32X4_BINOP_CASE(Mul) 409 F32X4_BINOP_CASE(Mul)
455 F32X4_BINOP_CASE(Div) 410 F32X4_BINOP_CASE(Div)
456 F32X4_BINOP_CASE(Min) 411 F32X4_BINOP_CASE(Min)
457 F32X4_BINOP_CASE(Max) 412 F32X4_BINOP_CASE(Max)
458 #undef F32X4_BINOP_CASE 413 #undef F32X4_BINOP_CASE
459 #define F32X4_UNOP_CASE(name) \
460 case IrOpcode::kFloat32x4##name: { \
461 LowerUnaryOp(node, rep_type, machine()->Float32##name()); \
462 break; \
463 }
464 F32X4_UNOP_CASE(Abs)
465 F32X4_UNOP_CASE(Neg)
466 F32X4_UNOP_CASE(Sqrt)
467 #undef F32x4_UNOP_CASE
468 case IrOpcode::kFloat32x4FromInt32x4: {
469 LowerUnaryOp(node, SimdType::kInt32, machine()->RoundInt32ToFloat32());
470 break;
471 }
472 case IrOpcode::kFloat32x4FromUint32x4: {
473 LowerUnaryOp(node, SimdType::kInt32, machine()->RoundUint32ToFloat32());
474 break;
475 }
476 case IrOpcode::kInt32x4Splat: 414 case IrOpcode::kInt32x4Splat:
477 case IrOpcode::kFloat32x4Splat: { 415 case IrOpcode::kFloat32x4Splat: {
478 Node* rep_node[kMaxLanes]; 416 Node* rep_node[kMaxLanes];
479 for (int i = 0; i < kMaxLanes; ++i) { 417 for (int i = 0; i < kMaxLanes; ++i) {
480 if (HasReplacement(0, node->InputAt(0))) { 418 if (HasReplacement(0, node->InputAt(0))) {
481 rep_node[i] = GetReplacements(node->InputAt(0))[0]; 419 rep_node[i] = GetReplacements(node->InputAt(0))[0];
482 } else { 420 } else {
483 rep_node[i] = node->InputAt(0); 421 rep_node[i] = node->InputAt(0);
484 } 422 }
485 } 423 }
(...skipping 130 matching lines...)
616 } else { 554 } else {
617 UNREACHABLE(); 555 UNREACHABLE();
618 } 556 }
619 } 557 }
620 ReplaceNode(phi, rep_nodes); 558 ReplaceNode(phi, rep_nodes);
621 } 559 }
622 } 560 }
623 } // namespace compiler 561 } // namespace compiler
624 } // namespace internal 562 } // namespace internal
625 } // namespace v8 563 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/simd-scalar-lowering.h ('k') | src/compiler/wasm-compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine