Commit e950f040 authored by evih's avatar evih Committed by Commit Bot

[wasm] Use js-to-wasm generic wrapper for i64 return

Currently, the generic wrapper is used for i32 and i64 params and 0 or 1
i32 and i64 return value.

Bug: v8:10701
Change-Id: I4b592d7e0e4ebcb3455520c094c92bf4177c5a5a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2412179Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Eva Herencsárová <evih@google.com>
Cr-Commit-Position: refs/heads/master@{#69920}
parent 440bb752
......@@ -3392,10 +3392,13 @@ void Builtins::Generate_GenericJSToWasmWrapper(MacroAssembler* masm) {
kFrameMarkerOffset - kSystemPointerSize;
constexpr int kParamCountOffset = kGCScanSlotCountOffset - kSystemPointerSize;
constexpr int kReturnCountOffset = kParamCountOffset - kSystemPointerSize;
constexpr int kNumSpillSlots = 3;
constexpr int kValueTypesArrayStartOffset =
kReturnCountOffset - kSystemPointerSize;
constexpr int kNumSpillSlots = 4;
__ subq(rsp, Immediate(kNumSpillSlots * kSystemPointerSize));
__ movq(MemOperand(rbp, kParamCountOffset), param_count);
__ movq(MemOperand(rbp, kReturnCountOffset), return_count);
__ movq(MemOperand(rbp, kValueTypesArrayStartOffset), valuetypes_array_ptr);
// -------------------------------------------
// Parameter handling.
......@@ -3654,26 +3657,26 @@ void Builtins::Generate_GenericJSToWasmWrapper(MacroAssembler* masm) {
current_param_slot, valuetypes_array_ptr, wasm_instance,
function_data);
Label kWasmI32_not_smi;
Label kWasmI64;
Label param_kWasmI32_not_smi;
Label param_kWasmI64;
Label restore_after_buitlin_call;
__ cmpq(valuetype, Immediate(wasm::kWasmI32.raw_bit_field()));
__ j(equal, &kWasmI32_not_smi);
__ j(equal, &param_kWasmI32_not_smi);
__ cmpq(valuetype, Immediate(wasm::kWasmI64.raw_bit_field()));
__ j(equal, &kWasmI64);
__ j(equal, &param_kWasmI64);
__ int3();
__ bind(&kWasmI32_not_smi);
__ bind(&param_kWasmI32_not_smi);
__ Call(BUILTIN_CODE(masm->isolate(), WasmTaggedNonSmiToInt32),
RelocInfo::CODE_TARGET);
// Param is the result of the builtin.
__ AssertZeroExtended(param);
__ jmp(&restore_after_buitlin_call);
__ bind(&kWasmI64);
__ bind(&param_kWasmI64);
__ Call(BUILTIN_CODE(masm->isolate(), BigIntToI64), RelocInfo::CODE_TARGET);
__ bind(&restore_after_buitlin_call);
......@@ -3684,10 +3687,34 @@ void Builtins::Generate_GenericJSToWasmWrapper(MacroAssembler* masm) {
__ jmp(&param_conversion_done);
// -------------------------------------------
// Return conversions (just kWasmI32 for now).
// Return conversions.
// -------------------------------------------
__ bind(&convert_return);
__ movq(valuetypes_array_ptr, MemOperand(rbp, kValueTypesArrayStartOffset));
// The first valuetype of the array is the return's valuetype.
__ movl(valuetype,
Operand(valuetypes_array_ptr, wasm::ValueType::bit_field_offset()));
Label return_kWasmI32;
Label return_kWasmI64;
__ cmpq(valuetype, Immediate(wasm::kWasmI32.raw_bit_field()));
__ j(equal, &return_kWasmI32);
__ cmpq(valuetype, Immediate(wasm::kWasmI64.raw_bit_field()));
__ j(equal, &return_kWasmI64);
__ int3();
__ bind(&return_kWasmI64);
// We don't need the JS context for this builtin call.
__ Call(BUILTIN_CODE(masm->isolate(), I64ToBigInt), RelocInfo::CODE_TARGET);
// We will need the parameter_count later.
__ movq(param_count, MemOperand(rbp, kParamCountOffset));
__ jmp(&return_done);
__ bind(&return_kWasmI32);
Label to_heapnumber;
// If pointer compression is disabled, we can convert the return to a smi.
if (SmiValuesAre32Bits()) {
......
......@@ -273,7 +273,8 @@ bool UseGenericWrapper(const FunctionSig* sig) {
return false;
}
if (sig->returns().size() == 1 &&
sig->GetReturn(0).kind() != ValueType::kI32) {
sig->GetReturn(0).kind() != ValueType::kI32 &&
sig->GetReturn(0).kind() != ValueType::kI64) {
return false;
}
for (ValueType type : sig->parameters()) {
......
......@@ -237,7 +237,7 @@ let kSig_v_iiiiiiii = makeSig([kWasmI32, kWasmI32, kWasmI32, kWasmI32,
assertEquals(33, x);
})();
(function testGenericWrapper1ReturnSmi() {
(function testGenericWrapper1I32ReturnSmi() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig_index = builder.addType(kSig_i_i);
......@@ -258,7 +258,7 @@ let kSig_v_iiiiiiii = makeSig([kWasmI32, kWasmI32, kWasmI32, kWasmI32,
assertEquals(17, instance.exports.main(5));
})();
(function testGenericWrapper1ReturnHeapNumber() {
(function testGenericWrapper1I32ReturnHeapNumber() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig_index = builder.addType(kSig_i_i);
......@@ -368,3 +368,23 @@ let kSig_v_liilliiil = makeSig([kWasmI64, kWasmI32, kWasmI32, kWasmI64,
let instance = builder.instantiate({ mod: { func: import_func } });
assertThrows(() => { instance.exports.main(17) }, TypeError);
})();
(function testGenericWrapper1I64Return() {
print(arguments.callee.name);
let builder = new WasmModuleBuilder();
let sig_index = builder.addType(kSig_l_v);
let func_index = builder.addImport("mod", "func", sig_index);
builder.addFunction("main", sig_index)
.addBody([
kExprCallFunction, func_index
])
.exportFunc();
function import_func() {
gc();
return 10000000000n;
}
let instance = builder.instantiate({ mod: { func: import_func } });
assertEquals(10000000000n, instance.exports.main());
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment