1 # SPDX-License: LGPLv3+
2 # Copyright (C) 2020, 2021 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
3 # Copyright (C) 2020, Michael Nolan
5 """Enums used in OpenPOWER ISA decoding
7 Note: for SV, from v3.1B p12:
9 The designated SPR sandbox consists of non-privileged SPRs 704-719 and
10 privileged SPRs 720-735.
12 Note: the option exists to select a much shorter list of SPRs, to reduce
13 regfile size in HDL. this is SPRreduced and the supported list is in
17 from enum
import Enum
, unique
20 from os
.path
import dirname
, join
21 from collections
import namedtuple
25 filedir
= os
.path
.dirname(os
.path
.abspath(__file__
))
26 basedir
= dirname(dirname(dirname(filedir
)))
27 tabledir
= join(basedir
, 'openpower')
28 isatables
= join(tabledir
, 'isatables')
29 #print ("find_wiki_dir", isatables)
33 def find_wiki_file(name
):
34 return join(find_wiki_dir(), name
)
38 file_path
= find_wiki_file(name
)
39 with
open(file_path
, 'r') as csvfile
:
40 reader
= csv
.DictReader(csvfile
)
44 # names of the fields in the tables that don't correspond to an enum
45 single_bit_flags
= ['inv A', 'inv out',
46 'cry out', 'BR', 'sgn ext', 'rsrv', '32b',
47 'sgn', 'lk', 'sgl pipe']
49 # default values for fields in the table
50 default_values
= {'unit': "NONE", 'internal op': "OP_ILLEGAL",
51 'in1': "RA", 'in2': 'NONE', 'in3': 'NONE', 'out': 'NONE',
55 'rc': 'NONE', 'cry in': 'ZERO', 'form': 'NONE'}
58 def get_signal_name(name
):
61 return name
.lower().replace(' ', '_')
63 # this corresponds to which Function Unit (pipeline-with-Reservation-Stations)
64 # is to process and guard the operation. they are roughly divided by having
65 # the same register input/output signature (X-Form, etc.)
82 SV
= 1 << 12 # Simple-V https://libre-soc.org/openpower/sv
118 SVL
= 29 # Simple-V for setvl instruction
119 SVD
= 30 # Simple-V for LD/ST bit-reverse, variant of D-Form
120 SVDS
= 31 # Simple-V for LD/ST bit-reverse, variant of DS-Form
121 SVM
= 32 # Simple-V SHAPE mode - TEMPORARY TEMPORARY TEMPORARY
122 SVRM
= 33 # Simple-V REMAP mode - TEMPORARY TEMPORARY TEMPORARY
124 # Simple-V svp64 fields https://libre-soc.org/openpower/sv/svp64/
148 Idx_1_2
= 5 # due to weird BA/BB for crops
152 class SVP64PredMode(Enum
):
159 class SVP64PredInt(Enum
):
171 class SVP64PredCR(Enum
):
183 class SVP64RMMode(Enum
):
193 class SVP64BCPredMode(Enum
):
199 class SVP64BCVLSETMode(Enum
):
205 # note that these are chosen to be exactly the same as
206 # SVP64 RM bit 4. ALL=1 => bit4=1
208 class SVP64BCGate(Enum
):
213 class SVP64BCCTRMode(Enum
):
220 class SVP64width(Enum
):
228 class SVP64subvl(Enum
):
236 class SVP64sat(Enum
):
242 class SVP64LDSTmode(Enum
):
250 # supported instructions: make sure to keep up-to-date with CSV files
251 # just like everything else
253 "NONE", "add", "addc", "addco", "adde", "addeo",
254 "addi", "addic", "addic.", "addis",
255 "addme", "addmeo", "addo", "addze", "addzeo",
257 "and", "andc", "andi.", "andis.",
259 "b", "bc", "bcctr", "bclr", "bctar",
263 "cmp", "cmpb", "cmpeqb", "cmpi", "cmpl", "cmpli", "cmprb",
264 "cntlzd", "cntlzw", "cnttzd", "cnttzw",
265 "crand", "crandc", "creqv",
266 "crnand", "crnor", "cror", "crorc", "crxor",
268 "dcbf", "dcbst", "dcbt", "dcbtst", "dcbz",
269 "divd", "divde", "divdeo", "divdeu",
270 "divdeuo", "divdo", "divdu", "divduo", "divw", "divwe", "divweo",
271 "divweu", "divweuo", "divwo", "divwu", "divwuo",
273 "extsb", "extsh", "extsw", "extswsli",
274 "fadd", "fadds", "fsub", "fsubs", # FP add / sub
275 "fcfids", "fcfidus", "fsqrts", "fres", "frsqrtes", # FP stuff
276 "fdmadds", # DCT FP 3-arg
277 "fmsubs", "fmadds", "fnmsubs", "fnmadds", # FP 3-arg
278 "ffadds", "ffsubs", "ffmuls", "ffdivs", # FFT FP 2-arg
279 "ffmsubs", "ffmadds", "ffnmsubs", "ffnmadds", # FFT FP 3-arg
280 "fmul", "fmuls", "fdiv", "fdivs", # FP mul / div
281 "fmr", "fabs", "fnabs", "fneg", "fcpsgn", # FP move/abs/neg
282 "fsins", "fcoss", # FP SIN/COS
283 "hrfid", "icbi", "icbt", "isel", "isync",
284 "lbarx", "lbz", "lbzu", "lbzux", "lbzx", # load byte
285 "ld", "ldarx", "ldbrx", "ldu", "ldux", "ldx", # load double
286 #"lbzbr", "lbzubr", # load byte SVP64 bit-reversed
287 #"ldbr", "ldubr", # load double SVP64 bit-reversed
288 "lfs", "lfsx", "lfsu", "lfsux", # FP load single
289 "lfd", "lfdx", "lfdu", "lfdux", "lfiwzx", "lfiwax", # FP load double
290 "lha", "lharx", "lhau", "lhaux", "lhax", # load half
291 "lhbrx", "lhz", "lhzu", "lhzux", "lhzx", # more load half
292 #"lhabr", "lhaubr", # load half SVP64 bit-reversed
293 #"lhzbr", "lhzubr", # more load half SVP64 bit-reversed
294 "lwa", "lwarx", "lwaux", "lwax", "lwbrx", # load word
295 "lwz", "lwzcix", "lwzu", "lwzux", "lwzx", # more load word
296 #"lwabr", # load word SVP64 bit-reversed
297 #"lwzbr", "lwzubr", # more load word SVP64 bit-reversed
298 "maddhd", "maddhdu", "maddld", # INT multiply-and-add
299 "mcrf", "mcrxr", "mcrxrx", "mfcr/mfocrf", # CR mvs
301 "modsd", "modsw", "modud", "moduw",
302 "mtcrf/mtocrf", "mtmsr", "mtmsrd", "mtspr",
303 "mulhd", "mulhdu", "mulhw", "mulhwu", "mulld", "mulldo",
304 "mulli", "mullw", "mullwo",
305 "nand", "neg", "nego",
307 "nor", "or", "orc", "ori", "oris",
308 "popcntb", "popcntd", "popcntw",
311 "rldcl", "rldcr", "rldic", "rldicl", "rldicr", "rldimi",
312 "rlwimi", "rlwinm", "rlwnm",
314 "setvl", # https://libre-soc.org/openpower/sv/setvl
315 "svremap", # https://libre-soc.org/openpower/sv/remap - TEMPORARY
316 "svshape", # https://libre-soc.org/openpower/sv/remap
317 "svstep", # https://libre-soc.org/openpower/sv/setvl
319 "slbia", "sld", "slw", "srad", "sradi",
320 "sraw", "srawi", "srd", "srw",
321 "stb", "stbcix", "stbcx", "stbu", "stbux", "stbx",
322 "std", "stdbrx", "stdcx", "stdu", "stdux", "stdx",
323 "stfs", "stfsx", "stfsu", "stfux", "stfsux", # FP store single
324 "stfd", "stfdx", "stfdu", "stfdux", "stfiwx", # FP store double
325 "sth", "sthbrx", "sthcx", "sthu", "sthux", "sthx",
326 "stw", "stwbrx", "stwcx", "stwu", "stwux", "stwx",
327 "subf", "subfc", "subfco", "subfe", "subfeo", "subfic",
328 "subfme", "subfmeo", "subfo", "subfze", "subfzeo",
333 "xor", "xori", "xoris",
336 # two-way lookup of instruction-to-index and vice-versa
339 for i
, insn
in enumerate(_insns
):
343 # must be long enough to cover all instructions
344 asmlen
= len(_insns
).bit_length()
346 # Internal Operation numbering. Add new opcodes here (FPADD, FPMUL etc.)
351 OP_ILLEGAL
= 0 # important that this is zero (see power_decoder.py)
425 OP_FPOP
= 77 # temporary: replace with actual ops
426 OP_FPOP_I
= 78 # temporary: replace with actual ops
442 RS
= 4 # for some ALU/Logical operations
462 RS
= 13 # for shiftrot (M-Form)
464 CONST_SVD
= 15 # for SVD-Form
465 CONST_SVDS
= 16 # for SVDS-Form
472 RB
= 2 # for shiftrot (M-Form)
475 RC
= 5 # for SVP64 bit-reverse LD/ST
499 class LDSTMode(Enum
):
534 class CROutSel(Enum
):
543 # SPRs - Special-Purpose Registers. See V3.0B Figure 18 p971 and
544 # http://libre-riscv.org/openpower/isatables/sprs.csv
545 # http://bugs.libre-riscv.org/show_bug.cgi?id=261
547 def get_spr_enum(full_file
):
548 """get_spr_enum - creates an Enum of SPRs, dynamically
549 has the option to reduce the enum to a much shorter list.
550 this saves drastically on the size of the regfile
552 short_list
= {'PIDR', 'DAR', 'PRTBL', 'DSISR', 'SVSRR0', 'SVSTATE',
553 'SVSTATE0', 'SVSTATE1', 'SVSTATE2', 'SVSTATE3',
554 'SPRG0_priv', 'SPRG1_priv', 'SPRG2_priv', 'SPRG3_priv',
558 for row
in get_csv("sprs.csv"):
559 if full_file
or row
['SPR'] in short_list
:
562 spr_info
= namedtuple('spr_info', 'SPR priv_mtspr priv_mfspr length idx')
566 info
= spr_info(SPR
=row
['SPR'], priv_mtspr
=row
['priv_mtspr'],
567 priv_mfspr
=row
['priv_mfspr'], length
=int(row
['len']),
569 spr_dict
[int(row
['Idx'])] = info
570 spr_byname
[row
['SPR']] = info
571 fields
= [(row
['SPR'], int(row
['Idx'])) for row
in spr_csv
]
572 SPR
= Enum('SPR', fields
)
573 return SPR
, spr_dict
, spr_byname
575 SPRfull
, spr_dict
, spr_byname
= get_spr_enum(full_file
=True)
576 SPRreduced
, _
, _
= get_spr_enum(full_file
=False)
586 if __name__
== '__main__':
587 # find out what the heck is in SPR enum :)
588 print("sprs full", len(SPRfull
))
590 print("sprs reduced", len(SPRreduced
))
591 print(dir(SPRreduced
))
593 print(SPRfull
.__members
__['TAR'])
595 print("full", x
, x
.value
, str(x
), x
.name
)
597 print("reduced", x
, x
.value
, str(x
), x
.name
)
599 print("function", Function
.ALU
.name
)