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

Side by Side Diff: src/wasm/asm-types.cc

Issue 2069443002: V8. ASM-2-WASM. Changes the asm-types library. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: removes unused type_traits include. Created 4 years, 6 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
« no previous file with comments | « src/wasm/asm-types.h ('k') | test/unittests/wasm/asm-types-unittest.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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/wasm/asm-types.h" 7 #include "src/wasm/asm-types.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
(...skipping 11 matching lines...) Expand all
22 switch (avt->Bitset()) { 22 switch (avt->Bitset()) {
23 #define RETURN_TYPE_NAME(CamelName, string_name, number, parent_types) \ 23 #define RETURN_TYPE_NAME(CamelName, string_name, number, parent_types) \
24 case AsmValueType::kAsm##CamelName: \ 24 case AsmValueType::kAsm##CamelName: \
25 return string_name; 25 return string_name;
26 FOR_EACH_ASM_VALUE_TYPE_LIST(RETURN_TYPE_NAME) 26 FOR_EACH_ASM_VALUE_TYPE_LIST(RETURN_TYPE_NAME)
27 #undef RETURN_TYPE_NAME 27 #undef RETURN_TYPE_NAME
28 default: 28 default:
29 UNREACHABLE(); 29 UNREACHABLE();
30 } 30 }
31 } 31 }
32
32 return this->AsCallableType()->Name(); 33 return this->AsCallableType()->Name();
33 } 34 }
34 35
35 bool AsmType::IsExactly(AsmType* that) { 36 bool AsmType::IsExactly(AsmType* that) {
36 // TODO(jpp): maybe this can become this == that. 37 // TODO(jpp): maybe this can become this == that.
37 AsmValueType* avt = this->AsValueType(); 38 AsmValueType* avt = this->AsValueType();
38 if (avt != nullptr) { 39 if (avt != nullptr) {
39 AsmValueType* tavt = that->AsValueType(); 40 AsmValueType* tavt = that->AsValueType();
40 if (tavt == nullptr) { 41 if (tavt == nullptr) {
41 return false; 42 return false;
42 } 43 }
43 return avt->Bitset() == tavt->Bitset(); 44 return avt->Bitset() == tavt->Bitset();
44 } 45 }
46
45 // TODO(jpp): is it useful to allow non-value types to be tested with 47 // TODO(jpp): is it useful to allow non-value types to be tested with
46 // IsExactly? 48 // IsExactly?
47 return that == this; 49 return that == this;
48 } 50 }
49 51
50 bool AsmType::IsA(AsmType* that) { 52 bool AsmType::IsA(AsmType* that) {
51 // IsA is used for querying inheritance relationships. Therefore it is only 53 // IsA is used for querying inheritance relationships. Therefore it is only
52 // meaningful for basic types. 54 // meaningful for basic types.
53 AsmValueType* tavt = that->AsValueType(); 55 AsmValueType* tavt = that->AsValueType();
54 if (tavt != nullptr) { 56 if (tavt != nullptr) {
55 AsmValueType* avt = this->AsValueType(); 57 AsmValueType* avt = this->AsValueType();
56 if (avt == nullptr) { 58 if (avt == nullptr) {
57 return false; 59 return false;
58 } 60 }
59 return (avt->Bitset() & tavt->Bitset()) == tavt->Bitset(); 61 return (avt->Bitset() & tavt->Bitset()) == tavt->Bitset();
60 } 62 }
63
61 // TODO(jpp): is it useful to allow non-value types to be tested with IsA? 64 // TODO(jpp): is it useful to allow non-value types to be tested with IsA?
62 return that == this; 65 return that == this;
63 } 66 }
64 67
65 int32_t AsmType::ElementSizeInBytes() { 68 int32_t AsmType::ElementSizeInBytes() {
66 auto* value = AsValueType(); 69 auto* value = AsValueType();
67 if (value == nullptr) { 70 if (value == nullptr) {
68 return AsmType::kNotHeapType; 71 return AsmType::kNotHeapType;
69 } 72 }
70 switch (value->Bitset()) { 73 switch (value->Bitset()) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 case AsmValueType::kAsmFloat32Array: 126 case AsmValueType::kAsmFloat32Array:
124 return AsmType::FloatishDoubleQ(); 127 return AsmType::FloatishDoubleQ();
125 case AsmValueType::kAsmFloat64Array: 128 case AsmValueType::kAsmFloat64Array:
126 return AsmType::FloatQDoubleQ(); 129 return AsmType::FloatQDoubleQ();
127 default: 130 default:
128 return AsmType::None(); 131 return AsmType::None();
129 } 132 }
130 } 133 }
131 134
132 std::string AsmFunctionType::Name() { 135 std::string AsmFunctionType::Name() {
136 if (IsFroundType()) {
137 return "fround";
138 }
139
133 std::string ret; 140 std::string ret;
134 ret += "("; 141 ret += "(";
135 for (size_t ii = 0; ii < args_.size(); ++ii) { 142 for (size_t ii = 0; ii < args_.size(); ++ii) {
136 ret += args_[ii]->Name(); 143 ret += args_[ii]->Name();
137 if (ii != args_.size() - 1) { 144 if (ii != args_.size() - 1) {
138 ret += ", "; 145 ret += ", ";
139 } 146 }
140 } 147 }
141 if (IsMinMaxType()) { 148 if (IsMinMaxType()) {
142 DCHECK_EQ(args_.size(), 2); 149 DCHECK_EQ(args_.size(), 2);
143 ret += "..."; 150 ret += "...";
144 } 151 }
145 ret += ") -> "; 152 ret += ") -> ";
146 ret += return_type_->Name(); 153 ret += return_type_->Name();
147 return ret; 154 return ret;
148 } 155 }
149 156
150 namespace { 157 namespace {
151 class AsmFroundType final : public AsmFunctionType { 158 class AsmFroundType final : public AsmFunctionType {
152 public: 159 public:
153 bool IsFroundType() const override { return true; } 160 bool IsFroundType() const override { return true; }
154 161
155 private: 162 private:
156 friend AsmType; 163 friend AsmType;
157 164
158 AsmFroundType(Zone* zone, AsmType* src) 165 explicit AsmFroundType(Zone* zone)
159 : AsmFunctionType(zone, AsmType::Float()) { 166 : AsmFunctionType(zone, AsmType::Float()) {}
160 AddArgument(src); 167
161 } 168 AsmType* ValidateCall(AsmType* function_type) override;
162 }; 169 };
163 } // namespace 170 } // namespace
164 171
165 AsmType* AsmType::FroundType(Zone* zone, AsmType* src) { 172 AsmType* AsmType::FroundType(Zone* zone) {
166 DCHECK(src->AsValueType() != nullptr); 173 auto* Fround = new (zone) AsmFroundType(zone);
167 auto* Fround = new (zone) AsmFroundType(zone, src);
168 return reinterpret_cast<AsmType*>(Fround); 174 return reinterpret_cast<AsmType*>(Fround);
169 } 175 }
170 176
177 AsmType* AsmFroundType::ValidateCall(AsmType* function_type) {
178 auto* callable = function_type->AsFunctionType();
179 if (callable->Arguments().size() != 1) {
180 return AsmType::None();
181 }
182
183 auto* arg = callable->Arguments()[0];
184 if (!arg->IsA(AsmType::Floatish()) && !arg->IsA(AsmType::DoubleQ()) &&
185 !arg->IsA(AsmType::Signed()) && !arg->IsA(AsmType::Unsigned())) {
186 return AsmType::None();
187 }
188
189 return AsmType::Float();
190 }
191
171 namespace { 192 namespace {
172 class AsmMinMaxType final : public AsmFunctionType { 193 class AsmMinMaxType final : public AsmFunctionType {
173 public: 194 public:
174 bool IsMinMaxType() const override { return true; } 195 bool IsMinMaxType() const override { return true; }
175 196
176 private: 197 private:
177 friend AsmType; 198 friend AsmType;
178 199
179 AsmMinMaxType(Zone* zone, AsmType* type) : AsmFunctionType(zone, type) { 200 AsmMinMaxType(Zone* zone, AsmType* dest, AsmType* src)
180 AddArgument(type); 201 : AsmFunctionType(zone, dest) {
181 AddArgument(type); 202 AddArgument(src);
203 AddArgument(src);
182 } 204 }
183 205
184 AsmType* ValidateCall(AsmType* function_type) override { 206 AsmType* ValidateCall(AsmType* function_type) override {
185 auto* callable = function_type->AsFunctionType(); 207 auto* callable = function_type->AsFunctionType();
186 if (callable == nullptr) { 208 if (callable == nullptr) {
187 return nullptr; 209 return nullptr;
188 } 210 }
189 211
190 if (!ReturnType()->IsExactly(callable->ReturnType())) { 212 if (!ReturnType()->IsExactly(callable->ReturnType())) {
191 return AsmType::None(); 213 return AsmType::None();
192 } 214 }
193 215
194 if (callable->Arguments().size() < 2) { 216 if (callable->Arguments().size() < 2) {
195 return AsmType::None(); 217 return AsmType::None();
196 } 218 }
197 219
198 for (size_t ii = 0; ii < Arguments().size(); ++ii) { 220 for (size_t ii = 0; ii < Arguments().size(); ++ii) {
199 if (!Arguments()[0]->IsExactly(callable->Arguments()[ii])) { 221 if (!Arguments()[0]->IsExactly(callable->Arguments()[ii])) {
200 return AsmType::None(); 222 return AsmType::None();
201 } 223 }
202 } 224 }
203 225
204 return ReturnType(); 226 return ReturnType();
205 } 227 }
206 }; 228 };
207 } // namespace 229 } // namespace
208 230
209 AsmType* AsmType::MinMaxType(Zone* zone, AsmType* type) { 231 AsmType* AsmType::MinMaxType(Zone* zone, AsmType* dest, AsmType* src) {
210 DCHECK(type->AsValueType() != nullptr); 232 DCHECK(dest->AsValueType() != nullptr);
211 auto* MinMax = new (zone) AsmMinMaxType(zone, type); 233 DCHECK(src->AsValueType() != nullptr);
234 auto* MinMax = new (zone) AsmMinMaxType(zone, dest, src);
212 return reinterpret_cast<AsmType*>(MinMax); 235 return reinterpret_cast<AsmType*>(MinMax);
213 } 236 }
214 237
215 AsmType* AsmFunctionType::ValidateCall(AsmType* function_type) { 238 AsmType* AsmFunctionType::ValidateCall(AsmType* function_type) {
216 auto* callable = function_type->AsFunctionType(); 239 auto* callable = function_type->AsFunctionType();
217 if (callable == nullptr) { 240 if (callable == nullptr) {
218 return nullptr; 241 return nullptr;
219 } 242 }
220 243
221 if (!return_type_->IsExactly(callable->return_type_)) { 244 if (!return_type_->IsExactly(callable->return_type_)) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 289 }
267 290
268 void AsmOverloadedFunctionType::AddOverload(AsmType* overload) { 291 void AsmOverloadedFunctionType::AddOverload(AsmType* overload) {
269 DCHECK(overload->AsFunctionType() != nullptr); 292 DCHECK(overload->AsFunctionType() != nullptr);
270 overloads_.push_back(overload); 293 overloads_.push_back(overload);
271 } 294 }
272 295
273 } // namespace wasm 296 } // namespace wasm
274 } // namespace internal 297 } // namespace internal
275 } // namespace v8 298 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/asm-types.h ('k') | test/unittests/wasm/asm-types-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698