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

Side by Side Diff: test/unittests/wasm/asm-types-unittest.cc

Issue 2078053002: V8. ASM-2-WASM. Another asm-types.h revision. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: removes TODOs 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
« src/wasm/asm-types.h ('K') | « src/wasm/asm-types.cc ('k') | no next file » | 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/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"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 #undef V 209 #undef V
210 210
211 EXPECT_THAT(Function(Type::Int)(Type::Double, Type::Float)->Name(), 211 EXPECT_THAT(Function(Type::Int)(Type::Double, Type::Float)->Name(),
212 StrEq("(double, float) -> int")); 212 StrEq("(double, float) -> int"));
213 213
214 EXPECT_THAT(Overload(Function(Type::Int)(Type::Double, Type::Float), 214 EXPECT_THAT(Overload(Function(Type::Int)(Type::Double, Type::Float),
215 Function(Type::Int)(Type::Int)) 215 Function(Type::Int)(Type::Int))
216 ->Name(), 216 ->Name(),
217 StrEq("(double, float) -> int /\\ (int) -> int")); 217 StrEq("(double, float) -> int /\\ (int) -> int"));
218 218
219 EXPECT_THAT(Type::FroundType(zone(), Type::Int())->Name(), 219 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 220
226 EXPECT_THAT(Type::MinMaxType(zone(), Type::Int())->Name(), 221 EXPECT_THAT(Type::MinMaxType(zone(), Type::Signed(), Type::Int())->Name(),
227 StrEq("(int, int...) -> int")); 222 StrEq("(int, int...) -> signed"));
228 EXPECT_THAT(Type::MinMaxType(zone(), Type::Floatish())->Name(), 223 EXPECT_THAT(Type::MinMaxType(zone(), Type::Float(), Type::Floatish())->Name(),
229 StrEq("(floatish, floatish...) -> floatish")); 224 StrEq("(floatish, floatish...) -> float"));
230 EXPECT_THAT(Type::MinMaxType(zone(), Type::DoubleQ())->Name(), 225 EXPECT_THAT(Type::MinMaxType(zone(), Type::Double(), Type::DoubleQ())->Name(),
231 StrEq("(double?, double?...) -> double?")); 226 StrEq("(double?, double?...) -> double"));
227
228 EXPECT_THAT(Type::FFIType(zone())->Name(), StrEq("Function"));
229
230 EXPECT_THAT(Type::FunctionTableType(zone(), 4)->Name(),
231 StrEq("[unbound][4]"));
232 auto* ft = Type::FunctionTableType(zone(), 15);
233 ft->AsFunctionTableType()->set_signature(Function(Type::Double)(Type::Int));
234 EXPECT_THAT(ft->Name(), StrEq("(int) -> double[15]"));
232 } 235 }
233 236
234 TEST_F(AsmTypeTest, IsExactly) { 237 TEST_F(AsmTypeTest, IsExactly) {
235 Type* test_types[] = { 238 Type* test_types[] = {
236 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), 239 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
237 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) 240 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
238 #undef CREATE 241 #undef CREATE
239 Function(Type::Int)(Type::Double), 242 Function(Type::Int)(Type::Double),
240 Function(Type::Int)(Type::DoubleQ), 243 Function(Type::Int)(Type::DoubleQ),
241 Overload(Function(Type::Int)(Type::Double)), 244 Overload(Function(Type::Int)(Type::Double)),
242 Function(Type::Int)(Type::Int, Type::Int), 245 Function(Type::Int)(Type::Int, Type::Int),
243 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), 246 Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
244 Type::FroundType(zone(), Type::Int()), 247 Function(Type::Int)(Type::Float), Type::FroundType(zone()),
248 Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
245 }; 249 };
246 250
247 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { 251 for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
248 for (size_t jj = 0; jj < arraysize(test_types); ++jj) { 252 for (size_t jj = 0; jj < arraysize(test_types); ++jj) {
249 EXPECT_EQ(ii == jj, test_types[ii]->IsExactly(test_types[jj])) 253 EXPECT_EQ(ii == jj, test_types[ii]->IsExactly(test_types[jj]))
250 << test_types[ii]->Name() 254 << test_types[ii]->Name()
251 << ((ii == jj) ? " is not exactly " : " is exactly ") 255 << ((ii == jj) ? " is not exactly " : " is exactly ")
252 << test_types[jj]->Name(); 256 << test_types[jj]->Name();
253 } 257 }
254 } 258 }
255 } 259 }
256 260
257 TEST_F(AsmTypeTest, IsA) { 261 TEST_F(AsmTypeTest, IsA) {
258 Type* test_types[] = { 262 Type* test_types[] = {
259 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), 263 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
260 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) 264 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
261 #undef CREATE 265 #undef CREATE
262 Function(Type::Int)(Type::Double), 266 Function(Type::Int)(Type::Double),
263 Function(Type::Int)(Type::DoubleQ), 267 Function(Type::Int)(Type::DoubleQ),
264 Overload(Function(Type::Int)(Type::Double)), 268 Overload(Function(Type::Int)(Type::Double)),
265 Function(Type::Int)(Type::Int, Type::Int), 269 Function(Type::Int)(Type::Int, Type::Int),
266 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), 270 Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
267 Type::FroundType(zone(), Type::Int()), 271 Function(Type::Int)(Type::Float), Type::FroundType(zone()),
272 Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
268 }; 273 };
269 274
270 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { 275 for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
271 for (size_t jj = 0; jj < arraysize(test_types); ++jj) { 276 for (size_t jj = 0; jj < arraysize(test_types); ++jj) {
272 const bool Expected = 277 const bool Expected =
273 (ii == jj) || ParentsOf(test_types[ii]).count(test_types[jj]) != 0; 278 (ii == jj) || ParentsOf(test_types[ii]).count(test_types[jj]) != 0;
274 EXPECT_EQ(Expected, test_types[ii]->IsA(test_types[jj])) 279 EXPECT_EQ(Expected, test_types[ii]->IsA(test_types[jj]))
275 << test_types[ii]->Name() << (Expected ? " is not a " : " is a ") 280 << test_types[ii]->Name() << (Expected ? " is not a " : " is a ")
276 << test_types[jj]->Name(); 281 << test_types[jj]->Name();
277 } 282 }
278 } 283 }
279 } 284 }
280 285
281 TEST_F(AsmTypeTest, ValidateCall) { 286 TEST_F(AsmTypeTest, ValidateCall) {
282 auto* min_max_int = Type::MinMaxType(zone(), Type::Int()); 287 auto* min_max_int = Type::MinMaxType(zone(), Type::Signed(), Type::Int());
283 auto* i2i = Function(Type::Int)(Type::Int); 288 auto* i2s = Function(Type::Signed)(Type::Int);
284 auto* ii2i = Function(Type::Int)(Type::Int, Type::Int); 289 auto* ii2s = Function(Type::Signed)(Type::Int, Type::Int);
285 auto* iii2i = Function(Type::Int)(Type::Int, Type::Int, Type::Int); 290 auto* iii2s = Function(Type::Signed)(Type::Int, Type::Int, Type::Int);
286 auto* iiii2i = 291 auto* iiii2s =
287 Function(Type::Int)(Type::Int, Type::Int, Type::Int, Type::Int); 292 Function(Type::Signed)(Type::Int, Type::Int, Type::Int, Type::Int);
288 293
289 EXPECT_EQ(Type::Int(), 294 EXPECT_EQ(Type::Signed(),
290 min_max_int->AsCallableType()->ValidateCall(min_max_int)); 295 min_max_int->AsCallableType()->ValidateCall(min_max_int));
291 EXPECT_EQ(Type::Int(), min_max_int->AsCallableType()->ValidateCall(ii2i)); 296 EXPECT_EQ(Type::Signed(), min_max_int->AsCallableType()->ValidateCall(ii2s));
292 EXPECT_EQ(Type::Int(), min_max_int->AsCallableType()->ValidateCall(iii2i)); 297 EXPECT_EQ(Type::Signed(), min_max_int->AsCallableType()->ValidateCall(iii2s));
293 EXPECT_EQ(Type::Int(), min_max_int->AsCallableType()->ValidateCall(iiii2i)); 298 EXPECT_EQ(Type::Signed(),
294 EXPECT_EQ(Type::None(), min_max_int->AsCallableType()->ValidateCall(i2i)); 299 min_max_int->AsCallableType()->ValidateCall(iiii2s));
300 EXPECT_EQ(Type::None(), min_max_int->AsCallableType()->ValidateCall(i2s));
295 301
296 auto* min_max_double = Type::MinMaxType(zone(), Type::Double()); 302 auto* min_max_double =
303 Type::MinMaxType(zone(), Type::Double(), Type::Double());
297 auto* d2d = Function(Type::Double)(Type::Double); 304 auto* d2d = Function(Type::Double)(Type::Double);
298 auto* dd2d = Function(Type::Double)(Type::Double, Type::Double); 305 auto* dd2d = Function(Type::Double)(Type::Double, Type::Double);
299 auto* ddd2d = 306 auto* ddd2d =
300 Function(Type::Double)(Type::Double, Type::Double, Type::Double); 307 Function(Type::Double)(Type::Double, Type::Double, Type::Double);
301 auto* dddd2d = Function(Type::Double)(Type::Double, Type::Double, 308 auto* dddd2d = Function(Type::Double)(Type::Double, Type::Double,
302 Type::Double, Type::Double); 309 Type::Double, Type::Double);
303 EXPECT_EQ(Type::Double(), 310 EXPECT_EQ(Type::Double(),
304 min_max_double->AsCallableType()->ValidateCall(min_max_double)); 311 min_max_double->AsCallableType()->ValidateCall(min_max_double));
305 EXPECT_EQ(Type::Double(), 312 EXPECT_EQ(Type::Double(),
306 min_max_double->AsCallableType()->ValidateCall(dd2d)); 313 min_max_double->AsCallableType()->ValidateCall(dd2d));
307 EXPECT_EQ(Type::Double(), 314 EXPECT_EQ(Type::Double(),
308 min_max_double->AsCallableType()->ValidateCall(ddd2d)); 315 min_max_double->AsCallableType()->ValidateCall(ddd2d));
309 EXPECT_EQ(Type::Double(), 316 EXPECT_EQ(Type::Double(),
310 min_max_double->AsCallableType()->ValidateCall(dddd2d)); 317 min_max_double->AsCallableType()->ValidateCall(dddd2d));
311 EXPECT_EQ(Type::None(), min_max_double->AsCallableType()->ValidateCall(d2d)); 318 EXPECT_EQ(Type::None(), min_max_double->AsCallableType()->ValidateCall(d2d));
312 319
313 auto* min_max = Overload(min_max_int, min_max_double); 320 auto* min_max = Overload(min_max_int, min_max_double);
314 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(min_max)); 321 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(min_max));
315 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(i2i)); 322 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(i2s));
316 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(d2d)); 323 EXPECT_EQ(Type::None(), min_max->AsCallableType()->ValidateCall(d2d));
317 EXPECT_EQ(Type::Int(), min_max->AsCallableType()->ValidateCall(min_max_int)); 324 EXPECT_EQ(Type::Signed(),
318 EXPECT_EQ(Type::Int(), min_max->AsCallableType()->ValidateCall(ii2i)); 325 min_max->AsCallableType()->ValidateCall(min_max_int));
319 EXPECT_EQ(Type::Int(), min_max->AsCallableType()->ValidateCall(iii2i)); 326 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall(ii2s));
320 EXPECT_EQ(Type::Int(), min_max->AsCallableType()->ValidateCall(iiii2i)); 327 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall(iii2s));
328 EXPECT_EQ(Type::Signed(), min_max->AsCallableType()->ValidateCall(iiii2s));
321 EXPECT_EQ(Type::Double(), 329 EXPECT_EQ(Type::Double(),
322 min_max->AsCallableType()->ValidateCall(min_max_double)); 330 min_max->AsCallableType()->ValidateCall(min_max_double));
323 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(dd2d)); 331 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(dd2d));
324 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(ddd2d)); 332 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(ddd2d));
325 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(dddd2d)); 333 EXPECT_EQ(Type::Double(), min_max->AsCallableType()->ValidateCall(dddd2d));
326 334
327 auto* fround_floatish = Type::FroundType(zone(), Type::Floatish()); 335 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 336
339 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( 337 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall(
340 Function(Type::Float)(Type::Floatish))); 338 Function(Type::Float)(Type::Floatish)));
341 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( 339 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall(
342 Function(Type::Float)(Type::FloatQ))); 340 Function(Type::Float)(Type::FloatQ)));
343 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( 341 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall(
344 Function(Type::Float)(Type::Float))); 342 Function(Type::Float)(Type::Float)));
345 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( 343 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall(
346 Function(Type::Float)(Type::DoubleQ))); 344 Function(Type::Float)(Type::DoubleQ)));
347 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall( 345 EXPECT_EQ(Type::Float(), fround->AsCallableType()->ValidateCall(
(...skipping 11 matching lines...) Expand all
359 auto* fi2d = Function(Type::Double)(Type::Float, Type::Int); 357 auto* fi2d = Function(Type::Double)(Type::Float, Type::Int);
360 auto* idif2i = 358 auto* idif2i =
361 Function(Type::Int)(Type::Int, Type::Double, Type::Int, Type::Float); 359 Function(Type::Int)(Type::Int, Type::Double, Type::Int, Type::Float);
362 auto* overload = Overload(idf2v, i2f, /*i2d missing, */ fi2d, idif2i); 360 auto* overload = Overload(idf2v, i2f, /*i2d missing, */ fi2d, idif2i);
363 EXPECT_EQ(Type::Void(), overload->AsCallableType()->ValidateCall(idf2v)); 361 EXPECT_EQ(Type::Void(), overload->AsCallableType()->ValidateCall(idf2v));
364 EXPECT_EQ(Type::Float(), overload->AsCallableType()->ValidateCall(i2f)); 362 EXPECT_EQ(Type::Float(), overload->AsCallableType()->ValidateCall(i2f));
365 EXPECT_EQ(Type::Double(), overload->AsCallableType()->ValidateCall(fi2d)); 363 EXPECT_EQ(Type::Double(), overload->AsCallableType()->ValidateCall(fi2d));
366 EXPECT_EQ(Type::Int(), overload->AsCallableType()->ValidateCall(idif2i)); 364 EXPECT_EQ(Type::Int(), overload->AsCallableType()->ValidateCall(idif2i));
367 EXPECT_EQ(Type::None(), overload->AsCallableType()->ValidateCall(i2d)); 365 EXPECT_EQ(Type::None(), overload->AsCallableType()->ValidateCall(i2d));
368 EXPECT_EQ(Type::None(), i2f->AsCallableType()->ValidateCall(i2d)); 366 EXPECT_EQ(Type::None(), i2f->AsCallableType()->ValidateCall(i2d));
367
368 auto* ffi = Type::FFIType(zone());
369 AsmType* (*kReturnTypes[])() = {
370 Type::Void, Type::Double, Type::Signed,
371 };
372 AsmType* (*kExternTypes[])() = {
373 Type::Double, Type::Signed, Type::FixNum,
374 };
375 for (size_t ii = 0; ii < arraysize(kReturnTypes); ++ii) {
376 for (size_t jj = 0; jj < arraysize(kExternTypes); ++jj) {
377 auto* f = Function(kReturnTypes[ii])(kExternTypes[jj]);
378 EXPECT_EQ(kReturnTypes[ii](), ffi->AsCallableType()->ValidateCall(f))
379 << kReturnTypes[ii]()->Name();
380
381 // Call with extern type should fail.
382 f = Function(kReturnTypes[ii])(kExternTypes[jj], Type::Int);
383 EXPECT_EQ(Type::None(), ffi->AsCallableType()->ValidateCall(f))
384 << kReturnTypes[ii]()->Name();
385 }
386 }
387
388 auto* ft0 = Type::FunctionTableType(zone(), 10);
389 ft0->AsFunctionTableType()->set_signature(fi2d);
390 EXPECT_EQ(Type::Double(), ft0->AsCallableType()->ValidateCall(fi2d));
391 EXPECT_EQ(Type::None(), ft0->AsCallableType()->ValidateCall(i2d));
392
393 auto* ft1 = Type::FunctionTableType(zone(), 10);
394 EXPECT_EQ(Type::Double(), ft1->AsCallableType()->ValidateCall(fi2d));
395 EXPECT_EQ(Type::Double(), ft1->AsCallableType()->ValidateCall(fi2d));
396 EXPECT_EQ(Type::None(), ft1->AsCallableType()->ValidateCall(i2d));
397 }
398
399 TEST_F(AsmTypeTest, ToReturnType) {
400 std::unordered_map<AsmType*, AsmType*> kToReturnType = {
401 {Type::Signed(), Type::Signed()}, {Type::FixNum(), Type::Signed()},
402 {Type::Double(), Type::Double()}, {Type::Float(), Type::Float()},
403 {Type::Void(), Type::Void()},
404 };
405
406 Type* test_types[] = {
407 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
408 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
409 #undef CREATE
410 Function(Type::Int)(Type::Double),
411 Function(Type::Int)(Type::DoubleQ),
412 Overload(Function(Type::Int)(Type::Double)),
413 Function(Type::Int)(Type::Int, Type::Int),
414 Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
415 Function(Type::Int)(Type::Float), Type::FroundType(zone()),
416 Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
417 };
418
419 for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
420 auto* return_type = Type::None();
421 auto to_return_type_iter = kToReturnType.find(test_types[ii]);
422 if (to_return_type_iter != kToReturnType.end()) {
423 return_type = to_return_type_iter->second;
424 }
425 EXPECT_EQ(return_type, test_types[ii]->ToReturnType())
426 << return_type->Name() << " != " << test_types[ii]->ToReturnType();
427 }
369 } 428 }
370 429
371 TEST_F(AsmTypeTest, IsReturnType) { 430 TEST_F(AsmTypeTest, IsReturnType) {
372 Type* test_types[] = { 431 Type* test_types[] = {
373 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), 432 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
374 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) 433 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
375 #undef CREATE 434 #undef CREATE
376 Function(Type::Int)(Type::Double), 435 Function(Type::Int)(Type::Double),
377 Function(Type::Int)(Type::DoubleQ), 436 Function(Type::Int)(Type::DoubleQ),
378 Overload(Function(Type::Int)(Type::Double)), 437 Overload(Function(Type::Int)(Type::Double)),
379 Function(Type::Int)(Type::Int, Type::Int), 438 Function(Type::Int)(Type::Int, Type::Int),
380 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), 439 Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
381 Type::FroundType(zone(), Type::Int()), 440 Function(Type::Int)(Type::Float), Type::FroundType(zone()),
441 Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
382 }; 442 };
383 443
384 std::unordered_set<Type*> return_types{ 444 std::unordered_set<Type*> return_types{
385 Type::Double(), Type::Signed(), Type::Float(), Type::Void(), 445 Type::Double(), Type::Signed(), Type::Float(), Type::Void(),
386 }; 446 };
387 447
388 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { 448 for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
389 const bool IsReturnType = return_types.count(test_types[ii]); 449 const bool IsReturnType = return_types.count(test_types[ii]);
390 EXPECT_EQ(IsReturnType, test_types[ii]->IsReturnType()) 450 EXPECT_EQ(IsReturnType, test_types[ii]->IsReturnType())
391 << test_types[ii]->Name() 451 << test_types[ii]->Name()
392 << (IsReturnType ? " is not a return type" : " is a return type"); 452 << (IsReturnType ? " is not a return type" : " is a return type");
393 } 453 }
394 } 454 }
395 455
456 TEST_F(AsmTypeTest, ToParameterType) {
457 std::unordered_map<AsmType*, AsmType*> kToParameterType = {
458 {Type::Int(), Type::Int()}, {Type::Signed(), Type::Int()},
459 {Type::Unsigned(), Type::Int()}, {Type::FixNum(), Type::Int()},
460 {Type::Double(), Type::Double()}, {Type::Float(), Type::Float()},
461 };
462
463 Type* test_types[] = {
464 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
465 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
466 #undef CREATE
467 Function(Type::Int)(Type::Double),
468 Function(Type::Int)(Type::DoubleQ),
469 Overload(Function(Type::Int)(Type::Double)),
470 Function(Type::Int)(Type::Int, Type::Int),
471 Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
472 Function(Type::Int)(Type::Float), Type::FroundType(zone()),
473 Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
474 };
475
476 for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
477 auto* parameter_type = Type::None();
478 auto to_parameter_type_iter = kToParameterType.find(test_types[ii]);
479 if (to_parameter_type_iter != kToParameterType.end()) {
480 parameter_type = to_parameter_type_iter->second;
481 }
482 EXPECT_EQ(parameter_type, test_types[ii]->ToParameterType())
483 << parameter_type->Name()
484 << " != " << test_types[ii]->ToParameterType();
485 }
486 }
487
396 TEST_F(AsmTypeTest, IsParameterType) { 488 TEST_F(AsmTypeTest, IsParameterType) {
397 Type* test_types[] = { 489 Type* test_types[] = {
398 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), 490 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
399 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) 491 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
400 #undef CREATE 492 #undef CREATE
401 Function(Type::Int)(Type::Double), 493 Function(Type::Int)(Type::Double),
402 Function(Type::Int)(Type::DoubleQ), 494 Function(Type::Int)(Type::DoubleQ),
403 Overload(Function(Type::Int)(Type::Double)), 495 Overload(Function(Type::Int)(Type::Double)),
404 Function(Type::Int)(Type::Int, Type::Int), 496 Function(Type::Int)(Type::Int, Type::Int),
405 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), 497 Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
406 Type::FroundType(zone(), Type::Int()), 498 Function(Type::Int)(Type::Float), Type::FroundType(zone()),
499 Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
407 }; 500 };
408 501
409 std::unordered_set<Type*> parameter_types{ 502 std::unordered_set<Type*> parameter_types{
410 Type::Double(), Type::Int(), Type::Float(), 503 Type::Double(), Type::Int(), Type::Float(),
411 }; 504 };
412 505
413 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { 506 for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
414 const bool IsParameterType = parameter_types.count(test_types[ii]); 507 const bool IsParameterType = parameter_types.count(test_types[ii]);
415 EXPECT_EQ(IsParameterType, test_types[ii]->IsParameterType()) 508 EXPECT_EQ(IsParameterType, test_types[ii]->IsParameterType())
416 << test_types[ii]->Name() 509 << test_types[ii]->Name()
417 << (IsParameterType ? " is not a parameter type" 510 << (IsParameterType ? " is not a parameter type"
418 : " is a parameter type"); 511 : " is a parameter type");
419 } 512 }
420 } 513 }
421 514
422 TEST_F(AsmTypeTest, IsComparableType) { 515 TEST_F(AsmTypeTest, IsComparableType) {
423 Type* test_types[] = { 516 Type* test_types[] = {
424 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), 517 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
425 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) 518 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
426 #undef CREATE 519 #undef CREATE
427 Function(Type::Int)(Type::Double), 520 Function(Type::Int)(Type::Double),
428 Function(Type::Int)(Type::DoubleQ), 521 Function(Type::Int)(Type::DoubleQ),
429 Overload(Function(Type::Int)(Type::Double)), 522 Overload(Function(Type::Int)(Type::Double)),
430 Function(Type::Int)(Type::Int, Type::Int), 523 Function(Type::Int)(Type::Int, Type::Int),
431 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), 524 Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
432 Type::FroundType(zone(), Type::Int()), 525 Function(Type::Int)(Type::Float), Type::FroundType(zone()),
526 Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
433 }; 527 };
434 528
435 std::unordered_set<Type*> comparable_types{ 529 std::unordered_set<Type*> comparable_types{
436 Type::Double(), Type::Signed(), Type::Unsigned(), Type::Float(), 530 Type::Double(), Type::Signed(), Type::Unsigned(), Type::Float(),
437 }; 531 };
438 532
439 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { 533 for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
440 const bool IsComparableType = comparable_types.count(test_types[ii]); 534 const bool IsComparableType = comparable_types.count(test_types[ii]);
441 EXPECT_EQ(IsComparableType, test_types[ii]->IsComparableType()) 535 EXPECT_EQ(IsComparableType, test_types[ii]->IsComparableType())
442 << test_types[ii]->Name() 536 << test_types[ii]->Name()
443 << (IsComparableType ? " is not a comparable type" 537 << (IsComparableType ? " is not a comparable type"
444 : " is a comparable type"); 538 : " is a comparable type");
445 } 539 }
446 } 540 }
447 541
448 TEST_F(AsmTypeTest, ElementSizeInBytes) { 542 TEST_F(AsmTypeTest, ElementSizeInBytes) {
449 Type* test_types[] = { 543 Type* test_types[] = {
450 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), 544 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
451 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) 545 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
452 #undef CREATE 546 #undef CREATE
453 Function(Type::Int)(Type::Double), 547 Function(Type::Int)(Type::Double),
454 Function(Type::Int)(Type::DoubleQ), 548 Function(Type::Int)(Type::DoubleQ),
455 Overload(Function(Type::Int)(Type::Double)), 549 Overload(Function(Type::Int)(Type::Double)),
456 Function(Type::Int)(Type::Int, Type::Int), 550 Function(Type::Int)(Type::Int, Type::Int),
457 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), 551 Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
458 Type::FroundType(zone(), Type::Int()), 552 Function(Type::Int)(Type::Float), Type::FroundType(zone()),
553 Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
459 }; 554 };
460 555
461 auto ElementSizeInBytesForType = [](Type* type) -> int32_t { 556 auto ElementSizeInBytesForType = [](Type* type) -> int32_t {
462 if (type == Type::Int8Array() || type == Type::Uint8Array()) { 557 if (type == Type::Int8Array() || type == Type::Uint8Array()) {
463 return 1; 558 return 1;
464 } 559 }
465 if (type == Type::Int16Array() || type == Type::Uint16Array()) { 560 if (type == Type::Int16Array() || type == Type::Uint16Array()) {
466 return 2; 561 return 2;
467 } 562 }
468 if (type == Type::Int32Array() || type == Type::Uint32Array() || 563 if (type == Type::Int32Array() || type == Type::Uint32Array() ||
(...skipping 14 matching lines...) Expand all
483 578
484 TEST_F(AsmTypeTest, LoadType) { 579 TEST_F(AsmTypeTest, LoadType) {
485 Type* test_types[] = { 580 Type* test_types[] = {
486 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), 581 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
487 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) 582 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
488 #undef CREATE 583 #undef CREATE
489 Function(Type::Int)(Type::Double), 584 Function(Type::Int)(Type::Double),
490 Function(Type::Int)(Type::DoubleQ), 585 Function(Type::Int)(Type::DoubleQ),
491 Overload(Function(Type::Int)(Type::Double)), 586 Overload(Function(Type::Int)(Type::Double)),
492 Function(Type::Int)(Type::Int, Type::Int), 587 Function(Type::Int)(Type::Int, Type::Int),
493 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), 588 Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
494 Type::FroundType(zone(), Type::Int()), 589 Function(Type::Int)(Type::Float), Type::FroundType(zone()),
590 Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
495 }; 591 };
496 592
497 auto LoadTypeForType = [](Type* type) -> Type* { 593 auto LoadTypeForType = [](Type* type) -> Type* {
498 if (type == Type::Int8Array() || type == Type::Uint8Array() || 594 if (type == Type::Int8Array() || type == Type::Uint8Array() ||
499 type == Type::Int16Array() || type == Type::Uint16Array() || 595 type == Type::Int16Array() || type == Type::Uint16Array() ||
500 type == Type::Int32Array() || type == Type::Uint32Array()) { 596 type == Type::Int32Array() || type == Type::Uint32Array()) {
501 return Type::Intish(); 597 return Type::Intish();
502 } 598 }
503 599
504 if (type == Type::Float32Array()) { 600 if (type == Type::Float32Array()) {
(...skipping 14 matching lines...) Expand all
519 615
520 TEST_F(AsmTypeTest, StoreType) { 616 TEST_F(AsmTypeTest, StoreType) {
521 Type* test_types[] = { 617 Type* test_types[] = {
522 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(), 618 #define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
523 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE) 619 FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
524 #undef CREATE 620 #undef CREATE
525 Function(Type::Int)(Type::Double), 621 Function(Type::Int)(Type::Double),
526 Function(Type::Int)(Type::DoubleQ), 622 Function(Type::Int)(Type::DoubleQ),
527 Overload(Function(Type::Int)(Type::Double)), 623 Overload(Function(Type::Int)(Type::Double)),
528 Function(Type::Int)(Type::Int, Type::Int), 624 Function(Type::Int)(Type::Int, Type::Int),
529 Type::MinMaxType(zone(), Type::Int()), Function(Type::Int)(Type::Float), 625 Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
530 Type::FroundType(zone(), Type::Int()), 626 Function(Type::Int)(Type::Float), Type::FroundType(zone()),
627 Type::FFIType(zone()), Type::FunctionTableType(zone(), 10),
531 }; 628 };
532 629
533 auto StoreTypeForType = [](Type* type) -> Type* { 630 auto StoreTypeForType = [](Type* type) -> Type* {
534 if (type == Type::Int8Array() || type == Type::Uint8Array() || 631 if (type == Type::Int8Array() || type == Type::Uint8Array() ||
535 type == Type::Int16Array() || type == Type::Uint16Array() || 632 type == Type::Int16Array() || type == Type::Uint16Array() ||
536 type == Type::Int32Array() || type == Type::Uint32Array()) { 633 type == Type::Int32Array() || type == Type::Uint32Array()) {
537 return Type::Intish(); 634 return Type::Intish();
538 } 635 }
539 636
540 if (type == Type::Float32Array()) { 637 if (type == Type::Float32Array()) {
(...skipping 10 matching lines...) Expand all
551 for (size_t ii = 0; ii < arraysize(test_types); ++ii) { 648 for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
552 EXPECT_EQ(StoreTypeForType(test_types[ii]), test_types[ii]->StoreType()) 649 EXPECT_EQ(StoreTypeForType(test_types[ii]), test_types[ii]->StoreType())
553 << test_types[ii]->Name(); 650 << test_types[ii]->Name();
554 } 651 }
555 } 652 }
556 653
557 } // namespace 654 } // namespace
558 } // namespace wasm 655 } // namespace wasm
559 } // namespace internal 656 } // namespace internal
560 } // namespace v8 657 } // namespace v8
OLDNEW
« src/wasm/asm-types.h ('K') | « src/wasm/asm-types.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698