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

Subversion Repositories yifive

[/] [yifive/] [trunk/] [caravel_yifive/] [verilog/] [rtl/] [syntacore/] [scr1/] [sim/] [tests/] [common/] [riscv_macros.h] - Blame information for rev 22

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 22 dinesha
// See LICENSE for license details.
2
 
3
#ifndef __RISCV_MACROS_H
4
#define __RISCV_MACROS_H
5
 
6
#include "riscv_csr_encoding.h"
7
#include "sc_test.h"
8
 
9
//-----------------------------------------------------------------------
10
// Begin Macro
11
//-----------------------------------------------------------------------
12
 
13
#define RVTEST_RV64U                                                    \
14
  .macro init;                                                          \
15
  .endm
16
 
17
#define RVTEST_RV64UF                                                   \
18
  .macro init;                                                          \
19
  RVTEST_FP_ENABLE;                                                     \
20
  .endm
21
 
22
#define RVTEST_RV32U                                                    \
23
  .macro init;                                                          \
24
  .endm
25
 
26
#define RVTEST_RV32UF                                                   \
27
  .macro init;                                                          \
28
  RVTEST_FP_ENABLE;                                                     \
29
  .endm
30
 
31
#define RVTEST_RV64M                                                    \
32
  .macro init;                                                          \
33
  RVTEST_ENABLE_MACHINE;                                                \
34
  .endm
35
 
36
#define RVTEST_RV64S                                                    \
37
  .macro init;                                                          \
38
  RVTEST_ENABLE_SUPERVISOR;                                             \
39
  .endm
40
 
41
#define RVTEST_RV32M                                                    \
42
  .macro init;                                                          \
43
  RVTEST_ENABLE_MACHINE;                                                \
44
  .endm
45
 
46
#define RVTEST_RV32S                                                    \
47
  .macro init;                                                          \
48
  RVTEST_ENABLE_SUPERVISOR;                                             \
49
  .endm
50
 
51
#if __riscv_xlen == 64
52
# define CHECK_XLEN li a0, 1; slli a0, a0, 31; bgez a0, 1f; RVTEST_PASS; 1:
53
#else
54
# define CHECK_XLEN li a0, 1; slli a0, a0, 31; bltz a0, 1f; RVTEST_PASS; 1:
55
#endif
56
 
57
#define INIT_PMP                                                        \
58
  la t0, 1f;                                                            \
59
  csrw mtvec, t0;                                                       \
60
  li t0, -1;        /* Set up a PMP to permit all accesses */           \
61
  csrw pmpaddr0, t0;                                                    \
62
  li t0, PMP_NAPOT | PMP_R | PMP_W | PMP_X;                             \
63
  csrw pmpcfg0, t0;                                                     \
64
  .balign 4;                                                             \
65
1:
66
 
67
#define INIT_SPTBR                                                      \
68
  la t0, 1f;                                                            \
69
  csrw mtvec, t0;                                                       \
70
  csrwi sptbr, 0;                                                       \
71
  .balign 4;                                                             \
72
1:
73
 
74
#define DELEGATE_NO_TRAPS
75
 
76
#define RVTEST_ENABLE_SUPERVISOR                                        \
77
  li a0, MSTATUS_MPP & (MSTATUS_MPP >> 1);                              \
78
  csrs mstatus, a0;                                                     \
79
  li a0, SIP_SSIP | SIP_STIP;                                           \
80
  csrs mideleg, a0;                                                     \
81
 
82
#define RVTEST_ENABLE_MACHINE                                           \
83
  li a0, MSTATUS_MPP;                                                   \
84
  csrs mstatus, a0;                                                     \
85
 
86
#define RVTEST_FP_ENABLE                                                \
87
  li a0, MSTATUS_FS & (MSTATUS_FS >> 1);                                \
88
  csrs mstatus, a0;                                                     \
89
  csrwi fcsr, 0
90
 
91
#define RISCV_MULTICORE_DISABLE                                         \
92
  csrr a0, mhartid;                                                     \
93
  1: bnez a0, 1b
94
 
95
#define EXTRA_TVEC_USER
96
#define EXTRA_TVEC_SUPERVISOR
97
#define EXTRA_TVEC_HYPERVISOR
98
#define EXTRA_TVEC_MACHINE
99
#define EXTRA_INIT
100
#define EXTRA_INIT_TIMER
101
 
102
#define INTERRUPT_HANDLER j other_exception /* No interrupts should occur */
103
 
104
#define RVTEST_CODE_BEGIN                                               \
105
        .section .text.init;                                            \
106
        .org 0xC0, 0x00;                                                \
107
        .balign  64;                                                    \
