selectable_int: support fields comparisons
authorDmitry Selyutin <ghostmansd@gmail.com>
Tue, 16 Aug 2022 14:54:55 +0000 (17:54 +0300)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 29 Aug 2022 19:38:10 +0000 (20:38 +0100)
src/openpower/decoder/selectable_int.py

index 675243a2ba727b66b03db753f251f8749cb673c7..bb0ac4c3ce32da34ac0de862cfd4dd61c0bdba24 100644 (file)
@@ -480,6 +480,17 @@ class SelectableIntMappingMeta(type):
 
 
 class SelectableIntMapping(SelectableInt, metaclass=SelectableIntMappingMeta):
+    @functools.total_ordering
+    class Field(FieldSelectableInt):
+        def __int__(self):
+            return self.asint(msb0=True)
+
+        def __lt__(self, other):
+            return (int(self) < other)
+
+        def __eq__(self, other):
+            return (int(self) == other)
+
     def __init__(self, value=0):
         return super().__init__(value, self.__class__.bits)
 
@@ -487,7 +498,7 @@ class SelectableIntMapping(SelectableInt, metaclass=SelectableIntMappingMeta):
         def field(value):
             if isinstance(value, dict):
                 return {key:field(value) for (key, value) in tuple(value.items())}
-            return FieldSelectableInt(si=self, br=value)
+            return self.__class__.Field(si=self, br=value)
 
         try:
             return field(getattr(self.__class__, attr))