From 53a48a2f9046a13616c446320618c9b21809408d Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Fri, 10 Dec 2021 13:07:47 -0800 Subject: [PATCH] format code --- src/openpower/sv/trans/svp64.py | 585 ++++++++++++++++---------------- 1 file changed, 296 insertions(+), 289 deletions(-) diff --git a/src/openpower/sv/trans/svp64.py b/src/openpower/sv/trans/svp64.py index 45b292b4..34b829b3 100644 --- a/src/openpower/sv/trans/svp64.py +++ b/src/openpower/sv/trans/svp64.py @@ -15,17 +15,18 @@ Encoding format of LDST: https://libre-soc.org/openpower/sv/ldst/ Bugtracker: https://bugs.libre-soc.org/show_bug.cgi?id=578 """ -import os, sys +import os +import sys from collections import OrderedDict from openpower.decoder.isa.caller import (SVP64PrefixFields, SV64P_MAJOR_SIZE, - SV64P_PID_SIZE, SVP64RMFields, - SVP64RM_EXTRA2_SPEC_SIZE, - SVP64RM_EXTRA3_SPEC_SIZE, - SVP64RM_MODE_SIZE, SVP64RM_SMASK_SIZE, - SVP64RM_MMODE_SIZE, SVP64RM_MASK_SIZE, - SVP64RM_SUBVL_SIZE, SVP64RM_EWSRC_SIZE, - SVP64RM_ELWIDTH_SIZE) + SV64P_PID_SIZE, SVP64RMFields, + SVP64RM_EXTRA2_SPEC_SIZE, + SVP64RM_EXTRA3_SPEC_SIZE, + SVP64RM_MODE_SIZE, SVP64RM_SMASK_SIZE, + SVP64RM_MMODE_SIZE, SVP64RM_MASK_SIZE, + SVP64RM_SUBVL_SIZE, SVP64RM_EWSRC_SIZE, + SVP64RM_ELWIDTH_SIZE) from openpower.decoder.pseudo.pagereader import ISA from openpower.decoder.power_svp64 import SVP64RM, get_regtype, decode_extra from openpower.decoder.selectable_int import SelectableInt @@ -36,7 +37,7 @@ from openpower.util import log # decode GPR into sv extra -def get_extra_gpr(etype, regmode, field): +def get_extra_gpr(etype, regmode, field): if regmode == 'scalar': # cut into 2-bits 5-bits SS FFFFF sv_extra = field >> 5 @@ -49,7 +50,7 @@ def get_extra_gpr(etype, regmode, field): # decode 3-bit CR into sv extra -def get_extra_cr_3bit(etype, regmode, field): +def get_extra_cr_3bit(etype, regmode, field): if regmode == 'scalar': # cut into 2-bits 3-bits SS FFF sv_extra = field >> 3 @@ -79,24 +80,24 @@ def decode_elwidth(encoding): # decodes predicate register encoding def decode_predicate(encoding): - pmap = { # integer - '1<> 1) == 0, \ "scalar GPR %s cannot fit into EXTRA2 %s" % \ - (rname, str(extras[extra_idx])) + (rname, str(extras[extra_idx])) # all good: encode as scalar sv_extra = sv_extra & 0b01 else: @@ -438,7 +441,7 @@ class SVP64Asm: assert sv_extra & 0b01 == 0, \ "%s: vector field %s cannot fit " \ "into EXTRA2 %s" % \ - (insn, rname, str(extras[extra_idx])) + (insn, rname, str(extras[extra_idx])) # all good: encode as vector (bit 2 set) sv_extra = 0b10 | (sv_extra >> 1) elif regmode == 'vector': @@ -454,14 +457,14 @@ class SVP64Asm: # range is CR0-CR15 in increments of 1 assert (sv_extra >> 1) == 0, \ "scalar CR %s cannot fit into EXTRA2 %s" % \ - (rname, str(extras[extra_idx])) + (rname, str(extras[extra_idx])) # all good: encode as scalar sv_extra = sv_extra & 0b01 else: # range is CR0-CR127 in increments of 16 assert sv_extra & 0b111 == 0, \ "vector CR %s cannot fit into EXTRA2 %s" % \ - (rname, str(extras[extra_idx])) + (rname, str(extras[extra_idx])) # all good: encode as vector (bit 2 set) sv_extra = 0b10 | (sv_extra >> 3) else: @@ -469,14 +472,14 @@ class SVP64Asm: # range is CR0-CR31 in increments of 1 assert (sv_extra >> 2) == 0, \ "scalar CR %s cannot fit into EXTRA2 %s" % \ - (rname, str(extras[extra_idx])) + (rname, str(extras[extra_idx])) # all good: encode as scalar sv_extra = sv_extra & 0b11 else: # range is CR0-CR127 in increments of 8 assert sv_extra & 0b11 == 0, \ "vector CR %s cannot fit into EXTRA2 %s" % \ - (rname, str(extras[extra_idx])) + (rname, str(extras[extra_idx])) # all good: encode as vector (bit 3 set) sv_extra = 0b100 | (sv_extra >> 2) @@ -485,7 +488,7 @@ class SVP64Asm: # passed through elif rtype == 'CR_5bit': cr_subfield = field & 0b11 - field = field >> 2 # strip bottom 2 bits + field = field >> 2 # strip bottom 2 bits sv_extra, field = get_extra_cr_3bit(etype, regmode, field) # now sanity-check (and shrink afterwards) if etype == 'EXTRA2': @@ -493,14 +496,14 @@ class SVP64Asm: # range is CR0-CR15 in increments of 1 assert (sv_extra >> 1) == 0, \ "scalar CR %s cannot fit into EXTRA2 %s" % \ - (rname, str(extras[extra_idx])) + (rname, str(extras[extra_idx])) # all good: encode as scalar sv_extra = sv_extra & 0b01 else: # range is CR0-CR127 in increments of 16 assert sv_extra & 0b111 == 0, \ "vector CR %s cannot fit into EXTRA2 %s" % \ - (rname, str(extras[extra_idx])) + (rname, str(extras[extra_idx])) # all good: encode as vector (bit 2 set) sv_extra = 0b10 | (sv_extra >> 3) else: @@ -508,48 +511,50 @@ class SVP64Asm: # range is CR0-CR31 in increments of 1 assert (sv_extra >> 2) == 0, \ "scalar CR %s cannot fit into EXTRA2 %s" % \ - (rname, str(extras[extra_idx])) + (rname, str(extras[extra_idx])) # all good: encode as scalar sv_extra = sv_extra & 0b11 else: # range is CR0-CR127 in increments of 8 assert sv_extra & 0b11 == 0, \ "vector CR %s cannot fit into EXTRA3 %s" % \ - (rname, str(extras[extra_idx])) + (rname, str(extras[extra_idx])) # all good: encode as vector (bit 3 set) sv_extra = 0b100 | (sv_extra >> 2) # reconstruct the actual 5-bit CR field field = (field << 2) | cr_subfield else: - print ("no type match", rtype) + print("no type match", rtype) # capture the extra field info - log ("=>", "%5s" % bin(sv_extra), field) + log("=>", "%5s" % bin(sv_extra), field) extras[extra_idx] = sv_extra # append altered field value to v3.0b, differs for LDST # note that duplicates are skipped e.g. EXTRA2 contains # *BOTH* s:RA *AND* d:RA which happens on LD/ST-with-update srcdest, idx, duplicate = extra_idx - if duplicate: # skip adding to v3.0b fields, already added + if duplicate: # skip adding to v3.0b fields, already added continue if ldst_imm: v30b_newfields.append(("%s(%s)" % (immed, str(field)))) else: v30b_newfields.append(str(field)) - log ("new v3.0B fields", v30b_op, v30b_newfields) - log ("extras", extras) + log("new v3.0B fields", v30b_op, v30b_newfields) + log("extras", extras) # rright. now we have all the info. start creating SVP64 RM svp64_rm = SVP64RMFields() # begin with EXTRA fields for idx, sv_extra in extras.items(): - log (idx) - if idx is None: continue - if idx[0] == 'imm': continue + log(idx) + if idx is None: + continue + if idx[0] == 'imm': + continue srcdest, idx, duplicate = idx if etype == 'EXTRA2': svp64_rm.extra2[idx].eq( @@ -561,22 +566,22 @@ class SVP64Asm: # identify if the op is a LD/ST. the "blegh" way. copied # from power_enums. TODO, split the list _insns down. is_ld = v30b_op in [ - "lbarx", "lbz", "lbzu", "lbzux", "lbzx", # load byte - "ld", "ldarx", "ldbrx", "ldu", "ldux", "ldx", # load double - "lfs", "lfsx", "lfsu", "lfsux", # FP load single - "lfd", "lfdx", "lfdu", "lfdux", "lfiwzx", "lfiwax", # FP load double - "lha", "lharx", "lhau", "lhaux", "lhax", # load half - "lhbrx", "lhz", "lhzu", "lhzux", "lhzx", # more load half - "lwa", "lwarx", "lwaux", "lwax", "lwbrx", # load word - "lwz", "lwzcix", "lwzu", "lwzux", "lwzx", # more load word + "lbarx", "lbz", "lbzu", "lbzux", "lbzx", # load byte + "ld", "ldarx", "ldbrx", "ldu", "ldux", "ldx", # load double + "lfs", "lfsx", "lfsu", "lfsux", # FP load single + "lfd", "lfdx", "lfdu", "lfdux", "lfiwzx", "lfiwax", # FP load double + "lha", "lharx", "lhau", "lhaux", "lhax", # load half + "lhbrx", "lhz", "lhzu", "lhzux", "lhzx", # more load half + "lwa", "lwarx", "lwaux", "lwax", "lwbrx", # load word + "lwz", "lwzcix", "lwzu", "lwzux", "lwzx", # more load word ] is_st = v30b_op in [ - "stb", "stbcix", "stbcx", "stbu", "stbux", "stbx", - "std", "stdbrx", "stdcx", "stdu", "stdux", "stdx", - "stfs", "stfsx", "stfsu", "stfux", # FP store single - "stfd", "stfdx", "stfdu", "stfdux", "stfiwx", # FP store double - "sth", "sthbrx", "sthcx", "sthu", "sthux", "sthx", - "stw", "stwbrx", "stwcx", "stwu", "stwux", "stwx", + "stb", "stbcix", "stbcx", "stbu", "stbux", "stbx", + "std", "stdbrx", "stdcx", "stdu", "stdux", "stdx", + "stfs", "stfsx", "stfsu", "stfux", # FP store single + "stfd", "stfdx", "stfdu", "stfdux", "stfiwx", # FP store double + "sth", "sthbrx", "sthcx", "sthu", "sthux", "sthx", + "stw", "stwbrx", "stwcx", "stwu", "stwux", "stwx", ] # use this to determine if the SVP64 RM format is different. # see https://libre-soc.org/openpower/sv/ldst/ @@ -590,11 +595,11 @@ class SVP64Asm: # parts of svp64_rm mmode = 0 # bit 0 pmask = 0 # bits 1-3 - destwid = 0 # bits 4-5 - srcwid = 0 # bits 6-7 + destwid = 0 # bits 4-5 + srcwid = 0 # bits 6-7 subvl = 0 # bits 8-9 - smask = 0 # bits 16-18 but only for twin-predication - mode = 0 # bits 19-23 + smask = 0 # bits 16-18 but only for twin-predication + mode = 0 # bits 19-23 mask_m_specified = False has_pmask = False @@ -694,36 +699,36 @@ class SVP64Asm: assert sv_mode is None sv_mode = 0b00 mapreduce = True - elif encmode == 'crm': # CR on map-reduce + elif encmode == 'crm': # CR on map-reduce assert sv_mode is None sv_mode = 0b00 mapreduce_crm = True - elif encmode == 'svm': # sub-vector mode + elif encmode == 'svm': # sub-vector mode mapreduce_svm = True elif is_bc: if encmode == 'all': bc_all = 1 - elif encmode == 'st': # svstep mode + elif encmode == 'st': # svstep mode bc_step = 1 - elif encmode == 'sr': # svstep BRc mode + elif encmode == 'sr': # svstep BRc mode bc_step = 1 bc_brc = 1 - elif encmode == 'vs': # VLSET mode + elif encmode == 'vs': # VLSET mode bc_vlset = 1 - elif encmode == 'vsi': # VLSET mode with VLI (VL inclusives) + elif encmode == 'vsi': # VLSET mode with VLI (VL inclusives) bc_vlset = 1 bc_vli = 1 - elif encmode == 'vsb': # VLSET mode with VSb + elif encmode == 'vsb': # VLSET mode with VSb bc_vlset = 1 bc_vsb = 1 - elif encmode == 'vsbi': # VLSET mode with VLI and VSb + elif encmode == 'vsbi': # VLSET mode with VLI and VSb bc_vlset = 1 bc_vli = 1 bc_vsb = 1 - elif encmode == 'snz': # sz (only) already set above + elif encmode == 'snz': # sz (only) already set above src_zero = 1 bc_snz = 1 - elif encmode == 'lu': # LR update mode + elif encmode == 'lu': # LR update mode bc_lru = 1 else: raise AssertionError("unknown encmode %s" % encmode) @@ -751,7 +756,7 @@ class SVP64Asm: if has_pmask and has_smask: assert smmode == pmmode, \ "predicate masks %s and %s must be same reg type" % \ - (pme, sme) + (pme, sme) # sanity-check that twin-predication mask only specified in 2P mode if ptype == '1P': @@ -781,8 +786,8 @@ class SVP64Asm: # XXX TODO: sanity-check bc modes if is_bc: sv_mode = ((bc_svstep << SVP64MODE.MOD2_MSB) | - (bc_vlset << SVP64MODE.MOD2_LSB) | - (bc_snz << SVP64MODE.BC_SNZ)) + (bc_vlset << SVP64MODE.MOD2_LSB) | + (bc_snz << SVP64MODE.BC_SNZ)) srcwid = (bc_vsb << 1) | bc_lru destwid = (bc_lru << 1) | bc_all @@ -791,11 +796,11 @@ class SVP64Asm: ###################################### # "normal" mode if sv_mode is None: - mode |= src_zero << SVP64MODE.SZ # predicate zeroing - mode |= dst_zero << SVP64MODE.DZ # predicate zeroing + mode |= src_zero << SVP64MODE.SZ # predicate zeroing + mode |= dst_zero << SVP64MODE.DZ # predicate zeroing if is_ldst: # TODO: for now, LD/ST-indexed is ignored. - mode |= ldst_elstride << SVP64MODE.ELS_NORMAL # el-strided + mode |= ldst_elstride << SVP64MODE.ELS_NORMAL # el-strided # shifted mode if ldst_shift: mode |= 1 << SVP64MODE.LDST_SHIFT @@ -809,62 +814,62 @@ class SVP64Asm: ###################################### # "mapreduce" modes elif sv_mode == 0b00: - mode |= (0b1<