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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 124 jeremybenn
/* is-sub-test.S. l.sub 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 are described in inst-set-test.S
27
 * ------------------------------------------------------------------------- */
28
 
29
/* ----------------------------------------------------------------------------
30
 * Test coverage
31
 *
32
 * The l.sub instruction should set the carry and overflow flags.
33
 *
34
 * Problems in this area were reported in Bugs 1782, 1783 and 1784. Having
35
 * fixed the problem, this is (in good software engineering style), a
36
 * regression test to go with the fix.
37
 *
38
 * This is not a comprehensive test of any instruction (yet).
39
 *
40
 * Of course what is really needed is a comprehensive instruction test...
41
 * ------------------------------------------------------------------------- */
42
 
43
 
44
#include "inst-set-test.h"
45
 
46
/* ----------------------------------------------------------------------------
47
 * A macro to carry out a test of subtraction in registers
48
 *
49
 *
50
 * Arguments
51
 *   set_flags: Flags to set in the SR
52
 *   clr_flags: Flags to clear in the SR
53
 *   op1:       First operand value
54
 *   op2:       Second operand value
55
 *   res:       Expected result
56
 *   cy:        Expected carry flag
57
 *   ov:        Expected overflow flag
58
 * ------------------------------------------------------------------------- */
59
#define TEST_SUB(set_flags, clr_flags, op1, op2, res, cy, ov)            \
60
        l.mfspr r3,r0,SPR_SR                                            ;\
61
        LOAD_CONST (r2, set_flags)      /* Set flags */                 ;\
62
        l.or    r3,r3,r2                                                ;\
63
        LOAD_CONST (r2, ~clr_flags)     /* Clear flags */               ;\
64
        l.and   r3,r3,r2                                                ;\
65
        l.mtspr r0,r3,SPR_SR                                            ;\
66
                                                                        ;\
67
        LOAD_CONST (r5,op1)             /* Load numbers to subtract */  ;\
68
        LOAD_CONST (r6,op2)                                             ;\
69
        l.mtspr r0,r0,SPR_EPCR_BASE     /* Clear record */              ;\
70
50:     l.sub   r4,r5,r6                                                ;\
71
        l.mfspr r2,r0,SPR_SR            /* So we can examine flags */   ;\
72
        l.mfspr r5,r0,SPR_EPCR_BASE     /* What triggered exception */  ;\
73
        PUSH (r5)                       /* Save EPCR for later */       ;\
74
        PUSH (r2)                                                       ;\
75
        PUSH (r4)                       /* Save result for later */     ;\
76
                                                                        ;\
77
        PUTS ("  0x")                                                   ;\
78
        PUTH (op1)                                                      ;\
79
        PUTS (" - 0x")                                                  ;\
80
        PUTH (op2)                                                      ;\
81
        PUTS (" = 0x")                                                  ;\
82
        PUTH (res)                                                      ;\
83
        PUTS (": ")                                                     ;\
84
        POP (r4)                                                        ;\
85
        CHECK_RES1 (r4, res)                                            ;\
86
                                                                        ;\
87
        POP(r2)                         /* Retrieve SR */               ;\
88
        PUSH(r2)                                                        ;\
89
        LOAD_CONST (r4, SPR_SR_CY)      /* The carry bit */             ;\
90
        l.and   r2,r2,r4                                                ;\
91
        l.sfeq  r2,r4                                                   ;\
92
        CHECK_FLAG ("- carry flag set:      ", cy)                      ;\
93
                                                                        ;\
94
        POP(r2)                         /* Retrieve SR */               ;\
95
        LOAD_CONST (r4, SPR_SR_OV)      /* The overflow bit */          ;\
96
        l.and   r2,r2,r4                                                ;\
97
        l.sfeq  r2,r4                                                   ;\
98
        CHECK_FLAG ("- overflow flag set:   ", ov)                      ;\
99
                                                                        ;\
100
        POP (r2)                        /* Retrieve EPCR */             ;\
101
        LOAD_CONST (r4, 50b)            /* The opcode of interest */    ;\
102
        l.and   r2,r2,r4                                                ;\
103
        l.sfeq  r2,r4                                                   ;\
104
        l.bnf   53f                                                     ;\
105
                                                                        ;\
106
        PUTS ("  - exception triggered: TRUE\n")                        ;\
107
        l.j     54f                                                     ;\
108
        l.nop                                                           ;\
109
                                                                        ;\
110
53:     PUTS ("  - exception triggered: FALSE\n")                       ;\
111
54:
112
 
113
 
114
/* ----------------------------------------------------------------------------
115
 * Start of code
116
 * ------------------------------------------------------------------------- */
117
        .section .text
118
        .global _start
119
_start:
120
        l.mfspr r3,r0,SPR_SR
121
        LOAD_CONST (r2, ~SPR_SR_OVE)    /* Clear OVE */
122
        l.and   r3,r3,r2
123
        l.mtspr r0,r3,SPR_SR
124
 
125
        LOAD_STR (r3, "  ** OVE flag cleared **\n")
126
        l.jal   _puts
127
        l.nop
128
 
129
/* ----------------------------------------------------------------------------
130
 * Test of subtract signed, l.sub
131
 * ------------------------------------------------------------------------- */
