Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update stack top in {unary,binary}_op() helpers
Browse files Browse the repository at this point in the history
chfast committed May 26, 2020

Verified

This commit was signed with the committer’s verified signature. The key has expired.
chfast Paweł Bylica
1 parent 6068b41 commit 992b512
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/fizzy/execute.cpp
Original file line number Diff line number Diff line change
@@ -378,26 +378,25 @@ inline bool store_into_memory(bytes& memory, OperandStack& stack, const uint8_t*
template <typename Op>
inline void unary_op(OperandStack& stack, Op op) noexcept
{
using T = decltype(op(stack.pop()));
const auto a = static_cast<T>(stack.pop());
stack.push(op(a));
using T = decltype(op(stack.top()));
stack.top() = op(static_cast<T>(stack.top()));
}

template <typename Op>
inline void binary_op(OperandStack& stack, Op op) noexcept
{
using T = decltype(op(stack.pop(), stack.pop()));
using T = decltype(op(stack.top(), stack.top()));
const auto val2 = static_cast<T>(stack.pop());
const auto val1 = static_cast<T>(stack.pop());
stack.push(static_cast<std::make_unsigned_t<T>>(op(val1, val2)));
const auto val1 = static_cast<T>(stack.top());
stack.top() = static_cast<std::make_unsigned_t<T>>(op(val1, val2));
}

template <typename T, template <typename> class Op>
inline void comparison_op(OperandStack& stack, Op<T> op) noexcept
{
const auto val2 = static_cast<T>(stack.pop());
const auto val1 = static_cast<T>(stack.pop());
stack.push(uint32_t{op(val1, val2)});
const auto val1 = static_cast<T>(stack.top());
stack.top() = uint32_t{op(val1, val2)};
}

template <typename T>

0 comments on commit 992b512

Please sign in to comment.