Skip to content

Commit

Permalink
improve heuristic for bytearray batch copy
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Jul 15, 2023
1 parent 3cb1205 commit 1232cba
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions vyper/codegen/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,17 @@ def make_byte_array_copier(dst, src):
return STORE(dst, 0)

with src.cache_when_complex("src") as (b1, src):
if _opt_gas() and not version_check(begin="cancun") and src.typ.maxlen <= 32:
# it's cheaper to run two load/stores instead of batch copy
has_storage = STORAGE in (src.location, dst.location)
batch_uses_identity = dst.location == src.location == MEMORY and not version_check(begin="cancun")
if src.typ.maxlen <= 32 and (has_storage or batch_uses_identity):
# it's cheaper to run two load/stores instead of copy_bytes
len_ = get_bytearray_length(src)
dst_data = get_bytearray_ptr(dst)
src_data = get_bytearray_ptr(src)
dst_data = bytes_data_ptr(dst)
src_data = bytes_data_ptr(src)
ret = ["seq"]
ret.append(STORE(dst, len_))
ret.append(STORE(dst_data, src_data))
return b1.resolve(b2.resolve(ret))
return b1.resolve(ret)

len_ = add_ofst(get_bytearray_length(src), 32)
max_bytes = src.typ.maxlen + 32
Expand Down

0 comments on commit 1232cba

Please sign in to comment.