132
_sub:
133
        LOAD_STR (r3, "l.sub\n")
134
        l.jal   _puts
135
        l.nop
136
 
137
        /* Subtract two small positive numbers. Sets the carry, but never the
138
           overflow if the result is negative. */
139
        TEST_SUB (0, SPR_SR_CY | SPR_SR_OV,
140
                  0x00000003, 0x00000002, 0x00000001,
141
                  FALSE, FALSE)
142
 
143
        TEST_SUB (0, SPR_SR_CY | SPR_SR_OV,
144
                  0x00000001, 0x00000002, 0xffffffff,
145
                  TRUE, FALSE)
146
 
147
        /* Check carry in is ignored. */
148
        TEST_SUB (SPR_SR_CY, SPR_SR_OV,
149
                  0x00000003, 0x00000002, 0x00000001,
150
                  FALSE, FALSE)
151
 
152
        /* Subtract two small negative numbers. Sets the carry flag if the
153
           result is negative, but never the overflow flag. */
154
        TEST_SUB (0, SPR_SR_CY | SPR_SR_OV,
155
                  0xfffffffd, 0xfffffffe, 0xffffffff,
156
                  TRUE, FALSE)
157
 
158
        TEST_SUB (0, SPR_SR_CY | SPR_SR_OV,
159
                  0xffffffff, 0xfffffffe, 0x00000001,
160
                  FALSE, FALSE)
161
 
162
        /* Subtract two quite large positive numbers. Should set neither the
163
           overflow nor the carry flag. */
164
        TEST_SUB (0, SPR_SR_CY | SPR_SR_OV,
165
                  0x7fffffff, 0x3fffffff, 0x40000000,
166
                  FALSE, FALSE)
167
 
168
        /* Subtract two quite large negative numbers. Should set neither the
169
           overflow nor the carry flag. */
170
        TEST_SUB (0, SPR_SR_CY | SPR_SR_OV,
171
                  0x40000000, 0x40000000, 0x00000000,
172
                  FALSE, FALSE)
173
 
174
        /* Subtract two large positive numbers with a negative result. Should
175
           set the carry, but not the overflow flag. */
176
        TEST_SUB (0, SPR_SR_CY | SPR_SR_OV,
177
                  0x3fffffff, 0x40000000, 0xffffffff,
178
                  TRUE, FALSE)
179
 
180
        /* Subtract two large negative numbers with a positive result. Should
181
           set niether the carry nor the overflow flag. */
182
        TEST_SUB (0, SPR_SR_CY | SPR_SR_OV,
183
                  0x40000000, 0x3fffffff, 0x00000001,
184
                  FALSE, FALSE)
185
 
186
        /* Subtract a large positive from a large negative number. Should set
187
           overflow but not the carry flag. */
188
        TEST_SUB (0, SPR_SR_CY | SPR_SR_OV,
189
                  0x80000000, 0x7fffffff, 0x00000001,
190
                  FALSE, TRUE)
191
 
192
        /* Subtract a large negative from a large positive number. Should set
193
           both the overflow and carry flags. */
194
        TEST_SUB (0, SPR_SR_CY | SPR_SR_OV,
195
                  0x7fffffff, 0x80000000, 0xffffffff,
196
                  TRUE, TRUE)
197
 
198
        /* Check that range exceptions are triggered */
199
        l.mfspr r3,r0,SPR_SR
200
        LOAD_CONST (r2, SPR_SR_OVE)     /* Set OVE */
201
        l.or    r3,r3,r2
202
        l.mtspr r0,r3,SPR_SR
203
 
204
        LOAD_STR (r3, "  ** OVE flag set **\n")
205
        l.jal   _puts
206
        l.nop
207
 
208
        /* Check that an overflow alone causes a RANGE Exception. */
209
        TEST_SUB (0, SPR_SR_CY | SPR_SR_OV,
210
                  0x80000000, 0x7fffffff, 0x00000001,
211
                  FALSE, TRUE)
212
 
213
        /* Check that a carry alone does not cause a RANGE Exception. */
214
        TEST_SUB (0, SPR_SR_CY | SPR_SR_OV,
215
                  0x3fffffff, 0x40000000, 0xffffffff,
216
                  TRUE, FALSE)
217
 
218
        /* Check that carry and overflow together cause an exception. */
219
        TEST_SUB (0, SPR_SR_CY | SPR_SR_OV,
220
                  0x7fffffff, 0x80000000, 0xffffffff,
221
                  TRUE, TRUE)
222
 
223
        /* Finished checking range exceptions */
224
        l.mfspr r3,r0,SPR_SR
225
        LOAD_CONST (r2, ~SPR_SR_OVE)    /* Clear OVE */
226
        l.and   r3,r3,r2
227
        l.mtspr r0,r3,SPR_SR
228
 
229
        LOAD_STR (r3, "  ** OVE flag cleared **\n")
230
        l.jal   _puts
231
        l.nop
232
 
233
/* ----------------------------------------------------------------------------
234
 * All done
235
 * ------------------------------------------------------------------------- */
236
_exit:
237
        LOAD_STR (r3, "Test completed\n")
238
        l.jal   _puts
239
        l.nop
240
 
241
        TEST_EXIT

powered by: WebSVN 2.1.0

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