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',
70 'sv.crand/ff=eq/m=r10 12,2,33',
71 'sv.crand/m=r10 12,2,33',
72 'sv.crand/m=r10/sz 12,2,33',
73 # XXX dz/sz is not the canonical way, must be zz
74 'sv.crand/dz/m=r10/sz 12,2,33', # NOT OK
75 'sv.crand/m=r10/zz 12,2,33', # SHOULD PASS
77 self
._do
_tst
(expected
)
79 def test_5_setvl(self
):
84 self
._do
_tst
(expected
)
86 def test_6_sv_setvl(self
):
88 "sv.setvl 5,4,5,0,1,1",
89 "sv.setvl 63,35,5,0,1,1",
91 self
._do
_tst
(expected
)
93 def test_7_batch(self
):
94 "these come from https://bugs.libre-soc.org/show_bug.cgi?id=917#c25"
108 "sv.fmuls *32,*32,*40",
114 "sv.fmuls *32,*32,*40",
129 "sv.lfs *48,256(16)",
130 "sv.fmuls *40,*32,*40",
132 "sv.fmuls *32,*32,*48",
140 "sv.lfs *48,256(16)",
141 "sv.fmuls *40,*32,*40",
143 "sv.fmuls *32,*32,*48",
160 "sv.fmuls *32,*32,*40",
165 self
._do
_tst
(expected
)
167 def test_8_madd(self
):
173 self
._do
_tst
(expected
)
175 def test_9_fptrans(self
):
176 "enumerates a list of fptrans instruction disassembly entries"
177 db
= Database(find_wiki_dir())
178 entries
= sorted(sv_binutils_fptrans
.collect(db
))
179 dis
= lambda entry
: sv_binutils_fptrans
.dis(entry
, binutils
=False)
180 self
._do
_tst
(list(map(dis
, entries
)))
182 def test_10_vec(self
):
184 "sv.add./vec2 *3,*7,*11",
185 "sv.add./vec3 *3,*7,*11",
186 "sv.add./vec4 *3,*7,*11",
188 self
._do
_tst
(expected
)
190 def test_11_elwidth(self
):
192 "sv.add./dw=8 *3,*7,*11",
193 "sv.add./dw=16 *3,*7,*11",
194 "sv.add./dw=32 *3,*7,*11",
195 "sv.add./sw=8 *3,*7,*11",
196 "sv.add./sw=16 *3,*7,*11",
197 "sv.add./sw=32 *3,*7,*11",
198 "sv.add./dw=8/sw=16 *3,*7,*11",
199 "sv.add./dw=16/sw=32 *3,*7,*11",
200 "sv.add./dw=32/sw=8 *3,*7,*11",
201 "sv.add./w=32 *3,*7,*11",
202 "sv.add./w=8 *3,*7,*11",
203 "sv.add./w=16 *3,*7,*11",
205 self
._do
_tst
(expected
)
207 def test_12_sat(self
):
209 "sv.add./satu *3,*7,*11",
210 "sv.add./sats *3,*7,*11",
212 self
._do
_tst
(expected
)
214 def test_12_mr_r(self
):
216 "sv.add./mrr/vec2 *3,*7,*11",
217 "sv.add./mr/vec2 *3,*7,*11",
218 "sv.add./mrr *3,*7,*11",
219 "sv.add./mr *3,*7,*11",
221 self
._do
_tst
(expected
)
223 def test_13_RC1(self
):
225 "sv.add/ff=RC1 *3,*7,*11",
226 "sv.add/pr=RC1 *3,*7,*11",
227 "sv.add/ff=~RC1 *3,*7,*11",
228 "sv.add/pr=~RC1 *3,*7,*11",
230 self
._do
_tst
(expected
)
232 def test_14_rc1_ff_pr(self
):
234 "sv.add./ff=eq *3,*7,*11",
235 "sv.add./ff=ns *3,*7,*11",
236 "sv.add./ff=lt *3,*7,*11",
237 "sv.add./ff=ge *3,*7,*11",
238 "sv.add./ff=le *3,*7,*11",
239 "sv.add./ff=gt *3,*7,*11",
240 "sv.add./ff=ne *3,*7,*11",
241 "sv.add./pr=eq *3,*7,*11",
242 "sv.add./pr=ns *3,*7,*11",
244 self
._do
_tst
(expected
)
246 def test_15_predicates(self
):
248 "sv.add./m=r3 *3,*7,*11",
249 "sv.add./m=1<<r3 *3,*7,*11",
250 "sv.add./m=~r10 *3,*7,*11",
251 "sv.add./m=so *3,*7,*11",
252 "sv.add./m=ne *3,*7,*11",
253 "sv.add./m=lt *3,*7,*11",
255 "sv.extsw/m=r30 3,7",
256 "sv.extsw/dm=~r30/sm=r30 3,7",
257 "sv.extsw/dm=eq/sm=gt 3,7",
258 "sv.extsw/sm=~r3 3,7",
259 "sv.extsw/dm=r30 3,7",
261 self
._do
_tst
(expected
)
263 def test_15_els(self
):
265 "sv.stw/els *4,16(2)",
266 "sv.lfs/els *1,256(4)",
268 self
._do
_tst
(expected
)
270 def test_16_bc(self
):
271 """bigger list in test_pysvp64dis_branch.py, this one's "quick"
274 "sv.bc/all 12,*1,0xc",
275 "sv.bc/snz 12,*1,0xc",
276 "sv.bc/m=r3/snz 12,*1,0xc",
277 "sv.bc/m=r3/sz 12,*1,0xc",
278 "sv.bc/all/sl/slu 12,*1,0xc",
279 "sv.bc/all/lru/sl/slu/snz 12,*1,0xc",
280 "sv.bc/all/lru/sl/slu/snz/vs 12,*1,0xc",
281 "sv.bc/all/lru/sl/slu/snz/vsi 12,*1,0xc",
282 "sv.bc/all/lru/sl/slu/snz/vsb 12,*1,0xc",
283 "sv.bc/all/lru/sl/slu/snz/vsbi 12,*1,0xc",
284 "sv.bc/all/ctr/lru/sl/slu/snz 12,*1,0xc",
285 "sv.bc/all/cti/lru/sl/slu/snz 12,*1,0xc",
286 "sv.bc/all/ctr/lru/sl/slu/snz/vsb 12,*1,0xc",
288 self
._do
_tst
(expected
)
290 def test_17_vli(self
):
292 "sv.add/ff=RC1/vli 3,7,11",
293 "sv.add/ff=~RC1/vli 3,7,11",
295 self
._do
_tst
(expected
)
297 def test_18_sea(self
):
301 self
._do
_tst
(expected
)
303 def test_19_ldst_idx_els(self
):
305 "sv.stdx/els *4,16,2",
306 "sv.stdx/els/sea *4,16,2",
307 "sv.ldx/els *4,16,2",
308 "sv.ldx/els/sea *4,16,2",
310 self
._do
_tst
(expected
)
312 def test_20_cmp(self
):
315 "sv.cmp/ff=RC1 *4,1,*0,1",
316 "sv.cmp/ff=RC1/vli *4,1,*0,1",
317 "sv.cmp/ff=~RC1 *4,1,*0,1",
318 "sv.cmp/ff=RC1/m=r3/sz *4,1,*0,1",
319 "sv.cmp/dz/ff=RC1/m=r3 *4,1,*0,1",
320 "sv.cmp/dz/ff=RC1/m=r3/sz *4,1,*0,1",
322 self
._do
_tst
(expected
)
324 def test_21_addex(self
):
330 self
._do
_tst
(expected
)
332 def test_22_ld(self
):
335 "ld 4,16(5)", # sigh, needs magic-shift (D||0b00)
336 "sv.ld 4,16(5)", # ditto
338 self
._do
_tst
(expected
)
340 def test_23_lq(self
):
343 "lq 4,16(5)", # ditto, magic-shift (DQ||0b0000)
344 "lq 4,32(5)", # ditto
345 "sv.lq 4,16(5)", # ditto
347 self
._do
_tst
(expected
)
349 def test_24_bc(self
):
354 self
._do
_tst
(expected
)
356 def test_25_stq(self
):
363 self
._do
_tst
(expected
)
365 def test_26_sv_stq_vector_name(self
):
367 "sv.stq *4,16(*5)", # RSp not recognised as "vector" name
369 self
._do
_tst
(expected
)
372 if __name__
== "__main__":