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_ctr_regression(self
):
57 lst
= [f
"bc {bo}, {bi}, {bc}"]
58 initial_sprs
= {9: SelectableInt(ctr
, 64)}
59 self
.add_case(Program(lst
, bigendian
),
60 initial_sprs
=initial_sprs
,
63 def case_bc_reg(self
):
64 # XXX: bcctr and bcctrl time out (irony: they're counters)
65 choices
= ["bclr", "bclrl", "bcctr", "bcctrl", "bctar", "bctarl"]
68 bh
= random
.randrange(0, 3)
69 bo
= random
.choice([4, 12])
70 bi
= random
.randrange(0, 31)
71 cr
= random
.randrange(0, (1 << 32)-1)
72 ctr
= random
.randint(0, (1 << 32)-1)
73 lr
= random
.randint(0, (1 << 64)-1) & ~
3
74 tar
= random
.randint(0, (1 << 64)-1) & ~
3
75 lst
= [f
"{insn} {bo}, {bi}, {bh}"]
76 initial_sprs
= {9: SelectableInt(ctr
, 64),
77 8: SelectableInt(lr
, 64),
78 815: SelectableInt(tar
, 64)}
79 self
.add_case(Program(lst
, bigendian
),
80 initial_sprs
=initial_sprs
,
83 def case_bc_microwatt_1_regression(self
):
84 """bc found to be testing ctr rather than (ctr-1)
85 11fb4: 08 00 49 40 bc 2,4*cr2+gt,0x11fbc
86 cr_file.vhdl:83:13:@136835ns:(report note): Reading CR 33209703
89 initial_regs
= [0] * 32
91 self
.add_case(Program(lst
, bigendian
), initial_regs
,
94 def case_bc_microwatt_2_regression(self
):
95 """modified version, set CTR=1 so that it hits zero in BC
98 initial_regs
= [0] * 32
101 initial_sprs
= {9: SelectableInt(ctr
, 64),
103 self
.add_case(Program(lst
, bigendian
), initial_regs
,
104 initial_sprs
=initial_sprs
,