a783551ce8b9cb53c34e209660fbcf164bd0de3b
[openpower-isa.git] / src / openpower / test / bigint / bigint_cases.py
1 from openpower.test.common import TestAccumulatorBase, skip_case
2 from openpower.sv.trans.svp64 import SVP64Asm
3 from openpower.test.state import ExpectedState
4 from openpower.simulator.program import Program
5
6 _SHIFT_TEST_RANGE = range(-64, 128, 16)
7
8
9 class BigIntCases(TestAccumulatorBase):
10 def case_maddedu(self):
11 lst = list(SVP64Asm(["maddedu 3,5,6,7"]))
12 gprs = [0] * 32
13 gprs[5] = 0x123456789ABCDEF
14 gprs[6] = 0xFEDCBA9876543210
15 gprs[7] = 0x02468ACE13579BDF
16 e = ExpectedState(pc=4, int_regs=gprs)
17 e.intregs[3] = (gprs[5] * gprs[6] + gprs[7]) % 2 ** 64
18 e.intregs[7] = (gprs[5] * gprs[6] + gprs[7]) >> 64
19 self.add_case(Program(lst, False), gprs, expected=e)
20
21 def case_divmod2du(self):
22 lst = list(SVP64Asm(["divmod2du 3,5,6,7"]))
23 gprs = [0] * 32
24 gprs[5] = 0x123456789ABCDEF
25 gprs[6] = 0xFEDCBA9876543210
26 gprs[7] = 0x02468ACE13579BDF
27 e = ExpectedState(pc=4, int_regs=gprs)
28 v = gprs[5] | (gprs[7] << 64)
29 e.intregs[3] = v // gprs[6]
30 e.intregs[7] = v % gprs[6]
31 self.add_case(Program(lst, False), gprs, expected=e)
32
33 # FIXME: test more divmod2du special cases
34
35 def case_dsld0(self):
36 prog = Program(list(SVP64Asm(["dsld 3,4,5,0"])), False)
37 for sh in _SHIFT_TEST_RANGE:
38 with self.subTest(sh=sh):
39 gprs = [0] * 32
40 gprs[3] = 0x123456789ABCDEF
41 gprs[4] = 0xFEDCBA9876543210
42 gprs[5] = sh % 2 ** 64
43 e = ExpectedState(pc=4, int_regs=gprs)
44 v = (gprs[3] << 64) | gprs[4]
45 v <<= sh % 64
46 e.intregs[3] = (v >> 64) % 2 ** 64
47 self.add_case(prog, gprs, expected=e)
48
49 def case_dsld1(self):
50 prog = Program(list(SVP64Asm(["dsld 3,4,5,1"])), False)
51 for sh in _SHIFT_TEST_RANGE:
52 with self.subTest(sh=sh):
53 gprs = [0] * 32
54 gprs[3] = 0x123456789ABCDEF
55 gprs[4] = 0xFEDCBA9876543210
56 gprs[5] = sh % 2 ** 64
57 e = ExpectedState(pc=4, int_regs=gprs)
58 v = (gprs[4] << 64) | gprs[3]
59 v <<= sh % 64
60 e.intregs[3] = (v >> 64) % 2 ** 64
61 self.add_case(prog, gprs, expected=e)
62
63 def case_dsld2(self):
64 prog = Program(list(SVP64Asm(["dsld 3,4,5,2"])), False)
65 for sh in _SHIFT_TEST_RANGE:
66 with self.subTest(sh=sh):
67 gprs = [0] * 32
68 gprs[3] = sh % 2 ** 64
69 gprs[4] = 0xFEDCBA9876543210
70 gprs[5] = 0x02468ACE13579BDF
71 e = ExpectedState(pc=4, int_regs=gprs)
72 v = (gprs[4] << 64) | gprs[5]
73 v <<= sh % 64
74 e.intregs[3] = (v >> 64) % 2 ** 64
75 self.add_case(prog, gprs, expected=e)
76
77 def case_dsld3(self):
78 prog = Program(list(SVP64Asm(["dsld 3,4,5,3"])), False)
79 for sh in _SHIFT_TEST_RANGE:
80 with self.subTest(sh=sh):
81 gprs = [0] * 32
82 gprs[3] = 0x123456789ABCDEF
83 gprs[4] = 0xFEDCBA9876543210
84 gprs[5] = sh % 2 ** 64
85 e = ExpectedState(pc=4, int_regs=gprs)
86 v = gprs[4]
87 v <<= sh % 64
88 e.intregs[3] = (v >> 64) % 2 ** 64
89 self.add_case(prog, gprs, expected=e)
90
91 def case_dsrd0(self):
92 prog = Program(list(SVP64Asm(["dsrd 3,4,5,0"])), False)
93 for sh in _SHIFT_TEST_RANGE:
94 with self.subTest(sh=sh):
95 gprs = [0] * 32
96 gprs[3] = 0x123456789ABCDEF
97 gprs[4] = 0xFEDCBA9876543210
98 gprs[5] = sh % 2 ** 64
99 e = ExpectedState(pc=4, int_regs=gprs)
100 v = (gprs[3] << 64) | gprs[4]
101 v >>= sh % 64
102 e.intregs[3] = v % 2 ** 64
103 self.add_case(prog, gprs, expected=e)
104
105 def case_dsrd1(self):
106 prog = Program(list(SVP64Asm(["dsrd 3,4,5,1"])), False)
107 for sh in _SHIFT_TEST_RANGE:
108 with self.subTest(sh=sh):
109 gprs = [0] * 32
110 gprs[3] = 0x123456789ABCDEF
111 gprs[4] = 0xFEDCBA9876543210
112 gprs[5] = sh % 2 ** 64
113 e = ExpectedState(pc=4, int_regs=gprs)
114 v = (gprs[4] << 64) | gprs[3]
115 v >>= sh % 64
116 e.intregs[3] = v % 2 ** 64
117 self.add_case(prog, gprs, expected=e)
118
119 def case_dsrd2(self):
120 prog = Program(list(SVP64Asm(["dsrd 3,4,5,2"])), False)
121 for sh in _SHIFT_TEST_RANGE:
122 with self.subTest(sh=sh):
123 gprs = [0] * 32
124 gprs[3] = sh % 2 ** 64
125 gprs[4] = 0xFEDCBA9876543210
126 gprs[5] = 0x02468ACE13579BDF
127 e = ExpectedState(pc=4, int_regs=gprs)
128 v = (gprs[4] << 64) | gprs[5]
129 v >>= sh % 64
130 e.intregs[3] = v % 2 ** 64
131 self.add_case(prog, gprs, expected=e)
132
133 def case_dsrd3(self):
134 prog = Program(list(SVP64Asm(["dsrd 3,4,5,3"])), False)
135 for sh in _SHIFT_TEST_RANGE:
136 with self.subTest(sh=sh):
137 gprs = [0] * 32
138 gprs[3] = 0x123456789ABCDEF
139 gprs[4] = 0xFEDCBA9876543210
140 gprs[5] = sh % 2 ** 64
141 e = ExpectedState(pc=4, int_regs=gprs)
142 v = gprs[4] << 64
143 v >>= sh % 64
144 e.intregs[3] = v % 2 ** 64
145 self.add_case(prog, gprs, expected=e)