pysvp64db: fix traversal
[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 cse_1_regression_negbranch(self):
20 lst = [f"bl -3377317"]
21 initial_regs = [0] * 32
22 self.add_case(Program(lst, bigendian), initial_regs)
23
24 def case_unconditional(self):
25 choices = ["b", "ba", "bl", "bla"]
26 for i in range(20):
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)
32
33 def case_bc_cr(self):
34 for i in range(20):
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)
42
43 def case_bc_ctr(self):
44 for i in range(20):
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,
54 initial_cr=cr)
55
56 def case_bc_ctr_regression(self):
57 bc = 13116
58 bo = 8
59 bi = 6
60 cr = 0x100983
61 ctr = 0x420abd56
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,
66 initial_cr=cr)
67
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"]
71 for insn in choices:
72 for i in range(20):
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,
86 initial_cr=cr)
87
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
92 """
93 lst = ["bc 2, 9, 8"]
94 initial_regs = [0] * 32
95 cr = 0x33209703
96 self.add_case(Program(lst, bigendian), initial_regs,
97 initial_cr=cr)
98
99 def case_bc_microwatt_2_regression(self):
100 """modified version, set CTR=1 so that it hits zero in BC
101 """
102 lst = ["bc 2, 9, 8"]
103 initial_regs = [0] * 32
104 cr = 0x33209703
105 ctr = 1
106 initial_sprs = {9: SelectableInt(ctr, 64),
107 }
108 self.add_case(Program(lst, bigendian), initial_regs,
109 initial_sprs=initial_sprs,
110 initial_cr=cr)
111