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

Subversion Repositories oops

[/] [oops/] [trunk/] [tb/] [test_map_table.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 smjoshua
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  OoOPs Core Register Map Table testbench                     //
4
//                                                              //
5
//  This file is part of the OoOPs project                      //
6
//  http://www.opencores.org/project,oops                       //
7
//                                                              //
8
//  Description:                                                //
9
//  Small, self-contained testbench for basic functionality of  //
10
//  the Map Table.                                              //
11
//                                                              //
12
//  Author(s):                                                  //
13
//      - Joshua Smith, smjoshua@umich.edu                      //
14
//                                                              //
15
//////////////////////////////////////////////////////////////////
16
//                                                              //
17
// Copyright (C) 2012 Authors and OPENCORES.ORG                 //
18
//                                                              //
19
// This source file may be used and distributed without         //
20
// restriction provided that this copyright statement is not    //
21
// removed from the file and that any derivative work contains  //
22
// the original copyright notice and the associated disclaimer. //
23
//                                                              //
24
// This source file is free software; you can redistribute it   //
25
// and/or modify it under the terms of the GNU Lesser General   //
26
// Public License as published by the Free Software Foundation; //
27
// either version 2.1 of the License, or (at your option) any   //
28
// later version.                                               //
29
//                                                              //
30
// This source is distributed in the hope that it will be       //
31
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
32
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
33
// PURPOSE.  See the GNU Lesser General Public License for more //
34
// details.                                                     //
35
//                                                              //
36
// You should have received a copy of the GNU Lesser General    //
37
// Public License along with this source; if not, download it   //
38
// from http://www.opencores.org/lgpl.shtml                     //
39
//                                                              //
40
//////////////////////////////////////////////////////////////////
41
`include "ooops_defs.v"
42
 
43
module test_map_table;
44
 
45
  // I/O to Map Table DUT
46
  reg                       clk;
47
  reg                       rst;
48
  reg                       ds1_valid;
49
  reg   [`REG_IDX_SZ-1:0]   ds1_src1_idx;
50
  reg   [`REG_IDX_SZ-1:0]   ds1_src2_idx;
51
  reg   [`REG_IDX_SZ-1:0]   ds1_dest_idx;
52
  reg                       ds1_dest_wr;
53
  reg                       ds1_type_br;
54
  reg                       rob_pipe_flush;
55
  reg                       rob_ds_ret_valid;
56
  reg                       rob_ds_ret_dest_write;
57
  reg   [`CHKPT_PTR_SZ-1:0] rob_ds_chkpt_ptr;
58
  reg   [`FL_PTR_SZ-1:0]    rob_ds_fl_head_ptr;
59
  reg                       rob_ds_ret_chkpt_free;
60
  reg   [`REG_IDX_SZ-1:0]   rob_ds_ret_idx;
61
  reg   [`TAG_SZ-1:0]       rob_ds_ret_tag;
62
  reg   [`TAG_SZ-1:0]       rob_ds_ret_tag_old;
63
 
64
  wire                      map_table_init;
65
  wire  [`TAG_SZ-1:0]       ds2_src1_tag;
66
  wire  [`TAG_SZ-1:0]       ds2_src2_tag;
67
  wire                      ds2_src1_valid;
68
  wire                      ds2_src2_valid;
69
  wire  [`TAG_SZ-1:0]       ds2_dest_tag;
70
  wire  [`TAG_SZ-1:0]       ds2_dest_tag_old;
71
  wire  [`FL_PTR_SZ-1:0]    ds2_fl_head_ptr;
