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/wasm/asm-types.h" | 5 #include "src/wasm/asm-types.h" |
6 | 6 |
7 #include <unordered_map> | 7 #include <unordered_map> |
8 #include <unordered_set> | 8 #include <unordered_set> |
9 | 9 |
10 #include "src/base/macros.h" | 10 #include "src/base/macros.h" |
11 #include "test/unittests/test-utils.h" | 11 #include "test/unittests/test-utils.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 namespace wasm { | 17 namespace wasm { |
18 namespace { | 18 namespace { |
19 | 19 |
20 using ::testing::StrEq; | 20 using ::testing::StrEq; |
21 | 21 |
22 class AsmTypeTest : public TestWithZone { | 22 class AsmTypeTest : public TestWithZone { |
23 public: | 23 public: |
24 using Type = AsmType; | 24 using Type = AsmType; |
25 | 25 |
26 AsmTypeTest() | 26 AsmTypeTest() |
27 : parents_({ | 27 : parents_({ |
28 {Type::Uint8Array(), {Type::Heap()}}, | 28 {Type::Uint8Array(), {Type::Heap()}}, |
29 {Type::Int8Array(), {Type::Heap()}}, | 29 {Type::Int8Array(), {Type::Heap()}}, |
| 30 {Type::Uint8ClampedArray(), {Type::Heap()}}, |
30 {Type::Uint16Array(), {Type::Heap()}}, | 31 {Type::Uint16Array(), {Type::Heap()}}, |
31 {Type::Int16Array(), {Type::Heap()}}, | 32 {Type::Int16Array(), {Type::Heap()}}, |
32 {Type::Uint32Array(), {Type::Heap()}}, | 33 {Type::Uint32Array(), {Type::Heap()}}, |
33 {Type::Int32Array(), {Type::Heap()}}, | 34 {Type::Int32Array(), {Type::Heap()}}, |
34 {Type::Float32Array(), {Type::Heap()}}, | 35 {Type::Float32Array(), {Type::Heap()}}, |
35 {Type::Float64Array(), {Type::Heap()}}, | 36 {Type::Float64Array(), {Type::Heap()}}, |
36 {Type::FloatishDoubleQ(), {Type::Floatish(), Type::DoubleQ()}}, | 37 {Type::FloatishDoubleQ(), {Type::Floatish(), Type::DoubleQ()}}, |
37 {Type::FloatQDoubleQ(), | 38 {Type::FloatQDoubleQ(), |
38 {Type::FloatQ(), Type::Floatish(), Type::DoubleQ()}}, | 39 {Type::FloatQ(), Type::Floatish(), Type::DoubleQ()}}, |
39 {Type::Float(), {Type::FloatQ(), Type::Floatish()}}, | 40 {Type::Float(), {Type::FloatQ(), Type::Floatish()}}, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 TEST_F(AsmTypeTest, ValidateBits) { | 143 TEST_F(AsmTypeTest, ValidateBits) { |
143 // Generic validation tests for the bits in the type system's type | 144 // Generic validation tests for the bits in the type system's type |
144 // definitions. | 145 // definitions. |
145 | 146 |
146 std::unordered_set<Type*> seen_types; | 147 std::unordered_set<Type*> seen_types; |
147 std::unordered_set<uint32_t> seen_numbers; | 148 std::unordered_set<uint32_t> seen_numbers; |
148 uint32_t total_types = 0; | 149 uint32_t total_types = 0; |
149 #define V(CamelName, string_name, number, parent_types) \ | 150 #define V(CamelName, string_name, number, parent_types) \ |
150 do { \ | 151 do { \ |
151 ++total_types; \ | 152 ++total_types; \ |
| 153 if (AsmValueTypeParents::CamelName != 0) { \ |
| 154 EXPECT_NE(0, ParentsOf(AsmType::CamelName()).size()) << #CamelName; \ |
| 155 } \ |
152 seen_types.insert(Type::CamelName()); \ | 156 seen_types.insert(Type::CamelName()); \ |
153 seen_numbers.insert(number); \ | 157 seen_numbers.insert(number); \ |
154 /* Every ASM type must have a valid number. */ \ | 158 /* Every ASM type must have a valid number. */ \ |
155 EXPECT_NE(0, number) << Type::CamelName()->Name(); \ | 159 EXPECT_NE(0, number) << Type::CamelName()->Name(); \ |
156 /* Inheritance cycles - unlikely, but we're paranoid and check for it */ \ | 160 /* Inheritance cycles - unlikely, but we're paranoid and check for it */ \ |
157 /* anyways.*/ \ | 161 /* anyways.*/ \ |
158 EXPECT_EQ(0, (1 << (number)) & AsmValueTypeParents::CamelName); \ | 162 EXPECT_EQ(0, (1 << (number)) & AsmValueTypeParents::CamelName); \ |
159 } while (0); | 163 } while (0); |
160 FOR_EACH_ASM_VALUE_TYPE_LIST(V) | 164 FOR_EACH_ASM_VALUE_TYPE_LIST(V) |
161 #undef V | 165 #undef V |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 #undef V | 213 #undef V |
210 | 214 |
211 EXPECT_THAT(Function(Type::Int)(Type::Double, Type::Float)->Name(), | 215 EXPECT_THAT(Function(Type::Int)(Type::Double, Type::Float)->Name(), |
212 StrEq("(double, float) -> int")); | 216 StrEq("(double, float) -> int")); |
213 | 217 |
214 EXPECT_THAT(Overload(Function(Type::Int)(Type::Double, Type::Float), | 218 EXPECT_THAT(Overload(Function(Type::Int)(Type::Double, Type::Float), |
215 Function(Type::Int)(Type::Int)) | 219 Function(Type::Int)(Type::Int)) |
216 ->Name(), | 220 ->Name(), |
217 StrEq("(double, float) -> int /\\ (int) -> int")); | 221 StrEq("(double, float) -> int /\\ (int) -> int")); |
218 | 222 |
219 EXPECT_THAT(Type::FroundType(zone(), Type::Int())->Name(), | 223 EXPECT_THAT(Type::FroundType(zone())->Name(), StrEq("fround")); |
220 StrEq("(int) -> float")); | |
221 EXPECT_THAT(Type::FroundType(zone(), Type::Floatish())->Name(), | |
222 StrEq("(floatish) -> float")); | |
223 EXPECT_THAT(Type::FroundType(zone(), Type::DoubleQ())->Name(), | |
224 StrEq("(double?) -> float")); | |
225 | 224 |
226 EXPECT_THAT(Type::MinMaxType(zone(), Type::Int())->Name(), | 225 EXPECT_THAT(Type::MinMaxType(zone(), Type::Signed(), Type::Int())->Name(), |
227 StrEq("(int, int...) -> int")); | 226 StrEq("(int, int...) -> signed")); |
228 EXPECT_THAT(Type::MinMaxType(zone(), Type::Floatish())->Name(), | 227 EXPECT_THAT(Type::MinMaxType(zone(), Type::Float(), Type::Floatish())->Name(), |
229 StrEq("(floatish, floatish...) -> floatish")); | 228 StrEq("(floatish, floatish...) -> float")); |
230 EXPECT_THAT(Type::MinMaxType(zone(), Type::DoubleQ())->Name(), | 229 EXPECT_THAT(Type::MinMaxType(zone(), Type::Double(), Type::Double())->Name(), |
231 StrEq("(double?, double?...) -> double?")); | 230 StrEq("(double, double...) -> double")); |
232 } | 231 } |
233 | 232 |
234 TEST_F(AsmTypeTest, IsExactly) { | 233 TEST_F(AsmTypeTest, IsExactly) { |
235 Type* test_types[] = { | 234 Type* test_types[] = { |
236 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 235 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
237 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 236 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
238 #undef CREATE | 237 #undef CREATE |
239 Function(Type::Int)(Type::Double), | 238 Function(Type::Int)(Type::Double), |
240 Function(Type::Int)(Type::DoubleQ), | 239 Function(Type::Int)(Type::DoubleQ), |
241 Overload(Function(Type::Int)(Type::Double)), | 240 Overload(Function(Type::Int)(Type::Double)), |
242 Function(Type::Int)(Type::Int, Type::Int), | 241 Function(Type::Int)(Type::Int, Type::Int), |
243 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), | 242 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
244 Type::FroundType(zone(), Type::Int()), | 243 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
245 }; | 244 }; |
246 | 245 |
247 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { | 246 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
248 for (size_t jj = 0; jj < arraysize(test_types); ++jj) { | 247 for (size_t jj = 0; jj < arraysize(test_types); ++jj) { |
249 EXPECT_EQ(ii == jj, test_types[ii]->IsExactly(test_types[jj])) | 248 EXPECT_EQ(ii == jj, test_types[ii]->IsExactly(test_types[jj])) |
250 << test_types[ii]->Name() | 249 << test_types[ii]->Name() |
251 << ((ii == jj) ? " is not exactly " : " is exactly ") | 250 << ((ii == jj) ? " is not exactly " : " is exactly ") |
252 << test_types[jj]->Name(); | 251 << test_types[jj]->Name(); |
253 } | 252 } |
254 } | 253 } |
255 } | 254 } |
256 | 255 |
257 TEST_F(AsmTypeTest, IsA) { | 256 TEST_F(AsmTypeTest, IsA) { |
258 Type* test_types[] = { | 257 Type* test_types[] = { |
259 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 258 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
260 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 259 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
261 #undef CREATE | 260 #undef CREATE |
262 Function(Type::Int)(Type::Double), | 261 Function(Type::Int)(Type::Double), |
263 Function(Type::Int)(Type::DoubleQ), | 262 Function(Type::Int)(Type::DoubleQ), |
264 Overload(Function(Type::Int)(Type::Double)), | 263 Overload(Function(Type::Int)(Type::Double)), |
265 Function(Type::Int)(Type::Int, Type::Int), | 264 Function(Type::Int)(Type::Int, Type::Int), |
266 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), | 265 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
267 Type::FroundType(zone(), Type::Int()), | 266 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
268 }; | 267 }; |
269 | 268 |
270 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { | 269 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
271 for (size_t jj = 0; jj < arraysize(test_types); ++jj) { | 270 for (size_t jj = 0; jj < arraysize(test_types); ++jj) { |
272 const bool Expected = | 271 const bool Expected = |
273 (ii == jj) || ParentsOf(test_types[ii]).count(test_types[jj]) != 0; | 272 (ii == jj) || ParentsOf(test_types[ii]).count(test_types[jj]) != 0; |
274 EXPECT_EQ(Expected, test_types[ii]->IsA(test_types[jj])) | 273 EXPECT_EQ(Expected, test_types[ii]->IsA(test_types[jj])) |
275 << test_types[ii]->Name() << (Expected ? " is not a " : " is a ") | 274 << test_types[ii]->Name() << (Expected ? " is not a " : " is a ") |
276 << test_types[jj]->Name(); | 275 << test_types[jj]->Name(); |
277 } | 276 } |
278 } | 277 } |
279 } | 278 } |
280 | 279 |
281 TEST_F(AsmTypeTest, ValidateCall) { | 280 TEST_F(AsmTypeTest, ValidateCall) { |
282 auto* min_max_int = Type::MinMaxType(zone(), Type::Int()); | 281 auto* min_max_int = Type::MinMaxType(zone(), Type::Signed(), Type::Int()); |
283 auto* i2i = Function(Type::Int)(Type::Int); | 282 auto* i2s = Function(Type::Signed)(Type::Int); |
284 auto* ii2i = Function(Type::Int)(Type::Int, Type::Int); | 283 auto* ii2s = Function(Type::Signed)(Type::Int, Type::Int); |
285 auto* iii2i = Function(Type::Int)(Type::Int, Type::Int, Type::Int); | 284 auto* iii2s = Function(Type::Signed)(Type::Int, Type::Int, Type::Int); |
286 auto* iiii2i = | 285 auto* iiii2s = |
287 Function(Type::Int)(Type::Int, Type::Int, Type::Int, Type::Int); | 286 Function(Type::Signed)(Type::Int, Type::Int, Type::Int, Type::Int); |
288 | 287 |
289 EXPECT_EQ(Type::Int(), | 288 EXPECT_EQ(Type::Signed(), |
290 min_max_int->AsCallableType()->ValidateCall(min_max_int)); | 289 min_max_int->AsCallableType()->ValidateCall(min_max_int)); |
291 EXPECT_EQ(Type::Int(), min_max_int->AsCallableType()->ValidateCall(ii2i)); | 290 EXPECT_EQ(Type::Signed(), min_max_int->AsCallableType()->ValidateCall(ii2s)); |
292 EXPECT_EQ(Type::Int(), min_max_int->AsCallableType()->ValidateCall(iii2i)); | 291 EXPECT_EQ(Type::Signed(), min_max_int->AsCallableType()->ValidateCall(iii2s)); |
293 EXPECT_EQ(Type::Int(), min_max_int->AsCallableType()->ValidateCall(iiii2i)); | 292 EXPECT_EQ(Type::Signed(), |
294 EXPECT_EQ(Type::None(), min_max_int->AsCallableType()->ValidateCall(i2i)); | 293 min_max_int->AsCallableType()->ValidateCall(iiii2s)); |
| 294 EXPECT_EQ(Type::None(), min_max_int->AsCallableType()->ValidateCall(i2s)); |
295 | 295 |
296 auto* min_max_double = Type::MinMaxType(zone(), Type::Double()); | 296 auto* min_max_double = |
| 297 Type::MinMaxType(zone(), Type::Double(), Type::Double()); |
297 auto* d2d = Function(Type::Double)(Type::Double); | 298 auto* d2d = Function(Type::Double)(Type::Double); |
298 auto* dd2d = Function(Type::Double)(Type::Double, Type::Double); | 299 auto* dd2d = Function(Type::Double)(Type::Double, Type::Double); |
299 auto* ddd2d = | 300 auto* ddd2d = |
300 Function(Type::Double)(Type::Double, Type::Double, Type::Double); | 301 Function(Type::Double)(Type::Double, Type::Double, Type::Double); |
301 auto* dddd2d = Function(Type::Double)(Type::Double, Type::Double, | 302 auto* dddd2d = Function(Type::Double)(Type::Double, Type::Double, |
302 Type::Double, Type::Double); | 303 Type::Double, Type::Double); |
303 EXPECT_EQ(Type::Double(), | 304 EXPECT_EQ(Type::Double(), |
304 min_max_double->AsCallableType()->ValidateCall(min_max_double)); | 305 min_max_double->AsCallableType()->ValidateCall(min_max_double)); |
305 EXPECT_EQ(Type::Double(), | 306 EXPECT_EQ(Type::Double(), |
306 min_max_double->AsCallableType()->ValidateCall(dd2d)); | 307 min_max_double->AsCallableType()->ValidateCall(dd2d)); |
307 EXPECT_EQ(Type::Double(), | 308 EXPECT_EQ(Type::Double(), |
308 min_max_double->AsCallableType()->ValidateCall(ddd2d)); | 309 min_max_double->AsCallableType()->ValidateCall(ddd2d)); |
309 EXPECT_EQ(Type::Double(), | 310 EXPECT_EQ(Type::Double(), |
310 min_max_double->AsCallableType()->ValidateCall(dddd2d)); | 311 min_max_double->AsCallableType()->ValidateCall(dddd2d)); |
311 EXPECT_EQ(Type::None(), min_max_double->AsCallableType()->ValidateCall(d2d)); | 312 EXPECT_EQ(Type::None(), min_max_double->AsCallableType()->ValidateCall(d2d)); |
312 | 313 |
313 auto* min_max = Overload(min_max_int, min_max_double); | 314 auto* min_max = Overload(min_max_int, min_max_double); |
314 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(min_max)); | 315 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(min_max)); |
315 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(i2i)); | 316 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(i2s)); |
316 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(d2d)); | 317 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(d2d)); |
317 EXPECT_EQ(Type::Int(), min_max->AsCallableType()->ValidateCall(min_max_int)); | 318 EXPECT_EQ(Type::Signed(), |
318 EXPECT_EQ(Type::Int(), min_max->AsCallableType()->ValidateCall(ii2i)); | 319 min_max->AsCallableType()->ValidateCall(min_max_int)); |
319 EXPECT_EQ(Type::Int(), min_max->AsCallableType()->ValidateCall(iii2i)); | 320 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall(ii2s)); |
320 EXPECT_EQ(Type::Int(), min_max->AsCallableType()->ValidateCall(iiii2i)); | 321 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall(iii2s)); |
| 322 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall(iiii2s)); |
321 EXPECT_EQ(Type::Double(), | 323 EXPECT_EQ(Type::Double(), |
322 min_max->AsCallableType()->ValidateCall(min_max_double)); | 324 min_max->AsCallableType()->ValidateCall(min_max_double)); |
323 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(dd2d)); | 325 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(dd2d)); |
324 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(ddd2d)); | 326 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(ddd2d)); |
325 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(dddd2d)); | 327 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(dddd2d)); |
326 | 328 |
327 auto* fround_floatish = Type::FroundType(zone(), Type::Floatish()); | 329 auto* fround = Type::FroundType(zone()); |
328 auto* fround_floatq = Type::FroundType(zone(), Type::FloatQ()); | |
329 auto* fround_float = Type::FroundType(zone(), Type::Float()); | |
330 auto* fround_doubleq = Type::FroundType(zone(), Type::DoubleQ()); | |
331 auto* fround_double = Type::FroundType(zone(), Type::Double()); | |
332 auto* fround_signed = Type::FroundType(zone(), Type::Signed()); | |
333 auto* fround_unsigned = Type::FroundType(zone(), Type::Unsigned()); | |
334 auto* fround_fixnum = Type::FroundType(zone(), Type::FixNum()); | |
335 auto* fround = | |
336 Overload(fround_floatish, fround_floatq, fround_float, fround_doubleq, | |
337 fround_double, fround_signed, fround_unsigned, fround_fixnum); | |
338 | 330 |
339 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( | 331 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( |
340 Function(Type::Float)(Type::Floatish))); | 332 Function(Type::Float)(Type::Floatish))); |
341 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( | 333 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( |
342 Function(Type::Float)(Type::FloatQ))); | 334 Function(Type::Float)(Type::FloatQ))); |
343 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( | 335 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( |
344 Function(Type::Float)(Type::Float))); | 336 Function(Type::Float)(Type::Float))); |
345 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( | 337 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( |
346 Function(Type::Float)(Type::DoubleQ))); | 338 Function(Type::Float)(Type::DoubleQ))); |
347 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( | 339 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( |
(...skipping 22 matching lines...) Expand all Loading... |
370 | 362 |
371 TEST_F(AsmTypeTest, IsReturnType) { | 363 TEST_F(AsmTypeTest, IsReturnType) { |
372 Type* test_types[] = { | 364 Type* test_types[] = { |
373 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 365 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
374 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 366 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
375 #undef CREATE | 367 #undef CREATE |
376 Function(Type::Int)(Type::Double), | 368 Function(Type::Int)(Type::Double), |
377 Function(Type::Int)(Type::DoubleQ), | 369 Function(Type::Int)(Type::DoubleQ), |
378 Overload(Function(Type::Int)(Type::Double)), | 370 Overload(Function(Type::Int)(Type::Double)), |
379 Function(Type::Int)(Type::Int, Type::Int), | 371 Function(Type::Int)(Type::Int, Type::Int), |
380 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), | 372 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
381 Type::FroundType(zone(), Type::Int()), | 373 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
382 }; | 374 }; |
383 | 375 |
384 std::unordered_set<Type*> return_types{ | 376 std::unordered_set<Type*> return_types{ |
385 Type::Double(), Type::Signed(), Type::Float(), Type::Void(), | 377 Type::Double(), Type::Signed(), Type::Float(), Type::Void(), |
386 }; | 378 }; |
387 | 379 |
388 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { | 380 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
389 const bool IsReturnType = return_types.count(test_types[ii]); | 381 const bool IsReturnType = return_types.count(test_types[ii]); |
390 EXPECT_EQ(IsReturnType, test_types[ii]->IsReturnType()) | 382 EXPECT_EQ(IsReturnType, test_types[ii]->IsReturnType()) |
391 << test_types[ii]->Name() | 383 << test_types[ii]->Name() |
392 << (IsReturnType ? " is not a return type" : " is a return type"); | 384 << (IsReturnType ? " is not a return type" : " is a return type"); |
393 } | 385 } |
394 } | 386 } |
395 | 387 |
396 TEST_F(AsmTypeTest, IsParameterType) { | 388 TEST_F(AsmTypeTest, IsParameterType) { |
397 Type* test_types[] = { | 389 Type* test_types[] = { |
398 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 390 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
399 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 391 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
400 #undef CREATE | 392 #undef CREATE |
401 Function(Type::Int)(Type::Double), | 393 Function(Type::Int)(Type::Double), |
402 Function(Type::Int)(Type::DoubleQ), | 394 Function(Type::Int)(Type::DoubleQ), |
403 Overload(Function(Type::Int)(Type::Double)), | 395 Overload(Function(Type::Int)(Type::Double)), |
404 Function(Type::Int)(Type::Int, Type::Int), | 396 Function(Type::Int)(Type::Int, Type::Int), |
405 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), | 397 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
406 Type::FroundType(zone(), Type::Int()), | 398 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
407 }; | 399 }; |
408 | 400 |
409 std::unordered_set<Type*> parameter_types{ | 401 std::unordered_set<Type*> parameter_types{ |
410 Type::Double(), Type::Int(), Type::Float(), | 402 Type::Double(), Type::Int(), Type::Float(), |
411 }; | 403 }; |
412 | 404 |
413 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { | 405 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
414 const bool IsParameterType = parameter_types.count(test_types[ii]); | 406 const bool IsParameterType = parameter_types.count(test_types[ii]); |
415 EXPECT_EQ(IsParameterType, test_types[ii]->IsParameterType()) | 407 EXPECT_EQ(IsParameterType, test_types[ii]->IsParameterType()) |
416 << test_types[ii]->Name() | 408 << test_types[ii]->Name() |
417 << (IsParameterType ? " is not a parameter type" | 409 << (IsParameterType ? " is not a parameter type" |
418 : " is a parameter type"); | 410 : " is a parameter type"); |
419 } | 411 } |
420 } | 412 } |
421 | 413 |
422 TEST_F(AsmTypeTest, IsComparableType) { | 414 TEST_F(AsmTypeTest, IsComparableType) { |
423 Type* test_types[] = { | 415 Type* test_types[] = { |
424 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 416 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
425 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 417 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
426 #undef CREATE | 418 #undef CREATE |
427 Function(Type::Int)(Type::Double), | 419 Function(Type::Int)(Type::Double), |
428 Function(Type::Int)(Type::DoubleQ), | 420 Function(Type::Int)(Type::DoubleQ), |
429 Overload(Function(Type::Int)(Type::Double)), | 421 Overload(Function(Type::Int)(Type::Double)), |
430 Function(Type::Int)(Type::Int, Type::Int), | 422 Function(Type::Int)(Type::Int, Type::Int), |
431 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), | 423 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
432 Type::FroundType(zone(), Type::Int()), | 424 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
433 }; | 425 }; |
434 | 426 |
435 std::unordered_set<Type*> comparable_types{ | 427 std::unordered_set<Type*> comparable_types{ |
436 Type::Double(), Type::Signed(), Type::Unsigned(), Type::Float(), | 428 Type::Double(), Type::Signed(), Type::Unsigned(), Type::Float(), |
437 }; | 429 }; |
438 | 430 |
439 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { | 431 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
440 const bool IsComparableType = comparable_types.count(test_types[ii]); | 432 const bool IsComparableType = comparable_types.count(test_types[ii]); |
441 EXPECT_EQ(IsComparableType, test_types[ii]->IsComparableType()) | 433 EXPECT_EQ(IsComparableType, test_types[ii]->IsComparableType()) |
442 << test_types[ii]->Name() | 434 << test_types[ii]->Name() |
443 << (IsComparableType ? " is not a comparable type" | 435 << (IsComparableType ? " is not a comparable type" |
444 : " is a comparable type"); | 436 : " is a comparable type"); |
445 } | 437 } |
446 } | 438 } |
447 | 439 |
448 TEST_F(AsmTypeTest, ElementSizeInBytes) { | 440 TEST_F(AsmTypeTest, ElementSizeInBytes) { |
449 Type* test_types[] = { | 441 Type* test_types[] = { |
450 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 442 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
451 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 443 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
452 #undef CREATE | 444 #undef CREATE |
453 Function(Type::Int)(Type::Double), | 445 Function(Type::Int)(Type::Double), |
454 Function(Type::Int)(Type::DoubleQ), | 446 Function(Type::Int)(Type::DoubleQ), |
455 Overload(Function(Type::Int)(Type::Double)), | 447 Overload(Function(Type::Int)(Type::Double)), |
456 Function(Type::Int)(Type::Int, Type::Int), | 448 Function(Type::Int)(Type::Int, Type::Int), |
457 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), | 449 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
458 Type::FroundType(zone(), Type::Int()), | 450 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
459 }; | 451 }; |
460 | 452 |
461 auto ElementSizeInBytesForType = [](Type* type) -> int32_t { | 453 auto ElementSizeInBytesForType = [](Type* type) -> int32_t { |
462 if (type == Type::Int8Array() || type == Type::Uint8Array()) { | 454 if (type == Type::Int8Array() || type == Type::Uint8Array() || |
| 455 type == Type::Uint8ClampedArray()) { |
463 return 1; | 456 return 1; |
464 } | 457 } |
465 if (type == Type::Int16Array() || type == Type::Uint16Array()) { | 458 if (type == Type::Int16Array() || type == Type::Uint16Array()) { |
466 return 2; | 459 return 2; |
467 } | 460 } |
468 if (type == Type::Int32Array() || type == Type::Uint32Array() || | 461 if (type == Type::Int32Array() || type == Type::Uint32Array() || |
469 type == Type::Float32Array()) { | 462 type == Type::Float32Array()) { |
470 return 4; | 463 return 4; |
471 } | 464 } |
472 if (type == Type::Float64Array()) { | 465 if (type == Type::Float64Array()) { |
(...skipping 10 matching lines...) Expand all Loading... |
483 | 476 |
484 TEST_F(AsmTypeTest, LoadType) { | 477 TEST_F(AsmTypeTest, LoadType) { |
485 Type* test_types[] = { | 478 Type* test_types[] = { |
486 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 479 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
487 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 480 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
488 #undef CREATE | 481 #undef CREATE |
489 Function(Type::Int)(Type::Double), | 482 Function(Type::Int)(Type::Double), |
490 Function(Type::Int)(Type::DoubleQ), | 483 Function(Type::Int)(Type::DoubleQ), |
491 Overload(Function(Type::Int)(Type::Double)), | 484 Overload(Function(Type::Int)(Type::Double)), |
492 Function(Type::Int)(Type::Int, Type::Int), | 485 Function(Type::Int)(Type::Int, Type::Int), |
493 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), | 486 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
494 Type::FroundType(zone(), Type::Int()), | 487 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
495 }; | 488 }; |
496 | 489 |
497 auto LoadTypeForType = [](Type* type) -> Type* { | 490 auto LoadTypeForType = [](Type* type) -> Type* { |
498 if (type == Type::Int8Array() || type == Type::Uint8Array() || | 491 if (type == Type::Int8Array() || type == Type::Uint8Array() || |
499 type == Type::Int16Array() || type == Type::Uint16Array() || | 492 type == Type::Uint8ClampedArray() || type == Type::Int16Array() || |
500 type == Type::Int32Array() || type == Type::Uint32Array()) { | 493 type == Type::Uint16Array() || type == Type::Int32Array() || |
| 494 type == Type::Uint32Array()) { |
501 return Type::Intish(); | 495 return Type::Intish(); |
502 } | 496 } |
503 | 497 |
504 if (type == Type::Float32Array()) { | 498 if (type == Type::Float32Array()) { |
505 return Type::FloatQ(); | 499 return Type::FloatQ(); |
506 } | 500 } |
507 | 501 |
508 if (type == Type::Float64Array()) { | 502 if (type == Type::Float64Array()) { |
509 return Type::DoubleQ(); | 503 return Type::DoubleQ(); |
510 } | 504 } |
511 | 505 |
512 return Type::None(); | 506 return Type::None(); |
513 }; | 507 }; |
514 | 508 |
515 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { | 509 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
516 EXPECT_EQ(LoadTypeForType(test_types[ii]), test_types[ii]->LoadType()); | 510 EXPECT_EQ(LoadTypeForType(test_types[ii]), test_types[ii]->LoadType()); |
517 } | 511 } |
518 } | 512 } |
519 | 513 |
520 TEST_F(AsmTypeTest, StoreType) { | 514 TEST_F(AsmTypeTest, StoreType) { |
521 Type* test_types[] = { | 515 Type* test_types[] = { |
522 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), | 516 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), |
523 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) | 517 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) |
524 #undef CREATE | 518 #undef CREATE |
525 Function(Type::Int)(Type::Double), | 519 Function(Type::Int)(Type::Double), |
526 Function(Type::Int)(Type::DoubleQ), | 520 Function(Type::Int)(Type::DoubleQ), |
527 Overload(Function(Type::Int)(Type::Double)), | 521 Overload(Function(Type::Int)(Type::Double)), |
528 Function(Type::Int)(Type::Int, Type::Int), | 522 Function(Type::Int)(Type::Int, Type::Int), |
529 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), | 523 Type::MinMaxType(zone(), Type::Signed(), Type::Int()), |
530 Type::FroundType(zone(), Type::Int()), | 524 Function(Type::Int)(Type::Float), Type::FroundType(zone()), |
531 }; | 525 }; |
532 | 526 |
533 auto StoreTypeForType = [](Type* type) -> Type* { | 527 auto StoreTypeForType = [](Type* type) -> Type* { |
534 if (type == Type::Int8Array() || type == Type::Uint8Array() || | 528 if (type == Type::Int8Array() || type == Type::Uint8Array() || |
535 type == Type::Int16Array() || type == Type::Uint16Array() || | 529 type == Type::Uint8ClampedArray() || type == Type::Int16Array() || |
536 type == Type::Int32Array() || type == Type::Uint32Array()) { | 530 type == Type::Uint16Array() || type == Type::Int32Array() || |
| 531 type == Type::Uint32Array()) { |
537 return Type::Intish(); | 532 return Type::Intish(); |
538 } | 533 } |
539 | 534 |
540 if (type == Type::Float32Array()) { | 535 if (type == Type::Float32Array()) { |
541 return Type::FloatishDoubleQ(); | 536 return Type::FloatishDoubleQ(); |
542 } | 537 } |
543 | 538 |
544 if (type == Type::Float64Array()) { | 539 if (type == Type::Float64Array()) { |
545 return Type::FloatQDoubleQ(); | 540 return Type::FloatQDoubleQ(); |
546 } | 541 } |
547 | 542 |
548 return Type::None(); | 543 return Type::None(); |
549 }; | 544 }; |
550 | 545 |
551 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { | 546 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { |
552 EXPECT_EQ(StoreTypeForType(test_types[ii]), test_types[ii]->StoreType()) | 547 EXPECT_EQ(StoreTypeForType(test_types[ii]), test_types[ii]->StoreType()) |
553 << test_types[ii]->Name(); | 548 << test_types[ii]->Name(); |
554 } | 549 } |
555 } | 550 } |
556 | 551 |
557 } // namespace | 552 } // namespace |
558 } // namespace wasm | 553 } // namespace wasm |
559 } // namespace internal | 554 } // namespace internal |
560 } // namespace v8 | 555 } // namespace v8 |
OLD | NEW |