Commit d20b023c authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Change signature of memory_copy_wrapper

All other simple C functions take a pointer to a stack slot which
contains the actual parameters, whereas the memory_copy_wrapper takes
three parameters. This makes the code generation from Liftoff more
difficult. This CL changes the signature of memory_copy_wrapper to match
the signature of other simple C functions.

As MemoryCopy and MemoryInit are already implemented with C calls, this
change should not make a big difference in terms of performance. Simpler
and smaller Liftoff code may have more effect on performance. If this
assumption turns out wrong, we can change it in the future.

R=clemensb@chromium.org

Bug: v8:10281
Change-Id: I39e0ea00fcb22b4e84e612fe58eb4642856b72c9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2078576
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66607}
parent 8b5d4de3
......@@ -4956,10 +4956,31 @@ Node* WasmGraphBuilder::MemoryInit(uint32_t data_segment_index, Node* dst,
Node* function = graph()->NewNode(mcgraph()->common()->ExternalConstant(
ExternalReference::wasm_memory_copy()));
MachineType sig_types[] = {MachineType::Pointer(), MachineType::Pointer(),
MachineType::Uint32()};
MachineSignature sig(0, 3, sig_types);
return SetEffect(BuildCCall(&sig, function, dst, src, size));
int stack_slot_bytes = kSystemPointerSize * 2 + sizeof(uint32_t);
Node* stack_slot =
graph()->NewNode(mcgraph()->machine()->StackSlot(stack_slot_bytes));
SetEffect(graph()->NewNode(
mcgraph()->machine()->Store(StoreRepresentation(
MachineType::PointerRepresentation(), kNoWriteBarrier)),
stack_slot, mcgraph()->Int32Constant(0), dst, effect(), control()));
SetEffect(graph()->NewNode(
mcgraph()->machine()->Store(StoreRepresentation(
MachineType::PointerRepresentation(), kNoWriteBarrier)),
stack_slot, mcgraph()->Int32Constant(kSystemPointerSize), src, effect(),
control()));
SetEffect(graph()->NewNode(
mcgraph()->machine()->Store(
StoreRepresentation(MachineRepresentation::kWord32, kNoWriteBarrier)),
stack_slot, mcgraph()->Int32Constant(kSystemPointerSize * 2), size,
effect(), control()));
MachineType sig_types[] = {MachineType::Pointer()};
MachineSignature sig(0, 1, sig_types);
return SetEffect(BuildCCall(&sig, function, stack_slot));
}
Node* WasmGraphBuilder::DataDrop(uint32_t data_segment_index,
......@@ -4986,10 +5007,31 @@ Node* WasmGraphBuilder::MemoryCopy(Node* dst, Node* src, Node* size,
Node* function = graph()->NewNode(mcgraph()->common()->ExternalConstant(
ExternalReference::wasm_memory_copy()));
MachineType sig_types[] = {MachineType::Pointer(), MachineType::Pointer(),
MachineType::Uint32()};
MachineSignature sig(0, 3, sig_types);
return SetEffect(BuildCCall(&sig, function, dst, src, size));
int stack_slot_bytes = kSystemPointerSize * 2 + sizeof(uint32_t);
Node* stack_slot =
graph()->NewNode(mcgraph()->machine()->StackSlot(stack_slot_bytes));
SetEffect(graph()->NewNode(
mcgraph()->machine()->Store(StoreRepresentation(
MachineType::PointerRepresentation(), kNoWriteBarrier)),
stack_slot, mcgraph()->Int32Constant(0), dst, effect(), control()));
SetEffect(graph()->NewNode(
mcgraph()->machine()->Store(StoreRepresentation(
MachineType::PointerRepresentation(), kNoWriteBarrier)),
stack_slot, mcgraph()->Int32Constant(kSystemPointerSize), src, effect(),
control()));
SetEffect(graph()->NewNode(
mcgraph()->machine()->Store(
StoreRepresentation(MachineRepresentation::kWord32, kNoWriteBarrier)),
stack_slot, mcgraph()->Int32Constant(kSystemPointerSize * 2), size,
effect(), control()));
MachineType sig_types[] = {MachineType::Pointer()};
MachineSignature sig(0, 1, sig_types);
return SetEffect(BuildCCall(&sig, function, stack_slot));
}
Node* WasmGraphBuilder::MemoryFill(Node* dst, Node* value, Node* size,
......
......@@ -673,7 +673,7 @@ void InstanceBuilder::LoadDataSegments(Handle<WasmInstanceObject> instance) {
reinterpret_cast<Address>(instance->memory_start()) + dest_offset;
Address src_addr = reinterpret_cast<Address>(wire_bytes.begin()) +
segment.source.offset();
memory_copy_wrapper(dest_addr, src_addr, size);
memory_copy(dest_addr, src_addr, size);
} else {
DCHECK(segment.active);
// Segments of size == 0 are just nops.
......
......@@ -331,7 +331,7 @@ void float64_pow_wrapper(Address data) {
// reset the thread-in-wasm flag before calling this function. However,
// as this is only a problem with Asan on Windows, we did not consider
// it worth the overhead.
DISABLE_ASAN void memory_copy_wrapper(Address dst, Address src, uint32_t size) {
DISABLE_ASAN void memory_copy(Address dst, Address src, uint32_t size) {
// Use explicit forward and backward copy to match the required semantics for
// the memory.copy instruction. It is assumed that the caller of this
// function has already performed bounds checks, so {src + size} and
......@@ -352,6 +352,14 @@ DISABLE_ASAN void memory_copy_wrapper(Address dst, Address src, uint32_t size) {
}
}
void memory_copy_wrapper(Address data) {
Address dst = ReadUnalignedValue<Address>(data);
Address src = ReadUnalignedValue<Address>(data + sizeof(dst));
uint32_t size =
ReadUnalignedValue<uint32_t>(data + sizeof(dst) + sizeof(src));
memory_copy(dst, src, size);
}
// Asan on Windows triggers exceptions in this function that confuse the
// WebAssembly trap handler, so Asan is disabled. See the comment on
// memory_copy_wrapper above for more info.
......
......@@ -71,7 +71,9 @@ V8_EXPORT_PRIVATE void word64_ror_wrapper(Address data);
V8_EXPORT_PRIVATE void float64_pow_wrapper(Address data);
void memory_copy_wrapper(Address dst, Address src, uint32_t size);
void memory_copy_wrapper(Address data);
void memory_copy(Address dst, Address src, uint32_t size);
void memory_fill_wrapper(Address dst, uint32_t value, uint32_t size);
......
......@@ -1824,7 +1824,7 @@ class ThreadImpl {
Address src_addr =
instance_object_->data_segment_starts()[imm.data_segment_index] +
src;
memory_copy_wrapper(dst_addr, src_addr, size);
memory_copy(dst_addr, src_addr, size);
return true;
}
case kExprDataDrop: {
......@@ -1850,7 +1850,7 @@ class ThreadImpl {
return false;
}
memory_copy_wrapper(dst_addr, src_addr, size);
memory_copy(dst_addr, src_addr, size);
return true;
}
case kExprMemoryFill: {
......
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