OLD | NEW |
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 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 WASM_GET_LOCAL(1)), | 605 WASM_GET_LOCAL(1)), |
606 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), | 606 WASM_I32_DIVS(WASM_STORE_MEM(MachineType::Int8(), |
607 WASM_ZERO, WASM_GET_LOCAL(0)), | 607 WASM_ZERO, WASM_GET_LOCAL(0)), |
608 WASM_GET_LOCAL(1)))); | 608 WASM_GET_LOCAL(1)))); |
609 CHECK_EQ(0, r.Call(0, 100)); | 609 CHECK_EQ(0, r.Call(0, 100)); |
610 CHECK_TRAP(r.Call(8, 0)); | 610 CHECK_TRAP(r.Call(8, 0)); |
611 CHECK_TRAP(r.Call(4, 0)); | 611 CHECK_TRAP(r.Call(4, 0)); |
612 CHECK_TRAP(r.Call(0, 0)); | 612 CHECK_TRAP(r.Call(0, 0)); |
613 } | 613 } |
614 | 614 |
615 | |
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) { | 615 void TestFloat32Binop(WasmOpcode opcode, int32_t expected, float a, float b) { |
696 { | 616 { |
697 WasmRunner<int32_t> r; | 617 WasmRunner<int32_t> r; |
698 // return K op K | 618 // return K op K |
699 BUILD(r, WASM_BINOP(opcode, WASM_F32(a), WASM_F32(b))); | 619 BUILD(r, WASM_BINOP(opcode, WASM_F32(a), WASM_F32(b))); |
700 CHECK_EQ(expected, r.Call()); | 620 CHECK_EQ(expected, r.Call()); |
701 } | 621 } |
702 { | 622 { |
703 WasmRunner<int32_t> r(MachineType::Float32(), MachineType::Float32()); | 623 WasmRunner<int32_t> r(MachineType::Float32(), MachineType::Float32()); |
704 // return a op b | 624 // return a op b |
(...skipping 2545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3250 | 3170 |
3251 #if WASM_64 | 3171 #if WASM_64 |
3252 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } | 3172 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } |
3253 #endif | 3173 #endif |
3254 | 3174 |
3255 | 3175 |
3256 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } | 3176 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } |
3257 | 3177 |
3258 | 3178 |
3259 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } | 3179 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } |
OLD | NEW |