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

Subversion Repositories fwrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mballance
/*
2
 * fwrisc_instr_tests_jump.cpp
3
 *
4
 *  Created on: Nov 10, 2018
5
 *      Author: ballance
6
 */
7
 
8
#include "fwrisc_instr_tests_jump.h"
9
 
10
fwrisc_instr_tests_jump::fwrisc_instr_tests_jump() {
11
        // TODO Auto-generated constructor stub
12
 
13
}
14
 
15
fwrisc_instr_tests_jump::~fwrisc_instr_tests_jump() {
16
        // TODO Auto-generated destructor stub
17
}
18
 
19
TEST_F(fwrisc_instr_tests_jump, j) {
20
        reg_val_s exp[] = {
21
                        {3, 4},
22
                        {4, 5},
23
                        {5, 6}
24
        };
25
        const char *program = R"(
26
                entry:
27
                        j               1f
28
                        lui             x2, 26
29
                        lui             x2, 26
30
                1:
31
                        li              x3, 4
32
                        j               2f
33
                        nop
34
                        nop
35
                1:
36
                        li              x4, 5
37
                        j               done
38
                2:
39
                        li              x5, 6
40
                        j               1b
41
                        )";
42
 
43
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
44
}
45
 
46
TEST_F(fwrisc_instr_tests_jump, jal) {
47
        reg_val_s exp[] = {
48
                        {1, 0},
49
                        {3, 0},
50
                        {4, 4}
51
        };
52
        const char *program = R"(
53
                entry:
54
                        jal             x1, 1f
55
                        lui             x2, 26
56
                        lui             x2, 26
57
                1:
58
                        la              x3, entry
59
                        sub             x4, x1, x3
60
                        li              x1, 0
61
                        li              x3, 0
62
                        j               done
63
                        )";
64
 
65
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
66
}
67
 
68
TEST_F(fwrisc_instr_tests_jump, jalr) {
69
        reg_val_s exp[] = {
70
                        {1, 0},
71
                        {2, 0},
72
                        {3, 0},
73
                        {4, 12}
74
        };
75
        const char *program = R"(
76
                entry:
77
                        la              x2, 1f // la is a two-word instruction (0x08, 0x0C)
78
                        jalr    x1, x2 // 0x10: R[1] <= 0x14
79
                        lui             x2, 26
80
                        lui             x2, 26
81
                1:
82
                        la              x3, entry  // 0x1c
83
                        sub             x4, x1, x3 //0x24
84
                        li              x1, 0
85
                        li              x2, 0
86
                        li              x3, 0
87
                        j               done
88
                        )";
89
 
90
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
91
}
92
 
93
TEST_F(fwrisc_instr_tests_jump, jalr_off_pos) {
94
        reg_val_s exp[] = {
95
                        {1, 0},
96
                        {2, 0},
97
                        {3, 0},
98
                        {4, 0x10}
99
        };
100
        const char *program = R"(
101
                entry:
102
                        la              x2, 1f // la is a two-word instruction (0x08, 0x0C)
103
                        addi    x2, x2, -4 // We'll add in the offset now
104
                        jalr    x1, 4(x2) // 0x14: R[1] <= 0x18
105
                        lui             x2, 26
106
                        lui             x2, 26
107
                1:
108
                        la              x3, entry // 0x1c
109
                        sub             x4, x1, x3
110
                        li              x1, 0
111
                        li              x2, 0
112
                        li              x3, 0
113
                        j               done
114
                        )";
115
 
116
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
117
}
118
 
119
TEST_F(fwrisc_instr_tests_jump, jalr_off_neg) {
120
        reg_val_s exp[] = {
121
                        {1, 0},
122
                        {2, 0},
123
                        {3, 0},
124
                        {4, 0x10}
125
        };
126
        const char *program = R"(
127
                entry:
128
                        la              x2, 1f // la is a two-word instruction (0x08, 0x0C)
129
                        addi    x2, x2, 4  // 0x10: We'll offset next
130
                        jalr    x1, -4(x2) // 0x14: R[1] <= 0x18
131
                        lui             x2, 26     // 0x18
132
                        lui             x2, 26     // 0x1C
133
                1:
134
                        la              x3, entry // 0x20
135
                        sub             x4, x1, x3
136
                        li              x1, 0
137
                        li              x2, 0
138
                        li              x3, 0
139
                        j               done
140
                        )";
141
 
142
        runtest(program, exp, sizeof(exp)/sizeof(reg_val_s));
143
}
144
 
145
 

powered by: WebSVN 2.1.0

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