Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke refactoring #564

Draft
wants to merge 2 commits into
base: optimize_call_result_push
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/fizzy/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,9 @@ void branch(const Code& code, OperandStack& stack, const uint8_t*& pc, uint32_t
stack.drop(stack_drop);
}

inline bool invoke_function(const FuncType& func_type, uint32_t func_idx, Instance& instance,
OperandStack& stack, ExecutionContext& ctx) noexcept
inline bool invoke_function(size_t num_args, [[maybe_unused]] size_t num_ret, uint32_t func_idx,
Instance& instance, OperandStack& stack, ExecutionContext& ctx) noexcept
{
const auto num_args = func_type.inputs.size();
assert(stack.size() >= num_args);
const auto call_args = stack.rend() - num_args;

Expand All @@ -525,7 +524,7 @@ inline bool invoke_function(const FuncType& func_type, uint32_t func_idx, Instan
stack.drop(num_args);

// NOTE: validation ensures there is at most 1 output value
assert(func_type.outputs.size() == (ret.has_value ? 1 : 0));
assert(num_ret == (ret.has_value ? 1 : 0));
// Push back the result
if (ret.has_value)
stack.push(ret.value);
Expand Down Expand Up @@ -631,7 +630,8 @@ ExecutionResult execute(
const auto called_func_idx = read<uint32_t>(pc);
const auto& called_func_type = instance.module->get_function_type(called_func_idx);

if (!invoke_function(called_func_type, called_func_idx, instance, stack, ctx))
if (!invoke_function(called_func_type.inputs.size(), called_func_type.outputs.size(),
called_func_idx, instance, stack, ctx))
goto trap;
break;
}
Expand All @@ -657,8 +657,8 @@ ExecutionResult execute(
if (expected_type != actual_type)
goto trap;

if (!invoke_function(
actual_type, called_func.func_idx, *called_func.instance, stack, ctx))
if (!invoke_function(actual_type.inputs.size(), actual_type.outputs.size(),
called_func.func_idx, *called_func.instance, stack, ctx))
goto trap;
break;
}
Expand Down