From: Dmitry Selyutin Date: Tue, 2 Aug 2022 11:16:26 +0000 (+0300) Subject: power_enums: better repr for Function enum X-Git-Tag: sv_maxu_works-initial~154 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e31ae9cb6ecafca9a512ed15e0dd6b4577facaad;p=openpower-isa.git power_enums: better repr for Function enum --- diff --git a/src/openpower/decoder/power_enums.py b/src/openpower/decoder/power_enums.py index 0cd4aab0..e414178c 100644 --- a/src/openpower/decoder/power_enums.py +++ b/src/openpower/decoder/power_enums.py @@ -22,6 +22,7 @@ import csv import os from os.path import dirname, join from collections import namedtuple +import functools def find_wiki_dir(): @@ -109,6 +110,20 @@ class Function(Enum): VL = 1 << 13 # setvl FPU = 1 << 14 # FPU + @functools.lru_cache(maxsize=None) + def __repr__(self): + counter = 0 + value = int(self.value) + if value != 0: + while value != 0: + counter += 1 + value >>= 1 + counter -= 1 + desc = f"(1 << {counter})" + else: + desc = "0" + return f"<{self.__class__.__name__}.{self.name}: {desc}>" + @unique class Form(Enum):