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

Subversion Repositories sparc64soc

[/] [sparc64soc/] [trunk/] [T1-common/] [srams/] [bw_r_irf.v] - Blame information for rev 8

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dmitryr
// ========== Copyright Header Begin ==========================================
2
// 
3
// OpenSPARC T1 Processor File: bw_r_irf.v
4
// Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
5
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
6
// 
7
// The above named program is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU General Public
9
// License version 2 as published by the Free Software Foundation.
10
// 
11
// The above named program is distributed in the hope that it will be 
12
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
// General Public License for more details.
15
// 
16
// You should have received a copy of the GNU General Public
17
// License along with this work; if not, write to the Free Software
18
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19
// 
20
// ========== Copyright Header End ============================================
21
////////////////////////////////////////////////////////////////////////
22
/*
23
//  Module Name: bw_r_irf
24
//      Description: Register file with 3 read ports and 2 write ports.  Has
25
//                              32 registers per thread with 4 threads.  Reading and writing
26
//                              the same register concurrently produces x.
27
*/
28
 
29
//FPGA_SYN enables all FPGA related modifications
30
`ifdef FPGA_SYN
31
`define FPGA_SYN_IRF
32
`endif
33
 
34
 
35
`ifdef FPGA_SYN_IRF
36
`ifdef FPGA_SYN_1THREAD
37
module bw_r_irf (/*AUTOARG*/
38
   // Outputs
39
   so, irf_byp_rs1_data_d_l, irf_byp_rs2_data_d_l,
40
   irf_byp_rs3_data_d_l, irf_byp_rs3h_data_d_l,
41
   // Inputs
42
   rclk, reset_l, si, se, sehold, rst_tri_en, ifu_exu_tid_s2,
43
   ifu_exu_rs1_s, ifu_exu_rs2_s, ifu_exu_rs3_s, ifu_exu_ren1_s,
44
   ifu_exu_ren2_s, ifu_exu_ren3_s, ecl_irf_wen_w, ecl_irf_wen_w2,
45
   ecl_irf_rd_m, ecl_irf_rd_g, byp_irf_rd_data_w, byp_irf_rd_data_w2,
46
   ecl_irf_tid_m, ecl_irf_tid_g, rml_irf_old_lo_cwp_e,
47
   rml_irf_new_lo_cwp_e, rml_irf_old_e_cwp_e, rml_irf_new_e_cwp_e,
48
   rml_irf_swap_even_e, rml_irf_swap_odd_e, rml_irf_swap_local_e,
49
   rml_irf_kill_restore_w, rml_irf_cwpswap_tid_e, rml_irf_old_agp,
50
   rml_irf_new_agp, rml_irf_swap_global, rml_irf_global_tid
51
   ) ;
52
   input rclk;
53
   input reset_l;
54
   input si;
55
   input se;
56
   input sehold;
57
   input rst_tri_en;
58
   input [1:0]  ifu_exu_tid_s2;  // s stage thread
59
   input [4:0]  ifu_exu_rs1_s;  // source addresses
60
   input [4:0]  ifu_exu_rs2_s;
61
   input [4:0]  ifu_exu_rs3_s;
62
   input ifu_exu_ren1_s;        // read enables for all 3 ports
63
   input ifu_exu_ren2_s;
64
   input ifu_exu_ren3_s;
65
   input ecl_irf_wen_w;        // write enables for both write ports
66
   input ecl_irf_wen_w2;
67
   input [4:0]  ecl_irf_rd_m;   // w destination
68
   input [4:0]  ecl_irf_rd_g;  // w2 destination
69
   input [71:0] byp_irf_rd_data_w;// write data from w1
70
   input [71:0] byp_irf_rd_data_w2;     // write data from w2
71
   input [1:0]  ecl_irf_tid_m;  // w stage thread
72
   input [1:0]  ecl_irf_tid_g; // w2 thread
73
 
74
   input [2:0]  rml_irf_old_lo_cwp_e;  // current window pointer for locals and odds
75
   input [2:0]  rml_irf_new_lo_cwp_e;  // target window pointer for locals and odds
76
   input [2:1]  rml_irf_old_e_cwp_e;  // current window pointer for evens
77
   input [2:1]  rml_irf_new_e_cwp_e;  // target window pointer for evens
78
   input        rml_irf_swap_even_e;
79
   input        rml_irf_swap_odd_e;
80
   input        rml_irf_swap_local_e;
81
   input        rml_irf_kill_restore_w;
82
   input [1:0]  rml_irf_cwpswap_tid_e;
83
 
84
   input [1:0]  rml_irf_old_agp; // alternate global pointer
85
   input [1:0]  rml_irf_new_agp; // alternate global pointer
86
   input        rml_irf_swap_global;
87
   input [1:0]  rml_irf_global_tid;
88
 
89
   output       so;
90
   output [71:0] irf_byp_rs1_data_d_l;
91
   output [71:0] irf_byp_rs2_data_d_l;
92
   output [71:0] irf_byp_rs3_data_d_l;
93
   output [31:0] irf_byp_rs3h_data_d_l;
94
 
95
   wire [71:0] irf_byp_rs1_data_d;
96
   wire [71:0] irf_byp_rs2_data_d;
97
   wire [71:0] irf_byp_rs3_data_d;
98
   wire [71:0] irf_byp_rs3h_data_d;
99
 
100
   wire [1:0]  ecl_irf_tid_w;  // w stage thread
101
   wire [1:0]  ecl_irf_tid_w2; // w2 thread
102
   wire [4:0]  ecl_irf_rd_w;   // w destination
103
   wire [4:0]  ecl_irf_rd_w2;  // w2 destination
104
   wire [1:0]  ifu_exu_thr_d;  // d stage thread
105
   wire ifu_exu_ren1_d;        // read enables for all 3 ports
106
   wire ifu_exu_ren2_d;
107
   wire ifu_exu_ren3_d;
108
   wire [4:0]  ifu_exu_rs1_d;  // source addresses
109
   wire [4:0]  ifu_exu_rs2_d;
110
   wire [4:0]  ifu_exu_rs3_d;
111
   wire [6:0]    thr_rs1;       // these 5 are a combination of the thr and reg
112
   wire [6:0]    thr_rs2;       // so that comparison can be done more easily
113
   wire [6:0]    thr_rs3;
114
   wire [6:0]    thr_rs3h;
115
   wire [6:0]    thr_rd_w;
116
   wire [6:0]    thr_rd_w2;
117
 
118
   reg [1:0] cwpswap_tid_m;
119
   reg [1:0] cwpswap_tid_w;
120
   reg [2:0] old_lo_cwp_m;
121
   reg [2:0] new_lo_cwp_m;
122
   reg [2:0] new_lo_cwp_w;
123
   reg [1:0] old_e_cwp_m;
124
   reg [1:0] new_e_cwp_m;
125
   reg [1:0] new_e_cwp_w;
126
   reg       swap_local_m;
127
   reg       swap_local_w;
128
   reg       swap_even_m;
129
   reg       swap_even_w;
130
   reg       swap_odd_m;
131
   reg       swap_odd_w;
132
   reg       kill_restore_d1;
133
   reg        swap_global_d1;
134
   reg        swap_global_d2;
135
   reg [1:0]  global_tid_d1;
136
   reg [1:0]  global_tid_d2;
137
   reg [1:0] old_agp_d1,
138
             new_agp_d1,
139
             new_agp_d2;
140
 
141
`ifdef FPGA_SYN_SAVE_BRAM
142
   wire [71:0] active_win_thr_rd_w_neg;
143
   wire [71:0] active_win_thr_rd_w2_neg;
144
   wire [6:0]  thr_rd_w_neg;
145
   wire [6:0]  thr_rd_w2_neg;
146
   wire        active_win_thr_rd_w_neg_wr_en;
147
   wire        active_win_thr_rd_w2_neg_wr_en;
148
   wire        rst_tri_en_neg;
149
`else
150
   reg [71:0] active_win_thr_rd_w_neg;
151
   reg [71:0] active_win_thr_rd_w2_neg;
152
   reg [6:0]  thr_rd_w_neg;
153
   reg [6:0]  thr_rd_w2_neg;
154
   reg        active_win_thr_rd_w_neg_wr_en;
155
   reg        active_win_thr_rd_w2_neg_wr_en;
156
   reg        rst_tri_en_neg;
157
`endif
158
 
159
   wire          se;
160
   wire          clk;
161
//   assign        clk = rclk & reset_l;
162
   assign        clk = rclk;
163
 
164
   wire          ren1_s;
165
   wire          ren2_s;
166
   wire          ren3_s;
167
   wire [4:0]    rs1_s;
168
   wire [4:0]    rs2_s;
169
   wire [4:0]    rs3_s;
170
   wire [1:0]    tid_s;
171
   wire [1:0]    tid_g;
172
   wire [1:0]    tid_m;
173
   wire [4:0]    rd_m;
174
   wire [4:0]    rd_g;
175
   wire          kill_restore_w;
176
   wire          swap_global_d1_vld;
177
   wire          swap_local_m_vld;
178
   wire          swap_even_m_vld;
179
   wire          swap_odd_m_vld;
180
 
181
   assign {ren1_s,ren2_s,ren3_s,rs1_s[4:0],rs2_s[4:0],rs3_s[4:0],tid_s[1:0],tid_g[1:0],tid_m[1:0],
182
           rd_m[4:0], rd_g[4:0]} = (sehold)?
183
          {ifu_exu_ren1_d,ifu_exu_ren2_d,ifu_exu_ren3_d,ifu_exu_rs1_d[4:0],ifu_exu_rs2_d[4:0],
184
           ifu_exu_rs3_d[4:0],ifu_exu_thr_d[1:0],ecl_irf_tid_w2[1:0],ecl_irf_tid_w[1:0],
185
           ecl_irf_rd_w[4:0],ecl_irf_rd_w2[4:0]}:
186
          {ifu_exu_ren1_s,ifu_exu_ren2_s,ifu_exu_ren3_s,ifu_exu_rs1_s[4:0],ifu_exu_rs2_s[4:0],
187
           ifu_exu_rs3_s[4:0],ifu_exu_tid_s2[1:0],ecl_irf_tid_g[1:0],ecl_irf_tid_m[1:0],
188
           ecl_irf_rd_m[4:0],ecl_irf_rd_g[4:0]};
189
   // Pipeline flops for irf control signals
190
   dff_s dff_ren1_s2d(.din(ren1_s), .clk(clk), .q(ifu_exu_ren1_d), .se(se),
191
                    .si(), .so());
192
   dff_s dff_ren2_s2d(.din(ren2_s), .clk(clk), .q(ifu_exu_ren2_d), .se(se),
193
                    .si(), .so());
194
   dff_s dff_ren3_s2d(.din(ren3_s), .clk(clk), .q(ifu_exu_ren3_d), .se(se),
195
                    .si(), .so());
196
   dff_s #5 dff_rs1_s2d(.din(rs1_s[4:0]), .clk(clk), .q(ifu_exu_rs1_d[4:0]), .se(se),
197
                      .si(),.so());
198
   dff_s #5 dff_rs2_s2d(.din(rs2_s[4:0]), .clk(clk), .q(ifu_exu_rs2_d[4:0]), .se(se),
199
                      .si(),.so());
200
   dff_s #5 dff_rs3_s2d(.din(rs3_s[4:0]), .clk(clk), .q(ifu_exu_rs3_d[4:0]), .se(se),
201
                      .si(),.so());
202
   dff_s #2 dff_thr_s2d(.din(tid_s[1:0]), .clk(clk), .q(ifu_exu_thr_d[1:0]), .se(se),
203
                      .si(),.so());
204
   dff_s #2 dff_thr_g2w2(.din(tid_g[1:0]), .clk(clk), .q(ecl_irf_tid_w2[1:0]), .se(se),
205
                      .si(),.so());
206
   dff_s #2 dff_thr_m2w(.din(tid_m[1:0]), .clk(clk), .q(ecl_irf_tid_w[1:0]), .se(se),
207
                      .si(),.so());
208
   dff_s #5 dff_rd_m2w(.din(rd_m[4:0]), .clk(clk), .q(ecl_irf_rd_w[4:0]), .se(se),
209
                      .si(),.so());
210
   dff_s #5 dff_rd_g2w2(.din(rd_g[4:0]), .clk(clk), .q(ecl_irf_rd_w2[4:0]), .se(se),
211
                      .si(),.so());
212
 
213
   // Concatenate the thread and rs1/rd bits together
214
   assign        thr_rs1[6:0] = {ifu_exu_thr_d, ifu_exu_rs1_d};
215
   assign        thr_rs2[6:0] = {ifu_exu_thr_d, ifu_exu_rs2_d};
216
   assign        thr_rs3[6:0] = {ifu_exu_thr_d, ifu_exu_rs3_d[4:0]};
