Skip to content

Shave a few instructions off of leave#193

Merged
maximecb merged 3 commits intomainfrom
shave-leave
Sep 1, 2021
Merged

Shave a few instructions off of leave#193
maximecb merged 3 commits intomainfrom
shave-leave

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.

XrXr added 2 commits August 30, 2021 15:30
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 👌

@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