diff options
author | Ali Ijaz Sheikh <ofrobots@google.com> | 2016-03-01 08:58:05 -0800 |
---|---|---|
committer | Ali Sheikh <ofrobots@lemonhope.roam.corp.google.com> | 2016-03-03 20:35:20 -0800 |
commit | 069e02ab47656b3efd1b6829c65856b2e1c2d1db (patch) | |
tree | eb643e0a2e88fd64bb9fc927423458d2ae96c2db /deps/v8/test/cctest/wasm/test-run-wasm-js.cc | |
parent | 8938355398c79f583a468284b768652d12ba9bc9 (diff) | |
download | node-new-069e02ab47656b3efd1b6829c65856b2e1c2d1db.tar.gz |
deps: upgrade to V8 4.9.385.18
Pick up the current branch head for V8 4.9
https://github.com/v8/v8/commit/1ecba0f
PR-URL: https://github.com/nodejs/node/pull/4722
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michaƫl Zasso <mic.besace@gmail.com>
Diffstat (limited to 'deps/v8/test/cctest/wasm/test-run-wasm-js.cc')
-rw-r--r-- | deps/v8/test/cctest/wasm/test-run-wasm-js.cc | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/deps/v8/test/cctest/wasm/test-run-wasm-js.cc b/deps/v8/test/cctest/wasm/test-run-wasm-js.cc new file mode 100644 index 0000000000..6fcde645cb --- /dev/null +++ b/deps/v8/test/cctest/wasm/test-run-wasm-js.cc @@ -0,0 +1,141 @@ +// 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> +#include <stdlib.h> +#include <string.h> + +#include "src/wasm/wasm-macro-gen.h" + +#include "test/cctest/cctest.h" +#include "test/cctest/wasm/test-signatures.h" +#include "test/cctest/wasm/wasm-run-utils.h" + +using namespace v8::base; +using namespace v8::internal; +using namespace v8::internal::compiler; +using namespace v8::internal::wasm; + +#define BUILD(r, ...) \ + do { \ + byte code[] = {__VA_ARGS__}; \ + r.Build(code, code + arraysize(code)); \ + } while (false) + + +static uint32_t AddJsFunction(TestingModule* module, FunctionSig* sig, + const char* source) { + Handle<JSFunction> jsfunc = Handle<JSFunction>::cast(v8::Utils::OpenHandle( + *v8::Local<v8::Function>::Cast(CompileRun(source)))); + module->AddFunction(sig, Handle<Code>::null()); + uint32_t index = static_cast<uint32_t>(module->module->functions->size() - 1); + Isolate* isolate = CcTest::InitIsolateOnce(); + Handle<Code> code = CompileWasmToJSWrapper(isolate, module, jsfunc, index); + module->function_code->at(index) = code; + return index; +} + + +static Handle<JSFunction> WrapCode(ModuleEnv* module, uint32_t index) { + Isolate* isolate = module->module->shared_isolate; + // Wrap the code so it can be called as a JS function. + Handle<String> name = isolate->factory()->NewStringFromStaticChars("main"); + Handle<JSObject> module_object = Handle<JSObject>(0, isolate); + Handle<Code> code = module->function_code->at(index); + WasmJs::InstallWasmFunctionMap(isolate, isolate->native_context()); + return compiler::CompileJSToWasmWrapper(isolate, module, name, code, + module_object, index); +} + + +static void EXPECT_CALL(double expected, Handle<JSFunction> jsfunc, double a, + double b) { + Isolate* isolate = jsfunc->GetIsolate(); + Handle<Object> buffer[] = {isolate->factory()->NewNumber(a), + isolate->factory()->NewNumber(b)}; + Handle<Object> global(isolate->context()->global_object(), isolate); + MaybeHandle<Object> retval = + Execution::Call(isolate, jsfunc, global, 2, buffer); + + CHECK(!retval.is_null()); + Handle<Object> result = retval.ToHandleChecked(); + if (result->IsSmi()) { + CHECK_EQ(expected, Smi::cast(*result)->value()); + } else { + CHECK(result->IsHeapNumber()); + CHECK_EQ(expected, HeapNumber::cast(*result)->value()); + } +} + + +TEST(Run_Int32Sub_jswrapped) { + TestSignatures sigs; + TestingModule module; + WasmFunctionCompiler t(sigs.i_ii()); + BUILD(t, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); + Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd(&module)); + + EXPECT_CALL(33, jsfunc, 44, 11); + EXPECT_CALL(-8723487, jsfunc, -8000000, 723487); +} + + +TEST(Run_Float32Div_jswrapped) { + TestSignatures sigs; + TestingModule module; + WasmFunctionCompiler t(sigs.f_ff()); + BUILD(t, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); + Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd(&module)); + + EXPECT_CALL(92, jsfunc, 46, 0.5); + EXPECT_CALL(64, jsfunc, -16, -0.25); +} + + +TEST(Run_Float64Add_jswrapped) { + TestSignatures sigs; + TestingModule module; + WasmFunctionCompiler t(sigs.d_dd()); + BUILD(t, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); + Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd(&module)); + + EXPECT_CALL(3, jsfunc, 2, 1); + EXPECT_CALL(-5.5, jsfunc, -5.25, -0.25); +} + + +TEST(Run_I32Popcount_jswrapped) { + TestSignatures sigs; + TestingModule module; + WasmFunctionCompiler t(sigs.i_i()); + BUILD(t, WASM_I32_POPCNT(WASM_GET_LOCAL(0))); + Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd(&module)); + + EXPECT_CALL(2, jsfunc, 9, 0); + EXPECT_CALL(3, jsfunc, 11, 0); + EXPECT_CALL(6, jsfunc, 0x3F, 0); + + USE(AddJsFunction); +} + + +#if !V8_TARGET_ARCH_ARM64 +// TODO(titzer): fix wasm->JS calls on arm64 (wrapper issues) + +TEST(Run_CallJS_Add_jswrapped) { + TestSignatures sigs; + TestingModule module; + WasmFunctionCompiler t(sigs.i_i(), &module); + uint32_t js_index = + AddJsFunction(&module, sigs.i_i(), "(function(a) { return a + 99; })"); + BUILD(t, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0))); + + Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd(&module)); + + EXPECT_CALL(101, jsfunc, 2, -8); + EXPECT_CALL(199, jsfunc, 100, -1); + EXPECT_CALL(-666666801, jsfunc, -666666900, -1); +} + +#endif |