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

Subversion Repositories sparc64soc

[/] [sparc64soc/] [trunk/] [T1-CPU/] [ifu/] [sparc_ifu_swl.v] - Blame information for rev 4

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: sparc_ifu_swl.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: sparc_ifu_swl
24
//  Description:
25
//  The switch logic manages the 4 threads.  It schedules the next
26
//  thread to be executed.
27
*/
28
////////////////////////////////////////////////////////////////////////
29
 
30
`include "ifu.h"
31
 
32
module sparc_ifu_swl(/*AUTOARG*/
33
   // Outputs
34
   swl_sscan_thrstate, so, dtu_reset, swl_dec_mulbusy_e,
35
   swl_dec_divbusy_e, swl_dec_fpbusy_e, swl_dec_fp_enable_d,
36
   swl_dec_ibe_e, dtu_fcl_ntr_s, dtu_fcl_running_s,
37
   dtu_fcl_rollback_g, dtu_fcl_retract_d, dtu_fcl_thr_active,
38
   dtu_fcl_nextthr_bf, swl_dcl_thr_d, swl_dcl_thr_w2,
39
   dtu_fdp_thrconf_e,
40
   // Inputs
41
   rclk, se, si, gdbginit_l, arst_l, grst_l, ctu_sscan_tid,
42
   ifq_dtu_thrrdy, ifq_dtu_pred_rdy, ifu_tlu_inst_vld_w,
43
   ifu_tlu_ttype_vld_m, fcl_dtu_hprivmode_d, fcl_dtu_hprivmode_w2,
44
   tlu_ifu_flush_pipe_w, fcl_swl_flush_w, fcl_dtu_sync_intr_d,
45
   fcl_dtu_nuke_thr_w, fcl_dtu_rst_thr_w, fcl_dtu_resum_thr_w,
46
   fcl_dtu_thr_f, tlu_hpstate_ibe, lsu_ifu_ldsta_internal_e,
47
   tlu_ifu_trappc_vld_w1, dec_swl_ll_done_d, dec_swl_br_done_d,
48
   dec_swl_rdsr_sel_thr_d, dec_swl_std_inst_d, dec_swl_sta_inst_e,
49
   wsr_fixed_inst_w, dec_swl_ld_inst_d, dec_swl_mul_inst_d,
50
   dec_swl_div_inst_d, dec_swl_fpop_d, dec_swl_allfp_d,
51
   dec_swl_frf_upper_d, dec_swl_frf_lower_d, dec_swl_wrtfprs_w,
52
   dcl_swl_tcc_done_m, exu_ifu_longop_done_g, exu_ifu_spill_e,
53
   lsu_ifu_ldst_cmplt, lsu_ifu_dc_parity_error_w2, lsu_ifu_stbcnt0,
54
   lsu_ifu_stbcnt1, lsu_ifu_stbcnt2, lsu_ifu_stbcnt3,
55
   lsu_ifu_quad_asi_e, ffu_ifu_fpop_done_w2, ffu_ifu_tid_w2,
56
   ffu_ifu_fst_ce_w, tlu_ifu_trap_tid_w1, tlu_ifu_pstate_pef,
57
   lsu_ifu_ldst_miss_g, fcl_swl_int_activate_i3,
58
   fcl_swl_flush_wake_w, ifq_swl_stallreq, fcl_dtu_stall_bf,
59
   fcl_swl_swout_f, fcl_swl_swcvld_s, fdp_fcl_swc_s2,
60
   fcl_ifq_icmiss_s1, fcl_dtu_inst_vld_e, fcl_dtu_intr_vld_e,
61
   fcl_dtu_inst_vld_d, erb_dtu_ifeterr_d1, dtu_inst_anull_e,
62
   const_cpuid, thr_config_in_m, dec_swl_wrt_tcr_w,
63
   dec_swl_st_inst_d, extra_longlat_compl
64
   );
65
 
66
   input       rclk,
67
               se,
68
               si,
69
               gdbginit_l,
70
               arst_l,
71
               grst_l;
72
 
73
   input [3:0] ctu_sscan_tid;   // guaranteed one-hot by ctu
74
 
75
   input [3:0] ifq_dtu_thrrdy;         // ifq completion signals
76
   input [3:0] ifq_dtu_pred_rdy;     // ifq almost done
77
 
78
   input       ifu_tlu_inst_vld_w,    //
79
                     ifu_tlu_ttype_vld_m;
80
   input       fcl_dtu_hprivmode_d;
81
   input       fcl_dtu_hprivmode_w2;
82
   input       tlu_ifu_flush_pipe_w;  // flush after a trap
83
   input       fcl_swl_flush_w;
84
   input       fcl_dtu_sync_intr_d;   // interrupt
85
   input       fcl_dtu_nuke_thr_w;    // sync suspend
86
   input       fcl_dtu_rst_thr_w;    // 
87
   input       fcl_dtu_resum_thr_w;    // 
88
   input [3:0] fcl_dtu_thr_f;
89
 
90
   input [3:0] tlu_hpstate_ibe;
91
 
92
   input       lsu_ifu_ldsta_internal_e,// sta to local reg
93
                     tlu_ifu_trappc_vld_w1, // trap completion
94
                     dec_swl_ll_done_d,   // rdsr completion
95
               dec_swl_br_done_d,
96
                     dec_swl_rdsr_sel_thr_d,
97
                     dec_swl_std_inst_d,    //
98
                     dec_swl_sta_inst_e,    // state change
99
                     wsr_fixed_inst_w,      // wrspr completion
100
                     dec_swl_ld_inst_d;     // load hit/compl. speculation
101
 
102
   input       dec_swl_mul_inst_d,
103
                     dec_swl_div_inst_d;
104
   input       dec_swl_fpop_d,
105
                     dec_swl_allfp_d;
106
 
107
   input       dec_swl_frf_upper_d,
108
                     dec_swl_frf_lower_d,
109
                     dec_swl_wrtfprs_w;
110
 
111
   input       dcl_swl_tcc_done_m;
112
 
113
   input [3:0] exu_ifu_longop_done_g; // save, restore, div, mul compl.
114
   input       exu_ifu_spill_e;
115
   input [3:0] lsu_ifu_ldst_cmplt;
116
   input       lsu_ifu_dc_parity_error_w2;
117
 
118
   input [3:0] lsu_ifu_stbcnt0,
119
                     lsu_ifu_stbcnt1,
120
                     lsu_ifu_stbcnt2,
121
                     lsu_ifu_stbcnt3;
122
 
123
//   input [3:0] lsu_ifu_stq_busy;
124
   input       lsu_ifu_quad_asi_e;
125
 
126
   input       ffu_ifu_fpop_done_w2;
127
   input [1:0] ffu_ifu_tid_w2;
128
   input       ffu_ifu_fst_ce_w;
129
 
130
   input [1:0] tlu_ifu_trap_tid_w1;
131
 
132
   input [3:0] tlu_ifu_pstate_pef;
133
 
134
   input       lsu_ifu_ldst_miss_g;   // dcache hit or miss
135
 
136
   input [3:0] fcl_swl_int_activate_i3; // wake up thread on interrupt
137
   input       fcl_swl_flush_wake_w;
138
 
139
   // TBD: with the latest changes fcl_dtu_switch_s = dtu_fcl_ntr_s, so 
140
   // this input can be removed.
141
//   input       fcl_dtu_switch_s; // switch out curr, sw in next
142
 
143
   input       ifq_swl_stallreq;
144
 
145
   input       fcl_dtu_stall_bf,
146
               fcl_swl_swout_f,       // curr thread is stalled
147
                     fcl_swl_swcvld_s,
148
               fdp_fcl_swc_s2,        // thread stall condition
149
                     fcl_ifq_icmiss_s1;     // icache miss
150
   input       fcl_dtu_inst_vld_e,
151
               fcl_dtu_intr_vld_e,
152
                     fcl_dtu_inst_vld_d;
153
 
154
   input       erb_dtu_ifeterr_d1;
155
 
156
   input       dtu_inst_anull_e;      // anull delay slot
157
 
158
   input [3:0] const_cpuid;           // use 4 bits to allow future
159
                                      // expansion to 16 cores
160
 
161
   input [2:0] thr_config_in_m;       // write data to thread status reg
162
   input       dec_swl_wrt_tcr_w;     // write signal for thr status reg
163
   input       dec_swl_st_inst_d;
164
 
165
   input [3:0] extra_longlat_compl;   // spare signal, not used
166
 
167
 
168
   output [10:0] swl_sscan_thrstate;
169
   output        so;
170
 
171
   output      dtu_reset;
172
 
173
   output      swl_dec_mulbusy_e,
174
                     swl_dec_divbusy_e,
175
                     swl_dec_fpbusy_e,
176
                     swl_dec_fp_enable_d;
177
 
178
   output      swl_dec_ibe_e;
179
 
180
   // to fcl
181
   output      dtu_fcl_ntr_s,         // next thread ready
182
               dtu_fcl_running_s,
183
                     dtu_fcl_rollback_g,    // rollback on spec
184
                     dtu_fcl_retract_d;     // rollback on hw hazard
185
 
186
   output [3:0] dtu_fcl_thr_active;   // currently active threads
187
 
188
   output [3:0] dtu_fcl_nextthr_bf,   // thread to switch to when ntr=1
189
                            swl_dcl_thr_d,
190
                            swl_dcl_thr_w2;
191
 
192
   // to fdp
193
   output [40:0] dtu_fdp_thrconf_e;   // thread conf for RDSR inst
194
 
195
//----------------------------------------------------------
196
// Declarations
197
//----------------------------------------------------------
198
   // local signals
199
//   wire [3:0]    count_nxt,
200
//                     count;
201
//   wire          proc0;
202
//   wire          start_on_rst;
203
 
204
   wire          ibe_d,
205
                 ibe_e;
206
 
207
   wire [3:0]    completion,
208
                             wm_imiss,
209
                             wm_other,
210
                             spec_ld_d,
211
                             issue_spec_ld,
212
                             ldmiss,
213
                             ldhit_thr,
214
                             spec_ld_g,
215
                             imiss,
216
                             trap,
217
                 ldmiss_non_crit,
218
                 ldmiss_crit,
219
                             trp_no_retr,
220
//                           rb_thr_w,
221
                 rt_st_thr_d,
222
                 rt_st_thr_e,
223
                             schedule,
224
                             int_activate,
225
                             start_thread,
226
                 thaw_thread,
227
                             resum_thread,
228
                             nuke_thread,
229
                             rst_thread;
230
 
231
   wire          rollback_g,
232
                 rb_en_g,
233
                 rollback_g_l,
234
                 rollback_w2;
235
 
236
 
237
   wire          sched_nt;
238
 
239
   wire [3:0]    fixedop_done,
240
                             wsr_done_w3;
241
 
242
   wire          wsr_inst_w2,
243
                 wsr_inst_w3;
244
 
245
   wire          wsr_fixed_qual_w,
246
                 wsr_fixed_w2;
247
 
248
   wire          llinst_done_e;
249
 
250
   wire [3:0]    ll_done_e,
251
                 branch_done_d,
252
                 std_tcc_done_m;
253
 
254
   wire          sta_done_e,
255
                             killed_inst_done_e;
256
   wire [3:0]    killed_uniop_done_e;
257
 
258
   wire          uniop_d,
259
                             uniop_e;
260
 
261
//   wire          no_iftrap_m,
262
//                 no_iftrap_w;
263
 
264
   wire [3:0]    thr_s1,
265
                 thr_s2,
266
                             thr_f,
267
                             thr_d,
268
                             thr_e,
269
                             thr_m,
270
                             thr_w,
271
                 st_thr_w2,
272
                             st_thr_w3;
273
 
274
   wire          flush_pipe_w_nxt,
275
                 flush_all_w,
276
                 flush_pipe_w2,
277
                 flush_done_w,
278
                 fp_flush_done_w2,
279
                 fp_flush_done_w3,
280
                             flush_done_w2;
281
 
282
   wire          rbfor_fst_ce_w;
283
 
284
   wire [3:0]    flush_wake_w2,
285
                 fp_flush_wake_w3,
286
                 halt_thread;
287
 
288
   wire          wrt_spec_w,
289
                 wrt_spec_w2,
290
                 halt_w,
291
                 halt_w2,
292
                             en_spec_d,
293
                             en_spec_m,
294
                             en_spec_g,
295
                             spec_next;
296
 
297
 
298
   wire          ld_inst_e,
299
                             ld_inst_next_e,
300
                 ld_inst_qual_d,
301
                             ld_inst_m,
302
                             ld_inst_unq_w,
303
                             ld_inst_w,
304
                 ld_inst_w2;
305
 
306
   wire          switch_out,
307
                       sw_cond_s,
308
                       swc_d,
309
                       swc_next_d,
310
                       swc_e;
311
 
312
   wire          trp_noretr_d;
313
 
314
   wire [3:0]    all_stall;
315
 
316
   wire [3:0]    rdy,
317
                       sprdy_or_urdy;
318
 
319
   wire          running_s2,
320
                 atr_s;
321
 
322
   wire [4:0]    thr0_state,
323
                             thr1_state,
324
                             thr2_state,
325
                             thr3_state;
326
 
327
   wire          use_spec;
328
 
329
   wire [3:0]    wrt_tcr_w2;
330
 
331
   wire [1:0]    enc_thr_d;
332
 
333
   wire          rd_thract_d,
334
                             rd_thract_e;
335
   wire [51:0]   fmt_thrconf_e,
336
                 thrconf_out_e,
337
                 fmt_thrconf_adj;
338
 
339
   wire          hprivmode_e,
340
                 rdsr_sel_thr_e;
341
 
342
   wire [2:0]    rd_tid_spec_e;
343
 
344
   wire [3:0]    mul_busy_d,
345
                             mul_busy_e,
346
                             div_busy_d,
347
                             div_busy_e,
348
                             fp_busy_d,
349
                             fp_busy_e;
350
 
351
   wire          true_fpbusy_e,
352
                 fpbusy_local_e,
353
                 true_mulbusy_e,
354
                 true_divbusy_e;
355
 
356
   wire          fbusy_nxt_d,
357
                 fbusy_crit_e,
358
                 fbusy_d3,
359
                 fbusy_d0,
360
                 fbusy_d1,
361
                 fbusy_d2,
362
                 dbusy_d3,
363
                 dbusy_d0,
364
                 dbusy_d1,
365
                 dbusy_d2,
366
                 mbusy_d3,
367
                 mbusy_d0,
368
                 mbusy_d1,
369
                 mbusy_d2;
370
 
371
   wire [3:0]    mul_wait,
372
                             mul_wait_nxt,
373
                             div_wait,
374
                             div_wait_nxt,
375
                             fp_wait,
376
                             fp_wait_nxt;
377
 
378
   wire          mul_wait_any,
379
                             div_wait_any,
380
                             fp_wait_any;
381
 
382
   wire [3:0]    mul_wake,
383
                             div_wake,
384
                             fp_wake;
385
 
386
   wire [3:0]    exu_lop_done,
387
                             mul_done,
388
                             div_done,
389
                             fp_done;
390
 
391
   wire [3:0]    retr_thr_wakeup;
392
   wire [3:0]    trap_thrrdy,
393
                             trap_thr;
394
 
395
   wire [3:0]    fp_thr,
396
                             fp_thrrdy;
397
 
398
   wire          same_thr_de,
399
                             same_thr_dg,
400
                 same_thr_fd,
401
                 same_thr_fe,
402
                             same_thr_fm,
403
                             same_thr_fg;
404
 
405
 
406
   wire          st_thisthr_e;
407
 
408
   wire          st_inst_e,
409
                             st_inst_qual_d,
410
                             st_inst_qual_e,
411
                             st_inst_m,
412
                             st_inst_g;
413
 
414
   wire          pipe_st_cnt_ge1,
415
                             pipe_st_cnt_ge2,
416
                             pipe_st_cnt_ge3;
417
 
418
   wire          pipe_st_d,
419
                 pipe_st_e,
420
                             pipe_st_m,
421
                             pipe_st_g;
422
 
423
   wire          all_dst_ge1,
424
                             all_dst_ge2,
425
                             all_dst_ge3,
426
                             all_dst_eq4;
427
 
428
   wire          dst_cnt_ge1,
429
                             dst_cnt_ge2,
430
                             dst_cnt_ge3;
431
 
432
 
433
   wire [3:0]    stbcnt_s,
434
                             stbcnt_d;
435
 
436
   wire [3:0]    stb_stall,
437
                             stb_blocked,
438
                             stb_blocked_d1,
439
                             st_in_pipe,
440
                             stb_retry,
441
                             wm_stbwait,
442
                             stb_wait_nxt;
443
 
444
   wire          switch_store_d,
445
//                           retract_stall_d,
446
                             retract_store_e,
447
                 retract_st_next_d,
448
                             retract_store_d;
449
 
450
   wire          retract_iferr_d,
451
                 iferr_s,
452
                 iferr_d;
453
 
454
   wire          clear_wmo_e;
455
 
456
   wire          sw_st_e,
457
                             sw_st_m,
458
                             sw_st_g,
459
                             sw_st_w2;
460
 
461
   wire          std_inst_e;
462
//                           stq_inst_e,
463
//                           stq_inst_m,
464
//                           stq_inst_w,
465
//                           stq_inst_w2;
466
   wire          std_done_e;
467
   wire          std_done_m;
468
//   wire [3:0]    stq_busy,
469
//                           stq_in_pipe,
470
//                           stq_wait,
471
//                           stq_wait_next,
472
//                           stq_done_thr;
473
 
474
   wire [2:0]    fprs0,
475
                             fprs1,
476
                             fprs2,
477
                             fprs3,
478
                             fprs_d,
479
                             fprs_e,
480
                             fprs_wrt_data,
481
                 thr_config_in_w,
482
                 thr_config_in_w2,
483
                             fprs0_nxt,
484
                             fprs1_nxt,
485
                             fprs2_nxt,
486
                             fprs3_nxt;
487
 
488
   wire [1:0]    new_fprs;
489
 
490
   wire [3:0]    fprs_en_s,
491
                             fpen_vec_s;
492
 
493
   wire          wrt_fprs_w,
494
                 wrt_fprs_w2;
495
 
496
   wire [3:0]    sel_wrt,
497
                             fprs_sel_set,
498
                             fprs_sel_wrt,
499
                             fprs_sel_old;
500
 
501
   wire          fpen_s;
502
 
503
   wire [1:0]    trap_tid_w2;
504
   wire          trappc_vld_w2;
505
 
506
   wire          dtu_reset_l;
507
   wire          sched_reset;
508
 
509
   wire          clk;
510
 
511
   //
512
   // Code Begins Here
513
   //
514
 
515
   assign        clk = rclk;
516
 
517
   // reset buffer
518
   dffrl_async rstff(.din (grst_l),
519
                        .q   (dtu_reset_l),
520
                        .clk (clk), .se(se), .si(), .so(),
521
                        .rst_l (arst_l));
522
 
523
   assign       dtu_reset = ~dtu_reset_l;
524
 
525
 
526
   //---------------------------------------------
527
   // Start off thread on reset using this counter
528
   //---------------------------------------------
529
//   dffr #(4) thrrdy_ctr(.din (count_nxt),
530
//                                  .clk (clk),
531
//                                  .q   (count),
532
//                                  .rst (dtu_reset),
533
//                                  .se (se), .si(), .so());
534
//
535
//   // count_nxt = count + 1, sticky at 8 = 1111
536
//   assign count_nxt[0] = ~count[0] | count[3];
537
//   assign count_nxt[1] = (count[1] ^ count[0]) | count[3];
538
//   assign count_nxt[2] = (count[2] ^ (count[1] & count[0])) | count[3]; 
539
//   assign count_nxt[3] = (count[3] ^ (count[2] & count[1] & count[0])) |
540
//                             count[3]; 
541
//
542
//   assign proc0 = (const_cpuid == 4'b0000) ? 1'b1 : 1'b0;
543
//   assign start_on_rst = (~count[3] & count[2] & count[1] & count[0])
544
//                          & proc0;
545
 
546
//`ifdef IFU_SAT   
547
//   // temporary hack to start threads
548
//   reg [3:0]  auto_start;
549
//   always @ (posedge clk)
550
//     auto_start = 4'b0000;
551
//`endif
552
 
