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

Improve gas cost for shift function #768

Closed
yzhang90 opened this issue Apr 9, 2018 · 0 comments
Closed

Improve gas cost for shift function #768

yzhang90 opened this issue Apr 9, 2018 · 0 comments
Labels
bug Bug that shouldn't change language semantics when fixed.

Comments

@yzhang90
Copy link

yzhang90 commented Apr 9, 2018

What's your issue about?

shift is compiled to the following code:

   ['if', ['sle', '_s', 0], 
          ['div', '_v', ['exp', 2, ['sub', 0, '_s']]], 
          ['mul', '_v', ['exp', 2, '_s']]]]],

When _s == 0, ['div', '_v', ['exp', 2, ['sub', 0, '_s']]] and ['mul', '_v', ['exp', 2, '_s']]]] are the same. But in the div branch, it need to execute sub which potentially costs more gas. Suggest using slt instead of sle. This will also ease the verification.

How can it be fixed?

change sle to slt

Cute Animal Picture

image

@jacqueswww jacqueswww changed the title Improve gas cost for shift funciton Improve gas cost for shift function Apr 10, 2018
@jacqueswww jacqueswww added the bug Bug that shouldn't change language semantics when fixed. label Apr 10, 2018
jacqueswww added a commit to jacqueswww/vyper that referenced this issue Apr 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that shouldn't change language semantics when fixed.
Projects
None yet
Development

No branches or pull requests

2 participants