OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [test-code-or1k/] [inst-set-test/] [is-add-test.S] - Blame information for rev 114

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 112 jeremybenn
/* is-add-test.S. l.add, l.addc, l.addi and l.addic instruction test of Or1ksim
2
 *
3
 * Copyright (C) 1999-2006 OpenCores
4
 * Copyright (C) 2010 Embecosm Limited
5
 *
6
 * Contributors various OpenCores participants
7
 * Contributor Jeremy Bennett 
8
 *
9
 * This file is part of OpenRISC 1000 Architectural Simulator.
10
 *
11
 * This program is free software; you can redistribute it and/or modify it
12
 * under the terms of the GNU General Public License as published by the Free
13
 * Software Foundation; either version 3 of the License, or (at your option)
14
 * any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful, but WITHOUT
17
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
 * more details.
20
 *
21
 * You should have received a copy of the GNU General Public License along
22
 * with this program.  If not, see .
23
 */
24
 
25
/* ----------------------------------------------------------------------------
26
 * Coding conventions
27
 *
28
 * A simple rising stack is provided starting at _stack and pointed to by
29
 * r1. r1 points to the next free word. Only 32-bit registers may be pushed
30
 * onto the stack.
31
 *
32
 * Local labels up to 49 are reserved for macros. Each is used only once in
33
 * all macros. You can get in a serious mess if you get local label clashing
34
 * in macros.
35
 *
36
 * Arguments to functions are passed in r3 through r8.
37
 * r9 is the link (return address)
38
 * r11 is for returning results
39
 *
40
 * Only r1 and r2 are preserved across function calls. It is up to the callee
41
 * to save any other registers required.
42
 * ------------------------------------------------------------------------- */
43
 
44
/* ----------------------------------------------------------------------------
45
 * Test coverage
46
 *
47
 * The l.add, l.addc, l.addi and l.addic instructions should set the carry and
48
 * overflow flags.
49
 *
50
 * In addition the l.addc and l.addic instructions should add in the carry
51
 * bit.
52
 *
53
 * Problems in this area were reported in Bug 1771. Having fixed the problem,
54
 * this is (in good software engineering style), a  regression test to go with
55
 * the fix.
56
 *
57
 * This is not a comprehensive test of any instruction (yet).
58
 *
59
 * Of course what is really needed is a comprehensive instruction test...
60
 * ------------------------------------------------------------------------- */
61
 
62
 
63
#include "inst-set-test.h"
64
 
65 114 jeremybenn
/* ----------------------------------------------------------------------------
66
 * A macro to carry out a test of addition in registers
67
 *
68
 *
69
 * Arguments
70
 *   set_flags: Flags to set in the SR
71
 *   clr_flags: Flags to clear in the SR
72
 *   opc:       The opcode
73
 *   op1:       First operand value
74
 *   op2:       Second operand value
75
 *   res:       Expected result
76
 *   str:       Output string
77
 *   cy:        Expected carry flag
78
 *   ov:        Expected overflow flag
79
 * ------------------------------------------------------------------------- */
80
#define TEST_ADD(set_flags, clr_flags, opc, op1, op2, res, str, cy, ov)  \
81
        l.mfspr r3,r0,SPR_SR                                            ;\
82
        LOAD_CONST (r2, set_flags)      /* Set flags */                 ;\
83
        l.or    r3,r3,r2                                                ;\
84
        LOAD_CONST (r2, ~clr_flags)     /* Clear flags */               ;\
85
        l.and   r3,r3,r2                                                ;\
86
        l.mtspr r0,r3,SPR_SR                                            ;\
87
                                                                        ;\
88
        LOAD_CONST (r5,op1)             /* Load numbers to add */       ;\
89
        LOAD_CONST (r6,op2)                                             ;\
90
        opc     r4,r5,r6                                                ;\
91
        l.mfspr r2,r0,SPR_SR            /* So we can examine flags */   ;\
92
        PUSH (r2)                                                       ;\
93
        CHECK_RES (str, r4, res)                                        ;\
94
        POP(r2)                         /* Retrieve SR */               ;\
95
        PUSH(r2)                                                        ;\
96
        LOAD_CONST (r4, SPR_SR_CY)      /* The carry bit */             ;\
97
        l.and   r2,r2,r4                                                ;\
98
        l.sfeq  r2,r4                                                   ;\
