add SelectableInt.abs
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 19 Jun 2020 14:25:04 +0000 (15:25 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 19 Jun 2020 14:25:04 +0000 (15:25 +0100)
https://bugs.libre-soc.org/show_bug.cgi?id=324#c19

src/soc/decoder/selectable_int.py

index 72640909fd3ceff79945eab5e9e38b242d8f52d4..eebada688102162877cd574cd395fa98c65467b7 100644 (file)
@@ -181,6 +181,8 @@ class SelectableInt:
         return self._op(or_, b)
     def __xor__(self, b):
         return self._op(xor, b)
+    def __abs__(self):
+        return SelectableInt(0, self.bits) - self
 
     def __rsub__(self, b):
         if isinstance(b, int):