553
   //-----------------
554
   // completion logic
555
   //-----------------
556
   sparc_ifu_thrcmpl compl(
557
                           .reset       (dtu_reset),
558
                                             /*AUTOINST*/
559
                           // Outputs
560
                           .completion  (completion[3:0]),
561
                           .wm_imiss    (wm_imiss[3:0]),
562
                           .wm_other    (wm_other[3:0]),
563
                           // Inputs
564
                           .clk         (clk),
565
                           .se          (se),
566
                           .si          (si),
567
                           .fcl_ifq_icmiss_s1(fcl_ifq_icmiss_s1),
568
                           .erb_dtu_ifeterr_d1(erb_dtu_ifeterr_d1),
569
                           .sw_cond_s   (sw_cond_s),
570
                           .en_spec_g   (en_spec_g),
571
                           .atr_s       (atr_s),
572
                           .dtu_fcl_thr_active(dtu_fcl_thr_active[3:0]),
573
                           .ifq_dtu_thrrdy(ifq_dtu_thrrdy[3:0]),
574
                           .ifq_dtu_pred_rdy(ifq_dtu_pred_rdy[3:0]),
575
                           .exu_lop_done(exu_lop_done[3:0]),
576
                           .branch_done_d(branch_done_d[3:0]),
577
                           .fixedop_done(fixedop_done[3:0]),
578
                           .ldmiss      (ldmiss[3:0]),
579
                           .spec_ld_d   (spec_ld_d[3:0]),
580
                           .trap        (trap[3:0]),
581
                           .retr_thr_wakeup(retr_thr_wakeup[3:0]),
582
                           .flush_wake_w2(flush_wake_w2[3:0]),
583
                           .ldhit_thr   (ldhit_thr[3:0]),
584
                           .spec_ld_g   (spec_ld_g[3:0]),
585
                           .clear_wmo_e (clear_wmo_e),
586
                           .wm_stbwait  (wm_stbwait[3:0]),
587
                           .stb_retry   (stb_retry[3:0]),
588
                           .rst_thread  (rst_thread[3:0]),
589
                           .trap_thrrdy (trap_thrrdy[3:0]),
590
                           .thr_s2      (thr_s2[3:0]),
591
                           .thr_e       (thr_e[3:0]),
592
                           .thr_s1      (thr_s1[3:0]),
593
                           .fp_thrrdy   (fp_thrrdy[3:0]),
594
                           .lsu_ifu_ldst_cmplt(lsu_ifu_ldst_cmplt[3:0]),
595
                           .sta_done_e  (sta_done_e),
596
                           .killed_inst_done_e(killed_inst_done_e));
