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 from openpower
.decoder
.isa
.caller
import SVP64State
7 _SHIFT_TEST_RANGE
= list(range(-64, 128, 16)) + [1, 63]
10 class BigIntCases(TestAccumulatorBase
):
11 def case_maddedu(self
):
12 lst
= list(SVP64Asm(["maddedu 3,5,6,7"]))
14 gprs
[5] = 0x123456789ABCDEF
15 gprs
[6] = 0xFEDCBA9876543210
16 gprs
[7] = 0x02468ACE13579BDF
17 e
= ExpectedState(pc
=4, int_regs
=gprs
)
18 e
.intregs
[3] = (gprs
[5] * gprs
[6] + gprs
[7]) % 2 ** 64
19 e
.intregs
[7] = (gprs
[5] * gprs
[6] + gprs
[7]) >> 64
20 self
.add_case(Program(lst
, False), gprs
, expected
=e
)
22 def case_divmod2du(self
):
23 lst
= list(SVP64Asm(["divmod2du 3,5,6,7"]))
25 gprs
[5] = 0x123456789ABCDEF
26 gprs
[6] = 0xFEDCBA9876543210
27 gprs
[7] = 0x02468ACE13579BDF
28 e
= ExpectedState(pc
=4, int_regs
=gprs
)
29 v
= gprs
[5] |
(gprs
[7] << 64)
30 e
.intregs
[3] = v
// gprs
[6]
31 e
.intregs
[7] = v
% gprs
[6]
32 self
.add_case(Program(lst
, False), gprs
, expected
=e
)
34 # FIXME: test more divmod2du special cases
37 prog
= Program(list(SVP64Asm(["dsld 3,4,5,6"])), False)
38 for sh
in _SHIFT_TEST_RANGE
:
39 with self
.subTest(sh
=sh
):
41 gprs
[6] = 0x123456789ABCDEF
42 gprs
[4] = 0xFEDCBA9876543210
43 gprs
[5] = sh
% 2 ** 64
44 e
= ExpectedState(pc
=4, int_regs
=gprs
)
49 e
.intregs
[3] = v
% 2 ** 64
50 e
.intregs
[6] = (v
>> 64) % 2 ** 64
51 self
.add_case(prog
, gprs
, expected
=e
)
54 prog
= Program(list(SVP64Asm(["dsrd 3,4,5,6"])), False)
55 for sh
in _SHIFT_TEST_RANGE
:
56 with self
.subTest(sh
=sh
):
58 gprs
[6] = 0x123456789ABCDEF
59 gprs
[4] = 0xFEDCBA9876543210
60 gprs
[5] = sh
% 2 ** 64
61 e
= ExpectedState(pc
=4, int_regs
=gprs
)
64 mask
= ~
((2 ** 64 - 1) >> (sh
%64))
66 print ("case_dsrd0", hex(mask
), sh
, hex(v
))
67 e
.intregs
[3] = v
% 2 ** 64
68 e
.intregs
[6] = (v
>> 64) % 2 ** 64
69 self
.add_case(prog
, gprs
, expected
=e
)
72 class SVP64BigIntCases(TestAccumulatorBase
):
73 def case_sv_bigint_add(self
):
74 """performs a carry-rollover-vector-add aka "big integer vector add"
75 this is remarkably simple, each sv.adde uses and produces a CA which
76 goes into the next sv.adde. arbitrary size is possible (1024+) as
77 is looping using the CA bit from one sv.adde on another batch to do
78 unlimited-size biginteger add.
80 r19/r18: 0x0000_0000_0000_0001 0xffff_ffff_ffff_ffff +
81 r21/r20: 0x8000_0000_0000_0000 0x0000_0000_0000_0001 =
82 r17/r16: 0x8000_0000_0000_0002 0x0000_0000_0000_0000
84 prog
= Program(list(SVP64Asm(["sv.adde *16, *18, *20"])), False)
86 gprs
[18] = 0xffff_ffff_ffff_ffff
87 gprs
[19] = 0x0000_0000_0000_0001
88 gprs
[20] = 0x0000_0000_0000_0001
89 gprs
[21] = 0x8000_0000_0000_0000
90 svstate
= SVP64State()
93 e
= ExpectedState(pc
=8, int_regs
=gprs
)
94 e
.intregs
[16] = 0x0000_0000_0000_0000
95 e
.intregs
[17] = 0x8000_0000_0000_0002
96 self
.add_case(prog
, gprs
, expected
=e
, initial_svstate
=svstate
)
98 def case_sv_bigint_shift_right_by_scalar(self
):
99 """performs a bigint shift-right by scalar.
102 0x0000_0000_5000_0002 0x8000_8000_8000_8001 0xffff_ffff_ffff_ffff >> 4
103 0x0000_0000_0500_0000 0x2800_0800_0800_0800 0x1fff_ffff_ffff_ffff
105 prog
= Program(list(SVP64Asm(["sv.dsrd *16,*17,3,1"])), False)
107 gprs
[16] = 0xffff_ffff_ffff_ffff
108 gprs
[17] = 0x8000_8000_8000_8001
109 gprs
[18] = 0x0000_0000_5000_0002
111 svstate
= SVP64State()
114 e
= ExpectedState(pc
=8, int_regs
=gprs
)
115 e
.intregs
[16] = 0x1fff_ffff_ffff_ffff
116 e
.intregs
[17] = 0x2800_0800_0800_0800
117 e
.intregs
[18] = 0x0000_0000_0500_0000
118 self
.add_case(prog
, gprs
, expected
=e
, initial_svstate
=svstate
)
120 def case_sv_bigint_shift_left_by_scalar(self
):
121 """performs a bigint shift-left by scalar.
123 because the result is moved down by one register there is no need
126 r18 is *not* modified (contains its original value).
128 0x0000_0000_0001_0002 0x3fff_ffff_ffff_ffff 0x4000_0000_0000_0001 << 4
130 0x0000_0000_0010_0023 0xffff_ffff_ffff_fff4 0x0000_0000_0000_0010
132 prog
= Program(list(SVP64Asm(["sv.dsld *15,*16,3,1"])), False)
135 gprs
[16] = 0x4000_0000_0000_0001
136 gprs
[17] = 0x3fff_ffff_ffff_ffff
137 gprs
[18] = 0x0000_0000_0001_0002
139 svstate
= SVP64State()
142 e
= ExpectedState(pc
=8, int_regs
=gprs
)
143 e
.intregs
[15] = 0x0000_0000_0000_0010
144 e
.intregs
[16] = 0xffff_ffff_ffff_fff4
145 e
.intregs
[17] = 0x0000_0000_0010_0023
146 self
.add_case(prog
, gprs
, expected
=e
, initial_svstate
=svstate
)
148 def case_sv_bigint_mul_by_scalar(self
):
149 """performs a carry-rollover-vector-mul-with-add with a scalar,
150 using "RC" as a 64-bit carry in/out. matched with the
154 0x1234_0000_5678_0000 0x9ABC_0000_DEF0_0000 0x1357_0000_9BDF_0000 *
155 r3 (scalar factor) 0x1_0001 +
156 r4 (carry in) 0xFEDC =
158 0x1234_5678_5678_9ABC 0x9ABC_DEF0_DEF0_1357 0x1357_9BDF_9BDF_FEDC
159 r4 (carry out) 0x1234
161 prog
= Program(list(SVP64Asm(["sv.maddedu *16,*16,3,4"])), False)
163 gprs
[16] = 0x1357_0000_9BDF_0000 # vector...
164 gprs
[17] = 0x9ABC_0000_DEF0_0000 # ...
165 gprs
[18] = 0x1234_0000_5678_0000 # ... input
166 gprs
[3] = 0x1_0001 # scalar multiplier
167 gprs
[4] = 0xFEDC # 64-bit carry-in
168 svstate
= SVP64State()
171 e
= ExpectedState(pc
=8, int_regs
=gprs
)
172 e
.intregs
[16] = 0x1357_9BDF_9BDF_FEDC # vector...
173 e
.intregs
[17] = 0x9ABC_DEF0_DEF0_1357 # ...
174 e
.intregs
[18] = 0x1234_5678_5678_9ABC # ... result
175 e
.intregs
[4] = 0x1234 # 64-bit carry-out
176 self
.add_case(prog
, gprs
, expected
=e
, initial_svstate
=svstate
)
178 def case_sv_bigint_scalar_maddedu(self
):
179 prog
= Program(list(SVP64Asm(["sv.maddedu 6,5,3,4"])), False)
181 gprs
[5] = 0x1357_0000_9BDF_0000 # scalar input
182 gprs
[3] = 0x1_0001 # scalar multiplier
183 gprs
[4] = 0xFEDC # 64-bit carry-in
184 svstate
= SVP64State()
185 svstate
.vl
= 16 # detect writing to RT+MAXVL or RT+1 rather than RC
187 e
= ExpectedState(pc
=8, int_regs
=gprs
)
188 e
.intregs
[6] = 0x1357_9BDF_9BDF_FEDC # scalar output
189 e
.intregs
[4] = 0x1357 # 64-bit carry-out
190 self
.add_case(prog
, gprs
, expected
=e
, initial_svstate
=svstate
)
192 def case_sv_bigint_div_by_scalar(self
):
193 """performs a carry-rollover-vector-divmod with a scalar,
194 using "RC" as a 64-bit carry. matched with the sv.maddedu
195 above it is effectively the scalar-vector inverse
198 0x1234_5678_5678_9ABC 0x9ABC_DEF0_DEF0_1357 0x1357_9BDF_9BDF_FEDC /
199 r3 (scalar factor) 0x1_0001 +
200 r4 (carry in at top-end) 0x1234 << 192 =
202 0x1234_0000_5678_0000 0x9ABC_0000_DEF0_0000 0x1357_0000_9BDF_0000 *
203 r4 (carry out i.e. scalar remainder) 0xFEDC
205 prog
= Program(list(SVP64Asm(["sv.divmod2du/mrr *16,*16,3,4"])), False)
207 gprs
[16] = 0x1357_9BDF_9BDF_FEDC # vector...
208 gprs
[17] = 0x9ABC_DEF0_DEF0_1357 # ...
209 gprs
[18] = 0x1234_5678_5678_9ABC # ... input
210 gprs
[3] = 0x1_0001 # scalar multiplier
211 gprs
[4] = 0x1234 # 64-bit carry-in
212 svstate
= SVP64State()
215 e
= ExpectedState(pc
=8, int_regs
=gprs
)
216 e
.intregs
[16] = 0x1357_0000_9BDF_0000 # vector...
217 e
.intregs
[17] = 0x9ABC_0000_DEF0_0000 # ...
218 e
.intregs
[18] = 0x1234_0000_5678_0000 # ... result
219 e
.intregs
[4] = 0xFEDC # 64-bit carry-out
220 self
.add_case(prog
, gprs
, expected
=e
, initial_svstate
=svstate
)