fix SelectableInt abs
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 6 Jul 2020 19:19:06 +0000 (20:19 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 6 Jul 2020 19:19:06 +0000 (20:19 +0100)
src/soc/decoder/selectable_int.py

index 3036b6f6412afd87c8aabc9fe6a58ef1652e57b6..1bd2b94c1e353de8932d81a1a556bab603bee9bf 100644 (file)
@@ -197,7 +197,10 @@ class SelectableInt:
     def __xor__(self, b):
         return self._op(xor, b)
     def __abs__(self):
-        return SelectableInt(0, self.bits) - self
+        print ("abs", self.value & (1<<(self.bits-1)))
+        if self.value & (1<<(self.bits-1)) != 0:
+            return SelectableInt(0, self.bits) - self
+        return self
 
     def __rsub__(self, b):
         if isinstance(b, int):