597
 
598
   //------------
599
   // Thread Pipe
600
   //------------
601
   assign thr_f = fcl_dtu_thr_f;
602
 
603
//   assign thr_dec_f[0] = thr_f[0] | rst_tri_en;
604
//   assign thr_dec_f[3:1] = thr_f[3:1] & {3{~rst_tri_en}};
605
 
606
//   assign thr_dec_d[0] = thr_d[0] | rst_tri_en;
607
//   assign thr_dec_d[3:1] = thr_d[3:1] & {3{~rst_tri_en}};
608
 
609
 
610
   dff_s #(4) thrd_reg(.din  (thr_f[3:0]),
611
                   .clk  (clk),
612
                   .q    (thr_d[3:0]),
613
                   .se   (se), .si(), .so());
614
 
615
   assign     swl_dcl_thr_d = thr_d;
616
 
617
   dff_s #(4) thre_reg(.din  (thr_d),
618
                   .clk  (clk),
619
                   .q    (thr_e),
620
                   .se   (se), .si(), .so());
621
 
622
   dff_s #(4) thrm_reg(.din  (thr_e),
623
                   .clk  (clk),
624
                   .q    (thr_m),
625
                   .se   (se), .si(), .so());
626
   dff_s #(4) thrw_reg(.din  (thr_m),
627
                   .clk  (clk),
628
                   .q    (thr_w),
629
                   .se   (se), .si(), .so());
630
 
631
   dff_s #(4) thrw2_reg(.din  (thr_w),
632
                    .clk  (clk),
633
                    .q    (st_thr_w2),
634
                    .se   (se), .si(), .so());
635
 
636
   dff_s #(4) thrw3_reg(.din  (st_thr_w2),
637
                    .clk  (clk),
638
                    .q    (st_thr_w3),
639
                    .se   (se), .si(), .so());
640
 
641
   assign     swl_dcl_thr_w2 = st_thr_w2;
642
 
643
   // send ibe of curr thread to dec
644
   assign ibe_d = (thr_d[0] & tlu_hpstate_ibe[0] |
645
                   thr_d[1] & tlu_hpstate_ibe[1] |
646
                   thr_d[2] & tlu_hpstate_ibe[2] |
647
                   thr_d[3] & tlu_hpstate_ibe[3]);
648
 
649
   dff_s #(1) ibee_ff(.din (ibe_d),
650
                    .q   (ibe_e),
651
                    .clk (clk), .se(se), .si(), .so());
652
   assign swl_dec_ibe_e = ibe_e;
653
 
654
//----------------------------------------------------------------------
655
// Track Thread Execution
656
//----------------------------------------------------------------------
657
 
658
   // track instructions
659
   dff_s #(1) lle_ff(.din (dec_swl_ll_done_d),
660
                   .q   (llinst_done_e),
661
                   .clk (clk), .se (se), .si(), .so());
662
 
663
   assign ll_done_e = thr_e & {4{llinst_done_e & fcl_dtu_inst_vld_e &
664
                                 ~exu_ifu_spill_e}};
665
   assign std_tcc_done_m = thr_m & {4{dcl_swl_tcc_done_m | std_done_m}};
666
 
667
   assign wsr_fixed_qual_w  = wsr_fixed_inst_w & ifu_tlu_inst_vld_w &
668
                              ~fcl_swl_flush_w;
669
   dff_s #(1) wsrw2_ff(.din (wsr_fixed_qual_w),
670
                     .q   (wsr_fixed_w2),
671
                     .clk (clk), .se(se), .si(), .so());
672
 
673
   assign wsr_inst_w2  = wsr_fixed_w2 & ~flush_pipe_w2;
674
 
675
   // delay one cycle to allow tlu to finish
676
   dff_s #(1) wsw3_ff(.din (wsr_inst_w2),
677
                    .q   (wsr_inst_w3),
678
                    .clk (clk), .se(se), .si(), .so());
679
 
680
   assign wsr_done_w3 = {4{wsr_inst_w3}} & st_thr_w3;
681
 
682
   assign fixedop_done = (ll_done_e | wsr_done_w3 | std_tcc_done_m |
683
                                wrt_tcr_w2 | extra_longlat_compl);
684
 
685
   assign branch_done_d = thr_d & {4{dec_swl_br_done_d & fcl_dtu_inst_vld_d}};
686
 
687
   assign sta_done_e = dec_swl_sta_inst_e & fcl_dtu_inst_vld_e &
688
                       ~lsu_ifu_ldsta_internal_e;
689
   assign ld_inst_qual_d = dec_swl_ld_inst_d & fcl_dtu_inst_vld_d &
690
                           ~iferr_d;
691
   dff_s #(1) lde_ff(.din  (ld_inst_qual_d),
692
                               .clk  (clk),
693
                               .q    (ld_inst_e),
694
                               .se   (se), .si(), .so());
695
   assign ld_inst_next_e = ld_inst_e;
696
//                         & ~dtu_inst_anull_e &    
697
//                           ~(lsu_ifu_ldsta_internal_e & 
698
//                             ifu_lsu_alt_space_e &
699
//                             fcl_dtu_inst_vld_e);
700
 
701
//   assign ld_inst_internal_e = ~dtu_inst_anull_e & ld_inst_e &
702
//                               (fcl_dtu_inst_vld_e & 
703
//                                lsu_ifu_ldsta_internal_e & 
704
//                                ifu_lsu_alt_space_e);
705
 
706
   dff_s #(1) ldm_ff(.din  (ld_inst_next_e),
707
                               .clk  (clk),
708
                               .q    (ld_inst_m),
709
                               .se   (se), .si(), .so());
710
   dff_s #(1) ldw_ff(.din  (ld_inst_m),
711
                               .clk  (clk),
712
                               .q    (ld_inst_unq_w),
713
                               .se   (se), .si(), .so());
714
   assign ld_inst_w = ifu_tlu_inst_vld_w & ld_inst_unq_w;
715
   dff_s #(1) ldw2_ff(.din  (ld_inst_w),
716
                               .clk  (clk),
717
                               .q    (ld_inst_w2),
718
                               .se   (se), .si(), .so());
719
 
720
   // track instruction status
721
   dff_s #(1) swcd_ff(.din  (sw_cond_s),
722
                                .clk  (clk),
723
                                .q    (swc_d),
724
                                .se   (se), .si(), .so());
725
 
726
   assign swc_next_d = (swc_d & ~dec_swl_br_done_d);
727
//                                         | fcl_dtu_sync_intr_d;
728
 
729
   dff_s #(1) swce_ff(.din  (swc_next_d),
730
                                .clk  (clk),
731
                                .q    (swc_e),
732
                                .se   (se), .si(), .so());
733
 
734
//bug6838,bug6989 - interrupt issued in annulled delay slot resets wm_other mask in e-stage; this
735
//                  reset causes switch logic to lose a long latency op(div) which set the wm_other mask
736
//                  in s-stage. Note that the div is issued to FPU. the ifu re-issues the interrupt - 
737
//                  which results in flush. this kills the long latency op and div is lost
738
//
739
//                  fix is to detect interrupt in anulled delay slot followed by long latency op and
740
//                  not reset the wm_other mask.
741
//
742
//       10/07/04 - fix changed to delay setting of wm_other mask from d-cycle to e-cycle. hence
743
//                  removing the kill in killed_inst_done_e
744
//
745
//   assign killed_inst_done_e = (fcl_dtu_inst_vld_e  & swc_e | //sw inst
746
//                                fcl_dtu_intr_vld_e) &  // any intr
747
//                                 dtu_inst_anull_e;
748
 
749
   assign killed_inst_done_e = fcl_dtu_inst_vld_e  & swc_e & //sw inst
750
                                 dtu_inst_anull_e;
751
 
752
   // a uniop is something that stalls all threads (looks like a uni
753
   // threaded machine)
754
   assign uniop_d = (dec_swl_allfp_d | //& swl_dec_fp_enable_d  
755
                     dec_swl_mul_inst_d | dec_swl_div_inst_d) &
756
                      fcl_dtu_inst_vld_d;
757
   dff_s #(1) uniop_ff(.din  (uniop_d),
758
                                 .clk  (clk),
759
                                 .q    (uniop_e),
760
                                 .se   (se), .si(), .so());
761
   assign killed_uniop_done_e = thr_e & {4{dtu_inst_anull_e & uniop_e &
762
                                           fcl_dtu_inst_vld_e |
763
                                           clear_wmo_e}};
764
 
765
//   assign sched_nt = fcl_dtu_switch_s & ~fcl_dtu_stall_bf;
766
   assign sched_nt = dtu_fcl_ntr_s & ~(fcl_dtu_stall_bf | ifq_swl_stallreq);
767
   assign schedule = dtu_fcl_nextthr_bf & {4{sched_nt}};
768
 
769
   // speculate load hit if it is a load instruction
770
   // FP loads are not speculated on 
771
   assign spec_ld_d = thr_d & {4{ld_inst_qual_d & en_spec_d}};
772
   assign issue_spec_ld = thr_d & {4{ld_inst_qual_d & en_spec_d}} &
773
                          ~wm_imiss & ~wm_stbwait;
774
 
775
//   assign issue_spec_ld = thr_d & {4{dec_swl_ld_inst_d & en_spec_d & 
776
//                                     ~fcl_ifq_icmiss_s1}} & ~wm_imiss;
777
 
778
   assign spec_ld_g = (thr_w & {4{ld_inst_w & en_spec_g}});
779
 
780
   // actual load hit signal and load miss stall
781
//   assign rollback_g = en_spec_g & ld_inst_w & lsu_ifu_ldst_miss_g;
782
   // expand to gates:
783
   assign rb_en_g = en_spec_g & ld_inst_w;
784
   assign rollback_g_l = ~(lsu_ifu_ldst_miss_g & rb_en_g);
785
//   bw_u1_nand2_7x UZsize_rbgen(.a (lsu_ifu_ldst_miss_g),
786
//                               .b (rb_en_g),
787
//                               .z (rollback_g_l));
788
   assign rollback_g = ~rollback_g_l;
789
//   bw_u1_invh_25x UZsize_rbbuf(.a (rollback_g_l),
790
//                               .z (rollback_g));
791
   assign dtu_fcl_rollback_g = rollback_g;
792
 
793
   // delay restart of ldhit when en_spec=0 by 1 more cycle?
794
 
795
// assign rb_thr_w = thr_w & {4{en_spec_g & ld_inst_w & lsu_ifu_ldst_miss_g}};
796
// assign spec_ldmiss = rb_thr_w; // to thrcmpl
797
 
798
   assign ldhit_thr = (thr_w & {4{ld_inst_w & ~lsu_ifu_ldst_miss_g}} |
799
                       thr_e & {4{ld_inst_e & dtu_inst_anull_e}});
