Skip to content

Merge locals and label values in Frame#605

Merged
ia0 merged 20 commits into
google:dev/fast-interpfrom
zhouwfang:dev/fast-interp
Sep 11, 2024
Merged

Merge locals and label values in Frame#605
ia0 merged 20 commits into
google:dev/fast-interpfrom
zhouwfang:dev/fast-interp

Conversation

@zhouwfang

Copy link
Copy Markdown
Contributor

Continuation of #598 towards adding a value stack in Thread.

#46

zhouwfang and others added 19 commits August 4, 2024 15:37
test result: FAILED. 71 passed; 17 failed; 2 ignored; 0 measured; 0 filtered out; finished in 3.91s

failures:
    block
    br
    br_if
    br_table
    call
    call_indirect
    fac
    global
    if_
    labels
    left_to_right
    local_tee
    loop_
    select
    switch
    unreachable
    unwind
failures:
    br
    br_if
    br_table
    if_
    labels
    loop_
    switch
    unreachable
    unwind

test result: FAILED. 79 passed; 9 failed; 2 ignored; 0 measured; 0 filtered out; finished in 5.16s
@zhouwfang
zhouwfang requested a review from ia0 as a code owner September 7, 2024 23:12
}
unsafe { self.parser.restore(frame.ret) };
self.values().extend(frame.labels_values);
self.values().extend(frame.values);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ia0 You mentioned earlier that this line could be optimized. Here self.values() refers to the values of the frame before the popped frame, and it does not know about frame.values. Could you explain more? Thanks.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will get optimized once we use a single value stack for the whole thread (not just per function frame). But this will only be true if we go with the "keep locals outside the stack" option (discussed above). Otherwise we'll have to drain.

@ia0 ia0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, although it's not clear yet whether we want to keep this in the end.

debug_assert_eq!(frame.labels_values.len(), label.values_cnt);
debug_assert_eq!(frame.labels_values.len(), frame.arity);
let mut frame = self.frames.pop().unwrap();
frame.values.drain(0 .. frame.locals_cnt);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure what's the best here. We might want to try both options (and look what others are doing). It looks like we can either:

  • keep the locals out of the stack (thus saving this drain)
  • keep the locals inside the stack (thus saving popping them when calling a function)

The main difference is that draining is proportional in the number of remaining elements, while popping is proportional to what is popped. But I expect both of those numbers to be rather small, so maybe it doesn't matter. Just something to keep in mind once we have something working and start doing benchmarks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the explanation. I'll add a TODO for this tradeoff in the next PR.

}
unsafe { self.parser.restore(frame.ret) };
self.values().extend(frame.labels_values);
self.values().extend(frame.values);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will get optimized once we use a single value stack for the whole thread (not just per function frame). But this will only be true if we go with the "keep locals outside the stack" option (discussed above). Otherwise we'll have to drain.

@ia0
ia0 merged commit bea2ebf into google:dev/fast-interp Sep 11, 2024
@ia0 ia0 linked an issue Sep 19, 2024 that may be closed by this pull request
ia0 added a commit that referenced this pull request Sep 19, 2024
Reverted #605 and keep values separate from locals for now.

#46

---------

Co-authored-by: Zhou Fang <[email protected]>
Co-authored-by: Julien Cretin <[email protected]>
Co-authored-by: Julien Cretin <[email protected]>
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.

Interpreter performance and footprint

2 participants