2016-01-14 09:48:45 +00:00
|
|
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2016-01-18 14:28:32 +00:00
|
|
|
#include <stdio.h>
|
2016-01-14 09:48:45 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-07-23 11:42:37 +00:00
|
|
|
#include "src/api-inl.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/assembler-inl.h"
|
2018-12-17 17:01:48 +00:00
|
|
|
#include "src/objects/heap-number-inl.h"
|
2016-01-14 09:48:45 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2016-02-18 09:55:25 +00:00
|
|
|
#include "test/cctest/compiler/value-helper.h"
|
2016-01-14 09:48:45 +00:00
|
|
|
#include "test/cctest/wasm/wasm-run-utils.h"
|
2016-10-05 11:59:47 +00:00
|
|
|
#include "test/common/wasm/test-signatures.h"
|
2017-04-25 11:29:17 +00:00
|
|
|
#include "test/common/wasm/wasm-macro-gen.h"
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace wasm {
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2016-01-18 14:28:32 +00:00
|
|
|
#define ADD_CODE(vec, ...) \
|
|
|
|
do { \
|
|
|
|
byte __buf[] = {__VA_ARGS__}; \
|
|
|
|
for (size_t i = 0; i < sizeof(__buf); i++) vec.push_back(__buf[i]); \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
// A helper for generating predictable but unique argument values that
|
|
|
|
// are easy to debug (e.g. with misaligned stacks).
|
|
|
|
class PredictableInputValues {
|
|
|
|
public:
|
|
|
|
int base_;
|
|
|
|
explicit PredictableInputValues(int base) : base_(base) {}
|
|
|
|
double arg_d(int which) { return base_ * which + ((which & 1) * 0.5); }
|
|
|
|
float arg_f(int which) { return base_ * which + ((which & 1) * 0.25); }
|
|
|
|
int32_t arg_i(int which) { return base_ * which + ((which & 1) * kMinInt); }
|
|
|
|
int64_t arg_l(int which) {
|
|
|
|
return base_ * which + ((which & 1) * (0x04030201LL << 32));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-06 10:18:18 +00:00
|
|
|
ManuallyImportedJSFunction CreateJSSelector(FunctionSig* sig, int which) {
|
2016-03-29 11:41:19 +00:00
|
|
|
const int kMaxParams = 11;
|
|
|
|
static const char* formals[kMaxParams] = {"",
|
|
|
|
"a",
|
|
|
|
"a,b",
|
|
|
|
"a,b,c",
|
|
|
|
"a,b,c,d",
|
|
|
|
"a,b,c,d,e",
|
|
|
|
"a,b,c,d,e,f",
|
|
|
|
"a,b,c,d,e,f,g",
|
|
|
|
"a,b,c,d,e,f,g,h",
|
|
|
|
"a,b,c,d,e,f,g,h,i",
|
|
|
|
"a,b,c,d,e,f,g,h,i,j"};
|
2016-01-18 14:28:32 +00:00
|
|
|
CHECK_LT(which, static_cast<int>(sig->parameter_count()));
|
|
|
|
CHECK_LT(static_cast<int>(sig->parameter_count()), kMaxParams);
|
|
|
|
|
|
|
|
i::EmbeddedVector<char, 256> source;
|
|
|
|
char param = 'a' + which;
|
|
|
|
SNPrintF(source, "(function(%s) { return %c; })",
|
|
|
|
formals[sig->parameter_count()], param);
|
|
|
|
|
2018-04-06 10:18:18 +00:00
|
|
|
Handle<JSFunction> js_function =
|
|
|
|
Handle<JSFunction>::cast(v8::Utils::OpenHandle(
|
2019-04-29 11:06:49 +00:00
|
|
|
*v8::Local<v8::Function>::Cast(CompileRun(source.begin()))));
|
2018-04-06 10:18:18 +00:00
|
|
|
ManuallyImportedJSFunction import = {sig, js_function};
|
|
|
|
|
|
|
|
return import;
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
} // namespace
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_Int32Sub_jswrapped) {
|
2018-08-21 15:01:31 +00:00
|
|
|
WasmRunner<int, int, int> r(execution_tier);
|
2016-12-16 10:13:11 +00:00
|
|
|
BUILD(r, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2019-01-28 16:09:28 +00:00
|
|
|
r.CheckCallViaJS(33, 44, 11);
|
|
|
|
r.CheckCallViaJS(-8723487, -8000000, 723487);
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_Float32Div_jswrapped) {
|
2018-08-21 15:01:31 +00:00
|
|
|
WasmRunner<float, float, float> r(execution_tier);
|
2016-12-16 10:13:11 +00:00
|
|
|
BUILD(r, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2019-01-28 16:09:28 +00:00
|
|
|
r.CheckCallViaJS(92, 46, 0.5);
|
|
|
|
r.CheckCallViaJS(64, -16, -0.25);
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_Float64Add_jswrapped) {
|
2018-08-21 15:01:31 +00:00
|
|
|
WasmRunner<double, double, double> r(execution_tier);
|
2016-12-16 10:13:11 +00:00
|
|
|
BUILD(r, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2019-01-28 16:09:28 +00:00
|
|
|
r.CheckCallViaJS(3, 2, 1);
|
|
|
|
r.CheckCallViaJS(-5.5, -5.25, -0.25);
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_I32Popcount_jswrapped) {
|
2018-08-21 15:01:31 +00:00
|
|
|
WasmRunner<int, int> r(execution_tier);
|
2016-12-16 10:13:11 +00:00
|
|
|
BUILD(r, WASM_I32_POPCNT(WASM_GET_LOCAL(0)));
|
2016-01-14 09:48:45 +00:00
|
|
|
|
2019-01-28 16:09:28 +00:00
|
|
|
r.CheckCallViaJS(2, 9);
|
|
|
|
r.CheckCallViaJS(3, 11);
|
|
|
|
r.CheckCallViaJS(6, 0x3F);
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_CallJS_Add_jswrapped) {
|
2016-01-14 09:48:45 +00:00
|
|
|
TestSignatures sigs;
|
2018-04-06 10:18:18 +00:00
|
|
|
HandleScope scope(CcTest::InitIsolateOnce());
|
|
|
|
const char* source = "(function(a) { return a + 99; })";
|
|
|
|
Handle<JSFunction> js_function =
|
|
|
|
Handle<JSFunction>::cast(v8::Utils::OpenHandle(
|
|
|
|
*v8::Local<v8::Function>::Cast(CompileRun(source))));
|
|
|
|
ManuallyImportedJSFunction import = {sigs.i_i(), js_function};
|
2018-08-21 15:01:31 +00:00
|
|
|
WasmRunner<int, int> r(execution_tier, &import);
|
2018-04-06 10:18:18 +00:00
|
|
|
uint32_t js_index = 0;
|
2019-01-28 16:09:28 +00:00
|
|
|
BUILD(r, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0)));
|
2018-04-04 15:14:01 +00:00
|
|
|
|
2019-01-28 16:09:28 +00:00
|
|
|
r.CheckCallViaJS(101, 2);
|
|
|
|
r.CheckCallViaJS(199, 100);
|
|
|
|
r.CheckCallViaJS(-666666801, -666666900);
|
2016-01-14 09:48:45 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2019-03-01 10:58:14 +00:00
|
|
|
WASM_EXEC_TEST(Run_IndirectCallJSFunction) {
|
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
TestSignatures sigs;
|
|
|
|
|
|
|
|
const char* source = "(function(a, b, c) { if(c) return a; return b; })";
|
|
|
|
Handle<JSFunction> js_function =
|
|
|
|
Handle<JSFunction>::cast(v8::Utils::OpenHandle(
|
|
|
|
*v8::Local<v8::Function>::Cast(CompileRun(source))));
|
|
|
|
|
|
|
|
ManuallyImportedJSFunction import = {sigs.i_iii(), js_function};
|
|
|
|
|
|
|
|
WasmRunner<int32_t, int32_t> r(execution_tier, &import);
|
|
|
|
|
|
|
|
const uint32_t js_index = 0;
|
|
|
|
const int32_t left = -2;
|
|
|
|
const int32_t right = 3;
|
|
|
|
|
|
|
|
WasmFunctionCompiler& rc_fn = r.NewFunction(sigs.i_i(), "rc");
|
|
|
|
|
|
|
|
r.builder().AddSignature(sigs.i_iii());
|
|
|
|
uint16_t indirect_function_table[] = {static_cast<uint16_t>(js_index)};
|
|
|
|
|
|
|
|
r.builder().AddIndirectFunctionTable(indirect_function_table,
|
|
|
|
arraysize(indirect_function_table));
|
|
|
|
|
|
|
|
BUILD(rc_fn, WASM_CALL_INDIRECT3(0, WASM_I32V(js_index), WASM_I32V(left),
|
|
|
|
WASM_I32V(right), WASM_GET_LOCAL(0)));
|
|
|
|
|
|
|
|
Handle<Object> args_left[] = {isolate->factory()->NewNumber(1)};
|
2019-03-18 23:57:16 +00:00
|
|
|
r.CheckCallApplyViaJS(left, rc_fn.function_index(), args_left, 1);
|
2019-03-01 10:58:14 +00:00
|
|
|
|
|
|
|
Handle<Object> args_right[] = {isolate->factory()->NewNumber(0)};
|
2019-03-18 23:57:16 +00:00
|
|
|
r.CheckCallApplyViaJS(right, rc_fn.function_index(), args_right, 1);
|
2019-03-01 10:58:14 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 15:01:31 +00:00
|
|
|
void RunJSSelectTest(ExecutionTier tier, int which) {
|
2016-01-18 14:28:32 +00:00
|
|
|
const int kMaxParams = 8;
|
|
|
|
PredictableInputValues inputs(0x100);
|
2016-12-21 13:43:00 +00:00
|
|
|
ValueType type = kWasmF64;
|
|
|
|
ValueType types[kMaxParams + 1] = {type, type, type, type, type,
|
2016-01-18 14:28:32 +00:00
|
|
|
type, type, type, type};
|
|
|
|
for (int num_params = which + 1; num_params < kMaxParams; num_params++) {
|
|
|
|
HandleScope scope(CcTest::InitIsolateOnce());
|
|
|
|
FunctionSig sig(1, num_params, types);
|
|
|
|
|
2018-04-06 10:18:18 +00:00
|
|
|
ManuallyImportedJSFunction import = CreateJSSelector(&sig, which);
|
2018-08-21 15:01:31 +00:00
|
|
|
WasmRunner<void> r(tier, &import);
|
2018-04-06 10:18:18 +00:00
|
|
|
uint32_t js_index = 0;
|
2017-09-08 02:55:51 +00:00
|
|
|
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmFunctionCompiler& t = r.NewFunction(&sig);
|
2016-01-18 14:28:32 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
std::vector<byte> code;
|
|
|
|
|
|
|
|
for (int i = 0; i < num_params; i++) {
|
|
|
|
ADD_CODE(code, WASM_F64(inputs.arg_d(i)));
|
|
|
|
}
|
|
|
|
|
2016-09-27 20:46:10 +00:00
|
|
|
ADD_CODE(code, kExprCallFunction, static_cast<byte>(js_index));
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2016-01-18 14:28:32 +00:00
|
|
|
size_t end = code.size();
|
|
|
|
code.push_back(0);
|
|
|
|
t.Build(&code[0], &code[end]);
|
|
|
|
}
|
|
|
|
|
|
|
|
double expected = inputs.arg_d(which);
|
2019-03-18 23:57:16 +00:00
|
|
|
r.CheckCallApplyViaJS(expected, t.function_index(), nullptr, 0);
|
2016-01-18 14:28:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelect_0) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectTest(execution_tier, 0);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelect_1) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectTest(execution_tier, 1);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelect_2) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectTest(execution_tier, 2);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelect_3) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectTest(execution_tier, 3);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelect_4) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectTest(execution_tier, 4);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelect_5) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectTest(execution_tier, 5);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelect_6) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectTest(execution_tier, 6);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelect_7) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectTest(execution_tier, 7);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2018-08-21 15:01:31 +00:00
|
|
|
void RunWASMSelectTest(ExecutionTier tier, int which) {
|
2016-01-18 14:28:32 +00:00
|
|
|
PredictableInputValues inputs(0x200);
|
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
|
|
const int kMaxParams = 8;
|
|
|
|
for (int num_params = which + 1; num_params < kMaxParams; num_params++) {
|
2016-12-21 13:43:00 +00:00
|
|
|
ValueType type = kWasmF64;
|
|
|
|
ValueType types[kMaxParams + 1] = {type, type, type, type, type,
|
2016-01-18 14:28:32 +00:00
|
|
|
type, type, type, type};
|
|
|
|
FunctionSig sig(1, num_params, types);
|
|
|
|
|
2018-08-21 15:01:31 +00:00
|
|
|
WasmRunner<void> r(tier);
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmFunctionCompiler& t = r.NewFunction(&sig);
|
2016-01-18 14:28:32 +00:00
|
|
|
BUILD(t, WASM_GET_LOCAL(which));
|
|
|
|
|
|
|
|
Handle<Object> args[] = {
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(0)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(1)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(2)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(3)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(4)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(5)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(6)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(7)),
|
|
|
|
};
|
|
|
|
|
|
|
|
double expected = inputs.arg_d(which);
|
2019-03-18 23:57:16 +00:00
|
|
|
r.CheckCallApplyViaJS(expected, t.function_index(), args, kMaxParams);
|
2016-01-18 14:28:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelect_0) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectTest(execution_tier, 0);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelect_1) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectTest(execution_tier, 1);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelect_2) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectTest(execution_tier, 2);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelect_3) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectTest(execution_tier, 3);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelect_4) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectTest(execution_tier, 4);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelect_5) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectTest(execution_tier, 5);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelect_6) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectTest(execution_tier, 6);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelect_7) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectTest(execution_tier, 7);
|
2016-08-11 08:32:47 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2018-08-21 15:01:31 +00:00
|
|
|
void RunWASMSelectAlignTest(ExecutionTier tier, int num_args, int num_params) {
|
2016-01-18 14:28:32 +00:00
|
|
|
PredictableInputValues inputs(0x300);
|
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
2016-03-29 11:41:19 +00:00
|
|
|
const int kMaxParams = 10;
|
2016-01-18 14:28:32 +00:00
|
|
|
DCHECK_LE(num_args, kMaxParams);
|
2016-12-21 13:43:00 +00:00
|
|
|
ValueType type = kWasmF64;
|
|
|
|
ValueType types[kMaxParams + 1] = {type, type, type, type, type, type,
|
2016-03-29 11:41:19 +00:00
|
|
|
type, type, type, type, type};
|
2016-01-18 14:28:32 +00:00
|
|
|
FunctionSig sig(1, num_params, types);
|
|
|
|
|
|
|
|
for (int which = 0; which < num_params; which++) {
|
2018-08-21 15:01:31 +00:00
|
|
|
WasmRunner<void> r(tier);
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmFunctionCompiler& t = r.NewFunction(&sig);
|
2016-01-18 14:28:32 +00:00
|
|
|
BUILD(t, WASM_GET_LOCAL(which));
|
|
|
|
|
2016-03-29 11:41:19 +00:00
|
|
|
Handle<Object> args[] = {isolate->factory()->NewNumber(inputs.arg_d(0)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(1)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(2)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(3)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(4)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(5)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(6)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(7)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(8)),
|
|
|
|
isolate->factory()->NewNumber(inputs.arg_d(9))};
|
2016-01-18 14:28:32 +00:00
|
|
|
|
|
|
|
double nan = std::numeric_limits<double>::quiet_NaN();
|
|
|
|
double expected = which < num_args ? inputs.arg_d(which) : nan;
|
2019-03-18 23:57:16 +00:00
|
|
|
r.CheckCallApplyViaJS(expected, t.function_index(), args, num_args);
|
2016-01-18 14:28:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelectAlign_0) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectAlignTest(execution_tier, 0, 1);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 0, 2);
|
2016-01-18 14:28:32 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelectAlign_1) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectAlignTest(execution_tier, 1, 2);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 1, 3);
|
2016-01-18 14:28:32 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelectAlign_2) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectAlignTest(execution_tier, 2, 3);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 2, 4);
|
2016-01-18 14:28:32 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelectAlign_3) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectAlignTest(execution_tier, 3, 3);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 3, 4);
|
2016-01-18 14:28:32 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelectAlign_4) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectAlignTest(execution_tier, 4, 3);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 4, 4);
|
2016-01-18 14:28:32 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelectAlign_7) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectAlignTest(execution_tier, 7, 5);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 7, 6);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 7, 7);
|
2016-03-29 11:41:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelectAlign_8) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectAlignTest(execution_tier, 8, 5);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 8, 6);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 8, 7);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 8, 8);
|
2016-03-29 11:41:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelectAlign_9) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectAlignTest(execution_tier, 9, 6);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 9, 7);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 9, 8);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 9, 9);
|
2016-03-29 11:41:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_WASMSelectAlign_10) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunWASMSelectAlignTest(execution_tier, 10, 7);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 10, 8);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 10, 9);
|
|
|
|
RunWASMSelectAlignTest(execution_tier, 10, 10);
|
2016-03-29 11:41:19 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2018-08-21 15:01:31 +00:00
|
|
|
void RunJSSelectAlignTest(ExecutionTier tier, int num_args, int num_params) {
|
2016-01-18 14:28:32 +00:00
|
|
|
PredictableInputValues inputs(0x400);
|
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
|
|
Factory* factory = isolate->factory();
|
2016-03-29 11:41:19 +00:00
|
|
|
const int kMaxParams = 10;
|
2016-01-18 14:28:32 +00:00
|
|
|
CHECK_LE(num_args, kMaxParams);
|
|
|
|
CHECK_LE(num_params, kMaxParams);
|
2016-12-21 13:43:00 +00:00
|
|
|
ValueType type = kWasmF64;
|
|
|
|
ValueType types[kMaxParams + 1] = {type, type, type, type, type, type,
|
2016-03-29 11:41:19 +00:00
|
|
|
type, type, type, type, type};
|
2016-01-18 14:28:32 +00:00
|
|
|
FunctionSig sig(1, num_params, types);
|
2016-12-16 10:13:11 +00:00
|
|
|
i::AccountingAllocator allocator;
|
|
|
|
Zone zone(&allocator, ZONE_NAME);
|
2016-01-18 14:28:32 +00:00
|
|
|
|
|
|
|
// Build the calling code.
|
|
|
|
std::vector<byte> code;
|
|
|
|
|
|
|
|
for (int i = 0; i < num_params; i++) {
|
|
|
|
ADD_CODE(code, WASM_GET_LOCAL(i));
|
|
|
|
}
|
|
|
|
|
2018-04-06 10:18:18 +00:00
|
|
|
uint8_t imported_js_index = 0;
|
|
|
|
ADD_CODE(code, kExprCallFunction, imported_js_index);
|
2016-04-29 09:15:26 +00:00
|
|
|
|
2016-01-18 14:28:32 +00:00
|
|
|
size_t end = code.size();
|
|
|
|
code.push_back(0);
|
|
|
|
|
|
|
|
// Call different select JS functions.
|
|
|
|
for (int which = 0; which < num_params; which++) {
|
2018-04-06 10:18:18 +00:00
|
|
|
HandleScope scope(isolate);
|
|
|
|
ManuallyImportedJSFunction import = CreateJSSelector(&sig, which);
|
2018-08-21 15:01:31 +00:00
|
|
|
WasmRunner<void> r(tier, &import);
|
2016-12-16 10:13:11 +00:00
|
|
|
WasmFunctionCompiler& t = r.NewFunction(&sig);
|
2016-01-18 14:28:32 +00:00
|
|
|
t.Build(&code[0], &code[end]);
|
|
|
|
|
|
|
|
Handle<Object> args[] = {
|
|
|
|
factory->NewNumber(inputs.arg_d(0)),
|
|
|
|
factory->NewNumber(inputs.arg_d(1)),
|
|
|
|
factory->NewNumber(inputs.arg_d(2)),
|
|
|
|
factory->NewNumber(inputs.arg_d(3)),
|
2016-03-29 11:41:19 +00:00
|
|
|
factory->NewNumber(inputs.arg_d(4)),
|
|
|
|
factory->NewNumber(inputs.arg_d(5)),
|
|
|
|
factory->NewNumber(inputs.arg_d(6)),
|
|
|
|
factory->NewNumber(inputs.arg_d(7)),
|
|
|
|
factory->NewNumber(inputs.arg_d(8)),
|
|
|
|
factory->NewNumber(inputs.arg_d(9)),
|
2016-01-18 14:28:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
double nan = std::numeric_limits<double>::quiet_NaN();
|
|
|
|
double expected = which < num_args ? inputs.arg_d(which) : nan;
|
2019-03-18 23:57:16 +00:00
|
|
|
r.CheckCallApplyViaJS(expected, t.function_index(), args, num_args);
|
2016-01-18 14:28:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelectAlign_0) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectAlignTest(execution_tier, 0, 1);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 0, 2);
|
2016-01-18 14:28:32 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelectAlign_1) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectAlignTest(execution_tier, 1, 2);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 1, 3);
|
2016-03-29 11:41:19 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelectAlign_2) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectAlignTest(execution_tier, 2, 3);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 2, 4);
|
2016-01-18 14:28:32 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelectAlign_3) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectAlignTest(execution_tier, 3, 3);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 3, 4);
|
2016-03-29 11:41:19 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelectAlign_4) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectAlignTest(execution_tier, 4, 3);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 4, 4);
|
2016-01-18 14:28:32 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelectAlign_7) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectAlignTest(execution_tier, 7, 3);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 7, 4);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 7, 4);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 7, 4);
|
2016-03-29 11:41:19 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelectAlign_8) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectAlignTest(execution_tier, 8, 5);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 8, 6);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 8, 7);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 8, 8);
|
2016-01-18 14:28:32 +00:00
|
|
|
}
|
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelectAlign_9) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectAlignTest(execution_tier, 9, 6);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 9, 7);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 9, 8);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 9, 9);
|
2016-03-29 11:41:19 +00:00
|
|
|
}
|
2016-01-18 14:28:32 +00:00
|
|
|
|
2017-09-20 09:06:09 +00:00
|
|
|
WASM_EXEC_TEST(Run_JSSelectAlign_10) {
|
2016-08-11 08:32:47 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-08-21 15:01:31 +00:00
|
|
|
RunJSSelectAlignTest(execution_tier, 10, 7);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 10, 8);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 10, 9);
|
|
|
|
RunJSSelectAlignTest(execution_tier, 10, 10);
|
2016-01-18 14:28:32 +00:00
|
|
|
}
|
2017-09-01 12:57:34 +00:00
|
|
|
|
2019-03-07 16:30:53 +00:00
|
|
|
// Set up a test with an import, so we can return call it.
|
|
|
|
// Create a javascript function that returns left or right arguments
|
|
|
|
// depending on the value of the third argument
|
|
|
|
// function (a,b,c){ if(c)return a; return b; }
|
|
|
|
|
|
|
|
void RunPickerTest(ExecutionTier tier, bool indirect) {
|
|
|
|
EXPERIMENTAL_FLAG_SCOPE(return_call);
|
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
TestSignatures sigs;
|
|
|
|
|
|
|
|
const char* source = "(function(a,b,c) { if(c)return a; return b; })";
|
|
|
|
Handle<JSFunction> js_function =
|
|
|
|
Handle<JSFunction>::cast(v8::Utils::OpenHandle(
|
|
|
|
*v8::Local<v8::Function>::Cast(CompileRun(source))));
|
|
|
|
|
|
|
|
ManuallyImportedJSFunction import = {sigs.i_iii(), js_function};
|
|
|
|
|
|
|
|
WasmRunner<int32_t, int32_t> r(tier, &import);
|
|
|
|
|
|
|
|
const uint32_t js_index = 0;
|
|
|
|
const int32_t left = -2;
|
|
|
|
const int32_t right = 3;
|
|
|
|
|
|
|
|
WasmFunctionCompiler& rc_fn = r.NewFunction(sigs.i_i(), "rc");
|
|
|
|
|
|
|
|
if (indirect) {
|
|
|
|
r.builder().AddSignature(sigs.i_iii());
|
|
|
|
uint16_t indirect_function_table[] = {static_cast<uint16_t>(js_index)};
|
|
|
|
|
|
|
|
r.builder().AddIndirectFunctionTable(indirect_function_table,
|
|
|
|
arraysize(indirect_function_table));
|
|
|
|
|
|
|
|
BUILD(rc_fn,
|
|
|
|
WASM_RETURN_CALL_INDIRECT(0, WASM_I32V(js_index), WASM_I32V(left),
|
|
|
|
WASM_I32V(right), WASM_GET_LOCAL(0)));
|
|
|
|
} else {
|
|
|
|
BUILD(rc_fn,
|
|
|
|
WASM_RETURN_CALL_FUNCTION(js_index, WASM_I32V(left), WASM_I32V(right),
|
|
|
|
WASM_GET_LOCAL(0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<Object> args_left[] = {isolate->factory()->NewNumber(1)};
|
2019-03-18 23:57:16 +00:00
|
|
|
r.CheckCallApplyViaJS(left, rc_fn.function_index(), args_left, 1);
|
2019-03-07 16:30:53 +00:00
|
|
|
|
|
|
|
Handle<Object> args_right[] = {isolate->factory()->NewNumber(0)};
|
2019-03-18 23:57:16 +00:00
|
|
|
r.CheckCallApplyViaJS(right, rc_fn.function_index(), args_right, 1);
|
2019-03-07 16:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WASM_EXEC_TEST(Run_ReturnCallImportedFunction) {
|
|
|
|
RunPickerTest(execution_tier, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
WASM_EXEC_TEST(Run_ReturnCallIndirectImportedFunction) {
|
|
|
|
RunPickerTest(execution_tier, true);
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:59:05 +00:00
|
|
|
#undef ADD_CODE
|
|
|
|
|
2017-09-01 12:57:34 +00:00
|
|
|
} // namespace wasm
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|