1 from nmigen
import Module
, Signal
2 from nmigen
.sim
import Simulator
, Delay
, Settle
3 from nmutil
.formaltest
import FHDLTestCase
5 from openpower
.decoder
.isa
.caller
import ISACaller
6 from openpower
.decoder
.power_decoder
import (create_pdecode
)
7 from openpower
.decoder
.power_decoder2
import (PowerDecode2
)
8 from openpower
.simulator
.program
import Program
9 from openpower
.decoder
.isa
.caller
import ISACaller
, SVP64State
, CRFields
10 from openpower
.decoder
.selectable_int
import SelectableInt
11 from openpower
.decoder
.orderedset
import OrderedSet
12 from openpower
.decoder
.isa
.all
import ISA
13 from openpower
.decoder
.isa
.test_caller
import Register
, run_tst
14 from openpower
.sv
.trans
.svp64
import SVP64Asm
15 from openpower
.consts
import SVP64CROffs
16 from copy
import deepcopy
18 class DecoderTestCase(FHDLTestCase
):
20 def _check_regs(self
, sim
, expected
):
24 self
.assertEqual(sim
.gpr(i
), SelectableInt(expected
[i
], 64))
26 def test_svstep_pack(self
):
29 lst
= SVP64Asm(["setvl 0, 0, 4, 0, 1, 1",
30 "svstep 0, 15, 0", # set dst-pack
31 "sv.svstep./vec2 *0, 5, 1", # svstep get vector srcstep
32 "sv.svstep./vec2 *8, 6, 1", # svstep get vector dststep
33 "sv.svstep./vec2 *16, 7, 1", # svstep get src substep
34 "sv.svstep./vec2 *24, 8, 1", # svstep get dst substep
39 svstate
= SVP64State()
41 #svstate.maxvl = 2 # MAXVL
42 print ("SVSTATE", bin(svstate
.asint()))
44 with
Program(lst
, bigendian
=False) as program
:
45 sim
= self
.run_tst_program(program
, svstate
=svstate
)
46 print ("SVSTATE after", bin(sim
.svstate
.asint()))
47 print (" vl", bin(sim
.svstate
.vl
))
48 print (" mvl", bin(sim
.svstate
.maxvl
))
49 print (" srcstep", bin(sim
.svstate
.srcstep
))
50 print (" dststep", bin(sim
.svstate
.dststep
))
51 print (" vfirst", bin(sim
.svstate
. vfirst
))
53 self
.assertEqual(sim
.svstate
.vl
, 4)
54 self
.assertEqual(sim
.svstate
.maxvl
, 4)
55 self
.assertEqual(sim
.svstate
.srcstep
, 0)
56 self
.assertEqual(sim
.svstate
.dststep
, 0)
61 self
.assertEqual(sim
.gpr(0+offs
), SelectableInt(i
, 64))
62 self
.assertEqual(sim
.gpr(8+skew
), SelectableInt(i
, 64))
63 self
.assertEqual(sim
.gpr(16+offs
), SelectableInt(j
, 64))
64 self
.assertEqual(sim
.gpr(24+skew
), SelectableInt(j
, 64))
65 self
.assertEqual(sim
.svstate
.vfirst
, 0)
67 print(" CR0", bin(CR0
.get_range().value
))
68 self
.assertEqual(CR0
[CRFields
.EQ
], 0)
69 self
.assertEqual(CR0
[CRFields
.LT
], 0)
70 self
.assertEqual(CR0
[CRFields
.GT
], 0)
71 self
.assertEqual(CR0
[CRFields
.SO
], 1)
73 def test_svstep_unpack(self
):
75 oh ha ha very funny, cannot use sv.srcstep on unpack:
76 the dest indices are themselves put *into*
77 the vector output in the order of their own values.
79 lst
= SVP64Asm(["setvl 0, 0, 4, 0, 1, 1",
80 "svstep 0, 14, 0", # set src-pack
81 "sv.ori/vec2 *0, *32, 0", # copy 01234567 to new order
86 svstate
= SVP64State()
88 #svstate.maxvl = 2 # MAXVL
89 print ("SVSTATE", bin(svstate
.asint()))
93 initial_regs
[32+i
] = i
95 with
Program(lst
, bigendian
=False) as program
:
96 sim
= self
.run_tst_program(program
, initial_regs
, svstate
=svstate
)
97 print ("SVSTATE after", bin(sim
.svstate
.asint()))
98 print (" vl", bin(sim
.svstate
.vl
))
99 print (" mvl", bin(sim
.svstate
.maxvl
))
100 print (" srcstep", bin(sim
.svstate
.srcstep
))
101 print (" dststep", bin(sim
.svstate
.dststep
))
102 print (" vfirst", bin(sim
.svstate
. vfirst
))
104 self
.assertEqual(sim
.svstate
.vl
, 4)
105 self
.assertEqual(sim
.svstate
.maxvl
, 4)
106 self
.assertEqual(sim
.svstate
.srcstep
, 0)
107 self
.assertEqual(sim
.svstate
.dststep
, 0)
112 self
.assertEqual(sim
.gpr(0+skew
), SelectableInt(offs
, 64))
114 def test_svstep_pack2(self
):
117 lst
= SVP64Asm(["setvl 0, 0, 4, 0, 1, 1",
118 "svstep 0, 15, 0", # set dst-pack
119 "sv.ori/vec2 *0, *32, 0", # copy 01234567 to new order
124 svstate
= SVP64State()
126 #svstate.maxvl = 2 # MAXVL
127 print ("SVSTATE", bin(svstate
.asint()))
129 initial_regs
= [0]*64
131 initial_regs
[32+i
] = i
133 with
Program(lst
, bigendian
=False) as program
:
134 sim
= self
.run_tst_program(program
, initial_regs
, svstate
=svstate
)
135 print ("SVSTATE after", bin(sim
.svstate
.asint()))
136 print (" vl", bin(sim
.svstate
.vl
))
137 print (" mvl", bin(sim
.svstate
.maxvl
))
138 print (" srcstep", bin(sim
.svstate
.srcstep
))
139 print (" dststep", bin(sim
.svstate
.dststep
))
140 print (" vfirst", bin(sim
.svstate
. vfirst
))
142 self
.assertEqual(sim
.svstate
.vl
, 4)
143 self
.assertEqual(sim
.svstate
.maxvl
, 4)
144 self
.assertEqual(sim
.svstate
.srcstep
, 0)
145 self
.assertEqual(sim
.svstate
.dststep
, 0)
150 self
.assertEqual(sim
.gpr(0+offs
), SelectableInt(skew
, 64))
152 def test_svstep_predicate_pack(self
):
153 """tests pack mode with a predicate
155 lst
= SVP64Asm(["setvl 0, 0, 4, 0, 1, 1",
156 "svstep 0, 15, 0", # set dst-pack
157 "sv.ori/vec2/m=r3 *8, *16, 0",
162 svstate
= SVP64State()
164 #svstate.maxvl = 2 # MAXVL
165 print ("SVSTATE", bin(svstate
.asint()))
168 initial_regs
= [0xffffffff]*64
169 initial_regs
[3] = mask
171 initial_regs
[16+i
] = i
173 with
Program(lst
, bigendian
=False) as program
:
174 sim
= self
.run_tst_program(program
, initial_regs
, svstate
=svstate
)
175 print ("SVSTATE after", bin(sim
.svstate
.asint()))
176 print (" vl", bin(sim
.svstate
.vl
))
177 print (" mvl", bin(sim
.svstate
.maxvl
))
178 print (" srcstep", bin(sim
.svstate
.srcstep
))
179 print (" dststep", bin(sim
.svstate
.dststep
))
180 print (" vfirst", bin(sim
.svstate
. vfirst
))
182 self
.assertEqual(sim
.svstate
.vl
, 4)
183 self
.assertEqual(sim
.svstate
.maxvl
, 4)
184 self
.assertEqual(sim
.svstate
.srcstep
, 0)
185 self
.assertEqual(sim
.svstate
.dststep
, 0)
187 # sigh, in sz=0 mode you end up skipping. have to
188 # take that into account, extracting the expected values
194 if mask
& (1<<(skew
>>1)):
195 to_expect
.append(skew
)
197 print ("expected", to_expect
)
202 if mask
& (1<<(offs
>>1)):
203 expected
= SelectableInt(to_expect
.pop(0), 64)
205 expected
= SelectableInt(0xffffffff, 64)
206 print ("checking", hex(expected
.value
), "at", offs
)
207 self
.assertEqual(sim
.gpr(8+offs
), expected
)
209 def test_svstep_unpack(self
):
210 """tests unpack mode with predicate
212 lst
= SVP64Asm(["setvl 0, 0, 4, 0, 1, 1",
213 "svstep 0, 14, 0", # set src-pack
214 "sv.ori/vec2/m=r3 *8, *16, 0", # copy with mask
219 svstate
= SVP64State()
221 #svstate.maxvl = 2 # MAXVL
222 print ("SVSTATE", bin(svstate
.asint()))
225 initial_regs
= [0xffffffff]*64
226 initial_regs
[3] = mask
228 initial_regs
[16+i
] = i
230 with
Program(lst
, bigendian
=False) as program
:
231 sim
= self
.run_tst_program(program
, initial_regs
, svstate
=svstate
)
232 print ("SVSTATE after", bin(sim
.svstate
.asint()))
233 print (" vl", bin(sim
.svstate
.vl
))
234 print (" mvl", bin(sim
.svstate
.maxvl
))
235 print (" srcstep", bin(sim
.svstate
.srcstep
))
236 print (" dststep", bin(sim
.svstate
.dststep
))
237 print (" vfirst", bin(sim
.svstate
. vfirst
))
239 self
.assertEqual(sim
.svstate
.vl
, 4)
240 self
.assertEqual(sim
.svstate
.maxvl
, 4)
241 self
.assertEqual(sim
.svstate
.srcstep
, 0)
242 self
.assertEqual(sim
.svstate
.dststep
, 0)
244 # sigh, in sz=0 mode you end up skipping. have to
245 # take that into account, extracting the expected values
251 if mask
& (1<<(offs
>>1)):
252 to_expect
.append(offs
)
254 print ("expected", to_expect
)
259 if mask
& (1<<(skew
>>1)):
260 expected
= SelectableInt(to_expect
.pop(0), 64)
262 expected
= SelectableInt(0xffffffff, 64)
263 self
.assertEqual(sim
.gpr(8+skew
), expected
)
265 def run_tst_program(self
, prog
, initial_regs
=None,
268 if initial_regs
is None:
269 initial_regs
= [0] * 32
270 simulator
= run_tst(prog
, initial_regs
, svstate
=svstate
,
271 initial_sprs
=initial_sprs
)
276 if __name__
== "__main__":