1 from openpower
.simulator
.program
import Program
2 from openpower
.sv
.trans
.pysvp64dis
import load
, dump
3 from openpower
.sv
.trans
.svp64
import SVP64Asm
4 from openpower
.decoder
.power_insn
import Database
, Verbosity
5 from openpower
.decoder
.power_enums
import find_wiki_dir
6 from openpower
.sv
import sv_binutils_fptrans
11 class SVSTATETestCase(unittest
.TestCase
):
13 def _do_tst(self
, expected
):
14 isa
= SVP64Asm(expected
)
16 with
Program(lst
, bigendian
=False) as program
:
17 print ("ops", program
._instructions
)
18 program
.binfile
.seek(0)
19 insns
= load(program
.binfile
)
23 print ("insns", insns
)
24 for i
, line
in enumerate(dump(insns
, verbosity
=Verbosity
.SHORT
)):
25 name
= expected
[i
].split(" ")[0]
26 with self
.subTest("%d:%s" % (i
, name
)):
27 print("instruction", repr(line
), repr(expected
[i
]))
28 self
.assertEqual(expected
[i
], line
,
29 "instruction does not match "
30 "'%s' expected '%s'" % (line
, expected
[i
]))
34 expected
= ['addi 1,5,2',
40 self
._do
_tst
(expected
)
42 def test_1_svshape2(self
):
44 'svshape2 12,1,15,5,0,0'
46 self
._do
_tst
(expected
)
48 def test_2_d_custom_op(self
):
54 self
._do
_tst
(expected
)
56 def test_3_sv_isel(self
):
60 'sv.isel 12,2,3,*483',
64 self
._do
_tst
(expected
)
66 def test_4_sv_crand(self
):
68 'sv.crand *16,*2,*33',
71 self
._do
_tst
(expected
)
73 def test_5_setvl(self
):
78 self
._do
_tst
(expected
)
80 def test_6_sv_setvl(self
):
82 "sv.setvl 5,4,5,0,1,1",
83 "sv.setvl 63,35,5,0,1,1",
85 self
._do
_tst
(expected
)
87 def test_7_batch(self
):
88 "these come from https://bugs.libre-soc.org/show_bug.cgi?id=917#c25"
102 "sv.fmuls *32,*32,*40",
108 "sv.fmuls *32,*32,*40",
123 "sv.lfs *48,256(16)",
124 "sv.fmuls *40,*32,*40",
126 "sv.fmuls *32,*32,*48",
134 "sv.lfs *48,256(16)",
135 "sv.fmuls *40,*32,*40",
137 "sv.fmuls *32,*32,*48",
154 "sv.fmuls *32,*32,*40",
159 self
._do
_tst
(expected
)
161 def test_8_madd(self
):
167 self
._do
_tst
(expected
)
169 def test_9_fptrans(self
):
170 "enumerates a list of fptrans instruction disassembly entries"
171 db
= Database(find_wiki_dir())
172 entries
= sorted(sv_binutils_fptrans
.collect(db
))
173 dis
= lambda entry
: sv_binutils_fptrans
.dis(entry
, binutils
=False)
174 self
._do
_tst
(list(map(dis
, entries
)))
176 def test_10_vec(self
):
178 "sv.add./vec2 *3,*7,*11",
179 "sv.add./vec3 *3,*7,*11",
180 "sv.add./vec4 *3,*7,*11",
182 self
._do
_tst
(expected
)
184 def test_11_elwidth(self
):
186 "sv.add./dw=8 *3,*7,*11",
187 "sv.add./dw=16 *3,*7,*11",
188 "sv.add./dw=32 *3,*7,*11",
189 "sv.add./sw=8 *3,*7,*11",
190 "sv.add./sw=16 *3,*7,*11",
191 "sv.add./sw=32 *3,*7,*11",
192 "sv.add./dw=8/sw=16 *3,*7,*11",
193 "sv.add./dw=16/sw=32 *3,*7,*11",
194 "sv.add./dw=32/sw=8 *3,*7,*11",
195 "sv.add./w=32 *3,*7,*11",
196 "sv.add./w=8 *3,*7,*11",
197 "sv.add./w=16 *3,*7,*11",
199 self
._do
_tst
(expected
)
201 def test_12_sat(self
):
203 "sv.add./satu *3,*7,*11",
204 "sv.add./sats *3,*7,*11",
206 self
._do
_tst
(expected
)
208 def test_12_mr_r(self
):
210 "sv.add./mrr/vec2 *3,*7,*11",
211 "sv.add./mr/vec2 *3,*7,*11",
212 "sv.add./mrr *3,*7,*11",
213 "sv.add./mr *3,*7,*11",
215 self
._do
_tst
(expected
)
217 def test_13_RC1(self
):
219 "sv.add/ff=RC1 *3,*7,*11",
220 "sv.add/pr=RC1 *3,*7,*11",
221 "sv.add/ff=~RC1 *3,*7,*11",
222 "sv.add/pr=~RC1 *3,*7,*11",
224 self
._do
_tst
(expected
)
226 def test_14_rc1_ff_pr(self
):
228 "sv.add./ff=eq *3,*7,*11",
229 "sv.add./ff=ns *3,*7,*11",
230 "sv.add./ff=lt *3,*7,*11",
231 "sv.add./ff=ge *3,*7,*11",
232 "sv.add./ff=le *3,*7,*11",
233 "sv.add./ff=gt *3,*7,*11",
234 "sv.add./ff=ne *3,*7,*11",
235 "sv.add./pr=eq *3,*7,*11",
236 "sv.add./pr=ns *3,*7,*11",
238 self
._do
_tst
(expected
)
240 def test_15_predicates(self
):
242 "sv.add./m=r3 *3,*7,*11",
243 "sv.add./m=1<<r3 *3,*7,*11",
244 "sv.add./m=~r10 *3,*7,*11",
245 "sv.add./m=so *3,*7,*11",
246 "sv.add./m=ne *3,*7,*11",
247 "sv.add./m=lt *3,*7,*11",
249 "sv.extsw/m=r30 3,7",
250 "sv.extsw/dm=~r30/sm=r30 3,7",
251 "sv.extsw/dm=eq/sm=gt 3,7",
252 "sv.extsw/sm=~r3 3,7",
253 "sv.extsw/dm=r30 3,7",
255 self
._do
_tst
(expected
)
257 def test_15_els(self
):
259 "sv.stw/els *4,16(2)",
260 "sv.lfs/els *1,256(4)",
262 self
._do
_tst
(expected
)
264 def test_16_bc(self
):
265 """bigger list in test_pysvp64dis_branch.py, this one's "quick"
268 "sv.bc/all 12,*1,0xc",
269 "sv.bc/snz 12,*1,0xc",
270 "sv.bc/m=r3/snz 12,*1,0xc",
271 "sv.bc/m=r3/sz 12,*1,0xc",
272 "sv.bc/all/sl/slu 12,*1,0xc",
273 "sv.bc/all/lru/sl/slu/snz 12,*1,0xc",
274 "sv.bc/all/lru/sl/slu/snz/vs 12,*1,0xc",
275 "sv.bc/all/lru/sl/slu/snz/vsi 12,*1,0xc",
276 "sv.bc/all/lru/sl/slu/snz/vsb 12,*1,0xc",
277 "sv.bc/all/lru/sl/slu/snz/vsbi 12,*1,0xc",
278 "sv.bc/all/ctr/lru/sl/slu/snz 12,*1,0xc",
279 "sv.bc/all/cti/lru/sl/slu/snz 12,*1,0xc",
280 "sv.bc/all/ctr/lru/sl/slu/snz/vsb 12,*1,0xc",
282 self
._do
_tst
(expected
)
284 def test_17_vli(self
):
286 "sv.add/ff=RC1/vli 3,7,11",
287 "sv.add/ff=~RC1/vli 3,7,11",
289 self
._do
_tst
(expected
)
291 def test_18_sea(self
):
295 self
._do
_tst
(expected
)
298 def test_19_ldst_idx_els(self
):
300 "sv.stdx/els *4,16,2",
301 "sv.stdx/els/sea *4,16,2",
302 "sv.ldx/els *4,16,2",
303 "sv.ldx/els/sea *4,16,2",
305 self
._do
_tst
(expected
)
307 def test_20_cmp(self
):
310 "sv.cmp/ff=RC1 *4,1,*0,1",
311 "sv.cmp/ff=RC1/vli *4,1,*0,1",
312 "sv.cmp/ff=~RC1 *4,1,*0,1",
313 "sv.cmp/ff=RC1/m=r3/sz *4,1,*0,1",
314 "sv.cmp/dz/ff=RC1/m=r3 *4,1,*0,1",
315 "sv.cmp/dz/ff=RC1/m=r3/sz *4,1,*0,1",
317 self
._do
_tst
(expected
)
320 if __name__
== "__main__":