108
        .weak stvec_handler;                                            \
109
        .weak mtvec_handler;                                            \
110
trap_vector:                                                            \
111
        /* test whether the test came from pass/fail */                 \
112
        csrr a4, mcause;                                                \
113
        li a5, CAUSE_USER_ECALL;                                        \
114
        beq a4, a5, _report;                                            \
115
        li a5, CAUSE_SUPERVISOR_ECALL;                                  \
116
        beq a4, a5, _report;                                            \
117
        li a5, CAUSE_MACHINE_ECALL;                                     \
118
        beq a4, a5, _report;                                            \
119
        /* if an mtvec_handler is defined, jump to it */                \
120
        la a4, mtvec_handler;                                           \
121
        beqz a4, 1f;                                                    \
122
        jr a4;                                                          \
123
        /* was it an interrupt or an exception? */                      \
124
1:      csrr a4, mcause;                                                \
125
        bgez a4, handle_exception;                                      \
126
        INTERRUPT_HANDLER;                                              \
127
handle_exception:                                                       \
128
        /* we don't know how to handle whatever the exception was */    \
129
other_exception:                                                        \
130
        /* some unhandlable exception occurred */                       \
131
        li   a0, 0x1;                                                   \
132
_report:                                                                \
133
        j sc_exit;                                                      \
134
        .balign  64;                                                    \
135
        .globl _start;                                                  \
136
_start:                                                                 \
137
        RISCV_MULTICORE_DISABLE;                                        \
138
        /*INIT_SPTBR;*/                                                 \
139
        /*INIT_PMP;*/                                                   \
140
        DELEGATE_NO_TRAPS;                                              \
141
        li TESTNUM, 0;                                                  \
142
        la t0, trap_vector;                                             \
143
        csrw mtvec, t0;                                                 \
144
        CHECK_XLEN;                                                     \
145
        /* if an stvec_handler is defined, delegate exceptions to it */ \
146
        la t0, stvec_handler;                                           \
147
        beqz t0, 1f;                                                    \
148
        csrw stvec, t0;                                                 \
149
        li t0, (1 << CAUSE_LOAD_PAGE_FAULT) |                           \
150
               (1 << CAUSE_STORE_PAGE_FAULT) |                          \
151
               (1 << CAUSE_FETCH_PAGE_FAULT) |                          \
152
               (1 << CAUSE_MISALIGNED_FETCH) |                          \
153
               (1 << CAUSE_USER_ECALL) |                                \
154
               (1 << CAUSE_BREAKPOINT);                                 \
155
        csrw medeleg, t0;                                               \
156
        csrr t1, medeleg;                                               \
157
        bne t0, t1, other_exception;                                    \
158
1:      csrwi mstatus, 0;                                               \
159
        init;                                                           \
160
        EXTRA_INIT;                                                     \
161
        EXTRA_INIT_TIMER;                                               \
162
        la t0, _run_test;                                               \
163
        csrw mepc, t0;                                                  \
164
        csrr a0, mhartid;                                               \
165
        mret;                                                           \
166
        .section .text;                                                 \
167
_run_test:
168
 
169
//-----------------------------------------------------------------------
170
// End Macro
171
//-----------------------------------------------------------------------
172
 
173
#define RVTEST_CODE_END ecall: ecall
174
 
175
//-----------------------------------------------------------------------
176
// Pass/Fail Macro
177
//-----------------------------------------------------------------------
178
 
179
#define RVTEST_PASS                                                     \
180
        fence;                                                          \
181
        mv a1, TESTNUM;                                                 \
182
        li  a0, 0x0;                                                    \
183
        ecall
184
 
185
#define TESTNUM x28
186
#define RVTEST_FAIL                                                     \
187
        fence;                                                          \
188
        mv a1, TESTNUM;                                                 \
189
        li  a0, 0x1;                                                    \
190
        ecall
191
 
192
//-----------------------------------------------------------------------
193
// Data Section Macro
194
//-----------------------------------------------------------------------
195
 
196
#define EXTRA_DATA
197
 
198
#define RVTEST_DATA_BEGIN                                                       \
199
        EXTRA_DATA                                                              \
200
        .pushsection .tohost,"aw",@progbits;                                    \
201
        .balign 64; .global tohost; tohost: .dword 0;                           \
202
        .balign 64; .global fromhost; fromhost: .dword 0;                       \
203
        .popsection;                                                            \
204
        .balign 16;                                                             \
205
        .global begin_regstate;  begin_regstate: .dword 0; .dword 0; .dword 0;  \
206
        .balign 16;                                                             \
207
        .global begin_signature; begin_signature:
208
 
209
#define RVTEST_DATA_END .balign 16; .global end_signature; end_signature:
210
 
