LibWasm: Utilise direct threading if/when possible

~50% performance improvement on coremark.
This commit is contained in:
Ali Mohammad Pur 2025-09-19 23:06:08 +02:00 committed by Ali Mohammad Pur
parent cf30d61d8b
commit 02b3c4f8a9
4 changed files with 3616 additions and 2118 deletions

File diff suppressed because it is too large Load Diff

View File

@ -61,10 +61,9 @@ struct WASM_API BytecodeInterpreter final : public Interpreter {
IndirectCall,
};
template<bool HasCompiledList, bool HasDynamicInsnLimit>
template<bool HasCompiledList, bool HasDynamicInsnLimit, bool HaveDirectThreadingInfo>
void interpret_impl(Configuration&, Expression const&);
protected:
InstructionPointer branch_to_label(Configuration&, LabelIndex);
template<typename ReadT, typename PushT>
bool load_and_push(Configuration&, Instruction const&, SourcesAndDestination const&);
@ -97,6 +96,12 @@ protected:
template<typename PopType, typename PushType, typename Operator, typename... Args>
bool unary_operation(Configuration&, SourcesAndDestination const&, Args&&...);
ALWAYS_INLINE bool set_trap(StringView reason)
{
m_trap = Trap { ByteString(reason) };
return true;
}
template<typename T>
T read_value(ReadonlyBytes data);
@ -119,6 +124,7 @@ protected:
return false;
}
protected:
Variant<Trap, Empty> m_trap;
StackInfo const& m_stack_info;
};

View File

@ -21,7 +21,10 @@ public:
void set_frame(Frame frame)
{
Label label(frame.arity(), frame.expression().instructions().size() - 1, m_value_stack.size());
auto continuation = frame.expression().instructions().size() - 1;
if (auto size = frame.expression().compiled_instructions.dispatches.size(); size > 0)
continuation = size - 1;
Label label(frame.arity(), continuation, m_value_stack.size());
frame.label_index() = m_label_stack.size();
if (auto hint = frame.expression().stack_usage_hint(); hint.has_value())
m_value_stack.ensure_capacity(*hint + m_value_stack.size());

View File

@ -535,7 +535,10 @@ struct Dispatch {
Stack = CountRegisters,
};
OpCode instruction_opcode;
union {
OpCode instruction_opcode;
FlatPtr handler_ptr;
};
Instruction const* instruction { nullptr };
union {
struct {
@ -548,6 +551,7 @@ struct Dispatch {
struct CompiledInstructions {
Vector<Dispatch> dispatches;
Vector<Instruction, 0, FastLastAccess::Yes> extra_instruction_storage;
bool direct = false; // true if all dispatches contain handler_ptr, otherwise false and all contain instruction_opcode.
};
struct SectionId {