40a2452a9e351f958053ee7a9d980409e6fdf1fa
1 from openpower
.decoder
.isa
.caller
import special_sprs
2 from openpower
.decoder
.selectable_int
import SelectableInt
3 from openpower
.simulator
.program
import Program
4 from openpower
.endian
import bigendian
6 from openpower
.test
.common
import TestAccumulatorBase
10 class BranchTestCase(TestAccumulatorBase
):
12 def case_0_regression_unconditional(self
):
14 imm
= random
.randrange(-1 << 23, (1 << 23)-1) * 4
16 initial_regs
= [0] * 32
17 self
.add_case(Program(lst
, bigendian
), initial_regs
)
19 def case_unconditional(self
):
20 choices
= ["b", "ba", "bl", "bla"]
22 choice
= random
.choice(choices
)
23 imm
= random
.randrange(-1 << 23, (1 << 23)-1) * 4
24 lst
= [f
"{choice} {imm}"]
25 initial_regs
= [0] * 32
26 self
.add_case(Program(lst
, bigendian
), initial_regs
)
30 bc
= random
.randrange(-1 << 13, (1 << 13)-1) * 4
31 bo
= random
.choice([0b01100, 0b00100, 0b10100])
32 bi
= random
.randrange(0, 31)
33 cr
= random
.randrange(0, (1 << 32)-1)
34 lst
= [f
"bc {bo}, {bi}, {bc}"]
35 initial_regs
= [0] * 32
36 self
.add_case(Program(lst
, bigendian
), initial_cr
=cr
)
38 def case_bc_ctr(self
):
40 bc
= random
.randrange(-1 << 13, (1 << 13)-1) * 4
41 bo
= random
.choice([0, 2, 8, 10, 16, 18])
42 bi
= random
.randrange(0, 31)
43 cr
= random
.randrange(0, (1 << 32)-1)
44 ctr
= random
.randint(0, (1 << 32)-1)
45 lst
= [f
"bc {bo}, {bi}, {bc}"]
46 initial_sprs
= {9: SelectableInt(ctr
, 64)}
47 self
.add_case(Program(lst
, bigendian
),
48 initial_sprs
=initial_sprs
,
51 def case_bc_reg(self
):
52 # XXX: bcctr and bcctrl time out (irony: they're counters)
53 choices
= ["bclr", "bclrl", "bcctr", "bcctrl", "bctar", "bctarl"]
56 bh
= random
.randrange(0, 3)
57 bo
= random
.choice([4, 12])
58 bi
= random
.randrange(0, 31)
59 cr
= random
.randrange(0, (1 << 32)-1)
60 ctr
= random
.randint(0, (1 << 32)-1)
61 lr
= random
.randint(0, (1 << 64)-1) & ~
3
62 tar
= random
.randint(0, (1 << 64)-1) & ~
3
63 lst
= [f
"{insn} {bo}, {bi}, {bh}"]
64 initial_sprs
= {9: SelectableInt(ctr
, 64),
65 8: SelectableInt(lr
, 64),
66 815: SelectableInt(tar
, 64)}
67 self
.add_case(Program(lst
, bigendian
),
68 initial_sprs
=initial_sprs
,
71 def case_bc_microwatt_1_regression(self
):
72 """bc found to be testing ctr rather than (ctr-1)
73 11fb4: 08 00 49 40 bc 2,4*cr2+gt,0x11fbc
74 cr_file.vhdl:83:13:@136835ns:(report note): Reading CR 33209703
77 initial_regs
= [0] * 32
79 self
.add_case(Program(lst
, bigendian
), initial_regs
,
82 def case_bc_microwatt_2_regression(self
):
83 """modified version, set CTR=1 so that it hits zero in BC
86 initial_regs
= [0] * 32
89 initial_sprs
= {9: SelectableInt(ctr
, 64),
91 self
.add_case(Program(lst
, bigendian
), initial_regs
,
92 initial_sprs
=initial_sprs
,