-
Notifications
You must be signed in to change notification settings - Fork 34
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
Conversation
c2a229c
to
6530093
Compare
Codecov Report
@@ 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 |
4501516
to
c7e8d2c
Compare
b32a20c
to
6dc8696
Compare
6dc8696
to
9fa554f
Compare
7d78346
to
5cb457c
Compare
ca8ae8d
to
8d201ff
Compare
158b7b2
to
85ee738
Compare
lib/fizzy/execute.cpp
Outdated
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); |
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.
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?
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, but these branches are removed in later commits and then it's used always
85ee738
to
e048cd4
Compare
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.
Excellent work!
e048cd4
to
e39fb28
Compare
Rebased. |
if (!labels.empty()) | ||
labels.pop(); | ||
if (labels.empty()) | ||
if (pc == &code.instructions[code.instructions.size()]) |
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.
Should have a comment this is about aborting after the "final" end.
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.
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); |
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.
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.
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.
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.
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.
Rephrased the comment slightly.
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.
This comment wording to me still suggests that loop always gets arity 0, just like the code does.
e39fb28
to
b3eed80
Compare
b3eed80
to
e8ff26f
Compare
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 entirebr_table
instruction.