2 from soc
.fu
.mul
.test
.helper
import MulTestHelper
3 from openpower
.simulator
.program
import Program
4 from soc
.config
.endian
import bigendian
5 from openpower
.test
.common
import (TestAccumulatorBase
)
9 class MulTestCases2Arg(TestAccumulatorBase
):
25 0xFFFF_FFFF_FFFF_FFFF,
26 0xFFFF_FFFF_FFFF_FFFE,
27 0x7FFF_FFFF_FFFF_FFFF,
28 0x8000_0000_0000_0000,
29 0x1234_5678_0000_0000,
30 0x1234_5678_8000_0000,
31 0x1234_5678_FFFF_FFFF,
32 0x1234_5678_7FFF_FFFF,
41 l
= [f
"{instr} 3, 1, 2"]
42 # use "with" so as to close the files used
43 with
Program(l
, bigendian
) as prog
:
44 for ra
in test_values
:
45 for rb
in test_values
:
46 initial_regs
= [0] * 32
49 self
.add_case(prog
, initial_regs
)
51 def case_all_rb_randint(self
):
66 0xFFFF_FFFF_FFFF_FFFF,
67 0xFFFF_FFFF_FFFF_FFFE,
68 0x7FFF_FFFF_FFFF_FFFF,
69 0x8000_0000_0000_0000,
70 0x1234_5678_0000_0000,
71 0x1234_5678_8000_0000,
72 0x1234_5678_FFFF_FFFF,
73 0x1234_5678_7FFF_FFFF,
82 l
= [f
"{instr} 3, 1, 2"]
83 # use "with" so as to close the files used
84 with
Program(l
, bigendian
) as prog
:
85 for ra
in test_values
:
86 initial_regs
= [0] * 32
88 initial_regs
[2] = random
.randint(0, (1 << 64)-1)
89 self
.add_case(prog
, initial_regs
)
91 def case_all_rb_close_to_ov(self
):
106 0xFFFF_FFFF_FFFF_FFFF,
107 0xFFFF_FFFF_FFFF_FFFE,
108 0x7FFF_FFFF_FFFF_FFFF,
109 0x8000_0000_0000_0000,
110 0x1234_5678_0000_0000,
111 0x1234_5678_8000_0000,
112 0x1234_5678_FFFF_FFFF,
113 0x1234_5678_7FFF_FFFF,
122 l
= [f
"{instr} 3, 1, 2"]
123 # use "with" so as to close the files used
124 with
Program(l
, bigendian
) as prog
:
126 x
= 0x7fffffff + random
.randint((-1 << 31), (1 << 31) - 1)
127 ra
= random
.randint(0, (1 << 32)-1)
130 initial_regs
= [0] * 32
133 self
.add_case(prog
, initial_regs
)
135 def case_mulli(self
):
137 imm_values
= [-32768, -32767, -32766, -2, -1, 0, 1, 2, 32766, 32767]
143 0xFFFF_FFFF_FFFF_FFFF,
144 0xFFFF_FFFF_FFFF_FFFE,
145 0x7FFF_FFFF_FFFF_FFFF,
146 0x8000_0000_0000_0000,
147 0x1234_5678_0000_0000,
148 0x1234_5678_8000_0000,
149 0x1234_5678_FFFF_FFFF,
150 0x1234_5678_7FFF_FFFF,
159 imm_values
.append(random
.randint(-1 << 15, (1 << 15) - 1))
162 ra_values
.append(random
.randint(0, (1 << 64) - 1))
164 for imm
in imm_values
:
165 l
= [f
"mulli 0, 1, {imm}"]
166 # use "with" so as to close the files used
167 with
Program(l
, bigendian
) as prog
:
169 initial_regs
= [0] * 32
171 self
.add_case(prog
, initial_regs
)
174 MUL_3_ARG_TEST_VALUES
= [
178 0xFFFF_FFFF_FFFF_FFFF,
179 0xFFFF_FFFF_FFFF_FFFE,
180 0x7FFF_FFFF_FFFF_FFFF,
181 0x8000_0000_0000_0000,
182 0x1234_5678_0000_0000,
183 0x1234_5678_8000_0000,
184 0x1234_5678_FFFF_FFFF,
185 0x1234_5678_7FFF_FFFF,
194 class MulTestCases3Arg(TestAccumulatorBase
):
195 def __init__(self
, subtest_index
):
196 self
.subtest_index
= subtest_index
200 instrs
= ["maddhd", "maddhdu", "maddld"]
203 l
= [f
"{instr} 1, 2, 3, 4"]
204 ra
= MUL_3_ARG_TEST_VALUES
[self
.subtest_index
]
205 for rb
in MUL_3_ARG_TEST_VALUES
:
206 for rc
in MUL_3_ARG_TEST_VALUES
:
207 initial_regs
= [0] * 32
211 # use "with" so as to close the files used
212 with
Program(l
, bigendian
) as prog
:
213 self
.add_case(prog
, initial_regs
)
216 class TestPipeLong(MulTestHelper
):
217 def test_mul_pipe_2_arg(self
):
218 self
.run_all(MulTestCases2Arg().test_data
, "mul_pipe_caller_long_2_arg",
219 has_third_input
=False)
221 def helper_3_arg(self
, subtest_index
):
222 self
.run_all(MulTestCases3Arg(subtest_index
).test_data
,
223 f
"mul_pipe_caller_long_3_arg_{subtest_index}",
224 has_third_input
=True)
226 # split out as separate functions so some test
227 # runners can test them all in parallel
228 def test_mul_pipe_3_arg_0(self
):
231 def test_mul_pipe_3_arg_1(self
):
234 def test_mul_pipe_3_arg_2(self
):
237 def test_mul_pipe_3_arg_3(self
):
240 def test_mul_pipe_3_arg_4(self
):
243 def test_mul_pipe_3_arg_5(self
):
246 def test_mul_pipe_3_arg_6(self
):
249 def test_mul_pipe_3_arg_7(self
):
252 def test_mul_pipe_3_arg_8(self
):
255 def test_mul_pipe_3_arg_9(self
):
258 def test_mul_pipe_3_arg_10(self
):
259 self
.helper_3_arg(10)
261 def test_mul_pipe_3_arg_11(self
):
262 self
.helper_3_arg(11)
264 def test_mul_pipe_3_arg_12(self
):
265 self
.helper_3_arg(12)
267 def test_mul_pipe_3_arg_13(self
):
268 self
.helper_3_arg(13)
270 def test_mul_pipe_3_arg_14(self
):
271 self
.helper_3_arg(14)
273 def test_mul_pipe_3_arg_15(self
):
274 self
.helper_3_arg(15)
276 def test_all_values_covered(self
):
277 count
= len(MUL_3_ARG_TEST_VALUES
)
278 for i
in range(count
):
279 getattr(self
, f
"test_mul_pipe_3_arg_{i}")
280 with self
.assertRaises(AttributeError):
281 getattr(self
, f
"test_mul_pipe_3_arg_{count}")
284 if __name__
== "__main__":