Skip to content

Commit

Permalink
refactor extract32 using bitshifts
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberthirst committed Mar 21, 2024
1 parent bb228e5 commit 87ca36a
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions vyper/builtins/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,23 +901,21 @@ def build_IR(self, expr, args, kwargs, context):
with mi32.cache_when_complex("_mi32") as (
b3, mi32
), di32.cache_when_complex("_di32") as (b4, di32):
left_bytes = [
"mul",
[load_op, add_ofst(sub, ["add", scale, ["mul", scale, di32]])],
["exp", 256, mi32]
]
right_bytes = [
"div",
[load_op, add_ofst(sub, ["add", scale, ["mul", scale, ["add", di32, 1]]])],
["exp", 256, ["sub", 32, mi32]],
]

left_payload = [load_op, add_ofst(sub, ["add", scale, ["mul", scale, di32]])]
left_bytes = shl(["mul", 8, mi32], left_payload)

right_payload = [load_op, add_ofst(sub, ["add", scale, ["mul", scale, ["add", di32, 1]]])]
right_bytes = shr(["mul", 8, ["sub", 32, mi32]], right_payload)

ret = [
"if",
mi32,
["add", left_bytes, right_bytes],
[load_op, add_ofst(sub, ["add", scale, ["mul", scale, di32]])],
]
o = IRnode.from_list(b1.resolve(b2.resolve(b3.resolve(b4.resolve(ret)))), typ=ret_type, annotation="extracting 32 bytes")

return IRnode.from_list(clamp_basetype(o), typ=ret_type)


Expand Down

0 comments on commit 87ca36a

Please sign in to comment.