800
   assign ldmiss_crit = thr_w & {4{ld_inst_w & lsu_ifu_ldst_miss_g}};
801
   assign ldmiss_non_crit = st_thr_w2 & {4{lsu_ifu_dc_parity_error_w2}};
802
                            // | thr_e & {4{ld_inst_internal_e}} 
803
 
804
   assign ldmiss = ldmiss_crit | ldmiss_non_crit;
805
 
806
   assign rt_st_thr_d = thr_d & {4{retract_store_d}};
807
   assign rt_st_thr_e = thr_e & {4{retract_store_e}};
808
 
809
   dff_s #(1) rbw2_ff(.din (rollback_g),
810
                    .q   (rollback_w2),
811
                    .clk (clk), .se(se), .si(), .so());
812
 
813
   // traps and interrupts
814
   dff_s #(1) ld_trp_reg(.din (tlu_ifu_trappc_vld_w1),
815
                       .q   (trappc_vld_w2),
816
                       .clk (clk), .se(se), .si(), .so());
817
 
818
   dff_s #(2) trp_tid_reg(.din (tlu_ifu_trap_tid_w1[1:0]),
819
                        .q   (trap_tid_w2[1:0]),
820
                        .clk (clk), .se(se), .si(), .so());
821
 
822
   assign trap_thr[0] = ~trap_tid_w2[1] & ~trap_tid_w2[0];
823
   assign trap_thr[1] = ~trap_tid_w2[1] &  trap_tid_w2[0];
824
   assign trap_thr[2] =  trap_tid_w2[1] & ~trap_tid_w2[0];
825
   assign trap_thr[3] =  trap_tid_w2[1] &  trap_tid_w2[0];
826
 
827
   assign trap_thrrdy = trap_thr & {4{trappc_vld_w2}};
828
 
829
   // fst processed directly in swl
830
   assign rbfor_fst_ce_w = ifu_tlu_inst_vld_w & ~tlu_ifu_flush_pipe_w &
831
                           ffu_ifu_fst_ce_w & ~fcl_swl_flush_w;
832
 
833
//   dff #(1) fstce_ff(.din (rbfor_fst_ce_w),
834
//                     .q   (rbfor_fst_ce_w2),
835
//                     .clk (clk), .se(se), .si(), .so());
836
 
837
   assign flush_all_w = tlu_ifu_flush_pipe_w | fcl_swl_flush_w;
838
//   assign flush_pipe_w_nxt = tlu_ifu_flush_pipe_w & ~fcl_swl_flush_w;
839
   assign flush_pipe_w_nxt = tlu_ifu_flush_pipe_w &
840
                             ~fcl_swl_flush_wake_w;
841
 
842
   dff_s #(1) flpw2_ff(.din (flush_pipe_w_nxt),
843
                     .q   (flush_pipe_w2),
844
                     .clk (clk), .se(se), .si(), .so());
845
 
846
//   assign no_iftrap_m = ~ifu_tlu_ttype_vld_m;
847
//   dff #(1) trpw_ff(.din (no_iftrap_m),
848
//                    .q   (no_iftrap_w),
849
//                    .clk (clk), .se(se), .si(), .so());
850
 
851
//bug6838,bug6989 - change setting of trap for interrupt from d-cycle to e-cycle
852
//                  remove  thr_d & {4{fcl_dtu_sync_intr_d & ~iferr_d}} & ~rt_st_thr_e |
853
 
854
//   assign trap =  thr_w & {4{flush_all_w}} |
855
   assign trap =  st_thr_w2 & {4{flush_pipe_w2}} |
856
                  thr_w & {4{fcl_swl_flush_w}} |
857
                        thr_e & {4{fcl_dtu_intr_vld_e & ~dtu_inst_anull_e}} |
858
                        thr_m & {4{ifu_tlu_ttype_vld_m}};
859
 
860
   assign trp_no_retr = st_thr_w2 & {4{flush_pipe_w2 |
861
                                       lsu_ifu_dc_parity_error_w2 &
862
                                       ld_inst_w2    |
863
                                       rollback_w2}}  |
864
                              trap_thr & {4{trappc_vld_w2}} |
865
                        fp_flush_wake_w3 |
866
                        thr_w & {4{fcl_swl_flush_w}};
867
//                             thr_m    & {4{ifu_tlu_ttype_vld_m}};
868
 
869
   assign trp_noretr_d = (thr_d[0] & trp_no_retr[0] |
870
                          thr_d[1] & trp_no_retr[1] |
871
                          thr_d[2] & trp_no_retr[2] |
872
                          thr_d[3] & trp_no_retr[3]);
873
 
874
//   assign flush_done_w = fcl_swl_flush_w & ~fcl_swl_flush_wait_w;
875
   assign flush_done_w = fcl_swl_flush_wake_w;
876
   dff_s #(1) flsh_ff(.din (flush_done_w),
877
                                .q   (flush_done_w2),
878
                                .clk (clk), .se(se), .si(), .so());
879
   assign flush_wake_w2 = {4{flush_done_w2}} & st_thr_w2 | fp_flush_wake_w3;
880
 
881
   // delay FP wakeup by one extra cycle to allow time for IRF CE
882
   // to be corrected.
883
   dff_s #(1) fpflsh_ff(.din (rbfor_fst_ce_w),
884
                                  .q   (fp_flush_done_w2),
885
                                  .clk (clk), .se(se), .si(), .so());
886
 
887
   dff_s #(1) fpflw_ff(.din (fp_flush_done_w2),
888
                                 .q   (fp_flush_done_w3),
889
                                 .clk (clk), .se(se), .si(), .so());
890
   assign fp_flush_wake_w3 = st_thr_w3 & {4{fp_flush_done_w3}};
891
 
892
   // store buffer full
893
//   assign stbfull_on_curr_thr = stb_stall & thr_f;
894
//   assign stbfull_thisthr =  stbfull_on_curr_thr[0] |
895
//                                 stbfull_on_curr_thr[1] |
896
//                                 stbfull_on_curr_thr[2] |
897
//                                 stbfull_on_curr_thr[3];
898
 
899
//   assign stbfull_nextthr = ((stb_stall & dtu_fcl_nextthr_bf)
900
//                                             == 4'b0) ?
901
//                                              1'b0 : 1'b1;
902
 
903
   // imiss stall condition
904
   assign thr_s1 = thr_d;
905
   assign imiss = (thr_s1 & {4{fcl_ifq_icmiss_s1}}) |
906
                          (thr_e & {4{erb_dtu_ifeterr_d1}});  //
907
 
908
   // All Stall conditions
909
   assign all_stall = imiss | ldmiss_non_crit | trap | stb_stall |
910
                      ldmiss_crit;
911
 
912
   // TBD: move to ifu -- done
913
//   assign ext_stallreq = ifq_dtu_stallreq | lsu_ifu_stallreq | 
914
//                         ffu_ifu_stallreq;  
915
                         // | other stall reqs
916
//   assign cpu_fcl_stallreq = ext_stallreq;
917
 
918
   // thread start and stop
919
//   assign switch_out = fcl_dtu_switch_s | fcl_dtu_stall_bf | fcl_swl_swout_f;
920
   assign switch_out = dtu_fcl_ntr_s | fcl_dtu_stall_bf | fcl_swl_swout_f |
921
                       ifq_swl_stallreq;
922
 
923
   // general stall condition
924
//   assign cpu_fcl_stallreq = ~dtu_fcl_ntr_s & (stbfull_thisthr) |
925
//                             dtu_fcl_ntr_s & (stbfull_nextthr) |
926
//                                 ext_stallreq;
927
 
928
   // ldmiss (i.e rollback) and flush_pipe are taken care of in FCL
929
   assign sw_cond_s = fdp_fcl_swc_s2 & fcl_swl_swcvld_s & ~iferr_s;
930
 
931
   // thread reset and other interrupts
932
   // added flop for timing reasons
933
 
934
//   assign async_rst_i3 = rst_thread & ~dtu_fcl_thr_active;
935
//   assign rst_thread   = rstthr_i3 & {4{rstint_i3}};
936
  // assign nuke_thread  = (rstthr_i3 & {4{nukeint_i3}} & 
937
//                                          ~dtu_fcl_thr_active) |   // if not active nuke 
938
                                                                     // immediately
939
//                                           ({4{fcl_dtu_nuke_thr_ms}} & thr_m);
940
                                                   // else wait for signal
941
 
942
   assign resum_thread = ({4{fcl_dtu_resum_thr_w}} & thr_w);
943
   assign nuke_thread = ({4{fcl_dtu_nuke_thr_w}} & thr_w);
944
   assign rst_thread = ({4{fcl_dtu_rst_thr_w}} & thr_w);
945
 
946
   assign int_activate = fcl_swl_int_activate_i3 & ~wm_imiss;
947
 
948
//`ifdef IFU_SAT   
949
//   assign start_thread = {3'b0, start_on_rst} | auto_start | 
950
//                         resum_thread & (~wm_imiss | ifq_dtu_thrrdy);
951
//`else
952
   assign start_thread = resum_thread & (~wm_imiss | ifq_dtu_thrrdy) &
953
                                          (~wm_stbwait | stb_retry);
954
   assign thaw_thread = resum_thread & (wm_imiss & ~ifq_dtu_thrrdy |
955
                                        wm_stbwait & ~stb_retry);
956
 
957
//`endif
958
 
959
 
960
//----------------------------------------------------------------------
961
// Thread FSM
962
//----------------------------------------------------------------------   
963
   sparc_ifu_thrfsm  thrfsm0(
964
                             // Outputs
965
`ifdef FPGA_SYN
966
 
967
                             .so        (/*so*/),
968
`else
969
                             .so        (so),
970
`endif
971
                             .thr_state (thr0_state[4:0]),
972
                             // Inputs
973
                             .completion(completion[0]),
974
                             .schedule  (schedule[0]),
975
                             .spec_ld   (issue_spec_ld[0]),
976
                             .ldhit     (ldhit_thr[0]),
977
                             .switch_out(switch_out),
978
 
979
                             .stall     (all_stall[0]),
980
                             .sw_cond   (sw_cond_s),
981
 
982
                             .int_activate(int_activate[0]),
983
                             .start_thread(start_thread[0]),
984
                             .thaw_thread(thaw_thread[0]),
985
                             .nuke_thread (nuke_thread[0]),
986
                             .rst_thread(rst_thread[0]),
987
 
988
                             .halt_thread (halt_thread[0]),
989
 
990
                             .clk       (clk),
991
                             .se        (se),
992
                             .si        (si),
993
                             .reset     (dtu_reset));
994
 
995
   sparc_ifu_thrfsm  thrfsm1(
996
                             // Outputs
997
`ifdef FPGA_SYN
998
 
999
                             .so        (/*so*/),
1000
`else
1001
                             .so        (so),
1002
`endif
1003
                             .thr_state (thr1_state[4:0]),
1004
                             // Inputs
1005
                             .completion(completion[1]),
1006
                             .schedule  (schedule[1]),
1007
                             .spec_ld   (issue_spec_ld[1]),
1008
                             .ldhit     (ldhit_thr[1]),
1009
                             .switch_out(switch_out),
1010
 
1011
                             .stall     (all_stall[1]),
1012
                             .sw_cond   (sw_cond_s),
1013
 
1014
                             .int_activate(int_activate[1]),
1015
                             .start_thread(start_thread[1]),
1016
                             .thaw_thread(thaw_thread[1]),
1017
                             .nuke_thread (nuke_thread[1]),
1018
                             .rst_thread(rst_thread[1]),
1019
 
1020
                             .halt_thread (halt_thread[1]),
1021
 
1022
                             .clk       (clk),
1023
                             .se        (se),
1024
                             .si        (si),
1025
                             .reset     (dtu_reset));