211
#-----------------------------------------------------------------------
212
# Helper macros
213
#-----------------------------------------------------------------------
214
 
215
#define MASK_XLEN(x) ((x) & ((1 << (__riscv_xlen - 1) << 1) - 1))
216
 
217
#define TEST_CASE( testnum, testreg, correctval, code... ) \
218
test_ ## testnum: \
219
    code; \
220
    li  x29, MASK_XLEN(correctval); \
221
    li  TESTNUM, testnum; \
222
    bne testreg, x29, fail;
223
 
224
# We use a macro hack to simpify code generation for various numbers
225
# of bubble cycles.
226
 
227
#define TEST_INSERT_NOPS_0
228
#define TEST_INSERT_NOPS_1  nop; TEST_INSERT_NOPS_0
229
#define TEST_INSERT_NOPS_2  nop; TEST_INSERT_NOPS_1
230
#define TEST_INSERT_NOPS_3  nop; TEST_INSERT_NOPS_2
231
#define TEST_INSERT_NOPS_4  nop; TEST_INSERT_NOPS_3
232
#define TEST_INSERT_NOPS_5  nop; TEST_INSERT_NOPS_4
233
#define TEST_INSERT_NOPS_6  nop; TEST_INSERT_NOPS_5
234
#define TEST_INSERT_NOPS_7  nop; TEST_INSERT_NOPS_6
235
#define TEST_INSERT_NOPS_8  nop; TEST_INSERT_NOPS_7
236
#define TEST_INSERT_NOPS_9  nop; TEST_INSERT_NOPS_8
237
#define TEST_INSERT_NOPS_10 nop; TEST_INSERT_NOPS_9
238
 
239
 
240
#-----------------------------------------------------------------------
241
# RV64UI MACROS
242
#-----------------------------------------------------------------------
243
 
244
#-----------------------------------------------------------------------
245
# Tests for instructions with immediate operand
246
#-----------------------------------------------------------------------
247
 
248
#define SEXT_IMM(x) ((x) | (-(((x) >> 11) & 1) << 11))
249
 
250
#define TEST_IMM_OP( testnum, inst, result, val1, imm ) \
251
    TEST_CASE( testnum, x3, result, \
252
      li  x1, MASK_XLEN(val1); \
253
      inst x3, x1, SEXT_IMM(imm); \
254
    )
255
 
256
#define TEST_IMM_OP_RVC( testnum, inst, result, val1, imm ) \
257
    TEST_CASE( testnum, x1, result, \
258
      li  x1, val1; \
259
      inst x1, imm; \
260
    )
261
 
262
#define TEST_IMM_SRC1_EQ_DEST( testnum, inst, result, val1, imm ) \
263
    TEST_CASE( testnum, x1, result, \
264
      li  x1, MASK_XLEN(val1); \
265
      inst x1, x1, SEXT_IMM(imm); \
266
    )
267
 
268
#define TEST_IMM_DEST_BYPASS( testnum, nop_cycles, inst, result, val1, imm ) \
269
    TEST_CASE( testnum, x6, result, \
270
      li  x4, 0; \
271
1:    li  x1, MASK_XLEN(val1); \
272
      inst x3, x1, SEXT_IMM(imm); \
273
      TEST_INSERT_NOPS_ ## nop_cycles \
274
      addi  x6, x3, 0; \
275
      addi  x4, x4, 1; \
276
      li  x5, 2; \
277
      bne x4, x5, 1b \
278
    )
279
 
280
#define TEST_IMM_SRC1_BYPASS( testnum, nop_cycles, inst, result, val1, imm ) \
281
    TEST_CASE( testnum, x3, result, \
282
      li  x4, 0; \
283
1:    li  x1, MASK_XLEN(val1); \
284
      TEST_INSERT_NOPS_ ## nop_cycles \
285
      inst x3, x1, SEXT_IMM(imm); \
286
      addi  x4, x4, 1; \
287
      li  x5, 2; \
288
      bne x4, x5, 1b \
289
    )
290
 
291
#define TEST_IMM_ZEROSRC1( testnum, inst, result, imm ) \
292
    TEST_CASE( testnum, x1, result, \
293
      inst x1, x0, SEXT_IMM(imm); \
294
    )
295
 
296
#define TEST_IMM_ZERODEST( testnum, inst, val1, imm ) \
297
    TEST_CASE( testnum, x0, 0, \
298
      li  x1, MASK_XLEN(val1); \
299
      inst x0, x1, SEXT_IMM(imm); \
300
    )
301
 
302
#-----------------------------------------------------------------------
303
# Tests for vector config instructions
304
#-----------------------------------------------------------------------
305
 
