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

Subversion Repositories steelcore

[/] [rtl/] [bench/] [tb_imm_generator.v] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 rafaelcalc
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Engineer: Rafael de Oliveira Calçada (rafaelcalcada@gmail.com)
4
// 
5
// Create Date: 26.04.2020 22:58:58
6
// Module Name: tb_imm_generator
7
// Project Name: Steel Core
8
// Description: Immediate Generator testbench
9
// 
10
// Dependencies: globals.vh
11
//               imm_generator.v
12
//               decoder.v
13
// 
14
// Version 0.01
15
// 
16
//////////////////////////////////////////////////////////////////////////////////
17
 
18
/*********************************************************************************
19
 
20
MIT License
21
 
22
Copyright (c) 2020 Rafael de Oliveira Calçada
23
 
24
Permission is hereby granted, free of charge, to any person obtaining a copy
25
of this software and associated documentation files (the "Software"), to deal
26
in the Software without restriction, including without limitation the rights
27
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28
copies of the Software, and to permit persons to whom the Software is
29
furnished to do so, subject to the following conditions:
30
 
31
The above copyright notice and this permission notice shall be included in all
32
copies or substantial portions of the Software.
33
 
34
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40
SOFTWARE.
41
 
42
********************************************************************************/
43
 
44
`timescale 1ns / 1ps
45
`include "../globals.vh"
46
 
47
module tb_imm_generator();
48
 
49
    reg [31:0] INSTR;
50
    reg [2:0] FUNCT3;
51
    wire [2:0] IMM_TYPE;
52
    wire [31:0] IMM;
53
 
54
    imm_generator dut(
55
 
56
        .INSTR(INSTR[31:7]),
57
        .IMM_TYPE(IMM_TYPE),
58
        .IMM(IMM)
59
 
60
        );
61
 