1026
 
1027
   sparc_ifu_thrfsm  thrfsm2(
1028
                             // Outputs
1029
`ifdef FPGA_SYN
1030
 
1031
                             .so        (/*so*/),
1032
`else
1033
                             .so        (so),
1034
`endif
1035
                             .thr_state (thr2_state[4:0]),
1036
                             // Inputs
1037
                             .completion(completion[2]),
1038
                             .schedule  (schedule[2]),
1039
                             .spec_ld   (issue_spec_ld[2]),
1040
                             .ldhit     (ldhit_thr[2]),
1041
                             .switch_out(switch_out),
1042
 
1043
                             .stall     (all_stall[2]),
1044
                             .sw_cond   (sw_cond_s),
1045
 
1046
                             .int_activate(int_activate[2]),
1047
                             .start_thread(start_thread[2]),
1048
                             .thaw_thread(thaw_thread[2]),
1049
                             .nuke_thread (nuke_thread[2]),
1050
                             .rst_thread(rst_thread[2]),
1051
 
1052
                             .halt_thread (halt_thread[2]),
1053
 
1054
                             .clk       (clk),
1055
                             .se        (se),
1056
                             .si        (si),
1057
                             .reset     (dtu_reset));
1058
 
1059
   sparc_ifu_thrfsm  thrfsm3(
1060
                             // Outputs
1061
`ifdef FPGA_SYN
1062
 
1063
                             .so        (/*so*/),
1064
`else
1065
                             .so        (so),
1066
`endif
1067
                             .thr_state (thr3_state[4:0]),
1068
                             // Inputs
1069
                             .completion(completion[3]),
1070
                             .schedule  (schedule[3]),
1071
                             .spec_ld   (issue_spec_ld[3]),
1072
                             .ldhit     (ldhit_thr[3]),
1073
                             .switch_out(switch_out),
1074
 
1075
                             .stall     (all_stall[3]),
1076
                             .sw_cond   (sw_cond_s),
1077
 
1078
                             .int_activate(int_activate[3]),
1079
                             .start_thread(start_thread[3]),
1080
                             .thaw_thread(thaw_thread[3]),
1081
                             .nuke_thread (nuke_thread[3]),
1082
                             .rst_thread(rst_thread[3]),
1083
 
1084
                             .halt_thread (halt_thread[3]),
1085
 
1086
                             .clk       (clk),
1087
                             .se        (se),
1088
                             .si        (si),
1089
                             .reset     (dtu_reset));
1090
 
1091
//----------------------------------------------------------------------
1092
// Schedule Next Thread
1093
//----------------------------------------------------------------------
1094
   // rdy bit from thrfsm
1095
   assign dtu_fcl_thr_active[0] = thr0_state[`TCR_ACTIVE];
1096
   assign dtu_fcl_thr_active[1] = thr1_state[`TCR_ACTIVE];
1097
   assign dtu_fcl_thr_active[2] = thr2_state[`TCR_ACTIVE];
1098
   assign dtu_fcl_thr_active[3] = thr3_state[`TCR_ACTIVE];
1099
 
1100
   assign rdy[0] = thr0_state[`TCR_URDY];
1101
   assign rdy[1] = thr1_state[`TCR_URDY];
1102
   assign rdy[2] = thr2_state[`TCR_URDY];
1103
   assign rdy[3] = thr3_state[`TCR_URDY];
1104
 
1105
   assign sprdy_or_urdy[0] = thr0_state[`TCR_READY];
1106
   assign sprdy_or_urdy[1] = thr1_state[`TCR_READY];
1107
   assign sprdy_or_urdy[2] = thr2_state[`TCR_READY];
1108
   assign sprdy_or_urdy[3] = thr3_state[`TCR_READY];
1109
 
1110
   assign running_s2 = (thr0_state[`TCR_RUNNING] |
1111
                                          thr1_state[`TCR_RUNNING] |
1112
                                          thr2_state[`TCR_RUNNING] |
1113
                                          thr3_state[`TCR_RUNNING]);
1114
 
1115
   assign dtu_fcl_running_s = running_s2;
1116
 
1117
   assign thr_s2 =  {thr3_state[`TCR_RUNNING],
1118
                                       thr2_state[`TCR_RUNNING],
1119
                                       thr1_state[`TCR_RUNNING],
1120
                                       thr0_state[`TCR_RUNNING]};
1121
 
1122
   // Next Thread Ready
1123
   assign dtu_fcl_ntr_s = (sprdy_or_urdy[0] | sprdy_or_urdy[1] |
1124
                                                   sprdy_or_urdy[2] | sprdy_or_urdy[3]);
1125
 
1126
   // Any thread ready
1127
   assign atr_s = dtu_fcl_ntr_s | running_s2;
1128
 
1129
   // decide which scheduler to use
1130
   // timing note: see if use_spec can be generated in previous cycle
1131
   assign use_spec = ~(rdy[3] | rdy[2] | rdy[1] | rdy[0]);
1132
 
1133
   assign sched_reset = dtu_reset | ~gdbginit_l;
1134
   // schedule ready threads
1135
   sparc_ifu_lru4 thr_sched(// Outputs
1136
                                              .grant_vec        (dtu_fcl_nextthr_bf[3:0]),
1137
                                              .so               (so),
1138
                                              // Inputs
1139
                                              .clk      (clk),
1140
                                              .reset    (sched_reset),
1141
                                              .se               (se),
1142
                                              .si               (si),
1143
                                              .recent_vec       (thr_e[3:0]),
1144
                                              .load_recent(fcl_dtu_inst_vld_e),
1145
                                              .req_vec  (rdy[3:0]),
1146
                            .spec_vec (sprdy_or_urdy[3:0]),
1147
                            .use_spec (use_spec));
1148
 
1149
//----------------------------------------------------------------------
1150
// Thread Status (Config) Register
1151
//----------------------------------------------------------------------
1152
   // Read thread config
1153
   assign enc_thr_d[1] = thr_d[3] | thr_d[2];
1154
   assign enc_thr_d[0] = thr_d[3] | thr_d[1];
1155
 
1156
   assign rd_thract_d = (thr0_state[0] & thr_d[0] |
1157
                         thr1_state[0] & thr_d[1] |
1158
                         thr2_state[0] & thr_d[2] |
1159
                         thr3_state[0] & thr_d[3]);
1160
 
1161
   dff_s #(1) rdthr_ff(.din (rd_thract_d),
1162
                                  .clk (clk),
1163
                                  .q   (rd_thract_e),
1164
                                  .se   (se), .si(), .so());
1165
 
1166
   dff_s #(3) rdcf_reg(.din ({enc_thr_d, en_spec_d}),
1167
                                 .clk (clk),
1168
                                 .q   (rd_tid_spec_e),
1169
                                 .se   (se), .si(), .so());
1170
 
1171
   dff_s #(1) hpe_ff(.din (fcl_dtu_hprivmode_d),
1172
                               .clk (clk),
1173
                               .q   (hprivmode_e),
1174
                               .se   (se), .si(), .so());
1175
   dff_s #(1) rdthre_ff(.din (dec_swl_rdsr_sel_thr_d),
1176
                                  .clk (clk),
1177
                                  .q   (rdsr_sel_thr_e),
1178
                                  .se   (se), .si(), .so());
1179
 
1180
   // TBD: read out all thread state, not just the current thread
1181
   //      Done 9/26/02
1182
   assign fmt_thrconf_e = {wm_stbwait,
1183
                           wm_other,
1184
                           wm_imiss,           // 51:40 - wait mask
1185
                           4'b0,               // 39:36 - rsvd
1186
                           thr0_state,
1187
                           thr1_state,
1188
                           thr2_state,
1189
                           thr3_state,         // 35:16 - thr state
1190
                                             {2'b0},             // 15:14 - rsvd
1191
                                             const_cpuid,        // 13:10 - 4b cpu id
1192
                                             rd_tid_spec_e[2:1], // 9:8 - 2b tid
1193
                                             {5'b0},             // 7:3 - rsvd
1194
                                             rd_tid_spec_e[0],   // 2 - en spec
1195
                                             {1'b0},             // 1 - QOS/rsvd
1196
                                             rd_thract_e};       // 0 - active
1197
 
1198
//`ifdef SPARC_HPV_EN
1199
   assign fmt_thrconf_adj[51:1] = fmt_thrconf_e[51:1] & {51{hprivmode_e}};
1200
   assign fmt_thrconf_adj[0] = fmt_thrconf_e[0];
1201
//`else
1202
//   assign fmt_thrconf_adj[51:0] = fmt_thrconf_e[51:0];
1203
//`endif
1204
 
1205
//   assign thrconf_out_e[51:16] = (fmt_thrconf_e[51:16] & 
1206
//                                      {36{hprivmode_e}});
1207
 
1208
//   mux2ds #(52) rdsr_mxe(.dout (thrconf_out_e[51:0]),
1209
//                                   .in0  ({49'b0, fprs_e}),
1210
//                                   .in1  (fmt_thrconf_adj[51:0]),
1211
//                                   .sel0 (~rdsr_sel_thr_e),
1212
//                                   .sel1 (rdsr_sel_thr_e));
1213
   assign thrconf_out_e[51:0] = rdsr_sel_thr_e ? fmt_thrconf_adj[51:0] :
1214
                                                 {49'b0, fprs_e};
1215
 
1216
   // leave out the zeros before sending to fdp
1217
   assign dtu_fdp_thrconf_e = {thrconf_out_e[51:40], // 40:29
1218
                               thrconf_out_e[35:16], // 28:9
1219
                               thrconf_out_e[13:8],  // 8:3
1220
                               thrconf_out_e[2:0]};
1221
 
1222
   // shadow scan outputs
1223
   mux4ds #(11) sscan_mx(.dout (swl_sscan_thrstate[10:0]),
1224
                         .in0  ({thr0_state[4:0],
1225
                                 wm_imiss[0],
1226
                                 wm_other[0],
1227
                                 wm_stbwait[0],
1228
                                 mul_busy_e[0],
1229
                                 div_busy_e[0],
1230
                                 fp_busy_e[0]}),
1231
                         .in1  ({thr1_state[4:0],
1232
                                 wm_imiss[1],
1233
                                 wm_other[1],
1234
                                 wm_stbwait[1],
1235
                                 mul_busy_e[1],
1236
                                 div_busy_e[1],
1237
                                 fp_busy_e[1]}),
1238
                         .in2  ({thr2_state[4:0],
1239
                                 wm_imiss[2],
1240
                                 wm_other[2],
1241
                                 wm_stbwait[2],
1242
                                 mul_busy_e[2],
1243
                                 div_busy_e[2],
1244
                                 fp_busy_e[2]}),
1245
                         .in3  ({thr3_state[4:0],
1246
                                 wm_imiss[3],
1247
                                 wm_other[3],
1248
                                 wm_stbwait[3],
1249
                                 mul_busy_e[3],
1250
                                 div_busy_e[3],
1251
                                 fp_busy_e[3]}),
1252
                         .sel0 (ctu_sscan_tid[0]),
1253
                         .sel1 (ctu_sscan_tid[1]),
1254
                         .sel2 (ctu_sscan_tid[2]),
1255
                         .sel3 (ctu_sscan_tid[3]));
1256
 
1257
   // write to TCR
1258
   assign wrt_spec_w = dec_swl_wrt_tcr_w & ifu_tlu_inst_vld_w &
1259
                       ~flush_all_w;
1260
 
1261
   assign spec_next = (wrt_spec_w2 & fcl_dtu_hprivmode_w2) ?
1262
                             thr_config_in_w2[2] :
1263
                             en_spec_d;
1264
 
1265
   assign halt_w = wrt_spec_w & ~thr_config_in_w[0];
1266
 
1267
   dff_s #(1) wrsw2_ff(.din (wrt_spec_w),
1268
                     .q   (wrt_spec_w2),
1269
                     .clk (clk), .se(se), .si(), .so());
1270
 
1271
   assign wrt_tcr_w2 = st_thr_w2 & {4{wrt_spec_w2}};
1272
 
1273
   dff_s #(1) hlt_ff(.din (halt_w),
1274
                   .q   (halt_w2),
1275
                   .clk (clk), .se(se), .si(), .so());
1276
   assign halt_thread = st_thr_w2 & {4{halt_w2}};
1277
 
1278
   dffr_s #(1) enspec_ff(.din (spec_next),
1279
                                   .clk (clk),
1280
                                   .q   (en_spec_d),
1281
                                   .rst (dtu_reset),
1282
                                   .se  (se), .si(), .so());
