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

Subversion Repositories fwrisc

[/] [fwrisc/] [trunk/] [ve/] [fwrisc/] [tests/] [fwrisc_instr_tests_ldst.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mballance
/*
2
 * fwrisc_instr_tests_ldst.cpp
3
 *
4
 *
5
 * Copyright 2018 Matthew Ballance
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the
8
 * "License"); you may not use this file except in
9
 * compliance with the License.  You may obtain a copy of
10
 * the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in
15
 * writing, software distributed under the License is
16
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17
 * CONDITIONS OF ANY KIND, either express or implied.  See
18
 * the License for the specific language governing
19
 * permissions and limitations under the License.
20
 *
21
 *  Created on: Oct 30, 2018
22
 *      Author: ballance
23
 */
24
 
25
#include "fwrisc_instr_tests_ldst.h"
26
 
27
fwrisc_instr_tests_ldst::fwrisc_instr_tests_ldst() {
28
        // TODO Auto-generated constructor stub
29
 
30
}
31
 
32
fwrisc_instr_tests_ldst::~fwrisc_instr_tests_ldst() {
33
        // TODO Auto-generated destructor stub
34
}
35
 
36
TEST_F(fwrisc_instr_tests_ldst, lb) {
37
        reg_val_s exp[] = {
38
                        {1, 0},
39
                        {2, 0x04},
40
                        {3, 0x03},
41
                        {4, 0x02},
42
                        {5, 0x01},
43
        };
44
        const char *program = R"(
45
                entry:
46
                        la              x1, data
47
                        lb              x2, 0(x1)
48
                        lb              x3, 1(x1)
49
                        lb              x4, 2(x1)
50
                        lb              x5, 3(x1)
51
                        li              x1, 0
52
                        j               done
53
                data:
54
                        .word 0x01020304
55
                        .word 0x05060708
56
                        )";
57
 
58
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
59
}
60
 
61
TEST_F(fwrisc_instr_tests_ldst, lb_u) {
62
        reg_val_s exp[] = {
63
                        {1, 0},
64
                        {2, 0x04},
65
                        {3, 0x03},
66
        };
67
        const char *program = R"(
68
                entry:
69
                        la              x1, data
70
                        lb              x2, 0(x1)
71
                        lb              x3, 1(x1)
72
                        li              x1, 0
73
                        j               done
74
                data:
75
                        .word 0x01020304
76
                        .word 0x05060708
77
                        )";
78
 
79
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
80
}
81
 
82
TEST_F(fwrisc_instr_tests_ldst, lb_s) {
83
        reg_val_s exp[] = {
84
                        {1, 0},
85
                        {2, 0xFFFFFF84},
86
                        {3, 0xFFFFFF83},
87
        };
88
        const char *program = R"(
89
                entry:
90
                        la              x1, data
91
                        lb              x2, 0(x1)
92
                        lb              x3, 1(x1)
93
                        li              x1, 0
94
                        j               done
95
                data:
96
                        .word 0x81828384
97
                        .word 0x05060708
98
                        )";
99
 
100
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
101
}
102
 
103
TEST_F(fwrisc_instr_tests_ldst, lh_u) {
104
        reg_val_s exp[] = {
105
                        {1, 0},
106
                        {2, 0x0304},
107
                        {3, 0x0102},
108
        };
109
        const char *program = R"(
110
                entry:
111
                        la              x1, data
112
                        lh              x2, 0(x1)
113
                        lh              x3, 2(x1)
114
                        li              x1, 0
115
                        j               done
116
                data:
117
                        .word 0x01020304
118
                        .word 0x05060708
119
                        )";
120
 
121
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
122
}
123
 
