From 309b35ee91f1ad6448379a1d804c304dd9681396 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Wed, 17 Nov 2021 12:50:50 -0800 Subject: [PATCH] add bitmanip_cases.py --- src/openpower/test/bitmanip/__init__.py | 0 src/openpower/test/bitmanip/bitmanip_cases.py | 36 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/openpower/test/bitmanip/__init__.py create mode 100644 src/openpower/test/bitmanip/bitmanip_cases.py diff --git a/src/openpower/test/bitmanip/__init__.py b/src/openpower/test/bitmanip/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/openpower/test/bitmanip/bitmanip_cases.py b/src/openpower/test/bitmanip/bitmanip_cases.py new file mode 100644 index 00000000..e741ddce --- /dev/null +++ b/src/openpower/test/bitmanip/bitmanip_cases.py @@ -0,0 +1,36 @@ +from openpower.test.common import TestAccumulatorBase +from openpower.endian import bigendian +from openpower.simulator.program import Program +from hashlib import sha256 + + +def hash_256(v): + return int.from_bytes( + sha256(bytes(v, encoding='utf-8')).digest(), + byteorder='little' + ) + + +class BitManipTestCase(TestAccumulatorBase): + def case_ternaryi(self): + po = 5 + rt = 3 + ra = 4 + rb = 5 + rc = 1 + xo = 0 + for i in range(100): + imm = hash_256(f"ternaryi imm {i}") & 0xFF + instr = po + instr = (instr << 5) | rt + instr = (instr << 5) | ra + instr = (instr << 5) | rb + instr = (instr << 8) | imm + instr = (instr << 2) | xo + instr = (instr << 1) | rc + lst = [f".4byte {hex(instr)}"] + initial_regs = [0] * 32 + initial_regs[3] = hash_256(f"ternaryi rt {i}") % 2 ** 64 + initial_regs[4] = hash_256(f"ternaryi ra {i}") % 2 ** 64 + initial_regs[5] = hash_256(f"ternaryi rb {i}") % 2 ** 64 + self.add_case(Program(lst, bigendian), initial_regs) -- 2.30.2