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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 124 jeremybenn
/* is-xor-test.S. l.xor and l.xori 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.xor and l.xori instructions should never set the carry and overflow
33
 * flags.
34
 *
35
 * Problems in this area were reported in Bugs 1782, 1783 and 1784. Having
36
 * fixed the problem, this is (in good software engineering style), a
37
 * regression test to go with the fix.
38
 *
39
 * This is not a comprehensive test of any instruction (yet).
40
 *
41
 * Of course what is really needed is a comprehensive instruction test...
42
 * ------------------------------------------------------------------------- */
43
 
44
 
45
#include "inst-set-test.h"
46
 
47
/* A macro to sign extend a 16-bit value */
48
#define SE(v) (v | ((v & 0x8000) <<  1) | \
49
                   ((v & 0x8000) <<  2) | \
50
                   ((v & 0x8000) <<  3) | \
51
                   ((v & 0x8000) <<  4) | \
52
                   ((v & 0x8000) <<  5) | \
53
                   ((v & 0x8000) <<  6) | \
54
                   ((v & 0x8000) <<  7) | \
55
                   ((v & 0x8000) <<  8) | \
56
                   ((v & 0x8000) <<  9) | \
57
                   ((v & 0x8000) << 10) | \
58
                   ((v & 0x8000) << 11) | \
59
                   ((v & 0x8000) << 12) | \
60
                   ((v & 0x8000) << 13) | \
61
                   ((v & 0x8000) << 14) | \
62
                   ((v & 0x8000) << 15) | \
63
                   ((v & 0x8000) << 16) )
64
 
65
/* ----------------------------------------------------------------------------
66
 * A macro to carry out a test of bitwise XOR in registers
67
 *
68
 * This opcode should never set the flags. Result is compared with the native
69
 * computed value.
70
 *
71
 * Arguments
72
 *   op1:       First operand value
73
 *   op2:       Second operand value
74
 * ------------------------------------------------------------------------- */
75
#define TEST_XOR(op1, op2)                                               \
76
        l.mfspr r3,r0,SPR_SR            /* Clear flags */               ;\
77
        LOAD_CONST (r2, ~(SPR_SR_CY | SPR_SR_OV))                       ;\
78
        l.and   r3,r3,r2                                                ;\
79
        l.mtspr r0,r3,SPR_SR                                            ;\
80
                                                                        ;\
81
        LOAD_CONST (r5,op1)             /* Load operands */             ;\
82
        LOAD_CONST (r6,op2)                                             ;\
83
        l.mtspr r0,r0,SPR_EPCR_BASE     /* Clear record */              ;\
84
50:     l.xor   r4,r5,r6                                                ;\
85
        l.mfspr r2,r0,SPR_SR            /* So we can examine flags */   ;\
86
        l.mfspr r5,r0,SPR_EPCR_BASE     /* What triggered exception */  ;\
87
        PUSH (r5)                       /* Save EPCR for later */       ;\
88
        PUSH (r2)                       /* Save SR for later */         ;\
89
        PUSH (r4)                       /* Save result for later */     ;\
90
                                                                        ;\
91
        PUTS ("  0x")                                                   ;\
92
        PUTH (op1)                                                      ;\
93
        PUTS (" ^ 0x")                                                  ;\
94
        PUTH (op2)                                                      ;\
95
        PUTS (" = 0x")                                                  ;\
96
        PUTH (op1 ^ op2)                                                ;\
97
        PUTS (": ")                                                     ;\
98
        POP (r4)                                                        ;\
99
        CHECK_RES1 (r4, op1 ^ op2)                                      ;\
100
                                                                        ;\
101
        POP(r2)                         /* Retrieve SR */               ;\
102
        PUSH(r2)                                                        ;\
103
        LOAD_CONST (r4, SPR_SR_CY)      /* The carry bit */             ;\
104
        l.and   r2,r2,r4                                                ;\
105
        l.sfeq  r2,r4                                                   ;\
106
        CHECK_FLAG ("- carry flag set:      ", FALSE)                   ;\
107
                                                                        ;\
108
        POP(r2)                         /* Retrieve SR */               ;\
109
        LOAD_CONST (r4, SPR_SR_OV)      /* The overflow bit */          ;\
110
        l.and   r2,r2,r4                                                ;\
111
        l.sfeq  r2,r4                                                   ;\
112
        CHECK_FLAG ("- overflow flag set:   ", FALSE)                   ;\
113
                                                                        ;\
114
        POP (r2)                        /* Retrieve EPCR */             ;\
115
        LOAD_CONST (r4, 50b)            /* The opcode of interest */    ;\
116
        l.and   r2,r2,r4                                                ;\
117
        l.sfeq  r2,r4                                                   ;\
118
        l.bnf   51f                                                     ;\
119
                                                                        ;\
120
        PUTS ("  - exception triggered: TRUE\n")                        ;\
121
        l.j     52f                                                     ;\
122
        l.nop                                                           ;\
123
                                                                        ;\
124
51:     PUTS ("  - exception triggered: FALSE\n")                       ;\
125
52:
126
 
127
 
128
/* ----------------------------------------------------------------------------
129
 * A macro to carry out a test of bitwise XOR with an immediate operand
130
 *
131
 * This opcode should never set the flags. Result is compared with the native
132
 * computed value. Note that the OR1K architecture specfies that the immediate
133
 * operand is sign-extended, not zero-extended.
134
 *
135
 * Arguments
136
 *   op1:       First operand value
137
 *   op2:       Second operand value
138
 * ------------------------------------------------------------------------- */
139
#define TEST_XORI(op1, op2)                                              \
140
        l.mfspr r3,r0,SPR_SR            /* Clear flags */               ;\
