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

proposal for opcodes for loading integers efficiently #6

Open
zack-bitcoin opened this issue Jul 20, 2019 · 2 comments
Open

proposal for opcodes for loading integers efficiently #6

zack-bitcoin opened this issue Jul 20, 2019 · 2 comments

Comments

@zack-bitcoin
Copy link
Owner

Currently, loading an integer always takes 5 bytes. one byte to warn the interpreter that the next 4 bytes encode an integer, and then those 4 bytes of integer.

Looking at the code being produced by our compiler, we spend a lot of time referencing

  • functions
  • global variables
  • local variables
    and for each of these things, we need to reference them by using integers.
    We tend to use the integers from 0-16 with high frequency.

So I want to add:
36 opcodes to load an integer from 0-35. so we can encode 0-35 in 1 byte.
1 opcode to indicate that the next byte is an integer. so we can encode 0-255 in 2 bytes.
1 opcode to indicate that the next 2 bytes are an integer. so we can encode 0-65535 in 3 bytes.

Historically speaking, bitcoin has opcodes to load the integers from 0-15 in one byte.

Looking at the smart contracts I have already written, and the bytecode being produced by the current version of the compiler, it seems like this update would reduce the size of the typical contract by about 1/2.

@zack-bitcoin
Copy link
Owner Author

2-byte and 3-byte versions are now live in the experimental branch.

@zack-bitcoin
Copy link
Owner Author

the 1 byte versions are now live in the experimental branch

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