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.
This commit is contained in:
Diego Frias 2024-08-02 21:12:20 -07:00 committed by Ali Mohammad Pur
commit a2448308fd
Notes: github-actions[bot] 2024-08-06 23:11:18 +00:00
2 changed files with 1 additions and 19 deletions

View file

@ -63,14 +63,8 @@ void BytecodeInterpreter::branch_to_label(Configuration& configuration, LabelInd
configuration.label_stack().take_last(); configuration.label_stack().take_last();
auto label = configuration.label_stack().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()); 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(); configuration.ip() = label.continuation();
} }
@ -409,17 +403,6 @@ double BytecodeInterpreter::read_value<double>(ReadonlyBytes data)
return bit_cast<double>(static_cast<u64>(raw_value)); return bit_cast<double>(static_cast<u64>(raw_value));
} }
Vector<Value> BytecodeInterpreter::pop_values(Configuration& configuration, size_t count)
{
Vector<Value> 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) 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()); dbgln_if(WASM_TRACE_DEBUG, "Executing instruction {} at ip {}", instruction_name(instruction.opcode()), ip.value());

View file

@ -79,7 +79,6 @@ protected:
template<typename T> template<typename T>
T read_value(ReadonlyBytes data); T read_value(ReadonlyBytes data);
Vector<Value> pop_values(Configuration& configuration, size_t count);
ALWAYS_INLINE bool trap_if_not(bool value, StringView reason) ALWAYS_INLINE bool trap_if_not(bool value, StringView reason)
{ {
if (!value) if (!value)