Skip to content

Refactor int128 clamps#2179

Merged
fubuloubu merged 3 commits into
vyperlang:masterfrom
iamdefinitelyahuman:refactor-int128-clamps
Oct 9, 2020
Merged

Refactor int128 clamps#2179
fubuloubu merged 3 commits into
vyperlang:masterfrom
iamdefinitelyahuman:refactor-int128-clamps

Conversation

@iamdefinitelyahuman

Copy link
Copy Markdown
Contributor

What I did

Refactor the process of clamping int128 using bitshifting.

How I did it

The new check can be expressed as:

assert abs(n) >> 127 == 0

This check produces smaller bytecode and uses less gas at runtime.

The logic is handled in a new int128_clamp function within vyper.parser.arg_clamps. All the locations where clamping previously happened are now calling to this function.

How to verify it

Run the tests.

I still need to verify how well tested this behavior is.

Cute Animal Picture

image

@codecov-commenter

codecov-commenter commented Oct 4, 2020

Copy link
Copy Markdown

Codecov Report

Merging #2179 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2179      +/-   ##
==========================================
+ Coverage   85.32%   85.34%   +0.01%     
==========================================
  Files          83       83              
  Lines        8403     8411       +8     
  Branches     2032     2033       +1     
==========================================
+ Hits         7170     7178       +8     
  Misses        731      731              
  Partials      502      502              
Impacted Files Coverage Δ
vyper/functions/convert.py 75.00% <100.00%> (+0.16%) ⬆️
vyper/functions/functions.py 89.73% <100.00%> (+0.01%) ⬆️
vyper/parser/arg_clamps.py 100.00% <100.00%> (ø)
vyper/parser/expr.py 77.09% <100.00%> (+0.04%) ⬆️
vyper/parser/parser_utils.py 80.70% <100.00%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a0c561c...d16cb8e. Read the comment docs.

@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #2179 into master will decrease coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2179      +/-   ##
==========================================
- Coverage   85.32%   85.24%   -0.09%     
==========================================
  Files          83       79       -4     
  Lines        8403     8227     -176     
  Branches     2032     2006      -26     
==========================================
- Hits         7170     7013     -157     
+ Misses        731      714      -17     
+ Partials      502      500       -2     
Impacted Files Coverage Δ
vyper/functions/convert.py 75.00% <100.00%> (+0.16%) ⬆️
vyper/functions/functions.py 89.73% <100.00%> (+0.01%) ⬆️
vyper/parser/arg_clamps.py 100.00% <100.00%> (ø)
vyper/parser/expr.py 77.09% <100.00%> (+0.04%) ⬆️
vyper/parser/parser_utils.py 80.54% <100.00%> (-0.11%) ⬇️
vyper/exceptions.py
vyper/opcodes.py
vyper/__main__.py
vyper/typing.py

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a0c561c...51c1cef. Read the comment docs.

@fubuloubu

Copy link
Copy Markdown
Contributor

lgtm

@fubuloubu fubuloubu merged commit 293f83d into vyperlang:master Oct 9, 2020
@iamdefinitelyahuman iamdefinitelyahuman deleted the refactor-int128-clamps branch October 9, 2020 17:34
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

Successfully merging this pull request may close these issues.

4 participants