From: Dmitry Selyutin Date: Sun, 6 Nov 2022 09:29:55 +0000 (+0300) Subject: power_insn: convert spans into properties X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cec6be38f30e7a6f612ed1ae68982a0af6de2c6d;p=openpower-isa.git power_insn: convert spans into properties --- diff --git a/src/openpower/decoder/power_insn.py b/src/openpower/decoder/power_insn.py index f0ac3714..9217ceb9 100644 --- a/src/openpower/decoder/power_insn.py +++ b/src/openpower/decoder/power_insn.py @@ -688,7 +688,7 @@ class Record: for (cls, kwargs) in self.mdwn.operands.static: operand = cls(record=self, **kwargs) - for (src, dst) in enumerate(reversed(operand.span(record=self))): + for (src, dst) in enumerate(reversed(operand.span)): value[dst] = int((operand.value & (1 << src)) != 0) mask[dst] = 1 @@ -773,11 +773,12 @@ class Operand: record: Record name: str - def span(self, record): - return record.fields[self.name] + @cached_property + def span(self): + return self.record.fields[self.name] def assemble(self, value, insn, record): - span = self.span(record=record) + span = self.span if isinstance(insn, SVP64Instruction): span = tuple(map(lambda bit: (bit + 32), span)) if isinstance(value, str): @@ -795,7 +796,7 @@ class Operand: class DynamicOperand(Operand): def disassemble(self, insn, record, verbosity=Verbosity.NORMAL, indent=""): - span = self.span(record=record) + span = self.span if isinstance(insn, SVP64Instruction): span = tuple(map(lambda bit: (bit + 32), span)) value = insn[span] @@ -818,7 +819,7 @@ class SignedOperand(DynamicOperand): def disassemble(self, insn, record, verbosity=Verbosity.NORMAL, indent=""): - span = self.span(record=record) + span = self.span if isinstance(insn, SVP64Instruction): span = tuple(map(lambda bit: (bit + 32), span)) value = insn[span] @@ -842,7 +843,7 @@ class StaticOperand(Operand): def disassemble(self, insn, record, verbosity=Verbosity.NORMAL, indent=""): - span = self.span(record=record) + span = self.span if isinstance(insn, SVP64Instruction): span = tuple(map(lambda bit: (bit + 32), span)) value = insn[span] @@ -878,7 +879,7 @@ class NonZeroOperand(DynamicOperand): def disassemble(self, insn, record, verbosity=Verbosity.NORMAL, indent=""): - span = self.span(record=record) + span = self.span if isinstance(insn, SVP64Instruction): span = tuple(map(lambda bit: (bit + 32), span)) value = insn[span] @@ -902,7 +903,7 @@ class ExtendableOperand(DynamicOperand): def spec(self, insn, record): vector = False - span = self.span(record=record) + span = self.span if isinstance(insn, SVP64Instruction): span = tuple(map(lambda bit: (bit + 32), span)) value = insn[span] @@ -1058,11 +1059,12 @@ class EXTSOperand(DynamicOperand): if not self.field: object.__setattr__(self, "field", self.name) - def span(self, record): - return record.fields[self.field] + @cached_property + def span(self): + return self.record.fields[self.field] def disassemble(self, insn, record, verbosity=Verbosity.NORMAL, indent=""): - span = self.span(record=record) + span = self.span if isinstance(insn, SVP64Instruction): span = tuple(map(lambda bit: (bit + 32), span)) value = insn[span] @@ -1111,14 +1113,16 @@ class EXTSOperandDQ(EXTSOperand, ImmediateOperand): @_dataclasses.dataclass(eq=True, frozen=True) class DOperandDX(SignedOperand): - def span(self, record): - operands = map(DynamicOperand, ("d0", "d1", "d2")) - spans = map(lambda operand: operand.span(record=record), operands) + @cached_property + def span(self): + cls = lambda name: DynamicOperand(name=name) + operands = map(cls, ("d0", "d1", "d2")) + spans = map(lambda operand: operand.span, operands) return sum(spans, tuple()) def disassemble(self, insn, record, verbosity=Verbosity.NORMAL, indent=""): - span = self.span(record=record) + span = self.span if isinstance(insn, SVP64Instruction): span = tuple(map(lambda bit: (bit + 32), span)) value = insn[span] @@ -1132,7 +1136,7 @@ class DOperandDX(SignedOperand): } for (subname, subspan) in mapping.items(): operand = DynamicOperand(name=subname) - span = operand.span(record=record) + span = operand.span if isinstance(insn, SVP64Instruction): span = tuple(map(lambda bit: (bit + 32), span)) value = insn[span] diff --git a/src/openpower/sv/sv_binutils_fptrans.py b/src/openpower/sv/sv_binutils_fptrans.py index b249e52c..9e89c5a7 100644 --- a/src/openpower/sv/sv_binutils_fptrans.py +++ b/src/openpower/sv/sv_binutils_fptrans.py @@ -82,13 +82,15 @@ def collect(db): @_dataclasses.dataclass(eq=True, frozen=True) class POStaticOperand(_StaticOperand): - def span(self, record): + @property + def span(self): return tuple(range(0, 6)) @_dataclasses.dataclass(eq=True, frozen=True) class XOStaticOperand(_StaticOperand): - def span(self, record): - return tuple(record.section.bitsel) + @property + def span(self): + return tuple(self.record.section.bitsel) static_operands = [(POStaticOperand, { "name": "PO", @@ -107,13 +109,13 @@ def collect(db): (cls, kwargs) = operand operand = cls(record=record, **kwargs) return StaticOperand(name=operand.name, - value=operand.value, span=operand.span(record=record)) + value=operand.value, span=operand.span) def dynamic_operand(operand): (cls, kwargs) = operand operand = cls(record=record, **kwargs) return DynamicOperand(name=operand.name, - span=operand.span(record=record)) + span=operand.span) static_operands = tuple(map(static_operand, static_operands)) dynamic_operands = tuple(map(dynamic_operand, dynamic_operands))