306
#define TEST_VSETCFGIVL( testnum, nxpr, nfpr, bank, vl, result ) \
307
    TEST_CASE( testnum, x1, result, \
308
      li x1, (bank << 12); \
309
      vsetcfg x1,nxpr,nfpr; \
310
      li x1, vl; \
311
      vsetvl x1,x1; \
312
    )
313
 
314
#define TEST_VVCFG( testnum, nxpr, nfpr, bank, vl, result ) \
315
    TEST_CASE( testnum, x1, result, \
316
      li x1, (bank << 12) | (nfpr << 6) | nxpr; \
317
      vsetcfg x1; \
318
      li x1, vl; \
319
      vsetvl x1,x1; \
320
    )
321
 
322
#define TEST_VSETVL( testnum, nxpr, nfpr, bank, vl, result ) \
323
    TEST_CASE( testnum, x1, result, \
324
      li x1, (bank << 12); \
325
      vsetcfg x1,nxpr,nfpr; \
326
      li x1, vl; \
327
      vsetvl x1, x1; \
328
    )
329
 
330
#-----------------------------------------------------------------------
331
# Tests for an instruction with register operands
332
#-----------------------------------------------------------------------
333
 
334
#define TEST_R_OP( testnum, inst, result, val1 ) \
335
    TEST_CASE( testnum, x3, result, \
336
      li  x1, val1; \
337
      inst x3, x1; \
338
    )
339
 
340
#define TEST_R_SRC1_EQ_DEST( testnum, inst, result, val1 ) \
341
    TEST_CASE( testnum, x1, result, \
342
      li  x1, val1; \
343
      inst x1, x1; \
344
    )
345
 
346
#define TEST_R_DEST_BYPASS( testnum, nop_cycles, inst, result, val1 ) \
347
    TEST_CASE( testnum, x6, result, \
348
      li  x4, 0; \
349
1:    li  x1, val1; \
350
      inst x3, x1; \
351
      TEST_INSERT_NOPS_ ## nop_cycles \
352
      addi  x6, x3, 0; \
353
      addi  x4, x4, 1; \
354
      li  x5, 2; \
355
      bne x4, x5, 1b \
356
    )
357
 
358
#-----------------------------------------------------------------------
359
# Tests for an instruction with register-register operands
360
#-----------------------------------------------------------------------
361
 
362
#define TEST_RR_OP( testnum, inst, result, val1, val2 ) \
363
    TEST_CASE( testnum, x3, result, \
364
      li  x1, MASK_XLEN(val1); \
365
      li  x2, MASK_XLEN(val2); \
366
      inst x3, x1, x2; \
367
    )
368
 
369
#define TEST_RR_SRC1_EQ_DEST( testnum, inst, result, val1, val2 ) \
370
    TEST_CASE( testnum, x1, result, \
371
      li  x1, MASK_XLEN(val1); \
372
      li  x2, MASK_XLEN(val2); \
373
      inst x1, x1, x2; \
374
    )
375
 
376
#define TEST_RR_SRC2_EQ_DEST( testnum, inst, result, val1, val2 ) \
377
    TEST_CASE( testnum, x2, result, \
378
      li  x1, MASK_XLEN(val1); \
379
      li  x2, MASK_XLEN(val2); \
380
      inst x2, x1, x2; \
381
    )
382
 
383
#define TEST_RR_SRC12_EQ_DEST( testnum, inst, result, val1 ) \
384
    TEST_CASE( testnum, x1, result, \
385
      li  x1, MASK_XLEN(val1); \
386
      inst x1, x1, x1; \
387
    )
388
 
389
#define TEST_RR_DEST_BYPASS( testnum, nop_cycles, inst, result, val1, val2 ) \
390
    TEST_CASE( testnum, x6, result, \
391
      li  x4, 0; \
392
1:    li  x1, MASK_XLEN(val1); \
393
      li  x2, MASK_XLEN(val2); \
394
      inst x3, x1, x2; \
395
      TEST_INSERT_NOPS_ ## nop_cycles \
396
      addi  x6, x3, 0; \
397
      addi  x4, x4, 1; \
398
      li  x5, 2; \
399
      bne x4, x5, 1b \
400
    )
401
 
402
#define TEST_RR_SRC12_BYPASS( testnum, src1_nops, src2_nops, inst, result, val1, val2 ) \
403
    TEST_CASE( testnum, x3, result, \
404
      li  x4, 0; \
405
1:    li  x1, MASK_XLEN(val1); \
406
      TEST_INSERT_NOPS_ ## src1_nops \
407
      li  x2, MASK_XLEN(val2); \
408
      TEST_INSERT_NOPS_ ## src2_nops \
409
      inst x3, x1, x2; \
410
      addi  x4, x4, 1; \
411
      li  x5, 2; \
412
      bne x4, x5, 1b \
413
    )
