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

Subversion Repositories steelcore

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 rafaelcalc
//////////////////////////////////////////////////////////////////////////////////
2
// Engineer: Rafael de Oliveira Calçada (rafaelcalcada@gmail.com)
3
// 
4
// Create Date: 26.04.2020 20:52:25
5
// Module Name: tb_load_unit
6
// Project Name: Steel Core
7
// Description: RISC-V Steel Core Load Unit testbench
8
// 
9
// Dependencies: globals.vh
10
//               load_unit.v
11
// 
12
// Version 0.01
13
// 
14
//////////////////////////////////////////////////////////////////////////////////
15
 
16
/*********************************************************************************
17
 
18
MIT License
19
 
20
Copyright (c) 2020 Rafael de Oliveira Calçada
21
 
22
Permission is hereby granted, free of charge, to any person obtaining a copy
23
of this software and associated documentation files (the "Software"), to deal
24
in the Software without restriction, including without limitation the rights
25
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
copies of the Software, and to permit persons to whom the Software is
27
furnished to do so, subject to the following conditions:
28
 
29
The above copyright notice and this permission notice shall be included in all
30
copies or substantial portions of the Software.
31
 
32
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38
SOFTWARE.
39
 
40
********************************************************************************/
41
 
42
`timescale 1ns / 1ps
43
`include "../globals.vh"
44
 
45
 
46
module tb_load_unit();
47
 
48
    reg [1:0] LOAD_SIZE;
49
    reg LOAD_UNSIGNED;
50
    reg [31:0] DATA_IN;
51
    reg [1:0] IADDER_OUT_1_TO_0;
52
    wire [31:0] OUTPUT;
53
 
54
    load_unit dut(
55
 
56
        .LOAD_SIZE(LOAD_SIZE),
57
        .LOAD_UNSIGNED(LOAD_UNSIGNED),
58
        .DATA_IN(DATA_IN),
59
        .IADDER_OUT_1_TO_0(IADDER_OUT_1_TO_0),
60
        .OUTPUT(OUTPUT)
61
 
62
        );
63
 
64
    integer i;
65
 
66
    initial
67
    begin
68
 
69
        $display("Testing Load Unit...");
70
 
71
        $display("Testing Load Unit for LB operation.");
72
        LOAD_SIZE = 2'b00;
73
        LOAD_UNSIGNED = 1'b0;
74
 
75
        for(i = 0; i < 10000; i=i+1)
76
        begin
77
 
78
            DATA_IN = $random;
79
            IADDER_OUT_1_TO_0 = $random;
80
 
81
            #10;
82
 
