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

Subversion Repositories fwrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mballance
/*
2
 * fwrisc_instr_tests_branch.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 29, 2018
22
 *      Author: ballance
23
 */
24
 
25
#include "fwrisc_instr_tests_branch.h"
26
 
27
fwrisc_instr_tests_branch::fwrisc_instr_tests_branch() {
28
        // TODO Auto-generated constructor stub
29
 
30
}
31
 
32
fwrisc_instr_tests_branch::~fwrisc_instr_tests_branch() {
33
        // TODO Auto-generated destructor stub
34
}
35
 
36
TEST_F(fwrisc_instr_tests_branch, beq_t_fwd) {
37
        reg_val_s exp[] = {
38
                        {1, 5},
39
                        {2, 5},
40
                        {3, 24} // r1==r2
41
        };
42
        const char *program = R"(
43
                entry:
44
                        li              x1, 5
45
                        li              x2, 5
46
                        beq             x1, x2, 1f
47
                        li              x3, 20
48
                        j               done
49
                1:
50
                        li              x3, 24
51
                        j               done
52
                        )";
53
 
54
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
55
}
56
 
57
TEST_F(fwrisc_instr_tests_branch, beq_t_back) {
58
        reg_val_s exp[] = {
59
                        {1, 5},
60
                        {2, 5},
61
                        {3, 24} // r1==r2
62
        };
63
        const char *program = R"(
64
                entry:
65
                        j               t_start
66
                        li              x3, 20
67
                        j               done
68
                1:
69
                        li              x3, 24
70
                        j               done
71
                t_start:
72
                        li              x1, 5
73
                        li              x2, 5
74
                        beq             x1, x2, 1b
75
                2: // fail
76
                        li              x3, 20
77
                        j               done
78
                        )";
79
 
80
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
81
}
82
 
83
TEST_F(fwrisc_instr_tests_branch, beq_f_fwd) {
84
        reg_val_s exp[] = {
85
                        {1, 5},
86
                        {2, 6},
87
                        {3, 24} // r1==r2
88
        };
89
        const char *program = R"(
90
                entry:
91
                        li              x1, 5
92
                        li              x2, 6
93
                        beq             x1, x2, 1f
94
                        li              x3, 24
95
                        j               done
96
                1:
97
                        li              x3, 20
98
                        j               done
99
                        )";
100
 
101
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
102
}
103
 
104
TEST_F(fwrisc_instr_tests_branch, beq_f_back) {
105
        reg_val_s exp[] = {
106
                        {1, 5},
107
                        {2, 6},
108
                        {3, 24} // r1==r2
109
        };
110
        const char *program = R"(
111
                entry:
112
                        j               t_start
113
                        li              x3, 20
114
                        j               done
115
                1:
116
                        li              x3, 20
117
                        j               done
118
                t_start:
119
                        li              x1, 5
120
                        li              x2, 6
121
                        beq             x1, x2, 1b
122
                2: // pass: x1!=x2
123
                        li              x3, 24
124
                        j               done
125
                        )";
126
 
127
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
128
}
129
 
130
TEST_F(fwrisc_instr_tests_branch, bge_eq_t_pos) {
131
        reg_val_s exp[] = {
132
                        {1, 5},
133
                        {2, 5},
134
                        {3, 24} // r1==r2
135
        };
136
        const char *program = R"(
137
                entry:
138
                        li              x1, 5
139
                        li              x2, 5
140
                        bge             x1, x2, 1f
141
                        li              x3, 20
142
                        j               done
143
                1:
144
                        li              x3, 24
145
                        j               done
146
                        )";
147
 
148
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
149
}
150
 
151
TEST_F(fwrisc_instr_tests_branch, bge_gt_t_pos) {
152
        reg_val_s exp[] = {
153
                        {1, 6},
154
                        {2, 5},
155
                        {3, 24} // r1==r2
156
        };
157
        const char *program = R"(
158
                entry:
159
                        li              x1, 6
160
                        li              x2, 5
161
                        bge             x1, x2, 1f
162
                        li              x3, 20
163
                        j               done
164
                1:
165
                        li              x3, 24
166
                        j               done
167
                        )";
168
 
169
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
170
}
171
 
172
TEST_F(fwrisc_instr_tests_branch, bge_gt_t_neg) {
173
        reg_val_s exp[] = {
174
                        {1, -5},
175
                        {2, -6},
176
                        {3, 24} // r1==r2
177
        };
178
        const char *program = R"(
179
                entry:
180
                        li              x1, -5
181
                        li              x2, -6
182
                        bge             x1, x2, 1f
183
                        li              x3, 20
184
                        j               done
185
                1:
186
                        li              x3, 24
187
                        j               done
188
                        )";
189
 
190
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
191
}
192
 
193
TEST_F(fwrisc_instr_tests_branch, bge_eq_t_neg) {
194
        reg_val_s exp[] = {
195
                        {1, -5},
196
                        {2, -5},
197
                        {3, 24} // r1==r2
198
        };
199
        const char *program = R"(
200
                entry:
201
                        li              x1, -5
202
                        li              x2, -5
203
                        bge             x1, x2, 1f
204
                        li              x3, 20
205
                        j               done
206
                1:
207
                        li              x3, 24
208
                        j               done
209
                        )";
