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

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

Issue 1991143002: Convert SIMD wasm ops to runtime function calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Review changes Created 4 years, 5 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/compiler/simd-lowering.h"
6
7 #include "src/assembler.h"
8 #include "src/compiler/js-graph.h"
9 #include "src/compiler/linkage.h"
10 #include "src/compiler/machine-operator.h"
11 #include "src/compiler/operator-properties.h"
12 #include "src/compiler/simplified-operator.h"
13
14 namespace v8 {
15 namespace internal {
16 namespace compiler {
17
18 SimdLowering::~SimdLowering() {}
19
20 Reduction SimdLowering::Reduce(Node* node) {
21 // For now lower everything to runtime calls.
22 switch (node->opcode()) {
23 case IrOpcode::kCreateInt32x4: {
24 static const Conversion signature[] = {kOpaque, kInt32, kInt32, kInt32,
25 kInt32};
26 return ChangeToRuntimeCall(node, Runtime::kCreateInt32x4, signature);
27 }
28 case IrOpcode::kCreateInt16x8: {
29 static const Conversion signature[] = {
30 kOpaque, kInt32, kInt32, kInt32, kInt32,
31 kInt32, kInt32, kInt32, kInt32,
32 };
33 return ChangeToRuntimeCall(node, Runtime::kCreateInt16x8, signature);
34 }
35 case IrOpcode::kCreateInt8x16: {
36 static const Conversion signature[] = {
37 kOpaque, kInt32, kInt32, kInt32, kInt32, kInt32,
38 kInt32, kInt32, kInt32, kInt32, kInt32, kInt32,
39 kInt32, kInt32, kInt32, kInt32, kInt32,
40 };
41 return ChangeToRuntimeCall(node, Runtime::kCreateInt8x16, signature);
42 }
43 case IrOpcode::kCreateFloat32x4: {
44 static const Conversion signature[] = {kOpaque, kFloat32, kFloat32,
45 kFloat32, kFloat32};
46 return ChangeToRuntimeCall(node, Runtime::kCreateFloat32x4, signature);
47 }
48 case IrOpcode::kInt8x16ExtractLane:
49 case IrOpcode::kInt16x8ExtractLane:
50 case IrOpcode::kInt32x4ExtractLane: {
51 static const Conversion signature[] = {kInt32, kOpaque, kInt32};
52 return ChangeToRuntimeCall(node, Runtime::kInt32x4ExtractLane, signature);
53 }
54 case IrOpcode::kFloat32x4ExtractLane: {
55 static const Conversion signature[] = {kFloat32, kOpaque, kInt32};
56 return ChangeToRuntimeCall(node, Runtime::kFloat32x4ExtractLane,
57 signature);
58 }
59 default: { break; }
60 }
61
62 // TODO(gdeepti): Implement and test.
63 // Assume the others are all just simd in and out.
64 Conversion signature[17] = {
65 kNone, kNone, kNone, kNone, kNone, kNone, kNone, kNone, kNone,
66 kNone, kNone, kNone, kNone, kNone, kNone, kNone, kNone,
67 };
68 switch (node->opcode()) {
69 #define F(Opcode) \
70 case IrOpcode::k##Opcode: { \
71 return ChangeToRuntimeCall(node, Runtime::k##Opcode, signature); \
72 }
73 MACHINE_SIMD_RETURN_SIMD_OP_LIST(F)
74 MACHINE_SIMD_RETURN_BOOL_OP_LIST(F)
75 #undef F
76 default: { return NoChange(); }
77 }
78 UNREACHABLE();
79 return NoChange();
80 }
81
82 Reduction SimdLowering::ChangeToRuntimeCall(Node* node,
83 Runtime::FunctionId function_id,
84 const Conversion* signature) {
85 SimplifiedOperatorBuilder simplified(jsgraph()->zone());
86 const Runtime::Function* function = Runtime::FunctionForId(function_id);
87 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
88 jsgraph()->zone(), function_id, function->nargs, Operator::kNoProperties,
89 CallDescriptor::kNoFlags);
90 const int kInputSize = 16;
91 const int kDefaultFunctionParams = 6;
92 Node* inputs[kInputSize + kDefaultFunctionParams];
93 DCHECK_LE(function->nargs + kDefaultFunctionParams,
94 static_cast<int>(arraysize(inputs)));
95 // Either there are control + effect or not.
96 DCHECK(node->InputCount() == function->nargs ||
97 node->InputCount() == function->nargs + 2);
98 int index = 0;
99 inputs[index++] = jsgraph()->CEntryStubConstant(function->result_size);
100 for (int i = 0; i < function->nargs; ++i) {
101 Node* arg = node->InputAt(i);
102 switch (signature[i + 1]) {
103 case kInt32:
104 arg = builder_->BuildChangeInt32ToTagged(arg);
105 break;
106 case kFloat32:
107 arg = jsgraph()->graph()->NewNode(
108 jsgraph()->machine()->ChangeFloat32ToFloat64(), arg);
109 arg = builder_->BuildChangeFloat64ToTagged(arg);
110 break;
111 case kFloat64:
112 arg = builder_->BuildChangeFloat64ToTagged(arg);
113 break;
114 default:
115 break;
116 }
117 inputs[index++] = arg;
118 }
119 inputs[index++] = jsgraph()->ExternalConstant(
120 ExternalReference(function_id, jsgraph()->isolate()));
121 inputs[index++] = jsgraph()->Int32Constant(function->nargs);
122 inputs[index++] = jsgraph()->Constant(context_);
123 // Loads and stores have control and effect, others do not and use
124 // the start node instead.
125 if (node->InputCount() == function->nargs + 2) {
126 inputs[index++] = node->InputAt(function->nargs + 1); // effect
127 inputs[index++] = node->InputAt(function->nargs + 2); // control
128 } else {
129 inputs[index++] = jsgraph()->graph()->start(); // effect
130 inputs[index++] = jsgraph()->graph()->start(); // control
131 }
132 Node* ret = jsgraph()->graph()->NewNode(jsgraph()->common()->Call(desc),
133 index, inputs);
134
135 Conversion return_type = signature[0];
136 switch (return_type) {
137 case kInt32:
138 ret = builder_->BuildChangeTaggedToInt32(ret);
139 break;
140 case kFloat32:
141 NodeProperties::SetType(ret, Type::Number());
142 ret = builder_->BuildChangeTaggedToFloat64(ret);
143 ret = jsgraph()->graph()->NewNode(
144 jsgraph()->machine()->TruncateInt64ToInt32(), ret);
145 break;
146 case kFloat64:
147 ret = builder_->BuildChangeTaggedToFloat64(ret);
148 break;
149 default:
150 break;
151 }
152 return Replace(ret);
153 }
154
155 } // namespace compiler
156 } // namespace internal
157 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698