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/base/platform/elapsed-timer.h" | 9 #include "src/base/platform/elapsed-timer.h" |
10 #include "src/utils.h" | 10 #include "src/utils.h" |
(...skipping 2614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2625 | 2625 |
2626 // Builder the caller function. | 2626 // Builder the caller function. |
2627 WasmRunner<int32_t> r(&module, MachineType::Int32()); | 2627 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
2628 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); | 2628 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); |
2629 | 2629 |
2630 CHECK_TRAP(r.Call(0)); | 2630 CHECK_TRAP(r.Call(0)); |
2631 CHECK_TRAP(r.Call(1)); | 2631 CHECK_TRAP(r.Call(1)); |
2632 CHECK_TRAP(r.Call(2)); | 2632 CHECK_TRAP(r.Call(2)); |
2633 } | 2633 } |
2634 | 2634 |
| 2635 WASM_EXEC_TEST(CallIndirect_canonical) { |
| 2636 TestSignatures sigs; |
| 2637 TestingModule module(execution_mode); |
| 2638 |
| 2639 WasmFunctionCompiler t1(sigs.i_ii(), &module); |
| 2640 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 2641 t1.CompileAndAdd(/*sig_index*/ 0); |
| 2642 |
| 2643 WasmFunctionCompiler t2(sigs.i_ii(), &module); |
| 2644 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 2645 t2.CompileAndAdd(/*sig_index*/ 1); |
| 2646 |
| 2647 WasmFunctionCompiler t3(sigs.f_ff(), &module); |
| 2648 BUILD(t3, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
| 2649 t3.CompileAndAdd(/*sig_index*/ 2); |
| 2650 |
| 2651 // Signature table. |
| 2652 module.AddSignature(sigs.i_ii()); |
| 2653 module.AddSignature(sigs.i_ii()); |
| 2654 module.AddSignature(sigs.f_ff()); |
| 2655 |
| 2656 // Function table. |
| 2657 uint16_t i1 = static_cast<uint16_t>(t1.function_index()); |
| 2658 uint16_t i2 = static_cast<uint16_t>(t2.function_index()); |
| 2659 uint16_t i3 = static_cast<uint16_t>(t3.function_index()); |
| 2660 uint16_t indirect_function_table[] = {i1, i2, i3, i1, i2}; |
| 2661 |
| 2662 module.AddIndirectFunctionTable(indirect_function_table, |
| 2663 arraysize(indirect_function_table)); |
| 2664 module.PopulateIndirectFunctionTable(); |
| 2665 |
| 2666 // Builder the caller function. |
| 2667 WasmRunner<int32_t> r(&module, MachineType::Int32()); |
| 2668 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(77), WASM_I8(11))); |
| 2669 |
| 2670 CHECK_EQ(88, r.Call(0)); |
| 2671 CHECK_EQ(66, r.Call(1)); |
| 2672 CHECK_TRAP(r.Call(2)); |
| 2673 CHECK_EQ(88, r.Call(3)); |
| 2674 CHECK_EQ(66, r.Call(4)); |
| 2675 CHECK_TRAP(r.Call(5)); |
| 2676 } |
| 2677 |
2635 WASM_EXEC_TEST(F32Floor) { | 2678 WASM_EXEC_TEST(F32Floor) { |
2636 WasmRunner<float> r(execution_mode, MachineType::Float32()); | 2679 WasmRunner<float> r(execution_mode, MachineType::Float32()); |
2637 BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0))); | 2680 BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0))); |
2638 | 2681 |
2639 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(floorf(*i), r.Call(*i)); } | 2682 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(floorf(*i), r.Call(*i)); } |
2640 } | 2683 } |
2641 | 2684 |
2642 WASM_EXEC_TEST(F32Ceil) { | 2685 WASM_EXEC_TEST(F32Ceil) { |
2643 WasmRunner<float> r(execution_mode, MachineType::Float32()); | 2686 WasmRunner<float> r(execution_mode, MachineType::Float32()); |
2644 BUILD(r, WASM_F32_CEIL(WASM_GET_LOCAL(0))); | 2687 BUILD(r, WASM_F32_CEIL(WASM_GET_LOCAL(0))); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2865 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP, | 2908 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP, |
2866 WASM_ZERO); | 2909 WASM_ZERO); |
2867 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 2910 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
2868 CHECK_EQ(0, r.Call(133, 100)); | 2911 CHECK_EQ(0, r.Call(133, 100)); |
2869 CHECK_EQ(0, r.Call(kMin, -1)); | 2912 CHECK_EQ(0, r.Call(kMin, -1)); |
2870 CHECK_EQ(0, r.Call(0, 1)); | 2913 CHECK_EQ(0, r.Call(0, 1)); |
2871 CHECK_TRAP(r.Call(100, 0)); | 2914 CHECK_TRAP(r.Call(100, 0)); |
2872 CHECK_TRAP(r.Call(-1001, 0)); | 2915 CHECK_TRAP(r.Call(-1001, 0)); |
2873 CHECK_TRAP(r.Call(kMin, 0)); | 2916 CHECK_TRAP(r.Call(kMin, 0)); |
2874 } | 2917 } |
OLD | NEW |