217
   assign        thr_rs3h[6:0] = {ifu_exu_thr_d[1:0], ifu_exu_rs3_d[4:1], 1'b1};
218
   assign        thr_rd_w[6:0] = {ecl_irf_tid_w, ecl_irf_rd_w};
219
   assign        thr_rd_w2[6:0] = {ecl_irf_tid_w2, ecl_irf_rd_w2};
220
 
221
   // Active low outputs
222
   assign        irf_byp_rs1_data_d_l[71:0] = ~irf_byp_rs1_data_d[71:0];
223
   assign        irf_byp_rs2_data_d_l[71:0] = ~irf_byp_rs2_data_d[71:0];
224
   assign        irf_byp_rs3_data_d_l[71:0] = ~irf_byp_rs3_data_d[71:0];
225
   assign        irf_byp_rs3h_data_d_l[31:0] = ~irf_byp_rs3h_data_d[31:0];
226
 
227
/////////////////////////////////////////////////////////////////
228
///  Write ports
229
////////////////////////////////////////////////////////////////
230
   // This is a latch that works if both wen is high and clk is low
231
 
232
`ifdef FPGA_SYN_SAVE_BRAM
233
  assign rst_tri_en_neg = rst_tri_en;
234
  assign active_win_thr_rd_w_neg = byp_irf_rd_data_w;
235
  assign active_win_thr_rd_w2_neg = byp_irf_rd_data_w2;
236
  assign thr_rd_w_neg = thr_rd_w;
237
  assign thr_rd_w2_neg = thr_rd_w2;
238
  assign active_win_thr_rd_w_neg_wr_en = ecl_irf_wen_w & (thr_rd_w[4:0] != 5'b0);
239
  assign active_win_thr_rd_w2_neg_wr_en = ecl_irf_wen_w2 & (thr_rd_w2[4:0] != 5'b0);
240
`else
241
 
242
   always @(negedge clk) begin
243
      rst_tri_en_neg <= rst_tri_en;
244
      // write conflict results in X written to destination
245
      if (ecl_irf_wen_w & ecl_irf_wen_w2 & (thr_rd_w[6:0] == thr_rd_w2[6:0])) begin
246
         active_win_thr_rd_w_neg <= {72{1'bx}};
247
         thr_rd_w_neg <= thr_rd_w;
248
         active_win_thr_rd_w_neg_wr_en <= 1'b1;
249
         active_win_thr_rd_w2_neg_wr_en <= 1'b0;
250
      end
251
      else begin
252
         // W1 write port
253
         if (ecl_irf_wen_w & (thr_rd_w[4:0] != 5'b0)) begin
254
            active_win_thr_rd_w_neg <= byp_irf_rd_data_w;
255
            thr_rd_w_neg <= thr_rd_w;
256
            active_win_thr_rd_w_neg_wr_en <= 1'b1;
257
         end
258
         else
259
           active_win_thr_rd_w_neg_wr_en <= 1'b0;
260
 
261
         // W2 write port
262
         if (ecl_irf_wen_w2 & (thr_rd_w2[4:0] != 5'b0)) begin
263
            active_win_thr_rd_w2_neg <= byp_irf_rd_data_w2;
264
            thr_rd_w2_neg <= thr_rd_w2;
265
            active_win_thr_rd_w2_neg_wr_en <= 1'b1;
266
         end
267
         else
268
           active_win_thr_rd_w2_neg_wr_en <= 1'b0;
269
      end
270
   end
271
 
272
`endif
273
 
274
 
275
 
276
/* MOVED TO CMP ENVIRONMENT
277
   initial begin
278
      // Hardcode R0 to zero
279
      active_window[{2'b00, 5'b00000}] = 72'b0;
280
      active_window[{2'b01, 5'b00000}] = 72'b0;
281
      active_window[{2'b10, 5'b00000}] = 72'b0;
282
      active_window[{2'b11, 5'b00000}] = 72'b0;
283
   end
284
*/
285
   //////////////////////////////////////////////////
286
   // Window management logic
287
   //////////////////////////////////////////////////
288
   // Pipeline flops for control signals
289
 
290
   // cwp swap signals
291
   assign kill_restore_w = (sehold)? kill_restore_d1: rml_irf_kill_restore_w;
292
   assign swap_local_m_vld = swap_local_m & ~rst_tri_en;
293
   assign swap_odd_m_vld = swap_odd_m & ~rst_tri_en;
294
   assign swap_even_m_vld = swap_even_m & ~rst_tri_en;
295
   assign swap_global_d1_vld = swap_global_d1 & ~rst_tri_en;
296
 
297
   always @ (posedge clk) begin
298
      cwpswap_tid_m[1:0] <= (sehold)? cwpswap_tid_m[1:0]: rml_irf_cwpswap_tid_e[1:0];
299
      cwpswap_tid_w[1:0] <= cwpswap_tid_m[1:0];
300
      old_lo_cwp_m[2:0] <= (sehold)? old_lo_cwp_m[2:0]: rml_irf_old_lo_cwp_e[2:0];
301
      new_lo_cwp_m[2:0] <= (sehold)? new_lo_cwp_m[2:0]: rml_irf_new_lo_cwp_e[2:0];
302
      new_lo_cwp_w[2:0] <= new_lo_cwp_m[2:0];
303
      old_e_cwp_m[1:0] <= (sehold)? old_e_cwp_m[1:0]: rml_irf_old_e_cwp_e[2:1];
304
      new_e_cwp_m[1:0] <= (sehold)? new_e_cwp_m[1:0]: rml_irf_new_e_cwp_e[2:1];
305
      new_e_cwp_w[1:0] <= new_e_cwp_m[1:0];
306
      swap_local_m <= (sehold)? swap_local_m & rst_tri_en: rml_irf_swap_local_e;
307
      swap_local_w <= swap_local_m_vld;
308
      swap_odd_m <= (sehold)? swap_odd_m & rst_tri_en: rml_irf_swap_odd_e;
309
      swap_odd_w <= swap_odd_m_vld;
310
      swap_even_m <= (sehold)? swap_even_m & rst_tri_en: rml_irf_swap_even_e;
311
      swap_even_w <= swap_even_m_vld;
312
      kill_restore_d1 <= kill_restore_w;
313
   end
314
   // global swap signals    
315
   always @ (posedge clk) begin
316
      swap_global_d1 <= (sehold)? swap_global_d1 & rst_tri_en: rml_irf_swap_global;
317
      swap_global_d2 <= swap_global_d1_vld;
318
      global_tid_d1[1:0] <= (sehold)? global_tid_d1[1:0]: rml_irf_global_tid[1:0];
319
      global_tid_d2[1:0] <= global_tid_d1[1:0];
320
      old_agp_d1[1:0] <= (sehold)? old_agp_d1[1:0]: rml_irf_old_agp[1:0];
321
      new_agp_d1[1:0] <= (sehold)? new_agp_d1[1:0]: rml_irf_new_agp[1:0];
322
      new_agp_d2[1:0] <= new_agp_d1[1:0];
323
   end
324
 
325
  wire wr_en  = active_win_thr_rd_w_neg_wr_en & (~rst_tri_en | ~rst_tri_en_neg);
326
  wire wr_en2 = active_win_thr_rd_w2_neg_wr_en & (~rst_tri_en | ~rst_tri_en_neg);
327
 
328
// synthesis translate_off
329
  always @(posedge clk) begin
330
    if(wr_en)
331
      $display("Write Port 1: %h %h", active_win_thr_rd_w_neg, thr_rd_w_neg );
332
    if(wr_en2)
333
      $display("Write Port 2: %h %h", active_win_thr_rd_w2_neg, thr_rd_w2_neg );
334
    if(ifu_exu_ren1_d) begin
335
      @(posedge clk);
336
      $display("Read Port 1: %h %h", irf_byp_rs1_data_d, thr_rs1);
337
    end
338
    if(ifu_exu_ren2_d) begin
339
      @(posedge clk);
340
      $display("Read Port 2: %h %h", irf_byp_rs2_data_d, thr_rs2);
341
    end
342
    if(ifu_exu_ren3_d) begin
343
      @(posedge clk);
344
      $display("Read Port 3: %h %h", irf_byp_rs3_data_d, thr_rs3);
345
    end
346
  end
347
//synthesis translate_on
348
 
349
bw_r_irf_core bw_r_irf_core (
350
        .clk                    (clk),
351
        .ifu_exu_ren1_d         (ifu_exu_ren1_d),
352
        .ifu_exu_ren2_d         (ifu_exu_ren2_d),
353
        .ifu_exu_ren3_d         (ifu_exu_ren3_d),
354
        .thr_rs1                (thr_rs1),
355
        .thr_rs2                (thr_rs2),
356
        .thr_rs3                (thr_rs3),
357
        .thr_rs3h               (thr_rs3h),
358
        .irf_byp_rs1_data_d     (irf_byp_rs1_data_d),
359
        .irf_byp_rs2_data_d     (irf_byp_rs2_data_d),
360
        .irf_byp_rs3_data_d     (irf_byp_rs3_data_d),
361
        .irf_byp_rs3h_data_d    (irf_byp_rs3h_data_d),
362
        .wr_en                  (wr_en),
363
        .wr_en2                 (wr_en2),
364
        .active_win_thr_rd_w_neg(active_win_thr_rd_w_neg),
365
        .active_win_thr_rd_w2_neg(active_win_thr_rd_w2_neg),
366
        .thr_rd_w_neg           (thr_rd_w_neg),
367
        .thr_rd_w2_neg          (thr_rd_w2_neg),
368
        .swap_global_d1_vld     (swap_global_d1_vld),
369
        .swap_global_d2         (swap_global_d2),
370
        .global_tid_d1          (global_tid_d1),
371
        .global_tid_d2          (global_tid_d2),
372
        .old_agp_d1             (old_agp_d1),
373
        .new_agp_d2             (new_agp_d2),
374
        .swap_local_m_vld       (swap_local_m_vld),
375
        .swap_local_w           (swap_local_w),
376
        .old_lo_cwp_m           (old_lo_cwp_m),
377
        .new_lo_cwp_w           (new_lo_cwp_w),
378
        .swap_even_m_vld        (swap_even_m_vld),
379
        .swap_even_w            (swap_even_w),
380
        .old_e_cwp_m            (old_e_cwp_m),
381
        .new_e_cwp_w            (new_e_cwp_w),
382
        .swap_odd_m_vld         (swap_odd_m_vld),
383
        .swap_odd_w             (swap_odd_w),
384
        .cwpswap_tid_m          (cwpswap_tid_m),
385
        .cwpswap_tid_w          (cwpswap_tid_w),
386
        .kill_restore_w         (kill_restore_w)
387
        );
388
 
389
endmodule // bw_r_irf
390
 
391
module bw_r_irf_core(
392
        clk,
393
        ifu_exu_ren1_d,
394
        ifu_exu_ren2_d,
395
        ifu_exu_ren3_d,
396
        thr_rs1,
397
        thr_rs2,
398
        thr_rs3,
399
        thr_rs3h,
400
        irf_byp_rs1_data_d,
401
        irf_byp_rs2_data_d,
402
        irf_byp_rs3_data_d,
403
        irf_byp_rs3h_data_d,
404
        wr_en,
405
        wr_en2,
406
        active_win_thr_rd_w_neg,
407
        active_win_thr_rd_w2_neg,
408
        thr_rd_w_neg,
409
        thr_rd_w2_neg,
410
        swap_global_d1_vld,
411
        swap_global_d2,
412
        global_tid_d1,
413
        global_tid_d2,
414
        old_agp_d1,
415
        new_agp_d2,
416
        swap_local_m_vld,
417
        swap_local_w,
418
        old_lo_cwp_m,
419
        new_lo_cwp_w,
420
        swap_even_m_vld,
421
        swap_even_w,
422
        old_e_cwp_m,
423
        new_e_cwp_w,
424
        swap_odd_m_vld,
425
        swap_odd_w,
426
        cwpswap_tid_m,
427
        cwpswap_tid_w,
428
        kill_restore_w);
429
 
430
 
431
        input           clk;
432
        input           ifu_exu_ren1_d;
433
        input           ifu_exu_ren2_d;
434
        input           ifu_exu_ren3_d;
435
 
436
        input   [6:0]    thr_rs1;
437
        input   [6:0]    thr_rs2;
438
        input   [6:0]    thr_rs3;
439
        input   [6:0]    thr_rs3h;
440
 
441
        output  [71:0]   irf_byp_rs1_data_d;
442
        output  [71:0]   irf_byp_rs2_data_d;
443
        output  [71:0]   irf_byp_rs3_data_d;
444
        output  [71:0]   irf_byp_rs3h_data_d;
445
 
446
 
447
        reg     [71:0]   irf_byp_rs1_data_d;
448
        reg     [71:0]   irf_byp_rs2_data_d;
449
        reg     [71:0]   irf_byp_rs3_data_d;
450
        reg     [71:0]   irf_byp_rs3h_data_d;
451
 
452
        input           wr_en;
453
        input           wr_en2;
454
        input   [71:0]   active_win_thr_rd_w_neg;
455
        input   [71:0]   active_win_thr_rd_w2_neg;
456
        input   [6:0]    thr_rd_w_neg;
457
        input   [6:0]    thr_rd_w2_neg;
458
 
459
        input           swap_global_d1_vld;
460
        input           swap_global_d2;
461
        input   [1:0]    global_tid_d1;
462
        input   [1:0]    global_tid_d2;
463
        input   [1:0]    old_agp_d1;
464
        input   [1:0]    new_agp_d2;
465
 
466
        input           swap_local_m_vld;
467
        input           swap_local_w;
468
        input   [2:0]    old_lo_cwp_m;
469
        input   [2:0]    new_lo_cwp_w;
470
 
471
        input           swap_even_m_vld;
472
        input           swap_even_w;
473
        input   [1:0]    old_e_cwp_m;
474
        input   [1:0]    new_e_cwp_w;
475
 
476
        input           swap_odd_m_vld;
477
        input           swap_odd_w;
478
 
479
        input   [1:0]    cwpswap_tid_m;
480
        input   [1:0]    cwpswap_tid_w;
481
 
482
        input           kill_restore_w;
483
 
484
 
485
        wire    [71:0]   rd_data00;
486
        wire    [71:0]   rd_data01;
487
        wire    [71:0]   rd_data02;
488
        wire    [71:0]   rd_data03;
489
        wire    [71:0]   rd_data04;
490
        wire    [71:0]   rd_data05;
491
        wire    [71:0]   rd_data06;
492
        wire    [71:0]   rd_data07;
493
        wire    [71:0]   rd_data08;
494
        wire    [71:0]   rd_data09;
495
        wire    [71:0]   rd_data10;
496
        wire    [71:0]   rd_data11;
497
        wire    [71:0]   rd_data12;
498
        wire    [71:0]   rd_data13;
499
        wire    [71:0]   rd_data14;
500
        wire    [71:0]   rd_data15;
501
        wire    [71:0]   rd_data16;
502
        wire    [71:0]   rd_data17;
503
        wire    [71:0]   rd_data18;
504
        wire    [71:0]   rd_data19;
505
        wire    [71:0]   rd_data20;
506
        wire    [71:0]   rd_data21;
507
        wire    [71:0]   rd_data22;
508
        wire    [71:0]   rd_data23;
509
        wire    [71:0]   rd_data24;
510
        wire    [71:0]   rd_data25;
511
        wire    [71:0]   rd_data26;
512
        wire    [71:0]   rd_data27;
513
        wire    [71:0]   rd_data28;
514
        wire    [71:0]   rd_data29;
515
        wire    [71:0]   rd_data30;
516
        wire    [71:0]   rd_data31;
517
 
518
// synthesis translate_off
519
always @(posedge clk) begin
520
        if(ifu_exu_ren1_d | ifu_exu_ren2_d | ifu_exu_ren3_d) begin
521
                if(thr_rs1[6:5] != 2'b00) begin
522
                        $display("Accessing thread # other than 0");
523
                        $finish;
524
                end
525
        end
526
end
527
// synthesis translate_on
528
 
529
   //reg [71:0]    active_window [127:0];// 32x4 72 bit registers
530
 
531
        always @(negedge clk)
532
          if(ifu_exu_ren1_d) //comes from a posedge clk
533
          case(thr_rs1[4:0])
534
            5'b00000: irf_byp_rs1_data_d <= rd_data00;
535
            5'b00001: irf_byp_rs1_data_d <= rd_data01;
536
            5'b00010: irf_byp_rs1_data_d <= rd_data02;
537
            5'b00011: irf_byp_rs1_data_d <= rd_data03;
538
            5'b00100: irf_byp_rs1_data_d <= rd_data04;
539
            5'b00101: irf_byp_rs1_data_d <= rd_data05;
540
            5'b00110: irf_byp_rs1_data_d <= rd_data06;
541
            5'b00111: irf_byp_rs1_data_d <= rd_data07;
542
            5'b01000: irf_byp_rs1_data_d <= rd_data08;
543
            5'b01001: irf_byp_rs1_data_d <= rd_data09;
544
            5'b01010: irf_byp_rs1_data_d <= rd_data10;
545
            5'b01011: irf_byp_rs1_data_d <= rd_data11;
546
            5'b01100: irf_byp_rs1_data_d <= rd_data12;
547
            5'b01101: irf_byp_rs1_data_d <= rd_data13;
548
            5'b01110: irf_byp_rs1_data_d <= rd_data14;
549
            5'b01111: irf_byp_rs1_data_d <= rd_data15;
550
            5'b10000: irf_byp_rs1_data_d <= rd_data16;
551
            5'b10001: irf_byp_rs1_data_d <= rd_data17;
552
            5'b10010: irf_byp_rs1_data_d <= rd_data18;
553
            5'b10011: irf_byp_rs1_data_d <= rd_data19;
554
            5'b10100: irf_byp_rs1_data_d <= rd_data20;
555
            5'b10101: irf_byp_rs1_data_d <= rd_data21;
556
            5'b10110: irf_byp_rs1_data_d <= rd_data22;
557
            5'b10111: irf_byp_rs1_data_d <= rd_data23;
558
            5'b11000: irf_byp_rs1_data_d <= rd_data24;
559
            5'b11001: irf_byp_rs1_data_d <= rd_data25;
560
            5'b11010: irf_byp_rs1_data_d <= rd_data26;
561
            5'b11011: irf_byp_rs1_data_d <= rd_data27;
562
            5'b11100: irf_byp_rs1_data_d <= rd_data28;
563
            5'b11101: irf_byp_rs1_data_d <= rd_data29;
564
            5'b11110: irf_byp_rs1_data_d <= rd_data30;
565
            5'b11111: irf_byp_rs1_data_d <= rd_data31;
566
          endcase
567
 
568
        always @(negedge clk)
569
          if(ifu_exu_ren2_d)
570
          case(thr_rs2[4:0])
571
            5'b00000: irf_byp_rs2_data_d <= rd_data00;
572
            5'b00001: irf_byp_rs2_data_d <= rd_data01;
573
            5'b00010: irf_byp_rs2_data_d <= rd_data02;
574
            5'b00011: irf_byp_rs2_data_d <= rd_data03;
575
            5'b00100: irf_byp_rs2_data_d <= rd_data04;
576
            5'b00101: irf_byp_rs2_data_d <= rd_data05;
577
            5'b00110: irf_byp_rs2_data_d <= rd_data06;
578
            5'b00111: irf_byp_rs2_data_d <= rd_data07;
579
            5'b01000: irf_byp_rs2_data_d <= rd_data08;
580
            5'b01001: irf_byp_rs2_data_d <= rd_data09;
581
            5'b01010: irf_byp_rs2_data_d <= rd_data10;
582
            5'b01011: irf_byp_rs2_data_d <= rd_data11;
583
            5'b01100: irf_byp_rs2_data_d <= rd_data12;
584
            5'b01101: irf_byp_rs2_data_d <= rd_data13;
585
            5'b01110: irf_byp_rs2_data_d <= rd_data14;
586
            5'b01111: irf_byp_rs2_data_d <= rd_data15;
587
            5'b10000: irf_byp_rs2_data_d <= rd_data16;
588
            5'b10001: irf_byp_rs2_data_d <= rd_data17;
589
            5'b10010: irf_byp_rs2_data_d <= rd_data18;
590
            5'b10011: irf_byp_rs2_data_d <= rd_data19;
591
            5'b10100: irf_byp_rs2_data_d <= rd_data20;
592
            5'b10101: irf_byp_rs2_data_d <= rd_data21;
593
            5'b10110: irf_byp_rs2_data_d <= rd_data22;
594
            5'b10111: irf_byp_rs2_data_d <= rd_data23;
595
            5'b11000: irf_byp_rs2_data_d <= rd_data24;
596
            5'b11001: irf_byp_rs2_data_d <= rd_data25;
597
            5'b11010: irf_byp_rs2_data_d <= rd_data26;
598
            5'b11011: irf_byp_rs2_data_d <= rd_data27;
599
            5'b11100: irf_byp_rs2_data_d <= rd_data28;
600
            5'b11101: irf_byp_rs2_data_d <= rd_data29;
601
            5'b11110: irf_byp_rs2_data_d <= rd_data30;
602
            5'b11111: irf_byp_rs2_data_d <= rd_data31;
603
          endcase
604
 
605
        always @(negedge clk)
606
          if(ifu_exu_ren3_d)
607
          case(thr_rs3[4:0])
608
            5'b00000: irf_byp_rs3_data_d <= rd_data00;
609
            5'b00001: irf_byp_rs3_data_d <= rd_data01;
610
            5'b00010: irf_byp_rs3_data_d <= rd_data02;
611
            5'b00011: irf_byp_rs3_data_d <= rd_data03;
612
            5'b00100: irf_byp_rs3_data_d <= rd_data04;
613
            5'b00101: irf_byp_rs3_data_d <= rd_data05;
614
            5'b00110: irf_byp_rs3_data_d <= rd_data06;
615
            5'b00111: irf_byp_rs3_data_d <= rd_data07;
616
            5'b01000: irf_byp_rs3_data_d <= rd_data08;
617
            5'b01001: irf_byp_rs3_data_d <= rd_data09;
618
            5'b01010: irf_byp_rs3_data_d <= rd_data10;
619
            5'b01011: irf_byp_rs3_data_d <= rd_data11;
620
            5'b01100: irf_byp_rs3_data_d <= rd_data12;
621
            5'b01101: irf_byp_rs3_data_d <= rd_data13;
622
            5'b01110: irf_byp_rs3_data_d <= rd_data14;
623
            5'b01111: irf_byp_rs3_data_d <= rd_data15;
624
            5'b10000: irf_byp_rs3_data_d <= rd_data16;
625
            5'b10001: irf_byp_rs3_data_d <= rd_data17;
626
            5'b10010: irf_byp_rs3_data_d <= rd_data18;
627
            5'b10011: irf_byp_rs3_data_d <= rd_data19;
628
            5'b10100: irf_byp_rs3_data_d <= rd_data20;
629
            5'b10101: irf_byp_rs3_data_d <= rd_data21;
630
            5'b10110: irf_byp_rs3_data_d <= rd_data22;
631
            5'b10111: irf_byp_rs3_data_d <= rd_data23;
632
            5'b11000: irf_byp_rs3_data_d <= rd_data24;
633
            5'b11001: irf_byp_rs3_data_d <= rd_data25;
634
            5'b11010: irf_byp_rs3_data_d <= rd_data26;
635
            5'b11011: irf_byp_rs3_data_d <= rd_data27;
636
            5'b11100: irf_byp_rs3_data_d <= rd_data28;
637
            5'b11101: irf_byp_rs3_data_d <= rd_data29;
638
            5'b11110: irf_byp_rs3_data_d <= rd_data30;
639
            5'b11111: irf_byp_rs3_data_d <= rd_data31;
640
          endcase
641
 
642
        always @(negedge clk)
643
          if(ifu_exu_ren3_d)
644
          case(thr_rs3h[4:1])
645
            4'b0000: irf_byp_rs3h_data_d <= rd_data01;
646
            4'b0001: irf_byp_rs3h_data_d <= rd_data03;
647
            4'b0010: irf_byp_rs3h_data_d <= rd_data05;
648
            4'b0011: irf_byp_rs3h_data_d <= rd_data07;
649
            4'b0100: irf_byp_rs3h_data_d <= rd_data09;
650
            4'b0101: irf_byp_rs3h_data_d <= rd_data11;
651
            4'b0110: irf_byp_rs3h_data_d <= rd_data13;
652
            4'b0111: irf_byp_rs3h_data_d <= rd_data15;
653
            4'b1000: irf_byp_rs3h_data_d <= rd_data17;
654
            4'b1001: irf_byp_rs3h_data_d <= rd_data19;
655
            4'b1010: irf_byp_rs3h_data_d <= rd_data21;
656
            4'b1011: irf_byp_rs3h_data_d <= rd_data23;
657
            4'b1100: irf_byp_rs3h_data_d <= rd_data25;
658
            4'b1101: irf_byp_rs3h_data_d <= rd_data27;
659
            4'b1110: irf_byp_rs3h_data_d <= rd_data29;
660
            4'b1111: irf_byp_rs3h_data_d <= rd_data31;
661
          endcase
662
 
663
wire wren = wr_en | wr_en2;
664
wire [4:0] wr_addr = wr_en ? thr_rd_w_neg[4:0] : thr_rd_w2_neg[4:0];
665
wire [71:0] wr_data = wr_en ? active_win_thr_rd_w_neg : active_win_thr_rd_w2_neg;
666
 
667
//GLOBALs
668
bw_r_irf_register register00(
669
                .clk(clk),
670
                .wren(wren & (wr_addr == 5'b00000)),
671
                .save(swap_global_d1_vld),
672
                .save_addr({1'b0,old_agp_d1[1:0]}),
673
                .restore(swap_global_d2),
674
                .restore_addr({1'b0,new_agp_d2[1:0]}),
675
                .wr_data(72'b0),
676
                .rd_data(rd_data00)
677
);
678
 
679
bw_r_irf_register register01(
680
                .clk(clk),
681
                .wren(wren & (wr_addr == 5'b00001)),
682
                .save(swap_global_d1_vld),
683
                .save_addr({1'b0,old_agp_d1[1:0]}),
684
                .restore(swap_global_d2),
685
                .restore_addr({1'b0,new_agp_d2[1:0]}),
686
                .wr_data(wr_data),
687
                .rd_data(rd_data01)
688
);
689
 
690
bw_r_irf_register register02(
691
                .clk(clk),
692
                .wren(wren & (wr_addr == 5'b00010)),
693
                .save(swap_global_d1_vld),
694
                .save_addr({1'b0,old_agp_d1[1:0]}),
695
                .restore(swap_global_d2),
696
                .restore_addr({1'b0,new_agp_d2[1:0]}),
697
                .wr_data(wr_data),
698
                .rd_data(rd_data02)
699
);
700
 
701
bw_r_irf_register register03(
702
                .clk(clk),
703
                .wren(wren & (wr_addr == 5'b00011)),
704
                .save(swap_global_d1_vld),
705
                .save_addr({1'b0,old_agp_d1[1:0]}),
706
                .restore(swap_global_d2),
707
                .restore_addr({1'b0,new_agp_d2[1:0]}),
708
                .wr_data(wr_data),
709
                .rd_data(rd_data03)
710
);
711
 
712
bw_r_irf_register register04(
713
                .clk(clk),
714
                .wren(wren & (wr_addr == 5'b00100)),
715
                .save(swap_global_d1_vld),
716
                .save_addr({1'b0,old_agp_d1[1:0]}),
717
                .restore(swap_global_d2),
718
                .restore_addr({1'b0,new_agp_d2[1:0]}),
719
                .wr_data(wr_data),
720
                .rd_data(rd_data04)
721
);
722
 
723
bw_r_irf_register register05(
724
                .clk(clk),
725
                .wren(wren & (wr_addr == 5'b00101)),
726
                .save(swap_global_d1_vld),
727
                .save_addr({1'b0,old_agp_d1[1:0]}),
728
                .restore(swap_global_d2),
729
                .restore_addr({1'b0,new_agp_d2[1:0]}),
730
                .wr_data(wr_data),
731
                .rd_data(rd_data05)
732
);
733
 
734
bw_r_irf_register register06(
735
                .clk(clk),
736
                .wren(wren & (wr_addr == 5'b00110)),
737
                .save(swap_global_d1_vld),
738
                .save_addr({1'b0,old_agp_d1[1:0]}),
739
                .restore(swap_global_d2),
740
                .restore_addr({1'b0,new_agp_d2[1:0]}),
741
                .wr_data(wr_data),
742
                .rd_data(rd_data06)
743
);
744
 
745
bw_r_irf_register register07(
746
                .clk(clk),
747
                .wren(wren & (wr_addr == 5'b00111)),
748
                .save(swap_global_d1_vld),
749
                .save_addr({1'b0,old_agp_d1[1:0]}),
750
                .restore(swap_global_d2),
751
                .restore_addr({1'b0,new_agp_d2[1:0]}),
752
                .wr_data(wr_data),
753
                .rd_data(rd_data07)
754
);
755
 
756
//ODDs
757
bw_r_irf_register register08(
758
                .clk(clk),
759
                .wren(wren & (wr_addr == 5'b01000)),
760
                .save(swap_odd_m_vld),
761
                .save_addr({1'b0,old_lo_cwp_m[2:1]}),
762
                .restore(swap_odd_w & ~kill_restore_w),
763
                .restore_addr({1'b0,new_lo_cwp_w[2:1]}),
764
                .wr_data(wr_data),
765
                .rd_data(rd_data08)
766
);
767
 
768
bw_r_irf_register register09(
769
                .clk(clk),
770
                .wren(wren & (wr_addr == 5'b01001)),
771
                .save(swap_odd_m_vld),
772
                .save_addr({1'b0,old_lo_cwp_m[2:1]}),
773
                .restore(swap_odd_w & ~kill_restore_w),
774
                .restore_addr({1'b0,new_lo_cwp_w[2:1]}),
775
                .wr_data(wr_data),
776
                .rd_data(rd_data09)
777
);
778
 
779
bw_r_irf_register register10(
780
                .clk(clk),
781
                .wren(wren & (wr_addr == 5'b01010)),
782
                .save(swap_odd_m_vld),
783
                .save_addr({1'b0,old_lo_cwp_m[2:1]}),
784
                .restore(swap_odd_w & ~kill_restore_w),
785
                .restore_addr({1'b0,new_lo_cwp_w[2:1]}),
786
                .wr_data(wr_data),
787
                .rd_data(rd_data10)
788
);
789
 
790
bw_r_irf_register register11(
791
                .clk(clk),
792
                .wren(wren & (wr_addr == 5'b01011)),
793
                .save(swap_odd_m_vld),
794
                .save_addr({1'b0,old_lo_cwp_m[2:1]}),
795
                .restore(swap_odd_w & ~kill_restore_w),
796
                .restore_addr({1'b0,new_lo_cwp_w[2:1]}),
797
                .wr_data(wr_data),
798
                .rd_data(rd_data11)
799
);
800
 
801
bw_r_irf_register register12(
802
                .clk(clk),
803
                .wren(wren & (wr_addr == 5'b01100)),
804
                .save(swap_odd_m_vld),
805
                .save_addr({1'b0,old_lo_cwp_m[2:1]}),
806
                .restore(swap_odd_w & ~kill_restore_w),
807
                .restore_addr({1'b0,new_lo_cwp_w[2:1]}),
808
                .wr_data(wr_data),
809
                .rd_data(rd_data12)
810
);
811
 
812
bw_r_irf_register register13(
813
                .clk(clk),
814
                .wren(wren & (wr_addr == 5'b01101)),
815
                .save(swap_odd_m_vld),
816
                .save_addr({1'b0,old_lo_cwp_m[2:1]}),
817
                .restore(swap_odd_w & ~kill_restore_w),
818
                .restore_addr({1'b0,new_lo_cwp_w[2:1]}),
819
                .wr_data(wr_data),
820
                .rd_data(rd_data13)
821
);
822
 
823
bw_r_irf_register register14(
824
                .clk(clk),
825
                .wren(wren & (wr_addr == 5'b01110)),
826
                .save(swap_odd_m_vld),
827
                .save_addr({1'b0,old_lo_cwp_m[2:1]}),
828
                .restore(swap_odd_w & ~kill_restore_w),
829
                .restore_addr({1'b0,new_lo_cwp_w[2:1]}),
830
                .wr_data(wr_data),
831
                .rd_data(rd_data14)
832
);
833
 
834
bw_r_irf_register register15(
835
                .clk(clk),
836
                .wren(wren & (wr_addr == 5'b01111)),
837
                .save(swap_odd_m_vld),
838
                .save_addr({1'b0,old_lo_cwp_m[2:1]}),
839
                .restore(swap_odd_w & ~kill_restore_w),
840
                .restore_addr({1'b0,new_lo_cwp_w[2:1]}),
841
                .wr_data(wr_data),
842
                .rd_data(rd_data15)
843
);
844
 
845
//LOCALs
846
bw_r_irf_register register16(
847
                .clk(clk),
848
                .wren(wren & (wr_addr == 5'b10000)),
849
                .save(swap_local_m_vld),
850
                .save_addr({old_lo_cwp_m[2:0]}),
851
                .restore(swap_local_w & ~kill_restore_w),
852
                .restore_addr({new_lo_cwp_w[2:0]}),
853
                .wr_data(wr_data),
854
                .rd_data(rd_data16)
855
);
856
 
857
bw_r_irf_register register17(
858
                .clk(clk),
859
                .wren(wren & (wr_addr == 5'b10001)),
860
                .save(swap_local_m_vld),
861
                .save_addr({old_lo_cwp_m[2:0]}),
862
                .restore(swap_local_w & ~kill_restore_w),
863
                .restore_addr({new_lo_cwp_w[2:0]}),
864
                .wr_data(wr_data),
865
                .rd_data(rd_data17)
866
);
867
 
868
bw_r_irf_register register18(
869
                .clk(clk),
870
                .wren(wren & (wr_addr == 5'b10010)),
871
                .save(swap_local_m_vld),
872
                .save_addr({old_lo_cwp_m[2:0]}),
873
                .restore(swap_local_w & ~kill_restore_w),
874
                .restore_addr({new_lo_cwp_w[2:0]}),
875
                .wr_data(wr_data),
876
                .rd_data(rd_data18)
877
);
878
 
879
bw_r_irf_register register19(
880
                .clk(clk),
881
                .wren(wren & (wr_addr == 5'b10011)),
882
                .save(swap_local_m_vld),
883
                .save_addr({old_lo_cwp_m[2:0]}),
884
                .restore(swap_local_w & ~kill_restore_w),
885
                .restore_addr({new_lo_cwp_w[2:0]}),
886
                .wr_data(wr_data),
887
                .rd_data(rd_data19)
888
);
889
 
890
bw_r_irf_register register20(
891
                .clk(clk),
892
                .wren(wren & (wr_addr == 5'b10100)),
893
                .save(swap_local_m_vld),
894
                .save_addr({old_lo_cwp_m[2:0]}),
895
                .restore(swap_local_w & ~kill_restore_w),
896
                .restore_addr({new_lo_cwp_w[2:0]}),
897
                .wr_data(wr_data),
898
                .rd_data(rd_data20)
899
);
900
 
901
bw_r_irf_register register21(
902
                .clk(clk),
903
                .wren(wren & (wr_addr == 5'b10101)),
904
                .save(swap_local_m_vld),
905
                .save_addr({old_lo_cwp_m[2:0]}),
906
                .restore(swap_local_w & ~kill_restore_w),
907
                .restore_addr({new_lo_cwp_w[2:0]}),
908
                .wr_data(wr_data),
909
                .rd_data(rd_data21)
910
);
911
 
912
bw_r_irf_register register22(
913
                .clk(clk),
914
                .wren(wren & (wr_addr == 5'b10110)),
915
                .save(swap_local_m_vld),
916
                .save_addr({old_lo_cwp_m[2:0]}),
917
                .restore(swap_local_w & ~kill_restore_w),
918
                .restore_addr({new_lo_cwp_w[2:0]}),
919
                .wr_data(wr_data),
920
                .rd_data(rd_data22)
921
);
922
 
923
bw_r_irf_register register23(
924
                .clk(clk),
925
                .wren(wren & (wr_addr == 5'b10111)),
926
                .save(swap_local_m_vld),
927
                .save_addr({old_lo_cwp_m[2:0]}),
928
                .restore(swap_local_w & ~kill_restore_w),
929
                .restore_addr({new_lo_cwp_w[2:0]}),
930
                .wr_data(wr_data),
931
                .rd_data(rd_data23)
932
);
933
 
934
//EVENs
935
bw_r_irf_register register24(
936
                .clk(clk),
937
                .wren(wren & (wr_addr == 5'b11000)),
938
                .save(swap_even_m_vld),
939
                .save_addr({1'b0,old_e_cwp_m[1:0]}),
940
                .restore(swap_even_w & ~kill_restore_w),
941
                .restore_addr({1'b0,new_e_cwp_w[1:0]}),
942
                .wr_data(wr_data),
943
                .rd_data(rd_data24)
944
);
945
 
946
bw_r_irf_register register25(
947
                .clk(clk),
948
                .wren(wren & (wr_addr == 5'b11001)),
949
                .save(swap_even_m_vld),
950
                .save_addr({1'b0,old_e_cwp_m[1:0]}),
951
                .restore(swap_even_w & ~kill_restore_w),
952
                .restore_addr({1'b0,new_e_cwp_w[1:0]}),
953
                .wr_data(wr_data),
954
                .rd_data(rd_data25)
955
);
956
 
957
bw_r_irf_register register26(
958
                .clk(clk),
959
                .wren(wren & (wr_addr == 5'b11010)),
960
                .save(swap_even_m_vld),
961
                .save_addr({1'b0,old_e_cwp_m[1:0]}),
962
                .restore(swap_even_w & ~kill_restore_w),
963
                .restore_addr({1'b0,new_e_cwp_w[1:0]}),
964
                .wr_data(wr_data),
965
                .rd_data(rd_data26)
966
);
967
 
968
bw_r_irf_register register27(
969
                .clk(clk),
970
                .wren(wren & (wr_addr == 5'b11011)),
971
                .save(swap_even_m_vld),
972
                .save_addr({1'b0,old_e_cwp_m[1:0]}),
973
                .restore(swap_even_w & ~kill_restore_w),
974
                .restore_addr({1'b0,new_e_cwp_w[1:0]}),
975
                .wr_data(wr_data),
976
                .rd_data(rd_data27)
977
);
978
 
979
bw_r_irf_register register28(
980
                .clk(clk),
981
                .wren(wren & (wr_addr == 5'b11100)),
982
                .save(swap_even_m_vld),
983
                .save_addr({1'b0,old_e_cwp_m[1:0]}),
984
                .restore(swap_even_w & ~kill_restore_w),
985
                .restore_addr({1'b0,new_e_cwp_w[1:0]}),
986
                .wr_data(wr_data),
987
                .rd_data(rd_data28)
988
);
989
 
990
bw_r_irf_register register29(
991
                .clk(clk),
992
                .wren(wren & (wr_addr == 5'b11101)),
993
                .save(swap_even_m_vld),
994
                .save_addr({1'b0,old_e_cwp_m[1:0]}),
995
                .restore(swap_even_w & ~kill_restore_w),
996
                .restore_addr({1'b0,new_e_cwp_w[1:0]}),
997
                .wr_data(wr_data),
998
                .rd_data(rd_data29)
999
);
1000
 
1001
bw_r_irf_register register30(
1002
                .clk(clk),
1003
                .wren(wren & (wr_addr == 5'b11110)),
1004
                .save(swap_even_m_vld),
1005
                .save_addr({1'b0,old_e_cwp_m[1:0]}),
1006
                .restore(swap_even_w & ~kill_restore_w),
1007
                .restore_addr({1'b0,new_e_cwp_w[1:0]}),
1008
                .wr_data(wr_data),
1009
                .rd_data(rd_data30)
1010
);
1011
 
1012
bw_r_irf_register register31(
1013
                .clk(clk),
1014
                .wren(wren & (wr_addr == 5'b11111)),
1015
                .save(swap_even_m_vld),
1016
                .save_addr({1'b0,old_e_cwp_m[1:0]}),
1017
                .restore(swap_even_w & ~kill_restore_w),
1018
                .restore_addr({1'b0,new_e_cwp_w[1:0]}),
1019
                .wr_data(wr_data),
1020
                .rd_data(rd_data31)
1021
);
1022
 
1023
endmodule
1024
 
1025
 
1026
`else
1027
 
1028
 
1029
module bw_r_irf(so, irf_byp_rs1_data_d_l, irf_byp_rs2_data_d_l,
1030
        irf_byp_rs3_data_d_l, irf_byp_rs3h_data_d_l, rclk, reset_l, si, se,
1031
        sehold, rst_tri_en, ifu_exu_tid_s2, ifu_exu_rs1_s, ifu_exu_rs2_s,
1032
        ifu_exu_rs3_s, ifu_exu_ren1_s, ifu_exu_ren2_s, ifu_exu_ren3_s,
1033
        ecl_irf_wen_w, ecl_irf_wen_w2, ecl_irf_rd_m, ecl_irf_rd_g,
1034
        byp_irf_rd_data_w, byp_irf_rd_data_w2, ecl_irf_tid_m, ecl_irf_tid_g,
1035
        rml_irf_old_lo_cwp_e, rml_irf_new_lo_cwp_e, rml_irf_old_e_cwp_e,
1036
        rml_irf_new_e_cwp_e, rml_irf_swap_even_e, rml_irf_swap_odd_e,
1037
        rml_irf_swap_local_e, rml_irf_kill_restore_w, rml_irf_cwpswap_tid_e,
1038
        rml_irf_old_agp, rml_irf_new_agp, rml_irf_swap_global,
1039
        rml_irf_global_tid);
1040
 
1041
        input                   rclk;
1042
        input                   reset_l;
1043
        input                   si;
1044
        input                   se;
1045
        input                   sehold;
1046
        input                   rst_tri_en;
1047
        input   [1:0]            ifu_exu_tid_s2;
1048
        input   [4:0]            ifu_exu_rs1_s;
1049
        input   [4:0]            ifu_exu_rs2_s;
1050
        input   [4:0]            ifu_exu_rs3_s;
1051
        input                   ifu_exu_ren1_s;
1052
        input                   ifu_exu_ren2_s;
1053
        input                   ifu_exu_ren3_s;
1054
        input                   ecl_irf_wen_w;
1055
        input                   ecl_irf_wen_w2;
1056
        input   [4:0]            ecl_irf_rd_m;
1057
        input   [4:0]            ecl_irf_rd_g;
1058
        input   [71:0]           byp_irf_rd_data_w;
1059
        input   [71:0]           byp_irf_rd_data_w2;
1060
        input   [1:0]            ecl_irf_tid_m;
1061
        input   [1:0]            ecl_irf_tid_g;
1062
        input   [2:0]            rml_irf_old_lo_cwp_e;
1063
        input   [2:0]            rml_irf_new_lo_cwp_e;
1064
        input   [2:1]           rml_irf_old_e_cwp_e;
1065
        input   [2:1]           rml_irf_new_e_cwp_e;
1066
        input                   rml_irf_swap_even_e;
1067
        input                   rml_irf_swap_odd_e;
1068
        input                   rml_irf_swap_local_e;
1069
        input                   rml_irf_kill_restore_w;
1070
        input   [1:0]            rml_irf_cwpswap_tid_e;
1071
        input   [1:0]            rml_irf_old_agp;
1072
        input   [1:0]            rml_irf_new_agp;
1073
        input                   rml_irf_swap_global;
1074
        input   [1:0]            rml_irf_global_tid;
1075
        output                  so;
1076
        output  [71:0]           irf_byp_rs1_data_d_l;
1077
        output  [71:0]           irf_byp_rs2_data_d_l;
1078
        output  [71:0]           irf_byp_rs3_data_d_l;
1079
        output  [31:0]           irf_byp_rs3h_data_d_l;
1080
 
1081
        wire    [71:0]           irf_byp_rs1_data_d;
1082
        wire    [71:0]           irf_byp_rs2_data_d;
1083
        wire    [71:0]           irf_byp_rs3_data_d;
1084
        wire    [71:0]           irf_byp_rs3h_data_d;
1085
        wire    [1:0]            ecl_irf_tid_w;
1086
        wire    [1:0]            ecl_irf_tid_w2;
1087
        wire    [4:0]            ecl_irf_rd_w;
1088
        wire    [4:0]            ecl_irf_rd_w2;
1089
        wire    [1:0]            ifu_exu_thr_d;
1090
        wire                    ifu_exu_ren1_d;
1091
        wire                    ifu_exu_ren2_d;
1092
        wire                    ifu_exu_ren3_d;
1093
        wire    [4:0]            ifu_exu_rs1_d;
1094
        wire    [4:0]            ifu_exu_rs2_d;
1095
        wire    [4:0]            ifu_exu_rs3_d;
1096
        wire    [6:0]            thr_rs1;
1097
        wire    [6:0]            thr_rs2;
1098
        wire    [6:0]            thr_rs3;
1099
        wire    [6:0]            thr_rs3h;
1100
        wire    [6:0]            thr_rd_w;
1101
        wire    [6:0]            thr_rd_w2;
1102
        reg     [1:0]            cwpswap_tid_m;
1103
        reg     [1:0]            cwpswap_tid_w;
1104
        reg     [2:0]            old_lo_cwp_m;
1105
        reg     [2:0]            new_lo_cwp_m;
1106
        reg     [2:0]            new_lo_cwp_w;
1107
        reg     [1:0]            old_e_cwp_m;
1108
        reg     [1:0]            new_e_cwp_m;
1109
        reg     [1:0]            new_e_cwp_w;
1110
        reg                     swap_local_m;
1111
        reg                     swap_local_w;
1112
        reg                     swap_even_m;
1113
        reg                     swap_even_w;
1114
        reg                     swap_odd_m;
1115
        reg                     swap_odd_w;
1116
        reg                     kill_restore_d1;
1117
        reg                     swap_global_d1;
1118
        reg                     swap_global_d2;
1119
        reg     [1:0]            global_tid_d1;
1120
        reg     [1:0]            global_tid_d2;
1121
        reg     [1:0]            old_agp_d1;
1122
        reg     [1:0]            new_agp_d1;
1123
        reg     [1:0]            new_agp_d2;
1124
        reg     [71:0]           active_win_thr_rd_w_neg;
1125
        reg     [71:0]           active_win_thr_rd_w2_neg;
1126
        reg     [6:0]            thr_rd_w_neg;
1127
        reg     [6:0]            thr_rd_w2_neg;
1128
        reg                     active_win_thr_rd_w_neg_wr_en;
1129
        reg                     active_win_thr_rd_w2_neg_wr_en;
1130
        reg                     rst_tri_en_neg;
1131
        wire                    clk;
1132
        wire                    ren1_s;
1133
        wire                    ren2_s;
1134
        wire                    ren3_s;
1135
        wire    [4:0]            rs1_s;
1136
        wire    [4:0]            rs2_s;
1137
        wire    [4:0]            rs3_s;
1138
        wire    [1:0]            tid_s;
1139
        wire    [1:0]            tid_g;
1140
        wire    [1:0]            tid_m;
1141
        wire    [4:0]            rd_m;
1142
        wire    [4:0]            rd_g;
1143
        wire                    kill_restore_w;
1144
        wire                    swap_global_d1_vld;
1145
        wire                    swap_local_m_vld;
1146
        wire                    swap_even_m_vld;
1147
        wire                    swap_odd_m_vld;
1148
        wire                    wr_en;
1149
        wire                    wr_en2;
1150
 
1151
        assign clk = rclk;
1152
        assign {ren1_s, ren2_s, ren3_s, rs1_s[4:0], rs2_s[4:0], rs3_s[4:0],
1153
                tid_s[1:0], tid_g[1:0], tid_m[1:0], rd_m[4:0], rd_g[4:0]} = (
1154
                sehold ? {ifu_exu_ren1_d, ifu_exu_ren2_d, ifu_exu_ren3_d,
1155
                ifu_exu_rs1_d[4:0], ifu_exu_rs2_d[4:0], ifu_exu_rs3_d[4:0],
1156
                ifu_exu_thr_d[1:0], ecl_irf_tid_w2[1:0], ecl_irf_tid_w[1:0],
1157
                ecl_irf_rd_w[4:0], ecl_irf_rd_w2[4:0]} : {ifu_exu_ren1_s,
1158
                ifu_exu_ren2_s, ifu_exu_ren3_s, ifu_exu_rs1_s[4:0],
1159
                ifu_exu_rs2_s[4:0], ifu_exu_rs3_s[4:0], ifu_exu_tid_s2[1:0],
1160
                ecl_irf_tid_g[1:0], ecl_irf_tid_m[1:0], ecl_irf_rd_m[4:0],
1161
                ecl_irf_rd_g[4:0]});
1162
        assign thr_rs1[6:0] = {ifu_exu_thr_d, ifu_exu_rs1_d};
1163
        assign thr_rs2[6:0] = {ifu_exu_thr_d, ifu_exu_rs2_d};
1164
        assign thr_rs3[6:0] = {ifu_exu_thr_d, ifu_exu_rs3_d[4:0]};
1165
        assign thr_rs3h[6:0] = {ifu_exu_thr_d[1:0], ifu_exu_rs3_d[4:1], 1'b1};
1166
        assign thr_rd_w[6:0] = {ecl_irf_tid_w, ecl_irf_rd_w};
1167
        assign thr_rd_w2[6:0] = {ecl_irf_tid_w2, ecl_irf_rd_w2};
1168
        assign irf_byp_rs1_data_d_l[71:0] = (~irf_byp_rs1_data_d[71:0]);
1169
        assign irf_byp_rs2_data_d_l[71:0] = (~irf_byp_rs2_data_d[71:0]);
1170
        assign irf_byp_rs3_data_d_l[71:0] = (~irf_byp_rs3_data_d[71:0]);
1171
        assign irf_byp_rs3h_data_d_l[31:0] = (~irf_byp_rs3h_data_d[31:0]);
1172
        assign kill_restore_w = (sehold ? kill_restore_d1 :
1173
                rml_irf_kill_restore_w);
1174
        assign swap_local_m_vld = (swap_local_m & (~rst_tri_en));
1175
        assign swap_odd_m_vld = (swap_odd_m & (~rst_tri_en));
1176
        assign swap_even_m_vld = (swap_even_m & (~rst_tri_en));
1177
        assign swap_global_d1_vld = (swap_global_d1 & (~rst_tri_en));
1178
        assign wr_en = (active_win_thr_rd_w_neg_wr_en & ((~rst_tri_en) | (~
1179
                rst_tri_en_neg)));
1180
        assign wr_en2 = (active_win_thr_rd_w2_neg_wr_en & ((~rst_tri_en) | (~
1181
                rst_tri_en_neg)));
1182
 
1183
        dff_s dff_ren1_s2d(
1184
                .din                            (ren1_s),
1185
                .clk                            (clk),
1186
                .q                              (ifu_exu_ren1_d),
1187
                .se                             (se));
1188
        dff_s dff_ren2_s2d(
1189
                .din                            (ren2_s),
1190
                .clk                            (clk),
1191
                .q                              (ifu_exu_ren2_d),
1192
                .se                             (se));
1193
        dff_s dff_ren3_s2d(
1194
                .din                            (ren3_s),
1195
                .clk                            (clk),
1196
                .q                              (ifu_exu_ren3_d),
1197
                .se                             (se));
1198
        dff_s #(5) dff_rs1_s2d(
1199
                .din                            (rs1_s[4:0]),
1200
                .clk                            (clk),
1201
                .q                              (ifu_exu_rs1_d[4:0]),
1202
                .se                             (se));
1203
        dff_s #(5) dff_rs2_s2d(
1204
                .din                            (rs2_s[4:0]),
1205
                .clk                            (clk),
1206
                .q                              (ifu_exu_rs2_d[4:0]),
1207
                .se                             (se));
1208
        dff_s #(5) dff_rs3_s2d(
1209
                .din                            (rs3_s[4:0]),
1210
                .clk                            (clk),
1211
                .q                              (ifu_exu_rs3_d[4:0]),
1212
                .se                             (se));
1213
        dff_s #(2) dff_thr_s2d(
1214
                .din                            (tid_s[1:0]),
1215
                .clk                            (clk),
1216
                .q                              (ifu_exu_thr_d[1:0]),
1217
                .se                             (se));
1218
        dff_s #(2) dff_thr_g2w2(
1219
                .din                            (tid_g[1:0]),
1220
                .clk                            (clk),
1221
                .q                              (ecl_irf_tid_w2[1:0]),
1222
                .se                             (se));
1223
        dff_s #(2) dff_thr_m2w(
1224
                .din                            (tid_m[1:0]),
1225
                .clk                            (clk),
1226
                .q                              (ecl_irf_tid_w[1:0]),
1227
                .se                             (se));
1228
        dff_s #(5) dff_rd_m2w(
1229
                .din                            (rd_m[4:0]),
1230
                .clk                            (clk),
1231
                .q                              (ecl_irf_rd_w[4:0]),
1232
                .se                             (se));
1233
        dff_s #(5) dff_rd_g2w2(
1234
                .din                            (rd_g[4:0]),
1235
                .clk                            (clk),
1236
                .q                              (ecl_irf_rd_w2[4:0]),
1237
                .se                             (se));
