Skip to content

Commit

Permalink
Remove extra branch in invoke_function with metering disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jun 16, 2022
1 parent 16732c5 commit 642a3d5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/fizzy/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,19 @@ void branch(const Code& code, OperandStack& stack, const uint8_t*& pc, uint32_t
stack.drop(stack_drop);
}

template <bool MeteringEnabled>
ExecutionResult execute(
Instance& instance, FuncIdx func_idx, const Value* args, ExecutionContext& ctx) noexcept;

template <bool MeteringEnabled>
inline bool invoke_function(const FuncType& func_type, 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;

const auto ret = execute(instance, func_idx, call_args, ctx);
const auto ret = execute<MeteringEnabled>(instance, func_idx, call_args, ctx);
// Bubble up traps
if (ret.trapped)
return false;
Expand Down Expand Up @@ -657,7 +662,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<MeteringEnabled>(
called_func_type, called_func_idx, instance, stack, ctx))
goto trap;
break;
}
Expand All @@ -683,7 +689,7 @@ ExecutionResult execute(
if (expected_type != actual_type)
goto trap;

if (!invoke_function(
if (!invoke_function<MeteringEnabled>(
actual_type, called_func.func_idx, *called_func.instance, stack, ctx))
goto trap;
break;
Expand Down

0 comments on commit 642a3d5

Please sign in to comment.