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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 124 jeremybenn
/* is-and-test.S. l.and and l.andi 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.and and l.andi 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
/* ----------------------------------------------------------------------------
48
 * A macro to carry out a test of bitwise AND in registers
49
 *
50
 * This opcode should never set the flags. Result is compared with the native
51
 * computed value.
52
 *
53
 * Arguments
54
 *   op1:       First operand value
55
 *   op2:       Second operand value
56
 * ------------------------------------------------------------------------- */
57
#define TEST_AND(op1, op2)                                               \
58
        l.mfspr r3,r0,SPR_SR            /* Clear flags */               ;\
59
        LOAD_CONST (r2, ~(SPR_SR_CY | SPR_SR_OV))                       ;\
60
        l.and   r3,r3,r2                                                ;\
61
        l.mtspr r0,r3,SPR_SR                                            ;\
62
                                                                        ;\
63
        LOAD_CONST (r5,op1)             /* Load operands */             ;\
64
        LOAD_CONST (r6,op2)                                             ;\
65
        l.mtspr r0,r0,SPR_EPCR_BASE     /* Clear record */              ;\
66
50:     l.and   r4,r5,r6                                                ;\
67
        l.mfspr r2,r0,SPR_SR            /* So we can examine flags */   ;\
68
        l.mfspr r5,r0,SPR_EPCR_BASE     /* What triggered exception */  ;\
69
        PUSH (r5)                       /* Save EPCR for later */       ;\
70
        PUSH (r2)                       /* Save SR for later */         ;\
71
        PUSH (r4)                       /* Save result for later */     ;\
72
                                                                        ;\
73
        PUTS ("  0x")                                                   ;\
74
        PUTH (op1)                                                      ;\
75
        PUTS (" & 0x")							;\
76
        PUTH (op2)                                                      ;\
77
        PUTS (" = 0x")                                                  ;\
78
        PUTH (op1 & op2)						;\
79
        PUTS (": ")                                                     ;\
80
        POP (r4)                                                        ;\
81
        CHECK_RES1 (r4, op1 & op2)					;\
82
                                                                        ;\
83
        POP(r2)                         /* Retrieve SR */               ;\
84
        PUSH(r2)                                                        ;\
85
        LOAD_CONST (r4, SPR_SR_CY)      /* The carry bit */             ;\
86
        l.and   r2,r2,r4                                                ;\
87
        l.sfeq  r2,r4                                                   ;\
88
        CHECK_FLAG ("- carry flag set:      ", FALSE)                   ;\
89
                                                                        ;\
90
        POP(r2)                         /* Retrieve SR */               ;\
91
        LOAD_CONST (r4, SPR_SR_OV)      /* The overflow bit */          ;\
92
        l.and   r2,r2,r4                                                ;\
93
        l.sfeq  r2,r4                                                   ;\
94
        CHECK_FLAG ("- overflow flag set:   ", FALSE)                   ;\
95
                                                                        ;\
96
        POP (r2)                        /* Retrieve EPCR */             ;\
97
        LOAD_CONST (r4, 50b)            /* The opcode of interest */    ;\
98
        l.and   r2,r2,r4                                                ;\
99
        l.sfeq  r2,r4                                                   ;\
100
        l.bnf   51f                                                     ;\
101
                                                                        ;\
102
        PUTS ("  - exception triggered: TRUE\n")                        ;\
103
        l.j     52f                                                     ;\
104
        l.nop                                                           ;\
105
                                                                        ;\
106
51:     PUTS ("  - exception triggered: FALSE\n")                       ;\
107
52:
108
 
109
 
110
/* ----------------------------------------------------------------------------
111
 * A macro to carry out a test of bitwise AND with an immediate operand
112
 *
113
 * This opcode should never set the flags. Result is compared with the native
114
 * computed value.
115
 *
116
 * Arguments
117
 *   op1:       First operand value
118
 *   op2:       Second operand value
119
 * ------------------------------------------------------------------------- */
120
#define TEST_ANDI(op1, op2)                                              \
121
        l.mfspr r3,r0,SPR_SR            /* Clear flags */               ;\
122
        LOAD_CONST (r2, ~(SPR_SR_CY | SPR_SR_OV))                       ;\
123
        l.and   r3,r3,r2                                                ;\
124
        l.mtspr r0,r3,SPR_SR                                            ;\
125
                                                                        ;\
126
        LOAD_CONST (r5,op1)             /* Load operands */             ;\
127
        l.mtspr r0,r0,SPR_EPCR_BASE     /* Clear record */              ;\
128
53:     l.andi  r4,r5,op2                                               ;\
129
        l.mfspr r2,r0,SPR_SR            /* So we can examine flags */   ;\
130
        l.mfspr r5,r0,SPR_EPCR_BASE     /* What triggered exception */  ;\
131
        PUSH (r5)                       /* Save EPCR for later */       ;\
132
        PUSH (r2)                       /* Save SR for later */         ;\
133
        PUSH (r4)                       /* Save result for later */     ;\