72
  wire  [`CHKPT_PTR_SZ-1:0] ds2_chkpt_ptr;
73
 
74
 
75
  // Instantiate DUT
76
  map_table m0 (
77
    .clk(clk),
78
    .rst(rst),
79
    .map_table_init(map_table_init),
80
 
81
    .ds1_valid(ds1_valid),
82
    .ds1_src1_idx(ds1_src1_idx),
83
    .ds1_src2_idx(ds1_src2_idx),
84
    .ds1_dest_idx(ds1_dest_idx),
85
    .ds1_dest_wr(ds1_dest_wr),
86
    .ds1_type_br(ds1_type_br),
87
    .ds2_src1_tag(ds2_src1_tag),
88
    .ds2_src2_tag(ds2_src2_tag),
89
    .ds2_src1_valid(ds2_src1_valid),
90
    .ds2_src2_valid(ds2_src2_valid),
91
    .ds2_dest_tag(ds2_dest_tag),
92
    .ds2_dest_tag_old(ds2_dest_tag_old),
93
    .ds2_fl_head_ptr(ds2_fl_head_ptr),
94
    .ds2_chkpt_ptr(ds2_chkpt_ptr),
95
 
96
    .rob_pipe_flush(rob_pipe_flush),
97
    .rob_ds_ret_valid(rob_ds_ret_valid),
98
    .rob_ds_ret_dest_write(rob_ds_ret_dest_write),
99
    .rob_ds_chkpt_ptr(rob_ds_chkpt_ptr),
100
    .rob_ds_fl_head_ptr(rob_ds_fl_head_ptr),
101
    .rob_ds_ret_chkpt_free(rob_ds_ret_chkpt_free),
102
    .rob_ds_ret_idx(rob_ds_ret_idx),
103
    .rob_ds_ret_tag(rob_ds_ret_tag),
104
    .rob_ds_ret_tag_old(rob_ds_ret_tag_old)
105
  );
106
 
107
 
108
  // generate clk
109
  always begin
110
    #5;
111
    clk = ~clk;
112
  end
113
 
114
  initial begin
115
    // Initialize clk and inputs
116
    clk = 1'b0;
117
    rst = 1'b1;
118
 
119
    ds1_valid               = 0;
120
    ds1_src1_idx            = 0;
121
    ds1_src2_idx            = 0;
122
    ds1_dest_idx            = 0;
123
    ds1_dest_wr             = 1'b0;
124
    ds1_type_br             = 1'b0;
125
    rob_pipe_flush          = 1'b0;
126
    rob_ds_ret_valid        = 1'b0;
127
    rob_ds_ret_dest_write   = 1'b0;
128
    rob_ds_chkpt_ptr        = 0;
129
    rob_ds_fl_head_ptr      = 0;
130
    rob_ds_ret_chkpt_free   = 0;
131
    rob_ds_ret_idx          = 0;
132
    rob_ds_ret_tag          = 0;
133
    rob_ds_ret_tag_old      = 0;
134
 
135
    // Set up waveform dump
136
    `ifdef WAVE_DUMP
137
    $dumpfile("wave.vcd");
138
    $dumpvars(0,test_map_table);
139
    `endif
140
 
141
    // Assert reset for a couple clks
142
    $display("Asserting reset...");
143
    repeat (3) @(negedge clk);
144
    rst = 1'b0;
145
    $display("Reset done.");
146
 
147
    // Wait for initialization to be done
148
    while (map_table_init)
149
      @(negedge clk);
150
 
151
    // Rename one instruction
152
    set_rename_inputs(1, 2, 3, 1'b1, 1'b0); // Read r1, r2; write r3; not branch
153
    @(negedge clk);
154
    clear_rename_inputs;
155
 
156
    // Check output src and dest tags
157
    if ((ds2_src1_tag != 'd1) || (ds2_src2_tag != 'd2) || (ds2_dest_tag != 'd34))
158
      fail('d1);
159
 
160
    // Rename a second dependent instruction
161
    set_rename_inputs(1, 3, 4, 1'b1, 1'b0); // Read r1, r3; write r4; not branch
162
    @(negedge clk);
163
    clear_rename_inputs;
164
 
165
    // Check output src and dest tags
166
    if ((ds2_src1_tag != 'd1) || (ds2_src2_tag != 'd34) || (ds2_dest_tag != 'd35))
167
      fail('d2);
168
 
169
 
170
    // Rename a branch which does not write a register to allocate new checkpoint
171
    set_rename_inputs(3, 4, 4, 1'b0, 1'b1); // Read r3, r4; no write;  is branch
172
    @(negedge clk);
173
    clear_rename_inputs;
174
 
175
    // Check output src tags and checkpoint ptr
176
    if ((ds2_src1_tag != 'd34) || (ds2_src2_tag != 'd35) || (ds2_dest_tag != 'd36) ||
177
        (ds2_chkpt_ptr != 'd0))
178
      fail('d3);
179
 
180
 
181
    // Rename two more instructions to overwrite r3 and r4, then recover from checkpoint
182
    set_rename_inputs(1, 2, 3, 1'b1, 1'b0); // Read r1, r2; write r3; not branch
183
    @(negedge clk);
184
    // Check tag and chkpt_ptr outputs
185
    if ((ds2_src1_tag != 'd1) || (ds2_src2_tag != 'd2) || (ds2_dest_tag != 'd36) || (ds2_dest_tag_old != 'd34) || (ds2_chkpt_ptr != 'd1))
186
      fail('d4);
187
 
188
    set_rename_inputs(1, 3, 4, 1'b1, 1'b0); // Read r1, r3; write r4; not branch
189
    @(negedge clk);
190
    clear_rename_inputs;
191
    // Check tag and chkpt_ptr outputs
192
    if ((ds2_src1_tag != 'd1) || (ds2_src2_tag != 'd36) || (ds2_dest_tag_old != 'd35) || (ds2_chkpt_ptr != 'd1))
193
      fail('d5);
194
 
195
    // Retire in-flight instructions, then recover checkpoint from branch misprediction
196
    set_retire_inputs(1'b0, 1'b1, 1'b0, 0, 'd35, 'd3, 'd34, 'd3);
197
    @(negedge clk);
198
    set_retire_inputs(1'b0, 1'b1, 1'b0, 0, 'd36, 'd4, 'd35, 'd4);
199
    @(negedge clk);
200
    set_retire_inputs(1'b1, 1'b0, 1'b0, 0, 'd37, 'd4, 'd36, 'd35); // Branch flush, don't free checkpoint
201
    @(negedge clk);
202
    clear_retire_inputs;
203
 
204
    // Now rename instruction that reads r3 and r4
205
    set_rename_inputs(3, 4, 4, 1'b1, 1'b0); // Read r3, r4; write r4; not branch
206
    @(negedge clk);
207
    clear_rename_inputs;
208
    // Check output tags and chkpt_ptr
209
    if ((ds2_src1_tag != 'd34) || (ds2_src2_tag != 'd35) || (ds2_dest_tag != 'd37) || (ds2_dest_tag_old != 'd35) || (ds2_chkpt_ptr != 'd0))
210
      fail('d6);
211
 
212
 
213
 
214
    // Let clock run for a few cycles before finishing
215
    repeat (5) @(negedge clk);
216
    $display("Finished!");
217
    $finish;
218
  end
219
 
220
 
221
  // Task to easily set all rename inputs
222
  task set_rename_inputs;
223
    input [`REG_IDX_SZ-1:0] src1_idx, src2_idx, dest_idx;