62
    decoder dec(
63
 
64
        .OPCODE(INSTR[6:0]),
65
        .FUNCT7_5(1'b0),
66
        .FUNCT3(FUNCT3),
67
        .IMM_TYPE(IMM_TYPE)
68
 
69
    );
70
 
71
    integer i;
72
 
73
    initial
74
    begin
75
 
76
        $display("Testing Immediate Generator...");
77
 
78
        INSTR = {30'b0, 2'b11};
79
        FUNCT3 = 3'b0;
80
 
81
        $display("Testing immediate generator for OP-IMM opcode");
82
 
83
        INSTR[6:2] = `OPCODE_OP_IMM;
84
 
85
        for(i = 0; i < 10000; i=i+1)
86
        begin
87
 
88
            INSTR[31:7] = $random;
89
 
90
            #10;
91
 
92
            if(IMM != { {20{INSTR[31]}}, INSTR[31:20] })
93
            begin
94
                $display("FAIL. Check the results.");
95
                $finish;
96
            end
97
 
98
        end
99
 
100
        $display("OP-IMM opcode successfully tested.");
101
 
102
        $display("Testing immediate generator for LOAD opcode");
103
 
104
        INSTR[6:2] = `OPCODE_LOAD;
105
 
106
        for(i = 0; i < 10000; i=i+1)
107
        begin
108
 
109
            INSTR[31:7] = $random;
110
 
111
            #10;
112
 
113
            if(IMM != { {20{INSTR[31]}}, INSTR[31:20] })
114
            begin
115
                $display("FAIL. Check the results.");
116
                $finish;
117
            end
118
 
119
        end
120
 
121
        $display("LOAD opcode successfully tested.");
122
 
123
        $display("Testing immediate generator for STORE opcode");
124
 
125
        INSTR[6:2] = `OPCODE_STORE;
126
 
127
        for(i = 0; i < 10000; i=i+1)
128
        begin
129
 
130
            INSTR[31:7] = $random;
131
 
132
            #10;
133
 
134
            if(IMM != { {20{INSTR[31]}}, INSTR[31:25], INSTR[11:7] })
135
            begin
136
                $display("FAIL. Check the results.");
137
                $finish;
138
            end
139
 
140
        end
141
 
142
        $display("STORE opcode successfully tested.");
143
 
144
        $display("Testing immediate generator for BRANCH opcode");
145
 
146
        INSTR[6:2] = `OPCODE_BRANCH;
147
 
148
        for(i = 0; i < 10000; i=i+1)
149
        begin
150
 
151
            INSTR[31:7] = $random;
152
 
153
            #10;
154
 
155
            if(IMM != { {19{INSTR[31]}}, INSTR[31], INSTR[7], INSTR[30:25], INSTR[11:8], 1'b0 })
156
            begin
157
                $display("FAIL. Check the results.");
158
                $finish;
159
            end
160
 
161
        end
162
 
163
        $display("BRANCH opcode successfully tested.");
164
 
165
        $display("Testing immediate generator for JALR opcode");
166
 
167
        INSTR[6:2] = `OPCODE_JALR;
168
 
169
        for(i = 0; i < 10000; i=i+1)
170
        begin
171
 
172
            INSTR[31:7] = $random;
173
 
174
            #10;
175
 
176
            if(IMM != { {20{INSTR[31]}}, INSTR[31:20] })
177
            begin
178
                $display("FAIL. Check the results.");
179
                $finish;
180
            end
181
 
182
        end
183
 
184
        $display("JALR opcode successfully tested.");
185
 
186
        $display("Testing immediate generator for JAL opcode");
187
 
188
        INSTR[6:2] = `OPCODE_JAL;
189
 
190
        for(i = 0; i < 10000; i=i+1)
191
        begin
192
 
193
            INSTR[31:7] = $random;
194
 
195
            #10;
196
 
197
            if(IMM != { {11{INSTR[31]}}, INSTR[31], INSTR[19:12], INSTR[20], INSTR[30:21], 1'b0 })
198
            begin
199
                $display("FAIL. Check the results.");
200
                $finish;
201
            end
202
 
203
        end
204
 
205
        $display("JAL opcode successfully tested.");
206
 
207
        $display("Testing immediate generator for LUI opcode");
208
 
209
        INSTR[6:2] = `OPCODE_LUI;
210
 
211
        for(i = 0; i < 10000; i=i+1)
212
        begin
213
 
214
            INSTR[31:7] = $random;
215
 
216
            #10;
217
 
218
            if(IMM != { INSTR[31:12], 12'h000 })
219
            begin
220
                $display("FAIL. Check the results.");
221
                $finish;
222
            end
223
 
224
        end
225
 
226
        $display("LUI opcode successfully tested.");
227
 
228
        $display("Testing immediate generator for AUIPC opcode");
229
 
230
        INSTR[6:2] = `OPCODE_AUIPC;
231
 
232
        for(i = 0; i < 10000; i=i+1)
233
        begin
234
 
235
            INSTR[31:7] = $random;
236
 
237
            #10;
238
 
239
            if(IMM != { INSTR[31:12], 12'h000 })
240
            begin
241
                $display("FAIL. Check the results.");
242
                $finish;
243
            end
244
 
245
        end
246
 
247
        $display("AUIPC opcode successfully tested.");
248
 
249
        $display("Testing immediate generator for SYSTEM opcode");
250
 
251
        INSTR[6:2] = `OPCODE_SYSTEM;
252
 
253
        for(i = 0; i < 10000; i=i+1)
254
        begin
255
 
256
            INSTR[31:7] = $random;
257
            FUNCT3 = $random;
258
 
259
            #10;
260
 
261
            if(FUNCT3 != 3'b000 && IMM != { 27'b0, INSTR[19:15] })
262
            begin
263
                $display("FAIL. Check the results.");
264
                $finish;
265
            end
266
 
267
        end
268
 
269
        $display("SYSTEM opcode successfully tested.");
270
 
271
        $display("Immediate Generator successfully tested.");
272
 
273
    end
274
 
275
endmodule

powered by: WebSVN 2.1.0

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