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

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

Issue 2594993002: [wasm] Rename wasm::LocalType to wasm::ValueType and kAst* to kWasm* (Closed)
Patch Set: Fix inspector tests Created 3 years, 12 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 | « src/wasm/wasm-opcodes.cc ('k') | 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/base/platform/elapsed-timer.h" 9 #include "src/base/platform/elapsed-timer.h"
10 #include "src/utils.h" 10 #include "src/utils.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 WASM_EXEC_TEST(Int32Add_P2) { 145 WASM_EXEC_TEST(Int32Add_P2) {
146 FLAG_wasm_mv_prototype = true; 146 FLAG_wasm_mv_prototype = true;
147 static const byte code[] = { 147 static const byte code[] = {
148 WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; 148 WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
149 RunInt32AddTest(execution_mode, code, sizeof(code)); 149 RunInt32AddTest(execution_mode, code, sizeof(code));
150 } 150 }
151 151
152 WASM_EXEC_TEST(Int32Add_block1) { 152 WASM_EXEC_TEST(Int32Add_block1) {
153 FLAG_wasm_mv_prototype = true; 153 FLAG_wasm_mv_prototype = true;
154 static const byte code[] = { 154 static const byte code[] = {
155 WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), 155 WASM_BLOCK_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)),
156 kExprI32Add}; 156 kExprI32Add};
157 RunInt32AddTest(execution_mode, code, sizeof(code)); 157 RunInt32AddTest(execution_mode, code, sizeof(code));
158 } 158 }
159 159
160 WASM_EXEC_TEST(Int32Add_block2) { 160 WASM_EXEC_TEST(Int32Add_block2) {
161 FLAG_wasm_mv_prototype = true; 161 FLAG_wasm_mv_prototype = true;
162 static const byte code[] = { 162 static const byte code[] = {
163 WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), 163 WASM_BLOCK_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
164 kExprBr, DEPTH_0), 164 kExprBr, DEPTH_0),
165 kExprI32Add}; 165 kExprI32Add};
166 RunInt32AddTest(execution_mode, code, sizeof(code)); 166 RunInt32AddTest(execution_mode, code, sizeof(code));
167 } 167 }
168 168
169 WASM_EXEC_TEST(Int32Add_multi_if) { 169 WASM_EXEC_TEST(Int32Add_multi_if) {
170 FLAG_wasm_mv_prototype = true; 170 FLAG_wasm_mv_prototype = true;
171 static const byte code[] = { 171 static const byte code[] = {
172 WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), 172 WASM_IF_ELSE_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0),
173 WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), 173 WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)),
174 WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), 174 WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))),
175 kExprI32Add}; 175 kExprI32Add};
176 RunInt32AddTest(execution_mode, code, sizeof(code)); 176 RunInt32AddTest(execution_mode, code, sizeof(code));
177 } 177 }
178 178
179 WASM_EXEC_TEST(Float32Add) { 179 WASM_EXEC_TEST(Float32Add) {
180 WasmRunner<int32_t> r(execution_mode); 180 WasmRunner<int32_t> r(execution_mode);
181 // int(11.5f + 44.5f) 181 // int(11.5f + 44.5f)
182 BUILD(r, 182 BUILD(r,
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 // select(a=0, a=1, a=2); return a 828 // select(a=0, a=1, a=2); return a
829 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(0, WASM_I8(0)), 829 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(0, WASM_I8(0)),
830 WASM_TEE_LOCAL(0, WASM_I8(1)), 830 WASM_TEE_LOCAL(0, WASM_I8(1)),
831 WASM_TEE_LOCAL(0, WASM_I8(2))), 831 WASM_TEE_LOCAL(0, WASM_I8(2))),
832 WASM_DROP, WASM_GET_LOCAL(0)); 832 WASM_DROP, WASM_GET_LOCAL(0));
833 FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); } 833 FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); }
834 } 834 }
835 835
836 WASM_EXEC_TEST(Select_strict2) { 836 WASM_EXEC_TEST(Select_strict2) {
837 WasmRunner<int32_t, int32_t> r(execution_mode); 837 WasmRunner<int32_t, int32_t> r(execution_mode);
838 r.AllocateLocal(kAstI32); 838 r.AllocateLocal(kWasmI32);
839 r.AllocateLocal(kAstI32); 839 r.AllocateLocal(kWasmI32);
840 // select(b=5, c=6, a) 840 // select(b=5, c=6, a)
841 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I8(5)), 841 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I8(5)),
842 WASM_TEE_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0))); 842 WASM_TEE_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0)));
843 FOR_INT32_INPUTS(i) { 843 FOR_INT32_INPUTS(i) {
844 int32_t expected = *i ? 5 : 6; 844 int32_t expected = *i ? 5 : 6;
845 CHECK_EQ(expected, r.Call(*i)); 845 CHECK_EQ(expected, r.Call(*i));
846 } 846 }
847 } 847 }
848 848
849 WASM_EXEC_TEST(Select_strict3) { 849 WASM_EXEC_TEST(Select_strict3) {
850 WasmRunner<int32_t, int32_t> r(execution_mode); 850 WasmRunner<int32_t, int32_t> r(execution_mode);
851 r.AllocateLocal(kAstI32); 851 r.AllocateLocal(kWasmI32);
852 r.AllocateLocal(kAstI32); 852 r.AllocateLocal(kWasmI32);
853 // select(b=5, c=6, a=b) 853 // select(b=5, c=6, a=b)
854 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I8(5)), 854 BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I8(5)),
855 WASM_TEE_LOCAL(2, WASM_I8(6)), 855 WASM_TEE_LOCAL(2, WASM_I8(6)),
856 WASM_TEE_LOCAL(0, WASM_GET_LOCAL(1)))); 856 WASM_TEE_LOCAL(0, WASM_GET_LOCAL(1))));
857 FOR_INT32_INPUTS(i) { 857 FOR_INT32_INPUTS(i) {
858 int32_t expected = 5; 858 int32_t expected = 5;
859 CHECK_EQ(expected, r.Call(*i)); 859 CHECK_EQ(expected, r.Call(*i));
860 } 860 }
861 } 861 }
862 862
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 1659
1660 for (int i = 0; i < kNumElems; ++i) { 1660 for (int i = 0; i < kNumElems; ++i) {
1661 CHECK_EQ(r.module().ReadMemory(&memory[i]), r.Call(i * 4)); 1661 CHECK_EQ(r.module().ReadMemory(&memory[i]), r.Call(i * 4));
1662 } 1662 }
1663 } 1663 }
1664 1664
1665 WASM_EXEC_TEST(MemI32_Sum) { 1665 WASM_EXEC_TEST(MemI32_Sum) {
1666 const int kNumElems = 20; 1666 const int kNumElems = 20;
1667 WasmRunner<uint32_t, int32_t> r(execution_mode); 1667 WasmRunner<uint32_t, int32_t> r(execution_mode);
1668 uint32_t* memory = r.module().AddMemoryElems<uint32_t>(kNumElems); 1668 uint32_t* memory = r.module().AddMemoryElems<uint32_t>(kNumElems);
1669 const byte kSum = r.AllocateLocal(kAstI32); 1669 const byte kSum = r.AllocateLocal(kWasmI32);
1670 1670
1671 BUILD( 1671 BUILD(
1672 r, 1672 r,
1673 WASM_WHILE( 1673 WASM_WHILE(
1674 WASM_GET_LOCAL(0), 1674 WASM_GET_LOCAL(0),
1675 WASM_BLOCK( 1675 WASM_BLOCK(
1676 WASM_SET_LOCAL(kSum, 1676 WASM_SET_LOCAL(kSum,
1677 WASM_I32_ADD(WASM_GET_LOCAL(kSum), 1677 WASM_I32_ADD(WASM_GET_LOCAL(kSum),
1678 WASM_LOAD_MEM(MachineType::Int32(), 1678 WASM_LOAD_MEM(MachineType::Int32(),
1679 WASM_GET_LOCAL(0)))), 1679 WASM_GET_LOCAL(0)))),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 WASM_EXEC_TEST(MemF32_Sum) { 1723 WASM_EXEC_TEST(MemF32_Sum) {
1724 const int kSize = 5; 1724 const int kSize = 5;
1725 WasmRunner<int32_t, int32_t> r(execution_mode); 1725 WasmRunner<int32_t, int32_t> r(execution_mode);
1726 r.module().AddMemoryElems<float>(kSize); 1726 r.module().AddMemoryElems<float>(kSize);
1727 float* buffer = r.module().raw_mem_start<float>(); 1727 float* buffer = r.module().raw_mem_start<float>();
1728 r.module().WriteMemory(&buffer[0], -99.25f); 1728 r.module().WriteMemory(&buffer[0], -99.25f);
1729 r.module().WriteMemory(&buffer[1], -888.25f); 1729 r.module().WriteMemory(&buffer[1], -888.25f);
1730 r.module().WriteMemory(&buffer[2], -77.25f); 1730 r.module().WriteMemory(&buffer[2], -77.25f);
1731 r.module().WriteMemory(&buffer[3], 66666.25f); 1731 r.module().WriteMemory(&buffer[3], 66666.25f);
1732 r.module().WriteMemory(&buffer[4], 5555.25f); 1732 r.module().WriteMemory(&buffer[4], 5555.25f);
1733 const byte kSum = r.AllocateLocal(kAstF32); 1733 const byte kSum = r.AllocateLocal(kWasmF32);
1734 1734
1735 BUILD( 1735 BUILD(
1736 r, 1736 r,
1737 WASM_WHILE( 1737 WASM_WHILE(
1738 WASM_GET_LOCAL(0), 1738 WASM_GET_LOCAL(0),
1739 WASM_BLOCK( 1739 WASM_BLOCK(
1740 WASM_SET_LOCAL(kSum, 1740 WASM_SET_LOCAL(kSum,
1741 WASM_F32_ADD(WASM_GET_LOCAL(kSum), 1741 WASM_F32_ADD(WASM_GET_LOCAL(kSum),
1742 WASM_LOAD_MEM(MachineType::Float32(), 1742 WASM_LOAD_MEM(MachineType::Float32(),
1743 WASM_GET_LOCAL(0)))), 1743 WASM_GET_LOCAL(0)))),
1744 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), 1744 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))),
1745 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), 1745 WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)),
1746 WASM_GET_LOCAL(0)); 1746 WASM_GET_LOCAL(0));
1747 1747
1748 CHECK_EQ(0, r.Call(4 * (kSize - 1))); 1748 CHECK_EQ(0, r.Call(4 * (kSize - 1)));
1749 CHECK_NE(-99.25f, r.module().ReadMemory(&buffer[0])); 1749 CHECK_NE(-99.25f, r.module().ReadMemory(&buffer[0]));
1750 CHECK_EQ(71256.0f, r.module().ReadMemory(&buffer[0])); 1750 CHECK_EQ(71256.0f, r.module().ReadMemory(&buffer[0]));
1751 } 1751 }
1752 1752
1753 template <typename T> 1753 template <typename T>
1754 T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop, 1754 T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop,
1755 T* buffer, uint32_t size, LocalType astType, 1755 T* buffer, uint32_t size, ValueType astType,
1756 MachineType memType) { 1756 MachineType memType) {
1757 WasmRunner<int32_t, int32_t> r(execution_mode); 1757 WasmRunner<int32_t, int32_t> r(execution_mode);
1758 T* memory = r.module().AddMemoryElems<T>(size); 1758 T* memory = r.module().AddMemoryElems<T>(size);
1759 for (uint32_t i = 0; i < size; ++i) { 1759 for (uint32_t i = 0; i < size; ++i) {
1760 r.module().WriteMemory(&memory[i], buffer[i]); 1760 r.module().WriteMemory(&memory[i], buffer[i]);
1761 } 1761 }
1762 const byte kAccum = r.AllocateLocal(astType); 1762 const byte kAccum = r.AllocateLocal(astType);
1763 1763
1764 BUILD(r, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)), 1764 BUILD(r, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)),
1765 WASM_WHILE( 1765 WASM_WHILE(
1766 WASM_GET_LOCAL(0), 1766 WASM_GET_LOCAL(0),
1767 WASM_BLOCK(WASM_SET_LOCAL( 1767 WASM_BLOCK(WASM_SET_LOCAL(
1768 kAccum, WASM_BINOP(binop, WASM_GET_LOCAL(kAccum), 1768 kAccum, WASM_BINOP(binop, WASM_GET_LOCAL(kAccum),
1769 WASM_LOAD_MEM( 1769 WASM_LOAD_MEM(
1770 memType, WASM_GET_LOCAL(0)))), 1770 memType, WASM_GET_LOCAL(0)))),
1771 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), 1771 WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0),
1772 WASM_I8(sizeof(T)))))), 1772 WASM_I8(sizeof(T)))))),
1773 WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)), 1773 WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)),
1774 WASM_GET_LOCAL(0)); 1774 WASM_GET_LOCAL(0));
1775 r.Call(static_cast<int>(sizeof(T) * (size - 1))); 1775 r.Call(static_cast<int>(sizeof(T) * (size - 1)));
1776 return r.module().ReadMemory(&memory[0]); 1776 return r.module().ReadMemory(&memory[0]);
1777 } 1777 }
1778 1778
1779 WASM_EXEC_TEST(MemF64_Mul) { 1779 WASM_EXEC_TEST(MemF64_Mul) {
1780 const size_t kSize = 6; 1780 const size_t kSize = 6;
1781 double buffer[kSize] = {1, 2, 2, 2, 2, 2}; 1781 double buffer[kSize] = {1, 2, 2, 2, 2, 2};
1782 double result = 1782 double result =
1783 GenerateAndRunFold<double>(execution_mode, kExprF64Mul, buffer, kSize, 1783 GenerateAndRunFold<double>(execution_mode, kExprF64Mul, buffer, kSize,
1784 kAstF64, MachineType::Float64()); 1784 kWasmF64, MachineType::Float64());
1785 CHECK_EQ(32, result); 1785 CHECK_EQ(32, result);
1786 } 1786 }
1787 1787
1788 WASM_EXEC_TEST(Build_Wasm_Infinite_Loop) { 1788 WASM_EXEC_TEST(Build_Wasm_Infinite_Loop) {
1789 WasmRunner<int32_t, int32_t> r(execution_mode); 1789 WasmRunner<int32_t, int32_t> r(execution_mode);
1790 // Only build the graph and compile, don't run. 1790 // Only build the graph and compile, don't run.
1791 BUILD(r, WASM_INFINITE_LOOP); 1791 BUILD(r, WASM_INFINITE_LOOP);
1792 } 1792 }
1793 1793
1794 WASM_EXEC_TEST(Build_Wasm_Infinite_Loop_effect) { 1794 WASM_EXEC_TEST(Build_Wasm_Infinite_Loop_effect) {
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
2087 BUILD(r, WASM_CALL_FUNCTION0(target_func.function_index())); 2087 BUILD(r, WASM_CALL_FUNCTION0(target_func.function_index()));
2088 2088
2089 int32_t result = r.Call(); 2089 int32_t result = r.Call();
2090 CHECK_EQ(kExpected, result); 2090 CHECK_EQ(kExpected, result);
2091 } 2091 }
2092 2092
2093 WASM_EXEC_TEST(CallF32StackParameter) { 2093 WASM_EXEC_TEST(CallF32StackParameter) {
2094 WasmRunner<float> r(execution_mode); 2094 WasmRunner<float> r(execution_mode);
2095 2095
2096 // Build the target function. 2096 // Build the target function.
2097 LocalType param_types[20]; 2097 ValueType param_types[20];
2098 for (int i = 0; i < 20; ++i) param_types[i] = kAstF32; 2098 for (int i = 0; i < 20; ++i) param_types[i] = kWasmF32;
2099 FunctionSig sig(1, 19, param_types); 2099 FunctionSig sig(1, 19, param_types);
2100 WasmFunctionCompiler& t = r.NewFunction(&sig); 2100 WasmFunctionCompiler& t = r.NewFunction(&sig);
2101 BUILD(t, WASM_GET_LOCAL(17)); 2101 BUILD(t, WASM_GET_LOCAL(17));
2102 2102
2103 // Build the calling function. 2103 // Build the calling function.
2104 BUILD(r, WASM_CALL_FUNCTION( 2104 BUILD(r, WASM_CALL_FUNCTION(
2105 t.function_index(), WASM_F32(1.0f), WASM_F32(2.0f), 2105 t.function_index(), WASM_F32(1.0f), WASM_F32(2.0f),
2106 WASM_F32(4.0f), WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f), 2106 WASM_F32(4.0f), WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f),
2107 WASM_F32(64.0f), WASM_F32(128.0f), WASM_F32(256.0f), 2107 WASM_F32(64.0f), WASM_F32(128.0f), WASM_F32(256.0f),
2108 WASM_F32(1.5f), WASM_F32(2.5f), WASM_F32(4.5f), WASM_F32(8.5f), 2108 WASM_F32(1.5f), WASM_F32(2.5f), WASM_F32(4.5f), WASM_F32(8.5f),
2109 WASM_F32(16.5f), WASM_F32(32.5f), WASM_F32(64.5f), 2109 WASM_F32(16.5f), WASM_F32(32.5f), WASM_F32(64.5f),
2110 WASM_F32(128.5f), WASM_F32(256.5f), WASM_F32(512.5f))); 2110 WASM_F32(128.5f), WASM_F32(256.5f), WASM_F32(512.5f)));
2111 2111
2112 float result = r.Call(); 2112 float result = r.Call();
2113 CHECK_EQ(256.5f, result); 2113 CHECK_EQ(256.5f, result);
2114 } 2114 }
2115 2115
2116 WASM_EXEC_TEST(CallF64StackParameter) { 2116 WASM_EXEC_TEST(CallF64StackParameter) {
2117 WasmRunner<double> r(execution_mode); 2117 WasmRunner<double> r(execution_mode);
2118 2118
2119 // Build the target function. 2119 // Build the target function.
2120 LocalType param_types[20]; 2120 ValueType param_types[20];
2121 for (int i = 0; i < 20; ++i) param_types[i] = kAstF64; 2121 for (int i = 0; i < 20; ++i) param_types[i] = kWasmF64;
2122 FunctionSig sig(1, 19, param_types); 2122 FunctionSig sig(1, 19, param_types);
2123 WasmFunctionCompiler& t = r.NewFunction(&sig); 2123 WasmFunctionCompiler& t = r.NewFunction(&sig);
2124 BUILD(t, WASM_GET_LOCAL(17)); 2124 BUILD(t, WASM_GET_LOCAL(17));
2125 2125
2126 // Build the calling function. 2126 // Build the calling function.
2127 BUILD(r, WASM_CALL_FUNCTION(t.function_index(), WASM_F64(1.0), WASM_F64(2.0), 2127 BUILD(r, WASM_CALL_FUNCTION(t.function_index(), WASM_F64(1.0), WASM_F64(2.0),
2128 WASM_F64(4.0), WASM_F64(8.0), WASM_F64(16.0), 2128 WASM_F64(4.0), WASM_F64(8.0), WASM_F64(16.0),
2129 WASM_F64(32.0), WASM_F64(64.0), WASM_F64(128.0), 2129 WASM_F64(32.0), WASM_F64(64.0), WASM_F64(128.0),
2130 WASM_F64(256.0), WASM_F64(1.5), WASM_F64(2.5), 2130 WASM_F64(256.0), WASM_F64(1.5), WASM_F64(2.5),
2131 WASM_F64(4.5), WASM_F64(8.5), WASM_F64(16.5), 2131 WASM_F64(4.5), WASM_F64(8.5), WASM_F64(16.5),
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2247 Zone zone(&allocator, ZONE_NAME); 2247 Zone zone(&allocator, ZONE_NAME);
2248 WasmRunner<int32_t> r(execution_mode); 2248 WasmRunner<int32_t> r(execution_mode);
2249 r.module().AddMemory(1024); 2249 r.module().AddMemory(1024);
2250 MachineType* memtypes = &mixed[start]; 2250 MachineType* memtypes = &mixed[start];
2251 MachineType result = memtypes[which]; 2251 MachineType result = memtypes[which];
2252 2252
2253 // ========================================================================= 2253 // =========================================================================
2254 // Build the selector function. 2254 // Build the selector function.
2255 // ========================================================================= 2255 // =========================================================================
2256 FunctionSig::Builder b(&zone, 1, num_params); 2256 FunctionSig::Builder b(&zone, 1, num_params);
2257 b.AddReturn(WasmOpcodes::LocalTypeFor(result)); 2257 b.AddReturn(WasmOpcodes::ValueTypeFor(result));
2258 for (int i = 0; i < num_params; ++i) { 2258 for (int i = 0; i < num_params; ++i) {
2259 b.AddParam(WasmOpcodes::LocalTypeFor(memtypes[i])); 2259 b.AddParam(WasmOpcodes::ValueTypeFor(memtypes[i]));
2260 } 2260 }
2261 WasmFunctionCompiler& t = r.NewFunction(b.Build()); 2261 WasmFunctionCompiler& t = r.NewFunction(b.Build());
2262 BUILD(t, WASM_GET_LOCAL(which)); 2262 BUILD(t, WASM_GET_LOCAL(which));
2263 2263
2264 // ========================================================================= 2264 // =========================================================================
2265 // Build the calling function. 2265 // Build the calling function.
2266 // ========================================================================= 2266 // =========================================================================
2267 std::vector<byte> code; 2267 std::vector<byte> code;
2268 2268
2269 // Load the offset for the store. 2269 // Load the offset for the store.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2307 WASM_EXEC_TEST(MixedCall_0) { Run_WasmMixedCall_N(execution_mode, 0); } 2307 WASM_EXEC_TEST(MixedCall_0) { Run_WasmMixedCall_N(execution_mode, 0); }
2308 WASM_EXEC_TEST(MixedCall_1) { Run_WasmMixedCall_N(execution_mode, 1); } 2308 WASM_EXEC_TEST(MixedCall_1) { Run_WasmMixedCall_N(execution_mode, 1); }
2309 WASM_EXEC_TEST(MixedCall_2) { Run_WasmMixedCall_N(execution_mode, 2); } 2309 WASM_EXEC_TEST(MixedCall_2) { Run_WasmMixedCall_N(execution_mode, 2); }
2310 WASM_EXEC_TEST(MixedCall_3) { Run_WasmMixedCall_N(execution_mode, 3); } 2310 WASM_EXEC_TEST(MixedCall_3) { Run_WasmMixedCall_N(execution_mode, 3); }
2311 2311
2312 WASM_EXEC_TEST(AddCall) { 2312 WASM_EXEC_TEST(AddCall) {
2313 WasmRunner<int32_t, int32_t> r(kExecuteCompiled); 2313 WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
2314 WasmFunctionCompiler& t1 = r.NewFunction<int32_t, int32_t, int32_t>(); 2314 WasmFunctionCompiler& t1 = r.NewFunction<int32_t, int32_t, int32_t>();
2315 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2315 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2316 2316
2317 byte local = r.AllocateLocal(kAstI32); 2317 byte local = r.AllocateLocal(kWasmI32);
2318 BUILD(r, WASM_SET_LOCAL(local, WASM_I8(99)), 2318 BUILD(r, WASM_SET_LOCAL(local, WASM_I8(99)),
2319 WASM_I32_ADD(WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(0), 2319 WASM_I32_ADD(WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(0),
2320 WASM_GET_LOCAL(0)), 2320 WASM_GET_LOCAL(0)),
2321 WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(1), 2321 WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(1),
2322 WASM_GET_LOCAL(local)))); 2322 WASM_GET_LOCAL(local))));
2323 2323
2324 CHECK_EQ(198, r.Call(0)); 2324 CHECK_EQ(198, r.Call(0));
2325 CHECK_EQ(200, r.Call(1)); 2325 CHECK_EQ(200, r.Call(1));
2326 CHECK_EQ(100, r.Call(-49)); 2326 CHECK_EQ(100, r.Call(-49));
2327 } 2327 }
2328 2328
2329 WASM_EXEC_TEST(MultiReturnSub) { 2329 WASM_EXEC_TEST(MultiReturnSub) {
2330 FLAG_wasm_mv_prototype = true; 2330 FLAG_wasm_mv_prototype = true;
2331 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); 2331 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
2332 2332
2333 LocalType storage[] = {kAstI32, kAstI32, kAstI32, kAstI32}; 2333 ValueType storage[] = {kWasmI32, kWasmI32, kWasmI32, kWasmI32};
2334 FunctionSig sig_ii_ii(2, 2, storage); 2334 FunctionSig sig_ii_ii(2, 2, storage);
2335 WasmFunctionCompiler& t1 = r.NewFunction(&sig_ii_ii); 2335 WasmFunctionCompiler& t1 = r.NewFunction(&sig_ii_ii);
2336 BUILD(t1, WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)); 2336 BUILD(t1, WASM_GET_LOCAL(1), WASM_GET_LOCAL(0));
2337 2337
2338 BUILD(r, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), 2338 BUILD(r, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
2339 WASM_CALL_FUNCTION0(t1.function_index()), kExprI32Sub); 2339 WASM_CALL_FUNCTION0(t1.function_index()), kExprI32Sub);
2340 2340
2341 FOR_INT32_INPUTS(i) { 2341 FOR_INT32_INPUTS(i) {
2342 FOR_INT32_INPUTS(j) { 2342 FOR_INT32_INPUTS(j) {
2343 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*j) - 2343 int32_t expected = static_cast<int32_t>(static_cast<uint32_t>(*j) -
2344 static_cast<uint32_t>(*i)); 2344 static_cast<uint32_t>(*i));
2345 CHECK_EQ(expected, r.Call(*i, *j)); 2345 CHECK_EQ(expected, r.Call(*i, *j));
2346 } 2346 }
2347 } 2347 }
2348 } 2348 }
2349 2349
2350 template <typename T> 2350 template <typename T>
2351 void RunMultiReturnSelect(WasmExecutionMode execution_mode, const T* inputs) { 2351 void RunMultiReturnSelect(WasmExecutionMode execution_mode, const T* inputs) {
2352 FLAG_wasm_mv_prototype = true; 2352 FLAG_wasm_mv_prototype = true;
2353 LocalType type = WasmOpcodes::LocalTypeFor(MachineTypeForC<T>()); 2353 ValueType type = WasmOpcodes::ValueTypeFor(MachineTypeForC<T>());
2354 LocalType storage[] = {type, type, type, type, type, type}; 2354 ValueType storage[] = {type, type, type, type, type, type};
2355 const size_t kNumReturns = 2; 2355 const size_t kNumReturns = 2;
2356 const size_t kNumParams = arraysize(storage) - kNumReturns; 2356 const size_t kNumParams = arraysize(storage) - kNumReturns;
2357 FunctionSig sig(kNumReturns, kNumParams, storage); 2357 FunctionSig sig(kNumReturns, kNumParams, storage);
2358 2358
2359 for (size_t i = 0; i < kNumParams; i++) { 2359 for (size_t i = 0; i < kNumParams; i++) {
2360 for (size_t j = 0; j < kNumParams; j++) { 2360 for (size_t j = 0; j < kNumParams; j++) {
2361 for (int k = 0; k < 2; k++) { 2361 for (int k = 0; k < 2; k++) {
2362 WasmRunner<T, T, T, T, T> r(execution_mode); 2362 WasmRunner<T, T, T, T, T> r(execution_mode);
2363 WasmFunctionCompiler& r1 = r.NewFunction(&sig); 2363 WasmFunctionCompiler& r1 = r.NewFunction(&sig);
2364 2364
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
2844 2844
2845 WASM_EXEC_TEST(F32CopySign) { 2845 WASM_EXEC_TEST(F32CopySign) {
2846 WasmRunner<float, float, float> r(execution_mode); 2846 WasmRunner<float, float, float> r(execution_mode);
2847 BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2847 BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2848 2848
2849 FOR_FLOAT32_INPUTS(i) { 2849 FOR_FLOAT32_INPUTS(i) {
2850 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(copysignf(*i, *j), r.Call(*i, *j)); } 2850 FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(copysignf(*i, *j), r.Call(*i, *j)); }
2851 } 2851 }
2852 } 2852 }
2853 2853
2854 static void CompileCallIndirectMany(LocalType param) { 2854 static void CompileCallIndirectMany(ValueType param) {
2855 // Make sure we don't run out of registers when compiling indirect calls 2855 // Make sure we don't run out of registers when compiling indirect calls
2856 // with many many parameters. 2856 // with many many parameters.
2857 TestSignatures sigs; 2857 TestSignatures sigs;
2858 for (byte num_params = 0; num_params < 40; ++num_params) { 2858 for (byte num_params = 0; num_params < 40; ++num_params) {
2859 WasmRunner<void> r(kExecuteCompiled); 2859 WasmRunner<void> r(kExecuteCompiled);
2860 FunctionSig* sig = sigs.many(r.zone(), kAstStmt, param, num_params); 2860 FunctionSig* sig = sigs.many(r.zone(), kWasmStmt, param, num_params);
2861 2861
2862 r.module().AddSignature(sig); 2862 r.module().AddSignature(sig);
2863 r.module().AddSignature(sig); 2863 r.module().AddSignature(sig);
2864 r.module().AddIndirectFunctionTable(nullptr, 0); 2864 r.module().AddIndirectFunctionTable(nullptr, 0);
2865 2865
2866 WasmFunctionCompiler& t = r.NewFunction(sig); 2866 WasmFunctionCompiler& t = r.NewFunction(sig);
2867 2867
2868 std::vector<byte> code; 2868 std::vector<byte> code;
2869 for (byte p = 0; p < num_params; ++p) { 2869 for (byte p = 0; p < num_params; ++p) {
2870 ADD_CODE(code, kExprGetLocal, p); 2870 ADD_CODE(code, kExprGetLocal, p);
2871 } 2871 }
2872 ADD_CODE(code, kExprI8Const, 0); 2872 ADD_CODE(code, kExprI8Const, 0);
2873 ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO); 2873 ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO);
2874 2874
2875 t.Build(&code[0], &code[0] + code.size()); 2875 t.Build(&code[0], &code[0] + code.size());
2876 } 2876 }
2877 } 2877 }
2878 2878
2879 TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kAstI32); } 2879 TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kWasmI32); }
2880 2880
2881 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } 2881 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kWasmF32); }
2882 2882
2883 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } 2883 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kWasmF64); }
2884 2884
2885 WASM_EXEC_TEST_WITH_TRAP(Int32RemS_dead) { 2885 WASM_EXEC_TEST_WITH_TRAP(Int32RemS_dead) {
2886 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); 2886 WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
2887 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP, 2887 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP,
2888 WASM_ZERO); 2888 WASM_ZERO);
2889 const int32_t kMin = std::numeric_limits<int32_t>::min(); 2889 const int32_t kMin = std::numeric_limits<int32_t>::min();
2890 CHECK_EQ(0, r.Call(133, 100)); 2890 CHECK_EQ(0, r.Call(133, 100));
2891 CHECK_EQ(0, r.Call(kMin, -1)); 2891 CHECK_EQ(0, r.Call(kMin, -1));
2892 CHECK_EQ(0, r.Call(0, 1)); 2892 CHECK_EQ(0, r.Call(0, 1));
2893 CHECK_TRAP(r.Call(100, 0)); 2893 CHECK_TRAP(r.Call(100, 0));
2894 CHECK_TRAP(r.Call(-1001, 0)); 2894 CHECK_TRAP(r.Call(-1001, 0));
2895 CHECK_TRAP(r.Call(kMin, 0)); 2895 CHECK_TRAP(r.Call(kMin, 0));
2896 } 2896 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-opcodes.cc ('k') | test/cctest/wasm/test-run-wasm-64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698