Skip to content

Commit

Permalink
inline wrap256
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Sep 12, 2023
1 parent c02df65 commit 86d7017
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions boa/vyper/ir_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ def executor(cls):
def _wrap256(x):
return x % 2**256

def wrap256(x_str):
return f"(({x_str}) % 2**256)"


def _as_signed(x):
return unsigned_to_signed(x, 256, strict=True)
Expand All @@ -421,12 +424,12 @@ def funcname(self):
return self._op.__module__ + "." + self._op.__name__

def _compile(self, x, y):
return f"_wrap256({self.funcname}({x}, {y}))"
return wrap256(f"{self.funcname}({x}, {y})")


class SignedBinopExecutor(UnsignedBinopExecutor):
def _compile(self, x, y):
return f"_wrap256({self.funcname}(_as_signed({x}), _as_signed({y})))"
return wrap256(f"{self.funcname}(_as_signed({x}), _as_signed({y}))")


# for binops, just use routines from vyper optimizer
Expand Down Expand Up @@ -455,7 +458,7 @@ class Sar(IRExecutor):

def _compile(self, bits, val):
# wrap256 to get back into unsigned land
return f"_wrap256(_as_signed({val}) >> {bits})"
return wrap256(f"_as_signed({val}) >> {bits}")


@executor
Expand All @@ -465,7 +468,7 @@ class Shl(IRExecutor):
_type: type = int

def _compile(self, bits, val):
return f"_wrap256({val} << {bits})"
return wrap256(f"{val} << {bits}")


@executor
Expand Down

0 comments on commit 86d7017

Please sign in to comment.