99
        CHECK_FLAG ("- carry flag set:    ", cy)                        ;\
100
                                                                        ;\
101
        POP(r2)                         /* Retrieve SR */               ;\
102
        PUSH(r2)                                                        ;\
103
        LOAD_CONST (r4, SPR_SR_OV)      /* The overflow bit */          ;\
104
        l.and   r2,r2,r4                                                ;\
105
        l.sfeq  r2,r4                                                   ;\
106
        CHECK_FLAG ("- overflow flag set: ", ov)
107
 
108
/* ----------------------------------------------------------------------------
109
 * A macro to carry out a test of addition with an immediate value
110
 *
111
 *
112
 * Arguments
113
 *   set_flags: Flags to set in the SR
114
 *   clr_flags: Flags to clear in the SR
115
 *   opc:       The opcode
116
 *   op1:       First operand value
117
 *   op2:       Second operand value (immediate)
118
 *   res:       Expected result
119
 *   str:       Output string
120
 *   cy:        Expected carry flag
121
 *   ov:        Expected overflow flag
122
 * ------------------------------------------------------------------------- */
123
#define TEST_ADDI(set_flags, clr_flags, opc, op1, op2, res, str, cy, ov) \
124
        l.mfspr r3,r0,SPR_SR                                            ;\
125
        LOAD_CONST (r2, set_flags)      /* Set flags */                 ;\
126
        l.or    r3,r3,r2                                                ;\
127
        LOAD_CONST (r2, ~clr_flags)     /* Clear flags */               ;\
128
        l.and   r3,r3,r2                                                ;\
129
        l.mtspr r0,r3,SPR_SR                                            ;\
130
                                                                        ;\
131
        LOAD_CONST (r5,op1)             /* Load first number to add */  ;\
132
        opc     r4,r5,op2                                               ;\
133
        l.mfspr r2,r0,SPR_SR            /* So we can examine flags */   ;\
134
        PUSH (r2)                                                       ;\
135
        CHECK_RES (str, r4, res)                                        ;\
136
        POP(r2)                         /* Retrieve SR */               ;\
137
        PUSH(r2)                                                        ;\
138
        LOAD_CONST (r4, SPR_SR_CY)      /* The carry bit */             ;\
139
        l.and   r2,r2,r4                                                ;\
140
        l.sfeq  r2,r4                                                   ;\
141
        CHECK_FLAG ("- carry flag set:    ", cy)                        ;\
142
                                                                        ;\
143
        POP(r2)                         /* Retrieve SR */               ;\
144
        PUSH(r2)                                                        ;\
145
        LOAD_CONST (r4, SPR_SR_OV)      /* The overflow bit */          ;\
146
        l.and   r2,r2,r4                                                ;\
147
        l.sfeq  r2,r4                                                   ;\
148
        CHECK_FLAG ("- overflow flag set: ", ov)
149
 
150
 
151 112 jeremybenn
        .section .text
152
        .global _start
153
_start:
154
 
155
/* ----------------------------------------------------------------------------
156
 * Test of add signed, l.add
157
 * ------------------------------------------------------------------------- */
158
_add:
159
        LOAD_STR (r3, "l.add\n")
160
        l.jal   _puts
161
        l.nop
162
 
163
        /* Add two small positive numbers */
164 114 jeremybenn
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
165
                  l.add, 1, 2, 3,
166
                  "0x00000001 + 0x00000002 = 0x00000003: ",
167
                  FALSE, FALSE)
168
 
169
        /* Check carry in is ignored. */
170
        TEST_ADD (SPR_SR_CY, SPR_SR_OV,
171
                  l.add, 1, 2, 3,
172
                  "0x00000001 + 0x00000002 = 0x00000003: ",
173
                  FALSE, FALSE)
174
 
175
        /* Add two small negative numbers. Sets the carry flag but not the
176
           overflow flag. */
177
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
178
                  l.add, 0xffffffff, 0xfffffffe, 0xfffffffd,
179
                  "0xffffffff + 0xfffffffe = 0xfffffffd: ",
180
                  TRUE, FALSE)
181
 
182
        /* Add two quite large positive numbers. Should set neither the
183
           overflow nor the carry flag. */
184
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
185
                  l.add, 0x40000000, 0x3fffffff, 0x7fffffff,
186
                  "0x40000000 + 0x3fffffff = 0x7fffffff: ",
187
                  FALSE, FALSE)
188
 
