OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 | 10 |
11 #include "src/wasm/wasm-macro-gen.h" | 11 #include "src/wasm/wasm-macro-gen.h" |
12 | 12 |
13 #include "test/cctest/cctest.h" | 13 #include "test/cctest/cctest.h" |
14 #include "test/cctest/compiler/value-helper.h" | 14 #include "test/cctest/compiler/value-helper.h" |
15 #include "test/cctest/wasm/test-signatures.h" | 15 #include "test/cctest/wasm/test-signatures.h" |
16 #include "test/cctest/wasm/wasm-run-utils.h" | 16 #include "test/cctest/wasm/wasm-run-utils.h" |
17 | 17 |
18 using namespace v8::base; | 18 using namespace v8::base; |
19 using namespace v8::internal; | 19 using namespace v8::internal; |
20 using namespace v8::internal::compiler; | 20 using namespace v8::internal::compiler; |
21 using namespace v8::internal::wasm; | 21 using namespace v8::internal::wasm; |
22 | 22 |
23 // for even shorter tests. | 23 // for even shorter tests. |
24 #define B2(a, b) kExprBlock, a, b, kExprEnd | 24 #define B2(a, b) kExprBlock, a, b, kExprEnd |
25 #define B1(a) kExprBlock, a, kExprEnd | 25 #define B1(a) kExprBlock, a, kExprEnd |
26 #define RET(x) x, kExprReturn, 1 | 26 #define RET(x) x, kExprReturn, 1 |
27 #define RET_I8(x) kExprI8Const, x, kExprReturn, 1 | 27 #define RET_I8(x) kExprI8Const, x, kExprReturn, 1 |
28 | 28 |
29 WASM_EXEC_TEST(Int32AsmjsDivS) { | 29 WASM_EXEC_TEST(Int32AsmjsDivS) { |
30 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 30 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 31 MachineType::Int32()); |
31 BUILD(r, WASM_BINOP(kExprI32AsmjsDivS, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 32 BUILD(r, WASM_BINOP(kExprI32AsmjsDivS, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
32 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 33 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
33 CHECK_EQ(0, r.Call(0, 100)); | 34 CHECK_EQ(0, r.Call(0, 100)); |
34 CHECK_EQ(0, r.Call(100, 0)); | 35 CHECK_EQ(0, r.Call(100, 0)); |
35 CHECK_EQ(0, r.Call(-1001, 0)); | 36 CHECK_EQ(0, r.Call(-1001, 0)); |
36 CHECK_EQ(kMin, r.Call(kMin, -1)); | 37 CHECK_EQ(kMin, r.Call(kMin, -1)); |
37 CHECK_EQ(0, r.Call(kMin, 0)); | 38 CHECK_EQ(0, r.Call(kMin, 0)); |
38 } | 39 } |
39 | 40 |
40 WASM_EXEC_TEST(Int32AsmjsRemS) { | 41 WASM_EXEC_TEST(Int32AsmjsRemS) { |
41 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 42 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 43 MachineType::Int32()); |
42 BUILD(r, WASM_BINOP(kExprI32AsmjsRemS, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 44 BUILD(r, WASM_BINOP(kExprI32AsmjsRemS, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
43 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 45 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
44 CHECK_EQ(33, r.Call(133, 100)); | 46 CHECK_EQ(33, r.Call(133, 100)); |
45 CHECK_EQ(0, r.Call(kMin, -1)); | 47 CHECK_EQ(0, r.Call(kMin, -1)); |
46 CHECK_EQ(0, r.Call(100, 0)); | 48 CHECK_EQ(0, r.Call(100, 0)); |
47 CHECK_EQ(0, r.Call(-1001, 0)); | 49 CHECK_EQ(0, r.Call(-1001, 0)); |
48 CHECK_EQ(0, r.Call(kMin, 0)); | 50 CHECK_EQ(0, r.Call(kMin, 0)); |
49 } | 51 } |
50 | 52 |
51 WASM_EXEC_TEST(Int32AsmjsDivU) { | 53 WASM_EXEC_TEST(Int32AsmjsDivU) { |
52 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 54 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 55 MachineType::Int32()); |
53 BUILD(r, WASM_BINOP(kExprI32AsmjsDivU, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 56 BUILD(r, WASM_BINOP(kExprI32AsmjsDivU, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
54 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 57 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
55 CHECK_EQ(0, r.Call(0, 100)); | 58 CHECK_EQ(0, r.Call(0, 100)); |
56 CHECK_EQ(0, r.Call(kMin, -1)); | 59 CHECK_EQ(0, r.Call(kMin, -1)); |
57 CHECK_EQ(0, r.Call(100, 0)); | 60 CHECK_EQ(0, r.Call(100, 0)); |
58 CHECK_EQ(0, r.Call(-1001, 0)); | 61 CHECK_EQ(0, r.Call(-1001, 0)); |
59 CHECK_EQ(0, r.Call(kMin, 0)); | 62 CHECK_EQ(0, r.Call(kMin, 0)); |
60 } | 63 } |
61 | 64 |
62 WASM_EXEC_TEST(Int32AsmjsRemU) { | 65 WASM_EXEC_TEST(Int32AsmjsRemU) { |
63 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32()); | 66 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
| 67 MachineType::Int32()); |
64 BUILD(r, WASM_BINOP(kExprI32AsmjsRemU, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 68 BUILD(r, WASM_BINOP(kExprI32AsmjsRemU, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
65 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 69 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
66 CHECK_EQ(17, r.Call(217, 100)); | 70 CHECK_EQ(17, r.Call(217, 100)); |
67 CHECK_EQ(0, r.Call(100, 0)); | 71 CHECK_EQ(0, r.Call(100, 0)); |
68 CHECK_EQ(0, r.Call(-1001, 0)); | 72 CHECK_EQ(0, r.Call(-1001, 0)); |
69 CHECK_EQ(0, r.Call(kMin, 0)); | 73 CHECK_EQ(0, r.Call(kMin, 0)); |
70 CHECK_EQ(kMin, r.Call(kMin, -1)); | 74 CHECK_EQ(kMin, r.Call(kMin, -1)); |
71 } | 75 } |
72 | 76 |
73 WASM_EXEC_TEST(I32AsmjsSConvertF32) { | 77 WASM_EXEC_TEST(I32AsmjsSConvertF32) { |
74 WasmRunner<int32_t> r(MachineType::Float32()); | 78 WasmRunner<int32_t> r(execution_mode, MachineType::Float32()); |
75 BUILD(r, WASM_UNOP(kExprI32AsmjsSConvertF32, WASM_GET_LOCAL(0))); | 79 BUILD(r, WASM_UNOP(kExprI32AsmjsSConvertF32, WASM_GET_LOCAL(0))); |
76 | 80 |
77 FOR_FLOAT32_INPUTS(i) { | 81 FOR_FLOAT32_INPUTS(i) { |
78 int32_t expected = DoubleToInt32(*i); | 82 int32_t expected = DoubleToInt32(*i); |
79 CHECK_EQ(expected, r.Call(*i)); | 83 CHECK_EQ(expected, r.Call(*i)); |
80 } | 84 } |
81 } | 85 } |
82 | 86 |
83 WASM_EXEC_TEST(I32AsmjsSConvertF64) { | 87 WASM_EXEC_TEST(I32AsmjsSConvertF64) { |
84 WasmRunner<int32_t> r(MachineType::Float64()); | 88 WasmRunner<int32_t> r(execution_mode, MachineType::Float64()); |
85 BUILD(r, WASM_UNOP(kExprI32AsmjsSConvertF64, WASM_GET_LOCAL(0))); | 89 BUILD(r, WASM_UNOP(kExprI32AsmjsSConvertF64, WASM_GET_LOCAL(0))); |
86 | 90 |
87 FOR_FLOAT64_INPUTS(i) { | 91 FOR_FLOAT64_INPUTS(i) { |
88 int32_t expected = DoubleToInt32(*i); | 92 int32_t expected = DoubleToInt32(*i); |
89 CHECK_EQ(expected, r.Call(*i)); | 93 CHECK_EQ(expected, r.Call(*i)); |
90 } | 94 } |
91 } | 95 } |
92 | 96 |
93 WASM_EXEC_TEST(I32AsmjsUConvertF32) { | 97 WASM_EXEC_TEST(I32AsmjsUConvertF32) { |
94 WasmRunner<uint32_t> r(MachineType::Float32()); | 98 WasmRunner<uint32_t> r(execution_mode, MachineType::Float32()); |
95 BUILD(r, WASM_UNOP(kExprI32AsmjsUConvertF32, WASM_GET_LOCAL(0))); | 99 BUILD(r, WASM_UNOP(kExprI32AsmjsUConvertF32, WASM_GET_LOCAL(0))); |
96 | 100 |
97 FOR_FLOAT32_INPUTS(i) { | 101 FOR_FLOAT32_INPUTS(i) { |
98 uint32_t expected = DoubleToUint32(*i); | 102 uint32_t expected = DoubleToUint32(*i); |
99 CHECK_EQ(expected, r.Call(*i)); | 103 CHECK_EQ(expected, r.Call(*i)); |
100 } | 104 } |
101 } | 105 } |
102 | 106 |
103 WASM_EXEC_TEST(I32AsmjsUConvertF64) { | 107 WASM_EXEC_TEST(I32AsmjsUConvertF64) { |
104 WasmRunner<uint32_t> r(MachineType::Float64()); | 108 WasmRunner<uint32_t> r(execution_mode, MachineType::Float64()); |
105 BUILD(r, WASM_UNOP(kExprI32AsmjsUConvertF64, WASM_GET_LOCAL(0))); | 109 BUILD(r, WASM_UNOP(kExprI32AsmjsUConvertF64, WASM_GET_LOCAL(0))); |
106 | 110 |
107 FOR_FLOAT64_INPUTS(i) { | 111 FOR_FLOAT64_INPUTS(i) { |
108 uint32_t expected = DoubleToUint32(*i); | 112 uint32_t expected = DoubleToUint32(*i); |
109 CHECK_EQ(expected, r.Call(*i)); | 113 CHECK_EQ(expected, r.Call(*i)); |
110 } | 114 } |
111 } | 115 } |
112 | 116 |
113 WASM_EXEC_TEST(LoadMemI32_oob_asm) { | 117 WASM_EXEC_TEST(LoadMemI32_oob_asm) { |
114 TestingModule module; | 118 TestingModule module(execution_mode); |
115 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 119 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
116 WasmRunner<int32_t> r(&module, MachineType::Uint32()); | 120 WasmRunner<int32_t> r(&module, MachineType::Uint32()); |
117 module.RandomizeMemory(1112); | 121 module.RandomizeMemory(1112); |
118 | 122 |
119 BUILD(r, WASM_UNOP(kExprI32AsmjsLoadMem, WASM_GET_LOCAL(0))); | 123 BUILD(r, WASM_UNOP(kExprI32AsmjsLoadMem, WASM_GET_LOCAL(0))); |
120 | 124 |
121 memory[0] = 999999; | 125 memory[0] = 999999; |
122 CHECK_EQ(999999, r.Call(0u)); | 126 CHECK_EQ(999999, r.Call(0u)); |
123 // TODO(titzer): offset 29-31 should also be OOB. | 127 // TODO(titzer): offset 29-31 should also be OOB. |
124 for (uint32_t offset = 32; offset < 40; offset++) { | 128 for (uint32_t offset = 32; offset < 40; offset++) { |
125 CHECK_EQ(0, r.Call(offset)); | 129 CHECK_EQ(0, r.Call(offset)); |
126 } | 130 } |
127 | 131 |
128 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { | 132 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { |
129 CHECK_EQ(0, r.Call(offset)); | 133 CHECK_EQ(0, r.Call(offset)); |
130 } | 134 } |
131 } | 135 } |
132 | 136 |
133 WASM_EXEC_TEST(LoadMemF32_oob_asm) { | 137 WASM_EXEC_TEST(LoadMemF32_oob_asm) { |
134 TestingModule module; | 138 TestingModule module(execution_mode); |
135 float* memory = module.AddMemoryElems<float>(8); | 139 float* memory = module.AddMemoryElems<float>(8); |
136 WasmRunner<float> r(&module, MachineType::Uint32()); | 140 WasmRunner<float> r(&module, MachineType::Uint32()); |
137 module.RandomizeMemory(1112); | 141 module.RandomizeMemory(1112); |
138 | 142 |
139 BUILD(r, WASM_UNOP(kExprF32AsmjsLoadMem, WASM_GET_LOCAL(0))); | 143 BUILD(r, WASM_UNOP(kExprF32AsmjsLoadMem, WASM_GET_LOCAL(0))); |
140 | 144 |
141 memory[0] = 9999.5f; | 145 memory[0] = 9999.5f; |
142 CHECK_EQ(9999.5f, r.Call(0u)); | 146 CHECK_EQ(9999.5f, r.Call(0u)); |
143 // TODO(titzer): offset 29-31 should also be OOB. | 147 // TODO(titzer): offset 29-31 should also be OOB. |
144 for (uint32_t offset = 32; offset < 40; offset++) { | 148 for (uint32_t offset = 32; offset < 40; offset++) { |
145 CHECK(std::isnan(r.Call(offset))); | 149 CHECK(std::isnan(r.Call(offset))); |
146 } | 150 } |
147 | 151 |
148 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { | 152 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { |
149 CHECK(std::isnan(r.Call(offset))); | 153 CHECK(std::isnan(r.Call(offset))); |
150 } | 154 } |
151 } | 155 } |
152 | 156 |
153 WASM_EXEC_TEST(LoadMemF64_oob_asm) { | 157 WASM_EXEC_TEST(LoadMemF64_oob_asm) { |
154 TestingModule module; | 158 TestingModule module(execution_mode); |
155 double* memory = module.AddMemoryElems<double>(8); | 159 double* memory = module.AddMemoryElems<double>(8); |
156 WasmRunner<double> r(&module, MachineType::Uint32()); | 160 WasmRunner<double> r(&module, MachineType::Uint32()); |
157 module.RandomizeMemory(1112); | 161 module.RandomizeMemory(1112); |
158 | 162 |
159 BUILD(r, WASM_UNOP(kExprF64AsmjsLoadMem, WASM_GET_LOCAL(0))); | 163 BUILD(r, WASM_UNOP(kExprF64AsmjsLoadMem, WASM_GET_LOCAL(0))); |
160 | 164 |
161 memory[0] = 9799.5; | 165 memory[0] = 9799.5; |
162 CHECK_EQ(9799.5, r.Call(0u)); | 166 CHECK_EQ(9799.5, r.Call(0u)); |
163 memory[1] = 11799.25; | 167 memory[1] = 11799.25; |
164 CHECK_EQ(11799.25, r.Call(8u)); | 168 CHECK_EQ(11799.25, r.Call(8u)); |
165 // TODO(titzer): offset 57-63 should also be OOB. | 169 // TODO(titzer): offset 57-63 should also be OOB. |
166 for (uint32_t offset = 64; offset < 80; offset++) { | 170 for (uint32_t offset = 64; offset < 80; offset++) { |
167 CHECK(std::isnan(r.Call(offset))); | 171 CHECK(std::isnan(r.Call(offset))); |
168 } | 172 } |
169 | 173 |
170 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { | 174 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { |
171 CHECK(std::isnan(r.Call(offset))); | 175 CHECK(std::isnan(r.Call(offset))); |
172 } | 176 } |
173 } | 177 } |
174 | 178 |
175 WASM_EXEC_TEST(StoreMemI32_oob_asm) { | 179 WASM_EXEC_TEST(StoreMemI32_oob_asm) { |
176 TestingModule module; | 180 TestingModule module(execution_mode); |
177 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 181 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
178 WasmRunner<int32_t> r(&module, MachineType::Uint32(), MachineType::Uint32()); | 182 WasmRunner<int32_t> r(&module, MachineType::Uint32(), MachineType::Uint32()); |
179 module.RandomizeMemory(1112); | 183 module.RandomizeMemory(1112); |
180 | 184 |
181 BUILD(r, WASM_BINOP(kExprI32AsmjsStoreMem, WASM_GET_LOCAL(0), | 185 BUILD(r, WASM_BINOP(kExprI32AsmjsStoreMem, WASM_GET_LOCAL(0), |
182 WASM_GET_LOCAL(1))); | 186 WASM_GET_LOCAL(1))); |
183 | 187 |
184 memory[0] = 7777; | 188 memory[0] = 7777; |
185 CHECK_EQ(999999, r.Call(0u, 999999)); | 189 CHECK_EQ(999999, r.Call(0u, 999999)); |
186 CHECK_EQ(999999, memory[0]); | 190 CHECK_EQ(999999, memory[0]); |
187 // TODO(titzer): offset 29-31 should also be OOB. | 191 // TODO(titzer): offset 29-31 should also be OOB. |
188 for (uint32_t offset = 32; offset < 40; offset++) { | 192 for (uint32_t offset = 32; offset < 40; offset++) { |
189 CHECK_EQ(8888, r.Call(offset, 8888)); | 193 CHECK_EQ(8888, r.Call(offset, 8888)); |
190 } | 194 } |
191 | 195 |
192 for (uint32_t offset = 0x10000000; offset < 0xF0000000; offset += 0x1000000) { | 196 for (uint32_t offset = 0x10000000; offset < 0xF0000000; offset += 0x1000000) { |
193 CHECK_EQ(7777, r.Call(offset, 7777)); | 197 CHECK_EQ(7777, r.Call(offset, 7777)); |
194 } | 198 } |
195 } | 199 } |
OLD | NEW |