a783551ce8b9cb53c34e209660fbcf164bd0de3b
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
6 _SHIFT_TEST_RANGE
= range(-64, 128, 16)
9 class BigIntCases(TestAccumulatorBase
):
10 def case_maddedu(self
):
11 lst
= list(SVP64Asm(["maddedu 3,5,6,7"]))
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
)
21 def case_divmod2du(self
):
22 lst
= list(SVP64Asm(["divmod2du 3,5,6,7"]))
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
)
33 # FIXME: test more divmod2du special cases
36 prog
= Program(list(SVP64Asm(["dsld 3,4,5,0"])), False)
37 for sh
in _SHIFT_TEST_RANGE
:
38 with self
.subTest(sh
=sh
):
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]
46 e
.intregs
[3] = (v
>> 64) % 2 ** 64
47 self
.add_case(prog
, gprs
, expected
=e
)
50 prog
= Program(list(SVP64Asm(["dsld 3,4,5,1"])), False)
51 for sh
in _SHIFT_TEST_RANGE
:
52 with self
.subTest(sh
=sh
):
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]
60 e
.intregs
[3] = (v
>> 64) % 2 ** 64
61 self
.add_case(prog
, gprs
, expected
=e
)
64 prog
= Program(list(SVP64Asm(["dsld 3,4,5,2"])), False)
65 for sh
in _SHIFT_TEST_RANGE
:
66 with self
.subTest(sh
=sh
):
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]
74 e
.intregs
[3] = (v
>> 64) % 2 ** 64
75 self
.add_case(prog
, gprs
, expected
=e
)
78 prog
= Program(list(SVP64Asm(["dsld 3,4,5,3"])), False)
79 for sh
in _SHIFT_TEST_RANGE
:
80 with self
.subTest(sh
=sh
):
82 gprs
[3] = 0x123456789ABCDEF
83 gprs
[4] = 0xFEDCBA9876543210
84 gprs
[5] = sh
% 2 ** 64
85 e
= ExpectedState(pc
=4, int_regs
=gprs
)
88 e
.intregs
[3] = (v
>> 64) % 2 ** 64
89 self
.add_case(prog
, gprs
, expected
=e
)
92 prog
= Program(list(SVP64Asm(["dsrd 3,4,5,0"])), False)
93 for sh
in _SHIFT_TEST_RANGE
:
94 with self
.subTest(sh
=sh
):
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]
102 e
.intregs
[3] = v
% 2 ** 64
103 self
.add_case(prog
, gprs
, expected
=e
)
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
):
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]
116 e
.intregs
[3] = v
% 2 ** 64
117 self
.add_case(prog
, gprs
, expected
=e
)
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
):
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]
130 e
.intregs
[3] = v
% 2 ** 64
131 self
.add_case(prog
, gprs
, expected
=e
)
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
):
138 gprs
[3] = 0x123456789ABCDEF
139 gprs
[4] = 0xFEDCBA9876543210
140 gprs
[5] = sh
% 2 ** 64
141 e
= ExpectedState(pc
=4, int_regs
=gprs
)
144 e
.intregs
[3] = v
% 2 ** 64
145 self
.add_case(prog
, gprs
, expected
=e
)