1238
        bw_r_irf_core bw_r_irf_core(
1239
                .clk                            (clk),
1240
                .ifu_exu_ren1_d                 (ifu_exu_ren1_d),
1241
                .ifu_exu_ren2_d                 (ifu_exu_ren2_d),
1242
                .ifu_exu_ren3_d                 (ifu_exu_ren3_d),
1243
                .thr_rs1                        (thr_rs1),
1244
                .thr_rs2                        (thr_rs2),
1245
                .thr_rs3                        (thr_rs3),
1246
                .thr_rs3h                       (thr_rs3h),
1247
                .irf_byp_rs1_data_d             (irf_byp_rs1_data_d),
1248
                .irf_byp_rs2_data_d             (irf_byp_rs2_data_d),
1249
                .irf_byp_rs3_data_d             (irf_byp_rs3_data_d),
1250
                .irf_byp_rs3h_data_d            (irf_byp_rs3h_data_d),
1251
                .wr_en                          (wr_en),
1252
                .wr_en2                         (wr_en2),
1253
                .active_win_thr_rd_w_neg        (active_win_thr_rd_w_neg),
1254
                .active_win_thr_rd_w2_neg       (active_win_thr_rd_w2_neg),
1255
                .thr_rd_w_neg                   (thr_rd_w_neg),
1256
                .thr_rd_w2_neg                  (thr_rd_w2_neg),
1257
                .swap_global_d1_vld             (swap_global_d1_vld),
1258
                .swap_global_d2                 (swap_global_d2),
1259
                .global_tid_d1                  (global_tid_d1),
1260
                .global_tid_d2                  (global_tid_d2),
1261
                .old_agp_d1                     (old_agp_d1),
1262
                .new_agp_d2                     (new_agp_d2),
1263
                .swap_local_m_vld               (swap_local_m_vld),
1264
                .swap_local_w                   (swap_local_w),
1265
                .old_lo_cwp_m                   (old_lo_cwp_m),
1266
                .new_lo_cwp_w                   (new_lo_cwp_w),
1267
                .swap_even_m_vld                (swap_even_m_vld),
1268
                .swap_even_w                    (swap_even_w),
1269
                .old_e_cwp_m                    (old_e_cwp_m),
1270
                .new_e_cwp_w                    (new_e_cwp_w),
1271
                .swap_odd_m_vld                 (swap_odd_m_vld),
1272
                .swap_odd_w                     (swap_odd_w),
1273
                .cwpswap_tid_m                  (cwpswap_tid_m),
1274
                .cwpswap_tid_w                  (cwpswap_tid_w),
1275
                .kill_restore_w                 (kill_restore_w));