189
        /* Add two large positive numbers. Should set the overflow, but not
190
           the carry flag. */
191
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
192
                  l.add, 0x40000000, 0x40000000, 0x80000000,
193
                  "0x40000000 + 0x40000000 = 0x80000000: ",
194
                  FALSE, TRUE)
195
 
196
        /* Add two quite large negative numbers. Should set the carry, but not
197
           the overflow flag. */
198
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
199
                  l.add, 0xc0000000, 0xc0000000, 0x80000000,
200
                  "0xc0000000 + 0xc0000000 = 0x80000000: ",
201
                  TRUE, FALSE)
202
 
203
        /* Add two large negative numbers. Should set both the overflow and
204
           carry flags. */
205
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
206
                  l.add, 0xbfffffff, 0xbfffffff, 0x7ffffffe,
207
                  "0xbfffffff + 0xbfffffff = 0x7ffffffe: ",
208
                  TRUE, TRUE)
209
 
210
        /* Check that range exceptions are triggered */
211 112 jeremybenn
        l.mfspr r3,r0,SPR_SR
212 114 jeremybenn
        LOAD_CONST (r2, SPR_SR_OVE)     /* Set OVE */
213
        l.or    r3,r3,r2
214 112 jeremybenn
        l.mtspr r0,r3,SPR_SR
215 114 jeremybenn
 
216
        LOAD_STR (r3, "  ** OVE flag set **\n")
217
        l.jal   _puts
218
        l.nop
219 112 jeremybenn
 
220 114 jeremybenn
        /* Check that an overflow alone causes a RANGE Exception. */
221
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
222
                  l.add, 0x40000000, 0x40000000, 0x80000000,
223
                  "0x40000000 + 0x40000000 = 0x80000000: ",
224
                  FALSE, TRUE)
225 112 jeremybenn
 
226 114 jeremybenn
        /* Check that a carry alone does not cause a RANGE Exception. */
227
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
228
                  l.add, 0xffffffff, 0xfffffffe, 0xfffffffd,
229
                  "0xffffffff + 0xfffffffe = 0xfffffffd: ",
230
                  TRUE, FALSE)
231 112 jeremybenn
 
232 114 jeremybenn
        /* Check that carry and overflow together cause an exception. */
233
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
234
                  l.add, 0xbfffffff, 0xbfffffff, 0x7ffffffe,
235
                  "0xbfffffff + 0xbfffffff = 0x7ffffffe: ",
236
                  TRUE, TRUE)
237 112 jeremybenn
 
238 114 jeremybenn
        /* Finished checking range exceptions */
239 112 jeremybenn
        l.mfspr r3,r0,SPR_SR
240 114 jeremybenn
        LOAD_CONST (r2, ~SPR_SR_OVE)    /* Clear OVE */
241 112 jeremybenn
        l.and   r3,r3,r2
242
        l.mtspr r0,r3,SPR_SR
243 114 jeremybenn
 
244
        LOAD_STR (r3, "  ** OVE flag cleared **\n")
245
        l.jal   _puts
246
        l.nop
247 112 jeremybenn
 
248 114 jeremybenn
/* ----------------------------------------------------------------------------
249
 * Test of add signed and carry, l.addc
250
 * ------------------------------------------------------------------------- */
251
_addc:
252
        LOAD_STR (r3, "l.addc\n")
253
        l.jal   _puts
254
        l.nop
255 112 jeremybenn
 
256 114 jeremybenn
        /* Add two small positive numbers */
257
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
258
                  l.addc, 1, 2, 3,
259
                  "0x00000001 + 0x00000002     = 0x00000003: ",
260
                  FALSE, FALSE)
261 112 jeremybenn
 
262 114 jeremybenn
        /* Add two small negative numbers. Sets the carry flag but not the
263
           overflow flag. */
264
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
265
                  l.addc, 0xffffffff, 0xfffffffe, 0xfffffffd,
266
                  "0xffffffff + 0xfffffffe     = 0xfffffffd: ",
267
                  TRUE, FALSE)
268 112 jeremybenn
 
269
        /* Add two quite large positive numbers. Should set neither the
270
           overflow nor the carry flag. */
271 114 jeremybenn
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
272
                  l.addc, 0x40000000, 0x3fffffff, 0x7fffffff,
273
                  "0x40000000 + 0x3fffffff     = 0x7fffffff: ",
274
                  FALSE, FALSE)
