From a2448308fd90ba0aafd42587a091c0da3c037ba9 Mon Sep 17 00:00:00 2001 From: Diego Frias Date: Fri, 2 Aug 2024 21:12:20 -0700 Subject: [PATCH] LibWasm: Directly remove from the stack when clearing a label Theoretically, the previous "pop, then push" method should be faster, but it's actually faster to just remove from the stack directly. --- .../AbstractMachine/BytecodeInterpreter.cpp | 19 +------------------ .../AbstractMachine/BytecodeInterpreter.h | 1 - 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index a6941c21baf..50ce2f43dfa 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -63,14 +63,8 @@ void BytecodeInterpreter::branch_to_label(Configuration& configuration, LabelInd configuration.label_stack().take_last(); auto label = configuration.label_stack().last(); dbgln_if(WASM_TRACE_DEBUG, "...which is actually IP {}, and has {} result(s)", label.continuation().value(), label.arity()); - auto results = pop_values(configuration, label.arity()); - - while (configuration.value_stack().size() != label.stack_height()) - configuration.value_stack().take_last(); - - for (auto& result : results.in_reverse()) - configuration.value_stack().append(result); + configuration.value_stack().remove(label.stack_height(), configuration.value_stack().size() - label.stack_height() - label.arity()); configuration.ip() = label.continuation(); } @@ -409,17 +403,6 @@ double BytecodeInterpreter::read_value(ReadonlyBytes data) return bit_cast(static_cast(raw_value)); } -Vector BytecodeInterpreter::pop_values(Configuration& configuration, size_t count) -{ - Vector results; - results.resize(count); - - for (size_t i = 0; i < count; ++i) - results[i] = configuration.value_stack().take_last(); - - return results; -} - ALWAYS_INLINE void BytecodeInterpreter::interpret_instruction(Configuration& configuration, InstructionPointer& ip, Instruction const& instruction) { dbgln_if(WASM_TRACE_DEBUG, "Executing instruction {} at ip {}", instruction_name(instruction.opcode()), ip.value()); diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h index 8c39238483d..18234c56ee5 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.h @@ -79,7 +79,6 @@ protected: template T read_value(ReadonlyBytes data); - Vector pop_values(Configuration& configuration, size_t count); ALWAYS_INLINE bool trap_if_not(bool value, StringView reason) { if (!value)