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
, Style
5 from openpower
.decoder
.power_enums
import find_wiki_dir
6 from openpower
.sv
import sv_binutils_fptrans
12 class SVSTATETestCase(unittest
.TestCase
):
14 def _do_tst(self
, expected
):
15 isa
= SVP64Asm(expected
)
17 with
Program(lst
, bigendian
=False) as program
:
18 print ("ops", program
._instructions
)
20 program
.binfile
.seek(0)
21 binfile
.write(program
.binfile
.read())
22 program
.binfile
.seek(0)
28 print ("insns", insns
)
29 for i
, line
in enumerate(dump(insns
, style
=Style
.SHORT
)):
30 name
= expected
[i
].split(" ")[0]
31 with self
.subTest("%d:%s" % (i
, name
)):
32 print("instruction", repr(line
), repr(expected
[i
]))
33 self
.assertEqual(expected
[i
], line
,
34 "instruction does not match "
35 "'%s' expected '%s'" % (line
, expected
[i
]))
39 expected
= ['addi 1,5,2',
45 self
._do
_tst
(expected
)
47 def test_1_svshape2(self
):
49 'svshape2 12,1,15,5,0,0'
51 self
._do
_tst
(expected
)
53 def test_2_d_custom_op(self
):
59 self
._do
_tst
(expected
)
61 def test_3_sv_isel(self
):
65 'sv.isel 12,2,3,*483',
69 self
._do
_tst
(expected
)
71 def test_4_sv_crand(self
):
73 'sv.crand *16,*2,*33',
75 'sv.crand/ff=RC1/m=r10 12,2,33',
76 'sv.crand/m=r10 12,2,33',
77 'sv.crand/m=r10/sz 12,2,33',
78 'sv.crand/m=r10/zz 12,2,33', # SHOULD PASS
80 self
._do
_tst
(expected
)
82 def test_5_setvl(self
):
87 self
._do
_tst
(expected
)
89 def test_6_sv_setvl(self
):
91 "sv.setvl 5,4,5,0,1,1",
92 "sv.setvl 63,35,5,0,1,1",
94 self
._do
_tst
(expected
)
96 def test_7_batch(self
):
97 "these come from https://bugs.libre-soc.org/show_bug.cgi?id=917#c25"
111 "sv.fmuls *32,*32,*40",
117 "sv.fmuls *32,*32,*40",
132 "sv.lfs *48,256(16)",
133 "sv.fmuls *40,*32,*40",
135 "sv.fmuls *32,*32,*48",
143 "sv.lfs *48,256(16)",
144 "sv.fmuls *40,*32,*40",
146 "sv.fmuls *32,*32,*48",
163 "sv.fmuls *32,*32,*40",
168 self
._do
_tst
(expected
)
170 def test_8_madd(self
):
176 self
._do
_tst
(expected
)
178 def test_9_fptrans(self
):
179 "enumerates a list of fptrans instruction disassembly entries"
180 db
= Database(find_wiki_dir())
181 entries
= sorted(sv_binutils_fptrans
.collect(db
))
182 dis
= lambda entry
: sv_binutils_fptrans
.dis(entry
, binutils
=False)
184 for generator
in map(dis
, entries
):
185 for line
in generator
:
189 def test_10_vec(self
):
191 "sv.add./vec2 *3,*7,*11",
192 "sv.add./vec3 *3,*7,*11",
193 "sv.add./vec4 *3,*7,*11",
195 self
._do
_tst
(expected
)
197 def test_11_elwidth(self
):
199 "sv.add./dw=8 *3,*7,*11",
200 "sv.add./dw=16 *3,*7,*11",
201 "sv.add./dw=32 *3,*7,*11",
202 "sv.add./sw=8 *3,*7,*11",
203 "sv.add./sw=16 *3,*7,*11",
204 "sv.add./sw=32 *3,*7,*11",
205 "sv.add./dw=8/sw=16 *3,*7,*11",
206 "sv.add./dw=16/sw=32 *3,*7,*11",
207 "sv.add./dw=32/sw=8 *3,*7,*11",
208 "sv.add./w=32 *3,*7,*11",
209 "sv.add./w=8 *3,*7,*11",
210 "sv.add./w=16 *3,*7,*11",
212 self
._do
_tst
(expected
)
214 def test_12_sat(self
):
216 "sv.add./satu *3,*7,*11",
217 "sv.add./sats *3,*7,*11",
219 self
._do
_tst
(expected
)
221 def test_12_mr_r(self
):
223 "sv.add./mrr/vec2 *3,*7,*11",
224 "sv.add./mr/vec2 *3,*7,*11",
225 "sv.add./mrr *3,*7,*11",
226 "sv.add./mr *3,*7,*11",
228 self
._do
_tst
(expected
)
230 def test_13_RC1(self
):
232 "sv.add/ff=RC1 *3,*7,*11",
233 "sv.add/ff=~RC1 *3,*7,*11",
235 self
._do
_tst
(expected
)
237 def test_14_rc1_ff_pr(self
):
239 "sv.add./ff=eq *3,*7,*11",
240 "sv.add./ff=ns *3,*7,*11",
241 "sv.add./ff=lt *3,*7,*11",
242 "sv.add./ff=ge *3,*7,*11",
243 "sv.add./ff=le *3,*7,*11",
244 "sv.add./ff=gt *3,*7,*11",
245 "sv.add./ff=ne *3,*7,*11",
247 self
._do
_tst
(expected
)
249 def test_15_predicates(self
):
251 "sv.add./m=r3 *3,*7,*11",
252 "sv.add./m=1<<r3 *3,*7,*11",
253 "sv.add./m=~r10 *3,*7,*11",
254 "sv.add./m=so *3,*7,*11",
255 "sv.add./m=ne *3,*7,*11",
256 "sv.add./m=lt *3,*7,*11",
258 "sv.extsw/m=r30 3,7",
259 "sv.extsw/dm=~r30/sm=r30 3,7",
260 "sv.extsw/dm=eq/sm=gt 3,7",
261 "sv.extsw/sm=~r3 3,7",
262 "sv.extsw/dm=r30 3,7",
264 self
._do
_tst
(expected
)
266 def test_15_els(self
):
268 "sv.stw/els *4,16(2)",
269 "sv.lfs/els *1,256(4)",
271 self
._do
_tst
(expected
)
273 def test_16_bc(self
):
274 """bigger list in test_pysvp64dis_branch.py, this one's "quick"
277 "sv.bc/all 12,*1,0xc",
278 "sv.bc/snz 12,*1,0xc",
279 "sv.bc/m=r3/snz 12,*1,0xc",
280 "sv.bc/m=r3/sz 12,*1,0xc",
281 "sv.bc/all/sl/slu 12,*1,0xc",
282 "sv.bc/all/lru/sl/slu/snz 12,*1,0xc",
283 "sv.bc/all/lru/sl/slu/snz/vs 12,*1,0xc",
284 "sv.bc/all/lru/sl/slu/snz/vsi 12,*1,0xc",
285 "sv.bc/all/lru/sl/slu/snz/vsb 12,*1,0xc",
286 "sv.bc/all/lru/sl/slu/snz/vsbi 12,*1,0xc",
287 "sv.bc/all/ctr/lru/sl/slu/snz 12,*1,0xc",
288 "sv.bc/all/cti/lru/sl/slu/snz 12,*1,0xc",
289 "sv.bc/all/ctr/lru/sl/slu/snz/vsb 12,*1,0xc",
291 self
._do
_tst
(expected
)
293 def test_17_vli(self
):
295 "sv.add/ff=RC1/vli 3,7,11",
296 "sv.add/ff=~RC1/vli 3,7,11",
298 self
._do
_tst
(expected
)
300 def test_18_sea(self
):
304 self
._do
_tst
(expected
)
306 def test_19_ldst_idx_els(self
):
308 "sv.stdx/els *4,16,2",
309 "sv.stdx/els/sea *4,16,2",
310 "sv.ldx/els *4,16,2",
311 "sv.ldx/els/sea *4,16,2",
313 self
._do
_tst
(expected
)
315 def test_20_cmp(self
):
318 "sv.cmp/ff=eq *4,1,*0,1",
319 "sv.cmp/ff=eq/vli *4,1,*0,1",
320 "sv.cmp/ff=ne *4,1,*0,1",
321 "sv.cmp/ff=eq/m=r3/zz *4,1,*0,1",
322 "sv.cmp/ff=lt/m=r3/zz *4,1,*0,1",
323 "sv.cmp/ff=gt/m=r3/zz *4,1,*0,1",
325 self
._do
_tst
(expected
)
327 def test_21_addex(self
):
333 self
._do
_tst
(expected
)
335 def test_22_ld(self
):
338 "ld 4,16(5)", # sigh, needs magic-shift (D||0b00)
339 "sv.ld 4,16(5)", # ditto
341 self
._do
_tst
(expected
)
343 def test_23_lq(self
):
346 "lq 4,16(5)", # ditto, magic-shift (DQ||0b0000)
347 "lq 4,32(5)", # ditto
348 "sv.lq 4,16(5)", # ditto
350 self
._do
_tst
(expected
)
352 def test_24_bc(self
):
357 self
._do
_tst
(expected
)
359 def test_25_stq(self
):
366 self
._do
_tst
(expected
)
368 def test_26_sv_stq_vector_name(self
):
370 "sv.stq *4,16(*5)", # RSp not recognised as "vector" name
372 self
._do
_tst
(expected
)
374 def test_27_sc(self
):
381 self
._do
_tst
(expected
)
383 def test_28_rfid(self
):
388 self
._do
_tst
(expected
)
390 def test_29_postinc(self
):
393 "sv.lwzu/pi *6,8(2)",
394 "sv.lwzu/pi *6,24(2)",
395 "sv.stwu/pi *6,24(2)",
397 self
._do
_tst
(expected
)
399 def test_29_dsld_dsrd(self
):
410 self
._do
_tst
(expected
)
412 def test_30_divmod2du(self
):
416 "sv.divmod2du 5,4,5,3",
417 "sv.divmod2du *6,4,*0,3",
418 "sv.maddedu 5,4,5,3",
419 "sv.maddedu *6,4,5,3",
421 self
._do
_tst
(expected
)
423 def test_31_shadd_shaddw_shadduw(self
):
450 self
._do
_tst
(expected
)
452 def test_32_ldst_idx_ffirst(self
):
454 "sv.stdx/ff=RC1 *4,16,2",
455 "sv.stdx/ff=~RC1 *4,16,2",
456 "sv.ldx/ff=RC1 *4,16,2",
457 "sv.ldx/ff=~RC1 *4,16,2",
459 self
._do
_tst
(expected
)
461 def test_33_ldst_imm_ffirst(self
):
463 "sv.std/ff=RC1 *4,16(2)",
464 "sv.std/ff=~RC1 *4,16(2)",
465 "sv.ld/ff=RC1 *4,16(2)",
466 "sv.ld/ff=~RC1 *4,16(2)",
468 self
._do
_tst
(expected
)
470 def test_34_ldst_update_imm_ffirst(self
):
472 "sv.ldu/ff=~RC1/vli *16,0(*17)",
474 self
._do
_tst
(expected
)
476 def test_35_ffmadds(self
):
478 "sv.ffmadds *0,*0,*0",
480 self
._do
_tst
(expected
)
482 if __name__
== "__main__":