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 cse_1_regression_negbranch(self
):
20 lst
= [f
"bl -3377317"]
21 initial_regs
= [0] * 32
22 self
.add_case(Program(lst
, bigendian
), initial_regs
)
24 def case_unconditional(self
):
25 choices
= ["b", "ba", "bl", "bla"]
27 choice
= random
.choice(choices
)
28 imm
= random
.randrange(-1 << 23, (1 << 23)-1) * 4
29 lst
= [f
"{choice} {imm}"]
30 initial_regs
= [0] * 32
31 self
.add_case(Program(lst
, bigendian
), initial_regs
)
35 bc
= random
.randrange(-1 << 13, (1 << 13)-1) * 4
36 bo
= random
.choice([0b01100, 0b00100, 0b10100])
37 bi
= random
.randrange(0, 31)
38 cr
= random
.randrange(0, (1 << 32)-1)
39 lst
= [f
"bc {bo}, {bi}, {bc}"]
40 initial_regs
= [0] * 32
41 self
.add_case(Program(lst
, bigendian
), initial_cr
=cr
)
43 def case_bc_ctr(self
):
45 bc
= random
.randrange(-1 << 13, (1 << 13)-1) * 4
46 bo
= random
.choice([0, 2, 8, 10, 16, 18])
47 bi
= random
.randrange(0, 31)
48 cr
= random
.randrange(0, (1 << 32)-1)
49 ctr
= random
.randint(0, (1 << 32)-1)
50 lst
= [f
"bc {bo}, {bi}, {bc}"]
51 initial_sprs
= {9: SelectableInt(ctr
, 64)}
52 self
.add_case(Program(lst
, bigendian
),
53 initial_sprs
=initial_sprs
,
56 def case_bc_ctr_regression(self
):
62 lst
= [f
"bc {bo}, {bi}, {bc}"]
63 initial_sprs
= {9: SelectableInt(ctr
, 64)}
64 self
.add_case(Program(lst
, bigendian
),
65 initial_sprs
=initial_sprs
,
68 def case_bc_reg(self
):
69 # XXX: bcctr and bcctrl time out (irony: they're counters)
70 choices
= ["bclr", "bclrl", "bcctr", "bcctrl", "bctar", "bctarl"]
73 bh
= random
.randrange(0, 3)
74 bo
= random
.choice([4, 12])
75 bi
= random
.randrange(0, 31)
76 cr
= random
.randrange(0, (1 << 32)-1)
77 ctr
= random
.randint(0, (1 << 32)-1)
78 lr
= random
.randint(0, (1 << 64)-1) & ~
3
79 tar
= random
.randint(0, (1 << 64)-1) & ~
3
80 lst
= [f
"{insn} {bo}, {bi}, {bh}"]
81 initial_sprs
= {9: SelectableInt(ctr
, 64),
82 8: SelectableInt(lr
, 64),
83 815: SelectableInt(tar
, 64)}
84 self
.add_case(Program(lst
, bigendian
),
85 initial_sprs
=initial_sprs
,
88 def case_bc_microwatt_1_regression(self
):
89 """bc found to be testing ctr rather than (ctr-1)
90 11fb4: 08 00 49 40 bc 2,4*cr2+gt,0x11fbc
91 cr_file.vhdl:83:13:@136835ns:(report note): Reading CR 33209703
94 initial_regs
= [0] * 32
96 self
.add_case(Program(lst
, bigendian
), initial_regs
,
99 def case_bc_microwatt_2_regression(self
):
100 """modified version, set CTR=1 so that it hits zero in BC
103 initial_regs
= [0] * 32
106 initial_sprs
= {9: SelectableInt(ctr
, 64),
108 self
.add_case(Program(lst
, bigendian
), initial_regs
,
109 initial_sprs
=initial_sprs
,