124
TEST_F(fwrisc_instr_tests_ldst, lh_s) {
125
        reg_val_s exp[] = {
126
                        {1, 0},
127
                        {2, 0xFFFF8384},
128
                        {3, 0xFFFF8182},
129
        };
130
        const char *program = R"(
131
                entry:
132
                        la              x1, data
133
                        lh              x2, 0(x1)
134
                        lh              x3, 2(x1)
135
                        li              x1, 0
136
                        j               done
137
                data:
138
                        .word 0x81828384
139
                        .word 0x05060708
140
                        )";
141
 
142
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
143
}
144
 
145
TEST_F(fwrisc_instr_tests_ldst, lhu_s) {
146
        reg_val_s exp[] = {
147
                        {1, 0},
148
                        {2, 0x00008384},
149
                        {3, 0x00008182},
150
        };
151
        const char *program = R"(
152
                entry:
153
                        la              x1, data  // 0x08
154
                        lhu             x2, 0(x1) // 0x0C
155
                        lhu             x3, 2(x1) // 0x10
156
                        li              x1, 0     // 0x14
157
                        j               done
158
                data:
159
                        .word 0x81828384
160
                        .word 0x05060708
161
                        )";
162
 
163
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
164
}
165
 
166
TEST_F(fwrisc_instr_tests_ldst, lw) {
167
        reg_val_s exp[] = {
168
                        {1, 0},
169
                        {2, 0x01020304},
170
                        {3, 0x05060708},
171
        };
172
        const char *program = R"(
173
                entry:
174
                        la              x1, data
175
                        lw              x2, 0(x1)
176
                        lw              x3, 4(x1)
177
                        li              x1, 0
178
                        j               done
179
                data:
180
                        .word 0x01020304
181
                        .word 0x05060708
182
                        )";
183
 
184
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
185
}
186
 
187
TEST_F(fwrisc_instr_tests_ldst, sw_lw) {
188
        reg_val_s exp[] = {
189
                        {1, 0x00000000},
190
                        {2, 0x55aaeeff},
191
                        {3, 0x55aaeeff}
192
        };
193
        const char *program = R"(
194
                entry:
195
                        la              x1, data
196
                        li              x2, 0x55aaeeff
197
                        sw              x2, 0(x1)
198
                        lw              x3, 0(x1)
199
                        li              x1, 0
200
                        j               done
201
                data:
202
                        .word 0x01020304
203
                        .word 0x05060708
204
                        )";
205
 
206
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
207
}
208
 
209
TEST_F(fwrisc_instr_tests_ldst, sb_lw) {
210
        reg_val_s exp[] = {
211
                        {1, 0x00000000},
212
                        {2, 0x00000055},
213
                        {3, 0x55aaeeff}
214
        };
215
        const char *program = R"(
216
                entry:
217
                        la              x1, data
218
                        li              x2, 0xff
219
                        sb              x2, 0(x1)
220
                        li              x2, 0xee
221
                        sb              x2, 1(x1)
222
                        li              x2, 0xaa
223
                        sb              x2, 2(x1)
224
                        li              x2, 0x55
225
                        sb              x2, 3(x1)
226
                        lw              x3, 0(x1)
227
                        li              x1, 0
228
                        j               done
229
                data:
230
                        .word 0x01020304
231
                        .word 0x05060708
232
                        )";
233
 
234
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
235
}
236
 
237
TEST_F(fwrisc_instr_tests_ldst, sh_lw) {
238
        reg_val_s exp[] = {
239
                        {1, 0x00000000},
240
                        {2, 0x000055aa},
241
                        {3, 0x55aaeeff}
242
        };
243
        const char *program = R"(
244
                entry:
245
                        la              x1, data
246
                        li              x2, 0xeeff
247
                        sh              x2, 0(x1)
248
                        li              x2, 0x55aa
249
                        sh              x2, 2(x1)
250
                        lw              x3, 0(x1)
251
                        li              x1, 0
252
                        j               done
253
                data:
254
                        .word 0x01020304
255
                        .word 0x05060708
256
                        )";
257
 
258
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
259
}

powered by: WebSVN 2.1.0

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