414
 
415
#define TEST_RR_SRC21_BYPASS( testnum, src1_nops, src2_nops, inst, result, val1, val2 ) \
416
    TEST_CASE( testnum, x3, result, \
417
      li  x4, 0; \
418
1:    li  x2, MASK_XLEN(val2); \
419
      TEST_INSERT_NOPS_ ## src1_nops \
420
      li  x1, MASK_XLEN(val1); \
421
      TEST_INSERT_NOPS_ ## src2_nops \
422
      inst x3, x1, x2; \
423
      addi  x4, x4, 1; \
424
      li  x5, 2; \
425
      bne x4, x5, 1b \
426
    )
427
 
428
#define TEST_RR_ZEROSRC1( testnum, inst, result, val ) \
429
    TEST_CASE( testnum, x2, result, \
430
      li x1, MASK_XLEN(val); \
431
      inst x2, x0, x1; \
432
    )
433
 
434
#define TEST_RR_ZEROSRC2( testnum, inst, result, val ) \
435
    TEST_CASE( testnum, x2, result, \
436
      li x1, MASK_XLEN(val); \
437
      inst x2, x1, x0; \
438
    )
439
 
440
#define TEST_RR_ZEROSRC12( testnum, inst, result ) \
441
    TEST_CASE( testnum, x1, result, \
442
      inst x1, x0, x0; \
443
    )
444
 
445
#define TEST_RR_ZERODEST( testnum, inst, val1, val2 ) \
446
    TEST_CASE( testnum, x0, 0, \
447
      li x1, MASK_XLEN(val1); \
448
      li x2, MASK_XLEN(val2); \
449
      inst x0, x1, x2; \
450
    )
451
 
452
#-----------------------------------------------------------------------
453
# Test memory instructions
454
#-----------------------------------------------------------------------
455
 
456
#define TEST_LD_OP( testnum, inst, result, offset, base ) \
457
    TEST_CASE( testnum, x3, result, \
458
      la  x1, base; \
459
      inst x3, offset(x1); \
460
    )
461
 
462
#define TEST_ST_OP( testnum, load_inst, store_inst, result, offset, base ) \
463
    TEST_CASE( testnum, x3, result, \
464
      la  x1, base; \
465
      li  x2, result; \
466
      store_inst x2, offset(x1); \
467
      load_inst x3, offset(x1); \
468
    )
469
 
470
#define TEST_LD_DEST_BYPASS( testnum, nop_cycles, inst, result, offset, base ) \
471
test_ ## testnum: \
472
    li  TESTNUM, testnum; \
473
    li  x4, 0; \
474
1:  la  x1, base; \
475
    inst x3, offset(x1); \
476
    TEST_INSERT_NOPS_ ## nop_cycles \
477
    addi  x6, x3, 0; \
478
    li  x29, result; \
479
    bne x6, x29, fail; \
480
    addi  x4, x4, 1; \
481
    li  x5, 2; \
482
    bne x4, x5, 1b; \
483
 
484
#define TEST_LD_SRC1_BYPASS( testnum, nop_cycles, inst, result, offset, base ) \
485
test_ ## testnum: \
486
    li  TESTNUM, testnum; \
487
    li  x4, 0; \
488
1:  la  x1, base; \
489
    TEST_INSERT_NOPS_ ## nop_cycles \
490
    inst x3, offset(x1); \
491
    li  x29, result; \
492
    bne x3, x29, fail; \
493
    addi  x4, x4, 1; \
494
    li  x5, 2; \
495
    bne x4, x5, 1b \
496
 
497
#define TEST_ST_SRC12_BYPASS( testnum, src1_nops, src2_nops, load_inst, store_inst, result, offset, base ) \
498
test_ ## testnum: \
499
    li  TESTNUM, testnum; \
500
    li  x4, 0; \
501
1:  li  x1, result; \
502
    TEST_INSERT_NOPS_ ## src1_nops \
503
    la  x2, base; \
504
    TEST_INSERT_NOPS_ ## src2_nops \
505
    store_inst x1, offset(x2); \
506
    load_inst x3, offset(x2); \
507
    li  x29, result; \
508
    bne x3, x29, fail; \
509
    addi  x4, x4, 1; \
510
    li  x5, 2; \
511
    bne x4, x5, 1b \
512
 
513
#define TEST_ST_SRC21_BYPASS( testnum, src1_nops, src2_nops, load_inst, store_inst, result, offset, base ) \
514
test_ ## testnum: \
515
    li  TESTNUM, testnum; \
