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

Resolve br/br_if/br_table in parser #312

Merged
merged 10 commits into from
May 29, 2020
Merged

Resolve br/br_if/br_table in parser #312

merged 10 commits into from
May 29, 2020

Conversation

gumb0
Copy link
Collaborator

@gumb0 gumb0 commented May 12, 2020

Replaces #297

I tried to make the change history to gradually introduce resolving in parser, at first keeping control stack in execute and old instruction immediates, then deleting it in the very end. So this can be reviewed by commit.

For br_table it currently puts arity into immedaites for each label. This should be further optimized to have one arity immediate for entire br_table instruction.

@gumb0 gumb0 force-pushed the control-stack-parser branch 3 times, most recently from c2a229c to 6530093 Compare May 12, 2020 17:36
@codecov
Copy link

codecov bot commented May 12, 2020

Codecov Report

Merging #312 into master will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #312      +/-   ##
==========================================
+ Coverage   98.78%   98.84%   +0.05%     
==========================================
  Files          38       38              
  Lines       11255    11468     +213     
==========================================
+ Hits        11118    11335     +217     
+ Misses        137      133       -4     

@gumb0 gumb0 force-pushed the control-stack-parser branch 10 times, most recently from 4501516 to c7e8d2c Compare May 15, 2020 14:06
@gumb0 gumb0 force-pushed the control-stack-parser branch 4 times, most recently from b32a20c to 6dc8696 Compare May 20, 2020 12:51
@gumb0 gumb0 force-pushed the control-stack-parser branch 2 times, most recently from 7d78346 to 5cb457c Compare May 20, 2020 18:59
@gumb0 gumb0 mentioned this pull request May 22, 2020
@gumb0 gumb0 force-pushed the control-stack-parser branch 5 times, most recently from ca8ae8d to 8d201ff Compare May 26, 2020 10:39
@gumb0 gumb0 requested review from chfast and axic May 27, 2020 12:00
lib/fizzy/execute.cpp Outdated Show resolved Hide resolved
const auto imm_offset = read<uint32_t>(immediates);
// TODO: these will be const when blocks other than loop use them
size_t stack_height = static_cast<uint32_t>(read<int>(immediates));
auto arity = read<uint8_t>(immediates);
Copy link
Member

Choose a reason for hiding this comment

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

Is the reading happening here for the label.pc == nullptr just to skip ahead? Would it make sense using skip/read in the branches below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but these branches are removed in later commits and then it's used always

Copy link
Collaborator

@chfast chfast left a comment

Choose a reason for hiding this comment

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

Excellent work!

@gumb0
Copy link
Collaborator Author

gumb0 commented May 28, 2020

Rebased.

@axic axic changed the title refactor: resolving br/br_if/br_table in parser Resolve br/br_if/br_table in parser May 28, 2020
if (!labels.empty())
labels.pop();
if (labels.empty())
if (pc == &code.instructions[code.instructions.size()])
Copy link
Member

Choose a reason for hiding this comment

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

Should have a comment this is about aborting after the "final" end.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added comment

push(immediates, static_cast<uint32_t>(frame.parent_stack_height));
// Always pushing 0 as loop's arity, because br executed in loop jumps to the top,
// resetting frame stack to 0, so return type arity is not important for br resolution.
push(immediates, frame.instruction == Instr::loop ? uint8_t{0} : frame.arity);
Copy link
Member

Choose a reason for hiding this comment

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

If arity for loop is ignored, couldn't we just always pass frame.arity to avoid this extra branch? Likely it is an unneeded micro-optimization at this stage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, if loop has a result, it still needs to clear all the stack when executing br, not keeping one element like br out of block or if.

This way it's less branching in execution - branching code doesn't care from what kind of block its jumping, and just takes destination and arity from immediates.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Rephrased the comment slightly.

Copy link
Member

Choose a reason for hiding this comment

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

This comment wording to me still suggests that loop always gets arity 0, just like the code does.

@gumb0 gumb0 merged commit db26ba6 into master May 29, 2020
@gumb0 gumb0 deleted the control-stack-parser branch May 29, 2020 10:42
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