| OLD | NEW |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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 <cstdint> | 5 #include <cstdint> |
| 6 | 6 |
| 7 #include "src/assembler-inl.h" | 7 #include "src/assembler-inl.h" |
| 8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
| 9 #include "src/wasm/wasm-macro-gen.h" | 9 #include "src/wasm/wasm-macro-gen.h" |
| 10 #include "src/wasm/wasm-objects.h" | 10 #include "src/wasm/wasm-objects.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 WasmRunnerBase& runner, WasmFunctionCompiler& inner_compiler, | 80 WasmRunnerBase& runner, WasmFunctionCompiler& inner_compiler, |
| 81 std::initializer_list<uint8_t> bytes_inner_function, | 81 std::initializer_list<uint8_t> bytes_inner_function, |
| 82 std::initializer_list<uint8_t> bytes_outer_function, | 82 std::initializer_list<uint8_t> bytes_outer_function, |
| 83 const T& expected_lambda) { | 83 const T& expected_lambda) { |
| 84 return ArgPassingHelper<T>(runner, inner_compiler, bytes_inner_function, | 84 return ArgPassingHelper<T>(runner, inner_compiler, bytes_inner_function, |
| 85 bytes_outer_function, expected_lambda); | 85 bytes_outer_function, expected_lambda); |
| 86 } | 86 } |
| 87 | 87 |
| 88 } // namespace | 88 } // namespace |
| 89 | 89 |
| 90 // Pass int32_t, return int32_t. |
| 90 TEST(TestArgumentPassing_int32) { | 91 TEST(TestArgumentPassing_int32) { |
| 91 WasmRunner<int32_t, int32_t> runner(kExecuteCompiled); | 92 WasmRunner<int32_t, int32_t> runner(kExecuteCompiled); |
| 92 WasmFunctionCompiler& f2 = runner.NewFunction<int32_t, int32_t>(); | 93 WasmFunctionCompiler& f2 = runner.NewFunction<int32_t, int32_t>(); |
| 93 | 94 |
| 94 auto helper = GetHelper( | 95 auto helper = GetHelper( |
| 95 runner, f2, | 96 runner, f2, |
| 96 {// Return 2*<0> + 1. | 97 {// Return 2*<0> + 1. |
| 97 WASM_I32_ADD(WASM_I32_MUL(WASM_I32V_1(2), WASM_GET_LOCAL(0)), WASM_ONE)}, | 98 WASM_I32_ADD(WASM_I32_MUL(WASM_I32V_1(2), WASM_GET_LOCAL(0)), WASM_ONE)}, |
| 98 {// Call f2 with param <0>. | 99 {// Call f2 with param <0>. |
| 99 WASM_GET_LOCAL(0), WASM_CALL_FUNCTION0(f2.function_index())}, | 100 WASM_GET_LOCAL(0), WASM_CALL_FUNCTION0(f2.function_index())}, |
| 100 [](int32_t a) { return 2 * a + 1; }); | 101 [](int32_t a) { return 2 * a + 1; }); |
| 101 | 102 |
| 102 std::vector<int32_t> test_values = compiler::ValueHelper::int32_vector(); | 103 std::vector<int32_t> test_values = compiler::ValueHelper::int32_vector(); |
| 103 for (int32_t v : test_values) helper.CheckCall(v); | 104 for (int32_t v : test_values) helper.CheckCall(v); |
| 104 } | 105 } |
| 105 | 106 |
| 106 TEST(TestArgumentPassing_int64) { | 107 // Pass int64_t, return double. |
| 108 TEST(TestArgumentPassing_double_int64) { |
| 107 WasmRunner<double, int32_t, int32_t> runner(kExecuteCompiled); | 109 WasmRunner<double, int32_t, int32_t> runner(kExecuteCompiled); |
| 108 WasmFunctionCompiler& f2 = runner.NewFunction<double, int64_t>(); | 110 WasmFunctionCompiler& f2 = runner.NewFunction<double, int64_t>(); |
| 109 | 111 |
| 110 auto helper = GetHelper( | 112 auto helper = GetHelper( |
| 111 runner, f2, | 113 runner, f2, |
| 112 {// Return (double)<0>. | 114 {// Return (double)<0>. |
| 113 WASM_F64_SCONVERT_I64(WASM_GET_LOCAL(0))}, | 115 WASM_F64_SCONVERT_I64(WASM_GET_LOCAL(0))}, |
| 114 {// Call f2 with param (<0> | (<1> << 32)). | 116 {// Call f2 with param (<0> | (<1> << 32)). |
| 115 WASM_I64_IOR(WASM_I64_UCONVERT_I32(WASM_GET_LOCAL(0)), | 117 WASM_I64_IOR(WASM_I64_UCONVERT_I32(WASM_GET_LOCAL(0)), |
| 116 WASM_I64_SHL(WASM_I64_UCONVERT_I32(WASM_GET_LOCAL(1)), | 118 WASM_I64_SHL(WASM_I64_UCONVERT_I32(WASM_GET_LOCAL(1)), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 131 | 133 |
| 132 std::vector<int64_t> test_values_i64 = compiler::ValueHelper::int64_vector(); | 134 std::vector<int64_t> test_values_i64 = compiler::ValueHelper::int64_vector(); |
| 133 for (int64_t v : test_values_i64) { | 135 for (int64_t v : test_values_i64) { |
| 134 int32_t v1 = static_cast<int32_t>(v); | 136 int32_t v1 = static_cast<int32_t>(v); |
| 135 int32_t v2 = static_cast<int32_t>(v >> 32); | 137 int32_t v2 = static_cast<int32_t>(v >> 32); |
| 136 helper.CheckCall(v1, v2); | 138 helper.CheckCall(v1, v2); |
| 137 helper.CheckCall(v2, v1); | 139 helper.CheckCall(v2, v1); |
| 138 } | 140 } |
| 139 } | 141 } |
| 140 | 142 |
| 143 // Pass double, return int64_t. |
| 144 TEST(TestArgumentPassing_int64_double) { |
| 145 // Outer function still returns double. |
| 146 WasmRunner<double, double> runner(kExecuteCompiled); |
| 147 WasmFunctionCompiler& f2 = runner.NewFunction<int64_t, double>(); |
| 148 |
| 149 auto helper = GetHelper( |
| 150 runner, f2, |
| 151 {// Return (int64_t)<0>. |
| 152 WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0))}, |
| 153 {// Call f2 with param <0>, convert returned value back to double. |
| 154 WASM_F64_SCONVERT_I64(WASM_SEQ( |
| 155 WASM_GET_LOCAL(0), WASM_CALL_FUNCTION0(f2.function_index())))}, |
| 156 [](double d) { return d; }); |
| 157 |
| 158 for (int64_t i : compiler::ValueHelper::int64_vector()) { |
| 159 helper.CheckCall(i); |
| 160 } |
| 161 } |
| 162 |
| 163 // Pass float, return double. |
| 141 TEST(TestArgumentPassing_float_double) { | 164 TEST(TestArgumentPassing_float_double) { |
| 142 WasmRunner<double, float> runner(kExecuteCompiled); | 165 WasmRunner<double, float> runner(kExecuteCompiled); |
| 143 WasmFunctionCompiler& f2 = runner.NewFunction<double, float>(); | 166 WasmFunctionCompiler& f2 = runner.NewFunction<double, float>(); |
| 144 | 167 |
| 145 auto helper = GetHelper( | 168 auto helper = GetHelper( |
| 146 runner, f2, | 169 runner, f2, |
| 147 {// Return 2*(double)<0> + 1. | 170 {// Return 2*(double)<0> + 1. |
| 148 WASM_F64_ADD( | 171 WASM_F64_ADD( |
| 149 WASM_F64_MUL(WASM_F64(2), WASM_F64_CONVERT_F32(WASM_GET_LOCAL(0))), | 172 WASM_F64_MUL(WASM_F64(2), WASM_F64_CONVERT_F32(WASM_GET_LOCAL(0))), |
| 150 WASM_F64(1))}, | 173 WASM_F64(1))}, |
| 151 {// Call f2 with param <0>. | 174 {// Call f2 with param <0>. |
| 152 WASM_GET_LOCAL(0), WASM_CALL_FUNCTION0(f2.function_index())}, | 175 WASM_GET_LOCAL(0), WASM_CALL_FUNCTION0(f2.function_index())}, |
| 153 [](float f) { return 2. * static_cast<double>(f) + 1.; }); | 176 [](float f) { return 2. * static_cast<double>(f) + 1.; }); |
| 154 | 177 |
| 155 std::vector<float> test_values = compiler::ValueHelper::float32_vector(); | 178 std::vector<float> test_values = compiler::ValueHelper::float32_vector(); |
| 156 for (float f : test_values) helper.CheckCall(f); | 179 for (float f : test_values) helper.CheckCall(f); |
| 157 } | 180 } |
| 158 | 181 |
| 182 // Pass two doubles, return double. |
| 159 TEST(TestArgumentPassing_double_double) { | 183 TEST(TestArgumentPassing_double_double) { |
| 160 WasmRunner<double, double, double> runner(kExecuteCompiled); | 184 WasmRunner<double, double, double> runner(kExecuteCompiled); |
| 161 WasmFunctionCompiler& f2 = runner.NewFunction<double, double, double>(); | 185 WasmFunctionCompiler& f2 = runner.NewFunction<double, double, double>(); |
| 162 | 186 |
| 163 auto helper = GetHelper(runner, f2, | 187 auto helper = GetHelper(runner, f2, |
| 164 {// Return <0> + <1>. | 188 {// Return <0> + <1>. |
| 165 WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}, | 189 WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}, |
| 166 {// Call f2 with params <0>, <1>. | 190 {// Call f2 with params <0>, <1>. |
| 167 WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), | 191 WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), |
| 168 WASM_CALL_FUNCTION0(f2.function_index())}, | 192 WASM_CALL_FUNCTION0(f2.function_index())}, |
| 169 [](double a, double b) { return a + b; }); | 193 [](double a, double b) { return a + b; }); |
| 170 | 194 |
| 171 std::vector<double> test_values = compiler::ValueHelper::float64_vector(); | 195 std::vector<double> test_values = compiler::ValueHelper::float64_vector(); |
| 172 for (double d1 : test_values) { | 196 for (double d1 : test_values) { |
| 173 for (double d2 : test_values) { | 197 for (double d2 : test_values) { |
| 174 helper.CheckCall(d1, d2); | 198 helper.CheckCall(d1, d2); |
| 175 } | 199 } |
| 176 } | 200 } |
| 177 } | 201 } |
| 178 | 202 |
| 203 // Pass int32_t, int64_t, float and double, return double. |
| 179 TEST(TestArgumentPassing_AllTypes) { | 204 TEST(TestArgumentPassing_AllTypes) { |
| 180 // The second and third argument will be combined to an i64. | 205 // The second and third argument will be combined to an i64. |
| 181 WasmRunner<double, int, int, int, float, double> runner(kExecuteCompiled); | 206 WasmRunner<double, int32_t, int32_t, int32_t, float, double> runner( |
| 207 kExecuteCompiled); |
| 182 WasmFunctionCompiler& f2 = | 208 WasmFunctionCompiler& f2 = |
| 183 runner.NewFunction<double, int, int64_t, float, double>(); | 209 runner.NewFunction<double, int32_t, int64_t, float, double>(); |
| 184 | 210 |
| 185 auto helper = GetHelper( | 211 auto helper = GetHelper( |
| 186 runner, f2, | 212 runner, f2, |
| 187 { | 213 { |
| 188 // Convert all arguments to double, add them and return the sum. | 214 // Convert all arguments to double, add them and return the sum. |
| 189 WASM_F64_ADD( // <0+1+2> + <3> | 215 WASM_F64_ADD( // <0+1+2> + <3> |
| 190 WASM_F64_ADD( // <0+1> + <2> | 216 WASM_F64_ADD( // <0+1> + <2> |
| 191 WASM_F64_ADD( // <0> + <1> | 217 WASM_F64_ADD( // <0> + <1> |
| 192 WASM_F64_SCONVERT_I32( | 218 WASM_F64_SCONVERT_I32( |
| 193 WASM_GET_LOCAL(0)), // <0> to double | 219 WASM_GET_LOCAL(0)), // <0> to double |
| (...skipping 29 matching lines...) Expand all Loading... |
| 223 std::max(std::max(test_values_i32.size(), test_values_i64.size()), | 249 std::max(std::max(test_values_i32.size(), test_values_i64.size()), |
| 224 std::max(test_values_f32.size(), test_values_f64.size())); | 250 std::max(test_values_f32.size(), test_values_f64.size())); |
| 225 for (size_t i = 0; i < max_len; ++i) { | 251 for (size_t i = 0; i < max_len; ++i) { |
| 226 int32_t i32 = test_values_i32[i % test_values_i32.size()]; | 252 int32_t i32 = test_values_i32[i % test_values_i32.size()]; |
| 227 int64_t i64 = test_values_i64[i % test_values_i64.size()]; | 253 int64_t i64 = test_values_i64[i % test_values_i64.size()]; |
| 228 float f32 = test_values_f32[i % test_values_f32.size()]; | 254 float f32 = test_values_f32[i % test_values_f32.size()]; |
| 229 double f64 = test_values_f64[i % test_values_f64.size()]; | 255 double f64 = test_values_f64[i % test_values_f64.size()]; |
| 230 CheckCall(i32, i64, f32, f64); | 256 CheckCall(i32, i64, f32, f64); |
| 231 } | 257 } |
| 232 } | 258 } |
| OLD | NEW |