141
        LOAD_CONST (r2, ~(SPR_SR_CY | SPR_SR_OV))                       ;\
142
        l.and   r3,r3,r2                                                ;\
143
        l.mtspr r0,r3,SPR_SR                                            ;\
144
                                                                        ;\
145
        LOAD_CONST (r5,op1)             /* Load operands */             ;\
146
        l.mtspr r0,r0,SPR_EPCR_BASE     /* Clear record */              ;\
147
53:     l.xori  r4,r5,op2                                               ;\
148
        l.mfspr r2,r0,SPR_SR            /* So we can examine flags */   ;\
149
        l.mfspr r5,r0,SPR_EPCR_BASE     /* What triggered exception */  ;\
150
        PUSH (r5)                       /* Save EPCR for later */       ;\
151
        PUSH (r2)                       /* Save SR for later */         ;\
152
        PUSH (r4)                       /* Save result for later */     ;\
153
                                                                        ;\
154
        PUTS ("  0x")                                                   ;\
155
        PUTH (op1)                                                      ;\
156
        PUTS (" ^ 0x")                                                  ;\
157
        PUTHH (op2)                                                     ;\
158
        PUTS (" = 0x")                                                  ;\
159
        PUTH (op1 ^ SE (op2))                                           ;\
160
        PUTS (": ")                                                     ;\
161
        POP (r4)                                                        ;\
162
        CHECK_RES1 (r4, op1 ^ SE (op2))                                 ;\
163
                                                                        ;\
164
        POP(r2)                         /* Retrieve SR */               ;\
165
        PUSH(r2)                                                        ;\
166
        LOAD_CONST (r4, SPR_SR_CY)      /* The carry bit */             ;\
167
        l.and   r2,r2,r4                                                ;\
168
        l.sfeq  r2,r4                                                   ;\
169
        CHECK_FLAG ("- carry flag set:      ", FALSE)                   ;\
170
                                                                        ;\
171
        POP(r2)                         /* Retrieve SR */               ;\
172
        LOAD_CONST (r4, SPR_SR_OV)      /* The overflow bit */          ;\
173
        l.and   r2,r2,r4                                                ;\
174
        l.sfeq  r2,r4                                                   ;\
175
        CHECK_FLAG ("- overflow flag set:   ", FALSE)                   ;\
176
                                                                        ;\
177
        POP (r2)                        /* Retrieve EPCR */             ;\
178
        LOAD_CONST (r4, 53b)            /* The opcode of interest */    ;\
179
        l.and   r2,r2,r4                                                ;\
180
        l.sfeq  r2,r4                                                   ;\
181
        l.bnf   54f                                                     ;\
182
                                                                        ;\
183
        PUTS ("  - exception triggered: TRUE\n")                        ;\
184
        l.j     55f                                                     ;\
185
        l.nop                                                           ;\
186
                                                                        ;\
187
54:     PUTS ("  - exception triggered: FALSE\n")                       ;\
188
55:
189
 
190
 
191
/* ----------------------------------------------------------------------------
192
 * Start of code
193
 * ------------------------------------------------------------------------- */
194
        .section .text
195
        .global _start
196
_start:
197
        /* Always set OVE. We should never trigger an exception, even if this
198
           bit is set. */
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
/* ----------------------------------------------------------------------------
209
 * Test of xor, l.xor
210
 * ------------------------------------------------------------------------- */
211
_xor:
212
        LOAD_STR (r3, "l.xor\n")
213
        l.jal   _puts
214
        l.nop
215
 
216
        /* Test a range of operands */
217
        TEST_XOR (0x00000000, 0x00000000)
218
        TEST_XOR (0xffffffff, 0xffffffff)
219
        TEST_XOR (0xaaaaaaaa, 0x00000000)
220
        TEST_XOR (0xaaaaaaaa, 0xaaaaaaaa)
221
        TEST_XOR (0x55555555, 0x00000000)
222
        TEST_XOR (0x55555555, 0x55555555)
223
        TEST_XOR (0xaaaaaaaa, 0x55555555)
224
        TEST_XOR (0x4c70f07c, 0xb38f0f83)
225
        TEST_XOR (0x4c70f07c, 0xc4c70f07)
226
        TEST_XOR (0xb38f0f83, 0x38f0f83b)
227
 
228
/* ----------------------------------------------------------------------------
229
 * Test of xor with immediate half word, l.xori
230
 * ------------------------------------------------------------------------- */
231
_xori:
232
        LOAD_STR (r3, "l.xori\n")
233
        l.jal   _puts
234
        l.nop
235
 
236
        /* Test a range of operands */
237
        TEST_XORI (0x00000000, 0x0000)
238
        TEST_XORI (0xffffffff, 0xffff)
239
        TEST_XORI (0xaaaaaaaa, 0x0000)
240
        TEST_XORI (0xaaaaaaaa, 0xaaaa)
241
        TEST_XORI (0x55555555, 0x0000)
242
        TEST_XORI (0x55555555, 0x5555)
243
        TEST_XORI (0xaaaaaaaa, 0x5555)
244
        TEST_XORI (0x4c70f07c, 0x0f83)
245
        TEST_XORI (0x4c70f07c, 0x0f07)
246
        TEST_XORI (0xb38f0f83, 0xf83b)
247
 
248
/* ----------------------------------------------------------------------------
249
 * All done
250
 * ------------------------------------------------------------------------- */
251
_exit:
252
        LOAD_STR (r3, "Test completed\n")
253
        l.jal   _puts
254
        l.nop
255
 
256
        TEST_EXIT

powered by: WebSVN 2.1.0

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