1283
 
1284
   dff_s #(1) enspecm_ff(.din (rd_tid_spec_e[0]),
1285
                                   .clk (clk),
1286
                                   .q   (en_spec_m),
1287
                                   .se  (se), .si(), .so());
1288
 
1289
   dff_s #(1) enspecw_ff(.din (en_spec_m),
1290
                                   .clk (clk),
1291
                                   .q   (en_spec_g),
1292
                                   .se  (se), .si(), .so());
1293
 
1294
 
1295
   //-----------------------------
1296
   // Instruction Flow Control
1297
   //-----------------------------
1298
 
1299
   // mul and div control (1 each per cpu)
1300
   assign mul_busy_d = ({4{dec_swl_mul_inst_d & ~swl_dec_mulbusy_e &
1301
                           fcl_dtu_inst_vld_d & ~iferr_d}} & thr_d &
1302
//                                        ~rb_thr_w & ~rt_st_thr_e |          // set
1303
                        ~rt_st_thr_e |
1304
                                          mul_busy_e & ~killed_uniop_done_e) &
1305
                                           ~exu_ifu_longop_done_g & (~trp_no_retr);  // reset wins
1306
 
1307
   assign div_busy_d = ({4{dec_swl_div_inst_d & ~swl_dec_divbusy_e &
1308
                           fcl_dtu_inst_vld_d & ~iferr_d}} &
1309
                                          thr_d  & ~rt_st_thr_e |        // set
1310
                                          div_busy_e & ~killed_uniop_done_e) &
1311
                                           ~exu_ifu_longop_done_g & (~trp_no_retr); // reset wins
1312
 
1313
   assign fp_busy_d = ({4{dec_swl_allfp_d & // swl_dec_fp_enable_d &
1314
                          fcl_dtu_inst_vld_d &
1315
                          ~fpbusy_local_e & ~iferr_d}} & thr_d &
1316
                                   ~rt_st_thr_d & ~rt_st_thr_e |
1317
                                  // FP could be a st
1318
                                   fp_busy_e & ~killed_uniop_done_e) &
1319
                                          {4{~ffu_ifu_fpop_done_w2}} & ~trp_no_retr; // reset wins
1320
 
1321
   dffr_s #(4) mulb_ff(.din (mul_busy_d),
1322
                                 .q   (mul_busy_e),
1323
                                 .clk (clk),
1324
                                 .rst (dtu_reset),
1325
                                 .se  (se), .si(), .so());
1326
   assign true_mulbusy_e = (|mul_busy_e[3:0]);
1327
   assign mbusy_d0 = true_mulbusy_e & mul_wait_any;
1328
 
1329
   // block shared resource for two extra cycles, to allow waiting
1330
   // threads a fair chance at getting it.  
1331
   assign swl_dec_mulbusy_e = true_mulbusy_e | mbusy_d3 | mbusy_d1 | mbusy_d2;
1332
 
1333
   dffr_s #(4) divb_ff(.din (div_busy_d),
1334
                                 .q   (div_busy_e),
1335
                                 .clk (clk),
1336
                                 .rst (dtu_reset),
1337
                                 .se  (se), .si(), .so());
1338
   assign true_divbusy_e = (|div_busy_e[3:0]);
1339
   assign dbusy_d0 = true_divbusy_e & div_wait_any;
1340
 
1341
   // block shared resource for two extra cycles, to allow waiting
1342
   // threads a fair chance at getting it.  
1343
   assign swl_dec_divbusy_e = true_divbusy_e | dbusy_d3 | dbusy_d1 | dbusy_d2;
1344
 
1345
   dffr_s #(4) fpb_ff(.din (fp_busy_d),
1346
                                .q   (fp_busy_e),
1347
                                .clk (clk),
1348
                                .rst (dtu_reset),
1349
                                .se  (se), .si(), .so());
1350
   assign true_fpbusy_e = (|fp_busy_e[3:0]);
1351
   assign fbusy_d0 = true_fpbusy_e & fp_wait_any;
1352
 
1353
   assign fbusy_nxt_d = (|fp_busy_d[3:0]) | fbusy_d0 | fbusy_d1 | fbusy_d2;
1354
   dffr_s #(1) tfbe_ff(.din (fbusy_nxt_d),
1355
                     .q   (fbusy_crit_e),
1356
                     .clk (clk),
1357
                     .rst (dtu_reset), .se(se), .si(), .so());
1358
 
1359
   // block shared resource for two extra cycles, to allow waiting
1360
   // threads a fair chance at getting it.  
1361
   assign swl_dec_fpbusy_e = fbusy_crit_e;
1362
   assign fpbusy_local_e = true_fpbusy_e | fbusy_d3 | fbusy_d1 | fbusy_d2;
1363
 
1364
   dff_s #(3) bd1_reg(.din ({mbusy_d0, dbusy_d0, fbusy_d0}),
1365
                    .q   ({mbusy_d1, dbusy_d1, fbusy_d1}),
1366
                    .clk (clk), .se(se), .si(), .so());
1367
 
1368
   dff_s #(3) bd2_reg(.din ({mbusy_d1, dbusy_d1, fbusy_d1}),
1369
                    .q   ({mbusy_d2, dbusy_d2, fbusy_d2}),
1370
                    .clk (clk), .se(se), .si(), .so());
1371
 
1372
   dff_s #(3) bd3_reg(.din ({mbusy_d2, dbusy_d2, fbusy_d2}),
1373
                    .q   ({mbusy_d3, dbusy_d3, fbusy_d3}),
1374
                    .clk (clk), .se(se), .si(), .so());
1375
 
1376
   // ifetch errors
1377
   // If there was an error in the ifetch call back this instruction
1378
   assign iferr_d = erb_dtu_ifeterr_d1 & same_thr_de;
1379
   assign iferr_s = erb_dtu_ifeterr_d1 & same_thr_fe;
1380
   assign retract_iferr_d =  erb_dtu_ifeterr_d1 & fcl_dtu_inst_vld_d &
1381
                             same_thr_de;
1382
 
1383
   // mul_inst is already already qualified with inst_vld
1384
   // so is fpop
1385
   // don't set retract if there is an iferr, since this will cancel
1386
   // the pending imisses!  
1387
   assign dtu_fcl_retract_d = ((dec_swl_mul_inst_d & swl_dec_mulbusy_e |
1388
                                                  dec_swl_div_inst_d & swl_dec_divbusy_e |
1389
                                                  dec_swl_allfp_d & fpbusy_local_e) &
1390
                                // & swl_dec_fp_enable_d 
1391
                               fcl_dtu_inst_vld_d |
1392
                               retract_store_d
1393
//                             |  retract_iferr_d
1394
                               );
1395
 
1396
   // what does this do???
1397
   // no need to stall after retract since thread is already switched out
1398
//   assign retract_stall_d = (dec_swl_mul_inst_d & swl_dec_mulbusy_e | 
1399
//                                             dec_swl_div_inst_d & swl_dec_divbusy_e |
1400
//                                             dec_swl_allfp_d & swl_dec_fp_enable_d & 
1401
//                             fpbusy_local_e);
1402
 
1403
   assign mul_wait_nxt = ({4{dec_swl_mul_inst_d & swl_dec_mulbusy_e &
1404
                             fcl_dtu_inst_vld_d & ~iferr_d}} &
1405
                                         thr_d  & ~rt_st_thr_e | mul_done |   // set
1406
                                         mul_wait & ~retr_thr_wakeup  & ~killed_uniop_done_e) &
1407
                                         (~trp_no_retr);
1408
 
1409
   dffr_s #(4) mw_ff(.din (mul_wait_nxt[3:0]),
1410
                               .q   (mul_wait[3:0]),
1411
                               .clk (clk),
1412
                               .rst (dtu_reset),
1413
                               .se(se), .si(), .so());
1414
   assign mul_wait_any = (|mul_wait[3:0]);
1415
 
1416
   assign div_wait_nxt =  ({4{dec_swl_div_inst_d & swl_dec_divbusy_e &
1417
                              fcl_dtu_inst_vld_d & ~iferr_d}} &
1418
                        thr_d  & ~rt_st_thr_e | div_done | // set 
1419
                                          div_wait & ~retr_thr_wakeup & ~killed_uniop_done_e) &
1420
                                          (~trp_no_retr);
1421
 
1422
   dffr_s #(4) dw_ff(.din (div_wait_nxt[3:0]),
1423
                               .q   (div_wait[3:0]),
1424
                               .clk (clk),
1425
                               .rst (dtu_reset),
1426
                               .se(se), .si(), .so());
1427
   assign div_wait_any = (|div_wait[3:0]);
1428
 
1429
   assign fp_wait_nxt =  ({4{dec_swl_allfp_d & // swl_dec_fp_enable_d & 
1430
                             fcl_dtu_inst_vld_d & fpbusy_local_e &
1431
                             ~iferr_d}} &
1432
                                            thr_d  & ~rt_st_thr_d & ~rt_st_thr_e |
1433
                          fp_done |    // set 
1434
                                            fp_wait & ~retr_thr_wakeup & ~killed_uniop_done_e) &
1435
                                             (~trp_no_retr);
1436
 
1437
   dffr_s #(4) fw_ff(.din (fp_wait_nxt[3:0]),
1438
                               .q   (fp_wait[3:0]),
1439
                               .clk (clk),
1440
                               .rst (dtu_reset),
1441
                               .se(se), .si(), .so());
1442
   assign fp_wait_any = (|fp_wait[3:0]);
1443
 
1444
   // wake up waiting threads when the unit is no longer busy
