From: Michael Nolan Date: Thu, 7 May 2020 15:17:48 +0000 (-0400) Subject: Fix bug with comparisons in selectable_int.py X-Git-Tag: div_pipeline~1360 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e15ade5daa8c82f659dd8193164def94d2cf129f;p=soc.git Fix bug with comparisons in selectable_int.py --- diff --git a/src/soc/decoder/selectable_int.py b/src/soc/decoder/selectable_int.py index 1227335e..b6414f90 100644 --- a/src/soc/decoder/selectable_int.py +++ b/src/soc/decoder/selectable_int.py @@ -235,7 +235,7 @@ class SelectableInt: assert other.bits == self.bits other = other.value if isinstance(other, int): - return other >= self.value + return onebit(self.value >= other.value) assert False def __le__(self, other): @@ -246,7 +246,7 @@ class SelectableInt: assert other.bits == self.bits other = other.value if isinstance(other, int): - return onebit(other <= self.value) + return onebit(self.value <= other) assert False def __gt__(self, other): @@ -257,7 +257,7 @@ class SelectableInt: assert other.bits == self.bits other = other.value if isinstance(other, int): - return onebit(other > self.value) + return onebit(self.value > other) assert False def __lt__(self, other): @@ -268,7 +268,7 @@ class SelectableInt: assert other.bits == self.bits other = other.value if isinstance(other, int): - return onebit(other < self.value) + return onebit(self.value < other) assert False def __eq__(self, other): @@ -413,5 +413,21 @@ class SelectableIntTestCase(unittest.TestCase): b = eval(repr(a)) self.assertEqual(a, b) + def test_cmp(self): + a = SelectableInt(10, bits=8) + b = SelectableInt(5, bits=8) + self.assertTrue(a > b) + self.assertFalse(a < b) + self.assertTrue(a != b) + self.assertFalse(a == b) + + def test_unsigned(self): + a = SelectableInt(0x80, bits=8) + b = SelectableInt(0x7f, bits=8) + self.assertTrue(a > b) + self.assertFalse(a < b) + self.assertTrue(a != b) + self.assertFalse(a == b) + if __name__ == "__main__": unittest.main()