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

Subversion Repositories fwrisc

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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