1 /* Tests instructions l.add, l.addc, l.addi and l.addic.
3 Copyright (C) 2017-2020 Free Software Foundation, Inc.
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.
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.
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/>. */
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
371 #include "or1k-asm-test-helpers.h"
373 STANDARD_TEST_ENVIRONMENT
375 .section .exception_vectors
377 /* Range exception. */
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
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 */
392 l.addi r1, r1, EXCEPTION_STACK_SKIP_SIZE
397 PUSH LINK_REGISTER_R9
401 /* Add two small positive numbers */
402 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 1, 2
404 /* The carry flag should be ignored. */
405 TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.add, 1, 2
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
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, \
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, \
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 */
426 /* Add two large negative numbers. Should set both the overflow
428 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 0xbfffffff, \
431 /* Check that range exceptions are triggered. */
433 SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
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, \
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, \
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, \
447 CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
451 /* Add two small positive numbers */
452 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, 1, 2
454 /* Add two small negative numbers. Sets the carry flag but not the
456 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, -1, -2
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, \
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, \
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, \
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
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, \
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, \
491 /* Add two large negative numbers. Should set both the overflow
493 TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, -1073741825, \
496 /* Check that range exceptions are triggered. */
498 SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
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, \
504 TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.addc, 0x40000000, \
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, \
511 TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.addc, 0x00000000, \
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, \
518 CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
522 /* Add two small positive numbers */
523 TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 1, 2
525 /* Check carry in is ignored. */
526 TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addi, 1, 2
528 /* Add two small negative numbers. Sets the carry flag but not the
530 TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0xffffffff, \
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, \
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, \
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, \
548 /* Add two large negative numbers. Should set both the overflow
550 TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0x80007fff, \
553 /* Check that range exceptions are triggered. */
555 SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
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, \
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, \
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, \
569 CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
573 /* Add two small positive numbers */
574 TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 1, 2
576 /* Add two small negative numbers. Sets the carry flag but not the
578 TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0xffffffff, \
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, \
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
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, \
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
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, \
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
611 /* Add two large negative numbers. Should set both the overflow
613 TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0x80007fff, \
616 /* Check that range exceptions are triggered. */
618 SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
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, \
624 TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addic, 0x7fffc000, 0x3fff
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, \
630 TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addic, 0x00000000, 0xffff
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, \
636 CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
639 RETURN_TO_LINK_REGISTER_R9