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

Use frame pointer opcodes for functions - part 1 #25

Open
fergalwalsh opened this issue Nov 28, 2022 · 1 comment
Open

Use frame pointer opcodes for functions - part 1 #25

fergalwalsh opened this issue Nov 28, 2022 · 1 comment
Labels
enhancement Planned new feature or improvement

Comments

@fergalwalsh
Copy link
Collaborator

AVM 8+ has support for frame pointers which allow for more efficient stack & slot usage for subroutines (functions in Tealish).

Tealish can generate Teal that uses proto at the start of function definitions instead of stores. frame_dig can be used to access the function args from the stack without having to store them in slots.

Teal example for reference:

pushbytes "ab"
pushbytes "cd"
// log(myfunc("ab", "cd"))
callsub myfunc
log
pushint 1
return


// myfunc(x: bytes, y: bytes) bytes:
myfunc:
// specify that our function takes 2 arguments and has one return value
proto 2 1 // internally puts the first 2 values from the stack into the frame
frame_dig -2 // first arg
frame_dig -1 // second arg
concat
retsub
@fergalwalsh fergalwalsh added the enhancement Planned new feature or improvement label Nov 28, 2022
@fergalwalsh fergalwalsh changed the title Use frame pointer opcodes for functions Use frame pointer opcodes for functions - part 1 Dec 5, 2022
@fergalwalsh
Copy link
Collaborator Author

I now understand that we can use frame pointers with frame_dig & frame_bury for function locals too instead of scratch slots. This is will allow for safe recursive functions and negate the need to analyse the call graph to find a safe slot allocation.
It is a more invasive change however so I suggest to tackle it as a separate issue after this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Planned new feature or improvement
Projects
None yet
Development

No branches or pull requests

1 participant