1445
   // need to qual with trp_no_retr since trp can occur at the same
1446
   // time as unit becoming unbusy.  
1447
   assign mul_wake = mul_wait & {4{~true_mulbusy_e}} & ~trp_no_retr;
1448
   assign div_wake = div_wait & {4{~true_divbusy_e}} & ~trp_no_retr;
1449
   assign fp_wake  = fp_wait & {4{~true_fpbusy_e}} & ~trp_no_retr;
1450
 
1451
//   assign retr_thr_wakeup = (mul_wait & {4{~swl_dec_mulbusy_e}} |
1452
//                           div_wait & {4{~swl_dec_divbusy_e}} | 
1453
//                           fp_wait & {4{~fpbusy_local_e}} | 
1454
//                           wm_stbwait & stb_retry);
1455
 
1456
   assign retr_thr_wakeup = mul_wake | div_wake | fp_wake;
1457
//                        |  (wm_stbwait & stb_retry & ~wm_other);
1458
 
1459
   assign fp_thr[0] = ~ffu_ifu_tid_w2[1] & ~ffu_ifu_tid_w2[0];
1460
   assign fp_thr[1] = ~ffu_ifu_tid_w2[1] &  ffu_ifu_tid_w2[0];
1461
   assign fp_thr[2] =  ffu_ifu_tid_w2[1] & ~ffu_ifu_tid_w2[0];
1462
   assign fp_thr[3] =  ffu_ifu_tid_w2[1] &  ffu_ifu_tid_w2[0];
1463
 
1464
   // Delay mul div completion to prevent one thread from hogging mul and div
1465
   assign mul_done = exu_ifu_longop_done_g & mul_busy_e & {4{mul_wait_any}};
1466
   assign div_done = exu_ifu_longop_done_g & div_busy_e & {4{div_wait_any}};
1467
   assign fp_done = fp_thr & {4{ffu_ifu_fpop_done_w2}} & {4{fp_wait_any}};
1468
 
1469
   assign fp_thrrdy = fp_thr & {4{ffu_ifu_fpop_done_w2}} & {4{~fp_wait_any}};
1470
 
1471
   // don't complete if another mul/div is waiting
1472
   assign exu_lop_done = (exu_ifu_longop_done_g &
1473
                                            (~mul_busy_e | {4{~mul_wait_any}}) &
1474
                                            (~div_busy_e | {4{~div_wait_any}}));
1475
 
1476
   // TBD:
1477
   // 1.  Put in similar wakeup sequence for fp completion -- done
1478
   // 2.  Is it worth doing a round robin wakeup when a deadlock problem
1479
   //     exists even in that case? -- no need with lru scheduler
1480
 
1481
 
1482
   //--------------------------
1483
   // Store buffer flow control
1484
   //--------------------------
1485
   // store pipe
1486
   assign st_inst_qual_d = dec_swl_st_inst_d & fcl_dtu_inst_vld_d;
1487
   dff_s ste_ff(.din (st_inst_qual_d),
1488
                    .q   (st_inst_e),
1489
                    .clk (clk),
1490
                    .se  (se), .si(), .so());
1491
   assign st_inst_qual_e = st_inst_e & ~dtu_inst_anull_e;
1492
 
1493
   dff_s stm_ff(.din (st_inst_qual_e),
1494
                    .q   (st_inst_m),
1495
                    .clk (clk),
1496
                    .se  (se), .si(), .so());
1497
   dff_s stg_ff(.din (st_inst_m),
1498
                    .q   (st_inst_g),
1499
                    .clk (clk),
1500
                    .se  (se), .si(), .so());
1501
 
1502
//   assign st_inst_qual_g = st_inst_g & ifu_tlu_inst_vld_w;
1503
//   dff stw2_ff(.din (st_inst_qual_g),
1504
//                   .q   (st_inst_w2),
1505
//                   .clk (clk),
1506
//               .se  (se), .si(), .so());
1507
 
1508
   // determine which of the above thread is to the D thread
1509
   assign same_thr_de = (thr_d[0] & thr_e[0] |
1510
                                           thr_d[1] & thr_e[1] |
1511
                                           thr_d[2] & thr_e[2] |
1512
                                           thr_d[3] & thr_e[3]);
1513
   assign same_thr_dg = (thr_d[0] & thr_w[0] |
1514
                                           thr_d[1] & thr_w[1] |
1515
                                           thr_d[2] & thr_w[2] |
1516
                                           thr_d[3] & thr_w[3]);
1517
 
1518
   assign same_thr_fd = (thr_f[0] & thr_d[0] |
1519
                                           thr_f[1] & thr_d[1] |
1520
                                           thr_f[2] & thr_d[2] |
1521
                                           thr_f[3] & thr_d[3]);
1522
   assign same_thr_fe = (thr_f[0] & thr_e[0] |
1523
                                           thr_f[1] & thr_e[1] |
1524
                                           thr_f[2] & thr_e[2] |
1525
                                           thr_f[3] & thr_e[3]);
1526
   assign same_thr_fm = (thr_f[0] & thr_m[0] |
1527
                                           thr_f[1] & thr_m[1] |
1528
                                           thr_f[2] & thr_m[2] |
1529
                                           thr_f[3] & thr_m[3]);
1530
   assign same_thr_fg = (thr_f[0] & thr_w[0] |
1531
                                           thr_f[1] & thr_w[1] |
1532
                                           thr_f[2] & thr_w[2] |
1533
                                           thr_f[3] & thr_w[3]);
1534
 
1535
   assign pipe_st_e = same_thr_fe & st_inst_e;
1536
   assign pipe_st_m = same_thr_fm & st_inst_m;
1537
   assign pipe_st_g = same_thr_fg & st_inst_g;
1538
   assign pipe_st_d = same_thr_fd & st_inst_qual_d;
1539
 
1540
   dff_s #(1) pste_ff(.din (pipe_st_d),
1541
                    .q   (st_thisthr_e),
1542
                    .clk (clk), .se(se), .si(), .so());
1543
 
1544
   // count the number of stores in the pipe to this thread (0-4)
1545
   assign pipe_st_cnt_ge1 = pipe_st_e | pipe_st_m | pipe_st_g;
1546
//                                pipe_st_w2;
1547
 
1548
   assign pipe_st_cnt_ge2 = (pipe_st_e & pipe_st_m |
1549
                                               pipe_st_e & pipe_st_g |
1550
                             pipe_st_m & pipe_st_g);
1551
 
1552
//   assign pipe_st_cnt_ge2 = (pipe_st_e & pipe_st_m |
1553
//                                             pipe_st_e & pipe_st_g |
1554
//                                             pipe_st_e & pipe_st_w2 |
1555
//                                             pipe_st_m & pipe_st_g |
1556
//                                             pipe_st_m & pipe_st_w2 |
1557
//                                 pipe_st_g & pipe_st_w2);
1558
 
1559
   assign pipe_st_cnt_ge3 = (pipe_st_e & pipe_st_m & pipe_st_g);
1560
//                                             pipe_st_e & pipe_st_m & pipe_st_w2 |
1561
//                                             pipe_st_e & pipe_st_g & pipe_st_w2 |
1562
//                                             pipe_st_m & pipe_st_g & pipe_st_w2);
1563
 
1564
//   assign pipe_st_cnt_eq4 = pipe_st_e & pipe_st_m & pipe_st_g & 
1565
//                                pipe_st_w2;
1566
 
1567
   dff_s #(3) pstc_reg(.din ({pipe_st_cnt_ge1,
1568
                            pipe_st_cnt_ge2,
1569
                            pipe_st_cnt_ge3}),
1570
                     .q   ({dst_cnt_ge1,
1571
                            dst_cnt_ge2,
1572
                            dst_cnt_ge3}),
1573
                     .clk (clk), .se(se), .si(), .so());
1574
 
1575
   // get the number of taken store buffer entries to this thread
1576
   mux4ds #(4) stbcnt_mux(.dout (stbcnt_s),
1577
                                            .in0  (lsu_ifu_stbcnt0),
1578
                                            .in1  (lsu_ifu_stbcnt1),
1579
                                            .in2  (lsu_ifu_stbcnt2),
1580
                                            .in3  (lsu_ifu_stbcnt3),
1581
                                            .sel0 (thr_f[0]),
1582
                                            .sel1 (thr_f[1]),
1583
                                            .sel2 (thr_f[2]),
1584
                                            .sel3 (thr_f[3]));
1585
 
1586
   dff_s #(4) stbd_reg(.din (stbcnt_s),
1587
                                 .q   (stbcnt_d),
1588
                                 .clk (clk),
1589
                                 .se  (se), .si(), .so());
1590
 
1591
   assign all_dst_ge1 = dst_cnt_ge1 | st_thisthr_e;
1592
   assign all_dst_ge2 = dst_cnt_ge1 & st_thisthr_e | dst_cnt_ge2;
1593
   assign all_dst_ge3 = dst_cnt_ge2 & st_thisthr_e | dst_cnt_ge3;
1594
   assign all_dst_eq4 = dst_cnt_ge3 & st_thisthr_e;
1595
 
1596
   // switch if taken entries + stores in pipe >= 8
1597
   assign switch_store_d = stbcnt_d[3] & fcl_dtu_inst_vld_d | // 8
1598
                    dec_swl_st_inst_d & fcl_dtu_inst_vld_d &
1599
                    (stbcnt_d[2] & stbcnt_d[1] & stbcnt_d[0] | // 7
1600
                           stbcnt_d[2] & stbcnt_d[1] & all_dst_ge1 | // 6 + 1
1601
                           stbcnt_d[2] & stbcnt_d[0] & all_dst_ge2 | // 5 + 2
1602
                           stbcnt_d[2]               & all_dst_ge3 | // 4 + 3
1603
                           stbcnt_d[1] & stbcnt_d[0] & all_dst_eq4); // 3 + 4
1604
 
1605
   assign stb_stall = {4{switch_store_d}} & thr_d;
1606
   assign stb_blocked = {lsu_ifu_stbcnt3[3], lsu_ifu_stbcnt2[3],
1607
                                           lsu_ifu_stbcnt1[3], lsu_ifu_stbcnt0[3]};
1608
 
1609
   dff_s #(4) stbb_reg(.din (stb_blocked),
1610
                                 .q   (stb_blocked_d1),
1611
                                 .clk (clk), .se(se), .si(), .so());
1612
 
1613
   // retract this thread if taken entries + stores in pipe >= 9
1614
   assign retract_store_d = dec_swl_st_inst_d & fcl_dtu_inst_vld_d &
1615
                (stbcnt_d[3] | // 8
1616
                 stbcnt_d[2] & stbcnt_d[1] & stbcnt_d[0] & all_dst_ge1 | // 7 + 1
1617
                 stbcnt_d[2] & stbcnt_d[1] & all_dst_ge2 |  // 6 + 2
1618
                 stbcnt_d[2] & stbcnt_d[0] & all_dst_ge3 |  // 5 + 3
1619
                 stbcnt_d[2] & all_dst_eq4);                // 4 + 4
1620
 
1621
   // remember if we retracted a store so that we can clear wmo in 
1622
   // the next cycle
1623
   assign retract_st_next_d = (retract_store_d | retract_iferr_d) &
1624
                              ~(same_thr_dg & rollback_g) &
1625
                              ~trp_noretr_d;