275 112 jeremybenn
 
276 114 jeremybenn
        /* Add two quite large positive numbers with a carry in. Should set
277
           the overflow but not the carry flag. */
278
        TEST_ADD (SPR_SR_CY, SPR_SR_OV,
279
                  l.addc, 0x40000000, 0x3fffffff, 0x80000000,
280
                  "0x40000000 + 0x3fffffff + c = 0x80000000: ",
281
                  FALSE, TRUE)
282 112 jeremybenn
 
283
        /* Add two large positive numbers. Should set the overflow, but not
284
           the carry flag. */
285 114 jeremybenn
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
286
                  l.addc, 0x40000000, 0x40000000, 0x80000000,
287
                  "0x40000000 + 0x40000000     = 0x80000000: ",
288
                  FALSE, TRUE)
289 112 jeremybenn
 
290 114 jeremybenn
        /* Add the largest unsigned value to zero with a carry. This
291
           potentially can break a simplistic test for carry that does not
292
           consider the carry flag properly. Do it both ways around. */
293
        TEST_ADD (SPR_SR_CY, SPR_SR_OV,
294
                  l.addc, 0xffffffff, 0x00000000, 0x00000000,
295
                  "0xffffffff + 0x00000000 + c = 0x00000000: ",
296
                  TRUE, FALSE)
297 112 jeremybenn
 
298 114 jeremybenn
        TEST_ADD (SPR_SR_CY, SPR_SR_OV,
299
                  l.addc, 0x00000000, 0xffffffff, 0x00000000,
300
                  "0x00000000 + 0xffffffff + c = 0x00000000: ",
301
                  TRUE, FALSE)
302 112 jeremybenn
 
303
        /* Add two quite large negative numbers. Should set the carry, but not
304
           the overflow flag. flag. */
305 114 jeremybenn
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
306
                  l.addc, 0xc0000000, 0xc0000000, 0x80000000,
307
                  "0xc0000000 + 0xc0000000     = 0x80000000: ",
308
                  TRUE, FALSE)
309
 
310
        /* Add two quite large negative numbers that would overflow, with a
311
           carry that just avoids the overflow. Should set the carry, but not
312
           the overflow flag. flag. */
313
        TEST_ADD (SPR_SR_CY, SPR_SR_OV,
314
                  l.addc, 0xc0000000, 0xbfffffff, 0x80000000,
315
                  "0xc0000000 + 0xbfffffff + c = 0x80000000: ",
316
                  TRUE, FALSE)
317
 
318
        /* Add two large negative numbers. Should set both the overflow and
319
           carry flags. */
320
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
321
                  l.addc, 0xbfffffff, 0xbfffffff, 0x7ffffffe,
322
                  "0xbfffffff + 0xbfffffff     = 0x7ffffffe: ",
323
                  TRUE, TRUE)
324
 
325
        /* Check that range exceptions are triggered */
326 112 jeremybenn
        l.mfspr r3,r0,SPR_SR
327 114 jeremybenn
        LOAD_CONST (r2, SPR_SR_OVE)     /* Set OVE */
328
        l.or    r3,r3,r2
329 112 jeremybenn
        l.mtspr r0,r3,SPR_SR
330 114 jeremybenn
 
331
        LOAD_STR (r3, "  ** OVE flag set **\n")
332
        l.jal   _puts
333
        l.nop
334 112 jeremybenn
 
335 114 jeremybenn
        /* Check that an overflow alone causes a RANGE Exception, even when it
336
           is the carry that causes the overflow. */
337
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
338
                  l.addc, 0x40000000, 0x40000000, 0x80000000,
339
                  "0x40000000 + 0x40000000     = 0x80000000: ",
340
                  FALSE, TRUE)
341 112 jeremybenn
 
342 114 jeremybenn
        TEST_ADD (SPR_SR_CY, SPR_SR_OV,
343
                  l.addc, 0x40000000, 0x3fffffff, 0x80000000,
344
                  "0x40000000 + 0x3fffffff + c = 0x80000000: ",
345
                  FALSE, TRUE)
346 112 jeremybenn
 
347 114 jeremybenn
        /* Check that a carry alone does not cause a RANGE Exception, even
348
           when it is the carry that causes the overflow. */
349
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
350
                  l.addc, 0xffffffff, 0xfffffffe, 0xfffffffd,
351
                  "0xffffffff + 0xfffffffe     = 0xfffffffd: ",
