a95b21786a929ef3ec7a8311f6bf2f9a1ad5a329
1 # SPDX-License-Identifier: LGPLv3+
2 # Copyright (C) 2021 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
3 # Funded by NLnet http://nlnet.nl
5 """SVP64 OpenPOWER v3.0B assembly translator
7 This class takes raw svp64 assembly mnemonics (aliases excluded) and
8 creates an EXT001-encoded "svp64 prefix" followed by a v3.0B opcode.
10 It is very simple and straightforward, the only weirdness being the
11 extraction of the register information and conversion to v3.0B numbering.
15 from soc
.decoder
.pseudo
.pagereader
import ISA
16 from soc
.decoder
.power_enums
import get_csv
, find_wiki_dir
19 def is_CR_3bit(regname
):
20 return regname
in ['BF', 'BFA']
22 def is_CR_5bit(regname
):
23 return regname
in ['BA', 'BB', 'BC', 'BI', 'BT']
26 return regname
in ['RA', 'RB', 'RC', 'RS', 'RT']
34 for fname
in os
.listdir(pth
):
36 if fname
.startswith("RM"):
37 entries
= get_csv(fname
)
42 def __init__(self
, lst
):
44 self
.trans
= self
.translate(lst
)
47 for insn
in self
.trans
:
50 def translate(self
, lst
):
51 isa
= ISA() # reads the v3.0B pseudo-code markdown files
54 # find first space, to get opcode
57 # now find opcode fields
58 fields
= ''.join(ls
[1:]).split(',')
59 fields
= list(map(str.strip
, fields
))
60 print (opcode
, fields
)
62 # identify if is a svp64 mnemonic
63 if not opcode
.startswith('sv.'):
64 res
.append(insn
) # unaltered
67 # start working on decoding the svp64 op: sv.baseop.vec2.mode
68 opmodes
= opcode
.split(".")[1:] # strip leading "sv."
69 v30b_op
= opmodes
.pop(0) # first is the v3.0B
70 if v30b_op
not in isa
.instr
:
71 raise Exception("opcode %s of '%s' not supported" % \
76 if __name__
== '__main__':
77 isa
= SVP64(['slw 3, 1, 4',