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

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

Issue 2403093002: [wasm] Canonicalize function signature indices for matching in indirect calls. (Closed)
Patch Set: [wasm] Canonicalize function signature indices for matching in indirect calls. Created 4 years, 2 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
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/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
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 indirect_function_table[] = {0, 1, 2, 0, 1};
2658 module.AddIndirectFunctionTable(indirect_function_table,
2659 arraysize(indirect_function_table));
2660 module.PopulateIndirectFunctionTable();
2661
2662 // Builder the caller function.
2663 WasmRunner<int32_t> r(&module, MachineType::Int32());
2664 BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(77), WASM_I8(11)));
2665
2666 CHECK_EQ(88, r.Call(0));
ahaas 2016/10/11 09:20:09 Also here, could you use t*.function_index()?
titzer 2016/10/11 11:58:31 Done.
2667 CHECK_EQ(66, r.Call(1));
2668 CHECK_TRAP(r.Call(2));
2669 CHECK_EQ(88, r.Call(3));
2670 CHECK_EQ(66, r.Call(4));
2671 CHECK_TRAP(r.Call(5));
2672 }
2673
2635 WASM_EXEC_TEST(F32Floor) { 2674 WASM_EXEC_TEST(F32Floor) {
2636 WasmRunner<float> r(execution_mode, MachineType::Float32()); 2675 WasmRunner<float> r(execution_mode, MachineType::Float32());
2637 BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0))); 2676 BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0)));
2638 2677
2639 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(floorf(*i), r.Call(*i)); } 2678 FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(floorf(*i), r.Call(*i)); }
2640 } 2679 }
2641 2680
2642 WASM_EXEC_TEST(F32Ceil) { 2681 WASM_EXEC_TEST(F32Ceil) {
2643 WasmRunner<float> r(execution_mode, MachineType::Float32()); 2682 WasmRunner<float> r(execution_mode, MachineType::Float32());
2644 BUILD(r, WASM_F32_CEIL(WASM_GET_LOCAL(0))); 2683 BUILD(r, WASM_F32_CEIL(WASM_GET_LOCAL(0)));
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2865 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP, 2904 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP,
2866 WASM_ZERO); 2905 WASM_ZERO);
2867 const int32_t kMin = std::numeric_limits<int32_t>::min(); 2906 const int32_t kMin = std::numeric_limits<int32_t>::min();
2868 CHECK_EQ(0, r.Call(133, 100)); 2907 CHECK_EQ(0, r.Call(133, 100));
2869 CHECK_EQ(0, r.Call(kMin, -1)); 2908 CHECK_EQ(0, r.Call(kMin, -1));
2870 CHECK_EQ(0, r.Call(0, 1)); 2909 CHECK_EQ(0, r.Call(0, 1));
2871 CHECK_TRAP(r.Call(100, 0)); 2910 CHECK_TRAP(r.Call(100, 0));
2872 CHECK_TRAP(r.Call(-1001, 0)); 2911 CHECK_TRAP(r.Call(-1001, 0));
2873 CHECK_TRAP(r.Call(kMin, 0)); 2912 CHECK_TRAP(r.Call(kMin, 0));
2874 } 2913 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698