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

local variable optimizations #7

Open
zack-bitcoin opened this issue Jul 20, 2019 · 1 comment
Open

local variable optimizations #7

zack-bitcoin opened this issue Jul 20, 2019 · 1 comment

Comments

@zack-bitcoin
Copy link
Owner

Another thing we could consider doing is optimizing accessing of variables who's pointers are offset from a value in the r-stack.

In a function, I use some contiguous available memory to store the local variables, and the root location is stored on the top of the r-stack.
So accessing the 3rd input of a function looks like 'r@ 2 + @'
I grab the pointer from the r-stack, add 2 to it so we are now pointing to the 3rd input, and then fetch it.

loading a value into the 3rd input of a function looks like 'r@ 2 + !'

So I am thinking we can add opcodes for access and setting the first 8 values

r@0 -> 'r@ @'
r!0 -> 'r@ !'
r@1 -> 'r@ 1 + @'
r!2 -> 'r@ 2 + !'

Currently we are using 8 opcodes to access or update a local variable. 5 opcodes to encode the integer, and 3 more opcodes to tell what we are doing.
By teaching the chalang VM these 16 new commands, we could get it down to 1 opcode for the first 8 local variables.
8 inputs is more than how many you need in the majority of function definitions.

@zack-bitcoin
Copy link
Owner Author

Maybe it is better to make r@ 2 + be the word, without the @ or ! at the end.

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

No branches or pull requests

1 participant