516
    li  x4, 0; \
517
1:  la  x2, base; \
518
    TEST_INSERT_NOPS_ ## src1_nops \
519
    li  x1, result; \
520
    TEST_INSERT_NOPS_ ## src2_nops \
521
    store_inst x1, offset(x2); \
522
    load_inst x3, offset(x2); \
523
    li  x29, result; \
524
    bne x3, x29, fail; \
525
    addi  x4, x4, 1; \
526
    li  x5, 2; \
527
    bne x4, x5, 1b \
528
 
529
#-----------------------------------------------------------------------
530
# Test branch instructions
531
#-----------------------------------------------------------------------
532
 
533
#define TEST_BR1_OP_TAKEN( testnum, inst, val1 ) \
534
test_ ## testnum: \
535
    li  TESTNUM, testnum; \
536
    li  x1, val1; \
537
    inst x1, 2f; \
538
    bne x0, TESTNUM, fail; \
539
1:  bne x0, TESTNUM, 3f; \
540
2:  inst x1, 1b; \
541
    bne x0, TESTNUM, fail; \
542
3:
543
 
544
#define TEST_BR1_OP_NOTTAKEN( testnum, inst, val1 ) \
545
test_ ## testnum: \
546
    li  TESTNUM, testnum; \
547
    li  x1, val1; \
548
    inst x1, 1f; \
549
    bne x0, TESTNUM, 2f; \
550
1:  bne x0, TESTNUM, fail; \
551
2:  inst x1, 1b; \
552
3:
553
 
554
#define TEST_BR1_SRC1_BYPASS( testnum, nop_cycles, inst, val1 ) \
555
test_ ## testnum: \
556
    li  TESTNUM, testnum; \
557
    li  x4, 0; \
558
1:  li  x1, val1; \
559
    TEST_INSERT_NOPS_ ## nop_cycles \
560
    inst x1, fail; \
561
    addi  x4, x4, 1; \
562
    li  x5, 2; \
563
    bne x4, x5, 1b \
564
 
565
#define TEST_BR2_OP_TAKEN( testnum, inst, val1, val2 ) \
566
test_ ## testnum: \
567
    li  TESTNUM, testnum; \
568
    li  x1, val1; \
569
    li  x2, val2; \
570
    inst x1, x2, 2f; \
571
    bne x0, TESTNUM, fail; \
572
1:  bne x0, TESTNUM, 3f; \
573
2:  inst x1, x2, 1b; \
574
    bne x0, TESTNUM, fail; \
575
3:
576
 
577
#define TEST_BR2_OP_NOTTAKEN( testnum, inst, val1, val2 ) \
578
test_ ## testnum: \
579
    li  TESTNUM, testnum; \
580
    li  x1, val1; \
581
    li  x2, val2; \
582
    inst x1, x2, 1f; \
583
    bne x0, TESTNUM, 2f; \
584
1:  bne x0, TESTNUM, fail; \
585
2:  inst x1, x2, 1b; \
586
3:
587
 
588
#define TEST_BR2_SRC12_BYPASS( testnum, src1_nops, src2_nops, inst, val1, val2 ) \
589
test_ ## testnum: \
590
    li  TESTNUM, testnum; \
591
    li  x4, 0; \
592
1:  li  x1, val1; \
593
    TEST_INSERT_NOPS_ ## src1_nops \
594
    li  x2, val2; \
595
    TEST_INSERT_NOPS_ ## src2_nops \
596
    inst x1, x2, fail; \
597
    addi  x4, x4, 1; \
598
    li  x5, 2; \
599
    bne x4, x5, 1b \
600
 
601
#define TEST_BR2_SRC21_BYPASS( testnum, src1_nops, src2_nops, inst, val1, val2 ) \
602
test_ ## testnum: \
603
    li  TESTNUM, testnum; \
604
    li  x4, 0; \
605
1:  li  x2, val2; \
606
    TEST_INSERT_NOPS_ ## src1_nops \
607
    li  x1, val1; \
608
    TEST_INSERT_NOPS_ ## src2_nops \
609
    inst x1, x2, fail; \
610
    addi  x4, x4, 1; \
611
    li  x5, 2; \
612
    bne x4, x5, 1b \
613
 
614
#-----------------------------------------------------------------------
615
# Test jump instructions
616
#-----------------------------------------------------------------------
617
 
618
#define TEST_JR_SRC1_BYPASS( testnum, nop_cycles, inst ) \
619
test_ ## testnum: \
620
    li  TESTNUM, testnum; \
621
    li  x4, 0; \
622
1:  la  x6, 2f; \
623
    TEST_INSERT_NOPS_ ## nop_cycles \
