mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:57:35 +00:00
LibWasm: Implement memory.fill instruction
This commit is contained in:
parent
e96c64cdb4
commit
42adba5ad4
1 changed files with 24 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
|
* Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
|
||||||
|
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -615,6 +616,29 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi
|
||||||
configuration.stack().peek() = Value((i32)-1);
|
configuration.stack().peek() = Value((i32)-1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// https://webassembly.github.io/spec/core/bikeshed/#exec-memory-fill
|
||||||
|
case Instructions::memory_fill.value(): {
|
||||||
|
auto address = configuration.frame().module().memories()[0];
|
||||||
|
auto instance = configuration.store().get(address);
|
||||||
|
auto count = configuration.stack().pop().get<Value>().to<i32>().value();
|
||||||
|
auto value = configuration.stack().pop().get<Value>().to<i32>().value();
|
||||||
|
auto destination_offset = configuration.stack().pop().get<Value>().to<i32>().value();
|
||||||
|
|
||||||
|
TRAP_IF_NOT(static_cast<size_t>(destination_offset + count) <= instance->data().size());
|
||||||
|
|
||||||
|
if (count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Instruction synthetic_store_instruction {
|
||||||
|
Instructions::i32_store8,
|
||||||
|
Instruction::MemoryArgument { 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
for (auto i = 0; i < count; ++i) {
|
||||||
|
store_to_memory(configuration, synthetic_store_instruction, { &value, sizeof(value) }, destination_offset);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
case Instructions::table_get.value():
|
case Instructions::table_get.value():
|
||||||
case Instructions::table_set.value():
|
case Instructions::table_set.value():
|
||||||
goto unimplemented;
|
goto unimplemented;
|
||||||
|
@ -950,7 +974,6 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi
|
||||||
}
|
}
|
||||||
case Instructions::data_drop.value():
|
case Instructions::data_drop.value():
|
||||||
case Instructions::memory_copy.value():
|
case Instructions::memory_copy.value():
|
||||||
case Instructions::memory_fill.value():
|
|
||||||
case Instructions::table_init.value():
|
case Instructions::table_init.value():
|
||||||
case Instructions::elem_drop.value():
|
case Instructions::elem_drop.value():
|
||||||
case Instructions::table_copy.value():
|
case Instructions::table_copy.value():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue