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

Side by Side Diff: test/cctest/wasm/test-run-wasm.cc

Issue 1784343004: [wasm] Refactor tests for i64. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | test/cctest/wasm/test-run-wasm-64.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 <stdint.h> 5 #include <stdint.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "src/wasm/wasm-macro-gen.h" 9 #include "src/wasm/wasm-macro-gen.h"
10 10
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 TEST(Run_WasmMemorySize) { 85 TEST(Run_WasmMemorySize) {
86 TestingModule module; 86 TestingModule module;
87 WasmRunner<int32_t> r(&module); 87 WasmRunner<int32_t> r(&module);
88 module.AddMemory(1024); 88 module.AddMemory(1024);
89 BUILD(r, kExprMemorySize); 89 BUILD(r, kExprMemorySize);
90 CHECK_EQ(1024, r.Call()); 90 CHECK_EQ(1024, r.Call());
91 } 91 }
92 92
93 93
94 #if WASM_64
95 TEST(Run_WasmInt64Const) {
96 WasmRunner<int64_t> r;
97 const int64_t kExpectedValue = 0x1122334455667788LL;
98 // return(kExpectedValue)
99 BUILD(r, WASM_I64V_9(kExpectedValue));
100 CHECK_EQ(kExpectedValue, r.Call());
101 }
102
103
104 TEST(Run_WasmInt64Const_many) {
105 int cntr = 0;
106 FOR_INT32_INPUTS(i) {
107 WasmRunner<int64_t> r;
108 const int64_t kExpectedValue = (static_cast<int64_t>(*i) << 32) | cntr;
109 // return(kExpectedValue)
110 BUILD(r, WASM_I64V(kExpectedValue));
111 CHECK_EQ(kExpectedValue, r.Call());
112 cntr++;
113 }
114 }
115 #endif
116
117
118 TEST(Run_WasmInt32Param0) { 94 TEST(Run_WasmInt32Param0) {
119 WasmRunner<int32_t> r(MachineType::Int32()); 95 WasmRunner<int32_t> r(MachineType::Int32());
120 // return(local[0]) 96 // return(local[0])
121 BUILD(r, WASM_GET_LOCAL(0)); 97 BUILD(r, WASM_GET_LOCAL(0));
122 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } 98 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
123 } 99 }
124 100
125 101
126 TEST(Run_WasmInt32Param0_fallthru) { 102 TEST(Run_WasmInt32Param0_fallthru) {
127 WasmRunner<int32_t> r(MachineType::Int32()); 103 WasmRunner<int32_t> r(MachineType::Int32());
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 309
334 310
335 TEST(Run_WasmInt32Popcnt) { 311 TEST(Run_WasmInt32Popcnt) {
336 TestInt32Unop(kExprI32Popcnt, 32, 0xffffffff); 312 TestInt32Unop(kExprI32Popcnt, 32, 0xffffffff);
337 TestInt32Unop(kExprI32Popcnt, 0, 0x00000000); 313 TestInt32Unop(kExprI32Popcnt, 0, 0x00000000);
338 TestInt32Unop(kExprI32Popcnt, 1, 0x00008000); 314 TestInt32Unop(kExprI32Popcnt, 1, 0x00008000);
339 TestInt32Unop(kExprI32Popcnt, 13, 0x12345678); 315 TestInt32Unop(kExprI32Popcnt, 13, 0x12345678);
340 TestInt32Unop(kExprI32Popcnt, 19, 0xfedcba09); 316 TestInt32Unop(kExprI32Popcnt, 19, 0xfedcba09);
341 } 317 }
342 318
343 319 TEST(Run_WasmI32Eqz) {
344 #if WASM_64 320 TestInt32Unop(kExprI32Eqz, 0, 1);
345 void TestInt64Binop(WasmOpcode opcode, int64_t expected, int64_t a, int64_t b) { 321 TestInt32Unop(kExprI32Eqz, 0, -1);
346 if (!WasmOpcodes::IsSupported(opcode)) return; 322 TestInt32Unop(kExprI32Eqz, 0, -827343);
347 { 323 TestInt32Unop(kExprI32Eqz, 0, 8888888);
348 WasmRunner<int64_t> r; 324 TestInt32Unop(kExprI32Eqz, 1, 0);
349 // return K op K
350 BUILD(r, WASM_BINOP(opcode, WASM_I64V(a), WASM_I64V(b)));
351 CHECK_EQ(expected, r.Call());
352 }
353 {
354 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
355 // return a op b
356 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
357 CHECK_EQ(expected, r.Call(a, b));
358 }
359 } 325 }
360 326
361 327
362 void TestInt64Cmp(WasmOpcode opcode, int64_t expected, int64_t a, int64_t b) {
363 if (!WasmOpcodes::IsSupported(opcode)) return;
364 {
365 WasmRunner<int32_t> r;
366 // return K op K
367 BUILD(r, WASM_BINOP(opcode, WASM_I64V(a), WASM_I64V(b)));
368 CHECK_EQ(expected, r.Call());
369 }
370 {
371 WasmRunner<int32_t> r(MachineType::Int64(), MachineType::Int64());
372 // return a op b
373 BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
374 CHECK_EQ(expected, r.Call(a, b));
375 }
376 }
377
378
379 TEST(Run_WasmInt64Binops) {
380 // TODO(titzer): real 64-bit numbers
381 TestInt64Binop(kExprI64Add, 8888888888888LL, 3333333333333LL,
382 5555555555555LL);
383 TestInt64Binop(kExprI64Sub, -111111111111LL, 777777777777LL, 888888888888LL);
384 TestInt64Binop(kExprI64Mul, 65130756, 88734, 734);
385 TestInt64Binop(kExprI64DivS, -66, -4777344, 72384);
386 TestInt64Binop(kExprI64DivU, 805306368, 0xF0000000, 5);
387 TestInt64Binop(kExprI64RemS, -3, -3003, 1000);
388 TestInt64Binop(kExprI64RemU, 4, 4004, 1000);
389 TestInt64Binop(kExprI64And, 0xEE, 0xFFEE, 0xFF0000FF);
390 TestInt64Binop(kExprI64Ior, 0xF0FF00FF, 0xF0F000EE, 0x000F0011);
391 TestInt64Binop(kExprI64Xor, 0xABCDEF01, 0xABCDEFFF, 0xFE);
392 TestInt64Binop(kExprI64Shl, 0xA0000000, 0xA, 28);
393 TestInt64Binop(kExprI64ShrU, 0x0700001000123456LL, 0x7000010001234567LL, 4);
394 TestInt64Binop(kExprI64ShrS, 0xFF00000000000000LL, 0x8000000000000000LL, 7);
395 TestInt64Binop(kExprI64Ror, 0x0100000000000000LL, 0x8000000000000000LL, 7);
396 TestInt64Binop(kExprI64Ror, 0x0100000000000000LL, 0x8000000000000000LL, 71);
397 TestInt64Binop(kExprI64Rol, 0x0000000000000040LL, 0x8000000000000000LL, 7);
398 TestInt64Binop(kExprI64Rol, 0x0000000000000040LL, 0x8000000000000000LL, 71);
399 TestInt64Cmp(kExprI64Eq, 1, -9999, -9999);
400 TestInt64Cmp(kExprI64Ne, 1, -9199, -9999);
401 TestInt64Cmp(kExprI64LtS, 1, -4, 4);
402 TestInt64Cmp(kExprI64LeS, 0, -2, -3);
403 TestInt64Cmp(kExprI64LtU, 1, 0, -6);
404 TestInt64Cmp(kExprI64LeU, 1, 98978, 0xF0000000);
405 }
406
407
408 TEST(Run_WasmInt64Clz) {
409 struct {
410 int64_t expected;
411 uint64_t input;
412 } values[] = {{0, 0x8000100000000000}, {1, 0x4000050000000000},
413 {2, 0x2000030000000000}, {3, 0x1000000300000000},
414 {4, 0x0805000000000000}, {5, 0x0400600000000000},
415 {6, 0x0200000000000000}, {7, 0x010000a000000000},
416 {8, 0x00800c0000000000}, {9, 0x0040000000000000},
417 {10, 0x0020000d00000000}, {11, 0x00100f0000000000},
418 {12, 0x0008000000000000}, {13, 0x0004100000000000},
419 {14, 0x0002002000000000}, {15, 0x0001030000000000},
420 {16, 0x0000804000000000}, {17, 0x0000400500000000},
421 {18, 0x0000205000000000}, {19, 0x0000170000000000},
422 {20, 0x0000087000000000}, {21, 0x0000040500000000},
423 {22, 0x0000020300000000}, {23, 0x0000010100000000},
424 {24, 0x0000008900000000}, {25, 0x0000004100000000},
425 {26, 0x0000002200000000}, {27, 0x0000001300000000},
426 {28, 0x0000000800000000}, {29, 0x0000000400000000},
427 {30, 0x0000000200000000}, {31, 0x0000000100000000},
428 {32, 0x0000000080001000}, {33, 0x0000000040000500},
429 {34, 0x0000000020000300}, {35, 0x0000000010000003},
430 {36, 0x0000000008050000}, {37, 0x0000000004006000},
431 {38, 0x0000000002000000}, {39, 0x00000000010000a0},
432 {40, 0x0000000000800c00}, {41, 0x0000000000400000},
433 {42, 0x000000000020000d}, {43, 0x0000000000100f00},
434 {44, 0x0000000000080000}, {45, 0x0000000000041000},
435 {46, 0x0000000000020020}, {47, 0x0000000000010300},
436 {48, 0x0000000000008040}, {49, 0x0000000000004005},
437 {50, 0x0000000000002050}, {51, 0x0000000000001700},
438 {52, 0x0000000000000870}, {53, 0x0000000000000405},
439 {54, 0x0000000000000203}, {55, 0x0000000000000101},
440 {56, 0x0000000000000089}, {57, 0x0000000000000041},
441 {58, 0x0000000000000022}, {59, 0x0000000000000013},
442 {60, 0x0000000000000008}, {61, 0x0000000000000004},
443 {62, 0x0000000000000002}, {63, 0x0000000000000001},
444 {64, 0x0000000000000000}};
445
446 WasmRunner<int64_t> r(MachineType::Uint64());
447 BUILD(r, WASM_I64_CLZ(WASM_GET_LOCAL(0)));
448 for (size_t i = 0; i < arraysize(values); i++) {
449 CHECK_EQ(values[i].expected, r.Call(values[i].input));
450 }
451 }
452
453
454 TEST(Run_WasmInt64Ctz) {
455 struct {
456 int64_t expected;
457 uint64_t input;
458 } values[] = {{64, 0x0000000000000000}, {63, 0x8000000000000000},
459 {62, 0x4000000000000000}, {61, 0x2000000000000000},
460 {60, 0x1000000000000000}, {59, 0xa800000000000000},
461 {58, 0xf400000000000000}, {57, 0x6200000000000000},
462 {56, 0x9100000000000000}, {55, 0xcd80000000000000},
463 {54, 0x0940000000000000}, {53, 0xaf20000000000000},
464 {52, 0xac10000000000000}, {51, 0xe0b8000000000000},
465 {50, 0x9ce4000000000000}, {49, 0xc792000000000000},
466 {48, 0xb8f1000000000000}, {47, 0x3b9f800000000000},
467 {46, 0xdb4c400000000000}, {45, 0xe9a3200000000000},
468 {44, 0xfca6100000000000}, {43, 0x6c8a780000000000},
469 {42, 0x8ce5a40000000000}, {41, 0xcb7d020000000000},
470 {40, 0xcb4dc10000000000}, {39, 0xdfbec58000000000},
471 {38, 0x27a9db4000000000}, {37, 0xde3bcb2000000000},
472 {36, 0xd7e8a61000000000}, {35, 0x9afdbc8800000000},
473 {34, 0x9afdbc8400000000}, {33, 0x9afdbc8200000000},
474 {32, 0x9afdbc8100000000}, {31, 0x0000000080000000},
475 {30, 0x0000000040000000}, {29, 0x0000000020000000},
476 {28, 0x0000000010000000}, {27, 0x00000000a8000000},
477 {26, 0x00000000f4000000}, {25, 0x0000000062000000},
478 {24, 0x0000000091000000}, {23, 0x00000000cd800000},
479 {22, 0x0000000009400000}, {21, 0x00000000af200000},
480 {20, 0x00000000ac100000}, {19, 0x00000000e0b80000},
481 {18, 0x000000009ce40000}, {17, 0x00000000c7920000},
482 {16, 0x00000000b8f10000}, {15, 0x000000003b9f8000},
483 {14, 0x00000000db4c4000}, {13, 0x00000000e9a32000},
484 {12, 0x00000000fca61000}, {11, 0x000000006c8a7800},
485 {10, 0x000000008ce5a400}, {9, 0x00000000cb7d0200},
486 {8, 0x00000000cb4dc100}, {7, 0x00000000dfbec580},
487 {6, 0x0000000027a9db40}, {5, 0x00000000de3bcb20},
488 {4, 0x00000000d7e8a610}, {3, 0x000000009afdbc88},
489 {2, 0x000000009afdbc84}, {1, 0x000000009afdbc82},
490 {0, 0x000000009afdbc81}};
491
492 WasmRunner<int64_t> r(MachineType::Uint64());
493 BUILD(r, WASM_I64_CTZ(WASM_GET_LOCAL(0)));
494 for (size_t i = 0; i < arraysize(values); i++) {
495 CHECK_EQ(values[i].expected, r.Call(values[i].input));
496 }
497 }
498
499
500 TEST(Run_WasmInt64Popcnt) {
501 struct {
502 int64_t expected;
503 uint64_t input;
504 } values[] = {{64, 0xffffffffffffffff},
505 {0, 0x0000000000000000},
506 {2, 0x0000080000008000},
507 {26, 0x1123456782345678},
508 {38, 0xffedcba09edcba09}};
509
510 WasmRunner<int64_t> r(MachineType::Uint64());
511 BUILD(r, WASM_I64_POPCNT(WASM_GET_LOCAL(0)));
512 for (size_t i = 0; i < arraysize(values); i++) {
513 CHECK_EQ(values[i].expected, r.Call(values[i].input));
514 }
515 }
516
517
518 #endif
519
520 TEST(Run_WASM_Int32DivS_trap) { 328 TEST(Run_WASM_Int32DivS_trap) {
521 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); 329 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
522 BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 330 BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
523 CHECK_EQ(0, r.Call(0, 100)); 331 CHECK_EQ(0, r.Call(0, 100));
524 CHECK_TRAP(r.Call(100, 0)); 332 CHECK_TRAP(r.Call(100, 0));
525 CHECK_TRAP(r.Call(-1001, 0)); 333 CHECK_TRAP(r.Call(-1001, 0));
526 CHECK_TRAP(r.Call(std::numeric_limits<int32_t>::min(), -1)); 334 CHECK_TRAP(r.Call(std::numeric_limits<int32_t>::min(), -1));
527 CHECK_TRAP(r.Call(std::numeric_limits<int32_t>::min(), 0)); 335 CHECK_TRAP(r.Call(std::numeric_limits<int32_t>::min(), 0));
528 } 336 }
529 337
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), 414 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(),
607 WASM_ZERO, WASM_GET_LOCAL(0)), 415 WASM_ZERO, WASM_GET_LOCAL(0)),
608 WASM_GET_LOCAL(1)))); 416 WASM_GET_LOCAL(1))));
609 CHECK_EQ(0, r.Call(0, 100)); 417 CHECK_EQ(0, r.Call(0, 100));
610 CHECK_TRAP(r.Call(8, 0)); 418 CHECK_TRAP(r.Call(8, 0));
611 CHECK_TRAP(r.Call(4, 0)); 419 CHECK_TRAP(r.Call(4, 0));
612 CHECK_TRAP(r.Call(0, 0)); 420 CHECK_TRAP(r.Call(0, 0));
613 } 421 }
614 422
615 423
616 #if WASM_64
617 #define as64(x) static_cast<int64_t>(x)
618 TEST(Run_WASM_Int64DivS_trap) {
619 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
620 BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
621 CHECK_EQ(0, r.Call(as64(0), as64(100)));
622 CHECK_TRAP64(r.Call(as64(100), as64(0)));
623 CHECK_TRAP64(r.Call(as64(-1001), as64(0)));
624 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), as64(-1)));
625 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), as64(0)));
626 }
627
628
629 TEST(Run_WASM_Int64RemS_trap) {
630 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
631 BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
632 CHECK_EQ(33, r.Call(as64(133), as64(100)));
633 CHECK_EQ(0, r.Call(std::numeric_limits<int64_t>::min(), as64(-1)));
634 CHECK_TRAP64(r.Call(as64(100), as64(0)));
635 CHECK_TRAP64(r.Call(as64(-1001), as64(0)));
636 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), as64(0)));
637 }
638
639
640 TEST(Run_WASM_Int64DivU_trap) {
641 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
642 BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
643 CHECK_EQ(0, r.Call(as64(0), as64(100)));
644 CHECK_EQ(0, r.Call(std::numeric_limits<int64_t>::min(), as64(-1)));
645 CHECK_TRAP64(r.Call(as64(100), as64(0)));
646 CHECK_TRAP64(r.Call(as64(-1001), as64(0)));
647 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), as64(0)));
648 }
649
650
651 TEST(Run_WASM_Int64RemU_trap) {
652 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
653 BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
654 CHECK_EQ(17, r.Call(as64(217), as64(100)));
655 CHECK_TRAP64(r.Call(as64(100), as64(0)));
656 CHECK_TRAP64(r.Call(as64(-1001), as64(0)));
657 CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), as64(0)));
658 CHECK_EQ(std::numeric_limits<int64_t>::min(),
659 r.Call(std::numeric_limits<int64_t>::min(), as64(-1)));
660 }
661
662
663 TEST(Run_WASM_Int64DivS_byzero_const) {
664 for (int8_t denom = -2; denom < 8; denom++) {
665 WasmRunner<int64_t> r(MachineType::Int64());
666 BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(denom)));
667 for (int64_t val = -7; val < 8; val++) {
668 if (denom == 0) {
669 CHECK_TRAP64(r.Call(val));
670 } else {
671 CHECK_EQ(val / denom, r.Call(val));
672 }
673 }
674 }
675 }
676
677
678 TEST(Run_WASM_Int64DivU_byzero_const) {
679 for (uint64_t denom = 0xfffffffffffffffe; denom < 8; denom++) {
680 WasmRunner<uint64_t> r(MachineType::Uint64());
681 BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(denom)));
682
683 for (uint64_t val = 0xfffffffffffffff0; val < 8; val++) {
684 if (denom == 0) {
685 CHECK_TRAP64(r.Call(val));
686 } else {
687 CHECK_EQ(val / denom, r.Call(val));
688 }
689 }
690 }
691 }
692 #endif
693
694
695 void TestFloat32Binop(WasmOpcode opcode, int32_t expected, float a, float b) { 424 void TestFloat32Binop(WasmOpcode opcode, int32_t expected, float a, float b) {
696 { 425 {
697 WasmRunner<int32_t> r; 426 WasmRunner<int32_t> r;
698 // return K op K 427 // return K op K
699 BUILD(r, WASM_BINOP(opcode, WASM_F32(a), WASM_F32(b))); 428 BUILD(r, WASM_BINOP(opcode, WASM_F32(a), WASM_F32(b)));
700 CHECK_EQ(expected, r.Call()); 429 CHECK_EQ(expected, r.Call());
701 } 430 }
702 { 431 {
703 WasmRunner<int32_t> r(MachineType::Float32(), MachineType::Float32()); 432 WasmRunner<int32_t> r(MachineType::Float32(), MachineType::Float32());
704 // return a op b 433 // return a op b
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 626
898 TEST(Run_Wasm_Return_I32) { 627 TEST(Run_Wasm_Return_I32) {
899 WasmRunner<int32_t> r(MachineType::Int32()); 628 WasmRunner<int32_t> r(MachineType::Int32());
900 629
901 BUILD(r, RET(WASM_GET_LOCAL(0))); 630 BUILD(r, RET(WASM_GET_LOCAL(0)));
902 631
903 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } 632 FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
904 } 633 }
905 634
906 635
907 #if WASM_64
908 TEST(Run_Wasm_Return_I64) {
909 WasmRunner<int64_t> r(MachineType::Int64());
910
911 BUILD(r, RET(WASM_GET_LOCAL(0)));
912
913 FOR_INT64_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
914 }
915 #endif
916
917
918 TEST(Run_Wasm_Return_F32) { 636 TEST(Run_Wasm_Return_F32) {
919 WasmRunner<float> r(MachineType::Float32()); 637 WasmRunner<float> r(MachineType::Float32());
920 638
921 BUILD(r, RET(WASM_GET_LOCAL(0))); 639 BUILD(r, RET(WASM_GET_LOCAL(0)));
922 640
923 FOR_FLOAT32_INPUTS(i) { 641 FOR_FLOAT32_INPUTS(i) {
924 float expect = *i; 642 float expect = *i;
925 float result = r.Call(expect); 643 float result = r.Call(expect);
926 if (std::isnan(expect)) { 644 if (std::isnan(expect)) {
927 CHECK(std::isnan(result)); 645 CHECK(std::isnan(result));
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 CHECK_EQ(0, r.Call(boundary)); // in bounds. 1378 CHECK_EQ(0, r.Call(boundary)); // in bounds.
1661 CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize)); 1379 CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize));
1662 1380
1663 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) { 1381 for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) {
1664 CHECK_TRAP(r.Call(offset)); // out of bounds. 1382 CHECK_TRAP(r.Call(offset)); // out of bounds.
1665 } 1383 }
1666 } 1384 }
1667 } 1385 }
1668 1386
1669 1387
1670 #if WASM_64
1671 TEST(Run_Wasm_F64ReinterpretI64) {
1672 TestingModule module;
1673 int64_t* memory = module.AddMemoryElems<int64_t>(8);
1674 WasmRunner<int64_t> r(&module);
1675
1676 BUILD(r, WASM_I64_REINTERPRET_F64(
1677 WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)));
1678
1679 FOR_INT32_INPUTS(i) {
1680 int64_t expected = static_cast<int64_t>(*i) * 0x300010001;
1681 memory[0] = expected;
1682 CHECK_EQ(expected, r.Call());
1683 }
1684 }
1685
1686
1687 TEST(Run_Wasm_I64ReinterpretF64) {
1688 TestingModule module;
1689 int64_t* memory = module.AddMemoryElems<int64_t>(8);
1690 WasmRunner<int64_t> r(&module, MachineType::Int64());
1691
1692 BUILD(r, WASM_BLOCK(
1693 2, WASM_STORE_MEM(MachineType::Float64(), WASM_ZERO,
1694 WASM_F64_REINTERPRET_I64(WASM_GET_LOCAL(0))),
1695 WASM_GET_LOCAL(0)));
1696
1697 FOR_INT32_INPUTS(i) {
1698 int64_t expected = static_cast<int64_t>(*i) * 0x300010001;
1699 CHECK_EQ(expected, r.Call(expected));
1700 CHECK_EQ(expected, memory[0]);
1701 }
1702 }
1703
1704
1705 TEST(Run_Wasm_LoadMemI64) {
1706 TestingModule module;
1707 int64_t* memory = module.AddMemoryElems<int64_t>(8);
1708 module.RandomizeMemory(1111);
1709 WasmRunner<int64_t> r(&module);
1710
1711 BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_I8(0)));
1712
1713 memory[0] = 0xaabbccdd00112233LL;
1714 CHECK_EQ(0xaabbccdd00112233LL, r.Call());
1715
1716 memory[0] = 0x33aabbccdd001122LL;
1717 CHECK_EQ(0x33aabbccdd001122LL, r.Call());
1718
1719 memory[0] = 77777777;
1720 CHECK_EQ(77777777, r.Call());
1721 }
1722 #endif
1723
1724
1725 TEST(Run_Wasm_LoadMemI32_P) { 1388 TEST(Run_Wasm_LoadMemI32_P) {
1726 const int kNumElems = 8; 1389 const int kNumElems = 8;
1727 TestingModule module; 1390 TestingModule module;
1728 int32_t* memory = module.AddMemoryElems<int32_t>(kNumElems); 1391 int32_t* memory = module.AddMemoryElems<int32_t>(kNumElems);
1729 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1392 WasmRunner<int32_t> r(&module, MachineType::Int32());
1730 module.RandomizeMemory(2222); 1393 module.RandomizeMemory(2222);
1731 1394
1732 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); 1395 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0)));
1733 1396
1734 for (int i = 0; i < kNumElems; i++) { 1397 for (int i = 0; i < kNumElems; i++) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, 1476 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO,
1814 WASM_GET_LOCAL(kSum)), 1477 WASM_GET_LOCAL(kSum)),
1815 WASM_GET_LOCAL(0))); 1478 WASM_GET_LOCAL(0)));
1816 1479
1817 CHECK_EQ(0, r.Call(4 * (kSize - 1))); 1480 CHECK_EQ(0, r.Call(4 * (kSize - 1)));
1818 CHECK_NE(-99.25, buffer[0]); 1481 CHECK_NE(-99.25, buffer[0]);
1819 CHECK_EQ(71256.0f, buffer[0]); 1482 CHECK_EQ(71256.0f, buffer[0]);
1820 } 1483 }
1821 1484
1822 1485
1823 #if WASM_64
1824 TEST(Run_Wasm_MemI64_Sum) {
1825 const int kNumElems = 20;
1826 TestingModule module;
1827 uint64_t* memory = module.AddMemoryElems<uint64_t>(kNumElems);
1828 WasmRunner<uint64_t> r(&module, MachineType::Int32());
1829 const byte kSum = r.AllocateLocal(kAstI64);
1830
1831 BUILD(r, WASM_BLOCK(
1832 2, WASM_WHILE(
1833 WASM_GET_LOCAL(0),
1834 WASM_BLOCK(
1835 2, WASM_SET_LOCAL(
1836 kSum, WASM_I64_ADD(
1837 WASM_GET_LOCAL(kSum),
1838 WASM_LOAD_MEM(MachineType::Int64(),
1839 WASM_GET_LOCAL(0)))),
1840 WASM_SET_LOCAL(
1841 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(8))))),
1842 WASM_GET_LOCAL(1)));
1843
1844 // Run 4 trials.
1845 for (int i = 0; i < 3; i++) {
1846 module.RandomizeMemory(i * 33);
1847 uint64_t expected = 0;
1848 for (size_t j = kNumElems - 1; j > 0; j--) {
1849 expected += memory[j];
1850 }
1851 uint64_t result = r.Call(8 * (kNumElems - 1));
1852 CHECK_EQ(expected, result);
1853 }
1854 }
1855 #endif
1856
1857
1858 template <typename T> 1486 template <typename T>
1859 T GenerateAndRunFold(WasmOpcode binop, T* buffer, size_t size, 1487 T GenerateAndRunFold(WasmOpcode binop, T* buffer, size_t size,
1860 LocalType astType, MachineType memType) { 1488 LocalType astType, MachineType memType) {
1861 TestingModule module; 1489 TestingModule module;
1862 module.AddMemoryElems<T>(size); 1490 module.AddMemoryElems<T>(size);
1863 for (size_t i = 0; i < size; i++) { 1491 for (size_t i = 0; i < size; i++) {
1864 module.raw_mem_start<T>()[i] = buffer[i]; 1492 module.raw_mem_start<T>()[i] = buffer[i];
1865 } 1493 }
1866 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1494 WasmRunner<int32_t> r(&module, MachineType::Int32());
1867 const byte kAccum = r.AllocateLocal(astType); 1495 const byte kAccum = r.AllocateLocal(astType);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2135 r.Call(i); 1763 r.Call(i);
2136 for (int j = 0; j < kNumGlobals; j++) { 1764 for (int j = 0; j < kNumGlobals; j++) {
2137 int32_t expected = j == g ? sum : before[j]; 1765 int32_t expected = j == g ? sum : before[j];
2138 CHECK_EQ(expected, *globals[j]); 1766 CHECK_EQ(expected, *globals[j]);
2139 } 1767 }
2140 } 1768 }
2141 } 1769 }
2142 } 1770 }
2143 1771
2144 1772
2145 #if WASM_64
2146 TEST(Run_WasmInt64Global) {
2147 TestingModule module;
2148 int64_t* global = module.AddGlobal<int64_t>(MachineType::Int64());
2149 WasmRunner<int32_t> r(&module, MachineType::Int32());
2150 // global = global + p0
2151 BUILD(r, B2(WASM_STORE_GLOBAL(
2152 0, WASM_I64_ADD(WASM_LOAD_GLOBAL(0),
2153 WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))),
2154 WASM_ZERO));
2155
2156 *global = 0xFFFFFFFFFFFFFFFFLL;
2157 for (int i = 9; i < 444444; i += 111111) {
2158 int64_t expected = *global + i;
2159 r.Call(i);
2160 CHECK_EQ(expected, *global);
2161 }
2162 }
2163 #endif
2164
2165
2166 TEST(Run_WasmFloat32Global) { 1773 TEST(Run_WasmFloat32Global) {
2167 TestingModule module; 1774 TestingModule module;
2168 float* global = module.AddGlobal<float>(MachineType::Float32()); 1775 float* global = module.AddGlobal<float>(MachineType::Float32());
2169 WasmRunner<int32_t> r(&module, MachineType::Int32()); 1776 WasmRunner<int32_t> r(&module, MachineType::Int32());
2170 // global = global + p0 1777 // global = global + p0
2171 BUILD(r, B2(WASM_STORE_GLOBAL( 1778 BUILD(r, B2(WASM_STORE_GLOBAL(
2172 0, WASM_F32_ADD(WASM_LOAD_GLOBAL(0), 1779 0, WASM_F32_ADD(WASM_LOAD_GLOBAL(0),
2173 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))), 1780 WASM_F32_SCONVERT_I32(WASM_GET_LOCAL(0)))),
2174 WASM_ZERO)); 1781 WASM_ZERO));
2175 1782
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2249 CHECK(static_cast<uint16_t>(0xccaa) == *var_uint16); 1856 CHECK(static_cast<uint16_t>(0xccaa) == *var_uint16);
2250 CHECK(static_cast<int32_t>(0xee55ccaa) == *var_int32); 1857 CHECK(static_cast<int32_t>(0xee55ccaa) == *var_int32);
2251 CHECK(static_cast<uint32_t>(0xee55ccaa) == *var_uint32); 1858 CHECK(static_cast<uint32_t>(0xee55ccaa) == *var_uint32);
2252 CHECK(bit_cast<float>(0xee55ccaa) == *var_float); 1859 CHECK(bit_cast<float>(0xee55ccaa) == *var_float);
2253 CHECK(bit_cast<double>(0x99112233ee55ccaaULL) == *var_double); 1860 CHECK(bit_cast<double>(0x99112233ee55ccaaULL) == *var_double);
2254 1861
2255 USE(unused); 1862 USE(unused);
2256 } 1863 }
2257 1864
2258 1865
2259 #if WASM_64
2260 // Test the WasmRunner with an Int64 return value and different numbers of
2261 // Int64 parameters.
2262 TEST(Run_TestI64WasmRunner) {
2263 {
2264 FOR_INT64_INPUTS(i) {
2265 WasmRunner<int64_t> r;
2266 BUILD(r, WASM_I64V(*i));
2267 CHECK_EQ(*i, r.Call());
2268 }
2269 }
2270 {
2271 WasmRunner<int64_t> r(MachineType::Int64());
2272 BUILD(r, WASM_GET_LOCAL(0));
2273 FOR_INT64_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
2274 }
2275 {
2276 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64());
2277 BUILD(r, WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2278 FOR_INT64_INPUTS(i) {
2279 FOR_INT64_INPUTS(j) { CHECK_EQ(*i + *j, r.Call(*i, *j)); }
2280 }
2281 }
2282 {
2283 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64(),
2284 MachineType::Int64());
2285 BUILD(r, WASM_I64_ADD(WASM_GET_LOCAL(0),
2286 WASM_I64_ADD(WASM_GET_LOCAL(1), WASM_GET_LOCAL(2))));
2287 FOR_INT64_INPUTS(i) {
2288 FOR_INT64_INPUTS(j) {
2289 CHECK_EQ(*i + *j + *j, r.Call(*i, *j, *j));
2290 CHECK_EQ(*j + *i + *j, r.Call(*j, *i, *j));
2291 CHECK_EQ(*j + *j + *i, r.Call(*j, *j, *i));
2292 }
2293 }
2294 }
2295 {
2296 WasmRunner<int64_t> r(MachineType::Int64(), MachineType::Int64(),
2297 MachineType::Int64(), MachineType::Int64());
2298 BUILD(r, WASM_I64_ADD(WASM_GET_LOCAL(0),
2299 WASM_I64_ADD(WASM_GET_LOCAL(1),
2300 WASM_I64_ADD(WASM_GET_LOCAL(2),
2301 WASM_GET_LOCAL(3)))));
2302 FOR_INT64_INPUTS(i) {
2303 FOR_INT64_INPUTS(j) {
2304 CHECK_EQ(*i + *j + *j + *j, r.Call(*i, *j, *j, *j));
2305 CHECK_EQ(*j + *i + *j + *j, r.Call(*j, *i, *j, *j));
2306 CHECK_EQ(*j + *j + *i + *j, r.Call(*j, *j, *i, *j));
2307 CHECK_EQ(*j + *j + *j + *i, r.Call(*j, *j, *j, *i));
2308 }
2309 }
2310 }
2311 }
2312 #endif
2313
2314
2315 TEST(Run_WasmCallEmpty) { 1866 TEST(Run_WasmCallEmpty) {
2316 const int32_t kExpected = -414444; 1867 const int32_t kExpected = -414444;
2317 // Build the target function. 1868 // Build the target function.
2318 TestSignatures sigs; 1869 TestSignatures sigs;
2319 TestingModule module; 1870 TestingModule module;
2320 WasmFunctionCompiler t(sigs.i_v(), &module); 1871 WasmFunctionCompiler t(sigs.i_v(), &module);
2321 BUILD(t, WASM_I32V_3(kExpected)); 1872 BUILD(t, WASM_I32V_3(kExpected));
2322 uint32_t index = t.CompileAndAdd(); 1873 uint32_t index = t.CompileAndAdd();
2323 1874
2324 // Build the calling function. 1875 // Build the calling function.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
2418 1969
2419 FOR_INT32_INPUTS(i) { 1970 FOR_INT32_INPUTS(i) {
2420 FOR_INT32_INPUTS(j) { 1971 FOR_INT32_INPUTS(j) {
2421 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) + 1972 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*i) +
2422 static_cast<uint32_t>(*j)); 1973 static_cast<uint32_t>(*j));
2423 CHECK_EQ(expected, r.Call(*i, *j)); 1974 CHECK_EQ(expected, r.Call(*i, *j));
2424 } 1975 }
2425 } 1976 }
2426 } 1977 }
2427 1978
2428 #if WASM_64
2429 TEST(Run_WasmCall_Int64Sub) {
2430 // Build the target function.
2431 TestSignatures sigs;
2432 TestingModule module;
2433 WasmFunctionCompiler t(sigs.l_ll(), &module);
2434 BUILD(t, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2435 uint32_t index = t.CompileAndAdd();
2436
2437 // Build the caller function.
2438 WasmRunner<int64_t> r(&module, MachineType::Int64(), MachineType::Int64());
2439 BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2440
2441 FOR_INT32_INPUTS(i) {
2442 FOR_INT32_INPUTS(j) {
2443 int64_t a = static_cast<int64_t>(*i) << 32 |
2444 (static_cast<int64_t>(*j) | 0xFFFFFFFF);
2445 int64_t b = static_cast<int64_t>(*j) << 32 |
2446 (static_cast<int64_t>(*i) | 0xFFFFFFFF);
2447
2448 int64_t expected = static_cast<int64_t>(static_cast<uint64_t>(a) -
2449 static_cast<uint64_t>(b));
2450 CHECK_EQ(expected, r.Call(a, b));
2451 }
2452 }
2453 }
2454 #endif
2455
2456
2457 TEST(Run_WasmCall_Float32Sub) { 1979 TEST(Run_WasmCall_Float32Sub) {
2458 TestSignatures sigs; 1980 TestSignatures sigs;
2459 TestingModule module; 1981 TestingModule module;
2460 WasmFunctionCompiler t(sigs.f_ff(), &module); 1982 WasmFunctionCompiler t(sigs.f_ff(), &module);
2461 1983
2462 // Build the target function. 1984 // Build the target function.
2463 BUILD(t, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 1985 BUILD(t, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2464 uint32_t index = t.CompileAndAdd(); 1986 uint32_t index = t.CompileAndAdd();
2465 1987
2466 // Builder the caller function. 1988 // Builder the caller function.
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
2765 WASM_BRV(1, WASM_I8(14)))))); 2287 WASM_BRV(1, WASM_I8(14))))));
2766 2288
2767 2289
2768 CHECK_EQ(11, r.Call(1, 1)); 2290 CHECK_EQ(11, r.Call(1, 1));
2769 CHECK_EQ(12, r.Call(1, 0)); 2291 CHECK_EQ(12, r.Call(1, 0));
2770 CHECK_EQ(13, r.Call(0, 1)); 2292 CHECK_EQ(13, r.Call(0, 1));
2771 CHECK_EQ(14, r.Call(0, 0)); 2293 CHECK_EQ(14, r.Call(0, 0));
2772 } 2294 }
2773 2295
2774 2296
2775 #if WASM_64
2776 TEST(Run_Wasm_LoadStoreI64_sx) {
2777 byte loads[] = {kExprI64LoadMem8S, kExprI64LoadMem16S, kExprI64LoadMem32S,
2778 kExprI64LoadMem};
2779
2780 for (size_t m = 0; m < arraysize(loads); m++) {
2781 TestingModule module;
2782 byte* memory = module.AddMemoryElems<byte>(16);
2783 WasmRunner<int64_t> r(&module);
2784
2785 byte code[] = {kExprI64StoreMem, ZERO_ALIGNMENT,
2786 ZERO_OFFSET, // --
2787 kExprI8Const, 8, // --
2788 loads[m], ZERO_ALIGNMENT,
2789 ZERO_OFFSET, // --
2790 kExprI8Const, 0}; // --
2791
2792 r.Build(code, code + arraysize(code));
2793
2794 // Try a bunch of different negative values.
2795 for (int i = -1; i >= -128; i -= 11) {
2796 int size = 1 << m;
2797 module.BlankMemory();
2798 memory[size - 1] = static_cast<byte>(i); // set the high order byte.
2799
2800 int64_t expected = static_cast<int64_t>(i) << ((size - 1) * 8);
2801
2802 CHECK_EQ(expected, r.Call());
2803 CHECK_EQ(static_cast<byte>(i), memory[8 + size - 1]);
2804 for (int j = size; j < 8; j++) {
2805 CHECK_EQ(255, memory[8 + j]);
2806 }
2807 }
2808 }
2809 }
2810
2811
2812 #endif
2813
2814
2815 TEST(Run_Wasm_SimpleCallIndirect) { 2297 TEST(Run_Wasm_SimpleCallIndirect) {
2816 TestSignatures sigs; 2298 TestSignatures sigs;
2817 TestingModule module; 2299 TestingModule module;
2818 2300
2819 WasmFunctionCompiler t1(sigs.i_ii(), &module); 2301 WasmFunctionCompiler t1(sigs.i_ii(), &module);
2820 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2302 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2821 t1.CompileAndAdd(/*sig_index*/ 1); 2303 t1.CompileAndAdd(/*sig_index*/ 1);
2822 2304
2823 WasmFunctionCompiler t2(sigs.i_ii(), &module); 2305 WasmFunctionCompiler t2(sigs.i_ii(), &module);
2824 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2306 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
3250 2732
3251 #if WASM_64 2733 #if WASM_64
3252 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } 2734 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); }
3253 #endif 2735 #endif
3254 2736
3255 2737
3256 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } 2738 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); }
3257 2739
3258 2740
3259 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } 2741 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); }
OLDNEW
« no previous file with comments | « no previous file | test/cctest/wasm/test-run-wasm-64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698