Commit | Line | Data |
---|---|---|
702d582e PG |
1 | /* Tests instructions l.add, l.addc, l.addi and l.addic. |
2 | ||
b811d2c2 | 3 | Copyright (C) 2017-2020 Free Software Foundation, Inc. |
702d582e PG |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
18 | # mach: or1k | |
19 | # output: report(0x00000001);\n | |
20 | # output: report(0x00000002);\n | |
21 | # output: report(0x00000003);\n | |
22 | # output: report(0x00000000);\n | |
23 | # output: report(0x00000000);\n | |
24 | # output: report(0x00000000);\n | |
25 | # output: \n | |
26 | # output: report(0x00000001);\n | |
27 | # output: report(0x00000002);\n | |
28 | # output: report(0x00000003);\n | |
29 | # output: report(0x00000000);\n | |
30 | # output: report(0x00000000);\n | |
31 | # output: report(0x00000000);\n | |
32 | # output: \n | |
33 | # output: report(0xffffffff);\n | |
34 | # output: report(0xfffffffe);\n | |
35 | # output: report(0xfffffffd);\n | |
36 | # output: report(0x00000001);\n | |
37 | # output: report(0x00000000);\n | |
38 | # output: report(0x00000000);\n | |
39 | # output: \n | |
40 | # output: report(0x40000000);\n | |
41 | # output: report(0x3fffffff);\n | |
42 | # output: report(0x7fffffff);\n | |
43 | # output: report(0x00000000);\n | |
44 | # output: report(0x00000000);\n | |
45 | # output: report(0x00000000);\n | |
46 | # output: \n | |
47 | # output: report(0x40000000);\n | |
48 | # output: report(0x40000000);\n | |
49 | # output: report(0x80000000);\n | |
50 | # output: report(0x00000000);\n | |
51 | # output: report(0x00000001);\n | |
52 | # output: report(0x00000000);\n | |
53 | # output: \n | |
54 | # output: report(0xc0000000);\n | |
55 | # output: report(0xc0000000);\n | |
56 | # output: report(0x80000000);\n | |
57 | # output: report(0x00000001);\n | |
58 | # output: report(0x00000000);\n | |
59 | # output: report(0x00000000);\n | |
60 | # output: \n | |
61 | # output: report(0xbfffffff);\n | |
62 | # output: report(0xbfffffff);\n | |
63 | # output: report(0x7ffffffe);\n | |
64 | # output: report(0x00000001);\n | |
65 | # output: report(0x00000001);\n | |
66 | # output: report(0x00000000);\n | |
67 | # output: \n | |
68 | # output: report(0x40000000);\n | |
69 | # output: report(0x40000000);\n | |
70 | # output: report(0x80000000);\n | |
71 | # output: report(0x00000000);\n | |
72 | # output: report(0x00000001);\n | |
73 | # output: report(0x00000001);\n | |
74 | # output: \n | |
75 | # output: report(0xffffffff);\n | |
76 | # output: report(0xfffffffe);\n | |
77 | # output: report(0xfffffffd);\n | |
78 | # output: report(0x00000001);\n | |
79 | # output: report(0x00000000);\n | |
80 | # output: report(0x00000000);\n | |
81 | # output: \n | |
82 | # output: report(0xbfffffff);\n | |
83 | # output: report(0xbfffffff);\n | |
84 | # output: report(0x7ffffffe);\n | |
85 | # output: report(0x00000001);\n | |
86 | # output: report(0x00000001);\n | |
87 | # output: report(0x00000001);\n | |
88 | # output: \n | |
89 | # output: report(0x00000001);\n | |
90 | # output: report(0x00000002);\n | |
91 | # output: report(0x00000003);\n | |
92 | # output: report(0x00000000);\n | |
93 | # output: report(0x00000000);\n | |
94 | # output: report(0x00000000);\n | |
95 | # output: \n | |
96 | # output: report(0xffffffff);\n | |
97 | # output: report(0xfffffffe);\n | |
98 | # output: report(0xfffffffd);\n | |
99 | # output: report(0x00000001);\n | |
100 | # output: report(0x00000000);\n | |
101 | # output: report(0x00000000);\n | |
102 | # output: \n | |
103 | # output: report(0x40000000);\n | |
104 | # output: report(0x3fffffff);\n | |
105 | # output: report(0x7fffffff);\n | |
106 | # output: report(0x00000000);\n | |
107 | # output: report(0x00000000);\n | |
108 | # output: report(0x00000000);\n | |
109 | # output: \n | |
110 | # output: report(0x40000000);\n | |
111 | # output: report(0x3fffffff);\n | |
112 | # output: report(0x80000000);\n | |
113 | # output: report(0x00000000);\n | |
114 | # output: report(0x00000001);\n | |
115 | # output: report(0x00000000);\n | |
116 | # output: \n | |
117 | # output: report(0x40000000);\n | |
118 | # output: report(0x40000000);\n | |
119 | # output: report(0x80000000);\n | |
120 | # output: report(0x00000000);\n | |
121 | # output: report(0x00000001);\n | |
122 | # output: report(0x00000000);\n | |
123 | # output: \n | |
124 | # output: report(0xffffffff);\n | |
125 | # output: report(0x00000000);\n | |
126 | # output: report(0x00000000);\n | |
127 | # output: report(0x00000001);\n | |
128 | # output: report(0x00000000);\n | |
129 | # output: report(0x00000000);\n | |
130 | # output: \n | |
131 | # output: report(0x00000000);\n | |
132 | # output: report(0xffffffff);\n | |
133 | # output: report(0x00000000);\n | |
134 | # output: report(0x00000001);\n | |
135 | # output: report(0x00000000);\n | |
136 | # output: report(0x00000000);\n | |
137 | # output: \n | |
138 | # output: report(0xc0000000);\n | |
139 | # output: report(0xc0000000);\n | |
140 | # output: report(0x80000000);\n | |
141 | # output: report(0x00000001);\n | |
142 | # output: report(0x00000000);\n | |
143 | # output: report(0x00000000);\n | |
144 | # output: \n | |
145 | # output: report(0xc0000000);\n | |
146 | # output: report(0xbfffffff);\n | |
147 | # output: report(0x80000000);\n | |
148 | # output: report(0x00000001);\n | |
149 | # output: report(0x00000000);\n | |
150 | # output: report(0x00000000);\n | |
151 | # output: \n | |
152 | # output: report(0xbfffffff);\n | |
153 | # output: report(0xbfffffff);\n | |
154 | # output: report(0x7ffffffe);\n | |
155 | # output: report(0x00000001);\n | |
156 | # output: report(0x00000001);\n | |
157 | # output: report(0x00000000);\n | |
158 | # output: \n | |
159 | # output: report(0x40000000);\n | |
160 | # output: report(0x40000000);\n | |
161 | # output: report(0x80000000);\n | |
162 | # output: report(0x00000000);\n | |
163 | # output: report(0x00000001);\n | |
164 | # output: report(0x00000001);\n | |
165 | # output: \n | |
166 | # output: report(0x40000000);\n | |
167 | # output: report(0x3fffffff);\n | |
168 | # output: report(0x80000000);\n | |
169 | # output: report(0x00000000);\n | |
170 | # output: report(0x00000001);\n | |
171 | # output: report(0x00000001);\n | |
172 | # output: \n | |
173 | # output: report(0xffffffff);\n | |
174 | # output: report(0xfffffffe);\n | |
175 | # output: report(0xfffffffd);\n | |
176 | # output: report(0x00000001);\n | |
177 | # output: report(0x00000000);\n | |
178 | # output: report(0x00000000);\n | |
179 | # output: \n | |
180 | # output: report(0x00000000);\n | |
181 | # output: report(0xffffffff);\n | |
182 | # output: report(0x00000000);\n | |
183 | # output: report(0x00000001);\n | |
184 | # output: report(0x00000000);\n | |
185 | # output: report(0x00000000);\n | |
186 | # output: \n | |
187 | # output: report(0xbfffffff);\n | |
188 | # output: report(0xbfffffff);\n | |
189 | # output: report(0x7ffffffe);\n | |
190 | # output: report(0x00000001);\n | |
191 | # output: report(0x00000001);\n | |
192 | # output: report(0x00000001);\n | |
193 | # output: \n | |
194 | # output: report(0x00000001);\n | |
195 | # output: report(0x00000002);\n | |
196 | # output: report(0x00000003);\n | |
197 | # output: report(0x00000000);\n | |
198 | # output: report(0x00000000);\n | |
199 | # output: report(0x00000000);\n | |
200 | # output: \n | |
201 | # output: report(0x00000001);\n | |
202 | # output: report(0x00000002);\n | |
203 | # output: report(0x00000003);\n | |
204 | # output: report(0x00000000);\n | |
205 | # output: report(0x00000000);\n | |
206 | # output: report(0x00000000);\n | |
207 | # output: \n | |
208 | # output: report(0xffffffff);\n | |
209 | # output: report(0x0000fffe);\n | |
210 | # output: report(0xfffffffd);\n | |
211 | # output: report(0x00000001);\n | |
212 | # output: report(0x00000000);\n | |
213 | # output: report(0x00000000);\n | |
214 | # output: \n | |
215 | # output: report(0x7fff8000);\n | |
216 | # output: report(0x00007fff);\n | |
217 | # output: report(0x7fffffff);\n | |
218 | # output: report(0x00000000);\n | |
219 | # output: report(0x00000000);\n | |
220 | # output: report(0x00000000);\n | |
221 | # output: \n | |
222 | # output: report(0x7fffc000);\n | |
223 | # output: report(0x00004000);\n | |
224 | # output: report(0x80000000);\n | |
225 | # output: report(0x00000000);\n | |
226 | # output: report(0x00000001);\n | |
227 | # output: report(0x00000000);\n | |
228 | # output: \n | |
229 | # output: report(0x80008000);\n | |
230 | # output: report(0x00008000);\n | |
231 | # output: report(0x80000000);\n | |
232 | # output: report(0x00000001);\n | |
233 | # output: report(0x00000000);\n | |
234 | # output: report(0x00000000);\n | |
235 | # output: \n | |
236 | # output: report(0x80007fff);\n | |
237 | # output: report(0x00008000);\n | |
238 | # output: report(0x7fffffff);\n | |
239 | # output: report(0x00000001);\n | |
240 | # output: report(0x00000001);\n | |
241 | # output: report(0x00000000);\n | |
242 | # output: \n | |
243 | # output: report(0x7fffc000);\n | |
244 | # output: report(0x00004000);\n | |
245 | # output: report(0x80000000);\n | |
246 | # output: report(0x00000000);\n | |
247 | # output: report(0x00000001);\n | |
248 | # output: report(0x00000001);\n | |
249 | # output: \n | |
250 | # output: report(0xffffffff);\n | |
251 | # output: report(0x0000fffe);\n | |
252 | # output: report(0xfffffffd);\n | |
253 | # output: report(0x00000001);\n | |
254 | # output: report(0x00000000);\n | |
255 | # output: report(0x00000000);\n | |
256 | # output: \n | |
257 | # output: report(0x80007fff);\n | |
258 | # output: report(0x00008000);\n | |
259 | # output: report(0x7fffffff);\n | |
260 | # output: report(0x00000001);\n | |
261 | # output: report(0x00000001);\n | |
262 | # output: report(0x00000001);\n | |
263 | # output: \n | |
264 | # output: report(0x00000001);\n | |
265 | # output: report(0x00000002);\n | |
266 | # output: report(0x00000003);\n | |
267 | # output: report(0x00000000);\n | |
268 | # output: report(0x00000000);\n | |
269 | # output: report(0x00000000);\n | |
270 | # output: \n | |
271 | # output: report(0xffffffff);\n | |
272 | # output: report(0x0000fffe);\n | |
273 | # output: report(0xfffffffd);\n | |
274 | # output: report(0x00000001);\n | |
275 | # output: report(0x00000000);\n | |
276 | # output: report(0x00000000);\n | |
277 | # output: \n | |
278 | # output: report(0x7fff8000);\n | |
279 | # output: report(0x00007fff);\n | |
280 | # output: report(0x7fffffff);\n | |
281 | # output: report(0x00000000);\n | |
282 | # output: report(0x00000000);\n | |
283 | # output: report(0x00000000);\n | |
284 | # output: \n | |
285 | # output: report(0x7fff8000);\n | |
286 | # output: report(0x00007fff);\n | |
287 | # output: report(0x80000000);\n | |
288 | # output: report(0x00000000);\n | |
289 | # output: report(0x00000001);\n | |
290 | # output: report(0x00000000);\n | |
291 | # output: \n | |
292 | # output: report(0x7fffc000);\n | |
293 | # output: report(0x00004000);\n | |
294 | # output: report(0x80000000);\n | |
295 | # output: report(0x00000000);\n | |
296 | # output: report(0x00000001);\n | |
297 | # output: report(0x00000000);\n | |
298 | # output: \n | |
299 | # output: report(0xffffffff);\n | |
300 | # output: report(0x00000000);\n | |
301 | # output: report(0x00000000);\n | |
302 | # output: report(0x00000001);\n | |
303 | # output: report(0x00000000);\n | |
304 | # output: report(0x00000000);\n | |
305 | # output: \n | |
306 | # output: report(0x00000000);\n | |
307 | # output: report(0x0000ffff);\n | |
308 | # output: report(0x00000000);\n | |
309 | # output: report(0x00000001);\n | |
310 | # output: report(0x00000000);\n | |
311 | # output: report(0x00000000);\n | |
312 | # output: \n | |
313 | # output: report(0x80008000);\n | |
314 | # output: report(0x00008000);\n | |
315 | # output: report(0x80000000);\n | |
316 | # output: report(0x00000001);\n | |
317 | # output: report(0x00000000);\n | |
318 | # output: report(0x00000000);\n | |
319 | # output: \n | |
320 | # output: report(0x80007fff);\n | |
321 | # output: report(0x00008000);\n | |
322 | # output: report(0x80000000);\n | |
323 | # output: report(0x00000001);\n | |
324 | # output: report(0x00000000);\n | |
325 | # output: report(0x00000000);\n | |
326 | # output: \n | |
327 | # output: report(0x80007fff);\n | |
328 | # output: report(0x00008000);\n | |
329 | # output: report(0x7fffffff);\n | |
330 | # output: report(0x00000001);\n | |
331 | # output: report(0x00000001);\n | |
332 | # output: report(0x00000000);\n | |
333 | # output: \n | |
334 | # output: report(0x7fffc000);\n | |
335 | # output: report(0x00004000);\n | |
336 | # output: report(0x80000000);\n | |
337 | # output: report(0x00000000);\n | |
338 | # output: report(0x00000001);\n | |
339 | # output: report(0x00000001);\n | |
340 | # output: \n | |
341 | # output: report(0x7fffc000);\n | |
342 | # output: report(0x00003fff);\n | |
343 | # output: report(0x80000000);\n | |
344 | # output: report(0x00000000);\n | |
345 | # output: report(0x00000001);\n | |
346 | # output: report(0x00000001);\n | |
347 | # output: \n | |
348 | # output: report(0xffffffff);\n | |
349 | # output: report(0x0000fffe);\n | |
350 | # output: report(0xfffffffd);\n | |
351 | # output: report(0x00000001);\n | |
352 | # output: report(0x00000000);\n | |
353 | # output: report(0x00000000);\n | |
354 | # output: \n | |
355 | # output: report(0x00000000);\n | |
356 | # output: report(0x0000ffff);\n | |
357 | # output: report(0x00000000);\n | |
358 | # output: report(0x00000001);\n | |
359 | # output: report(0x00000000);\n | |
360 | # output: report(0x00000000);\n | |
361 | # output: \n | |
362 | # output: report(0x80007fff);\n | |
363 | # output: report(0x00008000);\n | |
364 | # output: report(0x7fffffff);\n | |
365 | # output: report(0x00000001);\n | |
366 | # output: report(0x00000001);\n | |
367 | # output: report(0x00000001);\n | |
368 | # output: \n | |
369 | # output: exit(0)\n | |
370 | ||
371 | #include "or1k-asm-test-helpers.h" | |
372 | ||
373 | STANDARD_TEST_ENVIRONMENT | |
374 | ||
375 | .section .exception_vectors | |
376 | ||
377 | /* Range exception. */ | |
378 | .org 0xb00 | |
379 | ||
380 | /* The handling is a bit dubious at present. We just patch the | |
381 | instruction with l.nop and restart. This will go wrong in branch | |
382 | delay slots. But we don't have those in this test. */ | |
383 | l.addi r1, r1, -EXCEPTION_STACK_SKIP_SIZE | |
384 | PUSH r2 | |
385 | PUSH r3 | |
386 | /* Save the address of the instruction that caused the problem. */ | |
387 | MOVE_FROM_SPR r2, SPR_EPCR_BASE | |
388 | LOAD_IMMEDIATE r3, 0x15000000 /* Opcode for l.nop */ | |
389 | l.sw 0(r2), r3 | |
390 | POP r3 | |
391 | POP r2 | |
392 | l.addi r1, r1, EXCEPTION_STACK_SKIP_SIZE | |
393 | l.rfe | |
394 | ||
395 | .section .text | |
396 | start_tests: | |
397 | PUSH LINK_REGISTER_R9 | |
398 | ||
399 | /* Test l.add */ | |
400 | ||
401 | /* Add two small positive numbers */ | |
402 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 1, 2 | |
403 | ||
404 | /* The carry flag should be ignored. */ | |
405 | TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.add, 1, 2 | |
406 | ||
407 | /* Add two small negative numbers, which should set the carry flag | |
408 | but not the overflow flag. */ | |
409 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, -1, -2 | |
410 | ||
411 | /* Add two quite large positive numbers. Should set neither the | |
412 | overflow nor the carry flag. */ | |
413 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 0x40000000, \ | |
414 | 0x3fffffff | |
415 | ||
416 | /* Add two large positive numbers. Should set the overflow, but | |
417 | not the carry flag. */ | |
418 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 0x40000000, \ | |
419 | 0x40000000 | |
420 | ||
421 | /* Add two quite large negative numbers. Should set the carry, but | |
422 | not the overflow flag. */ | |
423 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, -1073741824, \ | |
424 | -1073741824 /* -1073741824 = 0xC0000000 */ | |
425 | ||
426 | /* Add two large negative numbers. Should set both the overflow | |
427 | and carry flags. */ | |
428 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 0xbfffffff, \ | |
429 | 0xbfffffff | |
430 | ||
431 | /* Check that range exceptions are triggered. */ | |
432 | ||
433 | SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3 | |
434 | ||
435 | /* Check that an overflow alone causes a RANGE Exception. */ | |
436 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 0x40000000, \ | |
437 | 0x40000000 | |
438 | ||
439 | /* Check that a carry alone does not cause a RANGE Exception. */ | |
440 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 0xffffffff, \ | |
441 | 0xfffffffe | |
442 | ||
443 | /* Check that carry and overflow together cause an exception. */ | |
444 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 0xbfffffff, \ | |
445 | 0xbfffffff | |
446 | ||
447 | CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3 | |
448 | ||
449 | /* Test l.addc */ | |
450 | ||
451 | /* Add two small positive numbers */ | |
452 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, 1, 2 | |
453 | ||
454 | /* Add two small negative numbers. Sets the carry flag but not the | |
455 | overflow flag. */ | |
456 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, -1, -2 | |
457 | ||
458 | /* Add two quite large positive numbers. Should set neither the | |
459 | overflow nor the carry flag. */ | |
460 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, 0x40000000, \ | |
461 | 0x3fffffff | |
462 | ||
463 | /* Add two quite large positive numbers with a carry in. Should | |
464 | set the overflow but not the carry flag. */ | |
465 | TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.addc, 0x40000000, \ | |
466 | 0x3fffffff | |
467 | ||
468 | /* Add two large positive numbers. Should set the overflow, but | |
469 | not the carry flag. */ | |
470 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, 0x40000000, \ | |
471 | 0x40000000 | |
472 | ||
473 | /* Add the largest unsigned value to zero with a carry. This | |
474 | potentially can break a simplistic test for carry that does not | |
475 | consider the carry flag properly. Do it both ways around. */ | |
476 | TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.addc, -1, 0 | |
477 | TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.addc, 0, -1 | |
478 | ||
479 | /* Add two quite large negative numbers. Should set the carry, but | |
480 | not the overflow flag. Here -1073741824 is 0xC0000000. */ | |
481 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, -1073741824, \ | |
482 | -1073741824 | |
483 | ||
484 | /* Add two quite large negative numbers that would overflow, with a | |
485 | carry that just avoids the overflow. Should set the carry, but | |
486 | not the overflow flag. Here -1073741824 is 0xC0000000 and | |
487 | -1073741825 is 0xBFFFFFFF. */ | |
488 | TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.addc, -1073741824, \ | |
489 | -1073741825 | |
490 | ||
491 | /* Add two large negative numbers. Should set both the overflow | |
492 | and carry flags. */ | |
493 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, -1073741825, \ | |
494 | -1073741825 | |
495 | ||
496 | /* Check that range exceptions are triggered. */ | |
497 | ||
498 | SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3 | |
499 | ||
500 | /* Check that an overflow alone causes a RANGE Exception, even when | |
501 | it is the carry that causes the overflow. */ | |
502 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, 0x40000000, \ | |
503 | 0x40000000 | |
504 | TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.addc, 0x40000000, \ | |
505 | 0x3fffffff | |
506 | ||
507 | /* Check that a carry alone does not cause a RANGE Exception, even | |
508 | when it is the carry that causes the overflow. */ | |
509 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, 0xffffffff, \ | |
510 | 0xfffffffe | |
511 | TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.addc, 0x00000000, \ | |
512 | 0xffffffff | |
513 | ||
514 | /* Check that carry and overflow together cause an exception. */ | |
515 | TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, 0xbfffffff, \ | |
516 | 0xbfffffff | |
517 | ||
518 | CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3 | |
519 | ||
520 | /* Test l.addi */ | |
521 | ||
522 | /* Add two small positive numbers */ | |
523 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 1, 2 | |
524 | ||
525 | /* Check carry in is ignored. */ | |
526 | TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addi, 1, 2 | |
527 | ||
528 | /* Add two small negative numbers. Sets the carry flag but not the | |
529 | overflow flag. */ | |
530 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0xffffffff, \ | |
531 | 0xfffe | |
532 | ||
533 | /* Add two quite large positive numbers. Should set neither the | |
534 | overflow nor the carry flag. */ | |
535 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0x7fff8000, \ | |
536 | 0x7fff | |
537 | ||
538 | /* Add two large positive numbers. Should set the overflow, but | |
539 | not the carry flag. */ | |
540 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0x7fffc000, \ | |
541 | 0x4000 | |
542 | ||
543 | /* Add two quite large negative numbers. Should set the carry, but | |
544 | not the overflow flag. */ | |
545 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0x80008000, \ | |
546 | 0x8000 | |
547 | ||
548 | /* Add two large negative numbers. Should set both the overflow | |
549 | and carry flags. */ | |
550 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0x80007fff, \ | |
551 | 0x8000 | |
552 | ||
553 | /* Check that range exceptions are triggered. */ | |
554 | ||
555 | SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3 | |
556 | ||
557 | /* Check that an overflow alone causes a RANGE Exception. */ | |
558 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0x7fffc000, \ | |
559 | 0x4000 | |
560 | ||
561 | /* Check that a carry alone does not cause a RANGE Exception. */ | |
562 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0xffffffff, \ | |
563 | 0xfffe | |
564 | ||
565 | /* Check that carry and overflow together cause an exception. */ | |
566 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0x80007fff, \ | |
567 | 0x8000 | |
568 | ||
569 | CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3 | |
570 | ||
571 | /* Test l.addi */ | |
572 | ||
573 | /* Add two small positive numbers */ | |
574 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 1, 2 | |
575 | ||
576 | /* Add two small negative numbers. Sets the carry flag but not the | |
577 | overflow flag. */ | |
578 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0xffffffff, \ | |
579 | 0xfffe | |
580 | ||
581 | /* Add two quite large positive numbers. Should set neither the | |
582 | overflow nor the carry flag. */ | |
583 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0x7fff8000, \ | |
584 | 0x7fff | |
585 | ||
586 | /* Add two quite large positive numbers with a carry in. Should | |
587 | set the overflow but not the carry flag. */ | |
588 | TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addic, 0x7fff8000, 0x7fff | |
589 | ||
590 | /* Add two large positive numbers. Should set the overflow, but | |
591 | not the carry flag. */ | |
592 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0x7fffc000, \ | |
593 | 0x4000 | |
594 | ||
595 | /* Add the largest unsigned value to zero with a carry. This | |
596 | potentially can break a simplistic test for carry that does not | |
597 | consider the carry flag properly. Do it both ways around. */ | |
598 | TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addic, 0xffffffff, 0x0000 | |
599 | TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addic, 0x00000000, 0xffff | |
600 | ||
601 | /* Add two quite large negative numbers. Should set the carry, but | |
602 | not the overflow flag. */ | |
603 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0x80008000, \ | |
604 | 0x8000 | |
605 | ||
606 | /* Add two quite large negative numbers that would overflow, with a | |
607 | carry that just avoids the overflow. This should set the carry, | |
608 | but not the overflow flag. */ | |
609 | TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addic, 0x80007fff, 0x8000 | |
610 | ||
611 | /* Add two large negative numbers. Should set both the overflow | |
612 | and carry flags. */ | |
613 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0x80007fff, \ | |
614 | 0x8000 | |
615 | ||
616 | /* Check that range exceptions are triggered. */ | |
617 | ||
618 | SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3 | |
619 | ||
620 | /* Check that an overflow alone causes a RANGE Exception, even when | |
621 | it is the carry that causes the overflow. */ | |
622 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0x7fffc000, \ | |
623 | 0x4000 | |
624 | TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addic, 0x7fffc000, 0x3fff | |
625 | ||
626 | /* Check that a carry alone does not cause a RANGE Exception, even | |
627 | when it is the carry that causes the overflow. */ | |
628 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0xffffffff, \ | |
629 | 0xfffe | |
630 | TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addic, 0x00000000, 0xffff | |
631 | ||
632 | /* Check that carry and overflow together cause an exception. */ | |
633 | TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0x80007fff, \ | |
634 | 0x8000 | |
635 | ||
636 | CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3 | |
637 | ||
638 | POP LINK_REGISTER_R9 | |
639 | RETURN_TO_LINK_REGISTER_R9 |