From ea985e2380e7bc54af3629af3a47cdfecd771f09 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Mon, 17 Jan 2022 20:55:10 -0800 Subject: [PATCH] format code --- src/openpower/decoder/helpers.py | 104 ++++---- src/openpower/decoder/isa/caller.py | 370 ++++++++++++++-------------- 2 files changed, 240 insertions(+), 234 deletions(-) diff --git a/src/openpower/decoder/helpers.py b/src/openpower/decoder/helpers.py index 8caa1068..e37d4777 100644 --- a/src/openpower/decoder/helpers.py +++ b/src/openpower/decoder/helpers.py @@ -41,7 +41,7 @@ def exts(value, bits): def EXTS(value): """ extends sign bit out from current MSB to all 256 bits """ - log ("EXTS", value, type(value)) + log("EXTS", value, type(value)) assert isinstance(value, SelectableInt) return SelectableInt(exts(value.value, value.bits) & ((1 << 256)-1), 256) @@ -108,6 +108,7 @@ def ROTL32(value, bits): value = SelectableInt(value.value, 64) return rotl(value | (value << 32), bits, 64) + def MASK32(x, y): if isinstance(x, SelectableInt): x = x.value @@ -115,6 +116,7 @@ def MASK32(x, y): y = y.value return MASK(x+32, y+32) + def MASK(x, y): if isinstance(x, SelectableInt): x = x.value @@ -183,37 +185,38 @@ def SINGLE(FRS): m = FRS[12:64] s = FRS[0] - log ("SINGLE", FRS) - log ("s e m", s.value, e.value, m.value) - - #No Denormalization Required (includes Zero / Infinity / NaN) - if e.value > 896 or FRS[1:64].value == 0: - log("nodenorm", FRS[0:2].value, hex(FRS[5:35].value)) - WORD[0:2] = FRS[0:2] - WORD[2:32] = FRS[5:35] - - #Denormalization Required - if e.value >= 874 and e.value <= 896: - sign = FRS[0] - exp = e.value - 1023 - frac = selectconcat(SelectableInt(1, 1), FRS[12:64]) - log("exp, fract", exp, hex(frac.value)) - # denormalize operand - while exp < -126: - frac[0:53] = selectconcat(SelectableInt(0, 1), frac[0:52]) - exp = exp + 1 - WORD[0] = sign - WORD[1:9] = SelectableInt(0, 8) - WORD[9:32] = frac[1:24] - #else WORD = undefined # return zeros - - log ("WORD", WORD) + log("SINGLE", FRS) + log("s e m", s.value, e.value, m.value) + + # No Denormalization Required (includes Zero / Infinity / NaN) + if e.value > 896 or FRS[1:64].value == 0: + log("nodenorm", FRS[0:2].value, hex(FRS[5:35].value)) + WORD[0:2] = FRS[0:2] + WORD[2:32] = FRS[5:35] + + # Denormalization Required + if e.value >= 874 and e.value <= 896: + sign = FRS[0] + exp = e.value - 1023 + frac = selectconcat(SelectableInt(1, 1), FRS[12:64]) + log("exp, fract", exp, hex(frac.value)) + # denormalize operand + while exp < -126: + frac[0:53] = selectconcat(SelectableInt(0, 1), frac[0:52]) + exp = exp + 1 + WORD[0] = sign + WORD[1:9] = SelectableInt(0, 8) + WORD[9:32] = frac[1:24] + # else WORD = undefined # return zeros + + log("WORD", WORD) return WORD # XXX NOTE: these are very quick hacked functions for utterly basic # FP support + def signinv(res, sign): if sign == 1: return res @@ -238,7 +241,7 @@ class ISAFPHelpers: result = math.sin(float(FRB)) cvt = fp64toselectable(result) cvt = self.DOUBLE2SINGLE(cvt) - log ("FPSIN32", FRB, float(FRB), "=", result, cvt) + log("FPSIN32", FRB, float(FRB), "=", result, cvt) return cvt def FPCOS32(self, FRB): @@ -246,106 +249,105 @@ class ISAFPHelpers: result = math.cos(float(FRB)) cvt = fp64toselectable(result) cvt = self.DOUBLE2SINGLE(cvt) - log ("FPCOS32", FRB, float(FRB), "=", result, cvt) + log("FPCOS32", FRB, float(FRB), "=", result, cvt) return cvt def FPADD32(self, FRA, FRB): - #return FPADD64(FRA, FRB) + # return FPADD64(FRA, FRB) #FRA = DOUBLE(SINGLE(FRA)) #FRB = DOUBLE(SINGLE(FRB)) result = float(FRA) + float(FRB) cvt = fp64toselectable(result) cvt = self.DOUBLE2SINGLE(cvt) - log ("FPADD32", FRA, FRB, float(FRA), "+", float(FRB), "=", result, cvt) + log("FPADD32", FRA, FRB, float(FRA), "+", float(FRB), "=", result, cvt) return cvt def FPSUB32(self, FRA, FRB): - #return FPSUB64(FRA, FRB) + # return FPSUB64(FRA, FRB) #FRA = DOUBLE(SINGLE(FRA)) #FRB = DOUBLE(SINGLE(FRB)) result = float(FRA) - float(FRB) cvt = fp64toselectable(result) cvt = self.DOUBLE2SINGLE(cvt) - log ("FPSUB32", FRA, FRB, float(FRA), "-", float(FRB), "=", result, cvt) + log("FPSUB32", FRA, FRB, float(FRA), "-", float(FRB), "=", result, cvt) return cvt def FPMUL32(self, FRA, FRB, sign=1): - #return FPMUL64(FRA, FRB) + # return FPMUL64(FRA, FRB) FRA = self.DOUBLE(SINGLE(FRA)) FRB = self.DOUBLE(SINGLE(FRB)) result = signinv(float(FRA) * float(FRB), sign) - log ("FPMUL32", FRA, FRB, float(FRA), float(FRB), result, sign) + log("FPMUL32", FRA, FRB, float(FRA), float(FRB), result, sign) cvt = fp64toselectable(result) cvt = self.DOUBLE2SINGLE(cvt) - log (" cvt", cvt) + log(" cvt", cvt) return cvt def FPMULADD32(self, FRA, FRC, FRB, mulsign, addsign): - #return FPMUL64(FRA, FRB) + # return FPMUL64(FRA, FRB) #FRA = DOUBLE(SINGLE(FRA)) #FRB = DOUBLE(SINGLE(FRB)) if addsign == 1: if mulsign == 1: - result = float(FRA) * float(FRC) + float(FRB) # fmadds + result = float(FRA) * float(FRC) + float(FRB) # fmadds elif mulsign == -1: result = -(float(FRA) * float(FRC) - float(FRB)) # fnmsubs elif addsign == -1: if mulsign == 1: - result = float(FRA) * float(FRC) - float(FRB) # fmsubs + result = float(FRA) * float(FRC) - float(FRB) # fmsubs elif mulsign == -1: result = -(float(FRA) * float(FRC) + float(FRB)) # fnmadds elif addsign == 0: result = 0.0 - log ("FPMULADD32 FRA FRC FRB", FRA, FRC, FRB) - log (" FRA", float(FRA)) - log (" FRC", float(FRC)) - log (" FRB", float(FRB)) - log (" (FRA*FRC)+FRB=", mulsign, addsign, result) + log("FPMULADD32 FRA FRC FRB", FRA, FRC, FRB) + log(" FRA", float(FRA)) + log(" FRC", float(FRC)) + log(" FRB", float(FRB)) + log(" (FRA*FRC)+FRB=", mulsign, addsign, result) cvt = fp64toselectable(result) cvt = self.DOUBLE2SINGLE(cvt) - log (" cvt", cvt) + log(" cvt", cvt) return cvt def FPDIV32(self, FRA, FRB, sign=1): - #return FPDIV64(FRA, FRB) + # return FPDIV64(FRA, FRB) #FRA = DOUBLE(SINGLE(FRA)) #FRB = DOUBLE(SINGLE(FRB)) result = signinv(float(FRA) / float(FRB), sign) cvt = fp64toselectable(result) cvt = self.DOUBLE2SINGLE(cvt) - log ("FPDIV32", FRA, FRB, result, cvt) + log("FPDIV32", FRA, FRB, result, cvt) return cvt def FPADD64(FRA, FRB): result = float(FRA) + float(FRB) cvt = fp64toselectable(result) - log ("FPADD64", FRA, FRB, result, cvt) + log("FPADD64", FRA, FRB, result, cvt) return cvt def FPSUB64(FRA, FRB): result = float(FRA) - float(FRB) cvt = fp64toselectable(result) - log ("FPSUB64", FRA, FRB, result, cvt) + log("FPSUB64", FRA, FRB, result, cvt) return cvt def FPMUL64(FRA, FRB, sign=1): result = signinv(float(FRA) * float(FRB), sign) cvt = fp64toselectable(result) - log ("FPMUL64", FRA, FRB, result, cvt, sign) + log("FPMUL64", FRA, FRB, result, cvt, sign) return cvt def FPDIV64(FRA, FRB, sign=1): result = signinv(float(FRA) / float(FRB), sign) cvt = fp64toselectable(result) - log ("FPDIV64", FRA, FRB, result, cvt, sign) + log("FPDIV64", FRA, FRB, result, cvt, sign) return cvt - def bitrev(val, VL): """Returns the integer whose value is the reverse of the lowest 'width' bits of the integer 'val' diff --git a/src/openpower/decoder/isa/caller.py b/src/openpower/decoder/isa/caller.py index 4ee485f6..a4b39ef1 100644 --- a/src/openpower/decoder/isa/caller.py +++ b/src/openpower/decoder/isa/caller.py @@ -18,13 +18,13 @@ from functools import wraps from copy import copy, deepcopy from openpower.decoder.orderedset import OrderedSet from openpower.decoder.selectable_int import (FieldSelectableInt, SelectableInt, - selectconcat) + selectconcat) from openpower.decoder.power_enums import (spr_dict, spr_byname, XER_bits, - insns, MicrOp, In1Sel, In2Sel, In3Sel, - OutSel, CRInSel, CROutSel, LDSTMode, - SVP64RMMode, SVP64PredMode, - SVP64PredInt, SVP64PredCR, - SVP64LDSTmode) + insns, MicrOp, In1Sel, In2Sel, In3Sel, + OutSel, CRInSel, CROutSel, LDSTMode, + SVP64RMMode, SVP64PredMode, + SVP64PredInt, SVP64PredCR, + SVP64LDSTmode) from openpower.decoder.power_enums import SVPtype @@ -33,7 +33,7 @@ from openpower.decoder.helpers import (exts, gtu, ltu, undefined, from openpower.consts import PIb, MSRb # big-endian (PowerISA versions) from openpower.consts import (SVP64MODE, SVP64CROffs, - ) + ) from openpower.decoder.power_svp64 import SVP64RM, decode_extra from openpower.decoder.isa.radixmmu import RADIX @@ -88,7 +88,7 @@ REG_SORT_ORDER = { "CA": 0, "CA32": 0, - "overflow": 7, # should definitely be last + "overflow": 7, # should definitely be last } fregs = ['FRA', 'FRB', 'FRC', 'FRS', 'FRT'] @@ -102,7 +102,6 @@ def create_args(reglist, extra=None): return retval - class GPR(dict): def __init__(self, decoder, isacaller, svstate, regfile): dict.__init__(self) @@ -221,7 +220,7 @@ class SPR(dict): def dump(self, printout=True): res = [] keys = list(self.keys()) - #keys.sort() + # keys.sort() for k in keys: sprname = spr_dict.get(k, None) if sprname is None: @@ -238,7 +237,7 @@ class SPR(dict): class PC: def __init__(self, pc_init=0): self.CIA = SelectableInt(pc_init, 64) - self.NIA = self.CIA + SelectableInt(4, 64) # only true for v3.0B! + self.NIA = self.CIA + SelectableInt(4, 64) # only true for v3.0B! def update_nia(self, is_svp64): increment = 8 if is_svp64 else 4 @@ -259,24 +258,24 @@ class SVP64RMFields: self.spr = SelectableInt(init, 24) # SVP64 RM fields: see https://libre-soc.org/openpower/sv/svp64/ self.mmode = FieldSelectableInt(self.spr, [0]) - self.mask = FieldSelectableInt(self.spr, tuple(range(1,4))) - self.elwidth = FieldSelectableInt(self.spr, tuple(range(4,6))) - self.ewsrc = FieldSelectableInt(self.spr, tuple(range(6,8))) - self.subvl = FieldSelectableInt(self.spr, tuple(range(8,10))) - self.extra = FieldSelectableInt(self.spr, tuple(range(10,19))) - self.mode = FieldSelectableInt(self.spr, tuple(range(19,24))) + self.mask = FieldSelectableInt(self.spr, tuple(range(1, 4))) + self.elwidth = FieldSelectableInt(self.spr, tuple(range(4, 6))) + self.ewsrc = FieldSelectableInt(self.spr, tuple(range(6, 8))) + self.subvl = FieldSelectableInt(self.spr, tuple(range(8, 10))) + self.extra = FieldSelectableInt(self.spr, tuple(range(10, 19))) + self.mode = FieldSelectableInt(self.spr, tuple(range(19, 24))) # these cover the same extra field, split into parts as EXTRA2 self.extra2 = list(range(4)) - self.extra2[0] = FieldSelectableInt(self.spr, tuple(range(10,12))) - self.extra2[1] = FieldSelectableInt(self.spr, tuple(range(12,14))) - self.extra2[2] = FieldSelectableInt(self.spr, tuple(range(14,16))) - self.extra2[3] = FieldSelectableInt(self.spr, tuple(range(16,18))) - self.smask = FieldSelectableInt(self.spr, tuple(range(16,19))) + self.extra2[0] = FieldSelectableInt(self.spr, tuple(range(10, 12))) + self.extra2[1] = FieldSelectableInt(self.spr, tuple(range(12, 14))) + self.extra2[2] = FieldSelectableInt(self.spr, tuple(range(14, 16))) + self.extra2[3] = FieldSelectableInt(self.spr, tuple(range(16, 18))) + self.smask = FieldSelectableInt(self.spr, tuple(range(16, 19))) # and here as well, but EXTRA3 self.extra3 = list(range(3)) - self.extra3[0] = FieldSelectableInt(self.spr, tuple(range(10,13))) - self.extra3[1] = FieldSelectableInt(self.spr, tuple(range(13,16))) - self.extra3[2] = FieldSelectableInt(self.spr, tuple(range(16,19))) + self.extra3[0] = FieldSelectableInt(self.spr, tuple(range(10, 13))) + self.extra3[1] = FieldSelectableInt(self.spr, tuple(range(13, 16))) + self.extra3[2] = FieldSelectableInt(self.spr, tuple(range(16, 19))) SVP64RM_MMODE_SIZE = len(SVP64RMFields().mmode.br) @@ -295,9 +294,9 @@ class SVP64PrefixFields: def __init__(self): self.insn = SelectableInt(0, 32) # 6 bit major opcode EXT001, 2 bits "identifying" (7, 9), 24 SV ReMap - self.major = FieldSelectableInt(self.insn, tuple(range(0,6))) - self.pid = FieldSelectableInt(self.insn, (7, 9)) # must be 0b11 - rmfields = [6, 8] + list(range(10,32)) # SVP64 24-bit RM (ReMap) + self.major = FieldSelectableInt(self.insn, tuple(range(0, 6))) + self.pid = FieldSelectableInt(self.insn, (7, 9)) # must be 0b11 + rmfields = [6, 8] + list(range(10, 32)) # SVP64 24-bit RM (ReMap) self.rm = FieldSelectableInt(self.insn, rmfields) @@ -327,10 +326,12 @@ class CRFields: self.crl.append(_cr) # decode SVP64 predicate integer to reg number and invert + + def get_predint(gpr, mask): r10 = gpr(10) r30 = gpr(30) - log ("get_predint", mask, SVP64PredInt.ALWAYS.value) + log("get_predint", mask, SVP64PredInt.ALWAYS.value) if mask == SVP64PredInt.ALWAYS.value: return 0xffff_ffff_ffff_ffff if mask == SVP64PredInt.R3_UNARY.value: @@ -349,6 +350,8 @@ def get_predint(gpr, mask): return ~gpr(30).value # decode SVP64 predicate CR to reg number and invert status + + def _get_predcr(mask): if mask == SVP64PredCR.LT.value: return 0, 1 @@ -369,13 +372,15 @@ def _get_predcr(mask): # read individual CR fields (0..VL-1), extract the required bit # and construct the mask + + def get_predcr(crl, mask, vl): idx, noninv = _get_predcr(mask) mask = 0 for i in range(vl): cr = crl[i+SVP64CROffs.CRPred] if cr[idx].value == noninv: - mask |= (1< 64: output = SelectableInt(output.value, 64) if name in fregs: @@ -1623,24 +1629,24 @@ class ISACaller(ISACallerHelper, ISAFPHelpers): nia_update = True if self.allow_next_step_inc: log("SVSTATE_NEXT: inc requested, mode", - self.svstate_next_mode, self.allow_next_step_inc) + self.svstate_next_mode, self.allow_next_step_inc) yield from self.svstate_pre_inc() pre = yield from self.update_new_svstate_steps() if pre: # reset at end of loop including exit Vertical Mode - log ("SVSTATE_NEXT: end of loop, reset") + log("SVSTATE_NEXT: end of loop, reset") self.svp64_reset_loop() self.svstate.vfirst = 0 self.update_nia() if rc_en: results = [SelectableInt(0, 64)] - self.handle_comparison(results) # CR0 + self.handle_comparison(results) # CR0 else: if self.allow_next_step_inc == 2: - log ("SVSTATE_NEXT: read") + log("SVSTATE_NEXT: read") nia_update = (yield from self.svstate_post_inc(ins_name)) else: - log ("SVSTATE_NEXT: post-inc") + log("SVSTATE_NEXT: post-inc") # use actual src/dst-step here to check end, do NOT # use bit-reversed version srcstep, dststep = self.new_srcstep, self.new_dststep @@ -1661,19 +1667,19 @@ class ISACaller(ISACallerHelper, ISAFPHelpers): dststep = self.svstate.srcstep endtest = 1 if (end_src or end_dst) else 0 #results = [SelectableInt(endtest, 64)] - #self.handle_comparison(results) # CR0 + # self.handle_comparison(results) # CR0 # see if svstep was requested, if so, which SVSTATE endings = 0b111 if self.svstate_next_mode > 0: shape_idx = self.svstate_next_mode.value-1 endings = self.remap_loopends[shape_idx] - cr_field = SelectableInt((~endings)<<1 | endtest, 4) - print ("svstep Rc=1, CR0", cr_field) - self.crl[0].eq(cr_field) # CR0 + cr_field = SelectableInt((~endings) << 1 | endtest, 4) + print("svstep Rc=1, CR0", cr_field) + self.crl[0].eq(cr_field) # CR0 if end_src or end_dst: # reset at end of loop including exit Vertical Mode - log ("SVSTATE_NEXT: after increments, reset") + log("SVSTATE_NEXT: after increments, reset") self.svp64_reset_loop() self.svstate.vfirst = 0 @@ -1717,9 +1723,9 @@ class ISACaller(ISACallerHelper, ISAFPHelpers): sv_a_nz = yield self.dec2.sv_a_nz fft_mode = yield self.dec2.use_svp64_fft in1 = yield self.dec2.e.read_reg1.data - log ("SVP64: VL, srcstep, dststep, sv_a_nz, in1 fft, svp64", - vl, srcstep, dststep, sv_a_nz, in1, fft_mode, - self.is_svp64_mode) + log("SVP64: VL, srcstep, dststep, sv_a_nz, in1 fft, svp64", + vl, srcstep, dststep, sv_a_nz, in1, fft_mode, + self.is_svp64_mode) # get predicate mask srcmask = dstmask = 0xffff_ffff_ffff_ffff @@ -1739,40 +1745,40 @@ class ISACaller(ISACallerHelper, ISAFPHelpers): srcmask = dstmask = get_predcr(self.crl, dstpred, vl) if sv_ptype == SVPtype.P2.value: srcmask = get_predcr(self.crl, srcpred, vl) - log (" pmode", pmode) - log (" reverse", reverse_gear) - log (" ptype", sv_ptype) - log (" srcpred", bin(srcpred)) - log (" dstpred", bin(dstpred)) - log (" srcmask", bin(srcmask)) - log (" dstmask", bin(dstmask)) - log (" pred_sz", bin(pred_src_zero)) - log (" pred_dz", bin(pred_dst_zero)) + log(" pmode", pmode) + log(" reverse", reverse_gear) + log(" ptype", sv_ptype) + log(" srcpred", bin(srcpred)) + log(" dstpred", bin(dstpred)) + log(" srcmask", bin(srcmask)) + log(" dstmask", bin(dstmask)) + log(" pred_sz", bin(pred_src_zero)) + log(" pred_dz", bin(pred_dst_zero)) # okaaay, so here we simply advance srcstep (TODO dststep) # until the predicate mask has a "1" bit... or we run out of VL # let srcstep==VL be the indicator to move to next instruction if not pred_src_zero: - while (((1<