rename ternaryi to ternlogi
[openpower-isa.git] / src / openpower / test / bitmanip / bitmanip_cases.py
1 from openpower.test.common import TestAccumulatorBase
2 from openpower.endian import bigendian
3 from openpower.simulator.program import Program
4 from hashlib import sha256
5
6
7 def hash_256(v):
8 return int.from_bytes(
9 sha256(bytes(v, encoding='utf-8')).digest(),
10 byteorder='little'
11 )
12
13
14 class BitManipTestCase(TestAccumulatorBase):
15 def case_ternlogi(self):
16 po = 5
17 rt = 3
18 ra = 4
19 rb = 5
20 rc = 1
21 xo = 0
22 for i in range(100):
23 imm = hash_256(f"ternlogi imm {i}") & 0xFF
24 instr = po
25 instr = (instr << 5) | rt
26 instr = (instr << 5) | ra
27 instr = (instr << 5) | rb
28 instr = (instr << 8) | imm
29 instr = (instr << 2) | xo
30 instr = (instr << 1) | rc
31 lst = [f".4byte {hex(instr)}"]
32 initial_regs = [0] * 32
33 initial_regs[3] = hash_256(f"ternlogi rt {i}") % 2 ** 64
34 initial_regs[4] = hash_256(f"ternlogi ra {i}") % 2 ** 64
35 initial_regs[5] = hash_256(f"ternlogi rb {i}") % 2 ** 64
36 self.add_case(Program(lst, bigendian), initial_regs)