1626
 
1627
   dff_s #(1) retr_se(.din (retract_st_next_d),
1628
                                .q   (retract_store_e),
1629
                                .clk (clk), .se (se), .si(), .so());
1630
 
1631
   // clear wmo if you set it already
1632
   assign clear_wmo_e = retract_store_e & (swc_d & same_thr_de | swc_e);
1633
// assign clear_wmo_e = retract_store_e;   
1634
 
1635
 
1636
   // mark a switched out thread for wakeup
1637
//   assign stb_wait_nxt = ({4{switch_store_d}} & thr_d & ~rb_thr_w |   // set
1638
//                                          wm_stbwait & ~stb_retry 
1639
//                                      ~(thr_d & {4{swc_d}}) & 
1640
//                                          ~(thr_e & {4{dec_swl_sta_inst_e & 
1641
//                                                             lsu_ifu_ldsta_internal_e}})   // reset
1642
//                                          ) & ~trp_no_retr;  // this reset wins
1643
 
1644
//   assign stb_wait_nxt = ({4{switch_store_d}} & thr_d & ~rb_thr_w |   // set
1645
//                                          wm_stbwait & ~stb_retry) & ~trp_no_retr;
1646
 
1647
   assign stb_wait_nxt = ({4{switch_store_d}} & thr_d |   // set
1648
                                            wm_stbwait & ~stb_retry);
1649
 
1650
   dffr_s #(4) stbw_reg(.din (stb_wait_nxt),
1651
                                  .q   (wm_stbwait),
1652
                                  .clk (clk),
1653
                                  .rst (dtu_reset),
1654
                                  .se  (se), .si(), .so());
1655
 
1656
   // count to 4 and retry 
1657
   dff_s stbrete_ff(.din (switch_store_d),
1658
                              .q   (sw_st_e),
1659
                              .clk (clk),
1660
                              .se  (se), .si(), .so());
1661
   dff_s stbretm_ff(.din (sw_st_e),
1662
                              .q   (sw_st_m),
1663
                              .clk (clk),
1664
                              .se  (se), .si(), .so());
1665
   dff_s stbretg_ff(.din (sw_st_m),
1666
                              .q   (sw_st_g),
1667
                              .clk (clk),
1668
                              .se  (se), .si(), .so());
1669
   dff_s stbretw2_ff(.din (sw_st_g),
1670
                               .q   (sw_st_w2),
1671
                               .clk (clk),
1672
                               .se  (se), .si(), .so());
1673
//   assign stb_retry = {4{sw_st_w2}} & st_thr_w2 & ~stb_blocked;
1674
 
1675
   assign st_in_pipe = ({4{sw_st_e}} & thr_e |
1676
                                          {4{sw_st_m}} & thr_m |
1677
                                          {4{sw_st_g}} & thr_w |
1678
                                          {4{sw_st_w2}} & st_thr_w2);
1679
 
1680
   // don't really need to AND with wm_stbwait with current logic, but
1681
   // for future use, this is left as is 
1682
   assign stb_retry = ~stb_blocked_d1 & ~st_in_pipe & wm_stbwait;
1683
 
1684
 
1685
   //
1686
   // Quad Stores
1687
   //
1688
   dff_s #(1) stde_ff(.din (dec_swl_std_inst_d),
1689
                                .q   (std_inst_e),
1690
                                .clk (clk), .se(se), .si(), .so());
1691
 
1692
//   assign stq_inst_e = std_inst_e & lsu_ifu_quad_asi_e & fcl_dtu_inst_vld_e;
1693
   assign std_done_e = std_inst_e & ~lsu_ifu_quad_asi_e & fcl_dtu_inst_vld_e;
1694
   dff_s #(1) stdm_ff(.din (std_done_e),
1695
                                .q   (std_done_m),
1696
                                .clk (clk), .se(se), .si(), .so());
1697
 
1698
//   dff #(1) stqm_ff(.din (stq_inst_e),
1699
//                              .q   (stq_inst_m),
1700
//                              .clk (clk), .se(se), .si(), .so());
1701
//   dff #(1) stqw_ff(.din (stq_inst_m),
1702
//                              .q   (stq_inst_w),
1703
//                              .clk (clk), .se(se), .si(), .so());
1704
//   dff #(1) stqw2_ff(.din (stq_inst_w),
1705
//                               .q   (stq_inst_w2),
1706
//                               .clk (clk), .se(se), .si(), .so());
1707
 
1708
//   assign stq_in_pipe = ({4{stq_inst_m}} & thr_m |
1709
//                                         {4{stq_inst_w}} & thr_w |
1710
//                                         {4{stq_inst_w2}} & st_thr_w2);
1711
 
1712
//   assign stq_busy = (stq_in_pipe | lsu_ifu_stq_busy);
1713
//   assign stq_wait_next = thr_e & {4{stq_inst_e}} | 
1714
//                                          stq_wait & stq_busy;
1715
 
1716
//   dffr #(4) stqwait_reg(.din (stq_wait_next),
1717
//                                   .q   (stq_wait),
1718
//                                   .rst (dtu_reset),
1719
//                                   .clk (clk), .se(se), .si(), .so());
1720
//
1721
//   assign stq_done_thr = stq_wait & ~stq_busy | thr_m & {4{std_done_m}};
1722
 
1723
 
1724
   //-----------------------------
1725
   // FPRS
1726
   //-----------------------------
1727
   dff_s #(3) wrtd_w_reg(.din (thr_config_in_m[2:0]),
1728
                        .q   (thr_config_in_w[2:0]),
1729
                        .clk (clk), .se(se), .si(), .so());
1730
 
1731
   dff_s #(3) wrtd_w2_reg(.din (thr_config_in_w[2:0]),
1732
                        .q   (thr_config_in_w2[2:0]),
1733
                        .clk (clk), .se(se), .si(), .so());
1734
 
1735
   assign fprs_wrt_data = thr_config_in_w2;
1736
   mux3ds #(3) fprs_mx0(.dout (fprs0_nxt),
1737
                                    .in0  (fprs_wrt_data),
1738
                                    .in1  (fprs0),
1739
                                    .in2  ({fprs0[2], new_fprs[1:0]}),
1740
                                    .sel0 (fprs_sel_wrt[0]),
1741
                                    .sel1 (fprs_sel_old[0]),
1742
                                    .sel2 (fprs_sel_set[0]));
1743
   mux3ds #(3) fprs_mx1(.dout (fprs1_nxt),
1744
                                    .in0  (fprs_wrt_data),
1745
                                    .in1  (fprs1),
1746
                                    .in2  ({fprs1[2], new_fprs[1:0]}),
1747
                                    .sel0 (fprs_sel_wrt[1]),
1748
                                    .sel1 (fprs_sel_old[1]),
1749
                                    .sel2 (fprs_sel_set[1]));
1750
   mux3ds #(3) fprs_mx2(.dout (fprs2_nxt),
1751
                                    .in0  (fprs_wrt_data),
1752
                                    .in1  (fprs2),
1753
                                    .in2  ({fprs2[2], new_fprs[1:0]}),
1754
                                    .sel0 (fprs_sel_wrt[2]),
1755
                                    .sel1 (fprs_sel_old[2]),
1756
                                    .sel2 (fprs_sel_set[2]));
1757
   mux3ds #(3) fprs_mx3(.dout (fprs3_nxt),
1758
                                    .in0  (fprs_wrt_data),
1759
                                    .in1  (fprs3),
1760
                                    .in2  ({fprs3[2], new_fprs[1:0]}),
1761
                                    .sel0 (fprs_sel_wrt[3]),
1762
                                    .sel1 (fprs_sel_old[3]),
1763
                                    .sel2 (fprs_sel_set[3]));
1764
 
1765
   // make resettable for now.  Eventually change to non-reset
1766
   // Done
1767
   dff_s #(3) t0_fprs(.din (fprs0_nxt),
1768
                                 .q   (fprs0),
1769
//                               .rst (dtu_reset),
1770
                                 .clk (clk), .se(se), .si(), .so());
1771
   dff_s #(3) t1_fprs(.din (fprs1_nxt),
1772
                                 .q   (fprs1),
1773
//                               .rst (dtu_reset),
1774
                                 .clk (clk), .se(se), .si(), .so());
1775
   dff_s #(3) t2_fprs(.din (fprs2_nxt),
1776
                                 .q   (fprs2),
1777
//                               .rst (dtu_reset),
1778
                                 .clk (clk), .se(se), .si(), .so());
1779
   dff_s #(3) t3_fprs(.din (fprs3_nxt),
1780
                                 .q   (fprs3),
1781
//                               .rst (dtu_reset),
1782
                                 .clk (clk), .se(se), .si(), .so());
1783
 
1784
   assign fprs_en_s = {fprs3[2],fprs2[2],fprs1[2],fprs0[2]};
1785
   assign fpen_vec_s = (tlu_ifu_pstate_pef & fprs_en_s & thr_f);
1786
   assign fpen_s = (|fpen_vec_s[3:0]);
1787
   dff_s #(1) fpend_ff(.din (fpen_s),
1788
                                 .q   (swl_dec_fp_enable_d),
1789
                                 .clk (clk), .se(se), .si(), .so());
1790
 
1791
   // unprotected since synopsys does not use one hot mux
1792
   mux4ds #(3) curr_fprs_mx(.dout (fprs_d),
1793
                                              .in0  (fprs0),
1794
                                              .in1  (fprs1),
1795
                                              .in2  (fprs2),
1796
                                              .in3  (fprs3),
1797
                                              .sel0 (thr_d[0]),
1798
                                              .sel1 (thr_d[1]),
1799
                                              .sel2 (thr_d[2]),
1800
                                              .sel3 (thr_d[3]));
1801
 
1802
   dff_s #(3) fprse_reg(.din (fprs_d),
1803
                                  .q   (fprs_e),
1804
                                  .clk (clk), .se(se), .si(), .so());
1805
 
1806
   assign new_fprs[1] = dec_swl_frf_upper_d | fprs_d[1];
1807
   assign new_fprs[0] = dec_swl_frf_lower_d | fprs_d[0];
1808
 
1809
   // writes to fprs are done by software
1810
   assign wrt_fprs_w = ifu_tlu_inst_vld_w & dec_swl_wrtfprs_w &
1811
                                         ~flush_all_w;
1812
 
1813
   dff_s #(1) fpwr_ff(.din (wrt_fprs_w),
1814
                    .q   (wrt_fprs_w2),
1815
                    .clk (clk), .se(se), .si(), .so());
1816
 
1817
   assign sel_wrt = st_thr_w2 & {4{wrt_fprs_w2}};
1818
   assign fprs_sel_set = thr_d & {4{dec_swl_fpop_d & swl_dec_fp_enable_d &
1819
                                    fcl_dtu_inst_vld_d}};
1820
   assign fprs_sel_wrt = ~fprs_sel_set & sel_wrt;
1821
   assign fprs_sel_old = ~sel_wrt & ~fprs_sel_set;
1822
 
1823
   sink #(52) s0(.in (thrconf_out_e));
1824
 
1825
 
1826
endmodule // sparc_ifu_swl
1827
 
1828
// Local Variables:
1829
// verilog-library-directories:("../../rtl" ".")
1830
// End:
1831
 

powered by: WebSVN 2.1.0

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