From: Dmitry Selyutin Date: Tue, 16 Aug 2022 14:54:55 +0000 (+0300) Subject: selectable_int: support fields comparisons X-Git-Tag: sv_maxu_works-initial~66 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=da220a3e47f773f7c862dd0919f6aff9f3d89366;p=openpower-isa.git selectable_int: support fields comparisons --- 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))