624
    inst x6; \
625
    bne x0, TESTNUM, fail; \
626
2:  addi  x4, x4, 1; \
627
    li  x5, 2; \
628
    bne x4, x5, 1b \
629
 
630
#define TEST_JALR_SRC1_BYPASS( testnum, nop_cycles, inst ) \
631
test_ ## testnum: \
632
    li  TESTNUM, testnum; \
633
    li  x4, 0; \
634
1:  la  x6, 2f; \
635
    TEST_INSERT_NOPS_ ## nop_cycles \
636
    inst x19, x6, 0; \
637
    bne x0, TESTNUM, fail; \
638
2:  addi  x4, x4, 1; \
639
    li  x5, 2; \
640
    bne x4, x5, 1b \
641
 
642
 
643
#-----------------------------------------------------------------------
644
# RV64UF MACROS
645
#-----------------------------------------------------------------------
646
 
647
#-----------------------------------------------------------------------
648
# Tests floating-point instructions
649
#-----------------------------------------------------------------------
650
 
651
#define qNaNf 0f:7fc00000
652
#define sNaNf 0f:7f800001
653
#define qNaN 0d:7ff8000000000000
654
#define sNaN 0d:7ff0000000000001
655
 
656
#define TEST_FP_OP_S_INTERNAL( testnum, flags, result, val1, val2, val3, code... ) \
657
test_ ## testnum: \
658
  li  TESTNUM, testnum; \
659
  la  a0, test_ ## testnum ## _data ;\
660
  flw f0, 0(a0); \
661
  flw f1, 4(a0); \
662
  flw f2, 8(a0); \
663
  lw  a3, 12(a0); \
664
  code; \
665
  fsflags a1, x0; \
666
  li a2, flags; \
667
  bne a0, a3, fail; \
668
  bne a1, a2, fail; \
669
  j 2f; \
670
  .balign 4; \
671
  .data; \
672
  test_ ## testnum ## _data: \
673
  .float val1; \
674
  .float val2; \
675
  .float val3; \
676
  .result; \
677
  .text; \
678
2:
679
 
680
#define TEST_FP_OP_D_INTERNAL( testnum, flags, result, val1, val2, val3, code... ) \
681
test_ ## testnum: \
682
  li  TESTNUM, testnum; \
683
  la  a0, test_ ## testnum ## _data ;\
684
  fld f0, 0(a0); \
685
  fld f1, 8(a0); \
686
  fld f2, 16(a0); \
687
  ld  a3, 24(a0); \
688
  code; \
689
  fsflags a1, x0; \
690
  li a2, flags; \
691
  bne a0, a3, fail; \
692
  bne a1, a2, fail; \
693
  j 2f; \
694
  .data; \
695
  .balign 8; \
696
  test_ ## testnum ## _data: \
697
  .double val1; \
698
  .double val2; \
699
  .double val3; \
700
  .result; \
701
  .text; \
702
2:
703
 
704
#define TEST_FCVT_S_D( testnum, result, val1 ) \
705
  TEST_FP_OP_D_INTERNAL( testnum, 0, double result, val1, 0.0, 0.0, \
706
                    fcvt.s.d f3, f0; fcvt.d.s f3, f3; fmv.x.d a0, f3)
707
 
708
#define TEST_FCVT_D_S( testnum, result, val1 ) \
709
  TEST_FP_OP_S_INTERNAL( testnum, 0, float result, val1, 0.0, 0.0, \
710
                    fcvt.d.s f3, f0; fcvt.s.d f3, f3; fmv.x.s a0, f3)
711
 
712
#define TEST_FP_OP1_S( testnum, inst, flags, result, val1 ) \
713
  TEST_FP_OP_S_INTERNAL( testnum, flags, float result, val1, 0.0, 0.0, \
714
                    inst f3, f0; fmv.x.s a0, f3)
715
 
716
#define TEST_FP_OP1_D( testnum, inst, flags, result, val1 ) \
717
  TEST_FP_OP_D_INTERNAL( testnum, flags, double result, val1, 0.0, 0.0, \
718
                    inst f3, f0; fmv.x.d a0, f3)
719
 
720
#define TEST_FP_OP1_S_DWORD_RESULT( testnum, inst, flags, result, val1 ) \
721
  TEST_FP_OP_S_INTERNAL( testnum, flags, dword result, val1, 0.0, 0.0, \
722
                    inst f3, f0; fmv.x.s a0, f3)
723
 
724
#define TEST_FP_OP1_D_DWORD_RESULT( testnum, inst, flags, result, val1 ) \
725
  TEST_FP_OP_D_INTERNAL( testnum, flags, dword result, val1, 0.0, 0.0, \
726
                    inst f3, f0; fmv.x.d a0, f3)