352
                  TRUE, FALSE)
353 112 jeremybenn
 
354 114 jeremybenn
        TEST_ADD (SPR_SR_CY, SPR_SR_OV,
355
                  l.addc, 0x00000000, 0xffffffff, 0x00000000,
356
                  "0x00000000 + 0xffffffff + c = 0x00000000: ",
357
                  TRUE, FALSE)
358
 
359
        /* Check that carry and overflow together cause an exception. */
360
        TEST_ADD (0, SPR_SR_CY | SPR_SR_OV,
361
                  l.addc, 0xbfffffff, 0xbfffffff, 0x7ffffffe,
362
                  "0xbfffffff + 0xbfffffff     = 0x7ffffffe: ",
363
                  TRUE, TRUE)
364
 
365
        /* Finished checking range exceptions */
366 112 jeremybenn
        l.mfspr r3,r0,SPR_SR
367 114 jeremybenn
        LOAD_CONST (r2, ~SPR_SR_OVE)    /* Clear OVE */
368 112 jeremybenn
        l.and   r3,r3,r2
369
        l.mtspr r0,r3,SPR_SR
370 114 jeremybenn
 
371
        LOAD_STR (r3, "  ** OVE flag cleared **\n")
372
        l.jal   _puts
373
        l.nop
374 112 jeremybenn
 
375 114 jeremybenn
/* ----------------------------------------------------------------------------
376
 * Test of add signed immediate, l.addi
377
 * ------------------------------------------------------------------------- */
378
_addi:
379
        LOAD_STR (r3, "l.addi\n")
380
        l.jal   _puts
381
        l.nop
382 112 jeremybenn
 
383 114 jeremybenn
        /* Add two small positive numbers */
384
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
385
                   l.addi, 1, 2, 3,
386
                   "0x00000001 + 0x00000002 = 0x00000003: ",
387
                   FALSE, FALSE)
388 112 jeremybenn
 
389 114 jeremybenn
        /* Check carry in is ignored. */
390
        TEST_ADDI (SPR_SR_CY, SPR_SR_OV,
391
                   l.addi, 1, 2, 3,
392
                   "0x00000001 + 0x00000002 = 0x00000003: ",
393
                   FALSE, FALSE)
394 112 jeremybenn
 
395 114 jeremybenn
        /* Add two small negative numbers. Sets the carry flag but not the
396
           overflow flag. */
397
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
398
                   l.addi, 0xffffffff, 0xfffe, 0xfffffffd,
399
                   "0xffffffff + 0xfffffffe = 0xfffffffd: ",
400
                   TRUE, FALSE)
401
 
402
        /* Add two quite large positive numbers. Should set neither the
403
           overflow nor the carry flag. */
404
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
405
                   l.addi, 0x7fff8000, 0x7fff, 0x7fffffff,
406
                   "0x7fff8000 + 0x00007fff = 0x7fffffff: ",
407
                   FALSE, FALSE)
408
 
409
        /* Add two large positive numbers. Should set the overflow, but not
410
           the carry flag. */
411
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
412
                   l.addi, 0x7fffc000, 0x4000, 0x80000000,
413
                   "0x7fffc000 + 0x00004000 = 0x80000000: ",
414
                   FALSE, TRUE)
415
 
416
        /* Add two quite large negative numbers. Should set the carry, but not
417
           the overflow flag. */
418
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
419
                   l.addi, 0x80008000, 0x8000, 0x80000000,
420
                   "0x80008000 + 0xffff8000 = 0x80000000: ",
421
                   TRUE, FALSE)
422
 
423
        /* Add two large negative numbers. Should set both the overflow and
424
           carry flags. */
425
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
426
                   l.addi, 0x80007fff, 0x8000, 0x7fffffff,
427
                   "0x80007fff + 0xffff8000 = 0x7fffffff: ",
428
                   TRUE, TRUE)
429
 
430 112 jeremybenn
        /* Check that range exceptions are triggered */
431 114 jeremybenn
        l.mfspr r3,r0,SPR_SR
432 112 jeremybenn
        LOAD_CONST (r2, SPR_SR_OVE)     /* Set OVE */
433
        l.or    r3,r3,r2
434
        l.mtspr r0,r3,SPR_SR
435
 
436 114 jeremybenn
        LOAD_STR (r3, "  ** OVE flag set **\n")
