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

Replace static_casts with Value::as<> #448

Merged
merged 2 commits into from
Aug 7, 2020
Merged

Replace static_casts with Value::as<> #448

merged 2 commits into from
Aug 7, 2020

Conversation

axic
Copy link
Member

@axic axic commented Jul 31, 2020

This should have been done in #423.

Depends on #446.

@@ -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>();
Copy link
Member Author

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?

Copy link
Collaborator

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 :)

/* br_table = 0x0e */ {{ValType::i32}, {}},

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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>();
Copy link
Member Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecov
Copy link

codecov bot commented Jul 31, 2020

Codecov Report

Merging #448 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           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 Show resolved Hide resolved
@axic axic requested review from chfast and gumb0 and removed request for chfast July 31, 2020 18:31
@@ -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()
Copy link
Collaborator

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 Show resolved Hide resolved
@@ -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>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const auto br_table_idx = stack.pop().as<uint64_t>();
const auto br_table_idx = stack.pop().i64;

Here and in other places.

lib/fizzy/execute.cpp Outdated Show resolved Hide resolved
@axic axic changed the base branch from master to float-globals August 6, 2020 23:24
@axic axic force-pushed the value-cast branch 3 times, most recently from f78903a to 3914eb0 Compare August 6, 2020 23:46
@gumb0 gumb0 force-pushed the float-globals branch 2 times, most recently from f1a036d to 12ac9ef Compare August 7, 2020 09:56
Base automatically changed from float-globals to master August 7, 2020 10:12
@axic
Copy link
Member Author

axic commented Aug 7, 2020

@chfast how about this now?

@axic axic requested review from gumb0 and chfast August 7, 2020 10:51
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});
Copy link
Member Author

@axic axic Aug 7, 2020

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.

Copy link
Collaborator

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>()}.

Copy link
Member Author

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.

Copy link
Collaborator

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});
Copy link
Collaborator

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>();
Copy link
Collaborator

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.

Copy link
Member Author

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.

@axic axic requested a review from chfast August 7, 2020 11:51
@axic
Copy link
Member Author

axic commented Aug 7, 2020

Squashed the commits. The first commit can be merged as part of this PR or separately under #461.

@chfast @gumb0 please give a final review

@axic axic merged commit c04cfeb into master Aug 7, 2020
@axic axic deleted the value-cast branch August 7, 2020 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants