selectable_int: allow setting multiple bit
authorDmitry Selyutin <ghostmansd@gmail.com>
Wed, 14 Sep 2022 22:50:10 +0000 (01:50 +0300)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 15 Sep 2022 20:54:31 +0000 (21:54 +0100)
src/openpower/decoder/selectable_int.py

index 7380295854f712c1792aa81b23573258435f6fc1..02c8839ac779a430949ea5e6ad7eefe718416bd9 100644 (file)
@@ -386,7 +386,6 @@ class SelectableInt:
             return SelectableInt(value, bits)
         else:
             bits = []
-            key = tuple(key)
             for bit in key:
                 if not isinstance(bit, (int, SelectableInt)):
                     raise ValueError(key)
@@ -434,7 +433,21 @@ class SelectableInt:
             value = value << start
             self.value = (self.value & ~mask) | (value & mask)
         else:
-            raise ValueError(key)
+            bits = []
+            for bit in key:
+                if not isinstance(bit, (int, SelectableInt)):
+                    raise ValueError(key)
+                bits.append(bit)
+
+            if isinstance(value, int):
+                if value.bit_count() > len(bits):
+                    raise ValueError(value)
+                value = SelectableInt(value=value, bits=len(bits))
+            if not isinstance(value, SelectableInt):
+                raise ValueError(value)
+
+            for (src, dst) in enumerate(bits):
+                self[dst] = value[src]
 
     def __ge__(self, other):
         if isinstance(other, FieldSelectableInt):