727
 
728
#define TEST_FP_OP2_S( testnum, inst, flags, result, val1, val2 ) \
729
  TEST_FP_OP_S_INTERNAL( testnum, flags, float result, val1, val2, 0.0, \
730
                    inst f3, f0, f1; fmv.x.s a0, f3)
731
 
732
#define TEST_FP_OP2_D( testnum, inst, flags, result, val1, val2 ) \
733
  TEST_FP_OP_D_INTERNAL( testnum, flags, double result, val1, val2, 0.0, \
734
                    inst f3, f0, f1; fmv.x.d a0, f3)
735
 
736
#define TEST_FP_OP3_S( testnum, inst, flags, result, val1, val2, val3 ) \
737
  TEST_FP_OP_S_INTERNAL( testnum, flags, float result, val1, val2, val3, \
738
                    inst f3, f0, f1, f2; fmv.x.s a0, f3)
739
 
740
#define TEST_FP_OP3_D( testnum, inst, flags, result, val1, val2, val3 ) \
741
  TEST_FP_OP_D_INTERNAL( testnum, flags, double result, val1, val2, val3, \
742
                    inst f3, f0, f1, f2; fmv.x.d a0, f3)
743
 
744
#define TEST_FP_INT_OP_S( testnum, inst, flags, result, val1, rm ) \
745
  TEST_FP_OP_S_INTERNAL( testnum, flags, word result, val1, 0.0, 0.0, \
746
                    inst a0, f0, rm)
747
 
748
#define TEST_FP_INT_OP_D( testnum, inst, flags, result, val1, rm ) \
749
  TEST_FP_OP_D_INTERNAL( testnum, flags, dword result, val1, 0.0, 0.0, \
750
                    inst a0, f0, rm)
751
 
752
#define TEST_FP_CMP_OP_S( testnum, inst, flags, result, val1, val2 ) \
753
  TEST_FP_OP_S_INTERNAL( testnum, flags, word result, val1, val2, 0.0, \
754
                    inst a0, f0, f1)
755
 
756
#define TEST_FP_CMP_OP_D( testnum, inst, flags, result, val1, val2 ) \
757
  TEST_FP_OP_D_INTERNAL( testnum, flags, dword result, val1, val2, 0.0, \
758
                    inst a0, f0, f1)
759
 
760
#define TEST_FCLASS_S(testnum, correct, input) \
761
  TEST_CASE(testnum, a0, correct, li a0, input; fmv.s.x fa0, a0; \
762
                    fclass.s a0, fa0)
763
 
764
#define TEST_FCLASS_D(testnum, correct, input) \
765
  TEST_CASE(testnum, a0, correct, li a0, input; fmv.d.x fa0, a0; \
766
                    fclass.d a0, fa0)
767
 
768
#define TEST_INT_FP_OP_S( testnum, inst, result, val1 ) \
769
test_ ## testnum: \
770
  li  TESTNUM, testnum; \
771
  la  a0, test_ ## testnum ## _data ;\
772
  lw  a3, 0(a0); \
773
  li  a0, val1; \
774
  inst f0, a0; \
775
  fsflags x0; \
776
  fmv.x.s a0, f0; \
777
  bne a0, a3, fail; \
778
  j 1f; \
779
  .balign 4; \
780
  test_ ## testnum ## _data: \
781
  .float result; \
782
1:
783
 
784
#define TEST_INT_FP_OP_D( testnum, inst, result, val1 ) \
785
test_ ## testnum: \
786
  li  TESTNUM, testnum; \
787
  la  a0, test_ ## testnum ## _data ;\
788
  ld  a3, 0(a0); \
789
  li  a0, val1; \
790
  inst f0, a0; \
791
  fsflags x0; \
792
  fmv.x.d a0, f0; \
793
  bne a0, a3, fail; \
794
  j 1f; \
795
  .balign 8; \
796
  test_ ## testnum ## _data: \
797
  .double result; \
798
1:
799
 
800
#-----------------------------------------------------------------------
801
# Pass and fail code (assumes test num is in TESTNUM)
802
#-----------------------------------------------------------------------
803
 
804
#define TEST_PASSFAIL \
805
        bne x0, TESTNUM, pass; \
806
fail: \
807
        RVTEST_FAIL; \
808
pass: \
809
        RVTEST_PASS \
810
 
811
 
812
#-----------------------------------------------------------------------
813
# Test data section
814
#-----------------------------------------------------------------------
815
 
816
#define TEST_DATA
817
 
818
#endif
819
 

powered by: WebSVN 2.1.0

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