83
            if(IADDER_OUT_1_TO_0 == 2'b00 & OUTPUT != { {24{DATA_IN[7]}} , DATA_IN[7:0]})
84
            begin
85
                $display("FAIL. Wrong result.");
86
                $finish;
87
            end
88
            else if(IADDER_OUT_1_TO_0 == 2'b01 & OUTPUT != { {24{DATA_IN[15]}} , DATA_IN[15:8]})
89
            begin
90
                $display("FAIL. Wrong result.");
91
                $finish;
92
            end
93
            else if(IADDER_OUT_1_TO_0 == 2'b10 & OUTPUT != { {24{DATA_IN[23]}} , DATA_IN[23:16]})
94
            begin
95
                $display("FAIL. Wrong result.");
96
                $finish;
97
            end
98
            else if(IADDER_OUT_1_TO_0 == 2'b11 & OUTPUT != { {24{DATA_IN[31]}} , DATA_IN[31:24]})
99
            begin
100
                $display("FAIL. Wrong result.");
101
                $finish;
102
            end
103
 
104
        end
105
 
106
        $display("LB operation successfully tested.");
107
 
108
        $display("Testing Load Unit for LH operation.");
109
        LOAD_SIZE = 2'b01;
110
        LOAD_UNSIGNED = 1'b0;
111
 
112
        for(i = 0; i < 10000; i=i+1)
113
        begin
114
 
115
            DATA_IN = $random;
116
            IADDER_OUT_1_TO_0 = $random;
117
            IADDER_OUT_1_TO_0[0] = 1'b0;
118
 
119
            #10;
120
 
121
            if(IADDER_OUT_1_TO_0[1] == 1'b0 & OUTPUT != { {16{DATA_IN[15]}} , DATA_IN[15:0]})
122
            begin
123
                $display("FAIL. Wrong result.");
124
                $finish;
125
            end
126
            else if(IADDER_OUT_1_TO_0[1] == 1'b1 & OUTPUT != { {16{DATA_IN[31]}} , DATA_IN[31:16]})
127
            begin
128
                $display("FAIL. Wrong result.");
129
                $finish;
130
            end
131
 
132
        end
133
 
134
        $display("LH operation successfully tested.");
135
 
136
        $display("Testing Load Unit for LW operation.");
137
        LOAD_SIZE = 2'b10;
138
        LOAD_UNSIGNED = 1'b0;
139
 
140
        for(i = 0; i < 10000; i=i+1)
141
        begin
142
 
143
            DATA_IN = $random;
144
            IADDER_OUT_1_TO_0 = 2'b00;
145
 
146
            #10;
147
 
148
            if(OUTPUT != DATA_IN[31:0])
149
            begin
150
                $display("FAIL. Wrong result.");
151
                $finish;
152
            end
153
 
154
        end
155
 
156
        $display("LW operation successfully tested.");
157
 
158
        $display("Testing Load Unit for LBU operation.");
159
        LOAD_SIZE = 2'b00;
160
        LOAD_UNSIGNED = 1'b1;
161
 
162
        for(i = 0; i < 10000; i=i+1)
163
        begin
164
 
165
            DATA_IN = $random;
166
            IADDER_OUT_1_TO_0 = $random;
167
 
168
            #10;
169
 
170
            if(IADDER_OUT_1_TO_0 == 2'b00 & OUTPUT != { 24'b0 , DATA_IN[7:0]})
171
            begin
172
                $display("FAIL. Wrong result.");
173
                $finish;
174
            end
175
            else if(IADDER_OUT_1_TO_0 == 2'b01 & OUTPUT != { 24'b0 , DATA_IN[15:8]})
176
            begin
177
                $display("FAIL. Wrong result.");
178
                $finish;
179
            end
180
            else if(IADDER_OUT_1_TO_0 == 2'b10 & OUTPUT != { 24'b0 , DATA_IN[23:16]})
181
            begin
182
                $display("FAIL. Wrong result.");
183
                $finish;
184
            end
185
            else if(IADDER_OUT_1_TO_0 == 2'b11 & OUTPUT != { 24'b0 , DATA_IN[31:24]})
186
            begin
187
                $display("FAIL. Wrong result.");
188
                $finish;
189
            end
190
 
191
        end
192
 
193
        $display("LBU operation successfully tested.");
194
 
195
        $display("Testing Load Unit for LHU operation.");
196
 
197
        LOAD_SIZE = 2'b01;
198
        LOAD_UNSIGNED = 1'b1;
199
 
200
        for(i = 0; i < 10000; i=i+1)
201
        begin
202
 
203
            DATA_IN = $random;
204
            IADDER_OUT_1_TO_0 = $random;
205
            IADDER_OUT_1_TO_0[0] = 1'b0;
206
 
207
            #10;
208
 
209
            if(IADDER_OUT_1_TO_0[1] == 1'b0 & OUTPUT != { 16'b0 , DATA_IN[15:0]})
210
            begin
211
                $display("FAIL. Wrong result.");
212
                $finish;
213
            end
214
            else if(IADDER_OUT_1_TO_0[1] == 1'b1 & OUTPUT != { 16'b0 , DATA_IN[31:16]})
215
            begin
216
                $display("FAIL. Wrong result.");
217
                $finish;
218
            end
219
 
220
        end
221
 
222
        $display("LHU operation successfully tested.");
223
 
224
        $display("Load Unit successfully tested.");
225
 
226
    end
227
 
228
endmodule

powered by: WebSVN 2.1.0

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