2 from openpower
.simulator
.program
import Program
3 from openpower
.endian
import bigendian
4 from openpower
.test
.common
import TestAccumulatorBase
8 class LogicalTestCase(TestAccumulatorBase
):
10 def case_complement(self
):
11 insns
= ["andc", "orc", "nand", "nor"]
13 choice
= random
.choice(insns
)
14 lst
= [f
"{choice} 3, 1, 2"]
15 initial_regs
= [0] * 32
16 initial_regs
[1] = random
.randint(0, (1 << 64)-1)
17 initial_regs
[2] = random
.randint(0, (1 << 64)-1)
18 self
.add_case(Program(lst
, bigendian
), initial_regs
)
21 insns
= ["and", "or", "xor", "eqv"]
23 choice
= random
.choice(insns
)
24 lst
= [f
"{choice} 3, 1, 2"]
25 initial_regs
= [0] * 32
26 initial_regs
[1] = random
.randint(0, (1 << 64)-1)
27 initial_regs
[2] = random
.randint(0, (1 << 64)-1)
28 self
.add_case(Program(lst
, bigendian
), initial_regs
)
31 insns
= ["and.", "or.", "xor.", "eqv.", "andc.",
32 "orc.", "nand.", "nor."]
33 for XER
in [0, 0xe00c0000]:
35 choice
= random
.choice(insns
)
36 lst
= [f
"{choice} 3, 1, 2"]
37 initial_regs
= [0] * 32
38 initial_regs
[1] = random
.randint(0, (1 << 64)-1)
39 initial_regs
[2] = random
.randint(0, (1 << 64)-1)
40 self
.add_case(Program(lst
, bigendian
), initial_regs
,
41 initial_sprs
= {'XER': XER
})
43 def case_rand_imm_so(self
):
44 insns
= ["andi.", "andis."]
46 choice
= random
.choice(insns
)
47 imm
= random
.randint(0, (1 << 16)-1)
48 lst
= [f
"{choice} 3, 1, {imm}"]
50 initial_regs
= [0] * 32
51 initial_regs
[1] = random
.randint(0, (1 << 64)-1)
52 initial_sprs
= {'XER': 0xe00c0000}
54 self
.add_case(Program(lst
, bigendian
), initial_regs
,
55 initial_sprs
=initial_sprs
)
57 def case_rand_imm_logical(self
):
58 insns
= ["andi.", "andis.", "ori", "oris", "xori", "xoris"]
60 choice
= random
.choice(insns
)
61 imm
= random
.randint(0, (1 << 16)-1)
62 lst
= [f
"{choice} 3, 1, {imm}"]
64 initial_regs
= [0] * 32
65 initial_regs
[1] = random
.randint(0, (1 << 64)-1)
66 self
.add_case(Program(lst
, bigendian
), initial_regs
)
69 insns
= ["cntlzd", "cnttzd", "cntlzw", "cnttzw"]
71 choice
= random
.choice(insns
)
72 lst
= [f
"{choice} 3, 1"]
74 initial_regs
= [0] * 32
75 initial_regs
[1] = random
.randint(0, (1 << 64)-1)
76 self
.add_case(Program(lst
, bigendian
), initial_regs
)
78 def case_parity(self
):
79 insns
= ["prtyw", "prtyd"]
81 choice
= random
.choice(insns
)
82 lst
= [f
"{choice} 3, 1"]
84 initial_regs
= [0] * 32
85 initial_regs
[1] = random
.randint(0, (1 << 64)-1)
86 self
.add_case(Program(lst
, bigendian
), initial_regs
)
88 def case_popcnt(self
):
89 insns
= ["popcntb", "popcntw", "popcntd"]
91 choice
= random
.choice(insns
)
92 lst
= [f
"{choice} 3, 1"]
94 initial_regs
= [0] * 32
95 initial_regs
[1] = random
.randint(0, (1 << 64)-1)
96 self
.add_case(Program(lst
, bigendian
), initial_regs
)
98 def case_popcnt_edge(self
):
99 insns
= ["popcntb", "popcntw", "popcntd"]
101 lst
= [f
"{choice} 3, 1"]
102 initial_regs
= [0] * 32
104 self
.add_case(Program(lst
, bigendian
), initial_regs
)
107 lst
= ["cmpb 3, 1, 2"]
108 initial_regs
= [0] * 32
109 initial_regs
[1] = 0xdeadbeefcafec0de
110 initial_regs
[2] = 0xd0adb0000afec1de
111 self
.add_case(Program(lst
, bigendian
), initial_regs
)
113 def case_bpermd(self
):
114 lst
= ["bpermd 3, 1, 2"]
116 initial_regs
= [0] * 32
117 initial_regs
[1] = 1 << random
.randint(0, 63)
118 initial_regs
[2] = 0xdeadbeefcafec0de
119 self
.add_case(Program(lst
, bigendian
), initial_regs
)