selectable_int: fix check on SI constructor
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 18 Aug 2022 20:48:58 +0000 (21:48 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 29 Aug 2022 19:38:52 +0000 (20:38 +0100)
Specifying the number of bits *is* allowed, it should mean "override
the length". More unit tests need running to confirm.

src/openpower/decoder/selectable_int.py

index 56ba07c3b78b1a9bf88dee0c37d755171732fcce..22985014e292f046f95decee20f0e7a820600d04 100644 (file)
@@ -221,7 +221,9 @@ class SelectableInt:
     def __init__(self, value, bits=None):
         if isinstance(value, SelectableInt):
             if bits is not None:
-                raise ValueError(value)
+                # check if the bitlength is different. TODO, allow override?
+                if bits != value.bits:
+                    raise ValueError(value)
             bits = value.bits
             value = value.value
         elif isinstance(value, FieldSelectableInt):