add single regression test for bc_ctr in branch cases
[openpower-isa.git] / src / openpower / test / branch / branch_cases.py
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
5
6 from openpower.test.common import TestAccumulatorBase
7 import random
8
9
10 class BranchTestCase(TestAccumulatorBase):
11
12 def case_0_regression_unconditional(self):
13 for i in range(2):
14 imm = random.randrange(-1 << 23, (1 << 23)-1) * 4
15 lst = [f"bl {imm}"]
16 initial_regs = [0] * 32
17 self.add_case(Program(lst, bigendian), initial_regs)
18
19 def case_unconditional(self):
20 choices = ["b", "ba", "bl", "bla"]
21 for i in range(20):
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)
27
28 def case_bc_cr(self):
29 for i in range(20):
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)
37
38 def case_bc_ctr(self):
39 for i in range(20):
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,
49 initial_cr=cr)
50
51 def case_bc_ctr_regression(self):
52 bc = 13116
53 bo = 8
54 bi = 6
55 cr = 0x100983
56 ctr = 0x420abd56
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,
61 initial_cr=cr)
62
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"]
66 for insn in choices:
67 for i in range(20):
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,
81 initial_cr=cr)
82
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
87 """
88 lst = ["bc 2, 9, 8"]
89 initial_regs = [0] * 32
90 cr = 0x33209703
91 self.add_case(Program(lst, bigendian), initial_regs,
92 initial_cr=cr)
93
94 def case_bc_microwatt_2_regression(self):
95 """modified version, set CTR=1 so that it hits zero in BC
96 """
97 lst = ["bc 2, 9, 8"]
98 initial_regs = [0] * 32
99 cr = 0x33209703
100 ctr = 1
101 initial_sprs = {9: SelectableInt(ctr, 64),
102 }
103 self.add_case(Program(lst, bigendian), initial_regs,
104 initial_sprs=initial_sprs,
105 initial_cr=cr)
106