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

Shave a few instructions off of leave #193

Merged
merged 3 commits into from
Sep 1, 2021
Merged

Shave a few instructions off of leave #193

merged 3 commits into from
Sep 1, 2021

Conversation

XrXr
Copy link
Contributor

@XrXr XrXr commented Aug 30, 2021

The code path for leave that returns to the interpreter
(gen_leave() -> yjit_gen_leave_exit()) used to have the logic:

    cfp->sp++;
    cfp->sp[-1] = return_val;
    cfp->sp--;
    return return_val;

The SP changes it made was unnecessary and this change removes it.

After this change, leave doesn't adjust the cfp->sp of the caller
and only writes cfp->sp[0]. To accomodate this in the JIT-to-JIT
return case, return stubs have an sp_offset of 1.

The change removes sp adjustment from the JIT-to-JIT return case, too,
making it more efficient. Also, since the C method case of send
has an sp_offset of 1 after the call, this change enables block
version sharing.

The code path for leave that returns to the interpreter
(gen_leave() -> yjit_gen_leave_exit()) used to have the logic:

```
    cfp->sp++;
    cfp->sp[-1] = return_val;
    cfp->sp--;
    return return_val;
```

The SP changes it made was unnecessary and this change removes it.

After this change, `leave` doesn't adjust the `cfp->sp` of the caller
and only writes `cfp->sp[0]`. To accomodate this in the JIT-to-JIT
return case, return stubs have an `sp_offset` of 1.

The change removes sp adjustment from the JIT-to-JIT return case, too,
making it more efficient. Also, since the C method case of `send`
has an `sp_offset` of 1 after the call, this change enables block
version sharing.
Copy link
Contributor

@maximecb maximecb left a comment

Choose a reason for hiding this comment

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

Nicely done 👍 and good job writing clear comments 👌

yjit_codegen.c Show resolved Hide resolved
@maximecb maximecb merged commit a83668b into main Sep 1, 2021
@maximecb maximecb deleted the shave-leave branch September 1, 2021 19:38
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