437 112 jeremybenn
        l.jal   _puts
438
        l.nop
439
 
440
        /* Check that an overflow alone causes a RANGE Exception. */
441 114 jeremybenn
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
442
                   l.addi, 0x7fffc000, 0x4000, 0x80000000,
443
                   "0x7fffc000 + 0x00004000 = 0x80000000: ",
444
                   FALSE, TRUE)
445
 
446
        /* Check that a carry alone does not cause a RANGE Exception. */
447
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
448
                   l.addi, 0xffffffff, 0xfffe, 0xfffffffd,
449
                   "0xffffffff + 0xfffffffe = 0xfffffffd: ",
450
                   TRUE, FALSE)
451
 
452
        /* Check that carry and overflow together cause an exception. */
453
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
454
                   l.addi, 0x80007fff, 0x8000, 0x7fffffff,
455
                   "0x80007fff + 0xffff8000 = 0x7ffffffe: ",
456
                   TRUE, TRUE)
457
 
458
        /* Finished checking range exceptions */
459 112 jeremybenn
        l.mfspr r3,r0,SPR_SR
460 114 jeremybenn
        LOAD_CONST (r2, ~SPR_SR_OVE)    /* Clear OVE */
461 112 jeremybenn
        l.and   r3,r3,r2
462
        l.mtspr r0,r3,SPR_SR
463 114 jeremybenn
 
464
        LOAD_STR (r3, "  ** OVE flag cleared **\n")
465
        l.jal   _puts
466
        l.nop
467 112 jeremybenn
 
468 114 jeremybenn
/* ----------------------------------------------------------------------------
469
 * Test of add signed and carry, l.addic
470
 * ------------------------------------------------------------------------- */
471
_addic:
472
        LOAD_STR (r3, "l.addic\n")
473
        l.jal   _puts
474
        l.nop
475 112 jeremybenn
 
476 114 jeremybenn
        /* Add two small positive numbers */
477
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
478
                   l.addic, 1, 2, 3,
479
                   "0x00000001 + 0x00000002     = 0x00000003: ",
480
                   FALSE, FALSE)
481 112 jeremybenn
 
482 114 jeremybenn
        /* Add two small negative numbers. Sets the carry flag but not the
483
           overflow flag. */
484
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
485
                   l.addic, 0xffffffff, 0xfffe, 0xfffffffd,
486
                   "0xffffffff + 0xfffffffe     = 0xfffffffd: ",
487
                   TRUE, FALSE)
488 112 jeremybenn
 
489 114 jeremybenn
        /* Add two quite large positive numbers. Should set neither the
490
           overflow nor the carry flag. */
491
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
492
                   l.addic, 0x7fff8000, 0x7fff, 0x7fffffff,
493
                   "0x7fff8000 + 0x00007fff     = 0x7fffffff: ",
494
                   FALSE, FALSE)
495 112 jeremybenn
 
496 114 jeremybenn
        /* Add two quite large positive numbers with a carry in. Should set
497
           the overflow but not the carry flag. */
498
        TEST_ADDI (SPR_SR_CY, SPR_SR_OV,
499
                   l.addic, 0x7fff8000, 0x7fff, 0x80000000,
500
                   "0x7fff8000 + 0x00007fff + c = 0x80000000: ",
501
                   FALSE, TRUE)
502 112 jeremybenn
 
503 114 jeremybenn
        /* Add two large positive numbers. Should set the overflow, but not
504
           the carry flag. */
505
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
506
                   l.addic, 0x7fffc000, 0x4000, 0x80000000,
507
                   "0x7fffc000 + 0x00004000     = 0x80000000: ",
508
                   FALSE, TRUE)
509 112 jeremybenn
 
510 114 jeremybenn
        /* Add the largest unsigned value to zero with a carry. This
511
           potentially can break a simplistic test for carry that does not
512
           consider the carry flag properly. Do it both ways around. */
513
        TEST_ADDI (SPR_SR_CY, SPR_SR_OV,
514
                   l.addic, 0xffffffff, 0x0000, 0x00000000,
515
                   "0xffffffff + 0x00000000 + c = 0x00000000: ",
516
                   TRUE, FALSE)
517 112 jeremybenn
 
518 114 jeremybenn
        TEST_ADDI (SPR_SR_CY, SPR_SR_OV,
519
                   l.addic, 0x00000000, 0xffff, 0x00000000,
520
                   "0x00000000 + 0xffffffff + c = 0x00000000: ",
521
                   TRUE, FALSE)