134
                                                                        ;\
135
        PUTS ("  0x")                                                   ;\
136
        PUTH (op1)                                                      ;\
137
        PUTS (" & 0x")							;\
138
        PUTHH (op2)                                                     ;\
139
        PUTS (" = 0x")                                                  ;\
140
        PUTH (op1 & op2)						;\
141
        PUTS (": ")                                                     ;\
142
        POP (r4)                                                        ;\
143
        CHECK_RES1 (r4, op1 & op2)					;\
144
                                                                        ;\
145
        POP(r2)                         /* Retrieve SR */               ;\
146
        PUSH(r2)                                                        ;\
147
        LOAD_CONST (r4, SPR_SR_CY)      /* The carry bit */             ;\
148
        l.and   r2,r2,r4                                                ;\
149
        l.sfeq  r2,r4                                                   ;\
150
        CHECK_FLAG ("- carry flag set:      ", FALSE)                   ;\
151
                                                                        ;\
152
        POP(r2)                         /* Retrieve SR */               ;\
153
        LOAD_CONST (r4, SPR_SR_OV)      /* The overflow bit */          ;\
154
        l.and   r2,r2,r4                                                ;\
155
        l.sfeq  r2,r4                                                   ;\
156
        CHECK_FLAG ("- overflow flag set:   ", FALSE)                   ;\
157
                                                                        ;\
158
        POP (r2)                        /* Retrieve EPCR */             ;\
159
        LOAD_CONST (r4, 53b)            /* The opcode of interest */    ;\
160
        l.and   r2,r2,r4                                                ;\
161
        l.sfeq  r2,r4                                                   ;\
162
        l.bnf   54f                                                     ;\
163
                                                                        ;\
164
        PUTS ("  - exception triggered: TRUE\n")                        ;\
165
        l.j     55f                                                     ;\
166
        l.nop                                                           ;\
167
                                                                        ;\
168
54:     PUTS ("  - exception triggered: FALSE\n")                       ;\
169
55:
170
 
171
 
172
/* ----------------------------------------------------------------------------
173
 * Start of code
174
 * ------------------------------------------------------------------------- */
175
        .section .text
176
        .global _start
177
_start:
178
        /* Always set OVE. We should never trigger an exception, even if this
179
           bit is set. */
180
        l.mfspr r3,r0,SPR_SR
181
        LOAD_CONST (r2, SPR_SR_OVE)     /* Set OVE */
182
        l.or    r3,r3,r2
183
        l.mtspr r0,r3,SPR_SR
184
 
185
        LOAD_STR (r3, "  ** OVE flag set **\n")
186
        l.jal   _puts
187
        l.nop
188
 
189
/* ----------------------------------------------------------------------------
190
 * Test of and, l.and
191
 * ------------------------------------------------------------------------- */
192
_and:
193
        LOAD_STR (r3, "l.and\n")
194
        l.jal   _puts
195
        l.nop
196
 
197
        /* Test a range of operands */
198
        TEST_AND (0x00000000, 0x00000000)
199
        TEST_AND (0xffffffff, 0xffffffff)
200
        TEST_AND (0xaaaaaaaa, 0x00000000)
201
        TEST_AND (0xaaaaaaaa, 0xaaaaaaaa)
202
        TEST_AND (0x55555555, 0x00000000)
203
        TEST_AND (0x55555555, 0x55555555)
204
        TEST_AND (0xaaaaaaaa, 0x55555555)
205
        TEST_AND (0x4c70f07c, 0xb38f0f83)
206
        TEST_AND (0x4c70f07c, 0xc4c70f07)
207
        TEST_AND (0xb38f0f83, 0x38f0f83b)
208
 
209
/* ----------------------------------------------------------------------------
210
 * Test of and with immediate half word, l.andi
211
 * ------------------------------------------------------------------------- */
212
_andi:
213
        LOAD_STR (r3, "l.andi\n")
214
        l.jal   _puts
215
        l.nop
216
 
217
        /* Test a range of operands */
218
        TEST_ANDI (0x00000000, 0x0000)
219
        TEST_ANDI (0xffffffff, 0xffff)
220
        TEST_ANDI (0xaaaaaaaa, 0x0000)
221
        TEST_ANDI (0xaaaaaaaa, 0xaaaa)
222
        TEST_ANDI (0x55555555, 0x0000)
223
        TEST_ANDI (0x55555555, 0x5555)
224
        TEST_ANDI (0xaaaaaaaa, 0x5555)
225
        TEST_ANDI (0x4c70f07c, 0x0f83)
226
        TEST_ANDI (0x4c70f07c, 0x0f07)
227
        TEST_ANDI (0xb38f0f83, 0xf83b)
228
 
229
/* ----------------------------------------------------------------------------
230
 * All done
231
 * ------------------------------------------------------------------------- */
232
_exit:
233
        LOAD_STR (r3, "Test completed\n")
234
        l.jal   _puts
235
        l.nop
236
 
237
        TEST_EXIT

powered by: WebSVN 2.1.0

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