From da220a3e47f773f7c862dd0919f6aff9f3d89366 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Tue, 16 Aug 2022 17:54:55 +0300 Subject: [PATCH] selectable_int: support fields comparisons --- src/openpower/decoder/selectable_int.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/openpower/decoder/selectable_int.py b/src/openpower/decoder/selectable_int.py index 675243a2..bb0ac4c3 100644 --- a/src/openpower/decoder/selectable_int.py +++ b/src/openpower/decoder/selectable_int.py @@ -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)) -- 2.30.2