224
    input                   dest_wr;
225
    input                   type_br;
226
 
227
    begin
228
      ds1_valid     = 1'b1;
229
      ds1_src1_idx  = src1_idx;
230
      ds1_src2_idx  = src2_idx;
231
      ds1_dest_idx  = dest_idx;
232
      ds1_dest_wr   = dest_wr;
233
      ds1_type_br   = type_br;
234
    end
235
  endtask
236
 
237
  task clear_rename_inputs;
238
    begin
239
      ds1_valid     = 1'b0;
240
      ds1_src1_idx  = 0;
241
      ds1_src2_idx  = 0;
242
      ds1_dest_wr   = 1'b0;
243
      ds1_type_br   = 1'b0;
244
    end
245
  endtask
246
 
247
  task set_retire_inputs;
248
    input                     pipe_flush, dest_write, chkpt_free;
249
    input [`CHKPT_PTR_SZ-1:0] chkpt_ptr;
250
    input [`FL_PTR_SZ-1:0]    fl_head_ptr;
251
    input [`REG_IDX_SZ-1:0]   dest_idx;
252
    input [`TAG_SZ-1:0]       dest_tag, dest_tag_old;
253
 
254
    begin
255
      rob_ds_ret_valid        = 1'b1;
256
      rob_pipe_flush          = pipe_flush;
257
      rob_ds_ret_dest_write   = dest_write;
258
      rob_ds_ret_chkpt_free   = chkpt_free;
259
      rob_ds_chkpt_ptr        = chkpt_ptr;
260
      rob_ds_fl_head_ptr      = fl_head_ptr;
261
      rob_ds_ret_idx          = dest_idx;
262
      rob_ds_ret_tag          = dest_tag;
263
      rob_ds_ret_tag_old      = dest_tag_old;
264
    end
265
  endtask
266
 
267
  task clear_retire_inputs;
268
    begin
269
      rob_ds_ret_valid        = 1'b0;
270
      rob_pipe_flush          = 1'b0;
271
      rob_ds_ret_dest_write   = 1'b0;
272
      rob_ds_ret_chkpt_free   = 1'b0;
273
      rob_ds_chkpt_ptr        = 0;
274
      rob_ds_fl_head_ptr      = 0;
275
      rob_ds_ret_idx          = 0;
276
      rob_ds_ret_tag          = 0;
277
      rob_ds_ret_tag_old      = 0;
278
    end
279
  endtask
280
 
281
  task fail;
282
    input integer test_num;
283
    begin
284
      $display("ERROR: Failed on test %0d at time %0d", test_num, $time);
285
      repeat(3) @(negedge clk);
286
      $finish;
287
    end
288
  endtask
289
endmodule

powered by: WebSVN 2.1.0

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