hdl.ast: implement abs() on values.

This commit is contained in:
whitequark 2020-03-22 20:50:07 +00:00
parent a0d279850e
commit 2d1e12d00c
2 changed files with 14 additions and 0 deletions

View file

@ -220,6 +220,13 @@ class Value(metaclass=ABCMeta):
def __ge__(self, other):
return Operator(">=", [self, other])
def __abs__(self):
width, signed = self.shape()
if signed:
return Mux(self >= 0, self, -self)
else:
return self
def __len__(self):
return self.shape().width