WebKit Bugzilla
Attachment 349391 Details for
Bug 189498
: [WebAssembly] Move type conversion code of JSToWasm return type to JS wasm wrapper
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-189498-20180911210633.patch (text/plain), 6.05 KB, created by
Yusuke Suzuki
on 2018-09-11 05:06:34 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Yusuke Suzuki
Created:
2018-09-11 05:06:34 PDT
Size:
6.05 KB
patch
obsolete
>Subversion Revision: 235892 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index e60abee4189f1442afc52c598099305a20175ed1..3140609c4c2e81f750d9cb85ca890859fa531e0b 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1 +1,25 @@ >+2018-09-11 Yusuke Suzuki <yusukesuzuki@slowstart.org> >+ >+ [WebAssembly] Move type conversion code of JSToWasm return type to JS wasm wrapper >+ https://bugs.webkit.org/show_bug.cgi?id=189498 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ To call JS-to-Wasm code we need to convert the result value from wasm function to >+ the JS type. Previously this is done by callWebAssemblyFunction by using swtich >+ over signature.returnType(). But since we know the value of `signature.returnType()` >+ at compiling phase, we can emit a small conversion code directly to JSToWasm glue >+ and remove this switch from callWebAssemblyFunction. >+ >+ In JSToWasm glue code, we do not have tag registers. So we use DoNotHaveTagRegisters >+ in boxInt32 and boxDouble. Since boxDouble does not have DoNotHaveTagRegisters version, >+ we add an implementation for that. >+ >+ * jit/AssemblyHelpers.h: >+ (JSC::AssemblyHelpers::boxDouble): >+ * wasm/js/JSToWasm.cpp: >+ (JSC::Wasm::createJSToWasmWrapper): >+ * wasm/js/WebAssemblyFunction.cpp: >+ (JSC::callWebAssemblyFunction): >+ > == Rolled over to ChangeLog-2018-09-11 == >diff --git a/Source/JavaScriptCore/jit/AssemblyHelpers.h b/Source/JavaScriptCore/jit/AssemblyHelpers.h >index 01731a5b1b1ffd78320de76c52f34ad6b4d85a55..9f1d30ba439488eeb02f6dafafb0b8c0056a6094 100644 >--- a/Source/JavaScriptCore/jit/AssemblyHelpers.h >+++ b/Source/JavaScriptCore/jit/AssemblyHelpers.h >@@ -1244,11 +1244,15 @@ class AssemblyHelpers : public MacroAssembler { > > // These methods convert between doubles, and doubles boxed and JSValues. > #if USE(JSVALUE64) >- GPRReg boxDouble(FPRReg fpr, GPRReg gpr) >+ GPRReg boxDouble(FPRReg fpr, GPRReg gpr, TagRegistersMode mode = HaveTagRegisters) > { > moveDoubleTo64(fpr, gpr); >- sub64(GPRInfo::tagTypeNumberRegister, gpr); >- jitAssertIsJSDouble(gpr); >+ if (mode == DoNotHaveTagRegisters) >+ sub64(TrustedImm64(TagTypeNumber), gpr); >+ else { >+ sub64(GPRInfo::tagTypeNumberRegister, gpr); >+ jitAssertIsJSDouble(gpr); >+ } > return gpr; > } > FPRReg unboxDoubleWithoutAssertions(GPRReg gpr, GPRReg resultGPR, FPRReg fpr) >@@ -1263,9 +1267,9 @@ class AssemblyHelpers : public MacroAssembler { > return unboxDoubleWithoutAssertions(gpr, resultGPR, fpr); > } > >- void boxDouble(FPRReg fpr, JSValueRegs regs) >+ void boxDouble(FPRReg fpr, JSValueRegs regs, TagRegistersMode mode = HaveTagRegisters) > { >- boxDouble(fpr, regs.gpr()); >+ boxDouble(fpr, regs.gpr(), mode); > } > > void unboxDoubleNonDestructive(JSValueRegs regs, FPRReg destFPR, GPRReg resultGPR, FPRReg) >diff --git a/Source/JavaScriptCore/wasm/js/JSToWasm.cpp b/Source/JavaScriptCore/wasm/js/JSToWasm.cpp >index 364f7c74bc19fc55bf2ad69bad490eceeee919da..cd24c7b8f4fbfeb6a594c25a170091374f29b756 100644 >--- a/Source/JavaScriptCore/wasm/js/JSToWasm.cpp >+++ b/Source/JavaScriptCore/wasm/js/JSToWasm.cpp >@@ -208,11 +208,27 @@ std::unique_ptr<InternalFunction> createJSToWasmWrapper(CompilationContext& comp > } > > switch (signature.returnType()) { >+ case Wasm::Void: >+ jit.moveTrustedValue(jsUndefined(), JSValueRegs { GPRInfo::returnValueGPR }); >+ break; >+ case Wasm::I32: >+ jit.zeroExtend32ToPtr(GPRInfo::returnValueGPR, GPRInfo::returnValueGPR); >+ jit.boxInt32(GPRInfo::returnValueGPR, JSValueRegs { GPRInfo::returnValueGPR }, DoNotHaveTagRegisters); >+ break; > case Wasm::F32: >- jit.moveFloatTo32(FPRInfo::returnValueFPR, GPRInfo::returnValueGPR); >+ jit.convertFloatToDouble(FPRInfo::returnValueFPR, FPRInfo::returnValueFPR); >+ FALLTHROUGH; >+ case Wasm::F64: { >+ jit.moveTrustedValue(jsNumber(pureNaN()), JSValueRegs { GPRInfo::returnValueGPR }); >+ auto isNaN = jit.branchDouble(CCallHelpers::DoubleNotEqualOrUnordered, FPRInfo::returnValueFPR, FPRInfo::returnValueFPR); >+ jit.boxDouble(FPRInfo::returnValueFPR, JSValueRegs { GPRInfo::returnValueGPR }, DoNotHaveTagRegisters); >+ isNaN.link(&jit); > break; >- case Wasm::F64: >- jit.moveDoubleTo64(FPRInfo::returnValueFPR, GPRInfo::returnValueGPR); >+ } >+ case Wasm::I64: >+ case Wasm::Func: >+ case Wasm::Anyfunc: >+ jit.breakpoint(); > break; > default: > break; >diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp >index 5db924f8ecfb03a7e0ba6f5d084822b34711bac7..f21689634d522da975ddbc540ee2abc70362c939 100644 >--- a/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp >+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp >@@ -161,22 +161,7 @@ static EncodedJSValue JSC_HOST_CALL callWebAssemblyFunction(ExecState* exec) > vm.wasmContext.store(prevWasmInstance, vm.softStackLimit()); > RETURN_IF_EXCEPTION(scope, { }); > >- switch (signature.returnType()) { >- case Wasm::Void: >- return JSValue::encode(jsUndefined()); >- case Wasm::I32: >- return JSValue::encode(jsNumber(static_cast<int32_t>(rawResult))); >- case Wasm::F32: >- return JSValue::encode(jsNumber(purifyNaN(static_cast<double>(bitwise_cast<float>(static_cast<int32_t>(rawResult)))))); >- case Wasm::F64: >- return JSValue::encode(jsNumber(purifyNaN(bitwise_cast<double>(rawResult)))); >- case Wasm::I64: >- case Wasm::Func: >- case Wasm::Anyfunc: >- RELEASE_ASSERT_NOT_REACHED(); >- } >- >- return EncodedJSValue(); >+ return rawResult; > } > > WebAssemblyFunction* WebAssemblyFunction::create(VM& vm, JSGlobalObject* globalObject, unsigned length, const String& name, JSWebAssemblyInstance* instance, Wasm::Callee& jsEntrypoint, Wasm::WasmToWasmImportableFunction::LoadLocation wasmToWasmEntrypointLoadLocation, Wasm::SignatureIndex signatureIndex)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
saam
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189498
:
349390
| 349391