522
 
523
        /* Add two quite large negative numbers. Should set the carry, but not
524
           the overflow flag. flag. */
525
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
526
                   l.addic, 0x80008000, 0x8000, 0x80000000,
527
                   "0x80008000 + 0xffff8000     = 0x80000000: ",
528
                   TRUE, FALSE)
529
 
530
        /* Add two quite large negative numbers that would overflow, with a
531
           carry that just avoids the overflow. Should set the carry, but not
532
           the overflow flag. flag. */
533
        TEST_ADDI (SPR_SR_CY, SPR_SR_OV,
534
                   l.addic, 0x80007fff, 0x8000, 0x80000000,
535
                   "0x80007fff + 0xffff8000 + c = 0x80000000: ",
536
                   TRUE, FALSE)
537
 
538
        /* Add two large negative numbers. Should set both the overflow and
539
           carry flags. */
540
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
541
                   l.addic, 0x80007fff, 0x8000, 0x7fffffff,
542
                   "0x80007fff + 0xffff8000     = 0x7fffffff: ",
543
                   TRUE, TRUE)
544
 
545
        /* Check that range exceptions are triggered */
546 112 jeremybenn
        l.mfspr r3,r0,SPR_SR
547 114 jeremybenn
        LOAD_CONST (r2, SPR_SR_OVE)     /* Set OVE */
548
        l.or    r3,r3,r2
549 112 jeremybenn
        l.mtspr r0,r3,SPR_SR
550 114 jeremybenn
 
551
        LOAD_STR (r3, "  ** OVE flag set **\n")
552
        l.jal   _puts
553
        l.nop
554 112 jeremybenn
 
555 114 jeremybenn
        /* Check that an overflow alone causes a RANGE Exception, even when it
556
           is the carry that causes the overflow. */
557
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
558
                   l.addic, 0x7fffc000, 0x4000, 0x80000000,
559
                   "0x7fffc000 + 0x00004000     = 0x80000000: ",
560
                   FALSE, TRUE)
561 112 jeremybenn
 
562 114 jeremybenn
        TEST_ADDI (SPR_SR_CY, SPR_SR_OV,
563
                   l.addic, 0x7fffc000, 0x3fff, 0x80000000,
564
                   "0x7fffc000 + 0x00003fff + c = 0x80000000: ",
565
                   FALSE, TRUE)
566 112 jeremybenn
 
567 114 jeremybenn
        /* Check that a carry alone does not cause a RANGE Exception, even
568
           when it is the carry that causes the overflow. */
569
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
570
                   l.addic, 0xffffffff, 0xfffe, 0xfffffffd,
571
                   "0xffffffff + 0xfffffffe     = 0xfffffffd: ",
572
                   TRUE, FALSE)
573 112 jeremybenn
 
574 114 jeremybenn
        TEST_ADDI (SPR_SR_CY, SPR_SR_OV,
575
                   l.addic, 0x00000000, 0xffff, 0x00000000,
576
                   "0x00000000 + 0xffffffff + c = 0x00000000: ",
577
                   TRUE, FALSE)
578
 
579
        /* Check that carry and overflow together cause an exception. */
580
        TEST_ADDI (0, SPR_SR_CY | SPR_SR_OV,
581
                   l.addic, 0x80007fff, 0x8000, 0x7fffffff,
582
                   "0x80007fff + 0xffff8000     = 0x7ffffffe: ",
583
                   TRUE, TRUE)
584
 
585 112 jeremybenn
        /* Finished checking range exceptions */
586 114 jeremybenn
        l.mfspr r3,r0,SPR_SR
587 112 jeremybenn
        LOAD_CONST (r2, ~SPR_SR_OVE)    /* Clear OVE */
588
        l.and   r3,r3,r2
589
        l.mtspr r0,r3,SPR_SR
590
 
591 114 jeremybenn
        LOAD_STR (r3, "  ** OVE flag cleared **\n")
592 112 jeremybenn
        l.jal   _puts
593
        l.nop
594
 
595
/* ----------------------------------------------------------------------------
596
 * All done
597
 * ------------------------------------------------------------------------- */
598
_exit:
599
        LOAD_STR (r3, "Test completed\n")
600
        l.jal   _puts
601
        l.nop
602
 
603
        TEST_EXIT

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.