210
 
211
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
212
}
213
 
214
TEST_F(fwrisc_instr_tests_branch, blt_t_pos) {
215
        reg_val_s exp[] = {
216
                        {1, 5},
217
                        {2, 6},
218
                        {3, 24} // r1==r2
219
        };
220
        const char *program = R"(
221
                entry:
222
                        li              x1, 5
223
                        li              x2, 6
224
                        blt             x1, x2, 1f
225
                        li              x3, 20
226
                        j               done
227
                1:
228
                        li              x3, 24
229
                        j               done
230
                        )";
231
 
232
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
233
}
234
 
235
TEST_F(fwrisc_instr_tests_branch, blt_t_neg) {
236
        reg_val_s exp[] = {
237
                        {1, -6},
238
                        {2, -5},
239
                        {3, 24} // r1==r2
240
        };
241
        const char *program = R"(
242
                entry:
243
                        li              x1, -6
244
                        li              x2, -5
245
                        blt             x1, x2, 1f
246
                        li              x3, 20
247
                        j               done
248
                1:
249
                        li              x3, 24
250
                        j               done
251
                        )";
252
 
253
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
254
}
255
 
256
TEST_F(fwrisc_instr_tests_branch, bltu_t_pos) {
257
        reg_val_s exp[] = {
258
                        {1, 5},
259
                        {2, 6},
260
                        {3, 24} // r1==r2
261
        };
262
        const char *program = R"(
263
                entry:
264
                        li              x1, 5
265
                        li              x2, 6
266
                        bltu    x1, x2, 1f
267
                        li              x3, 20
268
                        j               done
269
                1:
270
                        li              x3, 24
271
                        j               done
272
                        )";
273
 
274
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
275
}
276
 
277
TEST_F(fwrisc_instr_tests_branch, bltu_t_neg) {
278
        reg_val_s exp[] = {
279
                        {1, 0x80000000},
280
                        {2, 0x80000001},
281
                        {3, 24} // r1==r2
282
        };
283
        const char *program = R"(
284
                entry:
285
                        li              x1, 0x80000000
286
                        li              x2, 0x80000001
287
                        bltu    x1, x2, 1f
288
                        li              x3, 20
289
                        j               done
290
                1:
291
                        li              x3, 24
292
                        j               done
293
                        )";
294
 
295
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
296
}
297
 
298
TEST_F(fwrisc_instr_tests_branch, bne_t_fwd) {
299
        reg_val_s exp[] = {
300
                        {1, 5},
301
                        {2, 6},
302
                        {3, 24} // r1==r2
303
        };
304
        const char *program = R"(
305
                entry:
306
                        li              x1, 5
307
                        li              x2, 6
308
                        bne             x1, x2, 1f
309
                        li              x3, 20
310
                        j               done
311
                1:
312
                        li              x3, 24
313
                        j               done
314
                        )";
315
 
316
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
317
}
318
 
319
TEST_F(fwrisc_instr_tests_branch, bne_t_back) {
320
        reg_val_s exp[] = {
321
                        {1, 5},
322
                        {2, 6},
323
                        {3, 24} // r1==r2
324
        };
325
        const char *program = R"(
326
                entry:
327
                        j               t_start
328
                        li              x3, 20
329
                        j               done
330
                1:
331
                        li              x3, 24
332
                        j               done
333
                t_start:
334
                        li              x1, 5
335
                        li              x2, 6
336
                        bne             x1, x2, 1b
337
                2: // fail
338
                        li              x3, 20
339
                        j               done
340
                        )";
341
 
342
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
343
}
344
 
345
TEST_F(fwrisc_instr_tests_branch, bne_f_fwd) {
346
        reg_val_s exp[] = {
347
                        {1, 5},
348
                        {2, 5},
349
                        {3, 24} // r1==r2
350
        };
351
        const char *program = R"(
352
                entry:
353
                        li              x1, 5
354
                        li              x2, 5
355
                        bne             x1, x2, 1f
356
                        li              x3, 24
357
                        j               done
358
                1:
359
                        li              x3, 20
360
                        j               done
361
                        )";
362
 
363
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
364
}
365
 
366
TEST_F(fwrisc_instr_tests_branch, bne_f_back) {
367
        reg_val_s exp[] = {
368
                        {1, 5},
369
                        {2, 5},
370
                        {3, 24} // r1==r2
371
        };
372
        const char *program = R"(
373
                entry:
374
                        j               t_start
375
                        li              x3, 20
376
                        j               done
377
                1:
378
                        li              x3, 20
379
                        j               done
380
                t_start:
381
                        li              x1, 5
382
                        li              x2, 5
383
                        bne             x1, x2, 1b
384
                2: // pass: x1!=x2
385
                        li              x3, 24
386
                        j               done
387
                        )";
388
 
389
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
390
}

powered by: WebSVN 2.1.0

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