1276
 
1277
        always @(negedge clk) begin
1278
          rst_tri_en_neg <= rst_tri_en;
1279
          if ((ecl_irf_wen_w & ecl_irf_wen_w2) & (thr_rd_w[6:0] ==
1280
                  thr_rd_w2[6:0])) begin
1281
            active_win_thr_rd_w_neg <= {72 {1'bx}};
1282
            thr_rd_w_neg <= thr_rd_w;
1283
            active_win_thr_rd_w_neg_wr_en <= 1'b1;
1284
            active_win_thr_rd_w2_neg_wr_en <= 1'b0;
1285
          end
1286
          else
1287
            begin
1288
              if (ecl_irf_wen_w & (thr_rd_w[4:0] != 5'b0)) begin
1289
                active_win_thr_rd_w_neg <= byp_irf_rd_data_w;
1290
                thr_rd_w_neg <= thr_rd_w;
1291
                active_win_thr_rd_w_neg_wr_en <= 1'b1;
1292
              end
1293
              else begin
1294
                active_win_thr_rd_w_neg_wr_en <= 1'b0;
1295
              end
1296
              if (ecl_irf_wen_w2 & (thr_rd_w2[4:0] != 5'b0)) begin
1297
                active_win_thr_rd_w2_neg <= byp_irf_rd_data_w2;
1298
                thr_rd_w2_neg <= thr_rd_w2;
1299
                active_win_thr_rd_w2_neg_wr_en <= 1'b1;
1300
              end
1301
              else begin
1302
                active_win_thr_rd_w2_neg_wr_en <= 1'b0;
1303
              end
1304
            end
1305
        end
1306
        always @(posedge clk) begin
1307
          cwpswap_tid_m[1:0] <= (sehold ? cwpswap_tid_m[1:0] :
1308
                  rml_irf_cwpswap_tid_e[1:0]);
1309
          cwpswap_tid_w[1:0] <= cwpswap_tid_m[1:0];
1310
          old_lo_cwp_m[2:0] <= (sehold ? old_lo_cwp_m[2:0] :
1311
                  rml_irf_old_lo_cwp_e[2:0]);
1312
          new_lo_cwp_m[2:0] <= (sehold ? new_lo_cwp_m[2:0] :
1313
                  rml_irf_new_lo_cwp_e[2:0]);
1314
          new_lo_cwp_w[2:0] <= new_lo_cwp_m[2:0];
1315
          old_e_cwp_m[1:0] <= (sehold ? old_e_cwp_m[1:0] :
1316
                  rml_irf_old_e_cwp_e[2:1]);
1317
          new_e_cwp_m[1:0] <= (sehold ? new_e_cwp_m[1:0] :
1318
                  rml_irf_new_e_cwp_e[2:1]);
1319
          new_e_cwp_w[1:0] <= new_e_cwp_m[1:0];
1320
          swap_local_m <= (sehold ? (swap_local_m & rst_tri_en) :
1321
                  rml_irf_swap_local_e);
1322
          swap_local_w <= swap_local_m_vld;
1323
          swap_odd_m <= (sehold ? (swap_odd_m & rst_tri_en) : rml_irf_swap_odd_e
1324
                  );
1325
          swap_odd_w <= swap_odd_m_vld;
1326
          swap_even_m <= (sehold ? (swap_even_m & rst_tri_en) :
1327
                  rml_irf_swap_even_e);
1328
          swap_even_w <= swap_even_m_vld;
1329
          kill_restore_d1 <= kill_restore_w;
1330
        end
1331
        always @(posedge clk) begin
1332
          swap_global_d1 <= (sehold ? (swap_global_d1 & rst_tri_en) :
1333
                  rml_irf_swap_global);
1334
          swap_global_d2 <= swap_global_d1_vld;
1335
          global_tid_d1[1:0] <= (sehold ? global_tid_d1[1:0] :
1336
                  rml_irf_global_tid[1:0]);
1337
          global_tid_d2[1:0] <= global_tid_d1[1:0];
1338
          old_agp_d1[1:0] <= (sehold ? old_agp_d1[1:0] : rml_irf_old_agp[1:0]);
1339
          new_agp_d1[1:0] <= (sehold ? new_agp_d1[1:0] : rml_irf_new_agp[1:0]);
1340
          new_agp_d2[1:0] <= new_agp_d1[1:0];
1341
        end
1342
/*
1343
        always @(posedge clk) begin
1344
          if (wr_en) begin
1345
            $display("Write Port 1: %h %h", active_win_thr_rd_w_neg,
1346
                    thr_rd_w_neg);
1347
          end
1348
          if (wr_en2) begin
1349
            $display("Write Port 2: %h %h", active_win_thr_rd_w2_neg,
1350
                    thr_rd_w2_neg);
1351
          end
1352
          if (ifu_exu_ren1_d) begin
1353
            @(posedge clk) ;
1354
            $display("Read Port 1: %h %h", irf_byp_rs1_data_d, thr_rs1);
1355
          end
1356
          if (ifu_exu_ren2_d) begin
1357
            @(posedge clk) ;
1358
            $display("Read Port 2: %h %h", irf_byp_rs2_data_d, thr_rs2);
1359
          end
1360
          if (ifu_exu_ren3_d) begin
1361
            @(posedge clk) ;
1362
            $display("Read Port 3: %h %h", irf_byp_rs3_data_d, thr_rs3);
1363
          end
1364
        end
1365
*/
1366
endmodule
1367
 
1368
module bw_r_irf_core(clk, ifu_exu_ren1_d, ifu_exu_ren2_d, ifu_exu_ren3_d,
1369
        thr_rs1, thr_rs2, thr_rs3, thr_rs3h, irf_byp_rs1_data_d,
1370
        irf_byp_rs2_data_d, irf_byp_rs3_data_d, irf_byp_rs3h_data_d, wr_en,
1371
        wr_en2, active_win_thr_rd_w_neg, active_win_thr_rd_w2_neg, thr_rd_w_neg,
1372
        thr_rd_w2_neg, swap_global_d1_vld, swap_global_d2, global_tid_d1,
1373
        global_tid_d2, old_agp_d1, new_agp_d2, swap_local_m_vld, swap_local_w,
1374
        old_lo_cwp_m, new_lo_cwp_w, swap_even_m_vld, swap_even_w, old_e_cwp_m,
1375
        new_e_cwp_w, swap_odd_m_vld, swap_odd_w, cwpswap_tid_m, cwpswap_tid_w,
1376
        kill_restore_w);
1377
 
1378
        input                   clk;
1379
        input                   ifu_exu_ren1_d;
1380
        input                   ifu_exu_ren2_d;
1381
        input                   ifu_exu_ren3_d;
1382
        input   [6:0]            thr_rs1;
1383
        input   [6:0]            thr_rs2;
1384
        input   [6:0]            thr_rs3;
1385
        input   [6:0]            thr_rs3h;
1386
        output  [71:0]           irf_byp_rs1_data_d;
1387
        output  [71:0]           irf_byp_rs2_data_d;
1388
        output  [71:0]           irf_byp_rs3_data_d;
1389
        output  [71:0]           irf_byp_rs3h_data_d;
1390
        input                   wr_en;
1391
        input                   wr_en2;
1392
        input   [71:0]           active_win_thr_rd_w_neg;
1393
        input   [71:0]           active_win_thr_rd_w2_neg;
1394
        input   [6:0]            thr_rd_w_neg;
1395
        input   [6:0]            thr_rd_w2_neg;
1396
        input                   swap_global_d1_vld;
1397
        input                   swap_global_d2;
1398
        input   [1:0]            global_tid_d1;
1399
        input   [1:0]            global_tid_d2;
1400
        input   [1:0]            old_agp_d1;
1401
        input   [1:0]            new_agp_d2;
1402
        input                   swap_local_m_vld;
1403
        input                   swap_local_w;
1404
        input   [2:0]            old_lo_cwp_m;
1405
        input   [2:0]            new_lo_cwp_w;
1406
        input                   swap_even_m_vld;
1407
        input                   swap_even_w;
1408
        input   [1:0]            old_e_cwp_m;
1409
        input   [1:0]            new_e_cwp_w;
1410
        input                   swap_odd_m_vld;
1411
        input                   swap_odd_w;
1412
        input   [1:0]            cwpswap_tid_m;
1413
        input   [1:0]            cwpswap_tid_w;
1414
        input                   kill_restore_w;
1415
 
1416
        reg     [71:0]           irf_byp_rs1_data_d;
1417
        reg     [71:0]           irf_byp_rs2_data_d;
1418
        reg     [71:0]           irf_byp_rs3_data_d;
1419
        reg     [71:0]           irf_byp_rs3h_data_d;
1420
        wire    [71:0]           rd_data00;
1421
        wire    [71:0]           rd_data01;
1422
        wire    [71:0]           rd_data02;
1423
        wire    [71:0]           rd_data03;
1424
        wire    [71:0]           rd_data04;
1425
        wire    [71:0]           rd_data05;
1426
        wire    [71:0]           rd_data06;
1427
        wire    [71:0]           rd_data07;
1428
        wire    [71:0]           rd_data08;
1429
        wire    [71:0]           rd_data09;
1430
        wire    [71:0]           rd_data10;
1431
        wire    [71:0]           rd_data11;
1432
        wire    [71:0]           rd_data12;
1433
        wire    [71:0]           rd_data13;
1434
        wire    [71:0]           rd_data14;
1435
        wire    [71:0]           rd_data15;
1436
        wire    [71:0]           rd_data16;
1437
        wire    [71:0]           rd_data17;
1438
        wire    [71:0]           rd_data18;
1439
        wire    [71:0]           rd_data19;
1440
        wire    [71:0]           rd_data20;
1441
        wire    [71:0]           rd_data21;
1442
        wire    [71:0]           rd_data22;
1443
        wire    [71:0]           rd_data23;
1444
        wire    [71:0]           rd_data24;
1445
        wire    [71:0]           rd_data25;
1446
        wire    [71:0]           rd_data26;
1447
        wire    [71:0]           rd_data27;
1448
        wire    [71:0]           rd_data28;
1449
        wire    [71:0]           rd_data29;
1450
        wire    [71:0]           rd_data30;
1451
        wire    [71:0]           rd_data31;
1452
        wire                    wren;
1453
        wire    [4:0]            wr_addr;
1454
        wire    [71:0]           wr_data;
1455
 
1456
 
1457
        wire    [127:0]  wr_en1s = (wr_en << {thr_rd_w_neg[4:0],thr_rd_w_neg[6:5]});
1458
        wire    [127:0] wr_en2s = (wr_en2 << {thr_rd_w2_neg[4:0],thr_rd_w2_neg[6:5]});
1459
        wire    [127:0]  wrens = wr_en1s | wr_en2s;
1460
 
1461
        wire    [3:0]    wr_th1 = wr_en << thr_rd_w_neg[6:5];
1462
 
1463
        wire    [71:0]   wr_data0 = wr_th1[0] ? active_win_thr_rd_w_neg : active_win_thr_rd_w2_neg;
1464
        wire    [71:0]   wr_data1 = wr_th1[1] ? active_win_thr_rd_w_neg : active_win_thr_rd_w2_neg;
1465
        wire    [71:0]   wr_data2 = wr_th1[2] ? active_win_thr_rd_w_neg : active_win_thr_rd_w2_neg;
1466
        wire    [71:0]   wr_data3 = wr_th1[3] ? active_win_thr_rd_w_neg : active_win_thr_rd_w2_neg;
1467
 
1468
 
1469
        bw_r_irf_register register00(
1470
                .clk                            (clk),
1471
                .wrens                          (wrens[3:0]),
1472
                .save                           (swap_global_d1_vld),
1473
                .save_addr                      ({global_tid_d1, 1'b0, old_agp_d1[1:0]}),
1474
                .restore                        (swap_global_d2),
1475
                .restore_addr                   ({global_tid_d2, 1'b0, new_agp_d2[1:0]}),
1476
                .wr_data0                       (72'b0),
1477
                .wr_data1                       (72'b0),
1478
                .wr_data2                       (72'b0),
1479
                .wr_data3                       (72'b0),
1480
                .rd_thread                      (thr_rs1[6:5]),
1481
                .rd_data                        (rd_data00));
1482
        bw_r_irf_register register01(
1483
                .clk                            (clk),
1484
                .wrens                          (wrens[7:4]),
1485
                .save                           (swap_global_d1_vld),
1486
                .save_addr                      ({global_tid_d1, 1'b0, old_agp_d1[1:0]}),
1487
                .restore                        (swap_global_d2),
1488
                .restore_addr                   ({global_tid_d2, 1'b0, new_agp_d2[1:0]}),
1489
                .wr_data0                       (wr_data0),
1490
                .wr_data1                       (wr_data1),
1491
                .wr_data2                       (wr_data2),
1492
                .wr_data3                       (wr_data3),
1493
                .rd_thread                      (thr_rs1[6:5]),
1494
                .rd_data                        (rd_data01));
1495
        bw_r_irf_register register02(
1496
                .clk                            (clk),
1497
                .wrens                          (wrens[11:8]),
1498
                .save                           (swap_global_d1_vld),
1499
                .save_addr                      ({global_tid_d1, 1'b0, old_agp_d1[1:0]}),
1500
                .restore                        (swap_global_d2),
1501
                .restore_addr                   ({global_tid_d2, 1'b0, new_agp_d2[1:0]}),
1502
                .wr_data0                       (wr_data0),
1503
                .wr_data1                       (wr_data1),
1504
                .wr_data2                       (wr_data2),
1505
                .wr_data3                       (wr_data3),
1506
                .rd_thread                      (thr_rs1[6:5]),
1507
                .rd_data                        (rd_data02));
1508
        bw_r_irf_register register03(
1509
                .clk                            (clk),
1510
                .wrens                          (wrens[15:12]),
1511
                .save                           (swap_global_d1_vld),
1512
                .save_addr                      ({global_tid_d1, 1'b0, old_agp_d1[1:0]}),
1513
                .restore                        (swap_global_d2),
1514
                .restore_addr                   ({global_tid_d2, 1'b0, new_agp_d2[1:0]}),
1515
                .wr_data0                       (wr_data0),
1516
                .wr_data1                       (wr_data1),
1517
                .wr_data2                       (wr_data2),
1518
                .wr_data3                       (wr_data3),
1519
                .rd_thread                      (thr_rs1[6:5]),
1520
                .rd_data                        (rd_data03));
1521
        bw_r_irf_register register04(
1522
                .clk                            (clk),
1523
                .wrens                          (wrens[19:16]),
1524
                .save                           (swap_global_d1_vld),
1525
                .save_addr                      ({global_tid_d1, 1'b0, old_agp_d1[1:0]}),
1526
                .restore                        (swap_global_d2),
1527
                .restore_addr                   ({global_tid_d2, 1'b0, new_agp_d2[1:0]}),
1528
                .wr_data0                       (wr_data0),
1529
                .wr_data1                       (wr_data1),
1530
                .wr_data2                       (wr_data2),
1531
                .wr_data3                       (wr_data3),
1532
                .rd_thread                      (thr_rs1[6:5]),
1533
                .rd_data                        (rd_data04));
1534
        bw_r_irf_register register05(
1535
                .clk                            (clk),
1536
                .wrens                          (wrens[23:20]),
1537
                .save                           (swap_global_d1_vld),
1538
                .save_addr                      ({global_tid_d1, 1'b0, old_agp_d1[1:0]}),
1539
                .restore                        (swap_global_d2),
1540
                .restore_addr                   ({global_tid_d2, 1'b0, new_agp_d2[1:0]}),
1541
                .wr_data0                       (wr_data0),
1542
                .wr_data1                       (wr_data1),
1543
                .wr_data2                       (wr_data2),
1544
                .wr_data3                       (wr_data3),
1545
                .rd_thread                      (thr_rs1[6:5]),
1546
                .rd_data                        (rd_data05));
1547
        bw_r_irf_register register06(
1548
                .clk                            (clk),
1549
                .wrens                          (wrens[27:24]),
1550
                .save                           (swap_global_d1_vld),
1551
                .save_addr                      ({global_tid_d1, 1'b0, old_agp_d1[1:0]}),
1552
                .restore                        (swap_global_d2),
1553
                .restore_addr                   ({global_tid_d2, 1'b0, new_agp_d2[1:0]}),
1554
                .wr_data0                       (wr_data0),
1555
                .wr_data1                       (wr_data1),
1556
                .wr_data2                       (wr_data2),
1557
                .wr_data3                       (wr_data3),
1558
                .rd_thread                      (thr_rs1[6:5]),
1559
                .rd_data                        (rd_data06));
1560
        bw_r_irf_register register07(
1561
                .clk                            (clk),
1562
                .wrens                          (wrens[31:28]),
1563
                .save                           (swap_global_d1_vld),
1564
                .save_addr                      ({global_tid_d1, 1'b0, old_agp_d1[1:0]}),
1565
                .restore                        (swap_global_d2),
1566
                .restore_addr                   ({global_tid_d2, 1'b0, new_agp_d2[1:0]}),
1567
                .wr_data0                       (wr_data0),
1568
                .wr_data1                       (wr_data1),
1569
                .wr_data2                       (wr_data2),
1570
                .wr_data3                       (wr_data3),
1571
                .rd_thread                      (thr_rs1[6:5]),
1572
                .rd_data                        (rd_data07));
1573
 
1574
        bw_r_irf_register register08(
1575
                .clk                            (clk),
1576
                .wrens                          (wrens[35:32]),
1577
                .save                           (swap_odd_m_vld),
1578
                .save_addr                      ({cwpswap_tid_m, 1'b0, old_lo_cwp_m[2:1]}),
1579
                .restore                        ((swap_odd_w & (~kill_restore_w))),
1580
                .restore_addr                   ({cwpswap_tid_w,1'b0, new_lo_cwp_w[2:1]}),
1581
                .wr_data0                       (wr_data0),
1582
                .wr_data1                       (wr_data1),
1583
                .wr_data2                       (wr_data2),
1584
                .wr_data3                       (wr_data3),
1585
                .rd_thread                      (thr_rs1[6:5]),
1586
                .rd_data                        (rd_data08));
1587
        bw_r_irf_register register09(
1588
                .clk                            (clk),
1589
                .wrens                          (wrens[39:36]),
1590
                .save                           (swap_odd_m_vld),
1591
                .save_addr                      ({cwpswap_tid_m, 1'b0, old_lo_cwp_m[2:1]}),
1592
                .restore                        ((swap_odd_w & (~kill_restore_w))),
1593
                .restore_addr                   ({cwpswap_tid_w,1'b0, new_lo_cwp_w[2:1]}),
1594
                .wr_data0                       (wr_data0),
1595
                .wr_data1                       (wr_data1),
1596
                .wr_data2                       (wr_data2),
1597
                .wr_data3                       (wr_data3),
1598
                .rd_thread                      (thr_rs1[6:5]),
1599
                .rd_data                        (rd_data09));
1600
        bw_r_irf_register register10(
1601
                .clk                            (clk),
1602
                .wrens                          (wrens[43:40]),
1603
                .save                           (swap_odd_m_vld),
1604
                .save_addr                      ({cwpswap_tid_m, 1'b0, old_lo_cwp_m[2:1]}),
1605
                .restore                        ((swap_odd_w & (~kill_restore_w))),
1606
                .restore_addr                   ({cwpswap_tid_w,1'b0, new_lo_cwp_w[2:1]}),
1607
                .wr_data0                       (wr_data0),
1608
                .wr_data1                       (wr_data1),
1609
                .wr_data2                       (wr_data2),
1610
                .wr_data3                       (wr_data3),
1611
                .rd_thread                      (thr_rs1[6:5]),
1612
                .rd_data                        (rd_data10));
1613
        bw_r_irf_register register11(
1614
                .clk                            (clk),
1615
                .wrens                          (wrens[47:44]),
1616
                .save                           (swap_odd_m_vld),
1617
                .save_addr                      ({cwpswap_tid_m, 1'b0, old_lo_cwp_m[2:1]}),
1618
                .restore                        ((swap_odd_w & (~kill_restore_w))),
1619
                .restore_addr                   ({cwpswap_tid_w,1'b0, new_lo_cwp_w[2:1]}),
1620
                .wr_data0                       (wr_data0),
1621
                .wr_data1                       (wr_data1),
1622
                .wr_data2                       (wr_data2),
1623
                .wr_data3                       (wr_data3),
1624
                .rd_thread                      (thr_rs1[6:5]),
1625
                .rd_data                        (rd_data11));
1626
        bw_r_irf_register register12(
1627
                .clk                            (clk),
1628
                .wrens                          (wrens[51:48]),
1629
                .save                           (swap_odd_m_vld),
1630
                .save_addr                      ({cwpswap_tid_m, 1'b0, old_lo_cwp_m[2:1]}),
1631
                .restore                        ((swap_odd_w & (~kill_restore_w))),
1632
                .restore_addr                   ({cwpswap_tid_w,1'b0, new_lo_cwp_w[2:1]}),
1633
                .wr_data0                       (wr_data0),
1634
                .wr_data1                       (wr_data1),
1635
                .wr_data2                       (wr_data2),
1636
                .wr_data3                       (wr_data3),
1637
                .rd_thread                      (thr_rs1[6:5]),
1638
                .rd_data                        (rd_data12));
1639
        bw_r_irf_register register13(
1640
                .clk                            (clk),
1641
                .wrens                          (wrens[55:52]),
1642
                .save                           (swap_odd_m_vld),
1643
                .save_addr                      ({cwpswap_tid_m, 1'b0, old_lo_cwp_m[2:1]}),
1644
                .restore                        ((swap_odd_w & (~kill_restore_w))),
1645
                .restore_addr                   ({cwpswap_tid_w,1'b0, new_lo_cwp_w[2:1]}),
1646
                .wr_data0                       (wr_data0),
1647
                .wr_data1                       (wr_data1),
1648
                .wr_data2                       (wr_data2),
1649
                .wr_data3                       (wr_data3),
1650
                .rd_thread                      (thr_rs1[6:5]),
1651
                .rd_data                        (rd_data13));
1652
        bw_r_irf_register register14(
1653
                .clk                            (clk),
1654
                .wrens                          (wrens[59:56]),
1655
                .save                           (swap_odd_m_vld),
1656
                .save_addr                      ({cwpswap_tid_m, 1'b0, old_lo_cwp_m[2:1]}),
1657
                .restore                        ((swap_odd_w & (~kill_restore_w))),
1658
                .restore_addr                   ({cwpswap_tid_w,1'b0, new_lo_cwp_w[2:1]}),
1659
                .wr_data0                       (wr_data0),
1660
                .wr_data1                       (wr_data1),
1661
                .wr_data2                       (wr_data2),
1662
                .wr_data3                       (wr_data3),
1663
                .rd_thread                      (thr_rs1[6:5]),
1664
                .rd_data                        (rd_data14));
1665
        bw_r_irf_register register15(
1666
                .clk                            (clk),
1667
                .wrens                          (wrens[63:60]),
1668
                .save                           (swap_odd_m_vld),
1669
                .save_addr                      ({cwpswap_tid_m, 1'b0, old_lo_cwp_m[2:1]}),
1670
                .restore                        ((swap_odd_w & (~kill_restore_w))),
1671
                .restore_addr                   ({cwpswap_tid_w,1'b0, new_lo_cwp_w[2:1]}),
1672
                .wr_data0                       (wr_data0),
1673
                .wr_data1                       (wr_data1),
1674
                .wr_data2                       (wr_data2),
1675
                .wr_data3                       (wr_data3),
1676
                .rd_thread                      (thr_rs1[6:5]),
1677
                .rd_data                        (rd_data15));
1678
 
1679
        bw_r_irf_register register16(
1680
                .clk                            (clk),
1681
                .wrens                          (wrens[67:64]),
1682
                .save                           (swap_local_m_vld),
1683
                .save_addr                      ({cwpswap_tid_m, old_lo_cwp_m[2:0]}),
1684
                .restore                        ((swap_local_w & (~kill_restore_w))),
1685
                .restore_addr                   ({cwpswap_tid_w, new_lo_cwp_w[2:0]}),
1686
                .wr_data0                       (wr_data0),
1687
                .wr_data1                       (wr_data1),
1688
                .wr_data2                       (wr_data2),
1689
                .wr_data3                       (wr_data3),
1690
                .rd_thread                      (thr_rs1[6:5]),
1691
                .rd_data                        (rd_data16));
1692
        bw_r_irf_register register17(
1693
                .clk                            (clk),
1694
                .wrens                          (wrens[71:68]),
1695
                .save                           (swap_local_m_vld),
1696
                .save_addr                      ({cwpswap_tid_m, old_lo_cwp_m[2:0]}),
1697
                .restore                        ((swap_local_w & (~kill_restore_w))),
1698
                .restore_addr                   ({cwpswap_tid_w, new_lo_cwp_w[2:0]}),
1699
                .wr_data0                       (wr_data0),
1700
                .wr_data1                       (wr_data1),
1701
                .wr_data2                       (wr_data2),
1702
                .wr_data3                       (wr_data3),
1703
                .rd_thread                      (thr_rs1[6:5]),
1704
                .rd_data                        (rd_data17));
1705
        bw_r_irf_register register18(
1706
                .clk                            (clk),
1707
                .wrens                          (wrens[75:72]),
1708
                .save                           (swap_local_m_vld),
1709
                .save_addr                      ({cwpswap_tid_m, old_lo_cwp_m[2:0]}),
1710
                .restore                        ((swap_local_w & (~kill_restore_w))),
1711
                .restore_addr                   ({cwpswap_tid_w, new_lo_cwp_w[2:0]}),
1712
                .wr_data0                       (wr_data0),
1713
                .wr_data1                       (wr_data1),
1714
                .wr_data2                       (wr_data2),
1715
                .wr_data3                       (wr_data3),
1716
                .rd_thread                      (thr_rs1[6:5]),
1717
                .rd_data                        (rd_data18));
1718
        bw_r_irf_register register19(
1719
                .clk                            (clk),
1720
                .wrens                          (wrens[79:76]),
1721
                .save                           (swap_local_m_vld),
1722
                .save_addr                      ({cwpswap_tid_m, old_lo_cwp_m[2:0]}),
1723
                .restore                        ((swap_local_w & (~kill_restore_w))),
1724
                .restore_addr                   ({cwpswap_tid_w, new_lo_cwp_w[2:0]}),
1725
                .wr_data0                       (wr_data0),
1726
                .wr_data1                       (wr_data1),
1727
                .wr_data2                       (wr_data2),
1728
                .wr_data3                       (wr_data3),
1729
                .rd_thread                      (thr_rs1[6:5]),
1730
                .rd_data                        (rd_data19));
1731
        bw_r_irf_register register20(
1732
                .clk                            (clk),
1733
                .wrens                          (wrens[83:80]),
1734
                .save                           (swap_local_m_vld),
1735
                .save_addr                      ({cwpswap_tid_m, old_lo_cwp_m[2:0]}),
1736
                .restore                        ((swap_local_w & (~kill_restore_w))),
1737
                .restore_addr                   ({cwpswap_tid_w, new_lo_cwp_w[2:0]}),
1738
                .wr_data0                       (wr_data0),
1739
                .wr_data1                       (wr_data1),
1740
                .wr_data2                       (wr_data2),
1741
                .wr_data3                       (wr_data3),
1742
                .rd_thread                      (thr_rs1[6:5]),
1743
                .rd_data                        (rd_data20));
1744
        bw_r_irf_register register21(
1745
                .clk                            (clk),
1746
                .wrens                          (wrens[87:84]),
1747
                .save                           (swap_local_m_vld),
1748
                .save_addr                      ({cwpswap_tid_m, old_lo_cwp_m[2:0]}),
1749
                .restore                        ((swap_local_w & (~kill_restore_w))),
1750
                .restore_addr                   ({cwpswap_tid_w, new_lo_cwp_w[2:0]}),
1751
                .wr_data0                       (wr_data0),
1752
                .wr_data1                       (wr_data1),
1753
                .wr_data2                       (wr_data2),
1754
                .wr_data3                       (wr_data3),
1755
                .rd_thread                      (thr_rs1[6:5]),
1756
                .rd_data                        (rd_data21));
1757
        bw_r_irf_register register22(
1758
                .clk                            (clk),
1759
                .wrens                          (wrens[91:88]),
1760
                .save                           (swap_local_m_vld),
1761
                .save_addr                      ({cwpswap_tid_m, old_lo_cwp_m[2:0]}),
1762
                .restore                        ((swap_local_w & (~kill_restore_w))),
1763
                .restore_addr                   ({cwpswap_tid_w, new_lo_cwp_w[2:0]}),
1764
                .wr_data0                       (wr_data0),
1765
                .wr_data1                       (wr_data1),
1766
                .wr_data2                       (wr_data2),
1767
                .wr_data3                       (wr_data3),
1768
                .rd_thread                      (thr_rs1[6:5]),
1769
                .rd_data                        (rd_data22));
1770
        bw_r_irf_register register23(
1771
                .clk                            (clk),
1772
                .wrens                          (wrens[95:92]),
1773
                .save                           (swap_local_m_vld),
1774
                .save_addr                      ({cwpswap_tid_m, old_lo_cwp_m[2:0]}),
1775
                .restore                        ((swap_local_w & (~kill_restore_w))),
1776
                .restore_addr                   ({cwpswap_tid_w, new_lo_cwp_w[2:0]}),
1777
                .wr_data0                       (wr_data0),
1778
                .wr_data1                       (wr_data1),
1779
                .wr_data2                       (wr_data2),
1780
                .wr_data3                       (wr_data3),
1781
                .rd_thread                      (thr_rs1[6:5]),
1782
                .rd_data                        (rd_data23));
1783
 
1784
        bw_r_irf_register register24(
1785
                .clk                            (clk),
1786
                .wrens                          (wrens[99:96]),
1787
                .save                           (swap_even_m_vld),
1788
                .save_addr                      ({cwpswap_tid_m[1:0], 1'b0, old_e_cwp_m[1:0]}),
1789
                .restore                        ((swap_even_w & (~kill_restore_w))),
1790
                .restore_addr                   ({cwpswap_tid_w[1:0], 1'b0, new_e_cwp_w[1:0]}),
1791
                .wr_data0                       (wr_data0),
1792
                .wr_data1                       (wr_data1),
1793
                .wr_data2                       (wr_data2),
1794
                .wr_data3                       (wr_data3),
1795
                .rd_thread                      (thr_rs1[6:5]),
1796
                .rd_data                        (rd_data24));
1797
        bw_r_irf_register register25(
1798
                .clk                            (clk),
1799
                .wrens                          (wrens[103:100]),
1800
                .save                           (swap_even_m_vld),
1801
                .save_addr                      ({cwpswap_tid_m[1:0], 1'b0, old_e_cwp_m[1:0]}),
1802
                .restore                        ((swap_even_w & (~kill_restore_w))),
1803
                .restore_addr                   ({cwpswap_tid_w[1:0], 1'b0, new_e_cwp_w[1:0]}),
1804
                .wr_data0                       (wr_data0),
1805
                .wr_data1                       (wr_data1),
1806
                .wr_data2                       (wr_data2),
1807
                .wr_data3                       (wr_data3),
1808
                .rd_thread                      (thr_rs1[6:5]),
1809
                .rd_data                        (rd_data25));
1810
        bw_r_irf_register register26(
1811
                .clk                            (clk),
1812
                .wrens                          (wrens[107:104]),
1813
                .save                           (swap_even_m_vld),
1814
                .save_addr                      ({cwpswap_tid_m[1:0], 1'b0, old_e_cwp_m[1:0]}),
1815
                .restore                        ((swap_even_w & (~kill_restore_w))),
1816
                .restore_addr                   ({cwpswap_tid_w[1:0], 1'b0, new_e_cwp_w[1:0]}),
1817
                .wr_data0                       (wr_data0),
1818
                .wr_data1                       (wr_data1),
1819
                .wr_data2                       (wr_data2),
1820
                .wr_data3                       (wr_data3),
1821
                .rd_thread                      (thr_rs1[6:5]),
1822
                .rd_data                        (rd_data26));
1823
        bw_r_irf_register register27(
1824
                .clk                            (clk),
1825
                .wrens                          (wrens[111:108]),
1826
                .save                           (swap_even_m_vld),
1827
                .save_addr                      ({cwpswap_tid_m[1:0], 1'b0, old_e_cwp_m[1:0]}),
1828
                .restore                        ((swap_even_w & (~kill_restore_w))),
1829
                .restore_addr                   ({cwpswap_tid_w[1:0], 1'b0, new_e_cwp_w[1:0]}),
1830
                .wr_data0                       (wr_data0),
1831
                .wr_data1                       (wr_data1),
1832
                .wr_data2                       (wr_data2),
1833
                .wr_data3                       (wr_data3),
1834
                .rd_thread                      (thr_rs1[6:5]),
1835
                .rd_data                        (rd_data27));
1836
        bw_r_irf_register register28(
1837
                .clk                            (clk),
1838
                .wrens                          (wrens[115:112]),
1839
                .save                           (swap_even_m_vld),
1840
                .save_addr                      ({cwpswap_tid_m[1:0], 1'b0, old_e_cwp_m[1:0]}),
1841
                .restore                        ((swap_even_w & (~kill_restore_w))),
1842
                .restore_addr                   ({cwpswap_tid_w[1:0], 1'b0, new_e_cwp_w[1:0]}),
1843
                .wr_data0                       (wr_data0),
1844
                .wr_data1                       (wr_data1),
1845
                .wr_data2                       (wr_data2),
1846
                .wr_data3                       (wr_data3),
1847
                .rd_thread                      (thr_rs1[6:5]),
1848
                .rd_data                        (rd_data28));
1849
        bw_r_irf_register register29(
1850
                .clk                            (clk),
1851
                .wrens                          (wrens[119:116]),
1852
                .save                           (swap_even_m_vld),
1853
                .save_addr                      ({cwpswap_tid_m[1:0], 1'b0, old_e_cwp_m[1:0]}),
1854
                .restore                        ((swap_even_w & (~kill_restore_w))),
1855
                .restore_addr                   ({cwpswap_tid_w[1:0], 1'b0, new_e_cwp_w[1:0]}),
1856
                .wr_data0                       (wr_data0),
1857
                .wr_data1                       (wr_data1),
1858
                .wr_data2                       (wr_data2),
1859
                .wr_data3                       (wr_data3),
1860
                .rd_thread                      (thr_rs1[6:5]),
1861
                .rd_data                        (rd_data29));
1862
        bw_r_irf_register register30(
1863
                .clk                            (clk),
1864
                .wrens                          (wrens[123:120]),
1865
                .save                           (swap_even_m_vld),
1866
                .save_addr                      ({cwpswap_tid_m[1:0], 1'b0, old_e_cwp_m[1:0]}),
1867
                .restore                        ((swap_even_w & (~kill_restore_w))),
1868
                .restore_addr                   ({cwpswap_tid_w[1:0], 1'b0, new_e_cwp_w[1:0]}),
1869
                .wr_data0                       (wr_data0),
1870
                .wr_data1                       (wr_data1),
1871
                .wr_data2                       (wr_data2),
1872
                .wr_data3                       (wr_data3),
1873
                .rd_thread                      (thr_rs1[6:5]),
1874
                .rd_data                        (rd_data30));
1875
        bw_r_irf_register register31(
1876
                .clk                            (clk),
1877
                .wrens                          (wrens[127:124]),
1878
                .save                           (swap_even_m_vld),
1879
                .save_addr                      ({cwpswap_tid_m[1:0], 1'b0, old_e_cwp_m[1:0]}),
1880
                .restore                        ((swap_even_w & (~kill_restore_w))),
1881
                .restore_addr                   ({cwpswap_tid_w[1:0], 1'b0, new_e_cwp_w[1:0]}),
1882
                .wr_data0                       (wr_data0),
1883
                .wr_data1                       (wr_data1),
1884
                .wr_data2                       (wr_data2),
1885
                .wr_data3                       (wr_data3),
1886
                .rd_thread                      (thr_rs1[6:5]),
1887
                .rd_data                        (rd_data31));
1888
 
1889
 
1890
        always @(negedge clk) if (ifu_exu_ren1_d) begin
1891
          case (thr_rs1[4:0])
1892
            5'b0:
1893
              irf_byp_rs1_data_d <= rd_data00;
1894
            5'b1:
1895
              irf_byp_rs1_data_d <= rd_data01;
1896
            5'b00010:
1897
              irf_byp_rs1_data_d <= rd_data02;
1898
            5'b00011:
1899
              irf_byp_rs1_data_d <= rd_data03;
1900
            5'b00100:
1901
              irf_byp_rs1_data_d <= rd_data04;
1902
            5'b00101:
1903
              irf_byp_rs1_data_d <= rd_data05;
1904
            5'b00110:
1905
              irf_byp_rs1_data_d <= rd_data06;
1906
            5'b00111:
1907
              irf_byp_rs1_data_d <= rd_data07;
1908
            5'b01000:
1909
              irf_byp_rs1_data_d <= rd_data08;
1910
            5'b01001:
1911
              irf_byp_rs1_data_d <= rd_data09;
1912
            5'b01010:
1913
              irf_byp_rs1_data_d <= rd_data10;
1914
            5'b01011:
1915
              irf_byp_rs1_data_d <= rd_data11;
1916
            5'b01100:
1917
              irf_byp_rs1_data_d <= rd_data12;
1918
            5'b01101:
1919
              irf_byp_rs1_data_d <= rd_data13;
1920
            5'b01110:
1921
              irf_byp_rs1_data_d <= rd_data14;
1922
            5'b01111:
1923
              irf_byp_rs1_data_d <= rd_data15;
1924
            5'b10000:
1925
              irf_byp_rs1_data_d <= rd_data16;
1926
            5'b10001:
1927
              irf_byp_rs1_data_d <= rd_data17;
1928
            5'b10010:
1929
              irf_byp_rs1_data_d <= rd_data18;
1930
            5'b10011:
1931
              irf_byp_rs1_data_d <= rd_data19;
1932
            5'b10100:
1933
              irf_byp_rs1_data_d <= rd_data20;
1934
            5'b10101:
1935
              irf_byp_rs1_data_d <= rd_data21;
1936
            5'b10110:
1937
              irf_byp_rs1_data_d <= rd_data22;
1938
            5'b10111:
1939
              irf_byp_rs1_data_d <= rd_data23;
1940
            5'b11000:
1941
              irf_byp_rs1_data_d <= rd_data24;
1942
            5'b11001:
1943
              irf_byp_rs1_data_d <= rd_data25;
1944
            5'b11010:
1945
              irf_byp_rs1_data_d <= rd_data26;
1946
            5'b11011:
1947
              irf_byp_rs1_data_d <= rd_data27;
1948
            5'b11100:
1949
              irf_byp_rs1_data_d <= rd_data28;
1950
            5'b11101:
1951
              irf_byp_rs1_data_d <= rd_data29;
1952
            5'b11110:
1953
              irf_byp_rs1_data_d <= rd_data30;
1954
            5'b11111:
1955
              irf_byp_rs1_data_d <= rd_data31;
1956
          endcase
1957
        end
1958
        always @(negedge clk) if (ifu_exu_ren2_d) begin
1959
          case (thr_rs2[4:0])
1960
            5'b0:
1961
              irf_byp_rs2_data_d <= rd_data00;
1962
            5'b1:
1963
              irf_byp_rs2_data_d <= rd_data01;
1964
            5'b00010:
1965
              irf_byp_rs2_data_d <= rd_data02;
1966
            5'b00011:
1967
              irf_byp_rs2_data_d <= rd_data03;
1968
            5'b00100:
1969
              irf_byp_rs2_data_d <= rd_data04;
1970
            5'b00101:
1971
              irf_byp_rs2_data_d <= rd_data05;
1972
            5'b00110:
1973
              irf_byp_rs2_data_d <= rd_data06;
1974
            5'b00111:
1975
              irf_byp_rs2_data_d <= rd_data07;
1976
            5'b01000:
1977
              irf_byp_rs2_data_d <= rd_data08;
1978
            5'b01001:
1979
              irf_byp_rs2_data_d <= rd_data09;
1980
            5'b01010:
1981
              irf_byp_rs2_data_d <= rd_data10;
1982
            5'b01011:
1983
              irf_byp_rs2_data_d <= rd_data11;
1984
            5'b01100:
1985
              irf_byp_rs2_data_d <= rd_data12;
1986
            5'b01101:
1987
              irf_byp_rs2_data_d <= rd_data13;
1988
            5'b01110:
1989
              irf_byp_rs2_data_d <= rd_data14;
1990
            5'b01111:
1991
              irf_byp_rs2_data_d <= rd_data15;
1992
            5'b10000:
1993
              irf_byp_rs2_data_d <= rd_data16;
1994
            5'b10001:
1995
              irf_byp_rs2_data_d <= rd_data17;
1996
            5'b10010:
1997
              irf_byp_rs2_data_d <= rd_data18;
1998
            5'b10011:
1999
              irf_byp_rs2_data_d <= rd_data19;
2000
            5'b10100:
2001
              irf_byp_rs2_data_d <= rd_data20;
2002
            5'b10101:
2003
              irf_byp_rs2_data_d <= rd_data21;
2004
            5'b10110:
2005
              irf_byp_rs2_data_d <= rd_data22;
2006
            5'b10111:
2007
              irf_byp_rs2_data_d <= rd_data23;
2008
            5'b11000:
2009
              irf_byp_rs2_data_d <= rd_data24;
2010
            5'b11001:
2011
              irf_byp_rs2_data_d <= rd_data25;
2012
            5'b11010:
2013
              irf_byp_rs2_data_d <= rd_data26;
2014
            5'b11011:
2015
              irf_byp_rs2_data_d <= rd_data27;
2016
            5'b11100:
2017
              irf_byp_rs2_data_d <= rd_data28;
2018
            5'b11101:
2019
              irf_byp_rs2_data_d <= rd_data29;
2020
            5'b11110:
2021
              irf_byp_rs2_data_d <= rd_data30;
2022
            5'b11111:
2023
              irf_byp_rs2_data_d <= rd_data31;
2024
          endcase
2025
        end
2026
        always @(negedge clk) if (ifu_exu_ren3_d) begin
2027
          case (thr_rs3[4:0])
2028
            5'b0:
2029
              irf_byp_rs3_data_d <= rd_data00;
2030
            5'b1:
2031
              irf_byp_rs3_data_d <= rd_data01;
2032
            5'b00010:
2033
              irf_byp_rs3_data_d <= rd_data02;
2034
            5'b00011:
2035
              irf_byp_rs3_data_d <= rd_data03;
2036
            5'b00100:
2037
              irf_byp_rs3_data_d <= rd_data04;
2038
            5'b00101:
2039
              irf_byp_rs3_data_d <= rd_data05;
2040
            5'b00110:
2041
              irf_byp_rs3_data_d <= rd_data06;
2042
            5'b00111:
2043
              irf_byp_rs3_data_d <= rd_data07;
2044
            5'b01000:
2045
              irf_byp_rs3_data_d <= rd_data08;
2046
            5'b01001:
2047
              irf_byp_rs3_data_d <= rd_data09;
2048
            5'b01010:
2049
              irf_byp_rs3_data_d <= rd_data10;
2050
            5'b01011:
2051
              irf_byp_rs3_data_d <= rd_data11;
2052
            5'b01100:
2053
              irf_byp_rs3_data_d <= rd_data12;
2054
            5'b01101:
2055
              irf_byp_rs3_data_d <= rd_data13;
2056
            5'b01110:
2057
              irf_byp_rs3_data_d <= rd_data14;
2058
            5'b01111:
2059
              irf_byp_rs3_data_d <= rd_data15;
2060
            5'b10000:
2061
              irf_byp_rs3_data_d <= rd_data16;
2062
            5'b10001:
2063
              irf_byp_rs3_data_d <= rd_data17;
2064
            5'b10010:
2065
              irf_byp_rs3_data_d <= rd_data18;
2066
            5'b10011:
2067
              irf_byp_rs3_data_d <= rd_data19;
2068
            5'b10100:
2069
              irf_byp_rs3_data_d <= rd_data20;
2070
            5'b10101:
2071
              irf_byp_rs3_data_d <= rd_data21;
2072
            5'b10110:
2073
              irf_byp_rs3_data_d <= rd_data22;
2074
            5'b10111:
2075
              irf_byp_rs3_data_d <= rd_data23;
2076
            5'b11000:
2077
              irf_byp_rs3_data_d <= rd_data24;
2078
            5'b11001:
2079
              irf_byp_rs3_data_d <= rd_data25;
2080
            5'b11010:
2081
              irf_byp_rs3_data_d <= rd_data26;
2082
            5'b11011:
2083
              irf_byp_rs3_data_d <= rd_data27;
2084
            5'b11100:
2085
              irf_byp_rs3_data_d <= rd_data28;
2086
            5'b11101:
2087
              irf_byp_rs3_data_d <= rd_data29;
2088
            5'b11110:
2089
              irf_byp_rs3_data_d <= rd_data30;
2090
            5'b11111:
2091
              irf_byp_rs3_data_d <= rd_data31;
2092
          endcase
2093
        end
2094
        always @(negedge clk) if (ifu_exu_ren3_d) begin
2095
          case (thr_rs3h[4:1])
2096
            4'b0:
2097
              irf_byp_rs3h_data_d <= rd_data01;
2098
            4'b1:
2099
              irf_byp_rs3h_data_d <= rd_data03;
2100
            4'b0010:
2101
              irf_byp_rs3h_data_d <= rd_data05;
2102
            4'b0011:
2103
              irf_byp_rs3h_data_d <= rd_data07;
2104
            4'b0100:
2105
              irf_byp_rs3h_data_d <= rd_data09;
2106
            4'b0101:
2107
              irf_byp_rs3h_data_d <= rd_data11;
2108
            4'b0110:
2109
              irf_byp_rs3h_data_d <= rd_data13;
2110
            4'b0111:
2111
              irf_byp_rs3h_data_d <= rd_data15;
2112
            4'b1000:
2113
              irf_byp_rs3h_data_d <= rd_data17;
2114
            4'b1001:
2115
              irf_byp_rs3h_data_d <= rd_data19;
2116
            4'b1010:
2117
              irf_byp_rs3h_data_d <= rd_data21;
2118
            4'b1011:
2119
              irf_byp_rs3h_data_d <= rd_data23;
2120
            4'b1100:
2121
              irf_byp_rs3h_data_d <= rd_data25;
2122
            4'b1101:
2123
              irf_byp_rs3h_data_d <= rd_data27;
2124
            4'b1110:
2125
              irf_byp_rs3h_data_d <= rd_data29;
2126
            4'b1111:
2127
              irf_byp_rs3h_data_d <= rd_data31;
2128
          endcase
2129
        end
2130
endmodule
2131
 
2132
`endif
2133
`else
2134
 
2135
module bw_r_irf (/*AUTOARG*/
2136
   // Outputs
2137
   so, irf_byp_rs1_data_d_l, irf_byp_rs2_data_d_l,
2138
   irf_byp_rs3_data_d_l, irf_byp_rs3h_data_d_l,
2139
   // Inputs
2140
   rclk, reset_l, si, se, sehold, rst_tri_en, ifu_exu_tid_s2,
2141
   ifu_exu_rs1_s, ifu_exu_rs2_s, ifu_exu_rs3_s, ifu_exu_ren1_s,
2142
   ifu_exu_ren2_s, ifu_exu_ren3_s, ecl_irf_wen_w, ecl_irf_wen_w2,
2143
   ecl_irf_rd_m, ecl_irf_rd_g, byp_irf_rd_data_w, byp_irf_rd_data_w2,
2144
   ecl_irf_tid_m, ecl_irf_tid_g, rml_irf_old_lo_cwp_e,
2145
   rml_irf_new_lo_cwp_e, rml_irf_old_e_cwp_e, rml_irf_new_e_cwp_e,
2146
   rml_irf_swap_even_e, rml_irf_swap_odd_e, rml_irf_swap_local_e,
2147
   rml_irf_kill_restore_w, rml_irf_cwpswap_tid_e, rml_irf_old_agp,
2148
   rml_irf_new_agp, rml_irf_swap_global, rml_irf_global_tid
2149
   ) ;
2150
   input rclk;
2151
   input reset_l;
2152
   input si;
2153
   input se;
2154
   input sehold;
2155
   input rst_tri_en;
2156
   input [1:0]  ifu_exu_tid_s2;  // s stage thread
2157
   input [4:0]  ifu_exu_rs1_s;  // source addresses
2158
   input [4:0]  ifu_exu_rs2_s;
2159
   input [4:0]  ifu_exu_rs3_s;
2160
   input ifu_exu_ren1_s;        // read enables for all 3 ports
2161
   input ifu_exu_ren2_s;
2162
   input ifu_exu_ren3_s;
2163
   input ecl_irf_wen_w;        // write enables for both write ports
2164
   input ecl_irf_wen_w2;
2165
   input [4:0]  ecl_irf_rd_m;   // w destination
2166
   input [4:0]  ecl_irf_rd_g;  // w2 destination
2167
   input [71:0] byp_irf_rd_data_w;// write data from w1
2168
   input [71:0] byp_irf_rd_data_w2;     // write data from w2
2169
   input [1:0]  ecl_irf_tid_m;  // w stage thread
2170
   input [1:0]  ecl_irf_tid_g; // w2 thread
2171
 
2172
   input [2:0]  rml_irf_old_lo_cwp_e;  // current window pointer for locals and odds
2173
   input [2:0]  rml_irf_new_lo_cwp_e;  // target window pointer for locals and odds
2174
   input [2:1]  rml_irf_old_e_cwp_e;  // current window pointer for evens
2175
   input [2:1]  rml_irf_new_e_cwp_e;  // target window pointer for evens
2176
   input        rml_irf_swap_even_e;
2177
   input        rml_irf_swap_odd_e;
2178
   input        rml_irf_swap_local_e;
2179
   input        rml_irf_kill_restore_w;
2180
   input [1:0]  rml_irf_cwpswap_tid_e;
2181
 
2182
   input [1:0]  rml_irf_old_agp; // alternate global pointer
2183
   input [1:0]  rml_irf_new_agp; // alternate global pointer
2184
   input        rml_irf_swap_global;
2185
   input [1:0]  rml_irf_global_tid;
2186
 
2187
   output       so;
2188
   output [71:0] irf_byp_rs1_data_d_l;
2189
   output [71:0] irf_byp_rs2_data_d_l;
2190
   output [71:0] irf_byp_rs3_data_d_l;
2191
   output [31:0] irf_byp_rs3h_data_d_l;
2192
   reg [71:0] irf_byp_rs1_data_d;
2193
   reg [71:0] irf_byp_rs2_data_d;
2194
   reg [71:0] irf_byp_rs3_data_d;
2195
   reg [71:0] irf_byp_rs3h_data_d;
2196
 
2197
   reg [71:0]    active_window [127:0];// 32x4 72 bit registers
2198
   reg [71:0]    locals[255:0];      // 4x8x8 registers
2199
   reg [71:0]    evens[127:0];      // 4x4x8 registers
2200
   reg [71:0]    odds[127:0];      // 4x4x8 registers
2201
   reg [71:0]    globals[127:0];      // 4x4x8 registers
2202
   // registers for manipulating windows
2203
   reg [6:0] active_pointer;
2204
   reg [7:0] regfile_pointer;
2205
   reg [5:0] i;
2206
 
2207
   wire [1:0]  ecl_irf_tid_w;  // w stage thread
2208
   wire [1:0]  ecl_irf_tid_w2; // w2 thread
2209
   wire [4:0]  ecl_irf_rd_w;   // w destination
2210
   wire [4:0]  ecl_irf_rd_w2;  // w2 destination
2211
   wire [1:0]  ifu_exu_thr_d;  // d stage thread
2212
   wire ifu_exu_ren1_d;        // read enables for all 3 ports
2213
   wire ifu_exu_ren2_d;
2214
   wire ifu_exu_ren3_d;
2215
   wire [4:0]  ifu_exu_rs1_d;  // source addresses
2216
   wire [4:0]  ifu_exu_rs2_d;
2217
   wire [4:0]  ifu_exu_rs3_d;
2218
   wire [6:0]    thr_rs1;       // these 5 are a combination of the thr and reg
2219
   wire [6:0]    thr_rs2;       // so that comparison can be done more easily
2220
   wire [6:0]    thr_rs3;
2221
   wire [6:0]    thr_rs3h;
2222
   wire [6:0]    thr_rd_w;
2223
   wire [6:0]    thr_rd_w2;
2224
 
2225
   reg [1:0] cwpswap_tid_m;
2226
   reg [1:0] cwpswap_tid_w;
2227
   reg [2:0] old_lo_cwp_m;
2228
   reg [2:0] new_lo_cwp_m;
2229
   reg [2:0] new_lo_cwp_w;
2230
   reg [1:0] old_e_cwp_m;
2231
   reg [1:0] new_e_cwp_m;
2232
   reg [1:0] new_e_cwp_w;
2233
   reg       swap_local_m;
2234
   reg       swap_local_w;
2235
   reg       swap_even_m;
2236
   reg       swap_even_w;
2237
   reg       swap_odd_m;
2238
   reg       swap_odd_w;
2239
   reg       kill_restore_d1;
2240
   reg        swap_global_d1;
2241
   reg        swap_global_d2;
2242
   reg [1:0]  global_tid_d1;
2243
   reg [1:0]  global_tid_d2;
2244
   reg [1:0] old_agp_d1,
2245
             new_agp_d1,
2246
             new_agp_d2;
2247
 
2248
   reg [71:0] active_win_thr_rd_w_neg;
2249
   reg        active_win_thr_rd_w_neg_wr_en;
2250
   reg [6:0]  thr_rd_w_neg;
2251
   reg [71:0] active_win_thr_rd_w2_neg;
2252
   reg        active_win_thr_rd_w2_neg_wr_en;
2253
   reg [6:0]  thr_rd_w2_neg;
2254
   reg        rst_tri_en_neg;
2255
 
2256
   wire          se;
2257
   wire          clk;
2258
   assign        clk = rclk & reset_l;
2259
   wire          ren1_s;
2260
   wire          ren2_s;
2261
   wire          ren3_s;
2262
   wire [4:0]    rs1_s;
2263
   wire [4:0]    rs2_s;
2264
   wire [4:0]    rs3_s;
2265
   wire [1:0]    tid_s;
2266
   wire [1:0]    tid_g;
2267
   wire [1:0]    tid_m;
2268
   wire [4:0]    rd_m;
2269
   wire [4:0]    rd_g;
2270
   wire          kill_restore_w;
2271
   wire          swap_global_d1_vld;
2272
   wire          swap_local_m_vld;
2273
   wire          swap_even_m_vld;
2274
   wire          swap_odd_m_vld;
2275
 
2276
   assign {ren1_s,ren2_s,ren3_s,rs1_s[4:0],rs2_s[4:0],rs3_s[4:0],tid_s[1:0],tid_g[1:0],tid_m[1:0],
2277
           rd_m[4:0], rd_g[4:0]} = (sehold)?
2278
          {ifu_exu_ren1_d,ifu_exu_ren2_d,ifu_exu_ren3_d,ifu_exu_rs1_d[4:0],ifu_exu_rs2_d[4:0],
2279
           ifu_exu_rs3_d[4:0],ifu_exu_thr_d[1:0],ecl_irf_tid_w2[1:0],ecl_irf_tid_w[1:0],
2280
           ecl_irf_rd_w[4:0],ecl_irf_rd_w2[4:0]}:
2281
          {ifu_exu_ren1_s,ifu_exu_ren2_s,ifu_exu_ren3_s,ifu_exu_rs1_s[4:0],ifu_exu_rs2_s[4:0],
2282
           ifu_exu_rs3_s[4:0],ifu_exu_tid_s2[1:0],ecl_irf_tid_g[1:0],ecl_irf_tid_m[1:0],
2283
           ecl_irf_rd_m[4:0],ecl_irf_rd_g[4:0]};
2284
   // Pipeline flops for irf control signals
2285
   dff_s dff_ren1_s2d(.din(ren1_s), .clk(clk), .q(ifu_exu_ren1_d), .se(se),
2286
                    .si(), .so());
2287
   dff_s dff_ren2_s2d(.din(ren2_s), .clk(clk), .q(ifu_exu_ren2_d), .se(se),
2288
                    .si(), .so());
2289
   dff_s dff_ren3_s2d(.din(ren3_s), .clk(clk), .q(ifu_exu_ren3_d), .se(se),
2290
                    .si(), .so());
2291
   dff_s #5 dff_rs1_s2d(.din(rs1_s[4:0]), .clk(clk), .q(ifu_exu_rs1_d[4:0]), .se(se),
2292
                      .si(),.so());
2293
   dff_s #5 dff_rs2_s2d(.din(rs2_s[4:0]), .clk(clk), .q(ifu_exu_rs2_d[4:0]), .se(se),
2294
                      .si(),.so());
2295
   dff_s #5 dff_rs3_s2d(.din(rs3_s[4:0]), .clk(clk), .q(ifu_exu_rs3_d[4:0]), .se(se),
2296
                      .si(),.so());
2297
   dff_s #2 dff_thr_s2d(.din(tid_s[1:0]), .clk(clk), .q(ifu_exu_thr_d[1:0]), .se(se),
2298
                      .si(),.so());
2299
   dff_s #2 dff_thr_g2w2(.din(tid_g[1:0]), .clk(clk), .q(ecl_irf_tid_w2[1:0]), .se(se),
2300
                      .si(),.so());
2301
   dff_s #2 dff_thr_m2w(.din(tid_m[1:0]), .clk(clk), .q(ecl_irf_tid_w[1:0]), .se(se),
2302
                      .si(),.so());
2303
   dff_s #5 dff_rd_m2w(.din(rd_m[4:0]), .clk(clk), .q(ecl_irf_rd_w[4:0]), .se(se),
2304
                      .si(),.so());
2305
   dff_s #5 dff_rd_g2w2(.din(rd_g[4:0]), .clk(clk), .q(ecl_irf_rd_w2[4:0]), .se(se),
2306
                      .si(),.so());
2307
 
2308
   // Concatenate the thread and rs1/rd bits together
2309
   assign        thr_rs1[6:0] = {ifu_exu_thr_d, ifu_exu_rs1_d};
2310
   assign        thr_rs2[6:0] = {ifu_exu_thr_d, ifu_exu_rs2_d};
2311
   assign        thr_rs3[6:0] = {ifu_exu_thr_d, ifu_exu_rs3_d[4:0]};
2312
   assign        thr_rs3h[6:0] = {ifu_exu_thr_d[1:0], ifu_exu_rs3_d[4:1], 1'b1};
2313
   assign        thr_rd_w[6:0] = {ecl_irf_tid_w, ecl_irf_rd_w};
2314
   assign        thr_rd_w2[6:0] = {ecl_irf_tid_w2, ecl_irf_rd_w2};
2315
 
2316
   // Active low outputs
2317
   assign        irf_byp_rs1_data_d_l[71:0] = ~irf_byp_rs1_data_d[71:0];
2318
   assign        irf_byp_rs2_data_d_l[71:0] = ~irf_byp_rs2_data_d[71:0];
2319
   assign        irf_byp_rs3_data_d_l[71:0] = ~irf_byp_rs3_data_d[71:0];
2320
   assign        irf_byp_rs3h_data_d_l[31:0] = ~irf_byp_rs3h_data_d[31:0];
2321
 
2322
   // Read port 1
2323
   always @ ( clk ) begin
2324
      if (clk) irf_byp_rs1_data_d <= {72{1'bx}};
2325
      else begin
2326
         if (ifu_exu_ren1_d) begin // read enable must be high
2327
            if (thr_rs1[4:0] == 5'b0) irf_byp_rs1_data_d <= {72{1'b0}};
2328
            else begin
2329
               if ((ecl_irf_wen_w && (thr_rs1 == thr_rd_w)) || // check r/w conflict
2330
                   (ecl_irf_wen_w2 && (thr_rs1 == thr_rd_w2))) begin
2331
                  irf_byp_rs1_data_d <= {72{1'bx}};  // rw conflict gives x
2332
               end
2333
               else begin
2334
                  irf_byp_rs1_data_d <= active_window[thr_rs1[6:0]];
2335
               end
2336
            end
2337
         end
2338
         // output disabled
2339
         else begin
2340
            irf_byp_rs1_data_d <= {72{1'bx}};
2341
         end
2342
      end
2343
   end
2344
 
2345
   // Read port 2
2346
   always @ ( clk ) begin
2347
      if (clk) irf_byp_rs2_data_d <= {72{1'bx}};
2348
      else begin
2349
         if (ifu_exu_ren2_d) begin
2350
            if (thr_rs2[4:0] == 5'b0) irf_byp_rs2_data_d <= {72{1'b0}};
2351
            else if ((ecl_irf_wen_w && (thr_rs2 == thr_rd_w)) ||
2352
                     (ecl_irf_wen_w2 && (thr_rs2 == thr_rd_w2)))
2353
              irf_byp_rs2_data_d <= {72{1'bx}};
2354
            else begin
2355
               irf_byp_rs2_data_d <= active_window[thr_rs2];
2356
            end
2357
         end
2358
         // output disabled
2359
         else irf_byp_rs2_data_d <= {72{1'bx}};
2360
      end
2361
   end
2362
 
2363
   // Read port 3
2364
   always @ ( clk ) begin
2365
      if (clk) irf_byp_rs3_data_d <= {72{1'bx}};
2366
      else begin
2367
         if (ifu_exu_ren3_d) begin
2368
            if (thr_rs3[4:0] == 5'b0) irf_byp_rs3_data_d[71:0] <= {72{1'b0}};
2369
            else if ((ecl_irf_wen_w && (thr_rs3 == thr_rd_w)) ||
2370
                     (ecl_irf_wen_w2 && (thr_rs3 == thr_rd_w2)))
2371
              begin
2372
                 irf_byp_rs3_data_d[71:0] <= {72{1'bx}};
2373
              end
2374
            else begin
2375
               irf_byp_rs3_data_d[71:0] <= active_window[thr_rs3];
2376
            end
2377
         end
2378
         // output disabled
2379
         else begin
2380
            irf_byp_rs3_data_d[71:0] <= {72{1'bx}};
2381
         end
2382
      end
2383
   end
2384
 
2385
   // Read port 3h
2386
   always @ ( clk ) begin
2387
      if (clk) irf_byp_rs3h_data_d[71:0] <= {72{1'bx}};
2388
      else begin
2389
         if (ifu_exu_ren3_d) begin
2390
            if (thr_rs3h[4:0] == 5'b0) irf_byp_rs3h_data_d[71:0] <= 72'b0;
2391
            else if ((ecl_irf_wen_w && (thr_rs3h == thr_rd_w)) ||
2392
                     (ecl_irf_wen_w2 && (thr_rs3h == thr_rd_w2)))
2393
              begin
2394
                 irf_byp_rs3h_data_d[71:0] <= {72{1'bx}};
2395
              end
2396
            else begin
2397
               irf_byp_rs3h_data_d[71:0] <= active_window[thr_rs3h];
2398
            end
2399
         end
2400
         // output disabled
2401
         else begin
2402
            irf_byp_rs3h_data_d[71:0] <= {72{1'bx}};
2403
         end
2404
      end
2405
   end
2406
 
2407
/////////////////////////////////////////////////////////////////
2408
///  Write ports
2409
////////////////////////////////////////////////////////////////
2410
   // This is a latch that works if both wen is high and clk is low
2411
 
2412
   always @(negedge clk) begin
2413
      rst_tri_en_neg <= rst_tri_en;
2414
      // write conflict results in X written to destination
2415
      if (ecl_irf_wen_w & ecl_irf_wen_w2 & (thr_rd_w[6:0] == thr_rd_w2[6:0])) begin
2416
         active_win_thr_rd_w_neg <= {72{1'bx}};
2417
         thr_rd_w_neg <= thr_rd_w;
2418
         active_win_thr_rd_w_neg_wr_en <= 1'b1;
2419
         active_win_thr_rd_w2_neg_wr_en <= 1'b0;
2420
      end
2421
      else begin
2422
         // W1 write port
2423
         if (ecl_irf_wen_w & (thr_rd_w[4:0] != 5'b0)) begin
2424
            active_win_thr_rd_w_neg <= byp_irf_rd_data_w;
2425
            thr_rd_w_neg <= thr_rd_w;
2426
            active_win_thr_rd_w_neg_wr_en <= 1'b1;
2427
         end
2428
         else
2429
           active_win_thr_rd_w_neg_wr_en <= 1'b0;
2430
 
2431
         // W2 write port
2432
         if (ecl_irf_wen_w2 & (thr_rd_w2[4:0] != 5'b0)) begin
2433
            active_win_thr_rd_w2_neg <= byp_irf_rd_data_w2;
2434
            thr_rd_w2_neg <= thr_rd_w2;
2435
            active_win_thr_rd_w2_neg_wr_en <= 1'b1;
2436
         end
2437
         else
2438
           active_win_thr_rd_w2_neg_wr_en <= 1'b0;
2439
      end
2440
   end
2441
 
2442
 
2443
 
2444
/* MOVED TO CMP ENVIRONMENT
2445
   initial begin
2446
      // Hardcode R0 to zero
2447
      active_window[{2'b00, 5'b00000}] = 72'b0;
2448
      active_window[{2'b01, 5'b00000}] = 72'b0;
2449
      active_window[{2'b10, 5'b00000}] = 72'b0;
2450
      active_window[{2'b11, 5'b00000}] = 72'b0;
2451
   end
2452
*/
2453
   //////////////////////////////////////////////////
2454
   // Window management logic
2455
   //////////////////////////////////////////////////
2456
   // Pipeline flops for control signals
2457
 
2458
   // cwp swap signals
2459
   assign kill_restore_w = (sehold)? kill_restore_d1: rml_irf_kill_restore_w;
2460
   assign swap_local_m_vld = swap_local_m & ~rst_tri_en;
2461
   assign swap_odd_m_vld = swap_odd_m & ~rst_tri_en;
2462
   assign swap_even_m_vld = swap_even_m & ~rst_tri_en;
2463
   assign swap_global_d1_vld = swap_global_d1 & ~rst_tri_en;
2464
 
2465
   always @ (posedge clk) begin
2466
      cwpswap_tid_m[1:0] <= (sehold)? cwpswap_tid_m[1:0]: rml_irf_cwpswap_tid_e[1:0];
2467
      cwpswap_tid_w[1:0] <= cwpswap_tid_m[1:0];
2468
      old_lo_cwp_m[2:0] <= (sehold)? old_lo_cwp_m[2:0]: rml_irf_old_lo_cwp_e[2:0];
2469
      new_lo_cwp_m[2:0] <= (sehold)? new_lo_cwp_m[2:0]: rml_irf_new_lo_cwp_e[2:0];
2470
      new_lo_cwp_w[2:0] <= new_lo_cwp_m[2:0];
2471
      old_e_cwp_m[1:0] <= (sehold)? old_e_cwp_m[1:0]: rml_irf_old_e_cwp_e[2:1];
2472
      new_e_cwp_m[1:0] <= (sehold)? new_e_cwp_m[1:0]: rml_irf_new_e_cwp_e[2:1];
2473
      new_e_cwp_w[1:0] <= new_e_cwp_m[1:0];
2474
      swap_local_m <= (sehold)? swap_local_m & rst_tri_en: rml_irf_swap_local_e;
2475
      swap_local_w <= swap_local_m_vld;
2476
      swap_odd_m <= (sehold)? swap_odd_m & rst_tri_en: rml_irf_swap_odd_e;
2477
      swap_odd_w <= swap_odd_m_vld;
2478
      swap_even_m <= (sehold)? swap_even_m & rst_tri_en: rml_irf_swap_even_e;
2479
      swap_even_w <= swap_even_m_vld;
2480
      kill_restore_d1 <= kill_restore_w;
2481
   end
2482
   // global swap signals    
2483
   always @ (posedge clk) begin
2484
      swap_global_d1 <= (sehold)? swap_global_d1 & rst_tri_en: rml_irf_swap_global;
2485
      swap_global_d2 <= swap_global_d1_vld;
2486
      global_tid_d1[1:0] <= (sehold)? global_tid_d1[1:0]: rml_irf_global_tid[1:0];
2487
      global_tid_d2[1:0] <= global_tid_d1[1:0];
2488
      old_agp_d1[1:0] <= (sehold)? old_agp_d1[1:0]: rml_irf_old_agp[1:0];
2489
      new_agp_d1[1:0] <= (sehold)? new_agp_d1[1:0]: rml_irf_new_agp[1:0];
2490
      new_agp_d2[1:0] <= new_agp_d1[1:0];
2491
   end
2492
 
2493
 
2494
   /////////////////////////////////////////////
2495
   // Globals
2496
   //-----------------------------------
2497
   // rml inputs are latched on rising edge
2498
   // 1st cycle used for decode
2499
   // 2nd cycle stores active window in phase 1
2500
   // 3rd cycle loads new globals in phase 1
2501
   /////////////////////////////////////////////
2502
 
2503
   always @ (posedge clk) begin
2504
 
2505
      if (active_win_thr_rd_w_neg_wr_en & (~rst_tri_en | ~rst_tri_en_neg)) begin
2506
         active_window[thr_rd_w_neg] = active_win_thr_rd_w_neg;
2507
      end
2508
      if (active_win_thr_rd_w2_neg_wr_en & (~rst_tri_en | ~rst_tri_en_neg)) begin
2509
         active_window[thr_rd_w2_neg] = active_win_thr_rd_w2_neg;
2510
      end
2511
      // save active globals in phase 1
2512
      if (swap_global_d1_vld) begin
2513
         for (i = 6'd0; i < 6'd8; i = i + 1) begin
2514
            active_pointer[6:0] = {global_tid_d1[1:0], i[4:0]};
2515
            regfile_pointer[7:0] = {1'b0, global_tid_d1[1:0], old_agp_d1[1:0], i[2:0]};
2516
            // prevent back to back swaps on same thread
2517
            if (swap_global_d2 & (global_tid_d1[1:0] == global_tid_d2[1:0])) begin
2518
               globals[regfile_pointer[6:0]] = {72{1'bx}};
2519
            end
2520
            else globals[regfile_pointer[6:0]] = active_window[active_pointer[6:0]];
2521
         end
2522
      end
2523
 
2524
    // load in new active globals in phase 2
2525
      if (swap_global_d2) begin
2526
         for (i = 6'd0; i < 6'd8; i = i + 1) begin
2527
            active_pointer[6:0] = {global_tid_d2[1:0], i[4:0]};
2528
            regfile_pointer[7:0] = {1'b0, global_tid_d2[1:0], new_agp_d2[1:0], i[2:0]};
2529
            if (swap_global_d1_vld & (global_tid_d1[1:0] == global_tid_d2[1:0])) begin
2530
               active_window[active_pointer] = {72{1'bx}};
2531
               globals[regfile_pointer[6:0]] = {72{1'bx}};
2532
            end
2533
            else active_window[active_pointer] = globals[regfile_pointer[6:0]];
2534
         end
2535
      end
2536
 
2537
   ////////////////////////////
2538
   // locals, ins and outs
2539
   //-------------------------
2540
   // E - set up inputs to flop
2541
   // M - Decode
2542
   // W (phase 1) - Save
2543
   // W (phase 2) - write is allowed for save because restore will get killed
2544
   // W2 (phase 1) - Restore
2545
   // W2 (phase 2) - write is allowed
2546
   //
2547
   // actions that occur in phase one are modelled as occurring on the
2548
   // rising edge
2549
   //
2550
   // swaps to the same thread in consecutive cycles not allowed
2551
   /////////////////////////////
2552
       if (swap_local_m_vld) begin
2553
          // save the locals (16-23 in active window)
2554
          for (i = 6'd16; i < 6'd24; i = i + 1) begin
2555
             active_pointer[6:0] = {cwpswap_tid_m[1:0], i[4:0]};
2556
             regfile_pointer[7:0] = {cwpswap_tid_m[1:0], old_lo_cwp_m[2:0], i[2:0]};
2557
             if (swap_local_w & ~kill_restore_w & (cwpswap_tid_m[1:0] == cwpswap_tid_w[1:0]))
2558
               locals[regfile_pointer[7:0]] = {72{1'bx}};
2559
             else
2560
               locals[regfile_pointer[7:0]] = active_window[active_pointer];
2561
          end
2562
       end
2563
       if (swap_even_m_vld) begin
2564
          // save the ins in even window (24-31 in active window)
2565
          for (i = 6'd24; i < 6'd32; i = i + 1) begin
2566
             active_pointer[6:0] = {cwpswap_tid_m[1:0], i[4:0]};
2567
             regfile_pointer[7:0] = {1'b0, cwpswap_tid_m[1:0], old_e_cwp_m[1:0], i[2:0]};
2568
             if (swap_even_w & ~kill_restore_w & (cwpswap_tid_m[1:0] == cwpswap_tid_w[1:0]))
2569
               evens[regfile_pointer[6:0]] = {72{1'bx}};
2570
             else
2571
               evens[regfile_pointer[6:0]] = active_window[active_pointer];
2572
          end
2573
       end
2574
       if (swap_odd_m_vld) begin
2575
          // save the ins in odd window (8-15 in active window)
2576
          for (i = 6'd8; i < 6'd16; i = i + 1) begin
2577
             active_pointer[6:0] = {cwpswap_tid_m[1:0], i[4:0]};
2578
             regfile_pointer[7:0] = {1'b0, cwpswap_tid_m[1:0], old_lo_cwp_m[2:1], i[2:0]};
2579
             if (swap_odd_w & ~kill_restore_w & (cwpswap_tid_m[1:0] == cwpswap_tid_w[1:0]))
2580
               odds[regfile_pointer[6:0]] = {72{1'bx}};
2581
             else
2582
               odds[regfile_pointer[6:0]] = active_window[active_pointer];
2583
          end
2584
       end
2585
       if(~kill_restore_w) begin
2586
          if (swap_local_w) begin
2587
            // restore the locals (16-23 in active window)
2588
            for (i = 6'd16; i < 6'd24; i = i + 1) begin
2589
               active_pointer[6:0] = {cwpswap_tid_w[1:0], i[4:0]};
2590
               regfile_pointer[7:0] = {cwpswap_tid_w[1:0], new_lo_cwp_w[2:0], i[2:0]};
2591
               if (swap_local_m_vld & (cwpswap_tid_m[1:0] == cwpswap_tid_w[1:0])) begin
2592
                 active_window[active_pointer] = {72{1'bx}};
2593
                 locals[regfile_pointer[7:0]] = {72{1'bx}};
2594
               end
2595
               else
2596
                 active_window[active_pointer] = locals[regfile_pointer[7:0]];
2597
            end
2598
         end
2599
         if (swap_even_w) begin
2600
            // restore the ins in even window (24-32 in active window)
2601
            for (i = 6'd24; i < 6'd32; i = i + 1) begin
2602
               active_pointer[6:0] = {cwpswap_tid_w[1:0], i[4:0]};
2603
               regfile_pointer[7:0] = {1'b0, cwpswap_tid_w[1:0], new_e_cwp_w[1:0], i[2:0]};
2604
               if (swap_even_m_vld & (cwpswap_tid_m[1:0] == cwpswap_tid_w[1:0])) begin
2605
                 active_window[active_pointer] = {72{1'bx}};
2606
                 evens[regfile_pointer[6:0]] = {72{1'bx}};
2607
               end
2608
               else
2609
                 active_window[active_pointer] = evens[regfile_pointer[6:0]];
2610
            end
2611
         end
2612
         if (swap_odd_w) begin
2613
            // restore the ins in odd window (8-16 in active window)
2614
            for (i = 6'd8; i < 6'd16; i = i + 1) begin
2615
               active_pointer[6:0] = {cwpswap_tid_w[1:0], i[4:0]};
2616
               regfile_pointer[7:0] = {1'b0, cwpswap_tid_w[1:0], new_lo_cwp_w[2:1], i[2:0]};
2617
               if (swap_odd_m_vld & (cwpswap_tid_m[1:0] == cwpswap_tid_w[1:0])) begin
2618
                 active_window[active_pointer] = {72{1'bx}};
2619
                 odds[regfile_pointer[6:0]]  = {72{1'bx}};
2620
               end
2621
               else
2622
                 active_window[active_pointer] = odds[regfile_pointer[6:0]];
2623
            end
2624
         end
2625
       end
2626
    end // always @ (posedge clk)
2627
 
2628
endmodule // bw_r_irf
2629
 
2630
`endif

powered by: WebSVN 2.1.0

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