-
Notifications
You must be signed in to change notification settings - Fork 718
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
Add scattered push/pop operations #499
Conversation
Is the cost of this instruction going to depend on how many registers were pushed? LGTM. |
LGTM as well |
No. It's cheap enough to execute anyway, the cost between 1 and 24 pushed registers is likely smaller than per-instruction overhead. |
One thing I'm wondering about is how safe it is to assume that the stack will be properly cleared after an internal function call before popping the registers back. Otherwise there's a risk that we'd be popping arbitrary data into the registers if the stack wasn't restored to its original state while pushing the registers. While this is a sway implementation concern, let's say I write a sway function that has an asm block which manually mucks with the stack by performing a |
Isn't this a concern today as well? where we push the registers to the stack before a call and pop them afterwards, but just with separate instructions instead of this one single one. I'd say it's hard for the compiler to do anything safely if ASM blocks are used unsafely. |
One workaround I can think of is if the compiler also pushed $sp to the stack before a function call, and after returning it shrinks the stack back to that value automatically (if $sp != $original_sp) before any popping. |
Initial PR to gather some feedback on push/pop instructions. Closes #407.
There's a possible further improvement at the cost of simplicity: we could special-case pushing zero values (immediate bitmask all zeroes) to do something useful instead. For instance, it could be used to push/pop all user registers using a single operation. However I feel like that wouldn't be too useful.