-
Notifications
You must be signed in to change notification settings - Fork 38
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
Replace static_casts with Value::as<> #448
Conversation
lib/fizzy/execute.cpp
Outdated
@@ -687,7 +688,8 @@ ExecutionResult execute(Instance& instance, FuncIdx func_idx, span<const Value> | |||
const auto br_table_size = read<uint32_t>(immediates); | |||
const auto arity = read<uint32_t>(immediates); | |||
|
|||
const auto br_table_idx = stack.pop(); | |||
// TODO: is uint64_t the correct stack type here? | |||
const auto br_table_idx = stack.pop().as<uint64_t>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gumb0 do you know this top of your head: what is the idx type for br_table
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a nice table to look it up :)
fizzy/lib/fizzy/instructions.cpp
Line 29 in 0728606
/* br_table = 0x0e */ {{ValType::i32}, {}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the validation spec that defines input value as i32
https://webassembly.github.io/spec/core/valid/instructions.html#xref-syntax-instructions-syntax-instr-control-mathsf-br-table-l-ast-l-n
lib/fizzy/execute.cpp
Outdated
@@ -716,7 +718,8 @@ ExecutionResult execute(Instance& instance, FuncIdx func_idx, span<const Value> | |||
const auto expected_type_idx = read<uint32_t>(immediates); | |||
assert(expected_type_idx < instance.module.typesec.size()); | |||
|
|||
const auto elem_idx = stack.pop(); | |||
// TODO: is this the correct stack type? | |||
const auto elem_idx = stack.pop().as<uint64_t>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gumb0 this here is elem_idx type for call_indirect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov Report
@@ Coverage Diff @@
## master #448 +/- ##
=======================================
Coverage 99.50% 99.50%
=======================================
Files 52 52
Lines 14937 14939 +2
=======================================
+ Hits 14863 14865 +2
Misses 74 74 |
lib/fizzy/execute.cpp
Outdated
@@ -344,8 +344,9 @@ template <typename DstT> | |||
inline bool store_into_memory( | |||
bytes& memory, OperandStack& stack, const uint8_t*& immediates) noexcept | |||
{ | |||
const auto value = static_cast<DstT>(stack.pop()); | |||
const auto address = static_cast<uint32_t>(stack.pop()); | |||
// TODO: consider adding uint8_t/uint16_t overloads to as() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not good idea.
lib/fizzy/execute.cpp
Outdated
@@ -687,7 +688,8 @@ ExecutionResult execute(Instance& instance, FuncIdx func_idx, span<const Value> | |||
const auto br_table_size = read<uint32_t>(immediates); | |||
const auto arity = read<uint32_t>(immediates); | |||
|
|||
const auto br_table_idx = stack.pop(); | |||
// TODO: is uint64_t the correct stack type here? | |||
const auto br_table_idx = stack.pop().as<uint64_t>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const auto br_table_idx = stack.pop().as<uint64_t>(); | |
const auto br_table_idx = stack.pop().i64; |
Here and in other places.
f78903a
to
3914eb0
Compare
f1a036d
to
12ac9ef
Compare
@chfast how about this now? |
const auto value = static_cast<int32_t>(stack.pop()); | ||
stack.push(static_cast<uint64_t>(int64_t{value})); | ||
const auto value = stack.pop().as<int32_t>(); | ||
stack.push(int64_t{value}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need this int64_t{}
here? We have an appropriate constructor for Value
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is needed as this is the core of this instruction implementation (otherwise for int32_t
type the value will be cap to 32 bits). But it may be better to move it to the live above: int64_t{stack.pop().as<int32_t>()}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also squash it into a single one: stack.push(int64_t{stack.pop().as<int32_t>()}
.
It all is a matter of preference, perhaps the current one is well balanced for readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine to leave it too.
const auto value = static_cast<int32_t>(stack.pop()); | ||
stack.push(static_cast<uint64_t>(int64_t{value})); | ||
const auto value = stack.pop().as<int32_t>(); | ||
stack.push(int64_t{value}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is needed as this is the core of this instruction implementation (otherwise for int32_t
type the value will be cap to 32 bits). But it may be better to move it to the live above: int64_t{stack.pop().as<int32_t>()}
.
@@ -691,7 +693,7 @@ ExecutionResult execute(Instance& instance, FuncIdx func_idx, span<const Value> | |||
const auto br_table_size = read<uint32_t>(immediates); | |||
const auto arity = read<uint32_t>(immediates); | |||
|
|||
const auto br_table_idx = stack.pop(); | |||
const auto br_table_idx = stack.pop().as<uint32_t>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure these functional changes are in a separate commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, the _idx stuff is a separate commit, also available as #461.
Or use `.i64` directly where appropriate.
This should have been done in #423.
Depends on #446.