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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v7/] [rtl/] [twoway/] [FT64.v] - Blame information for rev 61

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

Line No. Rev Author Line
1 60 robfinch
// ============================================================================
2
//        __
3 61 robfinch
//   \\__/ o\    (C) 2017-2019  Robert Finch, Waterloo
4 60 robfinch
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      FT64.v
9
//      Features include:
10
//  - 16/32/48 bit instructions
11
//  - vector instruction set,
12
//  - SIMD instructions
13
//  - data width of 64 bits
14
//      - 32 general purpose registers
15
//  - 32 floating point registers
16
//      - 32 vector registers, length 63
17
//  - powerful branch prediction
18
//  - branch target buffer (BTB)
19
//  - return address predictor (RSB)
20
//  - bus interface unit
21
//  - instruction and data caches
22
//      - fine-grained simultaneous multi-threading (SMT)
23
//  - bus randomizer on exceptional conditions
24
//
25
// This source file is free software: you can redistribute it and/or modify 
26
// it under the terms of the GNU Lesser General Public License as published 
27
// by the Free Software Foundation, either version 3 of the License, or     
28
// (at your option) any later version.                                      
29
//                                                                          
30
// This source file is distributed in the hope that it will be useful,      
31
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
32
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
33
// GNU General Public License for more details.                             
34
//                                                                          
35
// You should have received a copy of the GNU General Public License        
36
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
37
//
38
// Approx 41,000 LUTs. 66,000 LC's.
39
// ============================================================================
40
//
41
`include "FT64_config.vh"
42
`include "FT64_defines.vh"
43
 
44
module FT64(hartid, rst, clk_i, clk4x, tm_clk_i, irq_i, vec_i, bte_o, cti_o, bok_i, cyc_o, stb_o, ack_i, err_i, we_o, sel_o, adr_o, dat_o, dat_i,
45 61 robfinch
    ol_o, pcr_o, pcr2_o, pkeys_o, icl_o, sr_o, cr_o, rbi_i, signal_i, exc_o);
46 60 robfinch
input [63:0] hartid;
47
input rst;
48
input clk_i;
49
input clk4x;
50
input tm_clk_i;
51
input [3:0] irq_i;
52
input [7:0] vec_i;
53
output reg [1:0] bte_o;
54
output reg [2:0] cti_o;
55
input bok_i;
56
output cyc_o;
57
output reg stb_o;
58
input ack_i;
59
input err_i;
60
output we_o;
61
output reg [7:0] sel_o;
62
output [`ABITS] adr_o;
63
output reg [63:0] dat_o;
64
input [63:0] dat_i;
65
output reg [1:0] ol_o;
66
output [31:0] pcr_o;
67
output [63:0] pcr2_o;
68
output [63:0] pkeys_o;
69
output reg icl_o;
70
output reg cr_o;
71
output reg sr_o;
72
input rbi_i;
73
input [31:0] signal_i;
74 61 robfinch
(* mark_debug="true" *)
75
output [7:0] exc_o;
76 60 robfinch
 
77
parameter TM_CLKFREQ = 20000000;
78
parameter QENTRIES = `QENTRIES;
79
parameter RSTPC = 64'hFFFFFFFFFFFC0100;
80
parameter BRKPC = 64'hFFFFFFFFFFFC0000;
81
`ifdef SUPPORT_SMT
82
parameter PREGS = 256;   // number of physical registers - 1
83
parameter AREGS = 256;   // number of architectural registers
84
`else
85
parameter PREGS = 128;
86
parameter AREGS = 128;
87
`endif
88
parameter RBIT = 11;
89
parameter DEBUG = 1'b0;
90
parameter NMAP = QENTRIES;
91
parameter BRANCH_PRED = 1'b0;
92
parameter SUP_TXE = 1'b0;
93
`ifdef SUPPORT_VECTOR
94
parameter SUP_VECTOR = 1'b1;
95
`else
96
parameter SUP_VECTOR = 1'b0;
97
`endif
98
parameter DBW = 64;
99
parameter ABW = 64;
100
parameter AMSB = ABW-1;
101
parameter NTHREAD = 1;
102
reg [7:0] i;
103
integer n;
104
integer j, k;
105
genvar g, h;
106
parameter TRUE = 1'b1;
107
parameter FALSE = 1'b0;
108
// Memory access sizes
109
parameter byt = 3'd0;
110
parameter wyde = 3'd1;
111
parameter tetra = 3'd2;
112
parameter octa = 3'd3;
113 61 robfinch
parameter hexi = 3'd4;
114 60 robfinch
// IQ states
115
parameter IQS_INVALID = 3'd0;
116
parameter IQS_QUEUED = 3'd1;
117
parameter IQS_OUT = 3'd2;
118
parameter IQS_AGEN = 3'd3;
119
parameter IQS_MEM = 3'd4;
120
parameter IQS_DONE = 3'd5;
121
parameter IQS_CMT = 3'd6;
122
 
123
wire clk;
124
//BUFG uclkb1
125
//(
126
//      .I(clk_i),
127
//      .O(clk)
128
//);
129
assign clk = clk_i;
130
 
131
wire exv_i;
132
wire rdv_i;
133
wire wrv_i;
134
reg [ABW-1:0] vadr;
135
reg cyc;
136
reg we;
137
 
138
wire dc_ack;
139
wire acki = ack_i|dc_ack;
140
wire [RBIT:0] Ra0, Ra1, Ra2;
141
wire [RBIT:0] Rb0, Rb1, Rb2;
142
wire [RBIT:0] Rc0, Rc1, Rc2;
143
wire [RBIT:0] Rt0, Rt1, Rt2;
144
wire [63:0] rfoa0,rfob0,rfoc0,rfoc0a,rfot0;
145
wire [63:0] rfoa1,rfob1,rfoc1,rfoc1a,rfot1;
146
wire [63:0] rfoa2,rfob2,rfoc2,rfoc2a,rfot2;
147
`ifdef SUPPORT_SMT
148
wire [7:0] Ra0s = {Ra0[7:0]};
149
wire [7:0] Ra1s = {Ra1[7:0]};
150
wire [7:0] Ra2s = {Ra2[7:0]};
151
wire [7:0] Rb0s = {Rb0[7:0]};
152
wire [7:0] Rb1s = {Rb1[7:0]};
153
wire [7:0] Rb2s = {Rb2[7:0]};
154
wire [7:0] Rc0s = {Rc0[7:0]};
155
wire [7:0] Rc1s = {Rc1[7:0]};
156
wire [7:0] Rc2s = {Rc2[7:0]};
157
wire [7:0] Rt0s = {Rt0[7:0]};
158
wire [7:0] Rt1s = {Rt1[7:0]};
159
wire [7:0] Rt2s = {Rt2[7:0]};
160
`else
161
wire [6:0] Ra0s = {Ra0[7],Ra0[5:0]};
162
wire [6:0] Ra1s = {Ra1[7],Ra1[5:0]};
163
wire [6:0] Ra2s = {Ra2[7],Ra2[5:0]};
164
wire [6:0] Rb0s = {Rb0[7],Rb0[5:0]};
165
wire [6:0] Rb1s = {Rb1[7],Rb1[5:0]};
166
wire [6:0] Rb2s = {Rb2[7],Rb2[5:0]};
167
wire [6:0] Rc0s = {Rc0[7],Rc0[5:0]};
168
wire [6:0] Rc1s = {Rc1[7],Rc1[5:0]};
169
wire [6:0] Rc2s = {Rc2[7],Rc2[5:0]};
170
wire [6:0] Rt0s = {Rt0[7],Rt0[5:0]};
171
wire [6:0] Rt1s = {Rt1[7],Rt1[5:0]};
172
wire [6:0] Rt2s = {Rt2[7],Rt2[5:0]};
173
/*
174
wire [5:0] Ra0s = {Ra0[5:0]};
175
wire [5:0] Ra1s = {Ra1[5:0]};
176
wire [5:0] Rb0s = {Rb0[5:0]};
177
wire [5:0] Rb1s = {Rb1[5:0]};
178
wire [5:0] Rc0s = {Rc0[5:0]};
179
wire [5:0] Rc1s = {Rc1[5:0]};
180
wire [5:0] Rt0s = {Rt0[5:0]};
181
wire [5:0] Rt1s = {Rt1[5:0]};
182
*/
183
`endif
184
 
185
reg [63:0] wbrcd;
186
wire [5:0] brgs;
187
`ifdef SUPPORT_BBMS
188
reg [15:0] thrd_handle [0:63];
189
reg [63:0] prg_base [0:63];
190
reg [63:0] prg_limit [0:63];
191
reg [63:0] en_barrier [0:63];                                     // environment bound
192
reg [63:0] cl_barrier [0:63];
193
reg [63:0] cu_barrier [0:63];
194
reg [63:0] ro_barrier [0:63];
195
reg [63:0] dl_barrier [0:63];
196
reg [63:0] du_barrier [0:63];
197
reg [63:0] sl_barrier [0:63];
198
reg [63:0] su_barrier [0:63];
199
reg [7:0] env_priv [0:63];
200
reg [7:0] cod_priv [0:63];
201
reg [7:0] rdo_priv [0:63];
202
reg [7:0] dat_priv [0:63];
203
reg [7:0] stk_priv [0:63];
204
reg [15:0] th;
205
reg [63:0] pb;
206
reg [63:0] cbl;
207
reg [63:0] cbu;
208
reg [63:0] ro;
209
reg [63:0] dbl;
210
reg [63:0] dbu;
211
reg [63:0] sbl;
212
reg [63:0] sbu;
213
reg [63:0] en;
214
reg [7:0] env_pl;
215
reg [7:0] cod_pl;
216
reg [7:0] rdo_pl;
217
reg [7:0] dat_pl;
218
reg [7:0] stk_pl;
219
initial begin
220
        for (n = 0; n < 64; n = n + 1)
221
        begin
222
                thrd_handle[n] <= 1'd0;
223
                prg_base[n] <= 1'd0;
224
                cl_barrier[n] <= 1'd0;
225
                cu_barrier[n] <= 64'hFFFFFFFFFFFFFFFF;
226
                ro_barrier[n] <= 1'd0;
227
                dl_barrier[n] <= 1'd0;
228
                du_barrier[n] <= 64'hFFFFFFFFFFFFFFFF;
229
                sl_barrier[n] <= 1'd0;
230
                su_barrier[n] <= 64'hFFFFFFFFFFFFFFFF;
231
                env_priv[n] <= 8'h00;
232
                cod_priv[n] <= 8'h00;
233
                rdo_priv[n] <= 8'h00;
234
                dat_priv[n] <= 8'h00;
235
                stk_priv[n] <= 8'h00;
236
        end
237
end
238
always @(posedge clk_i)
239
begin
240
        th <= thrd_handle[brgs];
241
        pb <= prg_base[brgs];
242
        cbl <= cl_barrier[brgs];
243
        cbu <= cu_barrier[brgs];
244
        ro <= ro_barrier[brgs];
245
        dbl <= dl_barrier[brgs];
246
        dbu <= du_barrier[brgs];
247
        sbl <= sl_barrier[brgs];
248
        sbu <= su_barrier[brgs];
249
        en <= en_barrier[brgs];
250
        env_pl <= env_priv[brgs];
251
        cod_pl <= cod_priv[brgs];
252
        rdo_pl <= rdo_priv[brgs];
253
        dat_pl <= dat_priv[brgs];
254
        stk_pl <= stk_priv[brgs];
255
end
256
//wire [23:0] currentPrgSelector = prg_selector[brgs];
257
`else
258
wire [63:0] pb = 1'd0;
259
wire [63:0] cbl = 1'd0;
260
wire [63:0] cbu = 64'hFFFFFFFFFFFFFFFF;
261
wire [63:0] ro = 1'd0;
262
wire [63:0] dbl = 1'd0;
263
wire [63:0] dbu = 64'hFFFFFFFFFFFFFFFF;
264
wire [63:0] sbl = 1'd0;
265
wire [63:0] sbu = 64'hFFFFFFFFFFFFFFFF;
266
wire [63:0] en = 1'd0;
267
wire [7:0] env_pl = 8'h00;
268
wire [7:0] cod_pl = 8'h00;
269
wire [7:0] rdo_pl = 8'h00;
270
wire [7:0] dat_pl = 8'h00;
271
wire [7:0] stk_pl = 8'h00;
272
`endif
273
 
274
reg  [PREGS-1:0] rf_v;
275
reg  [`QBITSP1] rf_source[0:AREGS-1];
276
reg  [15:0] prf_v;
277
reg  [`QBITSP1] prf_source[0:15];
278
initial begin
279
for (n = 0; n < AREGS; n = n + 1)
280
        rf_source[n] = 1'b0;
281
for (n = 0; n < 16; n = n + 1)
282
        prf_source[n] <= 1'b0;
283
end
284
wire [`ABITS] pc0a;
285
wire [`ABITS] pc1a;
286
wire [`ABITS] pc2a;
287
`ifdef SUPPORT_BBMS
288
wire [`ABITS] pc0 = (pc0a[47:40]==8'hFF||ol==2'b00) ? pc0a : {pb[50:0],13'd0} + pc0a[47:0];
289
wire [`ABITS] pc1 = (pc1a[47:40]==8'hFF||ol==2'b00) ? pc1a : {pb[50:0],13'd0} + pc1a[47:0];
290
wire [`ABITS] pc2 = (pc2a[47:40]==8'hFF||ol==2'b00) ? pc2a : {pb[50:0],13'd0} + pc2a[47:0];
291
`else
292
wire [`ABITS] pc0 = pc0a;
293
wire [`ABITS] pc1 = pc1a;
294
wire [`ABITS] pc2 = pc2a;
295
`endif
296
 
297
reg excmiss;
298
reg [`ABITS] excmisspc;
299
reg excthrd;
300
reg exception_set;
301
reg rdvq;               // accumulated read violation
302
reg errq;               // accumulated err_i input status
303
reg exvq;
304
 
305
// Vector
306
reg [5:0] vqe0, vqe1, vqe2;   // vector element being queued
307
reg [5:0] vqet0, vqet1, vqet2;
308
reg [7:0] vl;           // vector length
309
reg [63:0] vm [0:7];    // vector mask registers
310
reg [1:0] m2;
311
 
312
reg [31:0] wb_merges;
313
// CSR's
314
reg [63:0] cr0;
315
wire snr = cr0[17];             // sequence number reset
316
wire dce = cr0[30];     // data cache enable
317
wire bpe = cr0[32];     // branch predictor enable
318
wire wbm = cr0[34];
319
wire sple = cr0[35];            // speculative load enable
320
wire ctgtxe = cr0[33];
321
wire pred_on = 1'b0;
322
reg [63:0] pmr;
323
wire id1_available = pmr[0];
324
wire id2_available = pmr[1];
325
wire id3_available = pmr[2];
326
wire alu0_available = pmr[8];
327
wire alu1_available = pmr[9];
328
wire fpu1_available = pmr[16];
329
wire fpu2_available = pmr[17];
330
wire mem1_available = pmr[24];
331
wire mem2_available = pmr[25];
332
wire mem3_available = pmr[26];
333
wire fcu_available = pmr[32];
334
// Simply setting this flag to zero should strip out almost all the logic
335
// associated SMT.
336
`ifdef SUPPORT_SMT
337
wire thread_en = cr0[16];
338
`else
339
wire thread_en = 1'b0;
340
`endif
341
wire vechain = cr0[18];
342 61 robfinch
// Performance CSR's
343 60 robfinch
reg [39:0] iq_ctr;
344
reg [39:0] irq_ctr;                                      // count of number of interrupts
345
reg [39:0] bm_ctr;                                       // branch miss counter
346 61 robfinch
reg [39:0] br_ctr;                                       // branch counter
347 60 robfinch
reg [39:0] icl_ctr;                                      // instruction cache load counter
348
 
349
reg [7:0] fcu_timeout;
350
reg [63:0] tick;
351
reg [63:0] wc_time;
352
reg [31:0] pcr;
353
reg [63:0] pcr2;
354
assign pcr_o = pcr;
355
assign pcr2_o = pcr2;
356
reg [63:0] aec;
357 61 robfinch
(* mark_debug = "true" *)
358 60 robfinch
reg [15:0] cause[0:15];
359
`ifdef SUPPORT_SMT
360
reg [`ABITS] epc [0:NTHREAD];
361
reg [`ABITS] epc0 [0:NTHREAD];
362
reg [`ABITS] epc1 [0:NTHREAD];
363
reg [`ABITS] epc2 [0:NTHREAD];
364
reg [`ABITS] epc3 [0:NTHREAD];
365
reg [`ABITS] epc4 [0:NTHREAD];
366
reg [`ABITS] epc5 [0:NTHREAD];
367
reg [`ABITS] epc6 [0:NTHREAD];
368
reg [`ABITS] epc7 [0:NTHREAD];
369
reg [`ABITS] epc8 [0:NTHREAD];                   // exception pc and stack
370
reg [63:0] mstatus [0:NTHREAD];           // machine status
371
wire [3:0] im = mstatus[0][3:0];
372
wire [1:0] ol [0:NTHREAD];
373
wire [1:0] dl [0:NTHREAD];
374
assign ol[0] = mstatus[0][5:4];   // operating level
375
assign dl[0] = mstatus[0][21:20];
376
wire [7:0] cpl [0:NTHREAD];
377
assign cpl[0] = mstatus[0][13:6]; // current privilege level
378
wire [5:0] rgs [0:NTHREAD];
379
assign ol[1] = mstatus[1][5:4]; // operating level
380
assign cpl[1] = mstatus[1][13:6];       // current privilege level
381
assign dl[1] = mstatus[1][21:20];
382
wire [7:0] ASID = mstatus[0][47:40];
383
reg [15:0] ol_stack [0:NTHREAD];
384
reg [15:0] dl_stack [0:NTHREAD];
385
reg [31:0] im_stack [0:NTHREAD];
386
reg [63:0] pl_stack [0:NTHREAD];
387
reg [63:0] rs_stack [0:NTHREAD];
388
reg [63:0] brs_stack [0:NTHREAD];
389
reg [63:0] fr_stack [0:NTHREAD];
390
assign rgs[0] = rs_stack[0][5:0];
391
assign rgs[1] = rs_stack[1][5:0];
392
wire mprv = mstatus[0][55];
393
wire [5:0] fprgs = mstatus[0][25:20];
394
//assign ol_o = mprv ? ol_stack[0][2:0] : ol[0];
395
wire vca = mstatus[0][32];               // vector chaining active
396
`else
397
reg [`ABITS] epc ;
398
reg [`ABITS] epc0 ;
399
reg [`ABITS] epc1 ;
400
reg [`ABITS] epc2 ;
401
reg [`ABITS] epc3 ;
402
reg [`ABITS] epc4 ;
403
reg [`ABITS] epc5 ;
404
reg [`ABITS] epc6 ;
405
reg [`ABITS] epc7 ;
406
reg [`ABITS] epc8 ;                     // exception pc and stack
407
reg [63:0] mstatus ;             // machine status
408
wire [3:0] im = mstatus[3:0];
409
wire [1:0] ol ;
410
wire [1:0] dl;
411
assign ol = mstatus[5:4];       // operating level
412
assign dl = mstatus[21:20];
413
wire [7:0] cpl ;
414
assign cpl = mstatus[13:6];     // current privilege level
415
wire [5:0] rgs ;
416
reg [15:0] ol_stack ;
417
reg [15:0] dl_stack ;
418
reg [31:0] im_stack ;
419
reg [63:0] pl_stack ;
420
reg [63:0] rs_stack ;
421
reg [63:0] brs_stack ;
422
reg [63:0] fr_stack ;
423
assign rgs = rs_stack[5:0];
424
assign brgs = brs_stack[5:0];
425
wire mprv = mstatus[55];
426
wire [7:0] ASID = mstatus[47:40];
427
wire [5:0] fprgs = mstatus[25:20];
428
//assign ol_o = mprv ? ol_stack[2:0] : ol;
429
wire vca = mstatus[32];         // vector chaining active
430
`endif
431
reg [63:0] keys;
432
assign pkeys_o = keys;
433
reg [63:0] tcb;
434
reg [47:0] bad_instr[0:15];
435
reg [`ABITS] badaddr[0:15];
436
reg [`ABITS] tvec[0:7];
437
reg [63:0] sema;
438
reg [63:0] vm_sema;
439
reg [63:0] cas;         // compare and swap
440
reg [63:0] ve_hold;
441
reg isCAS, isAMO, isInc, isSpt, isRMW;
442
reg [`QBITS] casid;
443
reg [4:0] regLR = 5'd29;
444
 
445
 
446
reg [2:0] fp_rm;
447
reg fp_inexe;
448
reg fp_dbzxe;
449
reg fp_underxe;
450
reg fp_overxe;
451
reg fp_invopxe;
452
reg fp_giopxe;
453
reg fp_nsfp = 1'b0;
454
reg fp_fractie;
455
reg fp_raz;
456
 
457
reg fp_neg;
458
reg fp_pos;
459
reg fp_zero;
460
reg fp_inf;
461
 
462
reg fp_inex;            // inexact exception
463
reg fp_dbzx;            // divide by zero exception
464
reg fp_underx;          // underflow exception
465
reg fp_overx;           // overflow exception
466
reg fp_giopx;           // global invalid operation exception
467
reg fp_sx;                      // summary exception
468
reg fp_swtx;        // software triggered exception
469
reg fp_gx;
470
reg fp_invopx;
471
 
472
reg fp_infzerox;
473
reg fp_zerozerox;
474
reg fp_subinfx;
475
reg fp_infdivx;
476
reg fp_NaNCmpx;
477
reg fp_cvtx;
478
reg fp_sqrtx;
479
reg fp_snanx;
480
 
481
wire [31:0] fp_status = {
482
 
483
        fp_rm,
484
        fp_inexe,
485
        fp_dbzxe,
486
        fp_underxe,
487
        fp_overxe,
488
        fp_invopxe,
489
        fp_nsfp,
490
 
491
        fp_fractie,
492
        fp_raz,
493
        1'b0,
494
        fp_neg,
495
        fp_pos,
496
        fp_zero,
497
        fp_inf,
498
 
499
        fp_swtx,
500
        fp_inex,
501
        fp_dbzx,
502
        fp_underx,
503
        fp_overx,
504
        fp_giopx,
505
        fp_gx,
506
        fp_sx,
507
 
508
        fp_cvtx,
509
        fp_sqrtx,
510
        fp_NaNCmpx,
511
        fp_infzerox,
512
        fp_zerozerox,
513
        fp_infdivx,
514
        fp_subinfx,
515
        fp_snanx
516
        };
517
 
518
reg [63:0] fpu_csr;
519
wire [5:0] fp_rgs = fpu_csr[37:32];
520
 
521
//reg [25:0] m[0:8191];
522
reg  [3:0] panic;                // indexes the message structure
523
reg [128:0] message [0:15];       // indexed by panic
524
 
525
wire int_commit;
526
reg StatusHWI;
527
(* mark_debug = "true" *)
528
reg [55:0] insn0, insn1, insn2;
529
wire [55:0] insn0a, insn1b, insn2b;
530
reg [55:0] insn1a, insn2a;
531
// Only need enough bits in the seqnence number to cover the instructions in
532
// the queue plus an extra count for skipping on branch misses. In this case
533
// that would be four bits minimum (count 0 to 8). 
534
wire [63:0] rdat0,rdat1,rdat2;
535 61 robfinch
reg [127:0] xdati;
536 60 robfinch
 
537
reg canq1, canq2, canq3;
538
(* mark_debug = "true" *)
539
reg queued1;
540
reg queued2;
541
reg queued3;
542
(* mark_debug = "true" *)
543
reg queuedNop;
544
 
545
reg [47:0] codebuf[0:63];
546
reg [QENTRIES-1:0] setpred;
547
 
548
// instruction queue (ROB)
549
// State and stqte decodes
550
reg [2:0] iqentry_state [0:QENTRIES-1];
551
reg [QENTRIES-1:0] iqentry_v;                    // entry valid?  -- this should be the first bit
552
reg [QENTRIES-1:0] iqentry_done;
553
reg [QENTRIES-1:0] iqentry_out;
554
reg [QENTRIES-1:0] iqentry_agen;
555
reg [`SNBITS] iqentry_sn [0:QENTRIES-1];  // instruction sequence number
556
reg [QENTRIES-1:0] iqentry_iv;           // instruction is valid
557
reg [`QBITSP1] iqentry_is [0:QENTRIES-1];        // source of instruction
558
reg [QENTRIES-1:0] iqentry_thrd;         // which thread the instruction is in
559
reg [QENTRIES-1:0] iqentry_pt;           // predict taken
560
reg [QENTRIES-1:0] iqentry_bt;           // update branch target buffer
561
reg [QENTRIES-1:0] iqentry_takb; // take branch record
562
reg [QENTRIES-1:0] iqentry_jal;
563
reg [2:0] iqentry_sz [0:QENTRIES-1];
564
reg [QENTRIES-1:0] iqentry_alu = 8'h00;  // alu type instruction
565
reg [QENTRIES-1:0] iqentry_alu0;  // only valid on alu #0
566
reg [QENTRIES-1:0] iqentry_fpu;  // floating point instruction
567
reg [QENTRIES-1:0] iqentry_fc;   // flow control instruction
568
reg [QENTRIES-1:0] iqentry_canex = 8'h00;        // true if it's an instruction that can exception
569
reg [QENTRIES-1:0] iqentry_oddball = 8'h00;      // writes to register file
570
reg [QENTRIES-1:0] iqentry_load; // is a memory load instruction
571
reg [QENTRIES-1:0] iqentry_loadv;        // is a volatile memory load instruction
572 61 robfinch
reg [QENTRIES-1:0] iqentry_loadseg;
573 60 robfinch
reg [QENTRIES-1:0] iqentry_store;        // is a memory store instruction
574
reg [QENTRIES-1:0] iqentry_preload;      // is a memory preload instruction
575
reg [QENTRIES-1:0] iqentry_ldcmp;
576
reg [QENTRIES-1:0] iqentry_mem;  // touches memory: 1 if LW/SW
577
reg [QENTRIES-1:0] iqentry_memndx;  // indexed memory operation 
578
reg [2:0] iqentry_memsz [0:QENTRIES-1];   // size of memory op
579
reg [QENTRIES-1:0] iqentry_rmw;  // memory RMW op
580
reg [QENTRIES-1:0] iqentry_push;
581
reg [QENTRIES-1:0] iqentry_memdb;
582
reg [QENTRIES-1:0] iqentry_memsb;
583
reg [QENTRIES-1:0] iqentry_rtop;
584
reg [QENTRIES-1:0] iqentry_sei;
585
reg [QENTRIES-1:0] iqentry_aq;   // memory aquire
586
reg [QENTRIES-1:0] iqentry_rl;   // memory release
587
reg [QENTRIES-1:0] iqentry_shft;
588
reg [QENTRIES-1:0] iqentry_jmp;  // changes control flow: 1 if BEQ/JALR
589
reg [QENTRIES-1:0] iqentry_br;  // Bcc (for predictor)
590
reg [QENTRIES-1:0] iqentry_ret;
591
reg [QENTRIES-1:0] iqentry_irq;
592
reg [QENTRIES-1:0] iqentry_brk;
593
reg [QENTRIES-1:0] iqentry_rti;
594
reg [QENTRIES-1:0] iqentry_sync;  // sync instruction
595
reg [QENTRIES-1:0] iqentry_fsync;
596
reg [QENTRIES-1:0] iqentry_tlb;
597
reg [QENTRIES-1:0] iqentry_cmp;
598
reg [QENTRIES-1:0] iqentry_rfw = 1'b0;   // writes to register file
599
reg [QENTRIES-1:0] iqentry_prfw = 1'b0;
600
reg  [7:0] iqentry_we   [0:QENTRIES-1];   // enable strobe
601
reg [63:0] iqentry_res   [0:QENTRIES-1];  // instruction result
602 61 robfinch
reg [63:0] iqentry_seg_base      [0:QENTRIES-1];  //
603
reg [63:0] iqentry_seg_lb        [0:QENTRIES-1];  //
604
reg [63:0] iqentry_seg_ub        [0:QENTRIES-1];  //
605
reg [63:0] iqentry_seg_acr       [0:QENTRIES-1];  //
606 60 robfinch
reg [63:0] iqentry_ares  [0:QENTRIES-1];  // alternate instruction result
607
reg [47:0] iqentry_instr[0:QENTRIES-1];   // instruction opcode
608
reg  [2:0] iqentry_insln[0:QENTRIES-1]; // instruction length
609
reg  [7:0] iqentry_exc   [0:QENTRIES-1];  // only for branches ... indicates a HALT instruction
610
reg [RBIT:0] iqentry_tgt[0:QENTRIES-1];   // Rt field or ZERO -- this is the instruction's target (if any)
611
reg  [7:0] iqentry_vl   [0:QENTRIES-1];
612
reg  [5:0] iqentry_ven  [0:QENTRIES-1];  // vector element number
613
reg [AMSB:0] iqentry_ma [0:QENTRIES-1];   // memory address
614
reg [63:0] iqentry_a0    [0:QENTRIES-1];  // argument 0 (immediate)
615
reg [63:0] iqentry_a1    [0:QENTRIES-1];  // argument 1
616
reg [QENTRIES-1:0] iqentry_a1_v; // arg1 valid
617
reg [`QBITSP1] iqentry_a1_s     [0:QENTRIES-1];  // arg1 source (iq entry # with top bit representing ALU/DRAM bus)
618
reg [63:0] iqentry_a2    [0:QENTRIES-1];  // argument 2
619
reg        iqentry_a2_v [0:QENTRIES-1];  // arg2 valid
620
reg  [`QBITSP1] iqentry_a2_s    [0:QENTRIES-1];  // arg2 source (iq entry # with top bit representing ALU/DRAM bus)
621
reg [63:0] iqentry_a3    [0:QENTRIES-1];  // argument 3
622
reg        iqentry_a3_v [0:QENTRIES-1];  // arg3 valid
623
reg  [`QBITSP1] iqentry_a3_s    [0:QENTRIES-1];  // arg3 source (iq entry # with top bit representing ALU/DRAM bus)
624
reg [`ABITS] iqentry_pc [0:QENTRIES-1];  // program counter for this instruction
625
reg [RBIT:0] iqentry_Ra [0:QENTRIES-1];
626
reg [RBIT:0] iqentry_Rb [0:QENTRIES-1];
627
reg [RBIT:0] iqentry_Rc [0:QENTRIES-1];
628
 
629
// debugging
630
//reg  [4:0] iqentry_ra   [0:7];  // Ra
631
initial begin
632
for (n = 0; n < QENTRIES; n = n + 1)
633
        iqentry_a1_s[n] <= 5'd0;
634
        iqentry_a2_s[n] <= 5'd0;
635
        iqentry_a3_s[n] <= 5'd0;
636
end
637
 
638
reg [QENTRIES-1:0] iqentry_source = {QENTRIES{1'b0}};
639
reg [QENTRIES-1:0] iqentry_imm;
640
reg [QENTRIES-1:0] iqentry_memready;
641
reg [QENTRIES-1:0] iqentry_memopsvalid;
642
 
643
reg  [QENTRIES-1:0] memissue = {QENTRIES{1'b0}};
644
reg [1:0] missued;
645
reg [7:0] last_issue0, last_issue1, last_issue2;
646
reg  [QENTRIES-1:0] iqentry_memissue;
647
reg [QENTRIES-1:0] iqentry_stomp;
648
reg [3:0] stompedOnRets;
649
reg  [QENTRIES-1:0] iqentry_alu0_issue;
650
reg  [QENTRIES-1:0] iqentry_alu1_issue;
651
reg  [QENTRIES-1:0] iqentry_alu2_issue;
652
reg  [QENTRIES-1:0] iqentry_id1issue;
653
reg  [QENTRIES-1:0] iqentry_id2issue;
654
reg  [QENTRIES-1:0] iqentry_id3issue;
655
reg [1:0] iqentry_mem_islot [0:QENTRIES-1];
656
reg [QENTRIES-1:0] iqentry_fcu_issue;
657
reg [QENTRIES-1:0] iqentry_fpu1_issue;
658
reg [QENTRIES-1:0] iqentry_fpu2_issue;
659
 
660
reg [PREGS-1:1] livetarget;
661
reg [PREGS-1:1] iqentry_livetarget [0:QENTRIES-1];
662
reg [PREGS-1:1] iqentry_latestID [0:QENTRIES-1];
663
reg [PREGS-1:1] iqentry_cumulative [0:QENTRIES-1];
664
wire  [PREGS-1:1] iq_out [0:QENTRIES-1];
665
 
666
reg  [`QBITS] tail0;
667
reg  [`QBITS] tail1;
668
reg  [`QBITS] tail2;
669
reg  [`QBITS] heads[0:QENTRIES-1];
670
 
671
// To detect a head change at time of commit. Some values need to pulsed
672
// with a single pulse.
673
reg  [`QBITS] ohead[0:2];
674
reg ocommit0_v, ocommit1_v, ocommit2_v;
675
reg [11:0] cmt_timer;
676
 
677
wire take_branch0;
678
wire take_branch1;
679
 
680
reg [3:0] nop_fetchbuf;
681
wire        fetchbuf;   // determines which pair to read from & write to
682
wire [3:0] fb_panic;
683
 
684
wire [47:0] fetchbuf0_instr;
685
wire  [2:0] fetchbuf0_insln;
686
wire [`ABITS] fetchbuf0_pc;
687
(* mark_debug = "true" *)
688
wire        fetchbuf0_v;
689
wire            fetchbuf0_thrd;
690
wire            fetchbuf0_mem;
691
wire        fetchbuf0_rfw;
692
wire [47:0] fetchbuf1_instr;
693
wire  [2:0] fetchbuf1_insln;
694
wire [`ABITS] fetchbuf1_pc;
695
wire        fetchbuf1_v;
696
wire            fetchbuf1_thrd;
697
wire            fetchbuf1_mem;
698
wire        fetchbuf1_rfw;
699
wire [47:0] fetchbuf2_instr;
700
wire  [2:0] fetchbuf2_insln;
701
wire [`ABITS] fetchbuf2_pc;
702
wire        fetchbuf2_v;
703
wire            fetchbuf2_thrd;
704
wire            fetchbuf2_mem;
705
wire        fetchbuf2_rfw;
706
wire [47:0] fetchbufA_instr;
707
wire [`ABITS] fetchbufA_pc;
708
wire        fetchbufA_v;
709
wire [47:0] fetchbufB_instr;
710
wire [`ABITS] fetchbufB_pc;
711
wire        fetchbufB_v;
712
wire [47:0] fetchbufC_instr;
713
wire [`ABITS] fetchbufC_pc;
714
wire        fetchbufC_v;
715
wire [47:0] fetchbufD_instr;
716
wire [`ABITS] fetchbufD_pc;
717
wire        fetchbufD_v;
718
wire [47:0] fetchbufE_instr;
719
wire [`ABITS] fetchbufE_pc;
720
wire        fetchbufE_v;
721
wire [47:0] fetchbufF_instr;
722
wire [`ABITS] fetchbufF_pc;
723
wire        fetchbufF_v;
724
 
725
//reg        did_branchback0;
726
//reg        did_branchback1;
727
 
728
reg         id1_v;
729
reg   [`QBITSP1] id1_id;
730
reg  [47:0] id1_instr;
731
reg   [5:0] id1_ven;
732
reg   [7:0] id1_vl;
733
reg         id1_thrd;
734
reg         id1_pt;
735
reg   [4:0] id1_Rt;
736
wire [143:0] id1_bus;
737
 
738
reg         id2_v;
739
reg   [`QBITSP1] id2_id;
740
reg  [47:0] id2_instr;
741
reg   [5:0] id2_ven;
742
reg   [7:0] id2_vl;
743
reg         id2_thrd;
744
reg         id2_pt;
745
reg   [4:0] id2_Rt;
746
wire [143:0] id2_bus;
747
 
748
reg         id3_v;
749
reg   [`QBITSP1] id3_id;
750
reg  [47:0] id3_instr;
751
reg   [5:0] id3_ven;
752
reg   [7:0] id3_vl;
753
reg         id3_thrd;
754
reg         id3_pt;
755
reg   [4:0] id3_Rt;
756
wire [143:0] id3_bus;
757
 
758
reg [63:0] alu0_xs = 64'd0;
759
reg [63:0] alu1_xs = 64'd0;
760
 
761
reg [3:0]  alu0_pred;
762
reg                             alu0_cmt;
763
wire                            alu0_abort;
764
reg        alu0_ld;
765
reg        alu0_dataready;
766
wire       alu0_done;
767
wire       alu0_idle;
768
reg  [`QBITSP1] alu0_sourceid;
769
reg [47:0] alu0_instr;
770
reg                              alu0_tlb;
771
reg        alu0_mem;
772
reg        alu0_load;
773
reg        alu0_store;
774
reg                      alu0_push;
775
reg        alu0_shft;
776
reg [RBIT:0] alu0_Ra;
777
reg [63:0] alu0_argA;
778
reg [63:0] alu0_argB;
779
reg [63:0] alu0_argC;
780
reg [63:0] alu0_argT;
781
reg [63:0] alu0_argI;    // only used by BEQ
782
reg [2:0]  alu0_sz;
783
reg [RBIT:0] alu0_tgt;
784
reg [5:0]  alu0_ven;
785
reg        alu0_thrd;
786
reg [`ABITS] alu0_pc;
787
reg [63:0] alu0_bus;
788
wire [63:0] alu0b_bus;
789
wire [63:0] alu0_out;
790
wire  [`QBITSP1] alu0_id;
791
wire  [`XBITS] alu0_exc;
792
wire        alu0_v;
793
wire        alu0_branchmiss;
794
wire [`ABITS] alu0_misspc;
795
 
796
reg [3:0]  alu1_pred;
797
reg                             alu1_cmt;
798
wire                            alu1_abort;
799
reg        alu1_ld;
800
reg        alu1_dataready;
801
wire       alu1_done;
802
wire       alu1_idle;
803
reg  [`QBITSP1] alu1_sourceid;
804
reg [47:0] alu1_instr;
805
reg        alu1_mem;
806
reg        alu1_load;
807
reg        alu1_store;
808
reg                      alu1_push;
809
reg        alu1_shft;
810
reg [RBIT:0] alu1_Ra;
811
reg [63:0] alu1_argA;
812
reg [63:0] alu1_argB;
813
reg [63:0] alu1_argC;
814
reg [63:0] alu1_argT;
815
reg [63:0] alu1_argI;    // only used by BEQ
816
reg [2:0]  alu1_sz;
817
reg [RBIT:0] alu1_tgt;
818
reg [5:0]  alu1_ven;
819
reg [`ABITS] alu1_pc;
820
reg        alu1_thrd;
821
reg [63:0] alu1_bus;
822
wire [63:0] alu1b_bus;
823
wire [63:0] alu1_out;
824
wire  [`QBITSP1] alu1_id;
825
wire  [`XBITS] alu1_exc;
826
wire        alu1_v;
827
wire        alu1_branchmiss;
828
wire [`ABITS] alu1_misspc;
829
 
830
wire [`XBITS] fpu_exc;
831
reg [3:0] fpu1_pred;
832
reg                             fpu1_cmt;
833
reg        fpu1_ld;
834
reg        fpu1_dataready = 1'b1;
835
wire       fpu1_done = 1'b1;
836
wire       fpu1_idle;
837
reg [`QBITSP1] fpu1_sourceid;
838
reg [47:0] fpu1_instr;
839
reg [63:0] fpu1_argA;
840
reg [63:0] fpu1_argB;
841
reg [63:0] fpu1_argC;
842
reg [63:0] fpu1_argT;
843
reg [63:0] fpu1_argI;    // only used by BEQ
844
reg [RBIT:0] fpu1_tgt;
845
reg [`ABITS] fpu1_pc;
846
wire [63:0] fpu1_out = 64'h0;
847
reg [63:0] fpu1_bus = 64'h0;
848
wire  [`QBITSP1] fpu1_id;
849
wire  [`XBITS] fpu1_exc = 9'h000;
850
wire        fpu1_v;
851
wire [31:0] fpu1_status;
852
 
853
reg [3:0] fpu2_pred;
854
reg                             fpu2_cmt;
855
reg        fpu2_ld;
856
reg        fpu2_dataready = 1'b1;
857
wire       fpu2_done = 1'b1;
858
wire       fpu2_idle;
859
reg [`QBITSP1] fpu2_sourceid;
860
reg [47:0] fpu2_instr;
861
reg [63:0] fpu2_argA;
862
reg [63:0] fpu2_argB;
863
reg [63:0] fpu2_argC;
864
reg [63:0] fpu2_argT;
865
reg [63:0] fpu2_argI;    // only used by BEQ
866
reg [RBIT:0] fpu2_tgt;
867
reg [`ABITS] fpu2_pc;
868
wire [63:0] fpu2_out = 64'h0;
869
reg [63:0] fpu2_bus = 64'h0;
870
wire  [`QBITSP1] fpu2_id;
871
wire  [`XBITS] fpu2_exc = 9'h000;
872
wire        fpu2_v;
873
wire [31:0] fpu2_status;
874
 
875
reg [7:0] fccnt;
876
reg [47:0] waitctr;
877
reg [3:0] fcu_pred;
878
reg                             fcu_cmt;
879
reg        fcu_ld;
880
reg        fcu_dataready;
881
reg        fcu_done;
882
reg         fcu_idle = 1'b1;
883
reg [`QBITSP1] fcu_sourceid;
884
reg [47:0] fcu_instr;
885
reg [47:0] fcu_prevInstr;
886
reg  [2:0] fcu_insln;
887
reg        fcu_pt;                      // predict taken
888
reg        fcu_branch;
889
reg        fcu_call;
890
reg        fcu_ret;
891
reg        fcu_jal;
892
reg        fcu_brk;
893
reg        fcu_rti;
894
reg [63:0] fcu_argA;
895
reg [63:0] fcu_argB;
896
reg [63:0] fcu_argC;
897
reg [63:0] fcu_argI;     // only used by BEQ
898
reg [63:0] fcu_argT;
899
reg [63:0] fcu_argT2;
900 61 robfinch
reg [63:0] fcu_epc;
901
reg [23:0] fcu_ecs;              // excepted code segment
902
reg [23:0] fcu_rs;               // return selector
903 60 robfinch
reg [`ABITS] fcu_pc;
904
reg [`ABITS] fcu_nextpc;
905
reg [`ABITS] fcu_brdisp;
906
wire [63:0] fcu_out;
907
reg [63:0] fcu_bus;
908
wire  [`QBITSP1] fcu_id;
909
reg   [`XBITS] fcu_exc;
910
wire        fcu_v;
911
reg        fcu_thrd;
912
reg        fcu_branchmiss;
913
reg  fcu_clearbm;
914
reg [`ABITS] fcu_misspc;
915
 
916
reg [63:0] rmw_argA;
917
reg [63:0] rmw_argB;
918
reg [63:0] rmw_argC;
919
wire [63:0] rmw_res;
920
reg [47:0] rmw_instr;
921
 
922
// write buffer
923
reg [63:0] wb_data [0:`WB_DEPTH-1];
924
reg [`ABITS] wb_addr [0:`WB_DEPTH-1];
925
reg [1:0] wb_ol [0:`WB_DEPTH-1];
926
reg [`WB_DEPTH-1:0] wb_v;
927
reg [`WB_DEPTH-1:0] wb_rmw;
928
reg [QENTRIES-1:0] wb_id [0:`WB_DEPTH-1];
929
reg [QENTRIES-1:0] wbo_id;
930
reg [7:0] wb_sel [0:`WB_DEPTH-1];
931
reg wb_en;
932
reg wb_shift;
933
 
934
reg branchmiss = 1'b0;
935
reg branchmiss_thrd = 1'b0;
936
reg [`ABITS] misspc;
937
reg  [`QBITS] missid;
938
 
939
wire take_branch;
940
wire take_branchA;
941
wire take_branchB;
942
wire take_branchC;
943
wire take_branchD;
944
 
945
wire        dram_avail;
946
reg      [2:0] dram0;    // state of the DRAM request (latency = 4; can have three in pipeline)
947
reg      [2:0] dram1;    // state of the DRAM request (latency = 4; can have three in pipeline)
948
reg      [2:0] dram2;    // state of the DRAM request (latency = 4; can have three in pipeline)
949
reg [63:0] dram0_data;
950
reg [`ABITS] dram0_addr;
951
reg [47:0] dram0_instr;
952
reg        dram0_rmw;
953
reg                dram0_preload;
954
reg [RBIT:0] dram0_tgt;
955
reg  [`QBITSP1] dram0_id;
956
reg        dram0_unc;
957
reg [2:0]  dram0_memsize;
958
reg        dram0_load;  // is a load operation
959 61 robfinch
reg                      dram0_loadseg;
960 60 robfinch
reg        dram0_store;
961
reg  [1:0] dram0_ol;
962
reg [63:0] dram1_data;
963
reg [`ABITS] dram1_addr;
964
reg [47:0] dram1_instr;
965
reg        dram1_rmw;
966
reg                dram1_preload;
967
reg [RBIT:0] dram1_tgt;
968
reg  [`QBITSP1] dram1_id;
969
reg        dram1_unc;
970
reg [2:0]  dram1_memsize;
971
reg        dram1_load;
972 61 robfinch
reg                      dram1_loadseg;
973 60 robfinch
reg        dram1_store;
974
reg  [1:0] dram1_ol;
975
reg [63:0] dram2_data;
976
reg [`ABITS] dram2_addr;
977
reg [47:0] dram2_instr;
978
reg        dram2_rmw;
979
reg                dram2_preload;
980
reg [RBIT:0] dram2_tgt;
981
reg  [`QBITSP1] dram2_id;
982
reg        dram2_unc;
983
reg [2:0]  dram2_memsize;
984
reg        dram2_load;
985 61 robfinch
reg                      dram2_loadseg;
986 60 robfinch
reg        dram2_store;
987
reg  [1:0] dram2_ol;
988
 
989
reg        dramA_v;
990
reg  [`QBITSP1] dramA_id;
991
reg [63:0] dramA_bus;
992
reg        dramB_v;
993
reg  [`QBITSP1] dramB_id;
994
reg [63:0] dramB_bus;
995
reg        dramC_v;
996
reg  [`QBITSP1] dramC_id;
997
reg [63:0] dramC_bus;
998
 
999
wire        outstanding_stores;
1000
reg [63:0] I;            // instruction count
1001
reg [63:0] CC;   // commit count
1002
 
1003
reg        commit0_v;
1004
reg  [`QBITSP1] commit0_id;
1005
reg [RBIT:0] commit0_tgt;
1006
reg  [7:0] commit0_we = 8'h00;
1007
reg [63:0] commit0_bus;
1008
reg        commit1_v;
1009
reg  [`QBITSP1] commit1_id;
1010
reg [RBIT:0] commit1_tgt;
1011
reg  [7:0] commit1_we = 8'h00;
1012
reg [63:0] commit1_bus;
1013
reg        commit2_v;
1014
reg  [`QBITSP1] commit2_id;
1015
reg [RBIT:0] commit2_tgt;
1016
reg  [7:0] commit2_we = 8'h00;
1017
reg [63:0] commit2_bus;
1018
 
1019
reg StoreAck1;
1020
reg [4:0] bstate;
1021
parameter BIDLE = 5'd0;
1022
parameter B_StoreAck = 5'd1;
1023
parameter B_DCacheLoadStart = 5'd2;
1024
parameter B_DCacheLoadStb = 5'd3;
1025
parameter B_DCacheLoadWait1 = 5'd4;
1026
parameter B_DCacheLoadWait2 = 5'd5;
1027
parameter B_DCacheLoadResetBusy = 5'd6;
1028
parameter B_ICacheAck = 5'd7;
1029
parameter B8 = 5'd8;
1030
parameter B_ICacheNack = 5'd9;
1031
parameter B_ICacheNack2 = 5'd10;
1032
parameter B11 = 5'd11;
1033
parameter B12 = 5'd12;
1034
parameter B_DLoadAck = 5'd13;
1035
parameter B14 = 5'd14;
1036
parameter B15 = 5'd15;
1037
parameter B16 = 5'd16;
1038
parameter B17 = 5'd17;
1039
parameter B18 = 5'd18;
1040 61 robfinch
parameter B_LSNAck = 5'd19;
1041 60 robfinch
parameter B2a = 5'd20;
1042
parameter B2b = 5'd21;
1043
parameter B2c = 5'd22;
1044
parameter B_DCacheLoadAck = 5'd23;
1045
parameter B20 = 5'd24;
1046
parameter B21 = 5'd25;
1047
parameter B_DCacheLoadWait3 = 5'd26;
1048 61 robfinch
parameter B_LoadDesc = 5'd27;
1049
parameter B_LoadDescStb = 5'd28;
1050
parameter B_WaitSeg = 5'd29;
1051
parameter B_DLoadNack = 5'd30;
1052
parameter SEG_IDLE = 2'd0;
1053
parameter SEG_CHK = 2'd1;
1054
parameter SEG_UPD = 2'd2;
1055
parameter SEG_DONE = 2'd3;
1056 60 robfinch
reg [1:0] bwhich;
1057
reg [3:0] icstate,picstate;
1058
parameter IDLE = 4'd0;
1059
parameter IC1 = 4'd1;
1060
parameter IC2 = 4'd2;
1061
parameter IC3 = 4'd3;
1062
parameter IC_WaitL2 = 4'd4;
1063
parameter IC5 = 4'd5;
1064
parameter IC6 = 4'd6;
1065
parameter IC7 = 4'd7;
1066
parameter IC_Next = 4'd8;
1067
parameter IC9 = 4'd9;
1068
parameter IC10 = 4'd10;
1069
parameter IC3a = 4'd11;
1070
reg invic, invdc;
1071
reg [1:0] icwhich;
1072
reg icnxt,L2_nxt;
1073
wire ihit0,ihit1,ihit2,ihitL2;
1074
wire ihit = ihit0&ihit1&ihit2;
1075
reg phit;
1076
wire threadx;
1077
always @*
1078
        phit <= ihit&&icstate==IDLE;
1079
reg [2:0] iccnt;
1080 61 robfinch
(* mark_debug="true" *)
1081
reg icack;
1082 60 robfinch
reg L1_wr0,L1_wr1,L1_wr2;
1083
reg L1_invline;
1084
wire [1:0] ic0_fault,ic1_fault,ic2_fault;
1085 61 robfinch
reg [9:0] L1_en;
1086 60 robfinch
reg [71:0] L1_adr, L2_adr;
1087 61 robfinch
reg [305:0] L1_dati;
1088
wire [305:0] L2_dato;
1089 60 robfinch
reg L2_xsel;
1090
 
1091
generate begin : gRegfileInst
1092
if (`WAYS > 2) begin : gb1
1093
FT64_regfile2w9r_oc #(.RBIT(RBIT)) urf1
1094
(
1095
  .clk(clk),
1096
  .clk4x(clk4x),
1097
  .wr0(commit0_v),
1098
  .wr1(commit1_v),
1099
  .we0(commit0_we),
1100
  .we1(commit1_we),
1101
  .wa0(commit0_tgt),
1102
  .wa1(commit1_tgt),
1103
  .i0(commit0_bus),
1104
  .i1(commit1_bus),
1105
        .rclk(~clk),
1106
        .ra0(Ra0),
1107
        .ra1(Rb0),
1108
        .ra2(Rc0),
1109
        .o0(rfoa0),
1110
        .o1(rfob0),
1111
        .o2(rfoc0a),
1112
        .ra3(Ra1),
1113
        .ra4(Rb1),
1114
        .ra5(Rc1),
1115
        .o3(rfoa1),
1116
        .o4(rfob1),
1117
        .o5(rfoc1a),
1118
        .ra6(Ra2),
1119
        .ra7(Rb2),
1120
        .ra8(Rc2),
1121
        .o6(rfoa2),
1122
        .o7(rfob2),
1123
        .o8(rfoc2a)
1124
);
1125
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
1126
assign rfoc1 = Rc1[11:6]==6'h3F ? vm[Rc1[2:0]] : rfoc1a;
1127
assign rfoc2 = Rc2[11:6]==6'h3F ? vm[Rc2[2:0]] : rfoc2a;
1128
end
1129
else if (`WAYS > 1) begin : gb1
1130
FT64_regfile2w6r_oc #(.RBIT(RBIT)) urf1
1131
(
1132
  .clk(clk),
1133
  .clk4x(clk4x),
1134
  .wr0(commit0_v),
1135
  .wr1(commit1_v),
1136
  .we0(commit0_we),
1137
  .we1(commit1_we),
1138
  .wa0(commit0_tgt),
1139
  .wa1(commit1_tgt),
1140
  .i0(commit0_bus),
1141
  .i1(commit1_bus),
1142
        .rclk(~clk),
1143
        .ra0(Ra0),
1144
        .ra1(Rb0),
1145
        .ra2(Rc0),
1146
        .o0(rfoa0),
1147
        .o1(rfob0),
1148
        .o2(rfoc0a),
1149
        .ra3(Ra1),
1150
        .ra4(Rb1),
1151
        .ra5(Rc1),
1152
        .o3(rfoa1),
1153
        .o4(rfob1),
1154
        .o5(rfoc1a)
1155
);
1156
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
1157
assign rfoc1 = Rc1[11:6]==6'h3F ? vm[Rc1[2:0]] : rfoc1a;
1158
end
1159
else begin : gb1
1160
FT64_regfile1w4r_oc #(.RBIT(RBIT)) urf1
1161
(
1162
  .clk(clk),
1163
  .wr0(commit0_v),
1164
  .wa0(commit0_tgt),
1165
  .we0(8'hFF),
1166
  .i0(commit0_bus),
1167
  .rclk(~clk),
1168
        .ra0(Ra0),
1169
        .ra1(Rb0),
1170
        .ra2(Rc0),
1171
        .ra3(Rt0),
1172
        .o0(rfoa0),
1173
        .o1(rfob0),
1174
        .o2(rfoc0a),
1175
        .o3(rfot0)
1176
);
1177
end
1178
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
1179
end
1180
endgenerate
1181
 
1182
function [3:0] fnInsLength;
1183
input [47:0] ins;
1184
`ifdef SUPPORT_DCI
1185
if (ins[`INSTRUCTION_OP]==`CMPRSSD)
1186
        fnInsLength = 4'd2 | pred_on;
1187
else
1188
`endif
1189
        case(ins[7:6])
1190
        2'd0:   fnInsLength = 4'd4 | pred_on;
1191
        2'd1:   fnInsLength = 4'd6 | pred_on;
1192
        default:        fnInsLength = 4'd2 | pred_on;
1193
        endcase
1194
endfunction
1195
 
1196
wire [`ABITS] pc0plus6 = pc0 + 32'd7;
1197
wire [`ABITS] pc0plus12 = pc0 + 32'd14;
1198
 
1199
generate begin : gInsnVar
1200
        if (`WAYS > 1) begin
1201
                always @*
1202
                        if (thread_en)
1203
                                insn1a <= insn1b;
1204
                        else
1205
                                insn1a <= {insn1b,insn0a} >> {fnInsLength(insn0a),3'b0};
1206
        end
1207
        if (`WAYS > 2) begin
1208
                always @*
1209
                        if (thread_en)
1210
                                insn2a <= insn2b;
1211
                        else
1212
                                insn2a <= {insn2b,insn1b,insn0a} >> {fnInsLength(insn0a) + fnInsLength(insn1a),3'b0};
1213
        end
1214
end
1215
endgenerate
1216
 
1217
FT64_L1_icache #(.pSize(`L1_ICACHE_SIZE)) uic0
1218
(
1219
  .rst(rst),
1220
  .clk(clk),
1221
  .nxt(icnxt),
1222
  .wr(L1_wr0),
1223
  .wr_ack(),
1224
  .en(L1_en),
1225
  .adr((icstate==IDLE||icstate==IC_Next) ? {pcr[7:0],pc0} : L1_adr),
1226
  .wadr(L1_adr),
1227 61 robfinch
  .i(L1_dati),
1228 60 robfinch
  .o(insn0a),
1229
  .fault(ic0_fault),
1230
  .hit(ihit0),
1231
  .invall(invic),
1232
  .invline(L1_invline)
1233
);
1234
generate begin : gICacheInst
1235
if (`WAYS > 1) begin
1236
FT64_L1_icache #(.pSize(`L1_ICACHE_SIZE)) uic1
1237
(
1238
  .rst(rst),
1239
  .clk(clk),
1240
  .nxt(icnxt),
1241
  .wr(L1_wr1),
1242
  .wr_ack(),
1243
  .en(L1_en),
1244
  .adr((icstate==IDLE||icstate==IC_Next) ? (thread_en ? {pcr[7:0],pc1}: {pcr[7:0],pc0plus6} ): L1_adr),
1245
  .wadr(L1_adr),
1246 61 robfinch
  .i(L1_dati),
1247 60 robfinch
  .o(insn1b),
1248
  .fault(ic1_fault),
1249
  .hit(ihit1),
1250
  .invall(invic),
1251
  .invline(L1_invline)
1252
);
1253
end
1254
else begin
1255
assign ihit1 = 1'b1;
1256
end
1257
if (`WAYS > 2) begin
1258
FT64_L1_icache #(.pSize(`L1_ICACHE_SIZE)) uic2
1259
(
1260
  .rst(rst),
1261
  .clk(clk),
1262
  .nxt(icnxt),
1263
  .wr(L1_wr2),
1264
  .wr_ack(),
1265
  .en(L1_en),
1266
  .adr((icstate==IDLE||icstate==IC_Next) ? (thread_en ? {pcr[7:0],pc2} : {pcr[7:0],pc0plus12}) : L1_adr),
1267
  .wadr(L1_adr),
1268 61 robfinch
  .i(L1_dati),
1269 60 robfinch
  .o(insn2b),
1270
  .fault(ic2_fault),
1271
  .hit(ihit2),
1272
  .invall(invic),
1273
  .invline(L1_invline)
1274
);
1275
end
1276
else
1277
assign ihit2 = 1'b1;
1278
end
1279
endgenerate
1280
 
1281
FT64_L2_icache uic2
1282
(
1283
  .rst(rst),
1284
  .clk(clk),
1285
  .nxt(L2_nxt),
1286
  .wr(bstate==B_ICacheAck && (ack_i|err_i)),
1287
  .xsel(L2_xsel),
1288
  .adr(L2_adr),
1289
  .cnt(iccnt),
1290
  .exv_i(exvq),
1291
  .i(dat_i),
1292
  .err_i(errq),
1293
  .o(L2_dato),
1294
  .hit(ihitL2),
1295
  .invall(invic),
1296
  .invline()
1297
);
1298
 
1299
wire predict_taken;
1300
wire predict_taken0;
1301
wire predict_taken1;
1302
wire predict_taken2;
1303
wire predict_takenA;
1304
wire predict_takenB;
1305
wire predict_takenC;
1306
wire predict_takenD;
1307
wire predict_takenE;
1308
wire predict_takenF;
1309
wire predict_takenA1;
1310
wire predict_takenB1;
1311
wire predict_takenC1;
1312
wire predict_takenD1;
1313
 
1314
wire [`ABITS] btgtA, btgtB, btgtC, btgtD, btgtE, btgtF;
1315
wire btbwr0 = iqentry_v[heads[0]] && iqentry_state[heads[0]]==IQS_CMT &&
1316
        (iqentry_fc[heads[0]]);
1317
generate begin: gbtbvar
1318
if (`WAYS > 1) begin
1319
wire btbwr1 = iqentry_v[heads[1]] && iqentry_state[heads[1]]==IQS_CMT &&
1320
        (iqentry_fc[heads[1]]);
1321
end
1322
if (`WAYS > 2) begin
1323
wire btbwr2 = iqentry_v[heads[2]] && iqentry_state[heads[2]]==IQS_CMT &&
1324
        (iqentry_fc[heads[2]]);
1325
end
1326
end
1327
endgenerate
1328
 
1329
wire fcu_clk;
1330
`ifdef FCU_ENH
1331
//BUFGCE ufcuclk
1332
//(
1333
//      .I(clk_i),
1334
//      .CE(fcu_available),
1335
//      .O(fcu_clk)
1336
//);
1337
`endif
1338
assign fcu_clk = clk_i;
1339
 
1340
generate begin: gBTBInst
1341
if (`WAYS > 2) begin
1342
`ifdef FCU_ENH
1343
FT64_BTB #(.AMSB(AMSB)) ubtb1
1344
(
1345
  .rst(rst),
1346
  .wclk(fcu_clk),
1347
  .wr0(btbwr0),
1348
  .wadr0(iqentry_pc[heads[0]]),
1349
  .wdat0(iqentry_ma[heads[0]]),
1350
  .valid0((iqentry_br[heads[0]] ? iqentry_takb[heads[0]] : iqentry_bt[heads[0]]) & iqentry_v[heads[0]]),
1351
  .wr1(btbwr1),
1352
  .wadr1(iqentry_pc[heads[1]]),
1353
  .wdat1(iqentry_ma[heads[1]]),
1354
  .valid1((iqentry_br[heads[1]] ? iqentry_takb[heads[1]] : iqentry_bt[heads[1]]) & iqentry_v[heads[1]]),
1355
  .wr2(btbwr2),
1356
  .wadr2(iqentry_pc[heads[2]]),
1357
  .wdat2(iqentry_ma[heads[2]]),
1358
  .valid2((iqentry_br[heads[2]] ? iqentry_takb[heads[2]] : iqentry_bt[heads[2]]) & iqentry_v[heads[2]]),
1359
  .rclk(~clk),
1360
  .pcA(fetchbufA_pc),
1361
  .btgtA(btgtA),
1362
  .pcB(fetchbufB_pc),
1363
  .btgtB(btgtB),
1364
  .pcC(fetchbufC_pc),
1365
  .btgtC(btgtC),
1366
  .pcD(fetchbufD_pc),
1367
  .btgtD(btgtD),
1368
  .pcE(fetchbufE_pc),
1369
  .btgtE(btgtE),
1370
  .pcF(fetchbufF_pc),
1371
  .btgtF(btgtF),
1372
  .npcA(BRKPC),
1373
  .npcB(BRKPC),
1374
  .npcC(BRKPC),
1375
  .npcD(BRKPC),
1376
  .npcE(BRKPC),
1377
  .npcF(BRKPC)
1378
);
1379
`else
1380
// Branch tergets are picked up by fetchbuf logic and need to be present.
1381
// Without a target predictor they are just set to the reset address.
1382
// This virtually guarentees a miss.
1383
assign btgtA = RSTPC;
1384
assign btgtB = RSTPC;
1385
assign btgtC = RSTPC;
1386
assign btgtD = RSTPC;
1387
assign btgtE = RSTPC;
1388
assign btgtF = RSTPC;
1389
`endif
1390
end
1391
else if (`WAYS > 1) begin
1392
`ifdef FCU_ENH
1393
FT64_BTB #(.AMSB(AMSB)) ubtb1
1394
(
1395
  .rst(rst),
1396
  .wclk(fcu_clk),
1397
  .wr0(btbwr0),
1398
  .wadr0(iqentry_pc[heads[0]]),
1399
  .wdat0(iqentry_ma[heads[0]]),
1400
  .valid0((iqentry_br[heads[0]] ? iqentry_takb[heads[0]] : iqentry_bt[heads[0]]) & iqentry_v[heads[0]]),
1401
  .wr1(btbwr1),
1402
  .wadr1(iqentry_pc[heads[1]]),
1403
  .wdat1(iqentry_ma[heads[1]]),
1404
  .valid1((iqentry_br[heads[1]] ? iqentry_takb[heads[1]] : iqentry_bt[heads[1]]) & iqentry_v[heads[1]]),
1405
  .rclk(~clk),
1406
  .pcA(fetchbufA_pc),
1407
  .btgtA(btgtA),
1408
  .pcB(fetchbufB_pc),
1409
  .btgtB(btgtB),
1410
  .pcC(fetchbufC_pc),
1411
  .btgtC(btgtC),
1412
  .pcD(fetchbufD_pc),
1413
  .btgtD(btgtD),
1414
  .pcE(32'd0),
1415
  .btgtE(),
1416
  .pcF(32'd0),
1417
  .btgtF(),
1418
  .npcA(BRKPC),
1419
  .npcB(BRKPC),
1420
  .npcC(BRKPC),
1421
  .npcD(BRKPC),
1422
  .npcE(BRKPC),
1423
  .npcF(BRKPC)
1424
);
1425
`else
1426
// Branch tergets are picked up by fetchbuf logic and need to be present.
1427
// Without a target predictor they are just set to the reset address.
1428
// This virtually guarentees a miss.
1429
assign btgtA = RSTPC;
1430
assign btgtB = RSTPC;
1431
assign btgtC = RSTPC;
1432
assign btgtD = RSTPC;
1433
`endif
1434
end
1435
else begin
1436
`ifdef FCU_ENH
1437
FT64_BTB #(.AMSB(AMSB)) ubtb1
1438
(
1439
  .rst(rst),
1440
  .wclk(fcu_clk),
1441
  .wr0(btbwr0),
1442
  .wadr0(iqentry_pc[heads[0]]),
1443
  .wdat0(iqentry_ma[heads[0]]),
1444
  .valid0((iqentry_br[heads[0]] ? iqentry_takb[heads[0]] : iqentry_bt[heads[0]]) & iqentry_v[heads[0]]),
1445
  .wr1(1'b0);
1446
  .wadr1(RSTPC),
1447
  .wdat1(RSTPC),
1448
  .valid1(1'b0),
1449
  .wr2(1'b0);
1450
  .wadr2(RSTPC),
1451
  .wdat2(RSTPC),
1452
  .valid2(1'b0),
1453
  .rclk(~clk),
1454
  .pcA(fetchbufA_pc),
1455
  .btgtA(btgtA),
1456
  .pcB(fetchbufB_pc),
1457
  .btgtB(btgtB),
1458
  .pcC(32'd0),
1459
  .btgtC(),
1460
  .pcD(32'd0),
1461
  .btgtD(),
1462
  .pcE(32'd0),
1463
  .btgtE(),
1464
  .pcF(32'd0),
1465
  .btgtF(),
1466
  .hitA(),
1467
  .hitB(),
1468
  .hitC(),
1469
  .hitD(),
1470
  .hitE(),
1471
  .hitF(),
1472
  .npcA(BRKPC),
1473
  .npcB(BRKPC),
1474
  .npcC(BRKPC),
1475
  .npcD(BRKPC),
1476
  .npcE(BRKPC),
1477
  .npcF(BRKPC)
1478
);
1479
`else
1480
// Branch tergets are picked up by fetchbuf logic and need to be present.
1481
// Without a target predictor they are just set to the reset address.
1482
// This virtually guarentees a miss.
1483
assign btgtA = RSTPC;
1484
assign btgtB = RSTPC;
1485
`endif
1486
end
1487
end
1488
endgenerate
1489
 
1490
generate begin: gBPInst
1491
if (`WAYS > 2) begin
1492
`ifdef FCU_ENH
1493
FT64_BranchPredictor ubp1
1494
(
1495
  .rst(rst),
1496
  .clk(fcu_clk),
1497
  .en(bpe),
1498
  .xisBranch0(iqentry_br[heads[0]] & commit0_v),
1499
  .xisBranch1(iqentry_br[heads[1]] & commit1_v),
1500
  .xisBranch2(iqentry_br[heads[2]] & commit2_v),
1501
  .pcA(fetchbufA_pc),
1502
  .pcB(fetchbufB_pc),
1503
  .pcC(fetchbufC_pc),
1504
  .pcD(fetchbufD_pc),
1505
  .pcE(fetchbufE_pc),
1506
  .pcF(fetchbufF_pc),
1507
  .xpc0(iqentry_pc[heads[0]]),
1508
  .xpc1(iqentry_pc[heads[1]]),
1509
  .xpc2(iqentry_pc[heads[2]]),
1510
  .takb0(commit0_v & iqentry_takb[heads[0]]),
1511
  .takb1(commit1_v & iqentry_takb[heads[1]]),
1512
  .takb2(commit2_v & iqentry_takb[heads[2]]),
1513
  .predict_takenA(predict_takenA),
1514
  .predict_takenB(predict_takenB),
1515
  .predict_takenC(predict_takenC),
1516
  .predict_takenD(predict_takenD),
1517
  .predict_takenE(predict_takenE),
1518
  .predict_takenF(predict_takenF)
1519
);
1520
`else
1521
// Predict based on sign of displacement
1522
assign predict_takenA = fetchbufA_instr[6] ? fetchbufA_instr[47] : fetchbufA_instr[31];
1523
assign predict_takenB = fetchbufB_instr[6] ? fetchbufB_instr[47] : fetchbufB_instr[31];
1524
assign predict_takenC = fetchbufC_instr[6] ? fetchbufC_instr[47] : fetchbufC_instr[31];
1525
assign predict_takenD = fetchbufD_instr[6] ? fetchbufD_instr[47] : fetchbufD_instr[31];
1526
assign predict_takenE = fetchbufE_instr[6] ? fetchbufE_instr[47] : fetchbufE_instr[31];
1527
assign predict_takenF = fetchbufF_instr[6] ? fetchbufF_instr[47] : fetchbufF_instr[31];
1528
`endif
1529
end
1530
else if (`WAYS > 1) begin
1531
`ifdef FCU_ENH
1532
FT64_BranchPredictor ubp1
1533
(
1534
  .rst(rst),
1535
  .clk(fcu_clk),
1536
  .en(bpe),
1537
  .xisBranch0(iqentry_br[heads[0]] & commit0_v),
1538
  .xisBranch1(iqentry_br[heads[1]] & commit1_v),
1539
  .xisBranch2(iqentry_br[heads[2]] & commit2_v),
1540
  .pcA(fetchbufA_pc),
1541
  .pcB(fetchbufB_pc),
1542
  .pcC(fetchbufC_pc),
1543
  .pcD(fetchbufD_pc),
1544
  .pcE(32'd0),
1545
  .pcF(32'd0),
1546
  .xpc0(iqentry_pc[heads[0]]),
1547
  .xpc1(iqentry_pc[heads[1]]),
1548
  .xpc2(iqentry_pc[heads[2]]),
1549
  .takb0(commit0_v & iqentry_takb[heads[0]]),
1550
  .takb1(commit1_v & iqentry_takb[heads[1]]),
1551
  .takb2(commit2_v & iqentry_takb[heads[2]]),
1552
  .predict_takenA(predict_takenA),
1553
  .predict_takenB(predict_takenB),
1554
  .predict_takenC(predict_takenC),
1555
  .predict_takenD(predict_takenD),
1556
  .predict_takenE(),
1557
  .predict_takenF()
1558
);
1559
`else
1560
// Predict based on sign of displacement
1561
assign predict_takenA = fetchbufA_instr[6] ? fetchbufA_instr[47] : fetchbufA_instr[31];
1562
assign predict_takenB = fetchbufB_instr[6] ? fetchbufB_instr[47] : fetchbufB_instr[31];
1563
assign predict_takenC = fetchbufC_instr[6] ? fetchbufC_instr[47] : fetchbufC_instr[31];
1564
assign predict_takenD = fetchbufD_instr[6] ? fetchbufD_instr[47] : fetchbufD_instr[31];
1565
`endif
1566
end
1567
else begin
1568
`ifdef FCU_ENH
1569
FT64_BranchPredictor ubp1
1570
(
1571
  .rst(rst),
1572
  .clk(fcu_clk),
1573
  .en(bpe),
1574
  .xisBranch0(iqentry_br[heads[0]] & commit0_v),
1575
  .xisBranch1(iqentry_br[heads[1]] & commit1_v),
1576
  .xisBranch2(iqentry_br[heads[2]] & commit2_v),
1577
  .pcA(fetchbufA_pc),
1578
  .pcB(fetchbufB_pc),
1579
  .pcC(32'd0),
1580
  .pcD(32'd0),
1581
  .pcE(32'd0),
1582
  .pcF(32'd0),
1583
  .xpc0(iqentry_pc[heads[0]]),
1584
  .xpc1(iqentry_pc[heads[1]]),
1585
  .xpc2(iqentry_pc[heads[2]]),
1586
  .takb0(commit0_v & iqentry_takb[heads[0]]),
1587
  .takb1(commit1_v & iqentry_takb[heads[1]]),
1588
  .takb2(commit2_v & iqentry_takb[heads[2]]),
1589
  .predict_takenA(predict_takenA),
1590
  .predict_takenB(predict_takenB),
1591
  .predict_takenC(),
1592
  .predict_takenD(),
1593
  .predict_takenE(),
1594
  .predict_takenF()
1595
);
1596
`else
1597
// Predict based on sign of displacement
1598
assign predict_takenA = fetchbufA_instr[6] ? fetchbufA_instr[47] : fetchbufA_instr[31];
1599
assign predict_takenB = fetchbufB_instr[6] ? fetchbufB_instr[47] : fetchbufB_instr[31];
1600
`endif
1601
end
1602
end
1603
endgenerate
1604
 
1605
//-----------------------------------------------------------------------------
1606
// Debug
1607
//-----------------------------------------------------------------------------
1608
`ifdef SUPPORT_DBG
1609
 
1610
wire [DBW-1:0] dbg_stat1x;
1611
reg [DBW-1:0] dbg_stat;
1612
reg [DBW-1:0] dbg_ctrl;
1613
reg [ABW-1:0] dbg_adr0;
1614
reg [ABW-1:0] dbg_adr1;
1615
reg [ABW-1:0] dbg_adr2;
1616
reg [ABW-1:0] dbg_adr3;
1617
reg dbg_imatchA0,dbg_imatchA1,dbg_imatchA2,dbg_imatchA3,dbg_imatchA;
1618
reg dbg_imatchB0,dbg_imatchB1,dbg_imatchB2,dbg_imatchB3,dbg_imatchB;
1619
 
1620
wire dbg_lmatch00 =
1621
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1622
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1623
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1624
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1625
                                 dbg_ctrl[19:18]==2'b11)
1626
                                 ;
1627
wire dbg_lmatch01 =
1628
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1629
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1630
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1631
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1632
                  dbg_ctrl[19:18]==2'b11)
1633
                  ;
1634
wire dbg_lmatch02 =
1635
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1636
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1637
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1638
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1639
                dbg_ctrl[19:18]==2'b11)
1640
                ;
1641
wire dbg_lmatch10 =
1642
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1643
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1644
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1645
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1646
                  dbg_ctrl[23:22]==2'b11)
1647
                  ;
1648
wire dbg_lmatch11 =
1649
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1650
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1651
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1652
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1653
                dbg_ctrl[23:22]==2'b11)
1654
                ;
1655
wire dbg_lmatch12 =
1656
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1657
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1658
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1659
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1660
                dbg_ctrl[23:22]==2'b11)
1661
                ;
1662
wire dbg_lmatch20 =
1663
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1664
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1665
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1666
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1667
                    dbg_ctrl[27:26]==2'b11)
1668
                    ;
1669
wire dbg_lmatch21 =
1670
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1671
                   ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1672
                    (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1673
                    (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1674
                    dbg_ctrl[27:26]==2'b11)
1675
                    ;
1676
wire dbg_lmatch22 =
1677
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1678
                   ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1679
                    (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1680
                    (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1681
                    dbg_ctrl[27:26]==2'b11)
1682
                    ;
1683
wire dbg_lmatch30 =
1684
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1685
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1686
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1687
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1688
                      dbg_ctrl[31:30]==2'b11)
1689
                      ;
1690
wire dbg_lmatch31 =
1691
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1692
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1693
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1694
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1695
                    dbg_ctrl[31:30]==2'b11)
1696
                    ;
1697
wire dbg_lmatch32 =
1698
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1699
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1700
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1701
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1702
                    dbg_ctrl[31:30]==2'b11)
1703
                    ;
1704
wire dbg_lmatch0 = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30;
1705
wire dbg_lmatch1 = dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31;
1706
wire dbg_lmatch2 = dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32;
1707
wire dbg_lmatch = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30|
1708
                  dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31|
1709
                  dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32
1710
                    ;
1711
 
1712
wire dbg_smatch00 =
1713
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1714
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1715
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1716
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1717
                                 dbg_ctrl[19:18]==2'b11)
1718
                                 ;
1719
wire dbg_smatch01 =
1720
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1721
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1722
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1723
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1724
                  dbg_ctrl[19:18]==2'b11)
1725
                  ;
1726
wire dbg_smatch02 =
1727
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1728
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1729
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1730
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1731
                dbg_ctrl[19:18]==2'b11)
1732
                ;
1733
wire dbg_smatch10 =
1734
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1735
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1736
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1737
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1738
                  dbg_ctrl[23:22]==2'b11)
1739
                  ;
1740
wire dbg_smatch11 =
1741
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1742
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1743
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1744
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1745
                dbg_ctrl[23:22]==2'b11)
1746
                ;
1747
wire dbg_smatch12 =
1748
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1749
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1750
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1751
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1752
                dbg_ctrl[23:22]==2'b11)
1753
                ;
1754
wire dbg_smatch20 =
1755
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1756
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1757
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1758
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1759
                    dbg_ctrl[27:26]==2'b11)
1760
                    ;
1761
wire dbg_smatch21 =
1762
           dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1763
                    ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1764
                     (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1765
                     (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1766
                     dbg_ctrl[27:26]==2'b11)
1767
                     ;
1768
wire dbg_smatch22 =
1769
            dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1770
                     ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1771
                      (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1772
                      (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1773
                      dbg_ctrl[27:26]==2'b11)
1774
                      ;
1775
wire dbg_smatch30 =
1776
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1777
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1778
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1779
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1780
                      dbg_ctrl[31:30]==2'b11)
1781
                      ;
1782
wire dbg_smatch31 =
1783
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1784
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1785
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1786
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1787
                    dbg_ctrl[31:30]==2'b11)
1788
                    ;
1789
wire dbg_smatch32 =
1790
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1791
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1792
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1793
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1794
                    dbg_ctrl[31:30]==2'b11)
1795
                    ;
1796
wire dbg_smatch0 = dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30;
1797
wire dbg_smatch1 = dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31;
1798
wire dbg_smatch2 = dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32;
1799
 
1800
wire dbg_smatch =   dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30|
1801
                    dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31|
1802
                    dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32
1803
                    ;
1804
 
1805
wire dbg_stat0 = dbg_imatchA0 | dbg_imatchB0 | dbg_lmatch00 | dbg_lmatch01 | dbg_lmatch02 | dbg_smatch00 | dbg_smatch01 | dbg_smatch02;
1806
wire dbg_stat1 = dbg_imatchA1 | dbg_imatchB1 | dbg_lmatch10 | dbg_lmatch11 | dbg_lmatch12 | dbg_smatch10 | dbg_smatch11 | dbg_smatch12;
1807
wire dbg_stat2 = dbg_imatchA2 | dbg_imatchB2 | dbg_lmatch20 | dbg_lmatch21 | dbg_lmatch22 | dbg_smatch20 | dbg_smatch21 | dbg_smatch22;
1808
wire dbg_stat3 = dbg_imatchA3 | dbg_imatchB3 | dbg_lmatch30 | dbg_lmatch31 | dbg_lmatch32 | dbg_smatch30 | dbg_smatch31 | dbg_smatch32;
1809
assign dbg_stat1x = {dbg_stat3,dbg_stat2,dbg_stat1,dbg_stat0};
1810
wire debug_on = |dbg_ctrl[3:0]|dbg_ctrl[7]|dbg_ctrl[63];
1811
 
1812
always @*
1813
begin
1814
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf0_pc==dbg_adr0)
1815
        dbg_imatchA0 = `TRUE;
1816
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf0_pc==dbg_adr1)
1817
        dbg_imatchA1 = `TRUE;
1818
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf0_pc==dbg_adr2)
1819
        dbg_imatchA2 = `TRUE;
1820
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf0_pc==dbg_adr3)
1821
        dbg_imatchA3 = `TRUE;
1822
    if (dbg_imatchA0|dbg_imatchA1|dbg_imatchA2|dbg_imatchA3)
1823
        dbg_imatchA = `TRUE;
1824
end
1825
 
1826
always @*
1827
begin
1828
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf1_pc==dbg_adr0)
1829
        dbg_imatchB0 = `TRUE;
1830
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf1_pc==dbg_adr1)
1831
        dbg_imatchB1 = `TRUE;
1832
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf1_pc==dbg_adr2)
1833
        dbg_imatchB2 = `TRUE;
1834
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf1_pc==dbg_adr3)
1835
        dbg_imatchB3 = `TRUE;
1836
    if (dbg_imatchB0|dbg_imatchB1|dbg_imatchB2|dbg_imatchB3)
1837
        dbg_imatchB = `TRUE;
1838
end
1839
`endif
1840
 
1841
//-----------------------------------------------------------------------------
1842
//-----------------------------------------------------------------------------
1843
 
1844
// freezePC squashes the pc increment if there's an irq.
1845
// If there is a segment prefix present then defer the freezing of the pc.
1846
// If a hardware interrupt instruction is encountered in the instruction stream
1847
// flag it as a privilege violation.
1848
wire freezePC = (irq_i > im) && !int_commit;
1849
always @*
1850
if (freezePC) begin
1851 61 robfinch
        insn0 <= {32'h00,6'd0,5'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1852 60 robfinch
end
1853
else if (phit) begin
1854
//      if (insn0a[`INSTRUCTION_OP]==`BRK && insn0a[25:21]==5'd0 && insn0a[`INSTRUCTION_L2]==2'b00)
1855
//              insn0 <= {6'd1,5'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1856
//      else
1857
                insn0 <= insn0a;
1858 61 robfinch
                if (insn0a[15:0]==16'hFF00) begin        // BRK #255
1859
                        if (~|irq_i)
1860
                                insn0 <= {8'h00,`NOP_INSN};
1861
                        else
1862
                                insn0[20:0] <= {irq_i,1'b0,vec_i,2'b00,`BRK};
1863
                end
1864
                else if (ic0_fault[1])
1865
                        insn0 <= {32'h00,6'd0,5'd0,4'h0,1'b0,`FLT_IBE,2'b00,`BRK};
1866
                else if (ic0_fault[0])
1867
                        insn0 <= {32'h00,6'd0,5'd0,4'h0,1'b0,`FLT_EXF,2'b00,`BRK};
1868 60 robfinch
end
1869
else begin
1870
        insn0 <= {8'h00,`NOP_INSN};
1871
end
1872 61 robfinch
 
1873 60 robfinch
generate begin : gInsnMux
1874
if (`WAYS > 1) begin
1875
always @*
1876
if (freezePC && !thread_en) begin
1877
        insn1 <= {8'h00,6'd0,5'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1878
end
1879
else if (phit) begin
1880
//      if (insn1a[`INSTRUCTION_OP]==`BRK && insn1a[25:21]==5'd0 && insn1a[`INSTRUCTION_L2]==2'b00)
1881
//              insn1 <= {6'd1,5'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1882
//      else
1883
                insn1 <= insn1a;
1884 61 robfinch
                if (insn1a[15:0]==16'hFF00) begin
1885
                        if (~|irq_i)
1886
                                insn1 <= {8'h00,`NOP_INSN};
1887
                        else
1888
                                insn1[20:0] <= {irq_i,1'b0,vec_i,2'b00,`BRK};
1889
                end
1890
                else if (ic1_fault[1])
1891
                        insn1 <= {32'h00,6'd0,5'd0,4'h0,1'b0,`FLT_IBE,2'b00,`BRK};
1892
                else if (ic1_fault[0])
1893
                        insn1 <= {32'h00,6'd0,5'd0,4'h0,1'b0,`FLT_EXF,2'b00,`BRK};
1894 60 robfinch
end
1895
else begin
1896
        insn1 <= {8'h00,`NOP_INSN};
1897
end
1898
end
1899
if (`WAYS > 2) begin
1900
always @*
1901
if (freezePC && !thread_en)
1902
        insn2 <= {6'd0,5'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1903
else if (phit) begin
1904
//      if (insn2a[`INSTRUCTION_OP]==`BRK && insn1a[25:21]==5'd0 && insn2a[`INSTRUCTION_L2]==2'b00)
1905
//              insn2 <= {6'd1,5'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1906
//      else
1907
                insn2 <= insn2a;
1908 61 robfinch
                if (insn2a[15:0]==16'hFF00) begin
1909
                        if (~|irq_i)
1910
                                insn2 <= {8'h00,`NOP_INSN};
1911
                        else
1912
                                insn2[20:0] <= {irq_i,1'b0,vec_i,2'b00,`BRK};
1913
                end
1914
                else if (ic2_fault[1])
1915
                        insn2 <= {32'h00,6'd0,5'd0,4'h0,1'b0,`FLT_IBE,2'b00,`BRK};
1916
                else if (ic2_fault[0])
1917
                        insn2 <= {32'h00,6'd0,5'd0,4'h0,1'b0,`FLT_EXF,2'b00,`BRK};
1918 60 robfinch
end
1919
else
1920
        insn2 <= `NOP_INSN;
1921
end
1922
end
1923
endgenerate
1924
 
1925
wire [63:0] dc0_out, dc1_out, dc2_out;
1926 61 robfinch
assign rdat0 = dram0_unc ? xdati[63:0] : dc0_out;
1927
assign rdat1 = dram1_unc ? xdati[63:0] : dc1_out;
1928
assign rdat2 = dram2_unc ? xdati[63:0] : dc2_out;
1929 60 robfinch
 
1930
reg preload;
1931
reg [1:0] dccnt;
1932
wire dhit0, dhit1, dhit2;
1933
wire dhit0a, dhit1a, dhit2a;
1934
wire dhit00, dhit10, dhit20;
1935
wire dhit01, dhit11, dhit21;
1936
reg [`ABITS] dc_wadr;
1937
reg [63:0] dc_wdat;
1938
reg isStore;
1939
 
1940
// If the data is in the write buffer, give the buffer a chance to
1941
// write out the data before trying to load from the cache.
1942
reg wb_hit0, wb_hit1, wb_hit2;
1943
always @*
1944
begin
1945
        wb_hit0 <= FALSE;
1946
        wb_hit1 <= FALSE;
1947
        wb_hit2 <= FALSE;
1948
        for (n = 0; n < `WB_DEPTH; n = n + 1) begin
1949
                if (wb_v[n] && wb_addr[n][AMSB:3]==dram0_addr[AMSB:3])
1950
                        wb_hit0 <= TRUE;
1951
                if (`NUM_MEM > 1 && wb_v[n] && wb_addr[n][AMSB:3]==dram1_addr[AMSB:3])
1952
                        wb_hit1 <= TRUE;
1953
                if (`NUM_MEM > 2 && wb_v[n] && wb_addr[n][AMSB:3]==dram2_addr[AMSB:3])
1954
                        wb_hit2 <= TRUE;
1955
        end
1956
end
1957
 
1958
assign dhit0 = dhit0a && !wb_hit0;
1959
assign dhit1 = dhit1a && !wb_hit1;
1960
assign dhit2 = dhit2a && !wb_hit2;
1961
wire whit0, whit1, whit2;
1962
 
1963 61 robfinch
wire wr_dcache0 = (bstate==B_DCacheLoadAck && ack_i)||(((bstate==B_StoreAck && StoreAck1) || (bstate==B_LSNAck && isStore)) && whit0);
1964
wire wr_dcache1 = (bstate==B_DCacheLoadAck && ack_i)||(((bstate==B_StoreAck && StoreAck1) || (bstate==B_LSNAck && isStore)) && whit1);
1965
wire wr_dcache2 = (bstate==B_DCacheLoadAck && ack_i)||(((bstate==B_StoreAck && StoreAck1) || (bstate==B_LSNAck && isStore)) && whit2);
1966 60 robfinch
 
1967
FT64_dcache udc0
1968
(
1969
  .rst(rst),
1970
  .wclk(clk),
1971
  .dce(dce),
1972
  .wr(wr_dcache0),
1973
  .sel(sel_o),
1974
  .wadr({pcr[7:0],vadr}),
1975
  .whit(whit0),
1976
  .i((bstate==B_DCacheLoadAck) ? dat_i : dat_o),
1977
  .rclk(clk),
1978
  .rdsize(dram0_memsize),
1979
  .radr({pcr[7:0],dram0_addr}),
1980
  .o(dc0_out),
1981
  .rhit(dhit0a)
1982
);
1983
generate begin : gDCacheInst
1984
if (`NUM_MEM > 1) begin
1985
FT64_dcache udc1
1986
(
1987
  .rst(rst),
1988
  .wclk(clk),
1989
  .dce(dce),
1990
  .wr(wr_dcache1),
1991
  .sel(sel_o),
1992
  .wadr({pcr[7:0],vadr}),
1993
  .whit(whit1),
1994
  .i((bstate==B_DCacheLoadAck) ? dat_i : dat_o),
1995
  .rclk(clk),
1996
  .rdsize(dram1_memsize),
1997
  .radr({pcr[7:0],dram1_addr}),
1998
  .o(dc1_out),
1999
  .rhit(dhit1a)
2000
);
2001
end
2002
if (`NUM_MEM > 2) begin
2003
FT64_dcache udc2
2004
(
2005
  .rst(rst),
2006
  .wclk(clk),
2007
  .dce(dce),
2008
  .wr(wr_dcache2),
2009
  .sel(sel_o),
2010
  .wadr({pcr[7:0],vadr}),
2011
  .whit(whit2),
2012
  .i((bstate==B_DCacheLoadAck) ? dat_i : dat_o),
2013
  .rclk(clk),
2014
  .rdsize(dram2_memsize),
2015
  .radr({pcr[7:0],dram2_addr}),
2016
  .o(dc2_out),
2017
  .rhit(dhit2a)
2018
);
2019
end
2020
end
2021
endgenerate
2022
 
2023
`ifdef SUPPORT_SMT
2024
function [RBIT:0] fnRa;
2025
input [47:0] isn;
2026
input [5:0] vqei;
2027
input [5:0] vli;
2028
input thrd;
2029
case(isn[`INSTRUCTION_OP])
2030
`IVECTOR:
2031
        case(isn[`INSTRUCTION_S2])
2032
        `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
2033
        `VMxx:
2034
                case(isn[25:23])
2035
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
2036
                    fnRa = {6'h3F,1'b1,2'b0,isn[10:8]};
2037
            `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
2038
            default:fnRa = {6'h3F,1'b1,2'b0,isn[10:8]};
2039
            endcase
2040
        `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
2041
        `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
2042
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
2043
        default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
2044
        endcase
2045
`R2:    casez(isn[`INSTRUCTION_S2])
2046
                `MOV:
2047
                        case(isn[25:23])
2048
                        3'd0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2049
                        3'd1:   fnRa = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
2050
                        3'd2:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2051
                        3'd3:   fnRa = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RA]};
2052
                        3'd4:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2053
                        3'd5:   fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2054
                        3'd6:   fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2055
                        default:fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2056
                        endcase
2057
        `VMOV:
2058
            case (isn[`INSTRUCTION_S1])
2059
            5'h0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2060
            5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
2061
            endcase
2062
        default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2063
        endcase
2064
`FLOAT:         fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2065
default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2066
endcase
2067
endfunction
2068
 
2069
function [RBIT:0] fnRb;
2070
input [47:0] isn;
2071
input fb;
2072
input [5:0] vqei;
2073
input [5:0] rfoa0i;
2074
input [5:0] rfoa1i;
2075
input thrd;
2076
case(isn[`INSTRUCTION_OP])
2077
`R2:        case(isn[`INSTRUCTION_S2])
2078
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
2079
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2080
            default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2081
            endcase
2082
`IVECTOR:
2083
                        case(isn[`INSTRUCTION_S2])
2084
                        `VMxx:
2085
                                case(isn[25:23])
2086
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2087
                        fnRb = {6'h3F,1'b1,2'b0,isn[20:18]};
2088
                default:        fnRb = 12'h000;
2089
                endcase
2090
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2091
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2092
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
2093
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
2094
                fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2095
            `VSHL,`VSHR,`VASR:
2096
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
2097
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2098
            endcase
2099
`FLOAT:         fnRb = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2100
default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2101
endcase
2102
endfunction
2103
 
2104
function [RBIT:0] fnRc;
2105
input [47:0] isn;
2106
input [5:0] vqei;
2107
input thrd;
2108
case(isn[`INSTRUCTION_OP])
2109
`R2:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2110
`MEMNDX:        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};   // SVX not implemented
2111
`IVECTOR:
2112
                        case(isn[`INSTRUCTION_S2])
2113
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[25:23]};
2114
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2115
            endcase
2116
`FLOAT:         fnRc = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2117
default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2118
endcase
2119
endfunction
2120
 
2121
function [RBIT:0] fnRt;
2122
input [47:0] isn;
2123
input [5:0] vqei;
2124
input [5:0] vli;
2125
input thrd;
2126
casez(isn[`INSTRUCTION_OP])
2127
`IVECTOR:
2128
                case(isn[`INSTRUCTION_S2])
2129
                `VMxx:
2130
                        case(isn[25:23])
2131
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
2132
                    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2133
            `VMPOP:     fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2134
            default:
2135
                    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2136
            endcase
2137
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2138
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RT]};
2139
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RT]};
2140
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};    // ToDo: add element # from Ra
2141
        `V2BITS:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2142
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_Rt]};
2143
        endcase
2144
 
2145
`R2:
2146
        if (isn[`INSTRUCTION_L2]==2'b01)
2147
                case(isn[47:42])
2148
          `CMOVEZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2149
        `CMOVNZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2150
        default:                fnRt = 12'd0;
2151
                endcase
2152
        else
2153
    casez(isn[`INSTRUCTION_S2])
2154
                `MOV:
2155
                        case(isn[25:23])
2156
                        3'd0:   fnRt = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RT]};
2157
                        3'd1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2158
                        3'd2:   fnRt = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RT]};
2159
                        3'd3:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2160
                        3'd4:   fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2161
                        3'd5:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2162
                        3'd6:   fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2163
                        default:fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2164
                        endcase
2165
        `VMOV:
2166
            case (isn[`INSTRUCTION_S1])
2167
            5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RT]};
2168
            5'h1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2169
            default:    fnRt = 12'h000;
2170
            endcase
2171
        `R1:
2172
                case(isn[22:18])
2173
                `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT,`NEG,`REDOR,`ZXB,`ZXC,`ZXH,`SXB,`SXC,`SXH:
2174
                        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2175
                `MEMDB,`MEMSB,`SYNC:
2176
                        fnRt = 12'd0;
2177
                default:        fnRt = 12'd0;
2178
                endcase
2179
        `CMOVEZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2180
        `CMOVNZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2181
        `MUX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2182
        `MIN:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2183
        `MAX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2184
        `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
2185
        `SHIFTR:        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2186
        `SHIFT31,`SHIFT63:
2187
                                fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2188
        `SEI:           fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2189
        `WAIT,`RTI,`CHK:
2190
                        fnRt = 12'd0;
2191
                default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2192
        endcase
2193
`MEMNDX:
2194
        begin
2195
                if (!isn[31])
2196
                        case({isn[31:28],isn[22:21]})
2197
                        `LVX,
2198
                        `CACHEX,
2199
                        `LVBX,`LVBUX,`LVCX,`LVCUX,`LVHX,`LVHUX,`LVWX,
2200
                        `LBX,`LBUX,`LCX,`LCUX,`LHX,`LHUX,`LWX,`LWRX:
2201
                                fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2202
                        default: fnRt = 12'd0;
2203
                        endcase
2204
                else
2205
                        case({isn[31:28],isn[17:16]})
2206
                        `PUSH:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2207
                  `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
2208
                                        fnRt = 12'd0;
2209
                  default:    fnRt = 12'd0;
2210
                  endcase
2211
        end
2212
`FLOAT:
2213
                case(isn[31:26])
2214
                `FTX,`FCX,`FEX,`FDX,`FRM:
2215
                                        fnRt = 12'd0;
2216
                `FSYNC:         fnRt = 12'd0;
2217
                default:        fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2218
                endcase
2219
`BRK:   fnRt = 12'd0;
2220
`REX:   fnRt = 12'd0;
2221
`CHK:   fnRt = 12'd0;
2222 61 robfinch
//`EXEC:        fnRt = 12'd0;
2223 60 robfinch
`Bcc:   fnRt = 12'd0;
2224 61 robfinch
`BLcc:  fnRt = 12'd0;
2225 60 robfinch
`BBc:   fnRt = 12'd0;
2226
`NOP:  fnRt = 12'd0;
2227
`BEQI:  fnRt = 12'd0;
2228 61 robfinch
`BNEI:  fnRt = 12'd0;
2229 60 robfinch
`SB,`Sx,`SWC,`CACHE:
2230
                fnRt = 12'd0;
2231
`JMP:   fnRt = 12'd0;
2232
`CALL:  fnRt = {rgs[thrd],1'b0,5'd29};  // regLR
2233
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};
2234
`AMO:   fnRt = isn[31] ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]} : {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2235
`AUIPC,`LUI:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2236
default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2237
endcase
2238
endfunction
2239
`else
2240
function [RBIT:0] fnRa;
2241
input [47:0] isn;
2242
input [5:0] vqei;
2243
input [5:0] vli;
2244
input thrd;
2245
case(isn[`INSTRUCTION_OP])
2246
`IVECTOR:
2247
        case(isn[`INSTRUCTION_S2])
2248
  `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
2249
  `VMxx:
2250
        case(isn[25:23])
2251
        `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
2252
              fnRa = {6'h3F,1'b1,2'b0,isn[10:8]};
2253
      `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
2254
      default:fnRa = {6'h3F,1'b1,2'b0,isn[10:8]};
2255
      endcase
2256
  `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
2257
  `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
2258
  `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
2259
  default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
2260
  endcase
2261
`R2:
2262
        casez(isn[`INSTRUCTION_S2])
2263
        `MOV:
2264
                case(isn[25:23])
2265
                3'd0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2266
                3'd1:   fnRa = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
2267
                3'd2:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2268
                3'd3:   fnRa = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RA]};
2269
                3'd4:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2270
                3'd5:   fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2271
                3'd6:   fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2272
                default:fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2273
                endcase
2274
  `VMOV:
2275
    case (isn[`INSTRUCTION_S1])
2276
    5'h0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2277
    5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
2278
    default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2279
    endcase
2280
  default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2281
  endcase
2282
`FLOAT:         fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2283
default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2284
endcase
2285
endfunction
2286
 
2287
function [RBIT:0] fnRb;
2288
input [47:0] isn;
2289
input fb;
2290
input [5:0] vqei;
2291
input [5:0] rfoa0i;
2292
input [5:0] rfoa1i;
2293
input thrd;
2294
case(isn[`INSTRUCTION_OP])
2295
`RR:        case(isn[`INSTRUCTION_S2])
2296
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
2297
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2298
            default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2299
            endcase
2300
`IVECTOR:
2301
                        case(isn[`INSTRUCTION_S2])
2302
                        `VMxx:
2303
                                case(isn[25:23])
2304
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2305
                        fnRb = {6'h3F,1'b1,2'b0,isn[20:18]};
2306
                default:        fnRb = 12'h000;
2307
                endcase
2308
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2309
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2310
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
2311
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
2312
                fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2313
            `VSHL,`VSHR,`VASR:
2314
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
2315
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2316
            endcase
2317
`FLOAT:         fnRb = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
2318
default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2319
endcase
2320
endfunction
2321
 
2322
function [RBIT:0] fnRc;
2323
input [47:0] isn;
2324
input [5:0] vqei;
2325
input thrd;
2326
case(isn[`INSTRUCTION_OP])
2327
`R2:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2328
`MEMNDX:        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]}; // SVX not implemented
2329
`IVECTOR:
2330
                        case(isn[`INSTRUCTION_S2])
2331
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[25:23]};
2332
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2333
            endcase
2334
`FLOAT:         fnRc = {fp_rgs,1'b0,isn[`INSTRUCTION_RC]};
2335
default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2336
endcase
2337
endfunction
2338
 
2339
function [RBIT:0] fnRt;
2340
input [47:0] isn;
2341
input [5:0] vqei;
2342
input [5:0] vli;
2343
input thrd;
2344
casez(isn[`INSTRUCTION_OP])
2345
`IVECTOR:
2346
                case(isn[`INSTRUCTION_S2])
2347
                `VMxx:
2348
                        case(isn[25:23])
2349
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
2350
                    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2351
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2352
            default:
2353
                    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2354
            endcase
2355
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2356
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RT]};
2357
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RT]};
2358
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};    // ToDo: add element # from Ra
2359
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2360
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};
2361
        endcase
2362
 
2363
`FVECTOR:
2364
                case(isn[`INSTRUCTION_S2])
2365
                `VMxx:
2366
                        case(isn[25:23])
2367
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
2368
                    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2369
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2370
            default:
2371
                    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2372
            endcase
2373
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2374
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RT]};
2375
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RT]};
2376
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};    // ToDo: add element # from Ra
2377
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2378
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};
2379
        endcase
2380
 
2381
`R2:
2382
        if (isn[`INSTRUCTION_L2]==2'b01)
2383
                case(isn[47:42])
2384
          `CMOVEZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2385
        `CMOVNZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2386
        default:                fnRt = 12'd0;
2387
                endcase
2388
        else
2389
        casez(isn[`INSTRUCTION_S2])
2390
        `MOV:
2391
                case(isn[25:23])
2392
                3'd0:   fnRt = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RT]};
2393
                3'd1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2394
                3'd2:   fnRt = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RT]};
2395
                3'd3:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2396
                3'd4:   fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RT]};
2397
                3'd5:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2398
                3'd6:   fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RT]};
2399
                default:fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2400
                endcase
2401
  `VMOV:
2402
    case (isn[`INSTRUCTION_S1])
2403
    5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RT]};
2404
    5'h1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2405
    default:    fnRt = 12'h000;
2406
    endcase
2407
  `R1:
2408
        case(isn[22:18])
2409
        `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT,`NEG,`REDOR,`ZXB,`ZXC,`ZXH,`SXB,`SXC,`SXH:
2410
                fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2411
        `MEMDB,`MEMSB,`SYNC:
2412
                fnRt = 12'd0;
2413
        default:        fnRt = 12'd0;
2414
        endcase
2415
  `MUX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2416
  `MIN:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2417
  `MAX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2418
  `LVX:       fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};
2419
  `SHIFTR:      fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2420
  `SHIFT31,`SHIFT63:
2421
                        fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2422
  `SEI:         fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2423
  `WAIT,`RTI,`CHK:
2424
                        fnRt = 12'd0;
2425
  default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2426
  endcase
2427
`MEMNDX:
2428
        begin
2429
                if (!isn[31])
2430
                        case({isn[31:28],isn[22:21]})
2431
                        `LVX,
2432
                        `CACHEX,
2433
                        `LVBX,`LVBUX,`LVCX,`LVCUX,`LVHX,`LVHUX,`LVWX,
2434
                        `LBX,`LBUX,`LCX,`LCUX,`LHX,`LHUX,`LWX,`LWRX:
2435
                                fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2436
                        default: fnRt = 12'd0;
2437
                        endcase
2438
                else
2439
                        case({isn[31:28],isn[17:16]})
2440
                        `PUSH:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2441
                  `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
2442
                                        fnRt = 12'd0;
2443
                  default:    fnRt = 12'd0;
2444
                  endcase
2445
        end
2446
`FLOAT:
2447
                case(isn[31:26])
2448
                `FTX,`FCX,`FEX,`FDX,`FRM:
2449
                                        fnRt = 12'd0;
2450
                `FSYNC:         fnRt = 12'd0;
2451
                default:        fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RT]};
2452
                endcase
2453
`BRK:   fnRt = 12'd0;
2454
`REX:   fnRt = 12'd0;
2455
`CHK:   fnRt = 12'd0;
2456 61 robfinch
//`EXEC:        fnRt = 12'd0;
2457 60 robfinch
`Bcc:   fnRt = 12'd0;
2458 61 robfinch
`BLcc:  fnRt = 12'd0;
2459 60 robfinch
`BBc:   fnRt = 12'd0;
2460
`NOP:  fnRt = 12'd0;
2461
`BEQI:  fnRt = 12'd0;
2462 61 robfinch
`BNEI:  fnRt = 12'd0;
2463 60 robfinch
`SB,`Sx,`SWC,`CACHE:
2464
                fnRt = 12'd0;
2465
`JMP:   fnRt = 12'd0;
2466
`CALL:  fnRt = {rgs,1'b0,5'd29};        // regLR
2467
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};
2468
`AMO:   fnRt = isn[31] ? {rgs,1'b0,isn[`INSTRUCTION_RT]} : {rgs,1'b0,isn[`INSTRUCTION_RT]};
2469
`AUIPC,`LUI:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2470
default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2471
endcase
2472
endfunction
2473
`endif
2474
 
2475
// Determines which lanes of the target register get updated.
2476
// Duh, all the lanes.
2477
function [7:0] fnWe;
2478
input [47:0] isn;
2479
casez(isn[`INSTRUCTION_OP])
2480
`R2:
2481
        case(isn[`INSTRUCTION_S2])
2482
        `CMP:   fnWe = 8'h00;
2483
        default: fnWe = 8'hFF;
2484
        endcase
2485
default: fnWe = 8'hFF;
2486
endcase
2487
/*
2488
casez(isn[`INSTRUCTION_OP])
2489
`R2:
2490
        case(isn[`INSTRUCTION_S2])
2491
        `R1:
2492
                case(isn[22:18])
2493
                `ABS,`CNTLZ,`CNTLO,`CNTPOP:
2494
                        case(isn[25:23])
2495
                        3'b000: fnWe = 8'h01;
2496
                        3'b001: fnWe = 8'h03;
2497
                        3'b010: fnWe = 8'h0F;
2498
                        3'b011: fnWe = 8'hFF;
2499
                        default:        fnWe = 8'hFF;
2500
                        endcase
2501
                default: fnWe = 8'hFF;
2502
                endcase
2503
        `SHIFT31:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2504
        `SHIFT63:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2505
        `SLT,`SLTU,`SLE,`SLEU,
2506
        `ADD,`SUB,
2507
        `AND,`OR,`XOR,
2508
        `NAND,`NOR,`XNOR,
2509
        `DIV,`DIVU,`DIVSU,
2510
        `MOD,`MODU,`MODSU,
2511
        `MUL,`MULU,`MULSU,
2512
        `MULH,`MULUH,`MULSUH,
2513
        `FXMUL:
2514
                case(isn[25:23])
2515
                3'b000: fnWe = 8'h01;
2516
                3'b001: fnWe = 8'h03;
2517
                3'b010: fnWe = 8'h0F;
2518
                3'b011: fnWe = 8'hFF;
2519
                default:        fnWe = 8'hFF;
2520
                endcase
2521
        default: fnWe = 8'hFF;
2522
        endcase
2523
default:        fnWe = 8'hFF;
2524
endcase
2525
*/
2526
endfunction
2527
 
2528
// Detect if a source is automatically valid
2529
function Source1Valid;
2530
input [47:0] isn;
2531
casez(isn[`INSTRUCTION_OP])
2532
`BRK:   Source1Valid = isn[16] ? isn[`INSTRUCTION_RA]==5'd0 : TRUE;
2533
`Bcc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2534 61 robfinch
`BLcc:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2535 60 robfinch
`BBc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2536
`BEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2537 61 robfinch
`BNEI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2538 60 robfinch
`CHK:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2539
`RR:    case(isn[`INSTRUCTION_S2])
2540
        `SHIFT31:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2541
        `SHIFT63:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2542
        `SHIFTR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2543
        default:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2544
        endcase
2545
`MEMNDX:Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2546
`ADDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2547 61 robfinch
`SEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2548 60 robfinch
`SLTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2549
`SLTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2550
`SGTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2551
`SGTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2552
`ANDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2553
`ORI:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2554
`XORI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2555
`XNORI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2556
`MULI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2557
`MULUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2558
`MULFI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2559
`DIVI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2560
`DIVUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2561
`AMO:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2562
`LB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2563
`LBU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2564
`Lx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2565
`LxU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2566
`LWR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2567
`LV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2568
`LVx:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2569
`LVxU:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2570
`SB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2571
`Sx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2572
`SWC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2573
`SV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2574 61 robfinch
`PUSHC: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2575 60 robfinch
`INC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2576
`CAS:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2577
`CACHE: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2578
`JAL:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2579
`RET:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2580
`CSRRW: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2581
`BITFIELD:      case(isn[47:44])
2582
        `BFINSI:        Source1Valid = TRUE;
2583
        default:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0 || isn[30]==1'b0;
2584
        endcase
2585
`IVECTOR:
2586
        Source1Valid = FALSE;
2587
default:    Source1Valid = TRUE;
2588
endcase
2589
endfunction
2590
 
2591
function Source2Valid;
2592
input [47:0] isn;
2593
casez(isn[`INSTRUCTION_OP])
2594
`BRK:   Source2Valid = TRUE;
2595
`Bcc:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2596 61 robfinch
`BLcc:  Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2597 60 robfinch
`BBc:   Source2Valid = TRUE;
2598
`BEQI:  Source2Valid = TRUE;
2599 61 robfinch
`BNEI:  Source2Valid = TRUE;
2600 60 robfinch
`CHK:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2601
`R2:    casez(isn[`INSTRUCTION_S2])
2602
                                `TLB:                           Source2Valid = TRUE;
2603
        `R1:            Source2Valid = TRUE;
2604
        `MOV:                           Source2Valid = TRUE;
2605 61 robfinch
        `SHIFT31:       Source2Valid = TRUE;
2606
        `SHIFT63:       Source2Valid = TRUE;
2607 60 robfinch
        `LVX,`SVX:      Source2Valid = FALSE;
2608
        default:        Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2609
        endcase
2610
`MEMNDX:
2611
        begin
2612
                if (!isn[31])
2613
                        case({isn[31:28],isn[22:21]})
2614
                        `LVX: Source2Valid = FALSE;
2615
                        `CACHEX,
2616
                        `LVBX,`LVBUX,`LVCX,`LVCUX,`LVHX,`LVHUX,`LVWX,
2617
                        `LBX,`LBUX,`LCX,`LCUX,`LHX,`LHUX,`LWX,`LWRX:    Source2Valid = TRUE;
2618
                        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2619
                        endcase
2620
                else
2621
                        case({isn[31:28],isn[17:16]})
2622
                        `SVX: Source2Valid = FALSE;
2623
                        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2624
                        endcase
2625
        end
2626
`ADDI:  Source2Valid = TRUE;
2627 61 robfinch
`SEQI:  Source2Valid = TRUE;
2628 60 robfinch
`SLTI:  Source2Valid = TRUE;
2629
`SLTUI: Source2Valid = TRUE;
2630
`SGTI:  Source2Valid = TRUE;
2631
`SGTUI: Source2Valid = TRUE;
2632
`ANDI:  Source2Valid = TRUE;
2633
`ORI:   Source2Valid = TRUE;
2634
`XORI:  Source2Valid = TRUE;
2635
`XNORI: Source2Valid = TRUE;
2636
`MULUI: Source2Valid = TRUE;
2637
`MULFI: Source2Valid = TRUE;
2638
`LB:    Source2Valid = TRUE;
2639
`LBU:   Source2Valid = TRUE;
2640
`Lx:    Source2Valid = TRUE;
2641
`LxU:   Source2Valid = TRUE;
2642
`LWR:   Source2Valid = TRUE;
2643
`LVx:   Source2Valid = TRUE;
2644
`LVxU:  Source2Valid = TRUE;
2645
`INC:           Source2Valid = TRUE;
2646
`SB:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2647
`Sx:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2648
`SWC:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2649 61 robfinch
`PUSHC: Source2Valid = TRUE;
2650 60 robfinch
`CAS:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2651
`JAL:   Source2Valid = TRUE;
2652
`RET:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2653
`IVECTOR:
2654
                    case(isn[`INSTRUCTION_S2])
2655
        `VABS:  Source2Valid = TRUE;
2656
        `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2657
            Source2Valid = FALSE;
2658
        `VADDS,`VSUBS,`VANDS,`VORS,`VXORS:
2659
            Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2660
        `VBITS2V:   Source2Valid = TRUE;
2661
        `V2BITS:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2662
        `VSHL,`VSHR,`VASR:  Source2Valid = isn[22:21]==2'd2;
2663
        default:    Source2Valid = FALSE;
2664
        endcase
2665
`LV:        Source2Valid = TRUE;
2666
`SV:        Source2Valid = FALSE;
2667
`AMO:           Source2Valid = isn[31] || isn[`INSTRUCTION_RB]==5'd0;
2668
`BITFIELD:      Source2Valid = isn[`INSTRUCTION_RB]==5'd0 || isn[31]==1'b0;
2669
default:    Source2Valid = TRUE;
2670
endcase
2671
endfunction
2672
 
2673
function Source3Valid;
2674
input [47:0] isn;
2675
case(isn[`INSTRUCTION_OP])
2676
`IVECTOR:
2677
    case(isn[`INSTRUCTION_S2])
2678
    `VEX:       Source3Valid = TRUE;
2679
    default:    Source3Valid = TRUE;
2680
    endcase
2681
`CHK:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2682
`R2:
2683
        if (isn[`INSTRUCTION_L2]==2'b01)
2684
                case(isn[47:42])
2685
    `CMOVEZ,`CMOVNZ:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2686
                default:        Source3Valid = TRUE;
2687
                endcase
2688
        else
2689
    case(isn[`INSTRUCTION_S2])
2690
    `MAJ:               Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2691
    default:    Source3Valid = TRUE;
2692
    endcase
2693
`MEMNDX:
2694
                if (!isn[31])
2695
                        case({isn[31:28],isn[22:21]})
2696
                        `CACHEX,
2697
                        `LVBX,`LVBUX,`LVCX,`LVCUX,`LVHX,`LVHUX,`LVWX,
2698
                        `LBX,`LBUX,`LCX,`LCUX,`LHX,`LHUX,`LWX,`LWRX:
2699
                                Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2700
            default:    Source3Valid = TRUE;
2701
                        endcase
2702
                else
2703
            case({isn[31:28],isn[17:16]})
2704
            `PUSH:      Source3Valid = TRUE;
2705
            `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2706
            `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2707
            `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2708
            `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2709
            `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2710
            `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2711
            default:    Source3Valid = TRUE;
2712
            endcase
2713
`BITFIELD:      Source3Valid = isn[`INSTRUCTION_RC]==5'd0 || isn[32]==1'b0;
2714
default:    Source3Valid = TRUE;
2715
endcase
2716
endfunction
2717
 
2718
 
2719
// Used to indicate to the queue logic that the instruction needs to be
2720
// recycled to the queue VL number of times.
2721
function IsVector;
2722
input [47:0] isn;
2723
case(isn[`INSTRUCTION_OP])
2724
`MEMNDX:
2725
  case(isn[`INSTRUCTION_S2])
2726
  `LVX,`SVX:  IsVector = TRUE;
2727
  default:    IsVector = FALSE;
2728
  endcase
2729
`IVECTOR:
2730
        case(isn[`INSTRUCTION_S2])
2731
        `VMxx:
2732
                case(isn[25:23])
2733
        `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2734
              IsVector = FALSE;
2735
    default:    IsVector = TRUE;
2736
    endcase
2737
  `VEINS:     IsVector = FALSE;
2738
  `VEX:       IsVector = FALSE;
2739
  default:    IsVector = TRUE;
2740
  endcase
2741
`LV,`SV:    IsVector = TRUE;
2742
default:    IsVector = FALSE;
2743
endcase
2744
endfunction
2745
 
2746
function IsVeins;
2747
input [47:0] isn;
2748
case(isn[`INSTRUCTION_OP])
2749
`IVECTOR:   IsVeins = isn[`INSTRUCTION_S2]==`VEINS;
2750
default:    IsVeins = FALSE;
2751
endcase
2752
endfunction
2753
 
2754
function IsVex;
2755
input [47:0] isn;
2756
case(isn[`INSTRUCTION_OP])
2757
`IVECTOR:   IsVex = isn[`INSTRUCTION_S2]==`VEX;
2758
default:    IsVex = FALSE;
2759
endcase
2760
endfunction
2761
 
2762
function IsVCmprss;
2763
input [47:0] isn;
2764
case(isn[`INSTRUCTION_OP])
2765
`IVECTOR:   IsVCmprss = isn[`INSTRUCTION_S2]==`VCMPRSS || isn[`INSTRUCTION_S2]==`VCIDX;
2766
default:    IsVCmprss = FALSE;
2767
endcase
2768
endfunction
2769
 
2770
function IsVShifti;
2771
input [47:0] isn;
2772
case(isn[`INSTRUCTION_OP])
2773
`IVECTOR:
2774
                    case(isn[`INSTRUCTION_S2])
2775
            `VSHL,`VSHR,`VASR:
2776
                IsVShifti = {isn[25],isn[22]}==2'd2;
2777
            default:    IsVShifti = FALSE;
2778
            endcase
2779
default:    IsVShifti = FALSE;
2780
endcase
2781
endfunction
2782
 
2783
function IsVLS;
2784
input [47:0] isn;
2785
case(isn[`INSTRUCTION_OP])
2786
`MEMNDX:
2787
                if (IsLoad(isn))
2788
            case({isn[31:28],isn[22:21]})
2789
            `LVX,`LVWS:  IsVLS = TRUE;
2790
            default:    IsVLS = FALSE;
2791
            endcase
2792
    else
2793
            case({isn[31:28],isn[17:16]})
2794
            `SVX,`SVWS:  IsVLS = TRUE;
2795
            default:    IsVLS = FALSE;
2796
            endcase
2797
`LV,`SV:    IsVLS = TRUE;
2798
default:    IsVLS = FALSE;
2799
endcase
2800
endfunction
2801
 
2802
function [1:0] fnM2;
2803
input [31:0] isn;
2804
case(isn[`INSTRUCTION_OP])
2805
`RR:    fnM2 = isn[24:23];
2806
default:    fnM2 = 2'b00;
2807
endcase
2808
endfunction
2809
 
2810 61 robfinch
function IsMem;
2811 60 robfinch
input [47:0] isn;
2812
case(isn[`INSTRUCTION_OP])
2813
`MEMNDX:        IsMem = TRUE;
2814
`AMO:   IsMem = TRUE;
2815
`LB:    IsMem = TRUE;
2816
`LBU:   IsMem = TRUE;
2817
`Lx:    IsMem = TRUE;
2818
`LxU:   IsMem = TRUE;
2819
`LWR:   IsMem = TRUE;
2820
`LV,`SV:    IsMem = TRUE;
2821
`INC:           IsMem = TRUE;
2822
`SB:    IsMem = TRUE;
2823
`Sx:    IsMem = TRUE;
2824
`SWC:   IsMem = TRUE;
2825 61 robfinch
`PUSHC: IsMem = TRUE;
2826 60 robfinch
`CAS:   IsMem = TRUE;
2827
`LVx:           IsMem = TRUE;
2828
`LVxU:  IsMem = TRUE;
2829
default:    IsMem = FALSE;
2830
endcase
2831
endfunction
2832
 
2833
function IsMemNdx;
2834
input [47:0] isn;
2835
case(isn[`INSTRUCTION_OP])
2836
`MEMNDX:        IsMemNdx = TRUE;
2837
default:    IsMemNdx = FALSE;
2838
endcase
2839
endfunction
2840
 
2841
function IsLoad;
2842
input [47:0] isn;
2843
case(isn[`INSTRUCTION_OP])
2844
`MEMNDX:        IsLoad = !isn[31];
2845
`LB:    IsLoad = TRUE;
2846
`LBU:   IsLoad = TRUE;
2847
`Lx:    IsLoad = TRUE;
2848
`LxU:   IsLoad = TRUE;
2849
`LWR:   IsLoad = TRUE;
2850
`LV:    IsLoad = TRUE;
2851
`LVx:   IsLoad = TRUE;
2852
`LVxU:  IsLoad = TRUE;
2853
default:    IsLoad = FALSE;
2854
endcase
2855
endfunction
2856
 
2857
function IsInc;
2858
input [47:0] isn;
2859
case(isn[`INSTRUCTION_OP])
2860
`MEMNDX:
2861
        if (isn[`INSTRUCTION_L2]==2'b00)
2862
                case({isn[31:28],isn[17:16]})
2863
    `INC:   IsInc = TRUE;
2864
    default:    IsInc = FALSE;
2865
    endcase
2866
        else
2867
                IsInc = FALSE;
2868
`INC:    IsInc = TRUE;
2869
default:    IsInc = FALSE;
2870
endcase
2871
endfunction
2872
 
2873
function IsSWC;
2874
input [47:0] isn;
2875
case(isn[`INSTRUCTION_OP])
2876
`MEMNDX:
2877
        if (isn[`INSTRUCTION_L2]==2'b00)
2878
                case({isn[31:28],isn[17:16]})
2879
    `SWCX:   IsSWC = TRUE;
2880
    default:    IsSWC = FALSE;
2881
    endcase
2882
        else
2883
                IsSWC = FALSE;
2884
`SWC:    IsSWC = TRUE;
2885
default:    IsSWC = FALSE;
2886
endcase
2887
endfunction
2888
 
2889
// Aquire / release bits are only available on indexed SWC / LWR
2890
function IsSWCX;
2891
input [47:0] isn;
2892
case(isn[`INSTRUCTION_OP])
2893
`MEMNDX:
2894
        if (isn[`INSTRUCTION_L2]==2'b00)
2895
                case({isn[31:28],isn[17:16]})
2896
    `SWCX:   IsSWCX = TRUE;
2897
    default:    IsSWCX = FALSE;
2898
    endcase
2899
        else
2900
                IsSWCX = FALSE;
2901
default:    IsSWCX = FALSE;
2902
endcase
2903
endfunction
2904
 
2905
function IsLWR;
2906
input [47:0] isn;
2907
case(isn[`INSTRUCTION_OP])
2908
`MEMNDX:
2909
        if (isn[`INSTRUCTION_L2]==2'b00)
2910
            case({isn[31:28],isn[22:21]})
2911
            `LWRX:   IsLWR = TRUE;
2912
            default:    IsLWR = FALSE;
2913
            endcase
2914
        else
2915
                IsLWR = FALSE;
2916
`LWR:    IsLWR = TRUE;
2917
default:    IsLWR = FALSE;
2918
endcase
2919
endfunction
2920
 
2921
function IsLWRX;
2922
input [47:0] isn;
2923
case(isn[`INSTRUCTION_OP])
2924
`MEMNDX:
2925
        if (isn[`INSTRUCTION_L2]==2'b00)
2926
            case({isn[31:28],isn[22:21]})
2927
            `LWRX:   IsLWRX = TRUE;
2928
            default:    IsLWRX = FALSE;
2929
            endcase
2930
        else
2931
                IsLWRX = FALSE;
2932
default:    IsLWRX = FALSE;
2933
endcase
2934
endfunction
2935
 
2936
function IsCAS;
2937
input [47:0] isn;
2938
case(isn[`INSTRUCTION_OP])
2939
`MEMNDX:
2940
        if (isn[`INSTRUCTION_L2]==2'b00)
2941
                case({isn[31:28],isn[17:16]})
2942
    `CASX:   IsCAS = TRUE;
2943
    default:    IsCAS = FALSE;
2944
    endcase
2945
        else
2946
                IsCAS = FALSE;
2947
`CAS:       IsCAS = TRUE;
2948
default:    IsCAS = FALSE;
2949
endcase
2950
endfunction
2951
 
2952
function IsAMO;
2953
input [47:0] isn;
2954
case(isn[`INSTRUCTION_OP])
2955
`AMO:       IsAMO = TRUE;
2956
default:    IsAMO = FALSE;
2957
endcase
2958
endfunction
2959
 
2960
// Really IsPredictableBranch
2961
// Does not include BccR's
2962
function IsBranch;
2963
input [47:0] isn;
2964
casez(isn[`INSTRUCTION_OP])
2965
`Bcc:   IsBranch = TRUE;
2966 61 robfinch
`BLcc:  IsBranch = TRUE;
2967 60 robfinch
`BBc:   IsBranch = TRUE;
2968
`BEQI:  IsBranch = TRUE;
2969 61 robfinch
`BNEI:  IsBranch = TRUE;
2970 60 robfinch
`CHK:   IsBranch = TRUE;
2971
default:    IsBranch = FALSE;
2972
endcase
2973
endfunction
2974
 
2975
function IsWait;
2976
input [47:0] isn;
2977
IsWait = isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`WAIT;
2978
endfunction
2979
 
2980
function IsCall;
2981
input [47:0] isn;
2982
IsCall = isn[`INSTRUCTION_OP]==`CALL && isn[7]==1'b0;
2983
endfunction
2984
 
2985
function IsJmp;
2986
input [47:0] isn;
2987
IsJmp = isn[`INSTRUCTION_OP]==`JMP && isn[7]==1'b0;
2988
endfunction
2989
 
2990
function IsFlowCtrl;
2991
input [47:0] isn;
2992
casez(isn[`INSTRUCTION_OP])
2993
`BRK:    IsFlowCtrl = TRUE;
2994
`R2:    case(isn[`INSTRUCTION_S2])
2995
        `RTI:   IsFlowCtrl = TRUE;
2996
        default:    IsFlowCtrl = FALSE;
2997
        endcase
2998
`Bcc:   IsFlowCtrl = TRUE;
2999 61 robfinch
`BLcc:  IsFlowCtrl = TRUE;
3000 60 robfinch
`BBc:           IsFlowCtrl = TRUE;
3001
`BEQI:  IsFlowCtrl = TRUE;
3002 61 robfinch
`BNEI:  IsFlowCtrl = TRUE;
3003 60 robfinch
`CHK:   IsFlowCtrl = TRUE;
3004
`JAL:   IsFlowCtrl = TRUE;
3005
`JMP:           IsFlowCtrl = TRUE;
3006
`CALL:  IsFlowCtrl = TRUE;
3007
`RET:   IsFlowCtrl = TRUE;
3008
default:    IsFlowCtrl = FALSE;
3009
endcase
3010
endfunction
3011
 
3012
function IsCache;
3013
input [47:0] isn;
3014
case(isn[`INSTRUCTION_OP])
3015
`MEMNDX:
3016
        if (isn[`INSTRUCTION_L2]==2'b00)
3017
            case({isn[31:28],isn[22:21]})
3018
            `CACHEX:    IsCache = TRUE;
3019
            default:    IsCache = FALSE;
3020
            endcase
3021
        else
3022
                IsCache = FALSE;
3023
`CACHE: IsCache = TRUE;
3024
default: IsCache = FALSE;
3025
endcase
3026
endfunction
3027
 
3028
function [4:0] CacheCmd;
3029
input [47:0] isn;
3030
case(isn[`INSTRUCTION_OP])
3031
`MEMNDX:
3032
        if (isn[`INSTRUCTION_L2]==2'b00)
3033
            case({isn[31:28],isn[22:21]})
3034
            `CACHEX:    CacheCmd = isn[17:13];
3035
            default:    CacheCmd = 5'd0;
3036
            endcase
3037
        else
3038
                CacheCmd = 5'd0;
3039
`CACHE: CacheCmd = isn[15:11];
3040
default: CacheCmd = 5'd0;
3041
endcase
3042
endfunction
3043
 
3044
function IsMemsb;
3045
input [47:0] isn;
3046
IsMemsb = (isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMSB);
3047
endfunction
3048
 
3049
function IsSEI;
3050
input [47:0] isn;
3051
IsSEI = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`SEI);
3052
endfunction
3053
 
3054
function IsLV;
3055
input [47:0] isn;
3056
case(isn[`INSTRUCTION_OP])
3057
`MEMNDX:
3058
        if (isn[`INSTRUCTION_L2]==2'b00)
3059
            case({isn[31:28],isn[22:21]})
3060
            `LVX:   IsLV = TRUE;
3061
            default:    IsLV = FALSE;
3062
            endcase
3063
        else
3064
                IsLV = FALSE;
3065
`LV:        IsLV = TRUE;
3066
default:    IsLV = FALSE;
3067
endcase
3068
endfunction
3069
 
3070 61 robfinch
function IsRet;
3071
input [47:0] isn;
3072
IsRet = isn[`INSTRUCTION_OP]==`RET;
3073
endfunction
3074
 
3075 60 robfinch
function IsRFW;
3076
input [47:0] isn;
3077
input [5:0] vqei;
3078
input [5:0] vli;
3079
input thrd;
3080
if (fnRt(isn,vqei,vli,thrd)==12'd0)
3081
    IsRFW = FALSE;
3082
else
3083
casez(isn[`INSTRUCTION_OP])
3084
`IVECTOR:   IsRFW = TRUE;
3085
`FVECTOR:   IsRFW = TRUE;
3086
`R2:
3087
        if (isn[`INSTRUCTION_L2]==2'b00)
3088
            casez(isn[`INSTRUCTION_S2])
3089
            `TLB:               IsRFW = TRUE;
3090
            `R1:
3091
                case(isn[22:18])
3092
                `MEMDB,`MEMSB,`SYNC,`SETWB,5'h14,5'h15: IsRFW = FALSE;
3093
                default:        IsRFW = TRUE;
3094
                endcase
3095
            `ADD:   IsRFW = TRUE;
3096
            `SUB:   IsRFW = TRUE;
3097 61 robfinch
            `SEQ:   IsRFW = TRUE;
3098 60 robfinch
            `SLT:   IsRFW = TRUE;
3099
            `SLTU:  IsRFW = TRUE;
3100
            `SLE:   IsRFW = TRUE;
3101
        `SLEU:  IsRFW = TRUE;
3102
            `AND:   IsRFW = TRUE;
3103
            `OR:    IsRFW = TRUE;
3104
            `XOR:   IsRFW = TRUE;
3105
            `NAND:      IsRFW = TRUE;
3106
            `NOR:               IsRFW = TRUE;
3107
            `XNOR:      IsRFW = TRUE;
3108
            `MULU:  IsRFW = TRUE;
3109
            `MULSU: IsRFW = TRUE;
3110
            `MUL:   IsRFW = TRUE;
3111
            `MULUH:  IsRFW = TRUE;
3112
            `MULSUH: IsRFW = TRUE;
3113
            `MULH:   IsRFW = TRUE;
3114
            `MULF:      IsRFW = TRUE;
3115
            `FXMUL:     IsRFW = TRUE;
3116
            `DIVU:  IsRFW = TRUE;
3117
            `DIVSU: IsRFW = TRUE;
3118
            `DIV:IsRFW = TRUE;
3119
            `MODU:  IsRFW = TRUE;
3120
            `MODSU: IsRFW = TRUE;
3121
            `MOD:IsRFW = TRUE;
3122
            `MOV:       IsRFW = TRUE;
3123
            `VMOV:      IsRFW = TRUE;
3124
            `SHIFTR,`SHIFT31,`SHIFT63:
3125
                        IsRFW = TRUE;
3126
            `MIN,`MAX:    IsRFW = TRUE;
3127
            `SEI:       IsRFW = TRUE;
3128
            default:    IsRFW = FALSE;
3129
            endcase
3130
        else if (isn[`INSTRUCTION_L2]==2'b01)
3131
                case(isn[47:42])
3132
                `CMOVEZ:        IsRFW = TRUE;
3133
                `CMOVNZ:        IsRFW = TRUE;
3134
                default:        IsRFW = FALSE;
3135
                endcase
3136
        else if (isn[7]==1'b1)
3137
        // The following instructions might come from a compressed version.
3138
            casez(isn[`INSTRUCTION_S2])
3139
            `ADD:   IsRFW = TRUE;
3140
            `SUB:   IsRFW = TRUE;
3141
            `AND:   IsRFW = TRUE;
3142
            `OR:    IsRFW = TRUE;
3143
            `XOR:   IsRFW = TRUE;
3144
            `MOV:       IsRFW = TRUE;
3145
            `SHIFTR,`SHIFT31,`SHIFT63:
3146
                        IsRFW = TRUE;
3147
            default:    IsRFW = FALSE;
3148
            endcase
3149
        else
3150
                IsRFW = FALSE;
3151
`MEMNDX:
3152
        if (isn[`INSTRUCTION_L2]==2'b10) begin
3153
                if (!isn[31])
3154
                        IsRFW = TRUE;
3155
                else
3156
                        case({isn[31:28],isn[17:16]})
3157
                        `PUSH:  IsRFW = TRUE;
3158
            `CASX:  IsRFW = TRUE;
3159
            default:    IsRFW = FALSE;
3160
            endcase
3161
        end
3162
        else if (isn[`INSTRUCTION_L2]==2'b00) begin
3163
                if (!isn[31])
3164
            case({isn[31:28],isn[22:21]})
3165
            `LBX:   IsRFW = TRUE;
3166
            `LBUX:  IsRFW = TRUE;
3167
            `LCX:   IsRFW = TRUE;
3168
            `LCUX:  IsRFW = TRUE;
3169
            `LHX:   IsRFW = TRUE;
3170
            `LHUX:  IsRFW = TRUE;
3171
            `LWX:   IsRFW = TRUE;
3172
            `LVBX:  IsRFW = TRUE;
3173
            `LVBUX: IsRFW = TRUE;
3174
            `LVCX:  IsRFW = TRUE;
3175
            `LVCUX: IsRFW = TRUE;
3176
            `LVHX:  IsRFW = TRUE;
3177
            `LVHUX: IsRFW = TRUE;
3178
            `LVWX:  IsRFW = TRUE;
3179
            `LWRX:  IsRFW = TRUE;
3180
            `LVX:   IsRFW = TRUE;
3181
            default:    IsRFW = FALSE;
3182
            endcase
3183
    else
3184
                        case({isn[31:28],isn[17:16]})
3185
                        `PUSH:  IsRFW = TRUE;
3186
            `CASX:  IsRFW = TRUE;
3187
            default:    IsRFW = FALSE;
3188
            endcase
3189
        end
3190
        else
3191
                IsRFW = FALSE;
3192
`BBc:   IsRFW = FALSE;
3193
`BITFIELD:  IsRFW = TRUE;
3194
`ADDI:      IsRFW = TRUE;
3195 61 robfinch
`SEQI:      IsRFW = TRUE;
3196 60 robfinch
`SLTI:      IsRFW = TRUE;
3197
`SLTUI:     IsRFW = TRUE;
3198
`SGTI:      IsRFW = TRUE;
3199
`SGTUI:     IsRFW = TRUE;
3200
`ANDI:      IsRFW = TRUE;
3201
`ORI:       IsRFW = TRUE;
3202
`XORI:      IsRFW = TRUE;
3203
`XNORI:                 IsRFW = TRUE;
3204
`MULUI:     IsRFW = TRUE;
3205
`MULI:      IsRFW = TRUE;
3206
`MULFI:                 IsRFW = TRUE;
3207
`DIVUI:     IsRFW = TRUE;
3208
`DIVI:      IsRFW = TRUE;
3209
`MODI:      IsRFW = TRUE;
3210
`JAL:       IsRFW = TRUE;
3211
`CALL:      IsRFW = TRUE;
3212
`RET:       IsRFW = TRUE;
3213
`LB:        IsRFW = TRUE;
3214
`LBU:       IsRFW = TRUE;
3215
`Lx:        IsRFW = TRUE;
3216
`LxU:       IsRFW = TRUE;
3217
`LWR:       IsRFW = TRUE;
3218
`LV:        IsRFW = TRUE;
3219
`LVx:                           IsRFW = TRUE;
3220
`LVxU:                  IsRFW = TRUE;
3221 61 robfinch
`PUSHC:                 IsRFW = TRUE;
3222 60 robfinch
`CAS:       IsRFW = TRUE;
3223
`AMO:                           IsRFW = TRUE;
3224
`CSRRW:                 IsRFW = TRUE;
3225
`AUIPC:                 IsRFW = TRUE;
3226
`LUI:                           IsRFW = TRUE;
3227
default:    IsRFW = FALSE;
3228
endcase
3229
endfunction
3230
 
3231
function IsShifti;
3232
input [47:0] isn;
3233
case(isn[`INSTRUCTION_OP])
3234
`R2:
3235
        if (isn[`INSTRUCTION_L2]==2'b00)
3236
            case(isn[`INSTRUCTION_S2])
3237
            `SHIFT31,`SHIFT63:
3238
                IsShifti = TRUE;
3239
            default: IsShifti = FALSE;
3240
            endcase
3241
    else
3242
        IsShifti = FALSE;
3243
default: IsShifti = FALSE;
3244
endcase
3245
endfunction
3246
 
3247
function IsShift;
3248
input [47:0] isn;
3249
case(isn[`INSTRUCTION_OP])
3250
`R2:
3251
        if (isn[`INSTRUCTION_L2]==2'b00)
3252
    case(isn[31:26])
3253
    `SHIFTR: IsShift = TRUE;
3254
    `SHIFT31: IsShift = TRUE;
3255
    `SHIFT63: IsShift = TRUE;
3256
    default: IsShift = FALSE;
3257
    endcase
3258
  else
3259
        IsShift = FALSE;
3260
default: IsShift = FALSE;
3261
endcase
3262
endfunction
3263
 
3264
function IsShift48;
3265
input [47:0] isn;
3266
case(isn[`INSTRUCTION_OP])
3267
`R2:
3268
        if (isn[`INSTRUCTION_L2]==2'b01)
3269
    case(isn[47:42])
3270
    `SHIFTR: IsShift48 = TRUE;
3271
    default: IsShift48 = FALSE;
3272
    endcase
3273
  else
3274
        IsShift48 = FALSE;
3275
default: IsShift48 = FALSE;
3276
endcase
3277
endfunction
3278
 
3279
function IsRtop;
3280
input [47:0] isn;
3281
case(isn[`INSTRUCTION_OP])
3282
`R2:
3283
        if (isn[`INSTRUCTION_L2]==2'b01)
3284
            case(isn[47:42])
3285
            `RTOP: IsRtop = TRUE;
3286
            default: IsRtop = FALSE;
3287
            endcase
3288
    else
3289
        IsRtop = FALSE;
3290
default: IsRtop = FALSE;
3291
endcase
3292
endfunction
3293
 
3294
function IsMul;
3295
input [47:0] isn;
3296
case(isn[`INSTRUCTION_OP])
3297
`R2:
3298
        if (isn[`INSTRUCTION_L2]==2'b00)
3299
    case(isn[`INSTRUCTION_S2])
3300
    `MULU,`MULSU,`MUL: IsMul = TRUE;
3301
    `MULUH,`MULSUH,`MULH: IsMul = TRUE;
3302
    default:    IsMul = FALSE;
3303
    endcase
3304
        else
3305
                IsMul = FALSE;
3306
`MULUI,`MULI:  IsMul = TRUE;
3307
default:    IsMul = FALSE;
3308
endcase
3309
endfunction
3310
 
3311
function IsDivmod;
3312
input [47:0] isn;
3313
case(isn[`INSTRUCTION_OP])
3314
`R2:
3315
        if (isn[`INSTRUCTION_L2]==2'b00)
3316
    case(isn[`INSTRUCTION_S2])
3317
    `DIVU,`DIVSU,`DIV: IsDivmod = TRUE;
3318
    `MODU,`MODSU,`MOD: IsDivmod = TRUE;
3319
    default: IsDivmod = FALSE;
3320
    endcase
3321
        else
3322
                IsDivmod = FALSE;
3323
`DIVUI,`DIVI,`MODI:  IsDivmod = TRUE;
3324
default:    IsDivmod = FALSE;
3325
endcase
3326
endfunction
3327
 
3328
function [7:0] fnSelect;
3329
input [47:0] ins;
3330
input [`ABITS] adr;
3331
begin
3332
        case(ins[`INSTRUCTION_OP])
3333
        `MEMNDX:
3334
                if (ins[`INSTRUCTION_L2]==2'b10) begin
3335
                        if (ins[31]) begin
3336
                                case({ins[31:28],ins[17:16]})
3337
                                `PUSH:  fnSelect = 8'hFF;
3338
                                default: fnSelect = 8'h00;
3339
                                endcase
3340
                        end
3341
                        else
3342
                                fnSelect = 8'h00;
3343
                end
3344
                else if (ins[`INSTRUCTION_L2]==2'b00) begin
3345
                        if (!ins[31])
3346
                                case({ins[31:28],ins[22:21]})
3347
                                `LBX,`LBUX,`LVBX,`LVBUX:
3348
                                   case(adr[2:0])
3349
                                   3'd0:    fnSelect = 8'h01;
3350
                                   3'd1:    fnSelect = 8'h02;
3351
                                   3'd2:    fnSelect = 8'h04;
3352
                                   3'd3:    fnSelect = 8'h08;
3353
                                   3'd4:    fnSelect = 8'h10;
3354
                                   3'd5:    fnSelect = 8'h20;
3355
                                   3'd6:    fnSelect = 8'h40;
3356
                                   3'd7:    fnSelect = 8'h80;
3357
                                   endcase
3358
                                `LCX,`LCUX,`LVCX,`LVCUX:
3359
                                    case(adr[2:1])
3360
                                    2'd0:   fnSelect = 8'h03;
3361
                                    2'd1:   fnSelect = 8'h0C;
3362
                                    2'd2:   fnSelect = 8'h30;
3363
                                    2'd3:   fnSelect = 8'hC0;
3364
                                    endcase
3365
                                `LHX,`LHUX,`LVHX,`LVHUX:
3366
                                   case(adr[2])
3367
                                   1'b0:    fnSelect = 8'h0F;
3368
                                   1'b1:    fnSelect = 8'hF0;
3369
                                   endcase
3370
                                `INC,`LVWX,
3371
                                `LWX,`LWRX,`LVX:
3372
                                   fnSelect = 8'hFF;
3373
                                default:fnSelect = 8'hFF;
3374
                endcase
3375
            else
3376
                                case({ins[31:28],ins[17:16]})
3377
               `SBX:
3378
                   case(adr[2:0])
3379
                   3'd0:    fnSelect = 8'h01;
3380
                   3'd1:    fnSelect = 8'h02;
3381
                   3'd2:    fnSelect = 8'h04;
3382
                   3'd3:    fnSelect = 8'h08;
3383
                   3'd4:    fnSelect = 8'h10;
3384
                   3'd5:    fnSelect = 8'h20;
3385
                   3'd6:    fnSelect = 8'h40;
3386
                   3'd7:    fnSelect = 8'h80;
3387
                   endcase
3388
                `SCX:
3389
                    case(adr[2:1])
3390
                    2'd0:   fnSelect = 8'h03;
3391
                    2'd1:   fnSelect = 8'h0C;
3392
                    2'd2:   fnSelect = 8'h30;
3393
                    2'd3:   fnSelect = 8'hC0;
3394
                    endcase
3395
                `SHX:
3396
                   case(adr[2])
3397
                   1'b0:    fnSelect = 8'h0F;
3398
                   1'b1:    fnSelect = 8'hF0;
3399
                   endcase
3400
               `INC,
3401
               `SWX,`SWCX,`SVX,`CASX,`PUSH:
3402
                   fnSelect = 8'hFF;
3403
               default: fnSelect = 8'h00;
3404
                   endcase
3405
                 end
3406
           else
3407
                fnSelect = 8'h00;
3408
  `LB,`LBU,`SB:
3409
                case(adr[2:0])
3410
                3'd0:   fnSelect = 8'h01;
3411
                3'd1:   fnSelect = 8'h02;
3412
                3'd2:   fnSelect = 8'h04;
3413
                3'd3:   fnSelect = 8'h08;
3414
                3'd4:   fnSelect = 8'h10;
3415
                3'd5:   fnSelect = 8'h20;
3416
                3'd6:   fnSelect = 8'h40;
3417
                3'd7:   fnSelect = 8'h80;
3418
                endcase
3419
  `Lx,`LxU,`LVx,`LVxU:
3420
        casez(ins[20:18])
3421
        3'b100: fnSelect = 8'hFF;
3422
        3'b?10: fnSelect = adr[2] ? 8'hF0 : 8'h0F;
3423
        3'b??1:
3424
      case(adr[2:1])
3425
      2'd0:   fnSelect = 8'h03;
3426
      2'd1:   fnSelect = 8'h0C;
3427
      2'd2:   fnSelect = 8'h30;
3428
      2'd3:   fnSelect = 8'hC0;
3429
      endcase
3430
    default: fnSelect = 8'h00;
3431
    endcase
3432
  `Sx:
3433
        casez(ins[15:13])
3434
        3'b100: fnSelect = 8'hFF;
3435
        3'b?10: fnSelect = adr[2] ? 8'hF0 : 8'h0F;
3436
        3'b??1:
3437
      case(adr[2:1])
3438
      2'd0:   fnSelect = 8'h03;
3439
      2'd1:   fnSelect = 8'h0C;
3440
      2'd2:   fnSelect = 8'h30;
3441
      2'd3:   fnSelect = 8'hC0;
3442
      endcase
3443
    default: fnSelect = 8'h00;
3444
    endcase
3445 61 robfinch
  `PUSHC,
3446 60 robfinch
        `INC,
3447
        `LWR,`SWC,`CAS:   fnSelect = 8'hFF;
3448
        `LV,`SV:   fnSelect = 8'hFF;
3449
        `AMO:
3450
                case(ins[23:21])
3451
                3'd0:   fnSelect = {8'h01 << adr[2:0]};
3452
                3'd1:   fnSelect = {8'h03 << {adr[2:1],1'b0}};
3453
                3'd2:   fnSelect = {8'h0F << {adr[2],2'b00}};
3454
                3'd3:   fnSelect = 8'hFF;
3455
                default:        fnSelect = 8'hFF;
3456
                endcase
3457
        default:        fnSelect = 8'h00;
3458
        endcase
3459
end
3460
endfunction
3461
/*
3462
function [63:0] fnDatc;
3463
input [47:0] ins;
3464
input [63:0] dat;
3465
case(ins[`INSTRUCTION_OP])
3466
`R2:
3467
        if (isn[`INSTRUCTION_L2]==2'b01)
3468
                case(ins[47:42])
3469
                `FINDB:         fnDatc = dat[7:0];
3470
                `FINDC:         fnDatc = dat[15:0];
3471
                `FINDH:         fnDatc = dat[31:0];
3472
                `FINDW:         fnDatc = dat[63:0];
3473
                default:        fnDatc = dat[63:0];
3474
                endcase
3475
        else
3476
                fnDatc = dat[63:0];
3477
default:        fnDatc = dat[63:0];
3478
endcase
3479
endfunction
3480
*/
3481
/*
3482
function [63:0] fnMemInc;
3483
input [47:0] ins;
3484
case(ins[`INSTRUCTION_OP])
3485
`R2:
3486
        if (isn[`INSTRUCTION_L2]==2'b01)
3487
                case(ins[47:42])
3488
                `FINDB:         fnMemInc = 32'd1;
3489
                `FINDC:         fnMemInc = 32'd2;
3490
                `FINDH:         fnMemInc = 32'd4;
3491
                `FINDW:         fnMemInc = 32'd8;
3492
                default:        fnMemInc = 32'd8;
3493
                endcase
3494
        else
3495
                fnMemInc = 32'd8;
3496
default:        fnMemInc = 32'd8;
3497
endcase
3498
endfunction
3499
*/
3500
function [63:0] fnDatiAlign;
3501
input [47:0] ins;
3502
input [`ABITS] adr;
3503
input [63:0] dat;
3504
case(ins[`INSTRUCTION_OP])
3505
`MEMNDX:
3506
        if (ins[`INSTRUCTION_L2]==2'b00)
3507
            case({ins[31:28],ins[22:21]})
3508
            `LBX,`LVBX:
3509
                case(adr[2:0])
3510
                3'd0:   fnDatiAlign = {{56{dat[7]}},dat[7:0]};
3511
                3'd1:   fnDatiAlign = {{56{dat[15]}},dat[15:8]};
3512
                3'd2:   fnDatiAlign = {{56{dat[23]}},dat[23:16]};
3513
                3'd3:   fnDatiAlign = {{56{dat[31]}},dat[31:24]};
3514
                3'd4:   fnDatiAlign = {{56{dat[39]}},dat[39:32]};
3515
                3'd5:   fnDatiAlign = {{56{dat[47]}},dat[47:40]};
3516
                3'd6:   fnDatiAlign = {{56{dat[55]}},dat[55:48]};
3517
                3'd7:   fnDatiAlign = {{56{dat[63]}},dat[63:56]};
3518
                endcase
3519
            `LBUX,`LVBUX:
3520
                case(adr[2:0])
3521
                3'd0:   fnDatiAlign = {{56{1'b0}},dat[7:0]};
3522
                3'd1:   fnDatiAlign = {{56{1'b0}},dat[15:8]};
3523
                3'd2:   fnDatiAlign = {{56{1'b0}},dat[23:16]};
3524
                3'd3:   fnDatiAlign = {{56{1'b0}},dat[31:24]};
3525
                3'd4:   fnDatiAlign = {{56{1'b0}},dat[39:32]};
3526
                3'd5:   fnDatiAlign = {{56{1'b0}},dat[47:40]};
3527
                3'd6:   fnDatiAlign = {{56{1'b0}},dat[55:48]};
3528
                3'd7:   fnDatiAlign = {{56{2'b0}},dat[63:56]};
3529
                endcase
3530
            `LCX,`LVCX:
3531
                case(adr[2:1])
3532
                2'd0:   fnDatiAlign = {{48{dat[15]}},dat[15:0]};
3533
                2'd1:   fnDatiAlign = {{48{dat[31]}},dat[31:16]};
3534
                2'd2:   fnDatiAlign = {{48{dat[47]}},dat[47:32]};
3535
                2'd3:   fnDatiAlign = {{48{dat[63]}},dat[63:48]};
3536
                endcase
3537
            `LCUX,`LVCUX:
3538
                case(adr[2:1])
3539
                2'd0:   fnDatiAlign = {{48{1'b0}},dat[15:0]};
3540
                2'd1:   fnDatiAlign = {{48{1'b0}},dat[31:16]};
3541
                2'd2:   fnDatiAlign = {{48{1'b0}},dat[47:32]};
3542
                2'd3:   fnDatiAlign = {{48{1'b0}},dat[63:48]};
3543
                endcase
3544
            `LHX,`LVHX:
3545
                case(adr[2])
3546
                1'b0:   fnDatiAlign = {{32{dat[31]}},dat[31:0]};
3547
                1'b1:   fnDatiAlign = {{32{dat[63]}},dat[63:32]};
3548
                endcase
3549
            `LHUX,`LVHUX:
3550
                case(adr[2])
3551
                1'b0:   fnDatiAlign = {{32{1'b0}},dat[31:0]};
3552
                1'b1:   fnDatiAlign = {{32{1'b0}},dat[63:32]};
3553
                endcase
3554
            `LWX,`LWRX,`LVX,`CAS,`LVWX:  fnDatiAlign = dat;
3555
            default:    fnDatiAlign = dat;
3556
            endcase
3557
        else
3558
                fnDatiAlign = dat;
3559
`LB:
3560
  case(adr[2:0])
3561
  3'd0:   fnDatiAlign = {{56{dat[7]}},dat[7:0]};
3562
  3'd1:   fnDatiAlign = {{56{dat[15]}},dat[15:8]};
3563
  3'd2:   fnDatiAlign = {{56{dat[23]}},dat[23:16]};
3564
  3'd3:   fnDatiAlign = {{56{dat[31]}},dat[31:24]};
3565
  3'd4:   fnDatiAlign = {{56{dat[39]}},dat[39:32]};
3566
  3'd5:   fnDatiAlign = {{56{dat[47]}},dat[47:40]};
3567
  3'd6:   fnDatiAlign = {{56{dat[55]}},dat[55:48]};
3568
  3'd7:   fnDatiAlign = {{56{dat[63]}},dat[63:56]};
3569
  endcase
3570
`LBU:
3571
  case(adr[2:0])
3572
  3'd0:   fnDatiAlign = {{56{1'b0}},dat[7:0]};
3573
  3'd1:   fnDatiAlign = {{56{1'b0}},dat[15:8]};
3574
  3'd2:   fnDatiAlign = {{56{1'b0}},dat[23:16]};
3575
  3'd3:   fnDatiAlign = {{56{1'b0}},dat[31:24]};
3576
  3'd4:   fnDatiAlign = {{56{1'b0}},dat[39:32]};
3577
  3'd5:   fnDatiAlign = {{56{1'b0}},dat[47:40]};
3578
  3'd6:   fnDatiAlign = {{56{1'b0}},dat[55:48]};
3579
  3'd7:   fnDatiAlign = {{56{2'b0}},dat[63:56]};
3580
  endcase
3581
`Lx,`LVx:
3582
        casez(ins[20:18])
3583
        3'b100: fnDatiAlign = dat;
3584
        3'b?10:
3585
          case(adr[2])
3586
          1'b0:   fnDatiAlign = {{32{dat[31]}},dat[31:0]};
3587
          1'b1:   fnDatiAlign = {{32{dat[63]}},dat[63:32]};
3588
          endcase
3589
        3'b??1:
3590
          case(adr[2:1])
3591
          2'd0:   fnDatiAlign = {{48{dat[15]}},dat[15:0]};
3592
          2'd1:   fnDatiAlign = {{48{dat[31]}},dat[31:16]};
3593
          2'd2:   fnDatiAlign = {{48{dat[47]}},dat[47:32]};
3594
          2'd3:   fnDatiAlign = {{48{dat[63]}},dat[63:48]};
3595
          endcase
3596
        default:        fnDatiAlign = dat;
3597
        endcase
3598
`LxU,`LVxU:
3599
        casez(ins[20:18])
3600
        3'b100: fnDatiAlign = dat;
3601
        3'b?10:
3602
          case(adr[2])
3603
          1'b0:   fnDatiAlign = {{32{1'b0}},dat[31:0]};
3604
          1'b1:   fnDatiAlign = {{32{1'b0}},dat[63:32]};
3605
          endcase
3606
        3'b??1:
3607
          case(adr[2:1])
3608
          2'd0:   fnDatiAlign = {{48{1'b0}},dat[15:0]};
3609
          2'd1:   fnDatiAlign = {{48{1'b0}},dat[31:16]};
3610
          2'd2:   fnDatiAlign = {{48{1'b0}},dat[47:32]};
3611
          2'd3:   fnDatiAlign = {{48{1'b0}},dat[63:48]};
3612
          endcase
3613
        default:        fnDatiAlign = dat;
3614
        endcase
3615
`LWR,`LV,`CAS,`AMO:   fnDatiAlign = dat;
3616
default:    fnDatiAlign = dat;
3617
endcase
3618
endfunction
3619
 
3620
function [63:0] fnDato;
3621
input [47:0] isn;
3622
input [63:0] dat;
3623
case(isn[`INSTRUCTION_OP])
3624
`MEMNDX:
3625
        if (isn[`INSTRUCTION_L2]==2'b00)
3626
                case({isn[31:28],isn[17:16]})
3627
                `SBX:   fnDato = {8{dat[7:0]}};
3628
                `SCX:   fnDato = {4{dat[15:0]}};
3629
                `SHX:   fnDato = {2{dat[31:0]}};
3630
                default:    fnDato = dat;
3631
                endcase
3632
        else
3633
                fnDato = dat;
3634
`SB:   fnDato = {8{dat[7:0]}};
3635
`Sx:
3636
        casez(isn[15:13])
3637
        3'b100: fnDato = dat;
3638
        3'b?10: fnDato = {2{dat[31:0]}};
3639
        3'b??1: fnDato = {4{dat[15:0]}};
3640
        default:        fnDato = dat;
3641
        endcase
3642
`AMO:
3643
        case(isn[23:21])
3644
        3'd0:   fnDato = {8{dat[7:0]}};
3645
        3'd1:   fnDato = {4{dat[15:0]}};
3646
        3'd2:   fnDato = {2{dat[31:0]}};
3647
        3'd3:   fnDato = dat;
3648
        default:        fnDato = dat;
3649
        endcase
3650
default:    fnDato = dat;
3651
endcase
3652
endfunction
3653
 
3654
function IsTLB;
3655
input [47:0] isn;
3656
case(isn[`INSTRUCTION_OP])
3657
`R2:
3658
  case(isn[`INSTRUCTION_S2])
3659
  `TLB:   IsTLB = TRUE;
3660
  default:    IsTLB = FALSE;
3661
  endcase
3662
default:    IsTLB = FALSE;
3663
endcase
3664
endfunction
3665
 
3666
// Indicate if the ALU instruction is valid immediately (single cycle operation)
3667
function IsSingleCycle;
3668
input [47:0] isn;
3669
IsSingleCycle = !(IsMul(isn)|IsDivmod(isn)|IsTLB(isn)|IsShift48(isn));
3670
endfunction
3671
 
3672
 
3673
generate begin : gDecocderInst
3674
for (g = 0; g < QENTRIES; g = g + 1) begin
3675
`ifdef SUPPORT_SMT
3676
decoder8 iq0(.num({iqentry_tgt[g][8:7],iqentry_tgt[g][5:0]}), .out(iq_out[g]));
3677
`else
3678
decoder7 iq0(.num({iqentry_tgt[g][7],iqentry_tgt[g][5:0]}), .out(iq_out[g]));
3679
`endif
3680
end
3681
end
3682
endgenerate
3683
 
3684
initial begin: Init
3685
        //
3686
        //
3687
        // set up panic messages
3688
        message[ `PANIC_NONE ]                  = "NONE            ";
3689
        message[ `PANIC_FETCHBUFBEQ ]           = "FETCHBUFBEQ     ";
3690
        message[ `PANIC_INVALIDISLOT ]          = "INVALIDISLOT    ";
3691
        message[ `PANIC_IDENTICALDRAMS ]        = "IDENTICALDRAMS  ";
3692
        message[ `PANIC_OVERRUN ]               = "OVERRUN         ";
3693
        message[ `PANIC_HALTINSTRUCTION ]       = "HALTINSTRUCTION ";
3694
        message[ `PANIC_INVALIDMEMOP ]          = "INVALIDMEMOP    ";
3695
        message[ `PANIC_INVALIDFBSTATE ]        = "INVALIDFBSTATE  ";
3696
        message[ `PANIC_INVALIDIQSTATE ]        = "INVALIDIQSTATE  ";
3697
        message[ `PANIC_BRANCHBACK ]            = "BRANCHBACK      ";
3698
        message[ `PANIC_MEMORYRACE ]            = "MEMORYRACE      ";
3699
        message[ `PANIC_ALU0ONLY ] = "ALU0 Only       ";
3700
 
3701
        for (n = 0; n < 64; n = n + 1)
3702
                codebuf[n] <= 48'h0;
3703
 
3704
end
3705
 
3706
// ---------------------------------------------------------------------------
3707
// FETCH
3708
// ---------------------------------------------------------------------------
3709
//
3710 61 robfinch
assign fetchbuf0_mem = IsMem(fetchbuf0_instr) & ~IsRet(fetchbuf0_instr);// & IsLoad(fetchbuf0_instr);
3711 60 robfinch
assign fetchbuf0_rfw   = IsRFW(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd);
3712
 
3713
generate begin: gFetchbufDec
3714
if (`WAYS > 1) begin
3715 61 robfinch
assign fetchbuf1_mem = IsMem(fetchbuf1_instr) & ~IsRet(fetchbuf1_instr);// & IsLoad(fetchbuf1_instr);
3716 60 robfinch
assign fetchbuf1_rfw   = IsRFW(fetchbuf1_instr,vqe1,vl,fetchbuf1_thrd);
3717
end
3718
if (`WAYS > 2) begin
3719 61 robfinch
assign fetchbuf2_mem = IsMem(fetchbuf2_instr) & ~IsRet(fetchbuf2_instr);// & IsLoad(fetchbuf2_instr);
3720 60 robfinch
assign fetchbuf2_rfw   = IsRFW(fetchbuf2_instr,vqe2,vl,fetchbuf2_thrd);
3721
end
3722
end
3723
endgenerate
3724
 
3725
generate begin : gFetchbufInst
3726
if (`WAYS > 2) begin : gb1
3727
FT64_fetchbuf_x3 #(AMSB,RSTPC) ufb1
3728
(
3729
  .rst(rst),
3730
  .clk4x(clk4x),
3731
  .clk(clk),
3732
  .fcu_clk(fcu_clk),
3733
  .cs_i(vadr[31:16]==16'hFFFF),
3734
  .cyc_i(cyc),
3735
  .stb_i(stb_o),
3736
  .ack_o(dc_ack),
3737
  .we_i(we),
3738
  .adr_i(vadr[15:0]),
3739
  .dat_i(dat_o[47:0]),
3740
  .cmpgrp(cr0[10:8]),
3741
  .freezePC(freezePC),
3742
  .regLR(regLR),
3743
  .thread_en(thread_en),
3744
  .insn0(insn0),
3745
  .insn1(insn1),
3746
  .insn1(insn2),
3747
  .phit(phit),
3748
  .threadx(threadx),
3749
  .branchmiss(branchmiss),
3750
  .misspc(misspc),
3751
  .branchmiss_thrd(branchmiss_thrd),
3752
  .predict_takenA(predict_takenA),
3753
  .predict_takenB(predict_takenB),
3754
  .predict_takenC(predict_takenC),
3755
  .predict_takenD(predict_takenD),
3756
  .predict_takenE(predict_takenE),
3757
  .predict_takenF(predict_takenF),
3758
  .predict_taken0(predict_taken0),
3759
  .predict_taken1(predict_taken1),
3760
  .predict_taken2(predict_taken2),
3761
  .queued1(queued1),
3762
  .queued2(queued2),
3763
  .queued2(queued3),
3764
  .queuedNop(queuedNop),
3765
  .pc0(pc0a),
3766
  .pc1(pc1a),
3767
  .fetchbuf(fetchbuf),
3768
  .fetchbufA_v(fetchbufA_v),
3769
  .fetchbufB_v(fetchbufB_v),
3770
  .fetchbufC_v(fetchbufC_v),
3771
  .fetchbufD_v(fetchbufD_v),
3772
  .fetchbufD_v(fetchbufE_v),
3773
  .fetchbufD_v(fetchbufF_v),
3774
  .fetchbufA_pc(fetchbufA_pc),
3775
  .fetchbufB_pc(fetchbufB_pc),
3776
  .fetchbufC_pc(fetchbufC_pc),
3777
  .fetchbufD_pc(fetchbufD_pc),
3778
  .fetchbufD_pc(fetchbufE_pc),
3779
  .fetchbufD_pc(fetchbufF_pc),
3780
  .fetchbufA_instr(fetchbufA_instr),
3781
  .fetchbufB_instr(fetchbufB_instr),
3782
  .fetchbufC_instr(fetchbufC_instr),
3783
  .fetchbufD_instr(fetchbufD_instr),
3784
  .fetchbufE_instr(fetchbufE_instr),
3785
  .fetchbufF_instr(fetchbufF_instr),
3786
  .fetchbuf0_instr(fetchbuf0_instr),
3787
  .fetchbuf1_instr(fetchbuf1_instr),
3788
  .fetchbuf0_thrd(fetchbuf0_thrd),
3789
  .fetchbuf1_thrd(fetchbuf1_thrd),
3790
  .fetchbuf2_thrd(fetchbuf2_thrd),
3791
  .fetchbuf0_pc(fetchbuf0_pc),
3792
  .fetchbuf1_pc(fetchbuf1_pc),
3793
  .fetchbuf2_pc(fetchbuf2_pc),
3794
  .fetchbuf0_v(fetchbuf0_v),
3795
  .fetchbuf1_v(fetchbuf1_v),
3796
  .fetchbuf2_v(fetchbuf2_v),
3797
  .fetchbuf0_insln(fetchbuf0_insln),
3798
  .fetchbuf1_insln(fetchbuf1_insln),
3799
  .fetchbuf2_insln(fetchbuf2_insln),
3800 61 robfinch
  .codebuf0(codebuf[insn0[13:8]]),
3801
  .codebuf1(codebuf[insn1[13:8]]),
3802
  .codebuf2(codebuf[insn2[13:8]]),
3803 60 robfinch
  .btgtA(btgtA),
3804
  .btgtB(btgtB),
3805
  .btgtC(btgtC),
3806
  .btgtD(btgtD),
3807
  .btgtE(btgtE),
3808
  .btgtF(btgtF),
3809
  .nop_fetchbuf(nop_fetchbuf),
3810
  .take_branch0(take_branch0),
3811
  .take_branch1(take_branch1),
3812
  .take_branch2(take_branch2),
3813
  .stompedRets(stompedOnRets),
3814
  .pred_on(pred_on),
3815
  .panic(fb_panic)
3816
);
3817
end
3818
else if (`WAYS > 1) begin : gb1
3819
FT64_fetchbuf #(AMSB,RSTPC) ufb1
3820
(
3821
  .rst(rst),
3822
  .clk4x(clk4x),
3823
  .clk(clk),
3824
  .fcu_clk(fcu_clk),
3825
  .cs_i(vadr[31:16]==16'hFFFF),
3826
  .cyc_i(cyc),
3827
  .stb_i(stb_o),
3828
  .ack_o(dc_ack),
3829
  .we_i(we),
3830
  .adr_i(vadr[15:0]),
3831
  .dat_i(dat_o[47:0]),
3832
  .cmpgrp(cr0[10:8]),
3833
  .freezePC(freezePC),
3834
  .regLR(regLR),
3835
  .thread_en(thread_en),
3836
  .insn0(insn0),
3837
  .insn1(insn1),
3838
  .phit(phit),
3839
  .threadx(threadx),
3840
  .branchmiss(branchmiss),
3841
  .misspc(misspc),
3842
  .branchmiss_thrd(branchmiss_thrd),
3843
  .predict_takenA(predict_takenA),
3844
  .predict_takenB(predict_takenB),
3845
  .predict_takenC(predict_takenC),
3846
  .predict_takenD(predict_takenD),
3847
  .predict_taken0(predict_taken0),
3848
  .predict_taken1(predict_taken1),
3849
  .queued1(queued1),
3850
  .queued2(queued2),
3851
  .queuedNop(queuedNop),
3852
  .pc0(pc0a),
3853
  .pc1(pc1a),
3854
  .fetchbuf(fetchbuf),
3855
  .fetchbufA_v(fetchbufA_v),
3856
  .fetchbufB_v(fetchbufB_v),
3857
  .fetchbufC_v(fetchbufC_v),
3858
  .fetchbufD_v(fetchbufD_v),
3859
  .fetchbufA_pc(fetchbufA_pc),
3860
  .fetchbufB_pc(fetchbufB_pc),
3861
  .fetchbufC_pc(fetchbufC_pc),
3862
  .fetchbufD_pc(fetchbufD_pc),
3863
  .fetchbufA_instr(fetchbufA_instr),
3864
  .fetchbufB_instr(fetchbufB_instr),
3865
  .fetchbufC_instr(fetchbufC_instr),
3866
  .fetchbufD_instr(fetchbufD_instr),
3867
  .fetchbuf0_instr(fetchbuf0_instr),
3868
  .fetchbuf1_instr(fetchbuf1_instr),
3869
  .fetchbuf0_thrd(fetchbuf0_thrd),
3870
  .fetchbuf1_thrd(fetchbuf1_thrd),
3871
  .fetchbuf0_pc(fetchbuf0_pc),
3872
  .fetchbuf1_pc(fetchbuf1_pc),
3873
  .fetchbuf0_v(fetchbuf0_v),
3874
  .fetchbuf1_v(fetchbuf1_v),
3875
  .fetchbuf0_insln(fetchbuf0_insln),
3876
  .fetchbuf1_insln(fetchbuf1_insln),
3877 61 robfinch
  .codebuf0(codebuf[insn0[13:8]]),
3878
  .codebuf1(codebuf[insn1[13:8]]),
3879 60 robfinch
  .btgtA(btgtA),
3880
  .btgtB(btgtB),
3881
  .btgtC(btgtC),
3882
  .btgtD(btgtD),
3883
  .nop_fetchbuf(nop_fetchbuf),
3884
  .take_branch0(take_branch0),
3885
  .take_branch1(take_branch1),
3886
  .stompedRets(stompedOnRets),
3887
  .pred_on(pred_on),
3888
  .panic(fb_panic)
3889
);
3890
end
3891
else begin : gb1
3892
FT64_fetchbuf_x1 #(AMSB,RSTPC) ufb1
3893
(
3894
  .rst(rst),
3895
  .clk4x(clk4x),
3896
  .clk(clk),
3897
  .fcu_clk(fcu_clk),
3898
  .cs_i(vadr[31:16]==16'hFFFF),
3899
  .cyc_i(cyc),
3900
  .stb_i(stb_o),
3901
  .ack_o(dc_ack),
3902
  .we_i(we),
3903
  .adr_i(vadr[15:0]),
3904
  .dat_i(dat_o[47:0]),
3905
  .cmpgrp(cr0[10:8]),
3906
  .freezePC(freezePC),
3907
  .regLR(regLR),
3908
  .thread_en(thread_en),
3909
  .insn0(insn0),
3910
  .phit(phit),
3911
  .threadx(threadx),
3912
  .branchmiss(branchmiss),
3913
  .misspc(misspc),
3914
  .branchmiss_thrd(branchmiss_thrd),
3915
  .predict_takenA(predict_takenA),
3916
  .predict_takenB(predict_takenB),
3917
  .predict_taken0(predict_taken0),
3918
  .queued1(queued1),
3919
  .queuedNop(queuedNop),
3920
  .pc0(pc0a),
3921
  .fetchbuf(fetchbuf),
3922
  .fetchbufA_v(fetchbufA_v),
3923
  .fetchbufB_v(fetchbufB_v),
3924
  .fetchbufA_pc(fetchbufA_pc),
3925
  .fetchbufB_pc(fetchbufB_pc),
3926
  .fetchbufA_instr(fetchbufA_instr),
3927
  .fetchbufB_instr(fetchbufB_instr),
3928
  .fetchbuf0_instr(fetchbuf0_instr),
3929
  .fetchbuf0_thrd(fetchbuf0_thrd),
3930
  .fetchbuf0_pc(fetchbuf0_pc),
3931
  .fetchbuf0_v(fetchbuf0_v),
3932
  .fetchbuf0_insln(fetchbuf0_insln),
3933
  .fetchbuf0_pbyte(fetchbuf0_pbyte),
3934 61 robfinch
  .codebuf0(codebuf[insn0[13:8]]),
3935 60 robfinch
  .btgtA(btgtA),
3936
  .btgtB(btgtB),
3937
  .nop_fetchbuf(nop_fetchbuf),
3938
  .take_branch0(take_branch0),
3939
  .stompedRets(stompedOnRets),
3940
  .pred_on(pred_on),
3941
  .panic(fb_panic)
3942
);
3943
assign fetchbuf1_v = `INV;
3944
end
3945
end
3946
endgenerate
3947
 
3948 61 robfinch
// Stores might exception so we don't want the heads to advance if a subsequent
3949
// instruction is store even though there's no target register.
3950 60 robfinch
wire cmt_head1 = (!iqentry_rfw[heads[1]] && !iqentry_oddball[heads[1]] && ~|iqentry_exc[heads[1]]);
3951
wire cmt_head2 = (!iqentry_rfw[heads[2]] && !iqentry_oddball[heads[2]] && ~|iqentry_exc[heads[2]]);
3952
 
3953
// Determine the head increment amount, this must match code later on.
3954
reg [2:0] hi_amt;
3955
always @*
3956
begin
3957
        hi_amt <= 4'd0;
3958
  casez ({ iqentry_v[heads[0]],
3959
                iqentry_state[heads[0]]==IQS_CMT,
3960
                iqentry_v[heads[1]],
3961
                iqentry_state[heads[1]]==IQS_CMT,
3962
                iqentry_v[heads[2]],
3963
                iqentry_state[heads[2]]==IQS_CMT})
3964
 
3965
        // retire 3
3966
        6'b0?_0?_0?:
3967
                if (heads[0] != tail0 && heads[1] != tail0 && heads[2] != tail0)
3968
                        hi_amt <= 3'd3;
3969
                else if (heads[0] != tail0 && heads[1] != tail0)
3970
                        hi_amt <= 3'd2;
3971
                else if (heads[0] != tail0)
3972
                        hi_amt <= 3'd1;
3973
        6'b0?_0?_10:
3974
                if (heads[0] != tail0 && heads[1] != tail0)
3975
                        hi_amt <= 3'd2;
3976
                else if (heads[0] != tail0)
3977
                        hi_amt <= 3'd1;
3978
                else
3979
                        hi_amt <= 3'd0;
3980
        6'b0?_0?_11:
3981
                if (`NUM_CMT > 2 || cmt_head2)
3982
                        hi_amt <= 3'd3;
3983
                else
3984
                        hi_amt <= 3'd2;
3985
 
3986
        // retire 1 (wait for regfile for heads[1])
3987
        6'b0?_10_??:
3988
                hi_amt <= 3'd1;
3989
 
3990
        // retire 2
3991
        6'b0?_11_0?,
3992
        6'b0?_11_10:
3993
    if (`NUM_CMT > 1 || cmt_head1)
3994
                        hi_amt <= 3'd2;
3995
    else
3996
                        hi_amt <= 3'd1;
3997
  6'b0?_11_11:
3998
    if (`NUM_CMT > 2 || (`NUM_CMT > 1 && cmt_head2))
3999
                        hi_amt <= 3'd3;
4000
        else if (`NUM_CMT > 1 || cmt_head1)
4001
                        hi_amt <= 3'd2;
4002
        else
4003
                        hi_amt <= 3'd1;
4004
  6'b10_??_??:  ;
4005
  6'b11_0?_0?:
4006
        if (heads[1] != tail0 && heads[2] != tail0)
4007
                        hi_amt <= 3'd3;
4008
        else if (heads[1] != tail0)
4009
                        hi_amt <= 3'd2;
4010
        else
4011
                        hi_amt <= 3'd1;
4012
  6'b11_0?_10:
4013
        if (heads[1] != tail0)
4014
                        hi_amt <= 3'd2;
4015
        else
4016
                        hi_amt <= 3'd1;
4017
  6'b11_0?_11:
4018
        if (heads[1] != tail0) begin
4019
                if (`NUM_CMT > 2 || cmt_head2)
4020
                                hi_amt <= 3'd3;
4021
                else
4022
                                hi_amt <= 3'd2;
4023
        end
4024
        else
4025
                        hi_amt <= 3'd1;
4026
  6'b11_10_??:
4027
                        hi_amt <= 3'd1;
4028
  6'b11_11_0?:
4029
        if (`NUM_CMT > 1 && heads[2] != tail0)
4030
                        hi_amt <= 3'd3;
4031
        else if (cmt_head1 && heads[2] != tail0)
4032
                        hi_amt <= 3'd3;
4033
                else if (`NUM_CMT > 1 || cmt_head1)
4034
                        hi_amt <= 3'd2;
4035
        else
4036
                        hi_amt <= 3'd1;
4037
  6'b11_11_10:
4038
                if (`NUM_CMT > 1 || cmt_head1)
4039
                        hi_amt <= 3'd2;
4040
        else
4041
                        hi_amt <= 3'd1;
4042
        6'b11_11_11:
4043
                if (`NUM_CMT > 2 || (`NUM_CMT > 1 && cmt_head2))
4044
                        hi_amt <= 3'd3;
4045
                else if (`NUM_CMT > 1 || cmt_head1)
4046
                        hi_amt <= 3'd2;
4047
                else
4048
                        hi_amt <= 3'd1;
4049
        default:
4050
                begin
4051
                        hi_amt <= 3'd0;
4052
                        $display("hi_amt: Uncoded case %h",{ iqentry_v[heads[0]],
4053
                                iqentry_state[heads[0]],
4054
                                iqentry_v[heads[1]],
4055
                                iqentry_state[heads[1]],
4056
                                iqentry_v[heads[2]],
4057
                                iqentry_state[heads[2]]});
4058
                end
4059
  endcase
4060
end
4061
 
4062
// Amount subtracted from sequence numbers
4063
reg [`SNBITS] tosub;
4064
always @*
4065
case(hi_amt)
4066
3'd3: tosub <= (iqentry_v[heads[2]] ? iqentry_sn[heads[2]]
4067
                                                         : iqentry_v[heads[1]] ? iqentry_sn[heads[1]]
4068
                                                         : iqentry_v[heads[0]] ? iqentry_sn[heads[0]]
4069
                                                         : 4'b0);
4070
3'd2: tosub <= (iqentry_v[heads[1]] ? iqentry_sn[heads[1]]
4071
                                                         : iqentry_v[heads[0]] ? iqentry_sn[heads[0]]
4072
                                                         : 4'b0);
4073
3'd1: tosub <= (iqentry_v[heads[0]] ? iqentry_sn[heads[0]]
4074
                                                         : 4'b0);
4075
default:        tosub <= 4'd0;
4076
endcase
4077
 
4078
//initial begin: stop_at
4079
//#1000000; panic <= `PANIC_OVERRUN;
4080
//end
4081
 
4082
//
4083
// BRANCH-MISS LOGIC: livetarget
4084
//
4085
// livetarget implies that there is a not-to-be-stomped instruction that targets the register in question
4086
// therefore, if it is zero it implies the rf_v value should become VALID on a branchmiss
4087
// 
4088
 
4089
always @*
4090
for (j = 1; j < PREGS; j = j + 1) begin
4091
        livetarget[j] = 1'b0;
4092
        for (n = 0; n < QENTRIES; n = n + 1)
4093
                livetarget[j] = livetarget[j] | iqentry_livetarget[n][j];
4094
end
4095
 
4096
always @*
4097
        for (n = 0; n < QENTRIES; n = n + 1)
4098
                iqentry_livetarget[n] = {PREGS {iqentry_v[n]}} & {PREGS {~iqentry_stomp[n] && iqentry_thrd[n]==branchmiss_thrd}} & iq_out[n];
4099
 
4100
//
4101
// BRANCH-MISS LOGIC: latestID
4102
//
4103
// latestID is the instruction queue ID of the newest instruction (latest) that targets
4104
// a particular register.  looks a lot like scheduling logic, but in reverse.
4105
// 
4106
always @*
4107
        for (n = 0; n < QENTRIES; n = n + 1) begin
4108
                iqentry_cumulative[n] = 1'b0;
4109
                for (j = n; j < n + QENTRIES; j = j + 1) begin
4110
                        if (missid==(j % QENTRIES))
4111
                                for (k = n; k <= j; k = k + 1)
4112
                                        iqentry_cumulative[n] = iqentry_cumulative[n] | iqentry_livetarget[k % QENTRIES];
4113
                end
4114
        end
4115
 
4116
always @*
4117
        for (n = 0; n < QENTRIES; n = n + 1)
4118
    iqentry_latestID[n] = (missid == n || ((iqentry_livetarget[n] & iqentry_cumulative[(n+1)%QENTRIES]) == {PREGS{1'b0}}))
4119
                                    ? iqentry_livetarget[n]
4120
                                    : {PREGS{1'b0}};
4121
 
4122
always @*
4123
        for (n = 0; n < QENTRIES; n = n + 1)
4124
          iqentry_source[n] = | iqentry_latestID[n];
4125
 
4126
reg vqueued2;
4127
assign Ra0 = fnRa(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
4128
assign Rb0 = fnRb(fetchbuf0_instr,1'b0,vqe0,rfoa0[5:0],rfoa1[5:0],fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
4129
assign Rc0 = fnRc(fetchbuf0_instr,vqe0,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
4130
assign Rt0 = fnRt(fetchbuf0_instr,vqet0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
4131
assign Ra1 = fnRa(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
4132
assign Rb1 = fnRb(fetchbuf1_instr,1'b1,vqueued2 ? vqe0 + 1 : vqe1,rfoa0[5:0],rfoa1[5:0],fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
4133
assign Rc1 = fnRc(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
4134
assign Rt1 = fnRt(fetchbuf1_instr,vqueued2 ? vqet0 + 1 : vqet1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
4135
 
4136
//
4137
// additional logic for ISSUE
4138
//
4139
// for the moment, we look at ALU-input buffers to allow back-to-back issue of 
4140
// dependent instructions ... we do not, however, look ahead for DRAM requests 
4141
// that will become valid in the next cycle.  instead, these have to propagate
4142
// their results into the IQ entry directly, at which point it becomes issue-able
4143
//
4144
 
4145
// note that, for all intents & purposes, iqentry_done == iqentry_agen ... no need to duplicate
4146
 
4147
wire [QENTRIES-1:0] args_valid;
4148
wire [QENTRIES-1:0] could_issue;
4149
wire [QENTRIES-1:0] could_issueid;
4150
 
4151
// Note that bypassing is provided only from the first fpu.
4152
generate begin : issue_logic
4153
for (g = 0; g < QENTRIES; g = g + 1)
4154
begin
4155
assign args_valid[g] =
4156
                  (iqentry_a1_v[g]
4157
`ifdef FU_BYPASS
4158
        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready && (~alu0_mem | alu0_push))
4159
        || ((iqentry_a1_s[g] == alu1_sourceid && alu1_dataready && (~alu1_mem | alu1_push)) && (`NUM_ALU > 1))
4160
        || ((iqentry_a1_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
4161
`endif
4162
        )
4163
    && (iqentry_a2_v[g] || iqentry_mem[g]       // a2 does not need to be valid immediately for a mem op (agen), it is checked by iqentry_memready logic
4164
`ifdef FU_BYPASS
4165
        || (iqentry_a2_s[g] == alu0_sourceid && alu0_dataready && (~alu0_mem | alu0_push))
4166
        || ((iqentry_a2_s[g] == alu1_sourceid && alu1_dataready && (~alu1_mem | alu1_push)) && (`NUM_ALU > 1))
4167
        || ((iqentry_a2_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
4168
`endif
4169
        )
4170
    && (iqentry_a3_v[g]
4171
        || (iqentry_mem[g] & ~iqentry_agen[g] & ~iqentry_memndx[g])    // a3 needs to be valid for indexed instruction
4172
//        || (iqentry_mem[g] & ~iqentry_agen[g])
4173
`ifdef FU_BYPASS
4174
        || (iqentry_a3_s[g] == alu0_sourceid && alu0_dataready && (~alu0_mem | alu0_push))
4175
        || ((iqentry_a3_s[g] == alu1_sourceid && alu1_dataready && (~alu1_mem | alu1_push)) && (`NUM_ALU > 1))
4176
`endif
4177
        )
4178
    ;
4179
 
4180
assign could_issue[g] = iqentry_v[g] && iqentry_state[g]==IQS_QUEUED
4181
                                                                                                && args_valid[g]
4182
                                                                                                && iqentry_iv[g];
4183
                        //&& (iqentry_mem[g] ? !iqentry_agen[g] : 1'b1);
4184
 
4185
assign could_issueid[g] = (iqentry_v[g])// || (g==tail0 && canq1))// || (g==tail1 && canq2))
4186
                                                                                                                && !iqentry_iv[g];
4187
//                && (iqentry_a1_v[g] 
4188
//        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
4189
//        || (iqentry_a1_s[g] == alu1_sourceid && alu1_dataready));
4190
 
4191
end
4192
end
4193
endgenerate
4194
 
4195
// The (old) simulator didn't handle the asynchronous race loop properly in the 
4196
// original code. It would issue two instructions to the same islot. So the
4197
// issue logic has been re-written to eliminate the asynchronous loop.
4198
// Can't issue to the ALU if it's busy doing a long running operation like a 
4199
// divide.
4200
// ToDo: fix the memory synchronization, see fp_issue below
4201
`ifndef INLINE_DECODE
4202
always @*
4203
begin
4204
        iqentry_id1issue = {QENTRIES{1'b0}};
4205
        if (id1_available) begin
4206
                for (n = 0; n < QENTRIES; n = n + 1)
4207
                        if (could_issueid[heads[n]] && iqentry_id1issue=={QENTRIES{1'b0}})
4208
                          iqentry_id1issue[heads[n]] = `TRUE;
4209
        end
4210
end
4211
generate begin : gIDUIssue
4212
        if (`NUM_IDU > 1) begin
4213
                always @*
4214
                begin
4215
                        iqentry_id2issue = {QENTRIES{1'b0}};
4216
                        if (id2_available) begin
4217
                                for (n = 0; n < QENTRIES; n = n + 1)
4218
                                        if (could_issueid[heads[n]] && !iqentry_id1issue[heads[n]] && iqentry_id2issue=={QENTRIES{1'b0}})
4219
                                          iqentry_id2issue[heads[n]] = `TRUE;
4220
                        end
4221
                end
4222
        end
4223
        if (`NUM_IDU > 2) begin
4224
                always @*
4225
                begin
4226
                        iqentry_id3issue = {QENTRIES{1'b0}};
4227
                        if (id3_available) begin
4228
                                for (n = 0; n < QENTRIES; n = n + 1)
4229
                                        if (could_issueid[heads[n]]
4230
                                        && !iqentry_id1issue[heads[n]]
4231
                                        && !iqentry_id2issue[heads[n]]
4232
                                        && iqentry_id3issue=={QENTRIES{1'b0}})
4233
                                          iqentry_id3issue[heads[n]] = `TRUE;
4234
                        end
4235
                end
4236
        end
4237
end
4238
endgenerate
4239
`endif  // not INLINE_DECODE
4240
 
4241
// Detect if there are any valid queue entries prior to the given queue entry.
4242
reg [QENTRIES-1:0] prior_valid;
4243
//generate begin : gPriorValid
4244
always @*
4245
for (j = 0; j < QENTRIES; j = j + 1)
4246
begin
4247
        prior_valid[heads[j]] = 1'b0;
4248
        if (j > 0)
4249
                for (n = j-1; n >= 0; n = n - 1)
4250
                        prior_valid[heads[j]] = prior_valid[heads[j]]|iqentry_v[heads[n]];
4251
end
4252
//end
4253
//endgenerate
4254
 
4255
// Detect if there are any valid sync instructions prior to the given queue 
4256
// entry.
4257
reg [QENTRIES-1:0] prior_sync;
4258
//generate begin : gPriorSync
4259
always @*
4260
for (j = 0; j < QENTRIES; j = j + 1)
4261
begin
4262
        prior_sync[heads[j]] = 1'b0;
4263
        if (j > 0)
4264
                for (n = j-1; n >= 0; n = n - 1)
4265
                        prior_sync[heads[j]] = prior_sync[heads[j]]|(iqentry_v[heads[n]] & iqentry_sync[heads[n]]);
4266
end
4267
//end
4268
//endgenerate
4269
 
4270
// Detect if there are any valid fsync instructions prior to the given queue 
4271
// entry.
4272
reg [QENTRIES-1:0] prior_fsync;
4273
//generate begin : gPriorFsync
4274
always @*
4275
for (j = 0; j < QENTRIES; j = j + 1)
4276
begin
4277
        prior_fsync[heads[j]] = 1'b0;
4278
        if (j > 0)
4279
                for (n = j-1; n >= 0; n = n - 1)
4280
                        prior_fsync[heads[j]] = prior_fsync[heads[j]]|(iqentry_v[heads[n]] & iqentry_fsync[heads[n]]);
4281
end
4282
//end
4283
//endgenerate
4284
 
4285
// Start search for instructions to process at head of queue (oldest instruction).
4286
always @*
4287
begin
4288
        iqentry_alu0_issue = {QENTRIES{1'b0}};
4289
        iqentry_alu1_issue = {QENTRIES{1'b0}};
4290
 
4291
        if (alu0_available & alu0_idle) begin
4292
                for (n = 0; n < QENTRIES; n = n + 1) begin
4293
                        if (could_issue[heads[n]] && iqentry_alu[heads[n]]
4294
                        && iqentry_alu0_issue == {QENTRIES{1'b0}}
4295
                        // If there are no valid queue entries prior it doesn't matter if there is
4296
                        // a sync.
4297
                        && (!prior_sync[heads[n]] || !prior_valid[heads[n]])
4298
                        )
4299
                          iqentry_alu0_issue[heads[n]] = `TRUE;
4300
                end
4301
        end
4302
 
4303
        if (alu1_available && alu1_idle && `NUM_ALU > 1) begin
4304
//              if ((could_issue & ~iqentry_alu0_issue & ~iqentry_alu0) != {QENTRIES{1'b0}}) begin
4305
                        for (n = 0; n < QENTRIES; n = n + 1) begin
4306
                                if (could_issue[heads[n]] && iqentry_alu[heads[n]]
4307
                                        && !iqentry_alu0[heads[n]]      // alu0 only
4308
                                        && !iqentry_alu0_issue[heads[n]]
4309
                                        && iqentry_alu1_issue == {QENTRIES{1'b0}}
4310
                                        && (!prior_sync[heads[n]] || !prior_valid[heads[n]])
4311
                                )
4312
                                  iqentry_alu1_issue[heads[n]] = `TRUE;
4313
                        end
4314
//              end
4315
        end
4316
end
4317
 
4318
 
4319
// Start search for instructions to process at head of queue (oldest instruction).
4320
always @*
4321
begin
4322
        iqentry_fpu1_issue = {QENTRIES{1'b0}};
4323
        iqentry_fpu2_issue = {QENTRIES{1'b0}};
4324
 
4325
        if (fpu1_available && fpu1_idle && `NUM_FPU > 0) begin
4326
                for (n = 0; n < QENTRIES; n = n + 1) begin
4327
                        if (could_issue[heads[n]] && iqentry_fpu[heads[n]]
4328
                        && iqentry_fpu1_issue == {QENTRIES{1'b0}}
4329
                        // If there are no valid queue entries prior it doesn't matter if there is
4330
                        // a sync.
4331
                        && (!(prior_sync[heads[n]]|prior_fsync[heads[n]]) || !prior_valid[heads[n]])
4332
                        )
4333
                          iqentry_fpu1_issue[heads[n]] = `TRUE;
4334
                end
4335
        end
4336
 
4337
        if (fpu2_available && fpu2_idle && `NUM_FPU > 1) begin
4338
                for (n = 0; n < QENTRIES; n = n + 1) begin
4339
                        if (could_issue[heads[n]] && iqentry_fpu[heads[n]]
4340
                        && !iqentry_fpu1_issue[heads[n]]
4341
                        && iqentry_fpu2_issue == {QENTRIES{1'b0}}
4342
                        && (!(prior_sync[heads[n]]|prior_fsync[heads[n]]) || !prior_valid[heads[n]])
4343
                        )
4344
                          iqentry_fpu2_issue[heads[n]] = `TRUE;
4345
                end
4346
        end
4347
end
4348
 
4349
reg [QENTRIES-1:0] nextqd;
4350
// Next queue id
4351
 
4352
/*
4353
reg [`QBITS] nids [0:QENTRIES-1];
4354
always @*
4355
for (n = 0; n < QENTRIES; n = n + 1)
4356
begin
4357
        nids[n] = n[`QBITS];
4358
        for (j = n; j != (n+1) % QENTRIES; j = (j - 1) % QENTRIES)
4359
                if (iqentry_thrd[(j+1)%QENTRIES]==iqentry_thrd[n])
4360
                        nids[n] = (j + 1) % QENTRIES;
4361
        // Add one more compare and set
4362
end
4363
*/
4364
 
4365
reg [`QBITS] nids [0:QENTRIES-1];
4366
always @*
4367
for (j = 0; j < QENTRIES; j = j + 1) begin
4368
        // We can't both start and stop at j
4369
        for (n = j; n != (j+1)%QENTRIES; n = (n + (QENTRIES-1)) % QENTRIES)
4370
                if (iqentry_thrd[n]==iqentry_thrd[j])
4371
                        nids[j] = n;
4372
        // Do the last one
4373
        if (iqentry_thrd[(j+1)%QENTRIES]==iqentry_thrd[j])
4374
                nids[j] = (j+1)%QENTRIES;
4375
end
4376
/*
4377
assign nids[0] = nid0;
4378
assign nids[1] = nid1;
4379
assign nids[2] = nid2;
4380
assign nids[3] = nid3;
4381
assign nids[4] = nid4;
4382
assign nids[5] = nid5;
4383
assign nids[6] = nid6;
4384
assign nids[7] = nid7;
4385
assign nids[8] = nid8;
4386
assign nids[9] = nid9;
4387
*/
4388
// Search the queue for the next entry on the same thread.
4389
reg [`QBITS] nid;
4390
always @*
4391
begin
4392
        nid = fcu_id;
4393
        for (n = QENTRIES-1; n > 0; n = n - 1)
4394
                if (iqentry_thrd[(fcu_id + n) % QENTRIES]==fcu_thrd)
4395
                        nid = (fcu_id + n) % QENTRIES;
4396
end
4397
/*
4398
always @*
4399
if (iqentry_thrd[idp1(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4400
        nid = idp1(fcu_id);
4401
else if (iqentry_thrd[idp2(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4402
        nid = idp2(fcu_id);
4403
else if (iqentry_thrd[idp3(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4404
        nid = idp3(fcu_id);
4405
else if (iqentry_thrd[idp4(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4406
        nid = idp4(fcu_id);
4407
else if (iqentry_thrd[idp5(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4408
        nid = idp5(fcu_id);
4409
else if (iqentry_thrd[idp6(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4410
        nid = idp6(fcu_id);
4411
else if (iqentry_thrd[idp7(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4412
        nid = idp7(fcu_id);
4413
else if (iqentry_thrd[idp8(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4414
        nid = idp8(fcu_id);
4415
else if (iqentry_thrd[idp9(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4416
        nid = idp9(fcu_id);
4417
else
4418
        nid = fcu_id;
4419
*/
4420
always @*
4421
for (n = 0; n < QENTRIES; n = n + 1)
4422
        nextqd[n] <= iqentry_sn[nids[n]] > iqentry_sn[n] || iqentry_v[n];
4423
 
4424
//assign nextqd = 8'hFF;
4425
 
4426
// Don't issue to the fcu until the following instruction is enqueued.
4427
// However, if the queue is full then issue anyway. A branch miss will likely occur.
4428
// Start search for instructions at head of queue (oldest instruction).
4429
always @*
4430
begin
4431
        iqentry_fcu_issue = {QENTRIES{1'b0}};
4432
 
4433
        if (fcu_done & ~branchmiss) begin
4434
                for (n = 0; n < QENTRIES; n = n + 1) begin
4435
                        if (could_issue[heads[n]] && iqentry_fc[heads[n]] && (nextqd[heads[n]] || iqentry_br[heads[n]])
4436
                        && iqentry_fcu_issue == {QENTRIES{1'b0}}
4437
                        && (!prior_sync[heads[n]] || !prior_valid[heads[n]])
4438
                        )
4439
                          iqentry_fcu_issue[heads[n]] = `TRUE;
4440
                end
4441
        end
4442
end
4443
 
4444
 
4445
// Test if a given address is in the write buffer. This is done only for the
4446
// first two queue slots to save logic on comparators.
4447
reg inwb0;
4448
always @*
4449
begin
4450
        inwb0 = FALSE;
4451
`ifdef HAS_WB
4452
        for (n = 0; n < `WB_DEPTH; n = n + 1)
4453
                if (iqentry_ma[heads[0]][AMSB:3]==wb_addr[n][AMSB:3] && wb_v[n])
4454
                        inwb0 = TRUE;
4455
`endif
4456
end
4457
 
4458
reg inwb1;
4459
always @*
4460
begin
4461
        inwb1 = FALSE;
4462
`ifdef HAS_WB
4463
        for (n = 0; n < `WB_DEPTH; n = n + 1)
4464
                if (iqentry_ma[heads[1]][AMSB:3]==wb_addr[n][AMSB:3] && wb_v[n])
4465
                        inwb1 = TRUE;
4466
`endif
4467
end
4468
 
4469
always @*
4470
begin
4471
        for (n = 0; n < QENTRIES; n = n + 1) begin
4472 61 robfinch
                iqentry_v[n] = iqentry_state[n] != IQS_INVALID;
4473
                iqentry_done[n] = iqentry_state[n]==IQS_DONE || iqentry_state[n]==IQS_CMT;
4474
                iqentry_out[n] = iqentry_state[n]==IQS_OUT;
4475
                iqentry_agen[n] = iqentry_state[n]==IQS_AGEN;
4476 60 robfinch
        end
4477
end
4478
 
4479
//
4480
// determine if the instructions ready to issue can, in fact, issue.
4481
// "ready" means that the instruction has valid operands but has not gone yet
4482
reg [1:0] issue_count, missue_count;
4483
generate begin : gMemIssue
4484
always @*
4485
begin
4486
        issue_count = 0;
4487
         memissue[ heads[0] ] =  iqentry_memready[ heads[0] ] && !(iqentry_load[heads[0]] && inwb0);               // first in line ... go as soon as ready
4488
         if (memissue[heads[0]])
4489
                issue_count = issue_count + 1;
4490
 
4491
         memissue[ heads[1] ] = ~iqentry_stomp[heads[1]] && iqentry_memready[ heads[1] ]                // addr and data are valid
4492
                                        && issue_count < `NUM_MEM
4493
                                        // ... and no preceding instruction is ready to go
4494
                                        //&& ~iqentry_memready[heads[0]]
4495
                                        // ... and there is no address-overlap with any preceding instruction
4496
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]]) || iqentry_done[heads[0]]
4497
                                                || ((iqentry_ma[heads[1]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
4498
                                        // ... if a release, any prior memory ops must be done before this one
4499
                                        && (iqentry_rl[heads[1]] ? iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]] : 1'b1)
4500
                                        // ... if a preivous op has the aquire bit set
4501
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
4502
                                        // ... and there's nothing in the write buffer during a load
4503
                                        && !(iqentry_load[heads[1]] && (inwb1 || iqentry_store[heads[0]]))
4504
                                        // ... and, if it is a store, there is no chance of it being undone
4505
                                        && ((iqentry_load[heads[1]] && sple) ||
4506
                                           !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]]));
4507
         if (memissue[heads[1]])
4508
                issue_count = issue_count + 1;
4509
 
4510
         memissue[ heads[2] ] = ~iqentry_stomp[heads[2]] && iqentry_memready[ heads[2] ]                // addr and data are valid
4511
                                        // ... and no preceding instruction is ready to go
4512
                                        && issue_count < `NUM_MEM
4513
                                        //&& ~iqentry_memready[heads[0]]
4514
                                        //&& ~iqentry_memready[heads[1]] 
4515
                                        // ... and there is no address-overlap with any preceding instruction
4516
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]])  || iqentry_done[heads[0]]
4517
                                                || ((iqentry_ma[heads[2]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
4518
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]])  || iqentry_done[heads[1]]
4519
                                                || ((iqentry_ma[heads[2]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3] || iqentry_out[heads[1]] || iqentry_done[heads[1]])))
4520
                                        // ... if a release, any prior memory ops must be done before this one
4521
                                        && (iqentry_rl[heads[2]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
4522
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
4523
                                                                                         : 1'b1)
4524
                                        // ... if a preivous op has the aquire bit set
4525
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
4526
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
4527
                                        // ... and there's nothing in the write buffer during a load
4528
                                        && !(iqentry_load[heads[2]] && (wb_v!=1'b0
4529
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]]))
4530
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4531
            && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4532
                                && (!(iqentry_iv[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4533
                                        // ... and, if it is a SW, there is no chance of it being undone
4534
                                        && ((iqentry_load[heads[2]] && sple) ||
4535
                                              !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
4536
                                           && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]]));
4537
         if (memissue[heads[2]])
4538
                issue_count = issue_count + 1;
4539
 
4540
         memissue[ heads[3] ] = ~iqentry_stomp[heads[3]] && iqentry_memready[ heads[3] ]                // addr and data are valid
4541
                                        // ... and no preceding instruction is ready to go
4542
                                        && issue_count < `NUM_MEM
4543
                                        //&& ~iqentry_memready[heads[0]]
4544
                                        //&& ~iqentry_memready[heads[1]] 
4545
                                        //&& ~iqentry_memready[heads[2]] 
4546
                                        // ... and there is no address-overlap with any preceding instruction
4547
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]])  || iqentry_done[heads[0]]
4548
                                                || ((iqentry_ma[heads[3]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
4549
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]])  || iqentry_done[heads[1]]
4550
                                                || ((iqentry_ma[heads[3]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3] || iqentry_out[heads[1]] || iqentry_done[heads[1]])))
4551
                                        && (!iqentry_mem[heads[2]] || (iqentry_agen[heads[2]] & iqentry_out[heads[2]])  || iqentry_done[heads[2]]
4552
                                                || ((iqentry_ma[heads[3]][AMSB:3] != iqentry_ma[heads[2]][AMSB:3] || iqentry_out[heads[2]] || iqentry_done[heads[2]])))
4553
                                        // ... if a release, any prior memory ops must be done before this one
4554
                                        && (iqentry_rl[heads[3]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
4555
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
4556
                                                                                 && (iqentry_done[heads[2]] || !iqentry_v[heads[2]] || !iqentry_mem[heads[2]])
4557
                                                                                         : 1'b1)
4558
                                        // ... if a preivous op has the aquire bit set
4559
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
4560
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
4561
                                        && !(iqentry_aq[heads[2]] && iqentry_v[heads[2]])
4562
                                        // ... and there's nothing in the write buffer during a load
4563
                                        && !(iqentry_load[heads[3]] && (wb_v!=1'b0
4564
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]] || iqentry_store[heads[2]]))
4565
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4566
                    && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4567
                    && (!(iqentry_iv[heads[2]] && iqentry_memsb[heads[2]]) ||
4568
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4569
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4570
                                )
4571
                                && (!(iqentry_iv[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4572
                    && (!(iqentry_iv[heads[2]] && iqentry_memdb[heads[2]]) ||
4573
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4574
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4575
                                )
4576
                    // ... and, if it is a SW, there is no chance of it being undone
4577
                                        && ((iqentry_load[heads[3]] && sple) ||
4578
                                      !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
4579
                       && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]])
4580
                       && !(iqentry_fc[heads[2]]||iqentry_canex[heads[2]]));
4581
         if (memissue[heads[3]])
4582
                issue_count = issue_count + 1;
4583
 
4584
        if (QENTRIES > 4) begin
4585
         memissue[ heads[4] ] = ~iqentry_stomp[heads[4]] && iqentry_memready[ heads[4] ]                // addr and data are valid
4586
                                        // ... and no preceding instruction is ready to go
4587
                                        && issue_count < `NUM_MEM
4588
                                        //&& ~iqentry_memready[heads[0]]
4589
                                        //&& ~iqentry_memready[heads[1]] 
4590
                                        //&& ~iqentry_memready[heads[2]] 
4591
                                        //&& ~iqentry_memready[heads[3]] 
4592
                                        // ... and there is no address-overlap with any preceding instruction
4593
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]])  || iqentry_done[heads[0]]
4594
                                                || ((iqentry_ma[heads[4]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
4595
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]])  || iqentry_done[heads[1]]
4596
                                                || ((iqentry_ma[heads[4]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3] || iqentry_out[heads[1]] || iqentry_done[heads[1]])))
4597
                                        && (!iqentry_mem[heads[2]] || (iqentry_agen[heads[2]] & iqentry_out[heads[2]])  || iqentry_done[heads[2]]
4598
                                                || ((iqentry_ma[heads[4]][AMSB:3] != iqentry_ma[heads[2]][AMSB:3] || iqentry_out[heads[2]] || iqentry_done[heads[2]])))
4599
                                        && (!iqentry_mem[heads[3]] || (iqentry_agen[heads[3]] & iqentry_out[heads[3]])  || iqentry_done[heads[3]]
4600
                                                || ((iqentry_ma[heads[4]][AMSB:3] != iqentry_ma[heads[3]][AMSB:3] || iqentry_out[heads[3]] || iqentry_done[heads[3]])))
4601
                                        // ... if a release, any prior memory ops must be done before this one
4602
                                        && (iqentry_rl[heads[4]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
4603
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
4604
                                                                                 && (iqentry_done[heads[2]] || !iqentry_v[heads[2]] || !iqentry_mem[heads[2]])
4605
                                                                                 && (iqentry_done[heads[3]] || !iqentry_v[heads[3]] || !iqentry_mem[heads[3]])
4606
                                                                                         : 1'b1)
4607
                                        // ... if a preivous op has the aquire bit set
4608
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
4609
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
4610
                                        && !(iqentry_aq[heads[2]] && iqentry_v[heads[2]])
4611
                                        && !(iqentry_aq[heads[3]] && iqentry_v[heads[3]])
4612
                                        // ... and there's nothing in the write buffer during a load
4613
                                        && !(iqentry_load[heads[4]] && (wb_v!=1'b0
4614
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]] || iqentry_store[heads[2]] || iqentry_store[heads[3]]))
4615
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4616
                    && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4617
                    && (!(iqentry_iv[heads[2]] && iqentry_memsb[heads[2]]) ||
4618
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4619
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4620
                                )
4621
                    && (!(iqentry_iv[heads[3]] && iqentry_memsb[heads[3]]) ||
4622
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4623
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4624
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
4625
                                )
4626
                                && (!(iqentry_v[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4627
                    && (!(iqentry_iv[heads[2]] && iqentry_memdb[heads[2]]) ||
4628
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4629
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4630
                                )
4631
                    && (!(iqentry_iv[heads[3]] && iqentry_memdb[heads[3]]) ||
4632
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4633
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4634
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
4635
                                )
4636
                                        // ... and, if it is a SW, there is no chance of it being undone
4637
                                        && ((iqentry_load[heads[4]] && sple) ||
4638
                                      !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
4639
                       && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]])
4640
                       && !(iqentry_fc[heads[2]]||iqentry_canex[heads[2]])
4641
                       && !(iqentry_fc[heads[3]]||iqentry_canex[heads[3]]));
4642
         if (memissue[heads[4]])
4643
                issue_count = issue_count + 1;
4644
        end
4645
 
4646
        if (QENTRIES > 5) begin
4647
         memissue[ heads[5] ] = ~iqentry_stomp[heads[5]] && iqentry_memready[ heads[5] ]                // addr and data are valid
4648
                                        // ... and no preceding instruction is ready to go
4649
                                        && issue_count < `NUM_MEM
4650
                                        //&& ~iqentry_memready[heads[0]]
4651
                                        //&& ~iqentry_memready[heads[1]] 
4652
                                        //&& ~iqentry_memready[heads[2]] 
4653
                                        //&& ~iqentry_memready[heads[3]] 
4654
                                        //&& ~iqentry_memready[heads[4]] 
4655
                                        // ... and there is no address-overlap with any preceding instruction
4656
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]]) || iqentry_done[heads[0]]
4657
                                                || ((iqentry_ma[heads[5]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
4658
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]]) || iqentry_done[heads[1]]
4659
                                                || ((iqentry_ma[heads[5]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3] || iqentry_out[heads[1]] || iqentry_done[heads[1]])))
4660
                                        && (!iqentry_mem[heads[2]] || (iqentry_agen[heads[2]] & iqentry_out[heads[2]]) || iqentry_done[heads[2]]
4661
                                                || ((iqentry_ma[heads[5]][AMSB:3] != iqentry_ma[heads[2]][AMSB:3] || iqentry_out[heads[2]] || iqentry_done[heads[2]])))
4662
                                        && (!iqentry_mem[heads[3]] || (iqentry_agen[heads[3]] & iqentry_out[heads[3]]) || iqentry_done[heads[3]]
4663
                                                || ((iqentry_ma[heads[5]][AMSB:3] != iqentry_ma[heads[3]][AMSB:3] || iqentry_out[heads[3]] || iqentry_done[heads[3]])))
4664
                                        && (!iqentry_mem[heads[4]] || (iqentry_agen[heads[4]] & iqentry_out[heads[4]]) || iqentry_done[heads[4]]
4665
                                                || ((iqentry_ma[heads[5]][AMSB:3] != iqentry_ma[heads[4]][AMSB:3] || iqentry_out[heads[4]] || iqentry_done[heads[4]])))
4666
                                        // ... if a release, any prior memory ops must be done before this one
4667
                                        && (iqentry_rl[heads[5]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
4668
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
4669
                                                                                 && (iqentry_done[heads[2]] || !iqentry_v[heads[2]] || !iqentry_mem[heads[2]])
4670
                                                                                 && (iqentry_done[heads[3]] || !iqentry_v[heads[3]] || !iqentry_mem[heads[3]])
4671
                                                                                 && (iqentry_done[heads[4]] || !iqentry_v[heads[4]] || !iqentry_mem[heads[4]])
4672
                                                                                         : 1'b1)
4673
                                        // ... if a preivous op has the aquire bit set
4674
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
4675
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
4676
                                        && !(iqentry_aq[heads[2]] && iqentry_v[heads[2]])
4677
                                        && !(iqentry_aq[heads[3]] && iqentry_v[heads[3]])
4678
                                        && !(iqentry_aq[heads[4]] && iqentry_v[heads[4]])
4679
                                        // ... and there's nothing in the write buffer during a load
4680
                                        && !(iqentry_load[heads[5]] && (wb_v!=1'b0
4681
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]] || iqentry_store[heads[2]] || iqentry_store[heads[3]]
4682
                                                || iqentry_store[heads[4]]))
4683
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4684
                    && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4685
                    && (!(iqentry_iv[heads[2]] && iqentry_memsb[heads[2]]) ||
4686
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4687
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4688
                                )
4689
                    && (!(iqentry_iv[heads[3]] && iqentry_memsb[heads[3]]) ||
4690
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4691
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4692
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
4693
                                )
4694
                    && (!(iqentry_iv[heads[4]] && iqentry_memsb[heads[4]]) ||
4695
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4696
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4697
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4698
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
4699
                                )
4700
                                && (!(iqentry_iv[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4701
                    && (!(iqentry_iv[heads[2]] && iqentry_memdb[heads[2]]) ||
4702
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4703
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4704
                                )
4705
                    && (!(iqentry_iv[heads[3]] && iqentry_memdb[heads[3]]) ||
4706
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4707
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4708
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
4709
                                )
4710
                    && (!(iqentry_iv[heads[4]] && iqentry_memdb[heads[4]]) ||
4711
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4712
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4713
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4714
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
4715
                                )
4716
                                        // ... and, if it is a SW, there is no chance of it being undone
4717
                                        && ((iqentry_load[heads[5]] && sple) ||
4718
                                      !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
4719
                       && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]])
4720
                       && !(iqentry_fc[heads[2]]||iqentry_canex[heads[2]])
4721
                       && !(iqentry_fc[heads[3]]||iqentry_canex[heads[3]])
4722
                       && !(iqentry_fc[heads[4]]||iqentry_canex[heads[4]]));
4723
         if (memissue[heads[5]])
4724
                issue_count = issue_count + 1;
4725
        end
4726
 
4727
`ifdef FULL_ISSUE_LOGIC
4728
if (QENTRIES > 6) begin
4729
 memissue[ heads[6] ] = ~iqentry_stomp[heads[6]] && iqentry_memready[ heads[6] ]                // addr and data are valid
4730
                                        // ... and no preceding instruction is ready to go
4731
                                        && issue_count < `NUM_MEM
4732
                                        //&& ~iqentry_memready[heads[0]]
4733
                                        //&& ~iqentry_memready[heads[1]] 
4734
                                        //&& ~iqentry_memready[heads[2]] 
4735
                                        //&& ~iqentry_memready[heads[3]] 
4736
                                        //&& ~iqentry_memready[heads[4]] 
4737
                                        //&& ~iqentry_memready[heads[5]] 
4738
                                        // ... and there is no address-overlap with any preceding instruction
4739
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]]) || iqentry_done[heads[0]]
4740
                                                || ((iqentry_ma[heads[6]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3])))
4741
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]]) || iqentry_done[heads[1]]
4742
                                                || ((iqentry_ma[heads[6]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3])))
4743
                                        && (!iqentry_mem[heads[2]] || (iqentry_agen[heads[2]] & iqentry_out[heads[2]]) || iqentry_done[heads[2]]
4744
                                                || ((iqentry_ma[heads[6]][AMSB:3] != iqentry_ma[heads[2]][AMSB:3])))
4745
                                        && (!iqentry_mem[heads[3]] || (iqentry_agen[heads[3]] & iqentry_out[heads[3]]) || iqentry_done[heads[3]]
4746
                                                || ((iqentry_ma[heads[6]][AMSB:3] != iqentry_ma[heads[3]][AMSB:3])))
4747
                                        && (!iqentry_mem[heads[4]] || (iqentry_agen[heads[4]] & iqentry_out[heads[4]]) || iqentry_done[heads[4]]
4748
                                                || ((iqentry_ma[heads[6]][AMSB:3] != iqentry_ma[heads[4]][AMSB:3])))
4749
                                        && (!iqentry_mem[heads[5]] || (iqentry_agen[heads[5]] & iqentry_out[heads[5]]) || iqentry_done[heads[5]]
4750
                                                || ((iqentry_ma[heads[6]][AMSB:3] != iqentry_ma[heads[5]][AMSB:3])))
4751
                                        && (iqentry_rl[heads[6]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
4752
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
4753
                                                                                 && (iqentry_done[heads[2]] || !iqentry_v[heads[2]] || !iqentry_mem[heads[2]])
4754
                                                                                 && (iqentry_done[heads[3]] || !iqentry_v[heads[3]] || !iqentry_mem[heads[3]])
4755
                                                                                 && (iqentry_done[heads[4]] || !iqentry_v[heads[4]] || !iqentry_mem[heads[4]])
4756
                                                                                 && (iqentry_done[heads[5]] || !iqentry_v[heads[5]] || !iqentry_mem[heads[5]])
4757
                                                                                         : 1'b1)
4758
                                        // ... if a preivous op has the aquire bit set
4759
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
4760
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
4761
                                        && !(iqentry_aq[heads[2]] && iqentry_v[heads[2]])
4762
                                        && !(iqentry_aq[heads[3]] && iqentry_v[heads[3]])
4763
                                        && !(iqentry_aq[heads[4]] && iqentry_v[heads[4]])
4764
                                        && !(iqentry_aq[heads[5]] && iqentry_v[heads[5]])
4765
                                        // ... and there's nothing in the write buffer during a load
4766
                                        && !(iqentry_load[heads[6]] && (wb_v!=1'b0
4767
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]] || iqentry_store[heads[2]] || iqentry_store[heads[3]]
4768
                                                || iqentry_store[heads[4]] || iqentry_store[heads[5]]))
4769
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4770
                    && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4771
                    && (!(iqentry_iv[heads[2]] && iqentry_memsb[heads[2]]) ||
4772
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4773
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4774
                                )
4775
                    && (!(iqentry_iv[heads[3]] && iqentry_memsb[heads[3]]) ||
4776
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4777
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4778
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
4779
                                )
4780
                    && (!(iqentry_iv[heads[4]] && iqentry_memsb[heads[4]]) ||
4781
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4782
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4783
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4784
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
4785
                                )
4786
                    && (!(iqentry_iv[heads[5]] && iqentry_memsb[heads[5]]) ||
4787
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4788
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4789
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4790
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
4791
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
4792
                                )
4793
                                && (!(iqentry_iv[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4794
                    && (!(iqentry_iv[heads[2]] && iqentry_memdb[heads[2]]) ||
4795
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4796
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4797
                                )
4798
                    && (!(iqentry_iv[heads[3]] && iqentry_memdb[heads[3]]) ||
4799
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4800
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4801
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
4802
                                )
4803
                    && (!(iqentry_iv[heads[4]] && iqentry_memdb[heads[4]]) ||
4804
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4805
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4806
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4807
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
4808
                                )
4809
                    && (!(iqentry_iv[heads[5]] && iqentry_memdb[heads[5]]) ||
4810
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4811
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4812
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4813
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
4814
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
4815
                                )
4816
                                        // ... and, if it is a SW, there is no chance of it being undone
4817
                                        && ((iqentry_load[heads[6]] && sple) ||
4818
                                      !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
4819
                       && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]])
4820
                       && !(iqentry_fc[heads[2]]||iqentry_canex[heads[2]])
4821
                       && !(iqentry_fc[heads[3]]||iqentry_canex[heads[3]])
4822
                       && !(iqentry_fc[heads[4]]||iqentry_canex[heads[4]])
4823
                       && !(iqentry_fc[heads[5]]||iqentry_canex[heads[5]]));
4824
         if (memissue[heads[6]])
4825
                issue_count = issue_count + 1;
4826
        end
4827
 
4828
        if (QENTRIES > 7) begin
4829
        memissue[ heads[7] ] =  ~iqentry_stomp[heads[7]] && iqentry_memready[ heads[7] ]                // addr and data are valid
4830
                                        // ... and no preceding instruction is ready to go
4831
                                        && issue_count < `NUM_MEM
4832
                                        //&& ~iqentry_memready[heads[0]]
4833
                                        //&& ~iqentry_memready[heads[1]] 
4834
                                        //&& ~iqentry_memready[heads[2]] 
4835
                                        //&& ~iqentry_memready[heads[3]] 
4836
                                        //&& ~iqentry_memready[heads[4]] 
4837
                                        //&& ~iqentry_memready[heads[5]] 
4838
                                        //&& ~iqentry_memready[heads[6]] 
4839
                                        // ... and there is no address-overlap with any preceding instruction
4840
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]]) || iqentry_done[heads[0]]
4841
                                                || ((iqentry_ma[heads[7]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
4842
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]]) || iqentry_done[heads[1]]
4843
                                                || ((iqentry_ma[heads[7]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3] || iqentry_out[heads[1]] || iqentry_done[heads[1]])))
4844
                                        && (!iqentry_mem[heads[2]] || (iqentry_agen[heads[2]] & iqentry_out[heads[2]]) || iqentry_done[heads[2]]
4845
                                                || ((iqentry_ma[heads[7]][AMSB:3] != iqentry_ma[heads[2]][AMSB:3] || iqentry_out[heads[2]] || iqentry_done[heads[2]])))
4846
                                        && (!iqentry_mem[heads[3]] || (iqentry_agen[heads[3]] & iqentry_out[heads[3]]) || iqentry_done[heads[3]]
4847
                                                || ((iqentry_ma[heads[7]][AMSB:3] != iqentry_ma[heads[3]][AMSB:3] || iqentry_out[heads[3]] || iqentry_done[heads[3]])))
4848
                                        && (!iqentry_mem[heads[4]] || (iqentry_agen[heads[4]] & iqentry_out[heads[4]]) || iqentry_done[heads[4]]
4849
                                                || ((iqentry_ma[heads[7]][AMSB:3] != iqentry_ma[heads[4]][AMSB:3] || iqentry_out[heads[4]] || iqentry_done[heads[4]])))
4850
                                        && (!iqentry_mem[heads[5]] || (iqentry_agen[heads[5]] & iqentry_out[heads[5]]) || iqentry_done[heads[5]]
4851
                                                || ((iqentry_ma[heads[7]][AMSB:3] != iqentry_ma[heads[5]][AMSB:3] || iqentry_out[heads[5]] || iqentry_done[heads[5]])))
4852
                                        && (!iqentry_mem[heads[6]] || (iqentry_agen[heads[6]] & iqentry_out[heads[6]]) || iqentry_done[heads[6]]
4853
                                                || ((iqentry_ma[heads[7]][AMSB:3] != iqentry_ma[heads[6]][AMSB:3] || iqentry_out[heads[6]] || iqentry_done[heads[6]])))
4854
                                        && (iqentry_rl[heads[7]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
4855
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
4856
                                                                                 && (iqentry_done[heads[2]] || !iqentry_v[heads[2]] || !iqentry_mem[heads[2]])
4857
                                                                                 && (iqentry_done[heads[3]] || !iqentry_v[heads[3]] || !iqentry_mem[heads[3]])
4858
                                                                                 && (iqentry_done[heads[4]] || !iqentry_v[heads[4]] || !iqentry_mem[heads[4]])
4859
                                                                                 && (iqentry_done[heads[5]] || !iqentry_v[heads[5]] || !iqentry_mem[heads[5]])
4860
                                                                                 && (iqentry_done[heads[6]] || !iqentry_v[heads[6]] || !iqentry_mem[heads[6]])
4861
                                                                                         : 1'b1)
4862
                                        // ... if a preivous op has the aquire bit set
4863
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
4864
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
4865
                                        && !(iqentry_aq[heads[2]] && iqentry_v[heads[2]])
4866
                                        && !(iqentry_aq[heads[3]] && iqentry_v[heads[3]])
4867
                                        && !(iqentry_aq[heads[4]] && iqentry_v[heads[4]])
4868
                                        && !(iqentry_aq[heads[5]] && iqentry_v[heads[5]])
4869
                                        && !(iqentry_aq[heads[6]] && iqentry_v[heads[6]])
4870
                                        // ... and there's nothing in the write buffer during a load
4871
                                        && !(iqentry_load[heads[7]] && (wb_v!=1'b0
4872
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]] || iqentry_store[heads[2]] || iqentry_store[heads[3]]
4873
                                                || iqentry_store[heads[4]] || iqentry_store[heads[5]] || iqentry_store[heads[6]]))
4874
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4875
                    && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4876
                    && (!(iqentry_iv[heads[2]] && iqentry_memsb[heads[2]]) ||
4877
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4878
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4879
                                )
4880
                    && (!(iqentry_iv[heads[3]] && iqentry_memsb[heads[3]]) ||
4881
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4882
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4883
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
4884
                                )
4885
                    && (!(iqentry_iv[heads[4]] && iqentry_memsb[heads[4]]) ||
4886
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4887
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4888
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4889
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
4890
                                )
4891
                    && (!(iqentry_iv[heads[5]] && iqentry_memsb[heads[5]]) ||
4892
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4893
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4894
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4895
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
4896
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
4897
                                )
4898
                    && (!(iqentry_iv[heads[6]] && iqentry_memsb[heads[6]]) ||
4899
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4900
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4901
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4902
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
4903
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]])
4904
                                &&   (iqentry_done[heads[5]] || !iqentry_v[heads[5]]))
4905
                                )
4906
                                && (!(iqentry_iv[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4907
                    && (!(iqentry_iv[heads[2]] && iqentry_memdb[heads[2]]) ||
4908
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4909
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4910
                                )
4911
                    && (!(iqentry_iv[heads[3]] && iqentry_memdb[heads[3]]) ||
4912
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4913
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4914
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
4915
                                )
4916
                    && (!(iqentry_iv[heads[4]] && iqentry_memdb[heads[4]]) ||
4917
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4918
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4919
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4920
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
4921
                                )
4922
                    && (!(iqentry_iv[heads[5]] && iqentry_memdb[heads[5]]) ||
4923
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4924
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4925
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4926
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
4927
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
4928
                                )
4929
                    && (!(iqentry_iv[heads[6]] && iqentry_memdb[heads[6]]) ||
4930
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4931
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4932
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4933
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
4934
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]])
4935
                                && (!iqentry_mem[heads[5]] || iqentry_done[heads[5]] || !iqentry_v[heads[5]]))
4936
                                )
4937
                                        // ... and, if it is a SW, there is no chance of it being undone
4938
                                        && ((iqentry_load[heads[7]] && sple) ||
4939
                                      !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
4940
                       && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]])
4941
                       && !(iqentry_fc[heads[2]]||iqentry_canex[heads[2]])
4942
                       && !(iqentry_fc[heads[3]]||iqentry_canex[heads[3]])
4943
                       && !(iqentry_fc[heads[4]]||iqentry_canex[heads[4]])
4944
                       && !(iqentry_fc[heads[5]]||iqentry_canex[heads[5]])
4945
                       && !(iqentry_fc[heads[6]]||iqentry_canex[heads[6]]));
4946
         if (memissue[heads[7]])
4947
                issue_count = issue_count + 1;
4948
        end
4949
 
4950
        if (QENTRIES > 8) begin
4951
        memissue[ heads[8] ] =  ~iqentry_stomp[heads[8]] && iqentry_memready[ heads[8] ]                // addr and data are valid
4952
                                        // ... and no preceding instruction is ready to go
4953
                                        && issue_count < `NUM_MEM
4954
                                        //&& ~iqentry_memready[heads[0]]
4955
                                        //&& ~iqentry_memready[heads[1]] 
4956
                                        //&& ~iqentry_memready[heads[2]] 
4957
                                        //&& ~iqentry_memready[heads[3]] 
4958
                                        //&& ~iqentry_memready[heads[4]] 
4959
                                        //&& ~iqentry_memready[heads[5]] 
4960
                                        //&& ~iqentry_memready[heads[6]] 
4961
                                        // ... and there is no address-overlap with any preceding instruction
4962
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]]) || iqentry_done[heads[0]]
4963
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
4964
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]]) || iqentry_done[heads[1]]
4965
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3] || iqentry_out[heads[1]] || iqentry_done[heads[1]])))
4966
                                        && (!iqentry_mem[heads[2]] || (iqentry_agen[heads[2]] & iqentry_out[heads[2]]) || iqentry_done[heads[2]]
4967
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[2]][AMSB:3] || iqentry_out[heads[2]] || iqentry_done[heads[2]])))
4968
                                        && (!iqentry_mem[heads[3]] || (iqentry_agen[heads[3]] & iqentry_out[heads[3]]) || iqentry_done[heads[3]]
4969
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[3]][AMSB:3] || iqentry_out[heads[3]] || iqentry_done[heads[3]])))
4970
                                        && (!iqentry_mem[heads[4]] || (iqentry_agen[heads[4]] & iqentry_out[heads[4]]) || iqentry_done[heads[4]]
4971
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[4]][AMSB:3] || iqentry_out[heads[4]] || iqentry_done[heads[4]])))
4972
                                        && (!iqentry_mem[heads[5]] || (iqentry_agen[heads[5]] & iqentry_out[heads[5]]) || iqentry_done[heads[5]]
4973
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[5]][AMSB:3] || iqentry_out[heads[5]] || iqentry_done[heads[5]])))
4974
                                        && (!iqentry_mem[heads[6]] || (iqentry_agen[heads[6]] & iqentry_out[heads[6]]) || iqentry_done[heads[6]]
4975
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[6]][AMSB:3] || iqentry_out[heads[6]] || iqentry_done[heads[6]])))
4976
                                        && (!iqentry_mem[heads[7]] || (iqentry_agen[heads[7]] & iqentry_out[heads[7]]) || iqentry_done[heads[7]]
4977
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[7]][AMSB:3] || iqentry_out[heads[7]] || iqentry_done[heads[7]])))
4978
                                        && (iqentry_rl[heads[8]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
4979
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
4980
                                                                                 && (iqentry_done[heads[2]] || !iqentry_v[heads[2]] || !iqentry_mem[heads[2]])
4981
                                                                                 && (iqentry_done[heads[3]] || !iqentry_v[heads[3]] || !iqentry_mem[heads[3]])
4982
                                                                                 && (iqentry_done[heads[4]] || !iqentry_v[heads[4]] || !iqentry_mem[heads[4]])
4983
                                                                                 && (iqentry_done[heads[5]] || !iqentry_v[heads[5]] || !iqentry_mem[heads[5]])
4984
                                                                                 && (iqentry_done[heads[6]] || !iqentry_v[heads[6]] || !iqentry_mem[heads[6]])
4985
                                                                                 && (iqentry_done[heads[7]] || !iqentry_v[heads[7]] || !iqentry_mem[heads[7]])
4986
                                                                                         : 1'b1)
4987
                                        // ... if a preivous op has the aquire bit set
4988
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
4989
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
4990
                                        && !(iqentry_aq[heads[2]] && iqentry_v[heads[2]])
4991
                                        && !(iqentry_aq[heads[3]] && iqentry_v[heads[3]])
4992
                                        && !(iqentry_aq[heads[4]] && iqentry_v[heads[4]])
4993
                                        && !(iqentry_aq[heads[5]] && iqentry_v[heads[5]])
4994
                                        && !(iqentry_aq[heads[6]] && iqentry_v[heads[6]])
4995
                                        && !(iqentry_aq[heads[7]] && iqentry_v[heads[7]])
4996
                                        // ... and there's nothing in the write buffer during a load
4997
                                        && !(iqentry_load[heads[8]] && (wb_v!=1'b0
4998
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]] || iqentry_store[heads[2]] || iqentry_store[heads[3]]
4999
                                                || iqentry_store[heads[4]] || iqentry_store[heads[5]] || iqentry_store[heads[6]] || iqentry_store[heads[7]]))
5000
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5001
                    && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
5002
                    && (!(iqentry_iv[heads[2]] && iqentry_memsb[heads[2]]) ||
5003
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5004
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
5005
                                )
5006
                    && (!(iqentry_iv[heads[3]] && iqentry_memsb[heads[3]]) ||
5007
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5008
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5009
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
5010
                                )
5011
                    && (!(iqentry_iv[heads[4]] && iqentry_memsb[heads[4]]) ||
5012
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5013
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5014
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5015
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
5016
                                )
5017
                    && (!(iqentry_iv[heads[5]] && iqentry_memsb[heads[5]]) ||
5018
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5019
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5020
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5021
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5022
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
5023
                                )
5024
                    && (!(iqentry_iv[heads[6]] && iqentry_memsb[heads[6]]) ||
5025
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5026
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5027
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5028
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5029
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5030
                                &&   (iqentry_done[heads[5]] || !iqentry_v[heads[5]]))
5031
                                )
5032
                    && (!(iqentry_iv[heads[7]] && iqentry_memsb[heads[7]]) ||
5033
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5034
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5035
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5036
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5037
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5038
                                &&   (iqentry_done[heads[5]] || !iqentry_v[heads[5]])
5039
                                &&   (iqentry_done[heads[6]] || !iqentry_v[heads[6]])
5040
                                )
5041
                                )
5042
                                && (!(iqentry_iv[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
5043
                    && (!(iqentry_iv[heads[2]] && iqentry_memdb[heads[2]]) ||
5044
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5045
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
5046
                                )
5047
                    && (!(iqentry_iv[heads[3]] && iqentry_memdb[heads[3]]) ||
5048
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5049
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5050
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
5051
                                )
5052
                    && (!(iqentry_iv[heads[4]] && iqentry_memdb[heads[4]]) ||
5053
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5054
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5055
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5056
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
5057
                                )
5058
                    && (!(iqentry_iv[heads[5]] && iqentry_memdb[heads[5]]) ||
5059
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5060
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5061
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5062
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5063
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
5064
                                )
5065
                    && (!(iqentry_iv[heads[6]] && iqentry_memdb[heads[6]]) ||
5066
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5067
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5068
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5069
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5070
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5071
                                && (!iqentry_mem[heads[5]] || iqentry_done[heads[5]] || !iqentry_v[heads[5]]))
5072
                                )
5073
                    && (!(iqentry_iv[heads[7]] && iqentry_memdb[heads[7]]) ||
5074
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5075
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5076
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5077
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5078
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5079
                                && (!iqentry_mem[heads[5]] || iqentry_done[heads[5]] || !iqentry_v[heads[5]])
5080
                                && (!iqentry_mem[heads[6]] || iqentry_done[heads[6]] || !iqentry_v[heads[6]])
5081
                                )
5082
                                )
5083
                                        // ... and, if it is a SW, there is no chance of it being undone
5084
                                        && ((iqentry_load[heads[8]] && sple) ||
5085
                                      !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
5086
                       && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]])
5087
                       && !(iqentry_fc[heads[2]]||iqentry_canex[heads[2]])
5088
                       && !(iqentry_fc[heads[3]]||iqentry_canex[heads[3]])
5089
                       && !(iqentry_fc[heads[4]]||iqentry_canex[heads[4]])
5090
                       && !(iqentry_fc[heads[5]]||iqentry_canex[heads[5]])
5091
                       && !(iqentry_fc[heads[6]]||iqentry_canex[heads[6]])
5092
                       && !(iqentry_fc[heads[7]]||iqentry_canex[heads[7]])
5093
                       );
5094
         if (memissue[heads[8]])
5095
                issue_count = issue_count + 1;
5096
        end
5097
 
5098
        if (QENTRIES > 9) begin
5099
        memissue[ heads[9] ] =  ~iqentry_stomp[heads[9]] && iqentry_memready[ heads[9] ]                // addr and data are valid
5100
                                        // ... and no preceding instruction is ready to go
5101
                                        && issue_count < `NUM_MEM
5102
                                        //&& ~iqentry_memready[heads[0]]
5103
                                        //&& ~iqentry_memready[heads[1]] 
5104
                                        //&& ~iqentry_memready[heads[2]] 
5105
                                        //&& ~iqentry_memready[heads[3]] 
5106
                                        //&& ~iqentry_memready[heads[4]] 
5107
                                        //&& ~iqentry_memready[heads[5]] 
5108
                                        //&& ~iqentry_memready[heads[6]] 
5109
                                        // ... and there is no address-overlap with any preceding instruction
5110
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]]) || iqentry_done[heads[0]]
5111
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
5112
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]]) || iqentry_done[heads[1]]
5113
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3] || iqentry_out[heads[1]] || iqentry_done[heads[1]])))
5114
                                        && (!iqentry_mem[heads[2]] || (iqentry_agen[heads[2]] & iqentry_out[heads[2]]) || iqentry_done[heads[2]]
5115
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[2]][AMSB:3] || iqentry_out[heads[2]] || iqentry_done[heads[2]])))
5116
                                        && (!iqentry_mem[heads[3]] || (iqentry_agen[heads[3]] & iqentry_out[heads[3]]) || iqentry_done[heads[3]]
5117
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[3]][AMSB:3] || iqentry_out[heads[3]] || iqentry_done[heads[3]])))
5118
                                        && (!iqentry_mem[heads[4]] || (iqentry_agen[heads[4]] & iqentry_out[heads[4]]) || iqentry_done[heads[4]]
5119
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[4]][AMSB:3] || iqentry_out[heads[4]] || iqentry_done[heads[4]])))
5120
                                        && (!iqentry_mem[heads[5]] || (iqentry_agen[heads[5]] & iqentry_out[heads[5]]) || iqentry_done[heads[5]]
5121
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[5]][AMSB:3] || iqentry_out[heads[5]] || iqentry_done[heads[5]])))
5122
                                        && (!iqentry_mem[heads[6]] || (iqentry_agen[heads[6]] & iqentry_out[heads[6]]) || iqentry_done[heads[6]]
5123
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[6]][AMSB:3] || iqentry_out[heads[6]] || iqentry_done[heads[6]])))
5124
                                        && (!iqentry_mem[heads[7]] || (iqentry_agen[heads[7]] & iqentry_out[heads[7]]) || iqentry_done[heads[7]]
5125
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[7]][AMSB:3] || iqentry_out[heads[7]] || iqentry_done[heads[7]])))
5126
                                        && (!iqentry_mem[heads[8]] || (iqentry_agen[heads[8]] & iqentry_out[heads[8]]) || iqentry_done[heads[8]]
5127
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[8]][AMSB:3] || iqentry_out[heads[8]] || iqentry_done[heads[8]])))
5128
                                        && (iqentry_rl[heads[9]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
5129
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
5130
                                                                                 && (iqentry_done[heads[2]] || !iqentry_v[heads[2]] || !iqentry_mem[heads[2]])
5131
                                                                                 && (iqentry_done[heads[3]] || !iqentry_v[heads[3]] || !iqentry_mem[heads[3]])
5132
                                                                                 && (iqentry_done[heads[4]] || !iqentry_v[heads[4]] || !iqentry_mem[heads[4]])
5133
                                                                                 && (iqentry_done[heads[5]] || !iqentry_v[heads[5]] || !iqentry_mem[heads[5]])
5134
                                                                                 && (iqentry_done[heads[6]] || !iqentry_v[heads[6]] || !iqentry_mem[heads[6]])
5135
                                                                                 && (iqentry_done[heads[7]] || !iqentry_v[heads[7]] || !iqentry_mem[heads[7]])
5136
                                                                                 && (iqentry_done[heads[8]] || !iqentry_v[heads[8]] || !iqentry_mem[heads[8]])
5137
                                                                                         : 1'b1)
5138
                                        // ... if a preivous op has the aquire bit set
5139
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
5140
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
5141
                                        && !(iqentry_aq[heads[2]] && iqentry_v[heads[2]])
5142
                                        && !(iqentry_aq[heads[3]] && iqentry_v[heads[3]])
5143
                                        && !(iqentry_aq[heads[4]] && iqentry_v[heads[4]])
5144
                                        && !(iqentry_aq[heads[5]] && iqentry_v[heads[5]])
5145
                                        && !(iqentry_aq[heads[6]] && iqentry_v[heads[6]])
5146
                                        && !(iqentry_aq[heads[7]] && iqentry_v[heads[7]])
5147
                                        && !(iqentry_aq[heads[8]] && iqentry_v[heads[8]])
5148
                                        // ... and there's nothing in the write buffer during a load
5149
                                        && !(iqentry_load[heads[9]] && (wb_v!=1'b0
5150
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]] || iqentry_store[heads[2]] || iqentry_store[heads[3]]
5151
                                                || iqentry_store[heads[4]] || iqentry_store[heads[5]] || iqentry_store[heads[6]] || iqentry_store[heads[7]]
5152
                                                || iqentry_store[heads[8]]))
5153
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5154
                    && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
5155
                    && (!(iqentry_iv[heads[2]] && iqentry_memsb[heads[2]]) ||
5156
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5157
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
5158
                                )
5159
                    && (!(iqentry_iv[heads[3]] && iqentry_memsb[heads[3]]) ||
5160
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5161
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5162
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
5163
                                )
5164
                    && (!(iqentry_iv[heads[4]] && iqentry_memsb[heads[4]]) ||
5165
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5166
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5167
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5168
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
5169
                                )
5170
                    && (!(iqentry_iv[heads[5]] && iqentry_memsb[heads[5]]) ||
5171
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5172
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5173
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5174
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5175
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
5176
                                )
5177
                    && (!(iqentry_iv[heads[6]] && iqentry_memsb[heads[6]]) ||
5178
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5179
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5180
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5181
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5182
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5183
                                &&   (iqentry_done[heads[5]] || !iqentry_v[heads[5]]))
5184
                                )
5185
                    && (!(iqentry_iv[heads[7]] && iqentry_memsb[heads[7]]) ||
5186
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5187
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5188
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5189
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5190
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5191
                                &&   (iqentry_done[heads[5]] || !iqentry_v[heads[5]])
5192
                                &&   (iqentry_done[heads[6]] || !iqentry_v[heads[6]]))
5193
                                )
5194
                    && (!(iqentry_iv[heads[8]] && iqentry_memsb[heads[8]]) ||
5195
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5196
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5197
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5198
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5199
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5200
                                &&   (iqentry_done[heads[5]] || !iqentry_v[heads[5]])
5201
                                &&   (iqentry_done[heads[6]] || !iqentry_v[heads[6]])
5202
                                &&   (iqentry_done[heads[7]] || !iqentry_v[heads[7]])
5203
                                )
5204
                                )
5205
                                && (!(iqentry_iv[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
5206
                    && (!(iqentry_iv[heads[2]] && iqentry_memdb[heads[2]]) ||
5207
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5208
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
5209
                                )
5210
                    && (!(iqentry_iv[heads[3]] && iqentry_memdb[heads[3]]) ||
5211
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5212
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5213
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
5214
                                )
5215
                    && (!(iqentry_iv[heads[4]] && iqentry_memdb[heads[4]]) ||
5216
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5217
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5218
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5219
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
5220
                                )
5221
                    && (!(iqentry_iv[heads[5]] && iqentry_memdb[heads[5]]) ||
5222
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5223
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5224
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5225
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5226
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
5227
                                )
5228
                    && (!(iqentry_iv[heads[6]] && iqentry_memdb[heads[6]]) ||
5229
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5230
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5231
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5232
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5233
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5234
                                && (!iqentry_mem[heads[5]] || iqentry_done[heads[5]] || !iqentry_v[heads[5]]))
5235
                                )
5236
                    && (!(iqentry_iv[heads[7]] && iqentry_memdb[heads[7]]) ||
5237
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5238
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5239
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5240
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5241
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5242
                                && (!iqentry_mem[heads[5]] || iqentry_done[heads[5]] || !iqentry_v[heads[5]])
5243
                                && (!iqentry_mem[heads[6]] || iqentry_done[heads[6]] || !iqentry_v[heads[6]]))
5244
                                )
5245
                    && (!(iqentry_iv[heads[8]] && iqentry_memdb[heads[8]]) ||
5246
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5247
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5248
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5249
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5250
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5251
                                && (!iqentry_mem[heads[5]] || iqentry_done[heads[5]] || !iqentry_v[heads[5]])
5252
                                && (!iqentry_mem[heads[6]] || iqentry_done[heads[6]] || !iqentry_v[heads[6]])
5253
                                && (!iqentry_mem[heads[7]] || iqentry_done[heads[7]] || !iqentry_v[heads[7]])
5254
                                )
5255
                                )
5256
                                        // ... and, if it is a store, there is no chance of it being undone
5257
                                        && ((iqentry_load[heads[9]] && sple) ||
5258
                                      !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
5259
                       && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]])
5260
                       && !(iqentry_fc[heads[2]]||iqentry_canex[heads[2]])
5261
                       && !(iqentry_fc[heads[3]]||iqentry_canex[heads[3]])
5262
                       && !(iqentry_fc[heads[4]]||iqentry_canex[heads[4]])
5263
                       && !(iqentry_fc[heads[5]]||iqentry_canex[heads[5]])
5264
                       && !(iqentry_fc[heads[6]]||iqentry_canex[heads[6]])
5265
                       && !(iqentry_fc[heads[7]]||iqentry_canex[heads[7]])
5266
                       && !(iqentry_fc[heads[8]]||iqentry_canex[heads[8]])
5267
                       );
5268
         if (memissue[heads[9]])
5269
                issue_count = issue_count + 1;
5270
        end
5271
end
5272
end
5273
endgenerate
5274
`endif
5275
 
5276
// Starts search for instructions to issue at the head of the queue and 
5277
// progresses from there. This ensures that the oldest instructions are
5278
// selected first for processing.
5279
always @*
5280
begin
5281
        last_issue0 = QENTRIES;
5282
        last_issue1 = QENTRIES;
5283
        last_issue2 = QENTRIES;
5284
        for (n = 0; n < QENTRIES; n = n + 1)
5285 61 robfinch
    if (~iqentry_stomp[heads[n]] && iqentry_memissue[heads[n]] && !iqentry_done[heads[n]] && iqentry_v[heads[n]]) begin
5286 60 robfinch
      if (mem1_available && dram0 == `DRAMSLOT_AVAIL) begin
5287
       last_issue0 = heads[n];
5288
      end
5289
    end
5290
        for (n = 0; n < QENTRIES; n = n + 1)
5291
    if (~iqentry_stomp[heads[n]] && iqentry_memissue[heads[n]]) begin
5292
        if (mem2_available && heads[n] != last_issue0 && `NUM_MEM > 1) begin
5293
        if (dram1 == `DRAMSLOT_AVAIL) begin
5294
                                        last_issue1 = heads[n];
5295
        end
5296
        end
5297
    end
5298
        for (n = 0; n < QENTRIES; n = n + 1)
5299
    if (~iqentry_stomp[heads[n]] && iqentry_memissue[heads[n]]) begin
5300
        if (mem3_available && heads[n] != last_issue0 && heads[n] != last_issue1 && `NUM_MEM > 2) begin
5301
        if (dram2 == `DRAMSLOT_AVAIL) begin
5302
                last_issue2 = heads[n];
5303
        end
5304
        end
5305
    end
5306
end
5307
 
5308
reg [2:0] wbptr;
5309
// Stomp logic for branch miss.
5310
/*
5311
FT64_stomp #(QENTRIES) ustmp1
5312
(
5313
        .branchmiss(branchmiss),
5314
        .branchmiss_thrd(branchmiss_thrd),
5315
        .missid(missid),
5316
        .head0(heads[0]),
5317
        .thrd(iqentry_thrd),
5318
        .iqentry_v(iqentry_v),
5319
        .stomp(iqentry_stomp)
5320
);
5321
*/
5322
always @*
5323
begin
5324
        iqentry_stomp <= 1'b0;
5325
        if (branchmiss) begin
5326
                for (n = 0; n < QENTRIES; n = n + 1) begin
5327
                        if (iqentry_v[n] && iqentry_thrd[n]==branchmiss_thrd) begin
5328
                                if (iqentry_sn[n] > iqentry_sn[missid[`QBITS]])
5329
                                        iqentry_stomp[n] <= `TRUE;
5330
                        end
5331
                end
5332
        end
5333
        /*
5334
        if (fcu_branchmiss) begin
5335
                for (n = 0; n < QENTRIES; n = n + 1) begin
5336
                        if (iqentry_v[n] && iqentry_thrd[n]==fcu_thrd) begin
5337
                                if (iqentry_sn[n] > iqentry_sn[fcu_id[`QBITS]])
5338
                                        iqentry_stomp[n] <= `TRUE;
5339
                        end
5340
                end
5341
        end
5342
        */
5343
end
5344
 
5345
always @*
5346
begin
5347
        stompedOnRets = 1'b0;
5348
        for (n = 0; n < QENTRIES; n = n + 1)
5349
                if (iqentry_stomp[n] && iqentry_ret[n])
5350
                        stompedOnRets = stompedOnRets + 4'd1;
5351
end
5352
 
5353
reg id1_vi, id2_vi, id3_vi;
5354
wire [4:0] id1_ido, id2_ido, id3_ido;
5355
wire id1_vo, id2_vo, id3_vo;
5356
wire id1_clk, id2_clk, id3_clk;
5357
 
5358
// Always at least one decoder
5359
assign id1_clk = clk_i;
5360
//BUFGCE uclkb2
5361
//(
5362
//      .I(clk_i),
5363
//      .CE(id1_available),
5364
//      .O(id1_clk)
5365
//);
5366
 
5367
FT64_idecoder uid1
5368
(
5369
        .clk(id1_clk),
5370
        .idv_i(id1_vi),
5371
        .id_i(id1_id),
5372
`ifdef INLINE_DECODE
5373
        .instr(fetchbuf0_instr),
5374
        .Rt(Rt0[4:0]),
5375
        .predict_taken(predict_taken0),
5376
        .thrd(fetchbuf0_thrd),
5377
        .vl(vl),
5378
`else
5379
        .instr(id1_instr),
5380
        .Rt(id1_Rt),
5381
        .predict_taken(id1_pt),
5382
        .thrd(id1_thrd),
5383
        .vl(id1_vl),
5384
`endif
5385
//ToDo: fix for vectors length and element number
5386
        .ven(id1_ven),
5387
        .bus(id1_bus),
5388
        .id_o(id1_ido),
5389
        .idv_o(id1_vo),
5390
        .debug_on(debug_on),
5391
        .pred_on(pred_on)
5392
);
5393
/*
5394
`ifdef INLINE_DECODE
5395
        id1_Rt <= Rt0[4:0];
5396
        id1_vl <= vl;
5397
        id1_ven <= venno;
5398
        id1_id <= tail;
5399
        id1_pt <= predict_taken0;
5400
        id1_thrd <= fetchbuf0_thrd;
5401
        setinsn1(tail,id1_bus);
5402
`endif
5403
*/
5404
generate begin : gIDUInst
5405
if (`NUM_IDU > 1) begin
5406
//BUFGCE uclkb3
5407
//(
5408
//      .I(clk_i),
5409
//      .CE(id2_available),
5410
//      .O(id2_clk)
5411
//);
5412
assign id2_clk = clk_i;
5413
 
5414
FT64_idecoder uid2
5415
(
5416
        .clk(id2_clk),
5417
        .idv_i(id2_vi),
5418
        .id_i(id2_id),
5419
`ifdef INLINE_DECODE
5420
        .instr(fetchbuf1_instr),
5421
        .Rt(Rt1[4:0]),
5422
        .predict_taken(predict_taken1),
5423
        .thrd(fetchbuf1_thrd),
5424
        .vl(vl),
5425
`else
5426
        .instr(id2_instr),
5427
        .Rt(id2_Rt),
5428
        .predict_taken(id2_pt),
5429
        .thrd(id2_thrd),
5430
        .vl(id2_vl),
5431
`endif
5432
        .ven(id2_ven),
5433
        .bus(id2_bus),
5434
        .id_o(id2_ido),
5435
        .idv_o(id2_vo),
5436
        .debug_on(debug_on),
5437
        .pred_on(pred_on)
5438
);
5439
end
5440
if (`NUM_IDU > 2) begin
5441
//BUFGCE uclkb4
5442
//(
5443
//      .I(clk_i),
5444
//      .CE(id3_available),
5445
//      .O(id3_clk)
5446
//);
5447
assign id3_clk = clk_i;
5448
 
5449
FT64_idecoder uid2
5450
(
5451
        .clk(id3_clk),
5452
        .idv_i(id3_vi),
5453
        .id_i(id3_id),
5454
`ifdef INLINE_DECODE
5455
        .instr(fetchbuf2_instr),
5456
        .Rt(Rt2[4:0]),
5457
        .predict_taken(predict_taken2),
5458
        .thrd(fetchbuf2_thrd),
5459
        .vl(vl),
5460
`else
5461
        .instr(id3_instr),
5462
        .Rt(id3_Rt),
5463
        .predict_taken(id3_pt),
5464
        .thrd(id3_thrd),
5465
        .vl(id3_vl),
5466
`endif
5467
        .ven(id3_ven),
5468
        .bus(id3_bus),
5469
        .id_o(id3_ido),
5470
        .idv_o(id3_vo),
5471
        .debug_on(debug_on),
5472
        .pred_on(pred_on)
5473
);
5474
end
5475
end
5476
endgenerate
5477
 
5478
//
5479
// EXECUTE
5480
//
5481
wire [15:0] lfsro;
5482
lfsr #(16,16'hACE4) u1 (rst, clk, 1'b1, 1'b0, lfsro);
5483
 
5484
reg [63:0] csr_r;
5485
wire [11:0] csrno = alu0_instr[29:18];
5486
always @*
5487
begin
5488
`ifdef SUPPORT_SMT
5489
    if (csrno[11:10] >= ol[alu0_thrd])
5490
`else
5491
    if (csrno[11:10] >= ol)
5492
`endif
5493
    casez(csrno[9:0])
5494
    `CSR_CR0:       csr_r <= cr0;
5495
    `CSR_HARTID:    csr_r <= hartid;
5496
    `CSR_TICK:      csr_r <= tick;
5497
    `CSR_PCR:       csr_r <= pcr;
5498
    `CSR_PCR2:      csr_r <= pcr2;
5499
    `CSR_PMR:                           csr_r <= pmr;
5500
    `CSR_WBRCD:         csr_r <= wbrcd;
5501
    `CSR_SEMA:      csr_r <= sema;
5502
    `CSR_KEYS:                  csr_r <= keys;
5503
    `CSR_TCB:           csr_r <= tcb;
5504
    `CSR_FSTAT:     csr_r <= {fp_rgs,fp_status};
5505
`ifdef SUPPORT_DBG
5506
    `CSR_DBAD0:     csr_r <= dbg_adr0;
5507
    `CSR_DBAD1:     csr_r <= dbg_adr1;
5508
    `CSR_DBAD2:     csr_r <= dbg_adr2;
5509
    `CSR_DBAD3:     csr_r <= dbg_adr3;
5510
    `CSR_DBCTRL:    csr_r <= dbg_ctrl;
5511
    `CSR_DBSTAT:    csr_r <= dbg_stat;
5512
`endif
5513
    `CSR_CAS:       csr_r <= cas;
5514
    `CSR_TVEC:      csr_r <= tvec[csrno[2:0]];
5515
    `CSR_BADADR:    csr_r <= badaddr[{alu0_thrd,csrno[11:10]}];
5516
    `CSR_BADINSTR:      csr_r <= bad_instr[{alu0_thrd,csrno[11:10]}];
5517
    `CSR_CAUSE:     csr_r <= {48'd0,cause[{alu0_thrd,csrno[11:10]}]};
5518
`ifdef SUPPORT_SMT
5519
    `CSR_IM_STACK:      csr_r <= im_stack[alu0_thrd];
5520
    `CSR_OL_STACK:      csr_r <= {dl_stack[alu0_thrd],ol_stack[alu0_thrd]};
5521
    `CSR_PL_STACK:      csr_r <= pl_stack[alu0_thrd];
5522
    `CSR_RS_STACK:      csr_r <= rs_stack[alu0_thrd];
5523
    `CSR_STATUS:    csr_r <= mstatus[alu0_thrd][63:0];
5524
    `CSR_BRS_STACK:     csr_r <= brs_stack[alu0_thrd];
5525
    `CSR_EPC0:      csr_r <= epc0[alu0_thrd];
5526
    `CSR_EPC1:      csr_r <= epc1[alu0_thrd];
5527
    `CSR_EPC2:      csr_r <= epc2[alu0_thrd];
5528
    `CSR_EPC3:      csr_r <= epc3[alu0_thrd];
5529
    `CSR_EPC4:      csr_r <= epc4[alu0_thrd];
5530
    `CSR_EPC5:      csr_r <= epc5[alu0_thrd];
5531
    `CSR_EPC6:      csr_r <= epc6[alu0_thrd];
5532
    `CSR_EPC7:      csr_r <= epc7[alu0_thrd];
5533
`else
5534
    `CSR_IM_STACK:      csr_r <= im_stack;
5535
    `CSR_OL_STACK:      csr_r <= {dl_stack,ol_stack};
5536
    `CSR_PL_STACK:      csr_r <= pl_stack;
5537
    `CSR_RS_STACK:      csr_r <= rs_stack;
5538
    `CSR_STATUS:    csr_r <= mstatus[63:0];
5539
    `CSR_BRS_STACK:     csr_r <= brs_stack;
5540
    `CSR_EPC0:      csr_r <= epc0;
5541
    `CSR_EPC1:      csr_r <= epc1;
5542
    `CSR_EPC2:      csr_r <= epc2;
5543
    `CSR_EPC3:      csr_r <= epc3;
5544
    `CSR_EPC4:      csr_r <= epc4;
5545
    `CSR_EPC5:      csr_r <= epc5;
5546
    `CSR_EPC6:      csr_r <= epc6;
5547
    `CSR_EPC7:      csr_r <= epc7;
5548
`endif
5549
    `CSR_CODEBUF:   csr_r <= codebuf[csrno[5:0]];
5550
`ifdef SUPPORT_BBMS
5551
                `CSR_TB:                        csr_r <= tb;
5552
                `CSR_CBL:                       csr_r <= cbl;
5553
                `CSR_CBU:                       csr_r <= cbu;
5554
                `CSR_RO:                        csr_r <= ro;
5555
                `CSR_DBL:                       csr_r <= dbl;
5556
                `CSR_DBU:                       csr_r <= dbu;
5557
                `CSR_SBL:                       csr_r <= sbl;
5558
                `CSR_SBU:                       csr_r <= sbu;
5559
                `CSR_ENU:                       csr_r <= en;
5560
`endif
5561
    `CSR_Q_CTR:         csr_r <= iq_ctr;
5562
    `CSR_BM_CTR:        csr_r <= bm_ctr;
5563
    `CSR_ICL_CTR:       csr_r <= icl_ctr;
5564
    `CSR_IRQ_CTR:       csr_r <= irq_ctr;
5565
    `CSR_TIME:          csr_r <= wc_times;
5566
    `CSR_INFO:
5567
                    case(csrno[3:0])
5568
                    4'd0:   csr_r <= "Finitron";  // manufacturer
5569
                    4'd1:   csr_r <= "        ";
5570
                    4'd2:   csr_r <= "64 bit  ";  // CPU class
5571
                    4'd3:   csr_r <= "        ";
5572
                    4'd4:   csr_r <= "FT64    ";  // Name
5573
                    4'd5:   csr_r <= "        ";
5574
                    4'd6:   csr_r <= 64'd1;       // model #
5575
                    4'd7:   csr_r <= 64'd1;       // serial number
5576
                    4'd8:   csr_r <= {32'd16384,32'd16384};   // cache sizes instruction,csr_ra
5577
                    4'd9:   csr_r <= 64'd0;
5578
                    default:    csr_r <= 64'd0;
5579
                    endcase
5580
    default:    begin
5581
                        $display("Unsupported CSR:%h",csrno[10:0]);
5582
                        csr_r <= 64'hEEEEEEEEEEEEEEEE;
5583
                        end
5584
    endcase
5585
    else
5586
        csr_r <= 64'h0;
5587
end
5588
 
5589
reg [63:0] alu0_xu = 1'd0, alu1_xu = 1'd0;
5590
 
5591
`ifdef SUPPORT_BBMS
5592
 
5593
`else
5594
// This always block didn't work, it left the signals as X's.
5595
// So they are set to zero where the reg declaration is.
5596
// I'm guessing the @* says there's no variables on the right
5597
// hand side, so I'm not going to evaluate it.
5598
always @*
5599
        alu0_xs <= 64'd0;
5600
always @*
5601
        alu1_xs <= 64'd0;
5602
`endif
5603
 
5604
//always @*
5605
//    read_csr(alu0_instr[29:18],csr_r,alu0_thrd);
5606
FT64_alu #(.BIG(1'b1),.SUP_VECTOR(SUP_VECTOR)) ualu0 (
5607
  .rst(rst),
5608
  .clk(clk),
5609
  .ld(alu0_ld),
5610
  .abort(alu0_abort),
5611
  .instr(alu0_instr),
5612
  .sz(alu0_sz),
5613
  .tlb(alu0_tlb),
5614
  .store(alu0_store),
5615
  .a(alu0_argA),
5616
  .b(alu0_argB),
5617
  .c(alu0_argC),
5618
  .pc(alu0_pc),
5619
//    .imm(alu0_argI),
5620
  .tgt(alu0_tgt),
5621
  .ven(alu0_ven),
5622
  .vm(vm[alu0_instr[25:23]]),
5623
  .csr(csr_r),
5624
  .o(alu0_out),
5625
  .ob(alu0b_bus),
5626
  .done(alu0_done),
5627
  .idle(alu0_idle),
5628
  .excen(aec[4:0]),
5629
  .exc(alu0_exc),
5630
  .thrd(alu0_thrd),
5631
  .mem(alu0_mem),
5632
  .shift(alu0_shft),    // 48 bit shift inst.
5633
  .ol(ol),
5634
  .ASID(ASID),
5635
  .icl_i(icl_o),
5636
  .cyc_i(cyc),
5637
  .we_i(we),
5638
  .vadr_i(vadr),
5639
  .cyc_o(cyc_o),
5640
  .we_o(we_o),
5641
  .padr_o(adr_o),
5642
  .uncached(),
5643
  .tlb_miss(tlb_miss),
5644
  .exv_o(exv_i),
5645
  .wrv_o(wrv_i),
5646
  .rdv_o(rdv_i)
5647
`ifdef SUPPORT_BBMS
5648
  .pb(dl==2'b00 ? 64'd0 : pb),
5649
  .cbl(cbl),
5650
  .cbu(cbu),
5651
  .ro(ro),
5652
  .dbl(dbl),
5653
  .dbu(dbu),
5654
  .sbl(sbl),
5655
  .sbu(sbu),
5656
  .en(en)
5657
`endif
5658
);
5659
generate begin : gAluInst
5660
if (`NUM_ALU > 1) begin
5661
FT64_alu #(.BIG(1'b0),.SUP_VECTOR(SUP_VECTOR)) ualu1 (
5662
  .rst(rst),
5663
  .clk(clk),
5664
  .ld(alu1_ld),
5665
  .abort(alu1_abort),
5666
  .instr(alu1_instr),
5667
  .sz(alu1_sz),
5668
  .tlb(1'b0),
5669
  .store(alu1_store),
5670
  .a(alu1_argA),
5671
  .b(alu1_argB),
5672
  .c(alu1_argC),
5673
  .pc(alu1_pc),
5674
  //.imm(alu1_argI),
5675
  .tgt(alu1_tgt),
5676
  .ven(alu1_ven),
5677
  .vm(vm[alu1_instr[25:23]]),
5678
  .csr(64'd0),
5679
  .o(alu1_out),
5680
  .ob(alu1b_bus),
5681
  .done(alu1_done),
5682
  .idle(alu1_idle),
5683
  .excen(aec[4:0]),
5684
  .exc(alu1_exc),
5685
  .thrd(1'b0),
5686
  .mem(alu1_mem),
5687
  .shift(alu1_shft),
5688
  .ol(2'b0),
5689
  .ASID(8'h0),
5690
  .cyc_i(1'b0),
5691
  .we_i(1'b0),
5692
  .vadr_i(64'd0),
5693
  .cyc_o(),
5694
  .we_o(),
5695
  .padr_o(),
5696
  .uncached(),
5697
  .tlb_miss(),
5698
  .exv_o(),
5699
  .wrv_o(),
5700
  .rdv_o()
5701
`ifdef SUPPORT_BBMS
5702
  .pb(dl==2'b00 ? 64'd0 : pb),
5703
  .cbl(cbl),
5704
  .cbu(cbu),
5705
  .ro(ro),
5706
  .dbl(dbl),
5707
  .dbu(dbu),
5708
  .sbl(sbl),
5709
  .sbu(sbu),
5710
  .en(en)
5711
`endif
5712
);
5713
end
5714
end
5715
endgenerate
5716
 
5717
always @*
5718
begin
5719
    alu0_cmt <= 1'b1;
5720
    alu1_cmt <= 1'b1;
5721
    fpu1_cmt <= 1'b1;
5722
    fpu2_cmt <= 1'b1;
5723
    fcu_cmt <= 1'b1;
5724
 
5725
    alu0_bus <= alu0_out;
5726
    alu1_bus <= alu1_out;
5727
    fpu1_bus <= fpu1_out;
5728
    fpu2_bus <= fpu2_out;
5729
    fcu_bus <= fcu_out;
5730
end
5731
 
5732
assign alu0_abort = 1'b0;
5733
assign alu1_abort = 1'b0;
5734
 
5735
generate begin : gFPUInst
5736
if (`NUM_FPU > 0) begin
5737
wire fpu1_clk;
5738
//BUFGCE ufpc1
5739
//(
5740
//      .I(clk_i),
5741
//      .CE(fpu1_available),
5742
//      .O(fpu1_clk)
5743
//);
5744
assign fpu1_clk = clk_i;
5745
 
5746
fpUnit ufp1
5747
(
5748
  .rst(rst),
5749
  .clk(fpu1_clk),
5750
  .clk4x(clk4x),
5751
  .ce(1'b1),
5752
  .ir(fpu1_instr),
5753
  .ld(fpu1_ld),
5754
  .a(fpu1_argA),
5755
  .b(fpu1_argB),
5756
  .imm(fpu1_argI),
5757
  .o(fpu1_out),
5758
  .csr_i(),
5759
  .status(fpu1_status),
5760
  .exception(),
5761
  .done(fpu1_done)
5762
);
5763
end
5764
if (`NUM_FPU > 1) begin
5765
wire fpu2_clk;
5766
//BUFGCE ufpc2
5767
//(
5768
//      .I(clk_i),
5769
//      .CE(fpu2_available),
5770
//      .O(fpu2_clk)
5771
//);
5772
assign fpu2_clk = clk_i;
5773
fpUnit ufp1
5774
(
5775
  .rst(rst),
5776
  .clk(fpu2_clk),
5777
  .clk4x(clk4x),
5778
  .ce(1'b1),
5779
  .ir(fpu2_instr),
5780
  .ld(fpu2_ld),
5781
  .a(fpu2_argA),
5782
  .b(fpu2_argB),
5783
  .imm(fpu2_argI),
5784
  .o(fpu2_out),
5785
  .csr_i(),
5786
  .status(fpu2_status),
5787
  .exception(),
5788
  .done(fpu2_done)
5789
);
5790
end
5791
end
5792
endgenerate
5793
 
5794
assign fpu1_exc = (fpu1_available) ?
5795
                                                                        ((|fpu1_status[15:0]) ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
5796
assign fpu2_exc = (fpu2_available) ?
5797
                                                                        ((|fpu2_status[15:0]) ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
5798
 
5799
assign  alu0_v = alu0_dataready,
5800
        alu1_v = alu1_dataready;
5801
assign  alu0_id = alu0_sourceid,
5802
            alu1_id = alu1_sourceid;
5803
assign  fpu1_v = fpu1_dataready;
5804
assign  fpu1_id = fpu1_sourceid;
5805
assign  fpu2_v = fpu2_dataready;
5806
assign  fpu2_id = fpu2_sourceid;
5807
 
5808
`ifdef SUPPORT_SMT
5809
wire [1:0] olm = ol[fcu_thrd];
5810
`else
5811
wire [1:0] olm = ol;
5812
`endif
5813
 
5814
reg [`SNBITS] maxsn [0:`WAYS-1];
5815
always @*
5816
begin
5817
        for (j = 0; j < `WAYS; j = j + 1) begin
5818
                maxsn[j] = 8'd0;
5819
                for (n = 0; n < QENTRIES; n = n + 1)
5820
                        if (iqentry_sn[n] > maxsn[j] && iqentry_thrd[n]==j && iqentry_v[n])
5821
                                maxsn[j] = iqentry_sn[n];
5822
                maxsn[j] = maxsn[j] - tosub;
5823
        end
5824
end
5825
 
5826
assign  fcu_v = fcu_dataready;
5827
assign  fcu_id = fcu_sourceid;
5828
 
5829
wire [4:0] fcmpo;
5830
wire fnanx;
5831
fp_cmp_unit #(64) ufcmp1 (fcu_argA, fcu_argB, fcmpo, fnanx);
5832
 
5833
wire fcu_takb;
5834
 
5835
always @*
5836
begin
5837
    fcu_exc <= `FLT_NONE;
5838
    casez(fcu_instr[`INSTRUCTION_OP])
5839
`ifdef SUPPORT_BBMS
5840
    `LFCS:      fcu_exc <= currentCSSelector != fcu_instr[31:8] ? `FLT_CS : `FLT_NONE;
5841
    `RET:               fcu_exc <= fcu_argB[63:40] != currentCSSelector ? `FLT_RET : `FLT_NONE;
5842
`endif
5843
    `CHK:   begin
5844
                if (fcu_instr[21])
5845
                    fcu_exc <= fcu_argA >= fcu_argB && fcu_argA < fcu_argC ? `FLT_NONE : `FLT_CHK;
5846
            end
5847
    `REX:
5848
        case(olm)
5849
        `OL_USER:   fcu_exc <= `FLT_PRIV;
5850
        default:    ;
5851
        endcase
5852 61 robfinch
// Could have long branches exceptioning and unimplmented in the fetch stage.
5853
//   `BBc:      fcu_exc <= fcu_instr[6] ? `FLT_BRN : `FLT_NONE;
5854 60 robfinch
   default: fcu_exc <= `FLT_NONE;
5855
        endcase
5856
end
5857
 
5858
FT64_EvalBranch ube1
5859
(
5860
        .instr(fcu_instr),
5861
        .a(fcu_argA),
5862
        .b(fcu_argB),
5863
        .c(fcu_argC),
5864
        .takb(fcu_takb)
5865
);
5866
 
5867
FT64_FCU_Calc #(.AMSB(AMSB)) ufcuc1
5868
(
5869
        .ol(olm),
5870
        .instr(fcu_instr),
5871
        .tvec(tvec[fcu_instr[14:13]]),
5872
        .a(fcu_argA),
5873
        .pc(fcu_pc),
5874
        .nextpc(fcu_nextpc),
5875
        .im(im),
5876
        .waitctr(waitctr),
5877
        .bus(fcu_out)
5878
);
5879
 
5880
wire will_clear_branchmiss = branchmiss && ((fetchbuf0_v && fetchbuf0_pc==misspc) || (fetchbuf1_v && fetchbuf1_pc==misspc));
5881
 
5882
always @*
5883
begin
5884
case(fcu_instr[`INSTRUCTION_OP])
5885 61 robfinch
`R2:    fcu_misspc = fcu_epc;           // RTI (we don't bother fully decoding this as it's the only R2)
5886 60 robfinch
`RET:   fcu_misspc = fcu_argB;
5887
`REX:   fcu_misspc = fcu_bus;
5888
`BRK:   fcu_misspc = {tvec[0][AMSB:8], 1'b0, olm, 5'h0};
5889
`JAL:   fcu_misspc = fcu_argA + fcu_argI;
5890
//`CHK: fcu_misspc = fcu_nextpc + fcu_argI;     // Handled as an instruction exception
5891
// Default: branch
5892 61 robfinch
default:        fcu_misspc = fcu_pt ? fcu_nextpc : {fcu_pc[AMSB:32],fcu_pc[31:0] + fcu_brdisp[31:0]};
5893 60 robfinch
endcase
5894
fcu_misspc[0] = 1'b0;
5895
end
5896
 
5897
// To avoid false branch mispredicts the branch isn't evaluated until the
5898
// following instruction queues. The address of the next instruction is
5899
// looked at to see if the BTB predicted correctly.
5900
 
5901
wire fcu_brk_miss = fcu_brk || fcu_rti;
5902
`ifdef FCU_ENH
5903
wire fcu_ret_miss = fcu_ret && (fcu_argB != iqentry_pc[nid]);
5904
wire fcu_jal_miss = fcu_jal && (fcu_argA + fcu_argI != iqentry_pc[nid]);
5905
wire fcu_followed = iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]];
5906
`else
5907
wire fcu_ret_miss = fcu_ret;
5908
wire fcu_jal_miss = fcu_jal;
5909
wire fcu_followed = `TRUE;
5910
`endif
5911
always @*
5912
if (fcu_v) begin
5913
        // Break and RTI switch register sets, and so are always treated as a branch miss in order to
5914
        // flush the pipeline. Hardware interrupts also stream break instructions so they need to 
5915
        // flushed from the queue so the interrupt is recognized only once.
5916
        // BRK and RTI are handled as excmiss types which are processed during the commit stage.
5917
        if (fcu_brk_miss)
5918
                fcu_branchmiss = TRUE;
5919
        else if (fcu_branch && (fcu_takb ^ fcu_pt))
5920
    fcu_branchmiss = TRUE;
5921
        else
5922
`ifdef SUPPORT_SMT
5923
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol[fcu_thrd]))
5924
`else
5925
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol))
5926
`endif
5927
                fcu_branchmiss = TRUE;
5928
        else if (fcu_ret_miss)
5929
                fcu_branchmiss = TRUE;
5930
        else if (fcu_jal_miss)
5931
    fcu_branchmiss = TRUE;
5932
        else if (fcu_instr[`INSTRUCTION_OP] == `CHK && ~fcu_takb)
5933
    fcu_branchmiss = TRUE;
5934
        else
5935
    fcu_branchmiss = FALSE;
5936
end
5937
else
5938
        fcu_branchmiss = FALSE;
5939
 
5940
FT64_RMW_alu urmwalu0 (rmw_instr, rmw_argA, rmw_argB, rmw_argC, rmw_res);
5941
 
5942
 
5943
//
5944
// additional DRAM-enqueue logic
5945
 
5946
assign dram_avail = (dram0 == `DRAMSLOT_AVAIL || dram1 == `DRAMSLOT_AVAIL || dram2 == `DRAMSLOT_AVAIL);
5947
 
5948
always @*
5949
for (n = 0; n < QENTRIES; n = n + 1)
5950
        iqentry_memopsvalid[n] <= (iqentry_mem[n] && (iqentry_store[n] ? iqentry_a2_v[n] : 1'b1) && iqentry_state[n]==IQS_AGEN);
5951
 
5952
always @*
5953
for (n = 0; n < QENTRIES; n = n + 1)
5954
        iqentry_memready[n] <= (iqentry_v[n] & iqentry_iv[n] & iqentry_memopsvalid[n] & ~iqentry_memissue[n] & ~iqentry_stomp[n]);
5955
 
5956
assign outstanding_stores = (dram0 && dram0_store) ||
5957
                            (dram1 && dram1_store) ||
5958
                            (dram2 && dram2_store);
5959
 
5960
//
5961
// additional COMMIT logic
5962
//
5963
always @*
5964
begin
5965
    commit0_v <= (iqentry_state[heads[0]] == IQS_CMT && ~|panic);
5966
    commit0_id <= {iqentry_mem[heads[0]], heads[0]};      // if a memory op, it has a DRAM-bus id
5967
    commit0_tgt <= iqentry_tgt[heads[0]];
5968
    commit0_we  <= iqentry_we[heads[0]];
5969
    commit0_bus <= iqentry_res[heads[0]];
5970
    if (`NUM_CMT > 1) begin
5971
            commit1_v <= ({iqentry_v[heads[0]],  iqentry_state[heads[0]] == IQS_CMT} != 2'b10
5972
                       && iqentry_state[heads[1]] == IQS_CMT
5973
                       && ~|panic);
5974
            commit1_id <= {iqentry_mem[heads[1]], heads[1]};
5975
            commit1_tgt <= iqentry_tgt[heads[1]];
5976
            commit1_we  <= iqentry_we[heads[1]];
5977
            commit1_bus <= iqentry_res[heads[1]];
5978
            // Need to set commit1, and commit2 valid bits for the branch predictor.
5979
            if (`NUM_CMT > 2) begin
5980
                end
5981
                else begin
5982
                        commit2_v <= ({iqentry_v[heads[0]], iqentry_state[heads[0]] == IQS_CMT} != 2'b10
5983
                                                                 && {iqentry_v[heads[1]], iqentry_state[heads[1]] == IQS_CMT} != 2'b10
5984
                                                                 && {iqentry_v[heads[2]], iqentry_br[heads[2]], iqentry_state[heads[2]] == IQS_CMT}==3'b111
5985
                               && iqentry_tgt[heads[2]][4:0]==5'd0 && ~|panic);  // watch out for dbnz and ibne
5986
                        commit2_tgt <= 12'h000;
5987
                        commit2_we <= 8'h00;
5988
                end
5989
        end
5990
        else begin
5991
                commit1_v <= ({iqentry_v[heads[0]], iqentry_state[heads[0]] == IQS_CMT} != 2'b10
5992
                                                         && {iqentry_v[heads[1]], iqentry_state[heads[1]] == IQS_CMT} == 2'b11
5993
                       && !iqentry_rfw[heads[1]] && ~|panic);   // watch out for dbnz and ibne
5994
        commit1_id <= {iqentry_mem[heads[1]], heads[1]};        // if a memory op, it has a DRAM-bus id
5995
                commit1_tgt <= 12'h000;
5996
                commit1_we <= 8'h00;
5997
                // We don't really need the bus value since nothing is being written.
5998
            commit1_bus <= iqentry_res[heads[1]];
5999
                commit2_v <= ({iqentry_v[heads[0]], iqentry_state[heads[0]] == IQS_CMT} != 2'b10
6000
                                                         && {iqentry_v[heads[1]], iqentry_state[heads[1]] == IQS_CMT} != 2'b10
6001
                                                         && {iqentry_v[heads[2]], iqentry_br[heads[2]], iqentry_state[heads[2]] == IQS_CMT}==3'b111
6002
                       && !iqentry_rfw[heads[2]] && ~|panic);   // watch out for dbnz and ibne
6003
        commit2_id <= {iqentry_mem[heads[2]], heads[2]};        // if a memory op, it has a DRAM-bus id
6004
                commit2_tgt <= 12'h000;
6005
                commit2_we <= 8'h00;
6006
            commit2_bus <= iqentry_res[heads[2]];
6007
        end
6008
end
6009
 
6010
assign int_commit = (commit0_v && iqentry_irq[heads[0]])
6011
                                                                         || (commit0_v && commit1_v && iqentry_irq[heads[1]] && `NUM_CMT > 1)
6012
                                                                         || (commit0_v && commit1_v && commit2_v && iqentry_irq[heads[2]] && `NUM_CMT > 2);
6013
 
6014
// Detect if a given register will become valid during the current cycle.
6015
// We want a signal that is active during the current clock cycle for the read
6016
// through register file, which trims a cycle off register access for every
6017
// instruction. But two different kinds of assignment statements can't be
6018
// placed under the same always block, it's a bad practice and may not work.
6019
// So a signal is created here with it's own always block.
6020
reg [AREGS-1:0] regIsValid;
6021
always @*
6022
begin
6023
        for (n = 1; n < AREGS; n = n + 1)
6024
        begin
6025
                regIsValid[n] = rf_v[n];
6026
                if (branchmiss)
6027
               if (~livetarget[n]) begin
6028
                        if (branchmiss_thrd) begin
6029
                                if (n >= 128)
6030
                                        regIsValid[n] = `VAL;
6031
                        end
6032
                        else begin
6033
                                if (n < 128)
6034
                                        regIsValid[n] = `VAL;
6035
                        end
6036
               end
6037
                if (commit0_v && n=={commit0_tgt[7:0]})
6038
                        regIsValid[n] = regIsValid[n] | ((rf_source[ {commit0_tgt[7:0]} ] == commit0_id)
6039
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit0_id[`QBITS] ]));
6040
                if (commit1_v && n=={commit1_tgt[7:0]} && `NUM_CMT > 1)
6041
                        regIsValid[n] = regIsValid[n] | ((rf_source[ {commit1_tgt[7:0]} ] == commit1_id)
6042
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit1_id[`QBITS]] && iqentry_source[ commit1_id[`QBITS] ]));
6043
                if (commit2_v && n=={commit2_tgt[7:0]} && `NUM_CMT > 2)
6044
                        regIsValid[n] = regIsValid[n] | ((rf_source[ {commit2_tgt[7:0]} ] == commit2_id)
6045
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit2_id[`QBITS]] && iqentry_source[ commit2_id[`QBITS] ]));
6046
        end
6047
        regIsValid[0] = `VAL;
6048
        regIsValid[32] = `VAL;
6049
        regIsValid[64] = `VAL;
6050
        regIsValid[96] = `VAL;
6051
`ifdef SMT
6052
        regIsValid[128] = `VAL;
6053
        regIsValid[160] = `VAL;
6054
        regIsValid[192] = `VAL;
6055
        regIsValid[224] = `VAL;
6056
`endif
6057
end
6058
 
6059
// Wait until the cycle after Ra becomes valid to give time to read
6060
// the vector element from the register file.
6061
reg rf_vra0, rf_vra1;
6062
/*always @(posedge clk)
6063
    rf_vra0 <= regIsValid[Ra0s];
6064
always @(posedge clk)
6065
    rf_vra1 <= regIsValid[Ra1s];
6066
*/
6067
// Check how many instructions can be queued. This might be fewer than the
6068
// number ready to queue from the fetch stage if queue slots aren't
6069
// available or if there are no more physical registers left for remapping.
6070
// The fetch stage needs to know how many instructions will queue so this
6071
// logic is placed here.
6072
// NOPs are filtered out and do not enter the instruction queue. The core
6073
// will stream NOPs on a cache miss and they would mess up the queue order
6074
// if there are immediate prefixes in the queue.
6075
// For the VEX instruction, the instruction can't queue until register Ra
6076
// is valid, because register Ra is used to specify the vector element to
6077
// read.
6078
wire q2open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV;
6079
wire q3open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV && iqentry_v[(tail1 + 2'd1) % QENTRIES]==`INV;
6080
always @*
6081
begin
6082
        canq1 <= FALSE;
6083
        canq2 <= FALSE;
6084
        queued1 <= FALSE;
6085
        queued2 <= FALSE;
6086
        queuedNop <= FALSE;
6087
        vqueued2 <= FALSE;
6088
        if (!branchmiss) begin
6089
      // Two available
6090
      if (fetchbuf1_v & fetchbuf0_v) begin
6091
          // Is there a pair of NOPs ? (cache miss)
6092
          if ((fetchbuf0_instr[`INSTRUCTION_OP]==`NOP) && (fetchbuf1_instr[`INSTRUCTION_OP]==`NOP))
6093
              queuedNop <= TRUE;
6094
          else begin
6095
              // If it's a predicted branch queue only the first instruction, the second
6096
              // instruction will be stomped on.
6097
              if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
6098
                  if (iqentry_v[tail0]==`INV) begin
6099
                      canq1 <= TRUE;
6100
                      queued1 <= TRUE;
6101
                  end
6102
              end
6103
              // This is where a single NOP is allowed through to simplify the code. A
6104
              // single NOP can't be a cache miss. Otherwise it would be necessary to queue
6105
              // fetchbuf1 on tail0 it would add a nightmare to the enqueue code.
6106
              // Not a branch and there are two instructions fetched, see whether or not
6107
              // both instructions can be queued.
6108
              else begin
6109
                  if (iqentry_v[tail0]==`INV) begin
6110
                      canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
6111
                      queued1 <= (
6112
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
6113
                      if (iqentry_v[tail1]==`INV) begin
6114
                          canq2 <= ((!IsVex(fetchbuf1_instr) || rf_vra1)) || !SUP_VECTOR;
6115
                          queued2 <= (
6116
                                (!IsVector(fetchbuf1_instr) && (!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
6117
                          vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
6118
                      end
6119
                  end
6120
                  // If an irq is active during a vector instruction fetch, claim the vector instruction
6121
                  // is finished queueing even though it may not be. It'll pick up where it left off after
6122
                  // the exception is processed.
6123
                  if (freezePC) begin
6124
                        if (IsVector(fetchbuf0_instr) && IsVector(fetchbuf1_instr) && vechain) begin
6125
                                queued1 <= TRUE;
6126
                                queued2 <= TRUE;
6127
                        end
6128
                        else if (IsVector(fetchbuf0_instr)) begin
6129
                                queued1 <= TRUE;
6130
                                if (vqe0 < vl-2)
6131
                                        queued2 <= TRUE;
6132
                                else
6133
                                        queued2 <= iqentry_v[tail1]==`INV;
6134
                        end
6135
                  end
6136
              end
6137
          end
6138
      end
6139
      // One available
6140
      else if (fetchbuf0_v) begin
6141
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
6142
              if (iqentry_v[tail0]==`INV) begin
6143
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
6144
                  queued1 <=
6145
                        (((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
6146
              end
6147
              if (iqentry_v[tail1]==`INV) begin
6148
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
6149
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
6150
                end
6151
                if (freezePC) begin
6152
                if (IsVector(fetchbuf0_instr)) begin
6153
                        queued1 <= TRUE;
6154
                        if (vqe0 < vl-2)
6155
                                queued2 <= iqentry_v[tail1]==`INV;
6156
                end
6157
                end
6158
          end
6159
          else
6160
              queuedNop <= TRUE;
6161
      end
6162
      else if (fetchbuf1_v) begin
6163
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
6164
              if (iqentry_v[tail0]==`INV) begin
6165
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
6166
                  queued1 <= (
6167
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
6168
              end
6169
              if (iqentry_v[tail1]==`INV) begin
6170
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
6171
                  vqueued2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2;
6172
                end
6173
                if (freezePC) begin
6174
                if (IsVector(fetchbuf1_instr)) begin
6175
                        queued1 <= TRUE;
6176
                        if (vqe1 < vl-2)
6177
                                queued2 <= iqentry_v[tail1]==`INV;
6178
                end
6179
                end
6180
          end
6181
          else
6182
              queuedNop <= TRUE;
6183
      end
6184
      //else no instructions available to queue
6185
  end
6186
  else begin
6187
    // One available
6188
    if (fetchbuf0_v && fetchbuf0_thrd != branchmiss_thrd) begin
6189
        if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
6190
            if (iqentry_v[tail0]==`INV) begin
6191
                canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
6192
                queued1 <= (
6193
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
6194
            end
6195
            if (iqentry_v[tail1]==`INV) begin
6196
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
6197
                vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
6198
                end
6199
        end
6200
        else
6201 61 robfinch
          queuedNop <= TRUE;
6202 60 robfinch
    end
6203
    else if (fetchbuf1_v && fetchbuf1_thrd != branchmiss_thrd) begin
6204
        if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
6205
            if (iqentry_v[tail0]==`INV) begin
6206
                canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
6207
                queued1 <= (
6208
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
6209
            end
6210
            if (iqentry_v[tail1]==`INV) begin
6211
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
6212
                vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
6213
                end
6214
        end
6215
        else
6216
            queuedNop <= TRUE;
6217
    end
6218
//      else
6219
//              queuedNop <= TRUE;
6220
  end
6221
end
6222
 
6223
//
6224
// Branchmiss seems to be sticky sometimes during simulation. For instance branch miss
6225
// and cache miss at same time. The branchmiss should clear before the core continues
6226
// so the positive edge is detected to avoid incrementing the sequnce number too many
6227
// times.
6228
wire pebm;
6229
edge_det uedbm (.rst(rst), .clk(clk), .ce(1'b1), .i(branchmiss), .pe(pebm), .ne(), .ee() );
6230
 
6231
reg [5:0] ld_time;
6232
reg [63:0] wc_time_dat;
6233
reg [63:0] wc_times;
6234
always @(posedge tm_clk_i)
6235
begin
6236
        if (|ld_time)
6237
                wc_time <= wc_time_dat;
6238
        else begin
6239
                wc_time[31:0] <= wc_time[31:0] + 32'd1;
6240
                if (wc_time[31:0] >= TM_CLKFREQ-1) begin
6241
                        wc_time[31:0] <= 32'd0;
6242
                        wc_time[63:32] <= wc_time[63:32] + 32'd1;
6243
                end
6244
        end
6245
end
6246
 
6247
wire writing_wb =
6248 61 robfinch
                        (mem1_available && dram0==`DRAMSLOT_BUSY && dram0_store && wbptr<`WB_DEPTH-1)
6249
         || (mem2_available && dram1==`DRAMSLOT_BUSY && dram1_store && `NUM_MEM > 1 && wbptr<`WB_DEPTH-1)
6250
         || (mem3_available && dram2==`DRAMSLOT_BUSY && dram2_store && `NUM_MEM > 2 && wbptr<`WB_DEPTH-1)
6251 60 robfinch
         ;
6252
 
6253
// Monster clock domain.
6254
// Like to move some of this to clocking under different always blocks in order
6255
// to help out the toolset's synthesis, but it ain't gonna be easy.
6256
// Simulation doesn't like it if things are under separate always blocks.
6257
// Synthesis doesn't like it if things are under the same always block.
6258
 
6259
//always @(posedge clk)
6260
//begin
6261
//      branchmiss <= excmiss|fcu_branchmiss;
6262
//    misspc <= excmiss ? excmisspc : fcu_misspc;
6263
//    missid <= excmiss ? (|iqentry_exc[heads[0]] ? heads[0] : heads[1]) : fcu_sourceid;
6264
//      branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
6265
//end
6266
wire alu0_done_pe, alu1_done_pe, pe_wait;
6267
edge_det uedalu0d (.clk(clk), .ce(1'b1), .i(alu0_done), .pe(alu0_done_pe), .ne(), .ee());
6268
edge_det uedalu1d (.clk(clk), .ce(1'b1), .i(alu1_done), .pe(alu1_done_pe), .ne(), .ee());
6269
edge_det uedwait1 (.clk(clk), .ce(1'b1), .i((waitctr==48'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]]), .pe(pe_wait), .ne(), .ee());
6270
 
6271
// Bus randomization to mitigate meltdown attacks
6272
wire [63:0] ralu0_bus = |alu0_exc ? {4{lfsro}} : alu0_bus;
6273
wire [63:0] ralu1_bus = |alu1_exc ? {4{lfsro}} : alu1_bus;
6274
wire [63:0] rfpu1_bus = |fpu1_exc ? {4{lfsro}} : fpu1_bus;
6275
wire [63:0] rfpu2_bus = |fpu2_exc ? {4{lfsro}} : fpu2_bus;
6276 61 robfinch
wire [63:0] rfcu_bus  = |fcu_exc  ? {4{lfsro}} : fcu_bus;
6277
wire [63:0] rdramA_bus = dramA_bus;
6278
wire [63:0] rdramB_bus = dramB_bus;
6279
wire [63:0] rdramC_bus = dramC_bus;
6280 60 robfinch
 
6281
always @(posedge clk)
6282
if (rst) begin
6283
`ifdef SUPPORT_SMT
6284
     mstatus[0] <= 64'h4000F;    // select register set #16 for thread 0
6285
     mstatus[1] <= 64'h4800F;   // select register set #18 for thread 1
6286
     rs_stack[0] <= 64'd16;
6287
     brs_stack[0] <= 64'd16;
6288
     rs_stack[1] <= 64'd18;
6289
     brs_stack[1] <= 64'd18;
6290
`else
6291
     mstatus <= 64'h4000F;      // select register set #16 for thread 0
6292
     rs_stack <= 64'd16;
6293
     brs_stack <= 64'd16;
6294
`endif
6295
    for (n = 0; n < QENTRIES; n = n + 1) begin
6296
        iqentry_state[n] <= IQS_INVALID;
6297
       iqentry_iv[n] <= `INV;
6298
       iqentry_is[n] <= 3'b00;
6299
       iqentry_sn[n] <= 4'd0;
6300
       iqentry_pt[n] <= FALSE;
6301
       iqentry_bt[n] <= FALSE;
6302
       iqentry_br[n] <= FALSE;
6303
       iqentry_aq[n] <= FALSE;
6304
       iqentry_rl[n] <= FALSE;
6305
       iqentry_alu0[n] <= FALSE;
6306
       iqentry_alu[n] <= FALSE;
6307
       iqentry_fpu[n] <= FALSE;
6308
       iqentry_fsync[n] <= FALSE;
6309
       iqentry_fc[n] <= FALSE;
6310
       iqentry_takb[n] <= FALSE;
6311
       iqentry_jmp[n] <= FALSE;
6312
       iqentry_jal[n] <= FALSE;
6313
       iqentry_ret[n] <= FALSE;
6314
       iqentry_brk[n] <= FALSE;
6315
       iqentry_irq[n] <= FALSE;
6316
       iqentry_rti[n] <= FALSE;
6317
       iqentry_ldcmp[n] <= FALSE;
6318
       iqentry_load[n] <= FALSE;
6319
       iqentry_rtop[n] <= FALSE;
6320
       iqentry_sei[n] <= FALSE;
6321
       iqentry_shft[n] <= FALSE;
6322
       iqentry_sync[n] <= FALSE;
6323
       iqentry_ven[n] <= 6'd0;
6324
       iqentry_vl[n] <= 8'd0;
6325
       iqentry_we[n] <= 8'h00;
6326
       iqentry_rfw[n] <= FALSE;
6327
       iqentry_rmw[n] <= FALSE;
6328
       iqentry_pc[n] <= RSTPC;
6329
         iqentry_instr[n] <= `NOP_INSN;
6330
         iqentry_insln[n] <= 3'd4;
6331
         iqentry_preload[n] <= FALSE;
6332
         iqentry_mem[n] <= FALSE;
6333
         iqentry_memndx[n] <= FALSE;
6334
       iqentry_memissue[n] <= FALSE;
6335
       iqentry_mem_islot[n] <= 3'd0;
6336
       iqentry_memdb[n] <= FALSE;
6337
       iqentry_memsb[n] <= FALSE;
6338
       iqentry_tgt[n] <= 6'd0;
6339
       iqentry_imm[n] <= 1'b0;
6340
       iqentry_ma[n] <= 1'b0;
6341
       iqentry_a0[n] <= 64'd0;
6342
       iqentry_a1[n] <= 64'd0;
6343
       iqentry_a2[n] <= 64'd0;
6344
       iqentry_a3[n] <= 64'd0;
6345
       iqentry_a1_v[n] <= `INV;
6346
       iqentry_a2_v[n] <= `INV;
6347
       iqentry_a3_v[n] <= `INV;
6348
       iqentry_a1_s[n] <= 5'd0;
6349
       iqentry_a2_s[n] <= 5'd0;
6350
       iqentry_a3_s[n] <= 5'd0;
6351
       iqentry_canex[n] <= FALSE;
6352
    end
6353
     bwhich <= 2'b00;
6354
     dram0 <= `DRAMSLOT_AVAIL;
6355
     dram1 <= `DRAMSLOT_AVAIL;
6356
     dram2 <= `DRAMSLOT_AVAIL;
6357
     dram0_instr <= `NOP_INSN;
6358
     dram1_instr <= `NOP_INSN;
6359
     dram2_instr <= `NOP_INSN;
6360
     dram0_addr <= 32'h0;
6361
     dram1_addr <= 32'h0;
6362
     dram2_addr <= 32'h0;
6363
     dram0_id <= 1'b0;
6364
     dram1_id <= 1'b0;
6365
     dram2_id <= 1'b0;
6366
     L1_adr <= RSTPC;
6367 61 robfinch
     L2_adr <= RSTPC;
6368 60 robfinch
     invic <= FALSE;
6369
     tail0 <= 3'd0;
6370
     tail1 <= 3'd1;
6371
     for (n = 0; n < QENTRIES; n = n + 1)
6372
        heads[n] <= n;
6373
     panic = `PANIC_NONE;
6374
     alu0_dataready <= 1'b0;
6375
     alu1_dataready <= 1'b0;
6376
     alu0_sourceid <= 5'd0;
6377
     alu1_sourceid <= 5'd0;
6378
`define SIM_
6379
`ifdef SIM_
6380
                alu0_pc <= RSTPC;
6381
                alu0_instr <= `NOP_INSN;
6382
                alu0_argA <= 64'h0;
6383
                alu0_argB <= 64'h0;
6384
                alu0_argC <= 64'h0;
6385
                alu0_argI <= 64'h0;
6386
                alu0_mem <= 1'b0;
6387
                alu0_shft <= 1'b0;
6388
                alu0_thrd <= 1'b0;
6389
                alu0_tgt <= 6'h00;
6390
                alu0_ven <= 6'd0;
6391
                alu1_pc <= RSTPC;
6392
                alu1_instr <= `NOP_INSN;
6393
                alu1_argA <= 64'h0;
6394
                alu1_argB <= 64'h0;
6395
                alu1_argC <= 64'h0;
6396
                alu1_argI <= 64'h0;
6397
                alu1_mem <= 1'b0;
6398
                alu1_shft <= 1'b0;
6399
                alu1_thrd <= 1'b0;
6400
                alu1_tgt <= 6'h00;
6401
                alu1_ven <= 6'd0;
6402
`endif
6403
     fcu_dataready <= 0;
6404
     fcu_instr <= `NOP_INSN;
6405 61 robfinch
     fcu_call <= 1'b0;
6406 60 robfinch
     dramA_v <= 0;
6407
     dramB_v <= 0;
6408
     dramC_v <= 0;
6409
     I <= 0;
6410
     CC <= 0;
6411
     icstate <= IDLE;
6412
     bstate <= BIDLE;
6413
     tick <= 64'd0;
6414
     ol_o <= 2'b0;
6415
     bte_o <= 2'b00;
6416
     cti_o <= 3'b000;
6417
     cyc <= `LOW;
6418
     stb_o <= `LOW;
6419
     we <= `LOW;
6420
     sel_o <= 8'h00;
6421
     dat_o <= 64'hFFFFFFFFFFFFFFFF;
6422
     sr_o <= `LOW;
6423
     cr_o <= `LOW;
6424
     vadr <= RSTPC;
6425
     icl_o <= `LOW;             // instruction cache load
6426 61 robfinch
     L1_dati <= 306'd0;
6427 60 robfinch
     cr0 <= 64'd0;
6428
     cr0[13:8] <= 6'd0;         // select compressed instruction group #0
6429
     cr0[30] <= TRUE;           // enable data caching
6430
     cr0[32] <= TRUE;           // enable branch predictor
6431
     cr0[16] <= 1'b0;           // disable SMT
6432
     cr0[17] <= 1'b0;           // sequence number reset = 1
6433
     cr0[34] <= FALSE;  // write buffer merging enable
6434
     cr0[35] <= TRUE;           // load speculation enable
6435
     pcr <= 32'd0;
6436
     pcr2 <= 64'd0;
6437
    for (n = 0; n < PREGS; n = n + 1) begin
6438
      rf_v[n] <= `VAL;
6439
      rf_source[n] <= {`QBIT{1'b1}};
6440
    end
6441
     fp_rm <= 3'd0;                     // round nearest even - default rounding mode
6442
     fpu_csr[37:32] <= 5'd31;   // register set #31
6443
     waitctr <= 48'd0;
6444
    for (n = 0; n < 16; n = n + 1) begin
6445
      badaddr[n] <= 64'd0;
6446
      bad_instr[n] <= `NOP_INSN;
6447
    end
6448
    // Vector
6449
     vqe0 <= 6'd0;
6450
     vqet0 <= 6'd0;
6451
     vqe1 <= 6'd0;
6452
     vqet1 <= 6'd0;
6453
     vl <= 7'd62;
6454
    for (n = 0; n < 8; n = n + 1)
6455
         vm[n] <= 64'h7FFFFFFFFFFFFFFF;
6456
     nop_fetchbuf <= 4'h0;
6457
     fcu_done <= `TRUE;
6458
     sema <= 64'h0;
6459
     tvec[0] <= RSTPC;
6460
     pmr <= 64'hFFFFFFFFFFFFFFFF;
6461
     pmr[0] <= `ID1_AVAIL;
6462
     pmr[1] <= `ID2_AVAIL;
6463
     pmr[2] <= `ID3_AVAIL;
6464
     pmr[8] <= `ALU0_AVAIL;
6465
     pmr[9] <= `ALU1_AVAIL;
6466
     pmr[16] <= `FPU1_AVAIL;
6467
     pmr[17] <= `FPU2_AVAIL;
6468
     pmr[24] <= `MEM1_AVAIL;
6469
     pmr[25] <= `MEM2_AVAIL;
6470
                 pmr[26] <= `MEM3_AVAIL;
6471
     pmr[32] <= `FCU_AVAIL;
6472
     for (n = 0; n < `WB_DEPTH; n = n + 1) begin
6473
        wb_v[n] <= 1'b0;
6474
        wb_rmw[n] <= 1'b0;
6475
        wb_id[n] <= {QENTRIES{1'b0}};
6476
        wb_ol[n] <= 2'b00;
6477
        wb_sel[n] <= 8'h00;
6478
        wb_addr[n] <= 32'd0;
6479
        wb_data[n] <= 64'd0;
6480
     end
6481
     wb_en <= `TRUE;
6482
     wbo_id <= {QENTRIES{1'b0}};
6483
     wbptr <= 2'd0;
6484
`ifdef SIM
6485
                wb_merges <= 32'd0;
6486
`endif
6487
                iq_ctr <= 40'd0;
6488
                icl_ctr <= 40'd0;
6489
                bm_ctr <= 40'd0;
6490 61 robfinch
                br_ctr <= 40'd0;
6491 60 robfinch
                irq_ctr <= 40'd0;
6492
                cmt_timer <= 9'd0;
6493
                StoreAck1 <= `FALSE;
6494
                keys <= 64'h0;
6495
`ifdef SUPPORT_DBG
6496
                dbg_ctrl <= 64'h0;
6497
`endif
6498
/* Initialized with initial begin above
6499
`ifdef SUPPORT_BBMS
6500
                for (n = 0; n < 64; n = n + 1) begin
6501
                        thrd_handle[n] <= 16'h0;
6502
                        prg_base[n] <= 64'h0;
6503
                        cl_barrier[n] <= 64'h0;
6504
                        cu_barrier[n] <= 64'hFFFFFFFFFFFFFFFF;
6505
                        ro_barrier[n] <= 64'h0;
6506
                        dl_barrier[n] <= 64'h0;
6507
                        du_barrier[n] <= 64'hFFFFFFFFFFFFFFFF;
6508
                        sl_barrier[n] <= 64'h0;
6509
                        su_barrier[n] <= 64'hFFFFFFFFFFFFFFFF;
6510
                end
6511
`endif
6512
*/
6513
end
6514
else begin
6515
        if (|fb_panic)
6516
                panic <= fb_panic;
6517
 
6518
        // Only one branchmiss is allowed to be processed at a time. If a second 
6519
        // branchmiss occurs while the first is being processed, it would have
6520
        // to of occurred as a speculation in the branch shadow of the first.
6521
        // The second instruction would be stomped on by the first branchmiss so
6522
        // there is no need to process it.
6523
        // The branchmiss has to be latched, then cleared later as there could
6524
        // be a cache miss at the same time meaning the switch to the new pc
6525
        // does not take place immediately.
6526
        if (!branchmiss) begin
6527
                if (excmiss) begin
6528
                        branchmiss <= `TRUE;
6529
                        misspc <= excmisspc;
6530
                        missid <= (|iqentry_exc[heads[0]] ? heads[0] : heads[1]);
6531
                        branchmiss_thrd <= excthrd;
6532
                end
6533
                else if (fcu_branchmiss) begin
6534
                        branchmiss <= `TRUE;
6535
                        misspc <= fcu_misspc;
6536
                        missid <= fcu_sourceid;
6537
                        branchmiss_thrd <= fcu_thrd;
6538
                end
6539
        end
6540
        // Clear a branch miss when target instruction is fetched.
6541
        if (will_clear_branchmiss) begin
6542
                branchmiss <= `FALSE;
6543
        end
6544
 
6545
        // The following signals only pulse
6546
 
6547
        // Instruction decode output should only pulse once for a queue entry. We
6548
        // want the decode to be invalidated after a clock cycle so that it isn't
6549
        // inadvertently used to update the queue at a later point.
6550
        dramA_v <= `INV;
6551
        dramB_v <= `INV;
6552
        dramC_v <= `INV;
6553
        id1_vi <= `INV;
6554
        if (`NUM_IDU > 1)
6555
                id2_vi <= `INV;
6556
        if (`NUM_IDU > 2)
6557
                id3_vi <= `INV;
6558
        wb_shift <= FALSE;
6559
        ld_time <= {ld_time[4:0],1'b0};
6560
        wc_times <= wc_time;
6561
     rf_vra0 <= regIsValid[Ra0s];
6562
     rf_vra1 <= regIsValid[Ra1s];
6563
    if (vqe0 >= vl) begin
6564
         vqe0 <= 6'd0;
6565
         vqet0 <= 6'h0;
6566
    end
6567
    if (vqe1 >= vl) begin
6568
         vqe1 <= 6'd0;
6569
         vqet1 <= 6'h0;
6570
    end
6571
    // Turn off vector chaining indicator when chained instructions are done.
6572
    if ((vqe0 >= vl || vqe0==6'd0) && (vqe1 >= vl || vqe1==6'd0))
6573
`ifdef SUPPORT_SMT
6574
        mstatus[0][32] <= 1'b0;
6575
`else
6576
        mstatus[32] <= 1'b0;
6577
`endif
6578
 
6579
     nop_fetchbuf <= 4'h0;
6580
     excmiss <= FALSE;
6581
     invic <= FALSE;
6582
     tick <= tick + 64'd1;
6583
     alu0_ld <= FALSE;
6584
     alu1_ld <= FALSE;
6585
     fpu1_ld <= FALSE;
6586
     fpu2_ld <= FALSE;
6587
     fcu_ld <= FALSE;
6588
     cr0[17] <= 1'b0;
6589
    if (waitctr != 48'd0)
6590
         waitctr <= waitctr - 4'd1;
6591
 
6592
 
6593
    if (iqentry_fc[fcu_id[`QBITS]] && iqentry_v[fcu_id[`QBITS]] && !iqentry_done[fcu_id[`QBITS]] && iqentry_out[fcu_id[`QBITS]])
6594
        fcu_timeout <= fcu_timeout + 8'd1;
6595
 
6596
        if (branchmiss) begin
6597
        for (n = 1; n < PREGS; n = n + 1)
6598
           if (~livetarget[n]) begin
6599
                        if (branchmiss_thrd) begin
6600
                                if (n >= 128)
6601
                                rf_v[n] <= `VAL;
6602
                        end
6603
                        else begin
6604
                                if (n < 128)
6605
                                rf_v[n] <= `VAL;
6606
                end
6607
           end
6608
                        for (n = 0; n < QENTRIES; n = n + 1)
6609
                if (|iqentry_latestID[n])
6610
                        if (iqentry_thrd[n]==branchmiss_thrd) rf_source[ {iqentry_tgt[n][7:0]} ] <= { 1'b0, iqentry_mem[n], n[`QBITS] };
6611
    end
6612
 
6613
    // The source for the register file data might have changed since it was
6614
    // placed on the commit bus. So it's needed to check that the source is
6615
    // still as expected to validate the register.
6616
                if (commit0_v) begin
6617
      if (!rf_v[ {commit0_tgt[7:0]} ]) begin
6618
//         rf_v[ {commit0_tgt[7:0]} ] <= rf_source[ commit0_tgt[7:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]);
6619
        rf_v[ {commit0_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}];//rf_source[ commit0_tgt[4:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]);
6620
        if (regIsValid[{commit0_tgt[7:0]}])
6621
                rf_source[{commit0_tgt[7:0]}] <= {`QBIT{1'b1}};
6622
      end
6623
      if (commit0_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit0_tgt, commit0_bus, regIsValid[commit0_tgt[5:0]],
6624
      rf_source[ {commit0_tgt[7:0]} ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]));
6625
      if (commit0_tgt[5:0]==6'd30 && commit0_bus==64'd0)
6626
        $display("FP <= 0");
6627
    end
6628
    if (commit1_v && `NUM_CMT > 1) begin
6629
      if (!rf_v[ {commit1_tgt[7:0]} ]) begin
6630
        if ({commit1_tgt[7:0]}=={commit0_tgt[7:0]}) begin
6631
                rf_v[ {commit1_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}];
6632
                if (regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}])
6633
                rf_source[{commit1_tgt[7:0]}] <= {`QBIT{1'b1}};
6634
                /*
6635
                        (rf_source[ commit0_tgt[4:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ])) ||
6636
                        (rf_source[ commit1_tgt[4:0] ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6637
                */
6638
        end
6639
        else begin
6640
                                        rf_v[ {commit1_tgt[7:0]} ] <= regIsValid[{commit1_tgt[7:0]}];//rf_source[ commit1_tgt[4:0] ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]);
6641
          if (regIsValid[{commit1_tgt[7:0]}])
6642
                rf_source[{commit1_tgt[7:0]}] <= {`QBIT{1'b1}};
6643
        end
6644
      end
6645
      if (commit1_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit1_tgt, commit1_bus, regIsValid[commit1_tgt[5:0]],
6646
      rf_source[ {commit1_tgt[7:0]} ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6647
      if (commit1_tgt[5:0]==6'd30 && commit1_bus==64'd0)
6648
        $display("FP <= 0");
6649
    end
6650
    if (commit2_v && `NUM_CMT > 2) begin
6651
      if (!rf_v[ {commit2_tgt[7:0]} ]) begin
6652
        if ({commit2_tgt[7:0]}=={commit1_tgt[7:0]} && {commit2_tgt[7:0]}=={commit0_tgt[7:0]}) begin
6653
                rf_v[ {commit2_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}];
6654
                if (regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}])
6655
                rf_source[{commit0_tgt[7:0]}] <= {`QBIT{1'b1}};
6656
        end
6657
        else if ({commit2_tgt[7:0]}=={commit0_tgt[7:0]}) begin
6658
                rf_v[ {commit2_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}];
6659
                if (regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}])
6660
                rf_source[{commit0_tgt[7:0]}] <= {`QBIT{1'b1}};
6661
        end
6662
        else if ({commit2_tgt[7:0]}=={commit1_tgt[7:0]}) begin
6663
                rf_v[ {commit2_tgt[7:0]} ] <= regIsValid[{commit1_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}];
6664
                if (regIsValid[{commit1_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}])
6665
                rf_source[{commit1_tgt[7:0]}] <= {`QBIT{1'b1}};
6666
        end
6667
        else begin
6668
                rf_v[ {commit2_tgt[7:0]} ] <= regIsValid[{commit2_tgt[7:0]}];//rf_source[ commit1_tgt[4:0] ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]);
6669
                if (regIsValid[{commit2_tgt[7:0]}])
6670
                rf_source[{commit2_tgt[7:0]}] <= {`QBIT{1'b1}};
6671
        end
6672
      end
6673
      if (commit2_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit2_tgt, commit2_bus, regIsValid[commit2_tgt[5:0]],
6674
      rf_source[ {commit2_tgt[7:0]} ] == commit2_id || (branchmiss && iqentry_source[ commit2_id[`QBITS] ]));
6675
      if (commit2_tgt[5:0]==6'd30 && commit2_bus==64'd0)
6676
        $display("FP <= 0");
6677
    end
6678
     rf_v[0] <= 1;
6679
 
6680
  //
6681
  // ENQUEUE
6682
  //
6683
  // place up to two instructions from the fetch buffer into slots in the IQ.
6684
  //   note: they are placed in-order, and they are expected to be executed
6685
  // 0, 1, or 2 of the fetch buffers may have valid data
6686
  // 0, 1, or 2 slots in the instruction queue may be available.
6687
  // if we notice that one of the instructions in the fetch buffer is a predicted branch,
6688
  // (set branchback/backpc and delete any instructions after it in fetchbuf)
6689
  //
6690
 
6691
        // enqueue fetchbuf0 and fetchbuf1, but only if there is room, 
6692
        // and ignore fetchbuf1 if fetchbuf0 has a backwards branch in it.
6693
        //
6694
        // also, do some instruction-decode ... set the operand_valid bits in the IQ
6695
        // appropriately so that the DATAINCOMING stage does not have to look at the opcode
6696
        //
6697
        if (!branchmiss)        // don't bother doing anything if there's been a branch miss
6698
 
6699
                case ({fetchbuf0_v, fetchbuf1_v})
6700
 
6701
            2'b00: ; // do nothing
6702
 
6703
            2'b01:
6704
                    if (canq1) begin
6705
                                        if (fetchbuf1_rfw) begin
6706
                                                rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_mem, tail0 };    // top bit indicates ALU/MEM bus
6707
                                                rf_v [Rt1s] <= `INV;
6708
                                        end
6709
                                        if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6710
                                                vqe1 <= vqe1 + 4'd1;
6711
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6712
                                                        if (vm[fetchbuf1_instr[25:23]][vqe1])
6713
                                                                vqet1 <= vqet1 + 4'd1;
6714
                                                end
6715
                                                else
6716
                                                        vqet1 <= vqet1 + 4'd1;
6717
                                                if (vqe1 >= vl-2)
6718
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6719
                                                enque1(tail0, fetchbuf1_thrd ? maxsn[1]+4'd1 : maxsn[0]+4'd1, vqe1);
6720
                                                iq_ctr = iq_ctr + 4'd1;
6721
                                                if (canq2 && vqe1 < vl-2) begin
6722
                                                        vqe1 <= vqe1 + 4'd2;
6723
                                                        if (IsVCmprss(fetchbuf1_instr)) begin
6724
                                                                if (vm[fetchbuf1_instr[25:23]][vqe1+6'd1])
6725
                                                                        vqet1 <= vqet1 + 4'd2;
6726
                                                        end
6727
                                                        else
6728
                                                                vqet1 <= vqet1 + 4'd2;
6729
                                                        enque1(tail1, fetchbuf1_thrd ? maxsn[1] + 4'd2 : maxsn[0] + 4'd2, vqe1 + 6'd1);
6730
                                                        iq_ctr = iq_ctr + 4'd2;
6731
                                                end
6732
                                        end
6733
                                        else begin
6734
                                                enque1(tail0, fetchbuf1_thrd ? maxsn[1]+4'd1 : maxsn[0]+4'd1, 6'd0);
6735
                                                iq_ctr = iq_ctr + 4'd1;
6736
                                        end
6737
                    end
6738
 
6739
            2'b10:
6740
                if (canq1) begin
6741
                        enque0x();
6742
                    end
6743
 
6744
            2'b11:
6745
                    if (canq1) begin
6746
                                //
6747
                                // if the first instruction is a predicted branch, enqueue it & stomp on all following instructions
6748
                                // but only if the following instruction is in the same thread. Otherwise we want to queue two.
6749
                                //
6750
                                if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
6751
                                        enque0x();
6752
                                end
6753
 
6754
                                else begin      // fetchbuf0 doesn't contain a predicted branch
6755
                                    //
6756
                                    // so -- we can enqueue 1 or 2 instructions, depending on space in the IQ
6757
                                    // update the rf_v and rf_source bits separately (at end)
6758
                                    //   the problem is that if we do have two instructions, 
6759
                                    //   they may interact with each other, so we have to be
6760
                                    //   careful about where things point.
6761
                                    //
6762
                                    // enqueue the first instruction ...
6763
                                    //
6764
                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
6765
                                 vqe0 <= vqe0 + 4'd1;
6766
                                if (IsVCmprss(fetchbuf0_instr)) begin
6767
                                    if (vm[fetchbuf0_instr[25:23]][vqe0])
6768
                                         vqet0 <= vqet0 + 4'd1;
6769
                                end
6770
                                else
6771
                                     vqet0 <= vqet0 + 4'd1;
6772
                                if (vqe0 >= vl-2)
6773
                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6774
                            end
6775
                            if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
6776
                                    enque0(tail0, fetchbuf0_thrd ? maxsn[1]+4'd1 : maxsn[0]+4'd1, vqe0);
6777
                                                                        iq_ctr = iq_ctr + 4'd1;
6778
                                            //
6779
                                            // if there is room for a second instruction, enqueue it
6780
                                            //
6781
                                            if (canq2) begin
6782
                                                if (vechain && IsVector(fetchbuf1_instr)
6783
                                                && Ra1s != Rt0s // And there is no dependency
6784
                                                && Rb1s != Rt0s
6785
                                                && Rc1s != Rt0s
6786
                                                ) begin
6787
`ifdef SUPPORT_SMT
6788
                                                        mstatus[0][32] <= 1'b1;
6789
`else
6790
                                                        mstatus[32] <= 1'b1;
6791
`endif
6792
                                                vqe1 <= vqe1 + 4'd1;
6793
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6794
                                                    if (vm[fetchbuf1_instr[25:23]][vqe1])
6795
                                                         vqet1 <= vqet1 + 4'd1;
6796
                                                end
6797
                                                else
6798
                                                     vqet1 <= vqet1 + 4'd1;
6799
                                                if (vqe1 >= vl-2)
6800
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6801
                                                        enque1(tail1,
6802
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? maxsn[1] + 4'd2 :
6803
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? maxsn[0] + 4'd2 :
6804
                                                                fetchbuf1_thrd ? maxsn[1] + 4'd2: maxsn[0] + 4'd2, 6'd0);
6805
                                                                                iq_ctr = iq_ctr + 4'd2;
6806
 
6807
                                                                // SOURCE 1 ...
6808
                                                                a1_vs();
6809
 
6810
                                                                // SOURCE 2 ...
6811
                                                                a2_vs();
6812
 
6813
                                                                // SOURCE 3 ...
6814
                                                                a3_vs();
6815
 
6816
                                                                // if the two instructions enqueued target the same register, 
6817
                                                                // make sure only the second writes to rf_v and rf_source.
6818
                                                                // first is allowed to update rf_v and rf_source only if the
6819
                                                                // second has no target
6820
                                                                //
6821
                                                            if (fetchbuf0_rfw) begin
6822
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_mem, tail0 };
6823
                                                                     rf_v [ Rt0s] <= `INV;
6824
                                                            end
6825
                                                            if (fetchbuf1_rfw) begin
6826
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_mem, tail1 };
6827
                                                                     rf_v [ Rt1s ] <= `INV;
6828
                                                            end
6829
                                                end
6830
                                                // If there was a vector instruction in fetchbuf0, we really
6831
                                                // want to queue the next vector element, not the next
6832
                                                // instruction waiting in fetchbuf1.
6833
                                            else if (IsVector(fetchbuf0_instr) && SUP_VECTOR && vqe0 < vl-1) begin
6834
                                                 vqe0 <= vqe0 + 4'd2;
6835
                                                if (IsVCmprss(fetchbuf0_instr)) begin
6836
                                                    if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
6837
                                                         vqet0 <= vqet0 + 4'd2;
6838
                                                end
6839
                                                else
6840
                                                     vqet0 <= vqet0 + 4'd2;
6841
                                                if (vqe0 >= vl-3)
6842
                                                 nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6843
                                            if (vqe0 < vl-1) begin
6844
                                                                enque0(tail1, fetchbuf0_thrd ? maxsn[1] + 4'd2 : maxsn[0] + 4'd2, vqe0 + 6'd1);
6845
                                                                                        iq_ctr = iq_ctr + 4'd2;
6846
 
6847
                                                                        // SOURCE 1 ...
6848
                                                     iqentry_a1_v [tail1] <= regIsValid[Ra0s];
6849
                                                     iqentry_a1_s [tail1] <= rf_source [Ra0s];
6850
 
6851
                                                                        // SOURCE 2 ...
6852
                                                     iqentry_a2_v [tail1] <= regIsValid[Rb0s];
6853
                                                     iqentry_a2_s [tail1] <= rf_source[ Rb0s ];
6854
 
6855
                                                                        // SOURCE 3 ...
6856
                                                     iqentry_a3_v [tail1] <= regIsValid[Rc0s];
6857
                                                     iqentry_a3_s [tail1] <= rf_source[ Rc0s ];
6858
 
6859
 
6860
                                                                        // if the two instructions enqueued target the same register, 
6861
                                                                        // make sure only the second writes to rf_v and rf_source.
6862
                                                                        // first is allowed to update rf_v and rf_source only if the
6863
                                                                        // second has no target (BEQ or SW)
6864
                                                                        //
6865
                                                                    if (fetchbuf0_rfw) begin
6866
                                                                             rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_mem, tail1 };
6867
                                                                             rf_v [ Rt0s ] <= `INV;
6868
                                                                    end
6869
                                                                end
6870
                                                end
6871
                                            else if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6872
                                                 vqe1 <= 6'd1;
6873
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6874
                                                    if (vm[fetchbuf1_instr[25:23]][IsVector(fetchbuf0_instr)? 6'd0:vqe1+6'd1])
6875
                                                         vqet1 <= 6'd1;
6876
                                                else
6877
                                                         vqet1 <= 6'd0;
6878
                                                end
6879
                                                else
6880
                                                         vqet1 <= 6'd1;
6881
                                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR)
6882
                                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6883
                                                        enque1(tail1,
6884
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? maxsn[1] + 4'd2 :
6885
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? maxsn[0] + 4'd2 :
6886
                                                                fetchbuf1_thrd ? maxsn[1] + 4'd2: maxsn[0] + 4'd2, 6'd0);
6887
                                                                                iq_ctr = iq_ctr + 4'd2;
6888
 
6889
                                                                // SOURCE 1 ...
6890
                                                                a1_vs();
6891
 
6892
                                                                // SOURCE 2 ..
6893
                                                                a2_vs();
6894
 
6895
                                                                // SOURCE 3 ...
6896
                                                                a3_vs();
6897
 
6898
                                                                // if the two instructions enqueued target the same register, 
6899
                                                                // make sure only the second writes to rf_v and rf_source.
6900
                                                                // first is allowed to update rf_v and rf_source only if the
6901
                                                                // second has no target
6902
                                                                //
6903
                                                            if (fetchbuf0_rfw) begin
6904
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_mem, tail0 };
6905
                                                                     rf_v [ Rt0s] <= `INV;
6906
                                                            end
6907
                                                            if (fetchbuf1_rfw) begin
6908
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_mem, tail1 };
6909
                                                                     rf_v [ Rt1s ] <= `INV;
6910
                                                            end
6911
                                            end
6912
                                            else begin
6913
//                                                      enque1(tail1, seq_num + 5'd1, 6'd0);
6914
                                                        enque1(tail1,
6915
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? maxsn[1] + 4'd2 :
6916
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? maxsn[0] + 4'd2 :
6917
                                                                fetchbuf1_thrd ? maxsn[1] + 4'd1: maxsn[0]+4'd1, 6'd0);
6918
                                                                                iq_ctr = iq_ctr + 4'd2;
6919
 
6920
                                                                // SOURCE 1 ...
6921
                                                                a1_vs();
6922
 
6923
                                                                // SOURCE 2 ...
6924
                                                                a2_vs();
6925
 
6926
                                                                // SOURCE 3 ...
6927
                                                                a3_vs();
6928
 
6929
 
6930
                                                                // if the two instructions enqueued target the same register, 
6931
                                                                // make sure only the second writes to regIsValid and rf_source.
6932
                                                                // first is allowed to update regIsValid and rf_source only if the
6933
                                                                // second has no target (BEQ or SW)
6934
                                                                //
6935
                                                            if (fetchbuf0_rfw) begin
6936
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_mem, tail0 };
6937
                                                                     rf_v [ Rt0s] <= `INV;
6938
                                                                     $display("r%dx (%d) Invalidated", Rt0s, Rt0s[4:0]);
6939
                                                            end
6940
                                                            else
6941
                                                                $display("No rfw");
6942
                                                            if (fetchbuf1_rfw) begin
6943
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_mem, tail1 };
6944
                                                                     $display("r%dx (%d) Invalidated", Rt1s, Rt1s[4:0]);
6945
                                                                     rf_v [ Rt1s ] <= `INV;
6946
                                                            end
6947
                                                            else
6948
                                                                $display("No rfw");
6949
                                                        end
6950
 
6951
                                            end // ends the "if IQ[tail1] is available" clause
6952
                                            else begin  // only first instruction was enqueued
6953
                                                        if (fetchbuf0_rfw) begin
6954
                                                             $display("r%dx (%d) Invalidated 1", Rt0s, Rt0s[4:0]);
6955
                                                             rf_source[ Rt0s ] <= {1'b0,fetchbuf0_mem, tail0};
6956
                                                             rf_v [ Rt0s ] <= `INV;
6957
                                                        end
6958
                                                end
6959
                                    end
6960
 
6961
                                end     // ends the "else fetchbuf0 doesn't have a backwards branch" clause
6962
                    end
6963
                endcase
6964
        if (pebm) begin
6965
                bm_ctr <= bm_ctr + 40'd1;
6966
        end
6967
 
6968
//
6969
// DATAINCOMING
6970
//
6971
// wait for operand/s to appear on alu busses and puts them into 
6972
// the iqentry_a1 and iqentry_a2 slots (if appropriate)
6973
// as well as the appropriate iqentry_res slots (and setting valid bits)
6974
//
6975
// put results into the appropriate instruction entries
6976
//
6977
// This chunk of code has to be before the enqueue stage so that the agen bit
6978
// can be reset to zero by enqueue.
6979
// put results into the appropriate instruction entries
6980
//
6981
if (IsMul(alu0_instr)|IsDivmod(alu0_instr)|alu0_shft|alu0_tlb) begin
6982
        if (alu0_done_pe) begin
6983
                alu0_dataready <= TRUE;
6984
        end
6985
end
6986
if (alu1_shft) begin
6987
        if (alu1_done_pe) begin
6988
                alu1_dataready <= TRUE;
6989
        end
6990
end
6991
 
6992
if (alu0_v) begin
6993
        iqentry_tgt [ alu0_id[`QBITS] ] <= alu0_tgt;
6994
        iqentry_res     [ alu0_id[`QBITS] ] <= ralu0_bus;
6995
        iqentry_exc     [ alu0_id[`QBITS] ] <= alu0_exc;
6996
        if (!iqentry_mem[ alu0_id[`QBITS] ] && alu0_done) begin
6997
//              iqentry_done[ alu0_id[`QBITS] ] <= `TRUE;
6998
                iqentry_state[alu0_id[`QBITS]] <= IQS_CMT;
6999
        end
7000
//      if (alu0_done)
7001
//              iqentry_cmt [ alu0_id[`QBITS] ] <= `TRUE;
7002
//      iqentry_out     [ alu0_id[`QBITS] ] <= `INV;
7003
//      iqentry_agen[ alu0_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
7004
        if (iqentry_mem[alu0_id[`QBITS]])
7005
                iqentry_state[alu0_id[`QBITS]] <= IQS_AGEN;
7006
        if (iqentry_mem[ alu0_id[`QBITS] ] && !iqentry_agen[ alu0_id[`QBITS] ]) begin
7007
                iqentry_ma[ alu0_id[`QBITS] ] <= alu0_bus;
7008
        end
7009
        if (|alu0_exc) begin
7010
//              iqentry_done[alu0_id[`QBITS]] <= `VAL;
7011
                iqentry_store[alu0_id[`QBITS]] <= `INV;
7012
                iqentry_state[alu0_id[`QBITS]] <= IQS_CMT;
7013
        end
7014
        alu0_dataready <= FALSE;
7015
end
7016
 
7017
if (alu1_v && `NUM_ALU > 1) begin
7018
        iqentry_tgt [ alu1_id[`QBITS] ] <= alu1_tgt;
7019
        iqentry_res     [ alu1_id[`QBITS] ] <= ralu1_bus;
7020
        iqentry_exc     [ alu1_id[`QBITS] ] <= alu1_exc;
7021
        if (!iqentry_mem[ alu1_id[`QBITS] ] && alu1_done) begin
7022
//              iqentry_done[ alu1_id[`QBITS] ] <= `TRUE;
7023
                iqentry_state[alu1_id[`QBITS]] <= IQS_CMT;
7024
        end
7025
//      iqentry_done[ alu1_id[`QBITS] ] <= (!iqentry_mem[ alu1_id[`QBITS] ] && alu1_done);
7026
//      if (alu1_done)
7027
//              iqentry_cmt [ alu1_id[`QBITS] ] <= `TRUE;
7028
//      iqentry_out     [ alu1_id[`QBITS] ] <= `INV;
7029
        if (iqentry_mem[alu1_id[`QBITS]])
7030
                iqentry_state[alu1_id[`QBITS]] <= IQS_AGEN;
7031
//      iqentry_agen[ alu1_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
7032
        if (iqentry_mem[ alu1_id[`QBITS] ] && !iqentry_agen[ alu1_id[`QBITS] ]) begin
7033
                iqentry_ma[ alu1_id[`QBITS] ] <= alu1_bus;
7034
        end
7035
        if (|alu1_exc) begin
7036
//              iqentry_done[alu1_id[`QBITS]] <= `VAL;
7037
                iqentry_store[alu1_id[`QBITS]] <= `INV;
7038
                iqentry_state[alu1_id[`QBITS]] <= IQS_CMT;
7039
        end
7040
        alu1_dataready <= FALSE;
7041
end
7042
 
7043
if (fpu1_v && `NUM_FPU > 0) begin
7044
        iqentry_res [ fpu1_id[`QBITS] ] <= rfpu1_bus;
7045
        iqentry_ares[ fpu1_id[`QBITS] ] <= fpu1_status;
7046
        iqentry_exc [ fpu1_id[`QBITS] ] <= fpu1_exc;
7047
//      iqentry_done[ fpu1_id[`QBITS] ] <= fpu1_done;
7048
//      iqentry_out [ fpu1_id[`QBITS] ] <= `INV;
7049
        iqentry_state[fpu1_id[`QBITS]] <= IQS_CMT;
7050
        fpu1_dataready <= FALSE;
7051
end
7052
 
7053
if (fpu2_v && `NUM_FPU > 1) begin
7054
        iqentry_res [ fpu2_id[`QBITS] ] <= rfpu2_bus;
7055
        iqentry_ares[ fpu2_id[`QBITS] ] <= fpu2_status;
7056
        iqentry_exc [ fpu2_id[`QBITS] ] <= fpu2_exc;
7057
//      iqentry_done[ fpu2_id[`QBITS] ] <= fpu2_done;
7058
//      iqentry_out [ fpu2_id[`QBITS] ] <= `INV;
7059
        iqentry_state[fpu2_id[`QBITS]] <= IQS_CMT;
7060
        //iqentry_agen[ fpu_id[`QBITS] ] <= `VAL;  // RET
7061
        fpu2_dataready <= FALSE;
7062
end
7063
 
7064
if (IsWait(fcu_instr)) begin
7065
        if (pe_wait)
7066
                fcu_dataready <= `TRUE;
7067
end
7068
 
7069 61 robfinch
// If the return segment is not the same as the current code segment then a
7070
// segment load is triggered via the memory unit by setting the iq state to
7071
// AGEN. Otherwise the state is set to CMT which will cause a bypass of the
7072
// segment load from memory.
7073
 
7074 60 robfinch
if (fcu_v) begin
7075
        fcu_done <= `TRUE;
7076
        iqentry_ma  [ fcu_id[`QBITS] ] <= fcu_misspc;
7077
  iqentry_res [ fcu_id[`QBITS] ] <= rfcu_bus;
7078
  iqentry_exc [ fcu_id[`QBITS] ] <= fcu_exc;
7079
        iqentry_state[fcu_id[`QBITS] ] <= IQS_CMT;
7080
        // takb is looked at only for branches to update the predictor. Here it is
7081
        // unconditionally set, the value will be ignored if it's not a branch.
7082
        iqentry_takb[ fcu_id[`QBITS] ] <= fcu_takb;
7083 61 robfinch
        br_ctr <= br_ctr + fcu_branch;
7084 60 robfinch
        fcu_dataready <= `INV;
7085
end
7086
 
7087
// dramX_v only set on a load
7088 61 robfinch
if (dramA_v && iqentry_v[ dramA_id[`QBITS] ]) begin
7089 60 robfinch
        iqentry_res     [ dramA_id[`QBITS] ] <= rdramA_bus;
7090
//      iqentry_done[ dramA_id[`QBITS] ] <= `VAL;
7091
//      iqentry_out [ dramA_id[`QBITS] ] <= `INV;
7092
        iqentry_state[dramA_id[`QBITS] ] <= IQS_CMT;
7093
        iqentry_aq  [ dramA_id[`QBITS] ] <= `INV;
7094
end
7095 61 robfinch
if (`NUM_MEM > 1 && dramB_v && iqentry_v[ dramB_id[`QBITS] ]) begin
7096 60 robfinch
        iqentry_res     [ dramB_id[`QBITS] ] <= rdramB_bus;
7097
        iqentry_state[dramB_id[`QBITS] ] <= IQS_CMT;
7098
        iqentry_aq  [ dramB_id[`QBITS] ] <= `INV;
7099
end
7100 61 robfinch
if (`NUM_MEM > 2 && dramC_v && iqentry_v[ dramC_id[`QBITS] ]) begin
7101 60 robfinch
        iqentry_res     [ dramC_id[`QBITS] ] <= rdramC_bus;
7102
        iqentry_state[dramC_id[`QBITS] ] <= IQS_CMT;
7103
        iqentry_aq  [ dramC_id[`QBITS] ] <= `INV;
7104
//          if (iqentry_lptr[dram2_id[`QBITS]])
7105
//              wbrcd[pcr[5:0]] <= 1'b1;
7106
end
7107
 
7108
//
7109
// see if anybody else wants the results ... look at lots of buses:
7110
//  - fpu_bus
7111
//  - alu0_bus
7112
//  - alu1_bus
7113
//  - fcu_bus
7114
//  - dram_bus
7115
//  - commit0_bus
7116
//  - commit1_bus
7117
//
7118
 
7119
for (n = 0; n < QENTRIES; n = n + 1)
7120
begin
7121
        if (`NUM_FPU > 0)
7122
                setargs(n,{1'b0,fpu1_id},fpu1_v,rfpu1_bus);
7123
        if (`NUM_FPU > 1)
7124
                setargs(n,{1'b0,fpu2_id},fpu2_v,rfpu2_bus);
7125
 
7126
        // The memory address generated by the ALU should not be posted to be
7127
        // recieved into waiting argument registers. The arguments will be waiting
7128
        // for the result of the memory load, picked up from the dram busses. The
7129
        // only mem operation requiring the alu result bus is the push operation.
7130
        setargs(n,{1'b0,alu0_id},alu0_v & (~alu0_mem | alu0_push),ralu0_bus);
7131
        if (`NUM_ALU > 1)
7132
                setargs(n,{1'b0,alu1_id},alu1_v & (~alu1_mem | alu1_push),ralu1_bus);
7133
 
7134
        setargs(n,{1'b0,fcu_id},fcu_v,rfcu_bus);
7135
 
7136
        setargs(n,{1'b0,dramA_id},dramA_v,rdramA_bus);
7137
        if (`NUM_MEM > 1)
7138
                setargs(n,{1'b0,dramB_id},dramB_v,rdramB_bus);
7139
        if (`NUM_MEM > 2)
7140
                setargs(n,{1'b0,dramC_id},dramC_v,rdramC_bus);
7141
 
7142
        setargs(n,commit0_id,commit0_v,commit0_bus);
7143
        if (`NUM_CMT > 1)
7144
                setargs(n,commit1_id,commit1_v,commit1_bus);
7145
        if (`NUM_CMT > 2)
7146
                setargs(n,commit2_id,commit2_v,commit2_bus);
7147
`ifndef INLINE_DECODE
7148
        setinsn(n[`QBITS],id1_ido,id1_available&id1_vo,id1_bus);
7149
        if (`NUM_IDU > 1)
7150
                setinsn(n[`QBITS],id2_ido,id2_available&id2_vo,id2_bus);
7151
        if (`NUM_IDU > 2)
7152
                setinsn(n[`QBITS],id3_ido,id3_available&id3_vo,id3_bus);
7153
`endif
7154
end
7155
 
7156
 
7157
//
7158
// ISSUE 
7159
//
7160
// determines what instructions are ready to go, then places them
7161
// in the various ALU queues.  
7162
// also invalidates instructions following a branch-miss BEQ or any JALR (STOMP logic)
7163
//
7164
`ifndef INLINE_DECODE
7165
for (n = 0; n < QENTRIES; n = n + 1)
7166
if (id1_available) begin
7167
if (iqentry_id1issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7168
                id1_vi <= `VAL;
7169
                id1_id                  <= n[4:0];
7170
                id1_instr       <= iqentry_rtop[n] ? (
7171
                                                                                iqentry_a3_v[n] ? iqentry_a3[n]
7172
`ifdef FU_BYPASS
7173
                                : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7174
                                : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7175
`endif
7176
                                : `NOP_INSN)
7177
                                                                 : iqentry_instr[n];
7178
                id1_ven    <= iqentry_ven[n];
7179
                id1_vl     <= iqentry_vl[n];
7180
                id1_thrd   <= iqentry_thrd[n];
7181
                id1_Rt     <= iqentry_tgt[n][4:0];
7182
                id1_pt                  <= iqentry_pt[n];
7183
  end
7184
end
7185
if (`NUM_IDU > 1) begin
7186
for (n = 0; n < QENTRIES; n = n + 1)
7187
        if (id2_available) begin
7188
                if (iqentry_id2issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7189
                        id2_vi <= `VAL;
7190
                        id2_id                  <= n[4:0];
7191
                        id2_instr       <= iqentry_rtop[n] ? (
7192
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7193
`ifdef FU_BYPASS
7194
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7195
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7196
`endif
7197
                                        : `NOP_INSN)
7198
                                                                         : iqentry_instr[n];
7199
                        id2_ven    <= iqentry_ven[n];
7200
                        id2_vl     <= iqentry_vl[n];
7201
                        id2_thrd   <= iqentry_thrd[n];
7202
                        id2_Rt     <= iqentry_tgt[n][4:0];
7203
                        id2_pt                  <= iqentry_pt[n];
7204
                end
7205
        end
7206
end
7207
if (`NUM_IDU > 2) begin
7208
for (n = 0; n < QENTRIES; n = n + 1)
7209
        if (id3_available) begin
7210
                if (iqentry_id3issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7211
                        id3_vi <= `VAL;
7212
                        id3_id                  <= n[4:0];
7213
                        id3_instr       <= iqentry_rtop[n] ? (
7214
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7215
`ifdef FU_BYPASS
7216
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7217
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7218
`endif
7219
                                        : `NOP_INSN)
7220
                                                                         : iqentry_instr[n];
7221
                        id3_ven    <= iqentry_ven[n];
7222
                        id3_vl     <= iqentry_vl[n];
7223
                        id3_thrd   <= iqentry_thrd[n];
7224
                        id3_Rt     <= iqentry_tgt[n][4:0];
7225
                        id3_pt                  <= iqentry_pt[n];
7226
                end
7227
        end
7228
end
7229
`endif  // not INLINE_DECODE
7230
 
7231
// X's on unused busses cause problems in SIM.
7232
    for (n = 0; n < QENTRIES; n = n + 1)
7233
        if (iqentry_alu0_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7234
            if (alu0_available & alu0_done) begin
7235
                 alu0_sourceid  <= {iqentry_push[n],n[`QBITS]};
7236
                 alu0_instr     <= iqentry_rtop[n] ? (
7237
`ifdef FU_BYPASS
7238
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7239
                                                    : (iqentry_a3_s[n] == alu0_id) ? ralu0_bus
7240
                                                    : (iqentry_a3_s[n] == alu1_id) ? ralu1_bus
7241
                                                    : (iqentry_a3_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7242
                                                    : `NOP_INSN)
7243
`else
7244
                                                                                                                                        iqentry_a3[n])
7245
`endif
7246
                                                                         : iqentry_instr[n];
7247
                 alu0_sz    <= iqentry_sz[n];
7248
                 alu0_tlb   <= iqentry_tlb[n];
7249
                 alu0_mem   <= iqentry_mem[n];
7250
                 alu0_load  <= iqentry_load[n];
7251
                 alu0_store <= iqentry_store[n];
7252
                 alu0_push  <= iqentry_push[n];
7253
                 alu0_shft <= iqentry_shft[n];
7254
                 alu0_pc                <= iqentry_pc[n];
7255
                 alu0_argA      <=
7256
`ifdef FU_BYPASS
7257
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7258
                            : (iqentry_a1_s[n] == alu0_id) ? ralu0_bus
7259
                            : (iqentry_a1_s[n] == alu1_id) ? ralu1_bus
7260
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7261
                            : 64'hDEADDEADDEADDEAD;
7262
`else
7263
                                                                                                                iqentry_a1[n];
7264
`endif
7265
                 alu0_argB      <= iqentry_imm[n]
7266
                            ? iqentry_a0[n]
7267
`ifdef FU_BYPASS
7268
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7269
                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus
7270
                            : (iqentry_a2_s[n] == alu1_id) ? ralu1_bus
7271
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7272
                            : 64'hDEADDEADDEADDEAD);
7273
`else
7274
                                                                                                                : iqentry_a2[n];
7275
`endif
7276
                 alu0_argC      <=
7277
`ifdef FU_BYPASS
7278
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7279
                            : (iqentry_a3_s[n] == alu0_id) ? ralu0_bus : ralu1_bus;
7280
`else
7281
                                                                                                                        iqentry_a3[n];
7282
`endif
7283
                 alu0_argI      <= iqentry_a0[n];
7284
                 alu0_tgt    <= IsVeins(iqentry_instr[n]) ?
7285
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((
7286
                                                                                        iqentry_a2_v[n] ? iqentry_a2[n][5:0]
7287
                                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus[5:0]
7288
                                            : (iqentry_a2_s[n] == alu1_id) ? ralu1_bus[5:0]
7289
                                            : {4{16'h0000}})) << 6 :
7290
                                iqentry_tgt[n];
7291
                 alu0_ven    <= iqentry_ven[n];
7292
                 alu0_thrd   <= iqentry_thrd[n];
7293
                 alu0_dataready <= IsSingleCycle(iqentry_instr[n]);
7294
                 alu0_ld <= TRUE;
7295
                 iqentry_state[n] <= IQS_OUT;
7296
            end
7297
        end
7298
        if (`NUM_ALU > 1) begin
7299
    for (n = 0; n < QENTRIES; n = n + 1)
7300
        if (iqentry_alu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7301
            if (alu1_available && alu1_done) begin
7302
                        if (iqentry_alu0[n])
7303
                                panic <= `PANIC_ALU0ONLY;
7304
                 alu1_sourceid  <= {iqentry_push[n],n[`QBITS]};
7305
                 alu1_instr     <= iqentry_instr[n];
7306
                 alu1_sz    <= iqentry_sz[n];
7307
                 alu1_mem   <= iqentry_mem[n];
7308
                 alu1_load  <= iqentry_load[n];
7309
                 alu1_store <= iqentry_store[n];
7310
                 alu1_push  <= iqentry_push[n];
7311
                 alu1_shft  <= iqentry_shft[n];
7312
                 alu1_pc                <= iqentry_pc[n];
7313
                 alu1_argA      <=
7314
`ifdef FU_BYPASS
7315
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7316
                            : (iqentry_a1_s[n] == alu0_id) ? ralu0_bus
7317
                            : (iqentry_a1_s[n] == alu1_id) ? ralu1_bus
7318
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7319
                            : 64'hDEADDEADDEADDEAD;
7320
`else
7321
                                                                                                                        iqentry_a1[n];
7322
`endif
7323
                 alu1_argB      <= iqentry_imm[n]
7324
                            ? iqentry_a0[n]
7325
`ifdef FU_BYPASS
7326
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7327
                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus
7328
                            : (iqentry_a2_s[n] == alu1_id) ? ralu1_bus
7329
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7330
                            : 64'hDEADDEADDEADDEAD);
7331
`else
7332
                                                                                                                : iqentry_a2[n];
7333
`endif
7334
                 alu1_argC      <=
7335
`ifdef FU_BYPASS
7336
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7337
                            : (iqentry_a3_s[n] == alu0_id) ? ralu0_bus : ralu1_bus;
7338
`else
7339
                                                                                                                        iqentry_a3[n];
7340
`endif
7341
                 alu1_argI      <= iqentry_a0[n];
7342
                 alu1_tgt    <= IsVeins(iqentry_instr[n]) ?
7343
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((iqentry_a2_v[n] ? iqentry_a2[n][5:0]
7344
                                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus[5:0]
7345
                                            : (iqentry_a2_s[n] == alu1_id) ? ralu1_bus[5:0]
7346
                                            : {4{16'h0000}})) << 6 :
7347
                                iqentry_tgt[n];
7348
                 alu1_ven    <= iqentry_ven[n];
7349
                 alu1_dataready <= IsSingleCycle(iqentry_instr[n]);
7350
                 alu1_ld <= TRUE;
7351
                 iqentry_state[n] <= IQS_OUT;
7352
            end
7353
        end
7354
  end
7355
 
7356
    for (n = 0; n < QENTRIES; n = n + 1)
7357
        if (iqentry_fpu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7358
            if (fpu1_available & fpu1_done) begin
7359
                 fpu1_sourceid  <= n[`QBITS];
7360
                 fpu1_instr     <= iqentry_instr[n];
7361
                 fpu1_pc                <= iqentry_pc[n];
7362
                 fpu1_argA      <=
7363
`ifdef FU_BYPASS
7364
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7365
                            : (iqentry_a1_s[n] == alu0_id) ? ralu0_bus
7366
                            : (iqentry_a1_s[n] == alu1_id) ? ralu1_bus
7367
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7368
                            : 64'hDEADDEADDEADDEAD;
7369
`else
7370
                                                                                                                        iqentry_a1[n];
7371
`endif
7372
                 fpu1_argB      <=
7373
`ifdef FU_BYPASS
7374
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
7375
                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus
7376
                            : (iqentry_a2_s[n] == alu1_id) ? ralu1_bus
7377
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7378
                            : 64'hDEADDEADDEADDEAD);
7379
`else
7380
                                                                                                                        iqentry_a2[n];
7381
`endif
7382
                 fpu1_argC      <=
7383
`ifdef FU_BYPASS
7384
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
7385
                            : (iqentry_a3_s[n] == alu0_id) ? ralu0_bus : ralu1_bus;
7386
`else
7387
                                                                                                                        iqentry_a3[n];
7388
`endif
7389
                 fpu1_argI      <= iqentry_a0[n];
7390
                 fpu1_dataready <= `VAL;
7391
                 fpu1_ld <= TRUE;
7392
                 iqentry_state[n] <= IQS_OUT;
7393
            end
7394
        end
7395
 
7396
    for (n = 0; n < QENTRIES; n = n + 1)
7397
        if (`NUM_FPU > 1 && iqentry_fpu2_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7398
            if (fpu2_available & fpu2_done) begin
7399
                 fpu2_sourceid  <= n[`QBITS];
7400
                 fpu2_instr     <= iqentry_instr[n];
7401
                 fpu2_pc                <= iqentry_pc[n];
7402
                 fpu2_argA      <=
7403
`ifdef FU_BYPASS
7404
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7405
                            : (iqentry_a1_s[n] == alu0_id) ? ralu0_bus
7406
                            : (iqentry_a1_s[n] == alu1_id) ? ralu1_bus
7407
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7408
                            : 64'hDEADDEADDEADDEAD;
7409
`else
7410
                                                                                                                        iqentry_a1[n];
7411
`endif
7412
                 fpu2_argB      <=
7413
`ifdef FU_BYPASS
7414
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
7415
                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus
7416
                            : (iqentry_a2_s[n] == alu1_id) ? ralu1_bus
7417
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7418
                            : 64'hDEADDEADDEADDEAD);
7419
`else
7420
                                                                                                                        iqentry_a2[n];
7421
`endif
7422
                 fpu2_argC      <=
7423
`ifdef FU_BYPASS
7424
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
7425
                            : (iqentry_a3_s[n] == alu0_id) ? ralu0_bus : ralu1_bus;
7426
`else
7427
                                                                                                                        iqentry_a3[n];
7428
`endif
7429
                 fpu2_argI      <= iqentry_a0[n];
7430
                 fpu2_dataready <= `VAL;
7431
                 fpu2_ld <= TRUE;
7432
                 iqentry_state[n] <= IQS_OUT;
7433
            end
7434
        end
7435
 
7436
    for (n = 0; n < QENTRIES; n = n + 1)
7437
        if (iqentry_fcu_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7438
            if (fcu_done) begin
7439
                 fcu_sourceid   <= n[`QBITS];
7440
                 fcu_prevInstr <= fcu_instr;
7441
                 fcu_instr      <= iqentry_instr[n];
7442
                 fcu_insln  <= iqentry_insln[n];
7443
                 fcu_pc         <= iqentry_pc[n];
7444
                 fcu_nextpc <= iqentry_pc[n] + iqentry_insln[n];
7445
                 fcu_pt     <= iqentry_pt[n];
7446 61 robfinch
                 fcu_brdisp <= iqentry_instr[n][6] ? {{36{iqentry_instr[n][47]}},iqentry_instr[n][47:23],iqentry_instr[n][17:16],1'b0}
7447
                                                                         : {{52{iqentry_instr[n][31]}},iqentry_instr[n][31:23],iqentry_instr[n][17:16],1'b0};
7448 60 robfinch
                 fcu_branch <= iqentry_br[n];
7449
                 fcu_call    <= IsCall(iqentry_instr[n])|iqentry_jal[n];
7450
                 fcu_jal     <= iqentry_jal[n];
7451
                 fcu_ret    <= iqentry_ret[n];
7452
                 fcu_brk  <= iqentry_brk[n];
7453
                 fcu_rti  <= iqentry_rti[n];
7454
                 fcu_pc         <= iqentry_pc[n];
7455
                 fcu_argA       <= iqentry_a1_v[n] ? iqentry_a1[n]
7456
                            : (iqentry_a1_s[n] == alu0_id) ? ralu0_bus
7457
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7458
                            : ralu1_bus;
7459
`ifdef SUPPORT_SMT
7460 61 robfinch
//                 fcu_argB     <= iqentry_rti[n] ? epc0[iqentry_thrd[n]]
7461
                 fcu_epc  <= epc0[iqentry_thrd[n]];
7462 60 robfinch
`else
7463 61 robfinch
                                                                 fcu_epc  <= epc0;
7464
//                 fcu_argB     <= iqentry_rti[n] ? epc0
7465 60 robfinch
`endif
7466 61 robfinch
                                                                        fcu_argB        <=
7467
                                          (iqentry_a2_v[n] ? iqentry_a2[n]
7468 60 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus
7469
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7470
                            : ralu1_bus);
7471
                 // argB
7472
                 waitctr  <=  (iqentry_a2_v[n] ? iqentry_a2[n][47:0]
7473
                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus[47:0]
7474
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus[47:0]
7475
                            : ralu1_bus[47:0]);
7476
                 fcu_argC       <= iqentry_a3_v[n] ? iqentry_a3[n]
7477
                            : (iqentry_a3_s[n] == alu0_id) ? ralu0_bus : ralu1_bus;
7478
                 fcu_argI       <= iqentry_a0[n];
7479
                 fcu_thrd   <= iqentry_thrd[n];
7480
                 fcu_dataready <= !IsWait(iqentry_instr[n]);
7481
                 fcu_clearbm <= `FALSE;
7482
                 fcu_ld <= TRUE;
7483
                 fcu_timeout <= 8'h00;
7484
                 iqentry_state[n] <= IQS_OUT;
7485
                 fcu_done <= `FALSE;
7486
            end
7487
        end
7488
//
7489
// MEMORY
7490
//
7491
// update the memory queues and put data out on bus if appropriate
7492
//
7493
 
7494
//
7495
// dram0, dram1, dram2 are the "state machines" that keep track
7496
// of three pipelined DRAM requests.  if any has the value "000", 
7497
// then it can accept a request (which bumps it up to the value "001"
7498
// at the end of the cycle).  once it hits the value "111" the request
7499
// is finished and the dram_bus takes the value.  if it is a store, the 
7500
// dram_bus value is not used, but the dram_v value along with the
7501
// dram_id value signals the waiting memq entry that the store is
7502
// completed and the instruction can commit.
7503
//
7504
 
7505
//      if (dram0 != `DRAMSLOT_AVAIL)   dram0 <= dram0 + 2'd1;
7506
//      if (dram1 != `DRAMSLOT_AVAIL)   dram1 <= dram1 + 2'd1;
7507
//      if (dram2 != `DRAMSLOT_AVAIL)   dram2 <= dram2 + 2'd1;
7508
 
7509
// Flip the ready status to available. Used for loads or stores.
7510
 
7511
if (dram0 == `DRAMREQ_READY)
7512
        dram0 <= `DRAMSLOT_AVAIL;
7513
if (dram1 == `DRAMREQ_READY && `NUM_MEM > 1)
7514
        dram1 <= `DRAMSLOT_AVAIL;
7515
if (dram2 == `DRAMREQ_READY && `NUM_MEM > 2)
7516
        dram2 <= `DRAMSLOT_AVAIL;
7517
 
7518
// grab requests that have finished and put them on the dram_bus
7519 61 robfinch
// If stomping on the instruction don't place the value on the argument
7520
// bus to be loaded.
7521 60 robfinch
if (dram0 == `DRAMREQ_READY && dram0_load) begin
7522 61 robfinch
        dramA_v <= !iqentry_stomp[dram0_id[`QBITS]];
7523 60 robfinch
        dramA_id <= dram0_id;
7524
        dramA_bus <= fnDatiAlign(dram0_instr,dram0_addr,rdat0);
7525
end
7526
if (dram1 == `DRAMREQ_READY && dram1_load && `NUM_MEM > 1) begin
7527 61 robfinch
        dramB_v <= !iqentry_stomp[dram1_id[`QBITS]];
7528 60 robfinch
        dramB_id <= dram1_id;
7529
        dramB_bus <= fnDatiAlign(dram1_instr,dram1_addr,rdat1);
7530
end
7531
if (dram2 == `DRAMREQ_READY && dram2_load && `NUM_MEM > 2) begin
7532 61 robfinch
        dramC_v <= !iqentry_stomp[dram2_id[`QBITS]];
7533 60 robfinch
        dramC_id <= dram2_id;
7534
        dramC_bus <= fnDatiAlign(dram2_instr,dram2_addr,rdat2);
7535
end
7536
 
7537
if (dram0 == `DRAMREQ_READY && dram0_store)
7538
        $display("m[%h] <- %h", dram0_addr, dram0_data);
7539
if (dram1 == `DRAMREQ_READY && dram1_store && `NUM_MEM > 1)
7540
        $display("m[%h] <- %h", dram1_addr, dram1_data);
7541
if (dram2 == `DRAMREQ_READY && dram2_store && `NUM_MEM > 2)
7542
        $display("m[%h] <- %h", dram2_addr, dram2_data);
7543
 
7544
//
7545
// determine if the instructions ready to issue can, in fact, issue.
7546
// "ready" means that the instruction has valid operands but has not gone yet
7547 61 robfinch
for (n = 0; n < QENTRIES; n = n + 1)
7548
if (memissue[n])
7549
        iqentry_memissue[n] <= `VAL;
7550
//iqentry_memissue <= memissue;
7551 60 robfinch
missue_count <= issue_count;
7552
 
7553
for (n = 0; n < QENTRIES; n = n + 1)
7554
        if (iqentry_v[n] && iqentry_stomp[n]) begin
7555
                iqentry_iv[n] <= `INV;
7556
                iqentry_mem[n] <= `INV;
7557
                iqentry_load[n] <= `INV;
7558
                iqentry_store[n] <= `INV;
7559
                iqentry_state[n] <= IQS_INVALID;
7560
//              iqentry_agen[n] <= `INV;
7561
//              iqentry_out[n] <= `INV;
7562
//              iqentry_done[n] <= `INV;
7563
//              iqentry_cmt[n] <= `INV;
7564
        end
7565
 
7566 61 robfinch
// A store can't be stomped on, because a store won't issue unless there are
7567
// no instructions that could change the flow of execution before it. Meaning
7568
// stomp would never be true for a store.
7569
// A load could be stomped on, but the memory access is allowed to complete
7570
// to ensure the bus acknowledge doesn't get out of sync.
7571
/*
7572
if (iqentry_stomp[dram0_id[`QBITS]])  begin
7573
        if (dram0==`DRAMSLOT_HASBUS)
7574
                wb_nack();
7575
        dram0_load <= `FALSE;
7576
        dram0_store <= `FALSE;
7577
        dram0_rmw <= `FALSE;
7578
        dram0 <= `DRAMSLOT_AVAIL;
7579
end
7580
if (iqentry_stomp[dram1_id[`QBITS]])  begin
7581
        if (dram1==`DRAMSLOT_HASBUS)
7582
                wb_nack();
7583
        dram1_load <= `FALSE;
7584
        dram1_store <= `FALSE;
7585
        dram1_rmw <= `FALSE;
7586
        dram1 <= `DRAMSLOT_AVAIL;
7587
end
7588
if (iqentry_stomp[dram2_id[`QBITS]])  begin
7589
        if (dram2==`DRAMSLOT_HASBUS)
7590
                wb_nack();
7591
        dram2_load <= `FALSE;
7592
        dram2_store <= `FALSE;
7593
        dram2_rmw <= `FALSE;
7594
        dram2 <= `DRAMSLOT_AVAIL;
7595
end
7596
*/
7597
 
7598 60 robfinch
if (last_issue0 < QENTRIES)
7599
        tDram0Issue(last_issue0);
7600
if (last_issue1 < QENTRIES)
7601
        tDram1Issue(last_issue1);
7602
if (last_issue2 < QENTRIES)
7603
        tDram2Issue(last_issue2);
7604
 
7605
 
7606
//for (n = 0; n < QENTRIES; n = n + 1)
7607
//begin
7608
//      if (!iqentry_v[n])
7609
//              iqentry_done[n] <= FALSE;
7610
//end
7611
 
7612
if (ohead[0]==heads[0])
7613
        cmt_timer <= cmt_timer + 12'd1;
7614
else
7615
        cmt_timer <= 12'd0;
7616
 
7617 61 robfinch
if (cmt_timer==12'd1000 && icstate==IDLE) begin
7618 60 robfinch
        iqentry_state[heads[0]] <= IQS_CMT;
7619
        iqentry_exc[heads[0]] <= `FLT_CMT;
7620
        cmt_timer <= 12'd0;
7621
end
7622
 
7623
//
7624
// COMMIT PHASE (dequeue only ... not register-file update)
7625
//
7626
// look at heads[0] and heads[1] and let 'em write to the register file if they are ready
7627
//
7628
//    always @(posedge clk) begin: commit_phase
7629
ohead[0] <= heads[0];
7630
ohead[1] <= heads[1];
7631
ohead[2] <= heads[2];
7632
ocommit0_v <= commit0_v;
7633
ocommit1_v <= commit1_v;
7634
ocommit2_v <= commit2_v;
7635
 
7636
oddball_commit(commit0_v, heads[0], 2'd0);
7637
if (`NUM_CMT > 1)
7638
        oddball_commit(commit1_v, heads[1], 2'd1);
7639
if (`NUM_CMT > 2)
7640
        oddball_commit(commit2_v, heads[2], 2'd2);
7641
 
7642
// Fetch and queue are limited to two instructions per cycle, so we might as
7643
// well limit retiring to two instructions max to conserve logic.
7644
//
7645
if (~|panic)
7646
  casez ({ iqentry_v[heads[0]],
7647
                iqentry_state[heads[0]] == IQS_CMT,
7648
                iqentry_v[heads[1]],
7649
                iqentry_state[heads[1]] == IQS_CMT,
7650
                iqentry_v[heads[2]],
7651
                iqentry_state[heads[2]] == IQS_CMT})
7652
 
7653
        // retire 3
7654
        6'b0?_0?_0?:
7655
                if (heads[0] != tail0 && heads[1] != tail0 && heads[2] != tail0)
7656
                        head_inc(3);
7657
                else if (heads[0] != tail0 && heads[1] != tail0)
7658
            head_inc(2);
7659
                else if (heads[0] != tail0)
7660
            head_inc(1);
7661
        6'b0?_0?_10:
7662
                if (heads[0] != tail0 && heads[1] != tail0)
7663
                        head_inc(2);
7664
                else if (heads[0] != tail0)
7665
                        head_inc(1);
7666
        6'b0?_0?_11:
7667
                if (`NUM_CMT > 2 || cmt_head2)  // and it's not an oddball?
7668
      head_inc(3);
7669
                else
7670
      head_inc(2);
7671
 
7672
        // retire 1 (wait for regfile for heads[1])
7673
        6'b0?_10_??:
7674
                head_inc(1);
7675
 
7676
        // retire 2
7677
        6'b0?_11_0?,
7678
        6'b0?_11_10:
7679
    if (`NUM_CMT > 1 || cmt_head1)
7680
      head_inc(2);
7681
    else
7682
        head_inc(1);
7683
  6'b0?_11_11:
7684
    if (`NUM_CMT > 2 || (`NUM_CMT > 1 && cmt_head2))
7685
        head_inc(3);
7686
        else if (`NUM_CMT > 1 || cmt_head1)
7687
        head_inc(2);
7688
        else
7689
                head_inc(1);
7690
  6'b10_??_??:  ;
7691
  6'b11_0?_0?:
7692
        if (heads[1] != tail0 && heads[2] != tail0)
7693
                        head_inc(3);
7694
        else if (heads[1] != tail0)
7695
                        head_inc(2);
7696
        else
7697
                        head_inc(1);
7698
  6'b11_0?_10:
7699
        if (heads[1] != tail0)
7700
                        head_inc(2);
7701
        else
7702
                        head_inc(1);
7703
  6'b11_0?_11:
7704
        if (heads[1] != tail0) begin
7705
                if (`NUM_CMT > 2 || cmt_head2)
7706
                                head_inc(3);
7707
                else
7708
                                head_inc(2);
7709
        end
7710
        else
7711
                        head_inc(1);
7712
  6'b11_10_??:
7713
                        head_inc(1);
7714
  6'b11_11_0?:
7715
        if (`NUM_CMT > 1 && heads[2] != tail0)
7716
                        head_inc(3);
7717
        else if (cmt_head1 && heads[2] != tail0)
7718
                        head_inc(3);
7719
                else if (`NUM_CMT > 1 || cmt_head1)
7720
                        head_inc(2);
7721
        else
7722
                        head_inc(1);
7723
  6'b11_11_10:
7724
                if (`NUM_CMT > 1 || cmt_head1)
7725
                        head_inc(2);
7726
        else
7727
                        head_inc(1);
7728
        6'b11_11_11:
7729
                if (`NUM_CMT > 2 || (`NUM_CMT > 1 && cmt_head2))
7730
                        head_inc(3);
7731
                else if (`NUM_CMT > 1 || cmt_head1)
7732
                        head_inc(2);
7733
                else
7734
                        head_inc(1);
7735
        default:
7736
                begin
7737
                        $display("head_inc: Uncoded case %h",{ iqentry_v[heads[0]],
7738
                                iqentry_state[heads[0]],
7739
                                iqentry_v[heads[1]],
7740
                                iqentry_state[heads[1]],
7741
                                iqentry_v[heads[2]],
7742
                                iqentry_state[heads[2]]});
7743
                        $stop;
7744
                end
7745
  endcase
7746
 
7747
 
7748
rf_source[0] <= 0;
7749
L1_wr0 <= FALSE;
7750
L1_wr1 <= FALSE;
7751
L1_wr2 <= FALSE;
7752 61 robfinch
L1_en <= 10'h000;
7753 60 robfinch
L1_invline <= FALSE;
7754
icnxt <= FALSE;
7755
L2_nxt <= FALSE;
7756
// Instruction cache state machine.
7757
// On a miss first see if the instruction is in the L2 cache. No need to go to
7758
// the BIU on an L1 miss.
7759
// If not the machine will wait until the BIU loads the L2 cache.
7760
 
7761
// Capture the previous ic state, used to determine how long to wait in
7762
// icstate #4.
7763
picstate <= icstate;
7764
case(icstate)
7765
IDLE:
7766
        // If the bus unit is busy doing an update involving L1_adr or L2_adr
7767
        // we have to wait.
7768
        if (bstate != B_ICacheAck && bstate != B_ICacheNack && bstate != B_ICacheNack2) begin
7769
                if (!ihit0) begin
7770
                        L1_adr <= {pcr[7:0],pc0[AMSB:5],5'h0};
7771
                        L2_adr <= {pcr[7:0],pc0[AMSB:5],5'h0};
7772
                        L1_invline <= TRUE;
7773
                        icwhich <= 2'b00;
7774
                        iccnt <= 3'b00;
7775
                        icstate <= IC2;
7776
                end
7777
                else if (!ihit1 && `WAYS > 1) begin
7778
                        if (thread_en) begin
7779
                                L1_adr <= {pcr[7:0],pc1[AMSB:5],5'h0};
7780
                                L2_adr <= {pcr[7:0],pc1[AMSB:5],5'h0};
7781
                        end
7782
                        else begin
7783
                                L1_adr <= {pcr[7:0],pc0plus6[AMSB:5],5'h0};
7784
                                L2_adr <= {pcr[7:0],pc0plus6[AMSB:5],5'h0};
7785
                        end
7786
                        L1_invline <= TRUE;
7787
                        icwhich <= 2'b01;
7788
                        iccnt <= 3'b00;
7789
                        icstate <= IC2;
7790
                end
7791
                else if (!ihit2 && `WAYS > 2) begin
7792
                        if (thread_en) begin
7793
                                L1_adr <= {pcr[7:0],pc2[AMSB:5],5'h0};
7794
                                L2_adr <= {pcr[7:0],pc2[AMSB:5],5'h0};
7795
                        end
7796
                        else begin
7797
                                L1_adr <= {pcr[7:0],pc0plus12[AMSB:5],5'h0};
7798
                                L2_adr <= {pcr[7:0],pc0plus12[AMSB:5],5'h0};
7799
                        end
7800
                        L1_invline <= TRUE;
7801
                        icwhich <= 2'b10;
7802
                        iccnt <= 3'b00;
7803
                        icstate <= IC2;
7804
                end
7805
        end
7806
IC2:     icstate <= IC3;
7807
IC3:     icstate <= IC3a;
7808
IC3a:     icstate <= IC_WaitL2;
7809
// If data was in the L2 cache already there's no need to wait on the
7810
// BIU to retrieve data. It can be determined if the hit signal was
7811
// already active when this state was entered in which case waiting
7812
// will do no good.
7813
// The IC machine will stall in this state until the BIU has loaded the
7814
// L2 cache. 
7815
IC_WaitL2:
7816
        if (ihitL2 && picstate==IC3a) begin
7817 61 robfinch
                L1_en <= 10'h3FF;
7818 60 robfinch
                L1_wr0 <= TRUE;
7819
                L1_wr1 <= TRUE && `WAYS > 1;
7820
                L1_wr2 <= TRUE && `WAYS > 2;
7821 61 robfinch
//              L1_adr <= L2_adr;
7822
                // L1_dati is loaded dring an L2 icache load operation
7823
//              if (picstate==IC3a)
7824
                L1_dati <= L2_dato;
7825 60 robfinch
                icstate <= IC5;
7826
        end
7827
        else if (bstate!=B_ICacheNack)
7828
                ;
7829
        else begin
7830 61 robfinch
                L1_en <= 10'h3FF;
7831 60 robfinch
                L1_wr0 <= TRUE;
7832
                L1_wr1 <= TRUE && `WAYS > 1;
7833
                L1_wr2 <= TRUE && `WAYS > 2;
7834 61 robfinch
//              L1_adr <= L2_adr;
7835
                // L1_dati set below while loading cache line
7836
                //L1_dati <= L2_dato;
7837 60 robfinch
                icstate <= IC5;
7838
        end
7839 61 robfinch
 
7840
IC5:    icstate <= IC6;
7841 60 robfinch
IC6:  icstate <= IC7;
7842
IC7:    icstate <= IC_Next;
7843
IC_Next:
7844
  begin
7845
   icstate <= IDLE;
7846
   icnxt <= TRUE;
7847
        end
7848
default:     icstate <= IDLE;
7849
endcase
7850
 
7851 61 robfinch
if (dram0_load)
7852 60 robfinch
case(dram0)
7853
`DRAMSLOT_AVAIL:        ;
7854
`DRAMSLOT_BUSY:
7855
//      if (iqentry_v[dram0_id[`QBITS]] && !iqentry_stomp[dram0_id[`QBITS]])
7856
                dram0 <= dram0 + !dram0_unc;
7857
//      else begin
7858
//              dram0 <= `DRAMSLOT_AVAIL;
7859
//              dram0_load <= `FALSE;
7860
//      end
7861
3'd2:
7862
//      if (iqentry_v[dram0_id[`QBITS]] && !iqentry_stomp[dram0_id[`QBITS]])
7863
                dram0 <= dram0 + 3'd1;
7864
//      else begin
7865
//              dram0 <= `DRAMSLOT_AVAIL;
7866
//              dram0_load <= `FALSE;
7867
//      end
7868
3'd3:
7869
//      if (iqentry_v[dram0_id[`QBITS]] && !iqentry_stomp[dram0_id[`QBITS]])
7870
                dram0 <= dram0 + 3'd1;
7871
//      else begin
7872
//              dram0 <= `DRAMSLOT_AVAIL;
7873
//              dram0_load <= `FALSE;
7874
//      end
7875
3'd4:
7876 61 robfinch
//      if (iqentry_v[dram0_id[`QBITS]] && !iqentry_stomp[dram0_id[`QBITS]]) begin
7877 60 robfinch
                if (dhit0)
7878
                        dram0 <= `DRAMREQ_READY;
7879
                else
7880
                        dram0 <= `DRAMSLOT_REQBUS;
7881 61 robfinch
//      end
7882
//      else begin
7883
//              dram0 <= `DRAMSLOT_AVAIL;
7884
//              dram0_load <= `FALSE;
7885
//      end
7886 60 robfinch
`DRAMSLOT_REQBUS:       ;
7887
`DRAMSLOT_HASBUS:       ;
7888
`DRAMREQ_READY:         dram0 <= `DRAMSLOT_AVAIL;
7889
endcase
7890
 
7891 61 robfinch
if (dram1_load && `NUM_MEM > 1)
7892 60 robfinch
case(dram1)
7893
`DRAMSLOT_AVAIL:        ;
7894
`DRAMSLOT_BUSY:
7895
        dram1 <= dram1 + !dram1_unc;
7896
3'd2:
7897
        dram1 <= dram1 + 3'd1;
7898
3'd3:
7899
        dram1 <= dram1 + 3'd1;
7900
3'd4:
7901 61 robfinch
//      if (iqentry_v[dram1_id[`QBITS]] && !iqentry_stomp[dram1_id[`QBITS]]) begin
7902 60 robfinch
                if (dhit1)
7903
                        dram1 <= `DRAMREQ_READY;
7904
                else
7905
                        dram1 <= `DRAMSLOT_REQBUS;
7906 61 robfinch
//      end
7907
/*      else begin
7908 60 robfinch
                dram1 <= `DRAMSLOT_AVAIL;
7909
                dram1_load <= `FALSE;
7910 61 robfinch
        end*/
7911 60 robfinch
`DRAMSLOT_REQBUS:       ;
7912
`DRAMSLOT_HASBUS:       ;
7913
`DRAMREQ_READY:         dram1 <= `DRAMSLOT_AVAIL;
7914
endcase
7915
 
7916 61 robfinch
if (dram2_load && `NUM_MEM > 2)
7917 60 robfinch
case(dram2)
7918
`DRAMSLOT_AVAIL:        ;
7919
`DRAMSLOT_BUSY:
7920
        dram2 <= dram2 + !dram2_unc;
7921
3'd2:
7922
        dram2 <= dram2 + 3'd1;
7923
3'd3:
7924
        dram2 <= dram2 + 3'd1;
7925
3'd4:
7926 61 robfinch
//      if (iqentry_v[dram2_id[`QBITS]] && !iqentry_stomp[dram2_id[`QBITS]]) begin
7927 60 robfinch
                if (dhit2)
7928
                        dram2 <= `DRAMREQ_READY;
7929
                else
7930
                        dram2 <= `DRAMSLOT_REQBUS;
7931 61 robfinch
//      end
7932
/*      else begin
7933 60 robfinch
                dram2 <= `DRAMSLOT_AVAIL;
7934
                dram2_load <= `FALSE;
7935 61 robfinch
        end*/
7936 60 robfinch
`DRAMSLOT_REQBUS:       ;
7937
`DRAMSLOT_HASBUS:       ;
7938
`DRAMREQ_READY:         dram2 <= `DRAMSLOT_AVAIL;
7939
endcase
7940
 
7941
 
7942
// Bus Interface Unit (BIU)
7943
// Interfaces to the external bus which is WISHBONE compatible.
7944
// Stores take precedence over other operations.
7945
// Next data cache read misses are serviced.
7946
// Uncached data reads are serviced.
7947
// Finally L2 instruction cache misses are serviced.//
7948
// set the IQ entry == DONE as soon as the SW is let loose to the memory system
7949
//
7950
`ifndef HAS_WB
7951
if (mem1_available && dram0 == `DRAMSLOT_BUSY && dram0_store) begin
7952
        if ((alu0_v && (dram0_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram0_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
7953
//      iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
7954
//      iqentry_out[ dram0_id[`QBITS] ] <= `INV;
7955
        iqentry_state[ dram0_id[`QBITS] ] <= IQS_DONE;
7956
end
7957
if (mem2_available && `NUM_MEM > 1 && dram1 == `DRAMSLOT_BUSY && dram1_store) begin
7958
        if ((alu0_v && (dram1_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram1_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
7959
        iqentry_state[ dram1_id[`QBITS] ] <= IQS_DONE;
7960
end
7961
if (mem3_available && `NUM_MEM > 2 && dram2 == `DRAMSLOT_BUSY && dram2_store) begin
7962
        if ((alu0_v && (dram2_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram2_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
7963
        iqentry_state[ dram2_id[`QBITS] ] <= IQS_DONE;
7964
end
7965
`endif
7966
 
7967
`ifdef HAS_WB
7968 61 robfinch
  if (dram0==`DRAMSLOT_BUSY && dram0_store) begin
7969 60 robfinch
                if (wbptr<`WB_DEPTH-1) begin
7970
                        dram0 <= `DRAMSLOT_AVAIL;
7971
                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
7972
                        wb_update(
7973
                                dram0_id,
7974
                                `FALSE,
7975
                                fnSelect(dram0_instr,dram0_addr),
7976
                                dram0_ol,
7977
                                dram0_addr,
7978
                                fnDato(dram0_instr,dram0_data)
7979
                        );
7980
//                      iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
7981
//                      iqentry_out[ dram0_id[`QBITS] ] <= `INV;
7982
                        iqentry_state[ dram0_id[`QBITS] ] <= IQS_DONE;
7983
                end
7984
  end
7985 61 robfinch
  else if (dram1==`DRAMSLOT_BUSY && dram1_store && `NUM_MEM > 1) begin
7986 60 robfinch
                if (wbptr<`WB_DEPTH-1) begin
7987
                        dram1 <= `DRAMSLOT_AVAIL;
7988
      dram1_instr[`INSTRUCTION_OP] <= `NOP;
7989
                        wb_update(
7990
                                dram1_id,
7991
                                `FALSE,
7992
                                fnSelect(dram1_instr,dram1_addr),
7993
                                dram1_ol,
7994
                                dram1_addr,
7995
                                fnDato(dram1_instr,dram1_data)
7996
                        );
7997
                        iqentry_state[ dram1_id[`QBITS] ] <= IQS_DONE;
7998
                end
7999
  end
8000 61 robfinch
  else if (dram2==`DRAMSLOT_BUSY && dram2_store && `NUM_MEM > 2) begin
8001 60 robfinch
                if (wbptr<`WB_DEPTH-1) begin
8002
                        dram2 <= `DRAMSLOT_AVAIL;
8003
      dram2_instr[`INSTRUCTION_OP] <= `NOP;
8004
                        wb_update(
8005
                                dram2_id,
8006
                                `FALSE,
8007
                                fnSelect(dram2_instr,dram2_addr),
8008
                                dram2_ol,
8009
                                dram2_addr,
8010
                                fnDato(dram2_instr,dram2_data)
8011
                        );
8012
                        iqentry_state[ dram2_id[`QBITS] ] <= IQS_DONE;
8013
                end
8014
  end
8015
`endif
8016
 
8017
case(bstate)
8018
BIDLE:
8019
        begin
8020
                isCAS <= FALSE;
8021
                isAMO <= FALSE;
8022
                isInc <= FALSE;
8023
                isSpt <= FALSE;
8024
                isRMW <= FALSE;
8025
                rdvq <= 1'b0;
8026
                errq <= 1'b0;
8027
                exvq <= 1'b0;
8028
                bwhich <= 2'b00;
8029
                preload <= FALSE;
8030
`ifdef HAS_WB
8031
                if (wb_v[0] & wb_en & ~acki & ~cyc) begin
8032
                        cyc <= `HIGH;
8033
                        stb_o <= `HIGH;
8034
                        we <= `HIGH;
8035
                        sel_o <= wb_sel[0];
8036
                        vadr <= wb_addr[0];
8037
                        dat_o <= wb_data[0];
8038
                        ol_o  <= wb_ol[0];
8039
                        wbo_id <= wb_id[0];
8040
        isStore <= TRUE;
8041
                        bstate <= wb_rmw[0] ? B12 : B_StoreAck;
8042
                        wb_v[0] <= `INV;
8043
                end
8044
                if (wb_v[0]==`INV && !writing_wb) begin
8045
                        for (j = 1; j < `WB_DEPTH; j = j + 1) begin
8046
                wb_v[j-1] <= wb_v[j];
8047
                wb_id[j-1] <= wb_id[j];
8048
                wb_rmw[j-1] <= wb_rmw[j];
8049
                wb_sel[j-1] <= wb_sel[j];
8050
                wb_addr[j-1] <= wb_addr[j];
8051
                wb_data[j-1] <= wb_data[j];
8052
                wb_ol[j-1] <= wb_ol[j];
8053
                if (wbptr > 2'd0)
8054
                        wbptr <= wbptr - 2'd1;
8055
        end
8056
        wb_v[`WB_DEPTH-1] <= `INV;
8057
        wb_rmw[`WB_DEPTH-1] <= `FALSE;
8058
    end
8059
 
8060
`endif
8061 61 robfinch
      if (~|wb_v && dram0==`DRAMSLOT_BUSY && dram0_rmw) begin
8062 60 robfinch
`ifdef SUPPORT_DBG
8063
            if (dbg_smatch0|dbg_lmatch0) begin
8064
                 dramA_v <= `TRUE;
8065
                 dramA_id <= dram0_id;
8066
                 dramA_bus <= 64'h0;
8067 61 robfinch
                 iqentry_exc[dram0_id[`QBITS]] <= `FLT_DBG;
8068 60 robfinch
                 dram0 <= `DRAMSLOT_AVAIL;
8069
            end
8070
            else
8071
`endif
8072
            if (!acki) begin
8073
                 isRMW <= dram0_rmw;
8074
                 isCAS <= IsCAS(dram0_instr);
8075
                 isAMO <= IsAMO(dram0_instr);
8076
                 isInc <= IsInc(dram0_instr);
8077
                 casid <= dram0_id;
8078
                 bwhich <= 2'b00;
8079
                 dram0 <= `DRAMSLOT_HASBUS;
8080
                 cyc <= `HIGH;
8081
                 stb_o <= `HIGH;
8082
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
8083
                 vadr <= dram0_addr;
8084
                 dat_o <= fnDato(dram0_instr,dram0_data);
8085
                 ol_o  <= dram0_ol;
8086
                 bstate <= B12;
8087
            end
8088
        end
8089 61 robfinch
        else if (~|wb_v && dram1==`DRAMSLOT_BUSY && dram1_rmw && `NUM_MEM > 1) begin
8090 60 robfinch
`ifdef SUPPORT_DBG
8091
            if (dbg_smatch1|dbg_lmatch1) begin
8092
                 dramB_v <= `TRUE;
8093
                 dramB_id <= dram1_id;
8094
                 dramB_bus <= 64'h0;
8095 61 robfinch
                 iqentry_exc[dram1_id[`QBITS]] <= `FLT_DBG;
8096 60 robfinch
                 dram1 <= `DRAMSLOT_AVAIL;
8097
            end
8098
            else
8099
`endif
8100
            if (!acki) begin
8101
                 isRMW <= dram1_rmw;
8102
                 isCAS <= IsCAS(dram1_instr);
8103
                 isAMO <= IsAMO(dram1_instr);
8104
                 isInc <= IsInc(dram1_instr);
8105
                 casid <= dram1_id;
8106
                 bwhich <= 2'b01;
8107
                 dram1 <= `DRAMSLOT_HASBUS;
8108
                 cyc <= `HIGH;
8109
                 stb_o <= `HIGH;
8110
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
8111
                 vadr <= dram1_addr;
8112
                 dat_o <= fnDato(dram1_instr,dram1_data);
8113
                 ol_o  <= dram1_ol;
8114
                 bstate <= B12;
8115
            end
8116
        end
8117 61 robfinch
        else if (~|wb_v && dram2==`DRAMSLOT_BUSY && dram2_rmw && `NUM_MEM > 2) begin
8118 60 robfinch
`ifdef SUPPORT_DBG
8119
            if (dbg_smatch2|dbg_lmatch2) begin
8120
                 dramC_v <= `TRUE;
8121
                 dramC_id <= dram2_id;
8122
                 dramC_bus <= 64'h0;
8123 61 robfinch
                 iqentry_exc[dram2_id[`QBITS]] <= `FLT_DBG;
8124 60 robfinch
                 dram2 <= `DRAMSLOT_AVAIL;
8125
            end
8126
            else
8127
`endif
8128
            if (!acki) begin
8129
                 isRMW <= dram2_rmw;
8130
                 isCAS <= IsCAS(dram2_instr);
8131
                 isAMO <= IsAMO(dram2_instr);
8132
                 isInc <= IsInc(dram2_instr);
8133
                 casid <= dram2_id;
8134
                 bwhich <= 2'b10;
8135
                 dram2 <= `DRAMSLOT_HASBUS;
8136
                 cyc <= `HIGH;
8137
                 stb_o <= `HIGH;
8138
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
8139
                 vadr <= dram2_addr;
8140
                 dat_o <= fnDato(dram2_instr,dram2_data);
8141
                 ol_o  <= dram2_ol;
8142
                 bstate <= B12;
8143
            end
8144
        end
8145
`ifndef HAS_WB
8146
                                // Check write buffer enable ?
8147 61 robfinch
        else if (dram0==`DRAMSLOT_BUSY && dram0_store) begin
8148 60 robfinch
`ifdef SUPPORT_DBG
8149
            if (dbg_smatch0) begin
8150
                 dramA_v <= `TRUE;
8151
                 dramA_id <= dram0_id;
8152
                 dramA_bus <= 64'h0;
8153 61 robfinch
                 iqentry_exc[dram0_id[`QBITS]] <= `FLT_DBG;
8154 60 robfinch
                 dram0 <= `DRAMSLOT_AVAIL;
8155
            end
8156
            else
8157
`endif
8158
            begin
8159
                                                        bwhich <= 2'b00;
8160
                                                        if (!acki) begin
8161
                                                                dram0 <= `DRAMSLOT_HASBUS;
8162
                                                                dram0_instr[`INSTRUCTION_OP] <= `NOP;
8163
                cyc <= `HIGH;
8164
                stb_o <= `HIGH;
8165 61 robfinch
                we <= `HIGH;
8166 60 robfinch
                sel_o <= fnSelect(dram0_instr,dram0_addr);
8167
                vadr <= dram0_addr;
8168
                dat_o <= fnDato(dram0_instr,dram0_data);
8169
                ol_o  <= dram0_ol;
8170
                                        isStore <= TRUE;
8171
                bstate <= B_StoreAck;
8172
              end
8173
//                 cr_o <= IsSWC(dram0_instr);
8174
            end
8175
        end
8176 61 robfinch
        else if (dram1==`DRAMSLOT_BUSY && dram1_store && `NUM_MEM > 1) begin
8177 60 robfinch
`ifdef SUPPORT_DBG
8178
            if (dbg_smatch1) begin
8179
                 dramB_v <= `TRUE;
8180
                 dramB_id <= dram1_id;
8181
                 dramB_bus <= 64'h0;
8182 61 robfinch
                 iqentry_exc[dram1_id[`QBITS]] <= `FLT_DBG;
8183 60 robfinch
                 dram1 <= `DRAMSLOT_AVAIL;
8184
            end
8185
            else
8186
`endif
8187
            begin
8188
                 bwhich <= 2'b01;
8189
                                                        if (!acki) begin
8190
                dram1 <= `DRAMSLOT_HASBUS;
8191
                dram1_instr[`INSTRUCTION_OP] <= `NOP;
8192
                cyc <= `HIGH;
8193
                stb_o <= `HIGH;
8194 61 robfinch
                we <= `HIGH;
8195 60 robfinch
                sel_o <= fnSelect(dram1_instr,dram1_addr);
8196
                vadr <= dram1_addr;
8197
                dat_o <= fnDato(dram1_instr,dram1_data);
8198
                ol_o  <= dram1_ol;
8199
                                        isStore <= TRUE;
8200
                bstate <= B_StoreAck;
8201
              end
8202
//                 cr_o <= IsSWC(dram0_instr);
8203
            end
8204
        end
8205 61 robfinch
        else if (dram2==`DRAMSLOT_BUSY && dram2_store && `NUM_MEM > 2) begin
8206 60 robfinch
`ifdef SUPPORT_DBG
8207
            if (dbg_smatch2) begin
8208
                 dramC_v <= `TRUE;
8209
                 dramC_id <= dram2_id;
8210
                 dramC_bus <= 64'h0;
8211 61 robfinch
                 iqentry_exc[dram2_id[`QBITS]] <= `FLT_DBG;
8212 60 robfinch
                 dram2 <= `DRAMSLOT_AVAIL;
8213
            end
8214
            else
8215
`endif
8216
            begin
8217
                 bwhich <= 2'b10;
8218
                                                        if (!acki) begin
8219
                dram2 <= `DRAMSLOT_HASBUS;
8220
                dram2_instr[`INSTRUCTION_OP] <= `NOP;
8221
                cyc <= `HIGH;
8222
                stb_o <= `HIGH;
8223 61 robfinch
                we <= `HIGH;
8224 60 robfinch
                sel_o <= fnSelect(dram2_instr,dram2_addr);
8225
                vadr <= dram2_addr;
8226
                dat_o <= fnDato(dram2_instr,dram2_data);
8227
                ol_o  <= dram2_ol;
8228
                                        isStore <= TRUE;
8229
                bstate <= B_StoreAck;
8230
              end
8231
//                 cr_o <= IsSWC(dram0_instr);
8232
            end
8233
        end
8234
`endif
8235
        // Check for read misses on the data cache
8236 61 robfinch
        else if (~|wb_v && !dram0_unc && dram0==`DRAMSLOT_REQBUS && dram0_load) begin
8237 60 robfinch
`ifdef SUPPORT_DBG
8238
            if (dbg_lmatch0) begin
8239
               dramA_v <= `TRUE;
8240
               dramA_id <= dram0_id;
8241
               dramA_bus <= 64'h0;
8242 61 robfinch
               iqentry_exc[dram0_id[`QBITS]] <= `FLT_DBG;
8243 60 robfinch
               dram0 <= `DRAMSLOT_AVAIL;
8244
            end
8245
            else
8246
`endif
8247
            begin
8248
               dram0 <= `DRAMSLOT_HASBUS;
8249
               bwhich <= 2'b00;
8250
               preload <= dram0_preload;
8251
               bstate <= B_DCacheLoadStart;
8252
            end
8253
        end
8254 61 robfinch
        else if (~|wb_v && !dram1_unc && dram1==`DRAMSLOT_REQBUS && dram1_load && `NUM_MEM > 1) begin
8255 60 robfinch
`ifdef SUPPORT_DBG
8256
            if (dbg_lmatch1) begin
8257
               dramB_v <= `TRUE;
8258
               dramB_id <= dram1_id;
8259
               dramB_bus <= 64'h0;
8260 61 robfinch
               iqentry_exc[dram1_id[`QBITS]] <= `FLT_DBG;
8261 60 robfinch
               dram1 <= `DRAMSLOT_AVAIL;
8262
            end
8263
            else
8264
`endif
8265
            begin
8266
               dram1 <= `DRAMSLOT_HASBUS;
8267
               bwhich <= 2'b01;
8268
               preload <= dram1_preload;
8269
               bstate <= B_DCacheLoadStart;
8270
            end
8271
        end
8272 61 robfinch
        else if (~|wb_v && !dram2_unc && dram2==`DRAMSLOT_REQBUS && dram2_load && `NUM_MEM > 2) begin
8273 60 robfinch
`ifdef SUPPORT_DBG
8274
            if (dbg_lmatch2) begin
8275
               dramC_v <= `TRUE;
8276
               dramC_id <= dram2_id;
8277
               dramC_bus <= 64'h0;
8278 61 robfinch
               iqentry_exc[dram2_id[`QBITS]] <= `FLT_DBG;
8279 60 robfinch
               dram2 <= `DRAMSLOT_AVAIL;
8280
            end
8281
            else
8282
`endif
8283
            begin
8284
               dram2 <= `DRAMSLOT_HASBUS;
8285
               preload <= dram2_preload;
8286
               bwhich <= 2'b10;
8287
               bstate <= B_DCacheLoadStart;
8288
            end
8289
        end
8290 61 robfinch
        else if (~|wb_v && dram0_unc && dram0==`DRAMSLOT_BUSY && dram0_load) begin
8291 60 robfinch
`ifdef SUPPORT_DBG
8292
            if (dbg_lmatch0) begin
8293
               dramA_v <= `TRUE;
8294
               dramA_id <= dram0_id;
8295
               dramA_bus <= 64'h0;
8296 61 robfinch
               iqentry_exc[dram0_id[`QBITS]] <= `FLT_DBG;
8297 60 robfinch
               dram0 <= `DRAMSLOT_AVAIL;
8298
            end
8299
            else
8300
`endif
8301
            if (!acki) begin
8302
               bwhich <= 2'b00;
8303
               cyc <= `HIGH;
8304
               stb_o <= `HIGH;
8305
               sel_o <= fnSelect(dram0_instr,dram0_addr);
8306
               vadr <= {dram0_addr[AMSB:3],3'b0};
8307
               sr_o <=  IsLWR(dram0_instr);
8308
               ol_o  <= dram0_ol;
8309 61 robfinch
               dccnt <= 2'd0;
8310 60 robfinch
               bstate <= B_DLoadAck;
8311
            end
8312
        end
8313 61 robfinch
        else if (~|wb_v && dram1_unc && dram1==`DRAMSLOT_BUSY && dram1_load && `NUM_MEM > 1) begin
8314 60 robfinch
`ifdef SUPPORT_DBG
8315
            if (dbg_lmatch1) begin
8316
               dramB_v <= `TRUE;
8317
               dramB_id <= dram1_id;
8318
               dramB_bus <= 64'h0;
8319 61 robfinch
               iqentry_exc[dram1_id[`QBITS]] <= `FLT_DBG;
8320 60 robfinch
               dram1 <= `DRAMSLOT_AVAIL;
8321
            end
8322
            else
8323
`endif
8324
            if (!acki) begin
8325
               bwhich <= 2'b01;
8326
               cyc <= `HIGH;
8327
               stb_o <= `HIGH;
8328
               sel_o <= fnSelect(dram1_instr,dram1_addr);
8329
               vadr <= {dram1_addr[AMSB:3],3'b0};
8330
               sr_o <=  IsLWR(dram1_instr);
8331
               ol_o  <= dram1_ol;
8332 61 robfinch
               dccnt <= 2'd0;
8333 60 robfinch
               bstate <= B_DLoadAck;
8334
            end
8335
        end
8336 61 robfinch
        else if (~|wb_v && dram2_unc && dram2==`DRAMSLOT_BUSY && dram2_load && `NUM_MEM > 2) begin
8337 60 robfinch
`ifdef SUPPORT_DBG
8338
            if (dbg_lmatch2) begin
8339
               dramC_v <= `TRUE;
8340
               dramC_id <= dram2_id;
8341
               dramC_bus <= 64'h0;
8342 61 robfinch
               iqentry_exc[dram2_id[`QBITS]] <= `FLT_DBG;
8343 60 robfinch
               dram2 <= 2'd0;
8344
            end
8345
            else
8346
`endif
8347
            if (!acki) begin
8348
               bwhich <= 2'b10;
8349
               cyc <= `HIGH;
8350
               stb_o <= `HIGH;
8351
               sel_o <= fnSelect(dram2_instr,dram2_addr);
8352
               vadr <= {dram2_addr[AMSB:3],3'b0};
8353
               sr_o <=  IsLWR(dram2_instr);
8354
               ol_o  <= dram2_ol;
8355 61 robfinch
               dccnt <= 2'd0;
8356 60 robfinch
               bstate <= B_DLoadAck;
8357
            end
8358
        end
8359
        // Check for L2 cache miss
8360 61 robfinch
        else if (~|wb_v && !ihitL2 && !acki)
8361
        begin
8362 60 robfinch
           cti_o <= 3'b001;
8363
           bte_o <= 2'b00;//2'b01;      // 4 beat burst wrap
8364
           cyc <= `HIGH;
8365
           stb_o <= `HIGH;
8366
           sel_o <= 8'hFF;
8367
           icl_o <= `HIGH;
8368
           iccnt <= 3'd0;
8369 61 robfinch
           icack <= 1'b0;
8370 60 robfinch
//            adr_o <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
8371
//            L2_adr <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
8372
           vadr <= {pcr[7:0],L1_adr[AMSB:5],5'h0};
8373 61 robfinch
`ifdef SUPPORT_SMT
8374
`else
8375
           ol_o  <= ol;//???
8376
`endif
8377 60 robfinch
           L2_adr <= {pcr[7:0],L1_adr[AMSB:5],5'h0};
8378
           L2_xsel <= 1'b0;
8379
           bstate <= B_ICacheAck;
8380
        end
8381
    end
8382
 
8383
// Terminal state for a store operation.
8384
// Note that if only a single memory channel is selected, bwhich will be a
8385
// constant 0. This should cause the extra code to be removed.
8386
B_StoreAck:
8387
        begin
8388
                StoreAck1 <= `TRUE;
8389
                isStore <= `TRUE;
8390
        if (acki|err_i|tlb_miss|wrv_i) begin
8391
                wb_nack();
8392
                cr_o <= 1'b0;
8393
    // This isn't a good way of doing things; the state should be propagated
8394
    // to the commit stage, however since this is a store we know there will
8395
    // be no change of program flow. So the reservation status bit is set
8396
    // here. The author wanted to avoid the complexity of propagating the
8397
    // input signal to the commit stage. It does mean that the SWC
8398
    // instruction should be surrounded by SYNC's.
8399
    if (cr_o)
8400
                        sema[0] <= rbi_i;
8401
`ifdef HAS_WB
8402
                for (n = 0; n < QENTRIES; n = n + 1) begin
8403
                        if (wbo_id[n]) begin
8404
        iqentry_exc[n] <= tlb_miss ? `FLT_TLB : wrv_i ? `FLT_DWF : err_i ? `FLT_IBE : `FLT_NONE;
8405
        if (err_i|wrv_i) begin
8406
                wb_v <= 1'b0;                   // Invalidate write buffer if there is a problem with the store
8407
                wb_en <= `FALSE;        // and disable write buffer
8408
        end
8409 61 robfinch
        iqentry_state[n] <= IQS_CMT;
8410 60 robfinch
                                iqentry_aq[n] <= `INV;
8411
                        end
8412
                end
8413
`else
8414
    case(bwhich)
8415
    2'd0:   begin
8416
                dram0 <= `DRAMSLOT_AVAIL;
8417
                iqentry_exc[dram0_id[`QBITS]] <= (wrv_i|err_i) ? `FLT_DWF : `FLT_NONE;
8418
                                iqentry_state[dram0_id[`QBITS]] <= IQS_CMT;
8419
                                                        iqentry_aq[ dram0_id[`QBITS] ] <= `INV;
8420
                //iqentry_out[ dram0_id[`QBITS] ] <= `INV;
8421
            end
8422
    2'd1:   if (`NUM_MEM > 1) begin
8423
                dram1 <= `DRAMSLOT_AVAIL;
8424
                iqentry_exc[dram1_id[`QBITS]] <= (wrv_i|err_i) ? `FLT_DWF : `FLT_NONE;
8425
                                iqentry_state[dram1_id[`QBITS]] <= IQS_CMT;
8426
                                                        iqentry_aq[ dram1_id[`QBITS] ] <= `INV;
8427
                //iqentry_out[ dram1_id[`QBITS] ] <= `INV;
8428
            end
8429
    2'd2:   if (`NUM_MEM > 2) begin
8430
                dram2 <= `DRAMSLOT_AVAIL;
8431
                iqentry_exc[dram2_id[`QBITS]] <= (wrv_i|err_i) ? `FLT_DWF : `FLT_NONE;
8432
                                iqentry_state[dram2_id[`QBITS]] <= IQS_CMT;
8433
                                                        iqentry_aq[ dram2_id[`QBITS] ] <= `INV;
8434
                //iqentry_out[ dram2_id[`QBITS] ] <= `INV;
8435
            end
8436
    default:    ;
8437
    endcase
8438
`endif
8439 61 robfinch
                bstate <= B_LSNAck;
8440 60 robfinch
  end
8441
        end
8442
 
8443
B_DCacheLoadStart:
8444
  if (~acki & ~cyc) begin       // check for idle bus - it should be
8445
    dccnt <= 2'd0;
8446
    bstate <= B_DCacheLoadAck;
8447
                cti_o <= 3'b001;        // constant address burst
8448
                bte_o <= 2'b00;         // linear burst, non-wrapping
8449
                cyc <= `HIGH;
8450
                stb_o <= `HIGH;
8451
                // Select should be selecting all byte lanes for a cache load
8452
    sel_o <= 8'hFF;
8453
                // bwhich should always be one of the three channels.
8454
    case(bwhich)
8455
    2'd0:   begin
8456
             vadr <= {dram0_addr[AMSB:5],5'b0};
8457
             ol_o  <= dram0_ol;
8458
            end
8459
    2'd1:   if (`NUM_MEM > 1) begin
8460
             vadr <= {dram1_addr[AMSB:5],5'b0};
8461
             ol_o  <= dram1_ol;
8462
            end
8463
    2'd2:   if (`NUM_MEM > 2) begin
8464
             vadr <= {dram2_addr[AMSB:5],5'b0};
8465
             ol_o  <= dram2_ol;
8466
            end
8467
    default:
8468
      begin
8469
        $display("Invalid memory channel selection");
8470
        $stop;
8471
        wb_nack();
8472
                bstate <= BIDLE;
8473
        end
8474
    endcase
8475
  end
8476
 
8477
// Data cache load terminal state
8478
B_DCacheLoadAck:
8479 61 robfinch
  if (acki|err_i|tlb_miss|rdv_i) begin
8480 60 robfinch
        if (!bok_i) begin
8481
                stb_o <= `LOW;
8482
                bstate <= B_DCacheLoadStb;
8483
        end
8484
    errq <= errq | err_i;
8485
    rdvq <= rdvq | rdv_i;
8486
    if (!preload)       // A preload instruction ignores any error
8487
    case(bwhich)
8488 61 robfinch
    2'd0:       iqentry_exc[dram0_id[`QBITS]] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DBE : rdv_i ? `FLT_DRF : `FLT_NONE;
8489
    2'd1:   iqentry_exc[dram1_id[`QBITS]] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DBE : rdv_i ? `FLT_DRF : `FLT_NONE;
8490
    2'd2:   iqentry_exc[dram2_id[`QBITS]] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DBE : rdv_i ? `FLT_DRF : `FLT_NONE;
8491 60 robfinch
    default:    ;
8492
    endcase
8493
    dccnt <= dccnt + 2'd1;
8494
    vadr[4:3] <= vadr[4:3] + 2'd1;
8495
    if (dccnt==2'd2)
8496
                        cti_o <= 3'b111;
8497
    if (dccnt==2'd3) begin
8498
        wb_nack();
8499
                        bstate <= B_DCacheLoadWait1;
8500
    end
8501
  end
8502
B_DCacheLoadStb:
8503
        begin
8504
                stb_o <= `HIGH;
8505
                bstate <= B_DCacheLoadAck;
8506
  end
8507
B_DCacheLoadWait1: bstate <= B_DCacheLoadWait2;
8508
B_DCacheLoadWait2: bstate <= B_DCacheLoadResetBusy;
8509
//B_DCacheLoadWait3: bstate <= B_DCacheLoadResetBusy;
8510 61 robfinch
// There could be more than one memory cycle active. We reset the state
8511
// of all the machines to retest for a hit because otherwise sequential
8512
// loading of memory will cause successive machines to miss resulting in 
8513
// multiple dcache loads that aren't needed.
8514
B_DCacheLoadResetBusy:
8515
        begin
8516 60 robfinch
    if (dram0 != `DRAMSLOT_AVAIL && dram0_addr[AMSB:5]==vadr[AMSB:5]) dram0 <= `DRAMSLOT_BUSY;  // causes retest of dhit
8517
    if (dram1 != `DRAMSLOT_AVAIL && dram1_addr[AMSB:5]==vadr[AMSB:5]) dram1 <= `DRAMSLOT_BUSY;
8518
    if (dram2 != `DRAMSLOT_AVAIL && dram2_addr[AMSB:5]==vadr[AMSB:5]) dram2 <= `DRAMSLOT_BUSY;
8519 61 robfinch
    bstate <= BIDLE;
8520
  end
8521 60 robfinch
 
8522
// Ack state for instruction cache load
8523 61 robfinch
// Once the first ack is received in burst mode, further acks are not necessary
8524
// as the core counts the number of data items. Occasionally missing acks were
8525
// causing a problem.
8526 60 robfinch
B_ICacheAck:
8527 61 robfinch
  if (acki|err_i|tlb_miss|exv_i|icack) begin
8528 60 robfinch
        if (!bok_i) begin
8529
                stb_o <= `LOW;
8530
                bstate <= B_ICacheNack2;
8531
        end
8532 61 robfinch
        else
8533
                icack <= 1'b1;
8534 60 robfinch
    errq <= errq | err_i;
8535
    exvq <= exvq | exv_i;
8536
                if (tlb_miss) begin
8537 61 robfinch
                        L1_dati <= {19{`INSN_FLT_TLB}};
8538 60 robfinch
                        wb_nack();
8539
      icl_o <= `LOW;
8540
      bstate <= B_ICacheNack;
8541
    end
8542
                else if (exv_i) begin
8543 61 robfinch
                        L1_dati <= {19{`INSN_FLT_EXF}};
8544 60 robfinch
                        wb_nack();
8545
      icl_o <= `LOW;
8546
      bstate <= B_ICacheNack;
8547
                end
8548
    else if (err_i) begin
8549 61 robfinch
                        L1_dati <= {19{`INSN_FLT_IBE}};
8550 60 robfinch
                        wb_nack();
8551
      icl_o <= `LOW;
8552
      bstate <= B_ICacheNack;
8553
    end
8554
    else
8555
        case(iccnt)
8556 61 robfinch
        3'd0:   L1_dati[63:0] <= dat_i;
8557
        3'd1:   L1_dati[127:64] <= dat_i;
8558
        3'd2:   L1_dati[191:128] <= dat_i;
8559
        3'd3:   L1_dati[255:192] <= dat_i;
8560
        3'd4:   L1_dati[305:256] <= {2'b00,dat_i[47:0]};
8561
        default:        L1_dati <= L1_dati;
8562 60 robfinch
        endcase
8563
    iccnt <= iccnt + 3'd1;
8564
    if (iccnt==3'd3)
8565
      cti_o <= 3'b111;
8566
    if (iccnt==3'd4) begin
8567
                        wb_nack();
8568
      icl_o <= `LOW;
8569
      bstate <= B_ICacheNack;
8570
    end
8571
    else begin
8572
      L2_adr[4:3] <= L2_adr[4:3] + 2'd1;
8573
      if (L2_adr[4:3]==2'b11)
8574
        L2_xsel <= 1'b1;
8575
    end
8576
  end
8577
B_ICacheNack2:
8578
        if (~acki) begin
8579
                stb_o <= `HIGH;
8580
                vadr[AMSB:3] <= vadr[AMSB:3] + 2'd1;
8581
                bstate <= B_ICacheAck;
8582
        end
8583
B_ICacheNack:
8584
        begin
8585
                L2_xsel <= 1'b0;
8586 61 robfinch
                if (~acki) begin
8587 60 robfinch
                        icl_ctr <= icl_ctr + 40'd1;
8588
                        bstate <= BIDLE;
8589
                        L2_nxt <= TRUE;
8590 61 robfinch
                        vadr <= 32'hCCCCCCC8;
8591 60 robfinch
                end
8592
        end
8593 61 robfinch
 
8594 60 robfinch
B12:
8595 61 robfinch
    if (acki|err_i|tlb_miss|rdv_i) begin
8596 60 robfinch
        if (isCAS) begin
8597
             iqentry_res        [ casid[`QBITS] ] <= (dat_i == cas);
8598
             iqentry_exc [ casid[`QBITS] ] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8599
//             iqentry_done[ casid[`QBITS] ] <= `VAL;
8600
//           iqentry_out [ casid[`QBITS] ] <= `INV;
8601
             iqentry_state [ casid[`QBITS] ] <= IQS_DONE;
8602
             iqentry_instr[ casid[`QBITS]] <= `NOP_INSN;
8603
            if (err_i | rdv_i) iqentry_ma[casid[`QBITS]] <= vadr;
8604
            if (dat_i == cas) begin
8605
                 stb_o <= `LOW;
8606
                 we <= `TRUE;
8607
                 bstate <= B15;
8608
            end
8609
            else begin
8610
                 cas <= dat_i;
8611
                 cyc <= `LOW;
8612
                 stb_o <= `LOW;
8613
                case(bwhich)
8614
                2'b00:   dram0 <= `DRAMREQ_READY;
8615
                2'b01:   dram1 <= `DRAMREQ_READY;
8616
                2'b10:   dram2 <= `DRAMREQ_READY;
8617
                default:    ;
8618
                endcase
8619 61 robfinch
                 bstate <= B_LSNAck;
8620 60 robfinch
            end
8621
        end
8622
        else if (isRMW) begin
8623
             rmw_instr <= iqentry_instr[casid[`QBITS]];
8624
             rmw_argA <= dat_i;
8625
                 if (isSpt) begin
8626
                        rmw_argB <= 64'd1 << iqentry_a1[casid[`QBITS]][63:58];
8627
                        rmw_argC <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ?
8628
                                                iqentry_a3[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58] :
8629
                                                iqentry_a2[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58];
8630
                 end
8631
                 else if (isInc) begin
8632
                        rmw_argB <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ? {{59{iqentry_instr[casid[`QBITS]][22]}},iqentry_instr[casid[`QBITS]][22:18]} :
8633
                                                                                                                                 {{59{iqentry_instr[casid[`QBITS]][17]}},iqentry_instr[casid[`QBITS]][17:13]};
8634
                 end
8635
                 else begin // isAMO
8636
                     iqentry_res [ casid[`QBITS] ] <= dat_i;
8637
                     rmw_argB <= iqentry_instr[casid[`QBITS]][31] ? {{59{iqentry_instr[casid[`QBITS]][20:16]}},iqentry_instr[casid[`QBITS]][20:16]} : iqentry_a2[casid[`QBITS]];
8638
                 end
8639
             iqentry_exc [ casid[`QBITS] ] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8640
             stb_o <= `LOW;
8641
             bstate <= B20;
8642
                end
8643
    end
8644
 
8645
// Regular load
8646
B_DLoadAck:
8647 61 robfinch
  if (acki|err_i|tlb_miss|rdv_i) begin
8648 60 robfinch
        wb_nack();
8649
                sr_o <= `LOW;
8650 61 robfinch
                case(dccnt)
8651
                2'd0:   xdati[63:0] <= dat_i;
8652
                2'd1:   xdati[127:64] <= dat_i;
8653
                endcase
8654 60 robfinch
    case(bwhich)
8655
    2'b00:  begin
8656 61 robfinch
                                        if (dram0_memsize==hexi) begin
8657
                                                if (dccnt==2'd1) begin
8658
                                     dram0 <= `DRAMREQ_READY;
8659
                                     iqentry_seg_base[dram0_id[`QBITS]] <= xdati[63:0];
8660
                                     iqentry_seg_acr[dram0_id[`QBITS]] <= dat_i;
8661
                                  end
8662
                                  else begin
8663
                                        dccnt <= dccnt + 2'd1;
8664
                                        cyc <= `HIGH;
8665
                                        sel_o <= 8'hFF;
8666
                                        vadr <= vadr + 64'd8;
8667
                                        bstate <= B_DLoadNack;
8668
                                        end
8669
                                        end
8670
                                        else
8671
                        dram0 <= `DRAMREQ_READY;
8672 60 robfinch
             iqentry_exc [ dram0_id[`QBITS] ] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8673
            end
8674
    2'b01:  if (`NUM_MEM > 1) begin
8675
             dram1 <= `DRAMREQ_READY;
8676
             iqentry_exc [ dram1_id[`QBITS] ] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8677
            end
8678
    2'b10:  if (`NUM_MEM > 2) begin
8679
             dram2 <= `DRAMREQ_READY;
8680
             iqentry_exc [ dram2_id[`QBITS] ] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8681
            end
8682
    default:    ;
8683
    endcase
8684 61 robfinch
                bstate <= B_LSNAck;
8685 60 robfinch
        end
8686 61 robfinch
B_DLoadNack:
8687
        if (~acki) begin
8688
                stb_o <= `HIGH;
8689
                bstate <= B_DLoadAck;
8690
        end
8691 60 robfinch
 
8692
// Three cycles to detemrine if there's a cache hit during a store.
8693
B16:    begin
8694
            case(bwhich)
8695
            2'd0:      if (dhit0) begin  dram0 <= `DRAMREQ_READY; bstate <= B17; end
8696
            2'd1:      if (dhit1) begin  dram1 <= `DRAMREQ_READY; bstate <= B17; end
8697
            2'd2:      if (dhit2) begin  dram2 <= `DRAMREQ_READY; bstate <= B17; end
8698
            default:    bstate <= BIDLE;
8699
            endcase
8700
            end
8701
B17:     bstate <= B18;
8702 61 robfinch
B18:     bstate <= B_LSNAck;
8703
B_LSNAck:
8704
   begin
8705
                        bstate <= BIDLE;
8706
                        StoreAck1 <= `FALSE;
8707
                        isStore <= `FALSE;
8708
                end
8709 60 robfinch
B20:
8710 61 robfinch
        if (~acki) begin
8711 60 robfinch
                stb_o <= `HIGH;
8712
                we  <= `HIGH;
8713
                dat_o <= fnDato(rmw_instr,rmw_res);
8714
                bstate <= B_StoreAck;
8715
        end
8716
B21:
8717 61 robfinch
        if (~acki) begin
8718 60 robfinch
                stb_o <= `HIGH;
8719
                bstate <= B12;
8720
        end
8721
default:     bstate <= BIDLE;
8722
endcase
8723
 
8724 61 robfinch
 
8725 60 robfinch
if (!branchmiss) begin
8726 61 robfinch
  case({fetchbuf0_v, fetchbuf1_v})
8727
  2'b00:  ;
8728
  2'b01:
8729
    if (canq1) begin
8730
        tail0 <= (tail0+2'd1) % QENTRIES;
8731
        tail1 <= (tail1+2'd1) % QENTRIES;
8732
    end
8733
  2'b10:
8734
    if (canq1) begin
8735
        tail0 <= (tail0+2'd1) % QENTRIES;
8736
        tail1 <= (tail1+2'd1) % QENTRIES;
8737
    end
8738
  2'b11:
8739
    if (canq1) begin
8740
      if (IsBranch(fetchbuf0_instr) && predict_taken0 && fetchbuf0_thrd==fetchbuf1_thrd) begin
8741
        tail0 <= (tail0+2'd1) % QENTRIES;
8742
        tail1 <= (tail1+2'd1) % QENTRIES;
8743
      end
8744
      else begin
8745
                                if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
8746
          if (canq2) begin
8747
            tail0 <= (tail0 + 3'd2) % QENTRIES;
8748
            tail1 <= (tail1 + 3'd2) % QENTRIES;
8749
          end
8750
          else begin    // queued1 will be true
8751 60 robfinch
                tail0 <= (tail0+2'd1) % QENTRIES;
8752 61 robfinch
                                        tail1 <= (tail1+2'd1) % QENTRIES;
8753
          end
8754
        end
8755
      end
8756
    end
8757
  endcase
8758 60 robfinch
end
8759
else if (!thread_en) begin      // if branchmiss
8760
        for (n = QENTRIES-1; n >= 0; n = n - 1)
8761
                // (QENTRIES-1) is needed to ensure that n increments forwards so that the modulus is
8762
                // a positive number.
8763
                if (iqentry_stomp[n] & ~iqentry_stomp[(n+(QENTRIES-1))%QENTRIES]) begin
8764
                        tail0 <= n;
8765
                        tail1 <= (n + 1) % QENTRIES;
8766
                end
8767
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
8768
end
8769
 
8770
//      #5 rf[0] = 0; rf_v[0] = 1; rf_source[0] = 0;
8771
`ifdef SIM
8772
        $display("\n\n\n\n\n\n\n\n");
8773
        $display("TIME %0d", $time);
8774
        $display("%h #", pc0);
8775
`ifdef SUPPORT_SMT
8776
    $display ("Regfile: %d", rgs[0]);
8777
        for (n=0; n < 32; n=n+4) begin
8778
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8779
               n[4:0]+0, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8780
               n[4:0]+1, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8781
               n[4:0]+2, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8782
               n[4:0]+3, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8783
               );
8784
        end
8785
    $display ("Regfile: %d", rgs[1]);
8786
        for (n=128; n < 160; n=n+4) begin
8787
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8788
               n[4:0]+0, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8789
               n[4:0]+1, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8790
               n[4:0]+2, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8791
               n[4:0]+3, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8792
               );
8793
        end
8794
`else
8795
    $display ("Regfile: %d", rgs);
8796
        for (n=0; n < 32; n=n+4) begin
8797
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8798
               n[4:0]+0, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8799
               n[4:0]+1, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8800
               n[4:0]+2, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8801
               n[4:0]+3, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8802
               );
8803
        end
8804
`endif
8805
`ifdef FCU_ENH
8806
        $display("Call Stack:");
8807
        for (n = 0; n < 16; n = n + 4)
8808
                $display("%c%d: %h   %c%d: %h   %c%d: %h   %c%d: %h",
8809
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+0 ?">" : " ", n[4:0]+0, gFetchbufInst.gb1.ufb1.ursb1.ras[n+0],
8810
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+1 ?">" : " ", n[4:0]+1, gFetchbufInst.gb1.ufb1.ursb1.ras[n+1],
8811
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+2 ?">" : " ", n[4:0]+2, gFetchbufInst.gb1.ufb1.ursb1.ras[n+2],
8812
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+3 ?">" : " ", n[4:0]+3, gFetchbufInst.gb1.ufb1.ursb1.ras[n+3]
8813
                );
8814
        $display("\n");
8815
`endif
8816
//    $display("Return address stack:");
8817
//    for (n = 0; n < 16; n = n + 1)
8818
//        $display("%d %h", rasp+n[3:0], ras[rasp+n[3:0]]);
8819
        $display("TakeBr:%d #", take_branch);//, backpc);
8820
        $display("Insn%d: %h", 0, insn0);
8821
        if (`WAYS==1) begin
8822
        $display("%c%c A: %d %h %h #",
8823
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
8824
        $display("%c%c B: %d %h %h #",
8825
            45, fetchbuf?62:45, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
8826
        end
8827
        else if (`WAYS > 1) begin
8828
                $display("Insn%d: %h", 1, insn1);
8829
        $display("%c%c A: %d %h %h #",
8830
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
8831
        $display("%c%c B: %d %h %h #",
8832
            45, fetchbuf?45:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
8833
        end
8834
        else if (`WAYS > 2) begin
8835
                $display("%c%c C: %d %h %h #",
8836
                    45, fetchbuf?62:45, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
8837
                $display("%c%c D: %d %h %h #",
8838
                    45, fetchbuf?62:45, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
8839
        end
8840
        for (i=0; i<QENTRIES; i=i+1)
8841
            $display("%c%c %d: %c%c%c%c %d %d %c%c %c %c%h %d %o %h %h %h %d %o %h %d %o %h %d %o %d:%h %h %d#",
8842
                 (i[`QBITS]==heads[0])?"C":".",
8843
                 (i[`QBITS]==tail0)?"Q":".",
8844
                  i[`QBITS],
8845 61 robfinch
                  iqentry_state[i]==IQS_INVALID ? "-" :
8846
                  iqentry_state[i]==IQS_QUEUED ? "Q" :
8847
                  iqentry_state[i]==IQS_OUT ? "O"  :
8848
                  iqentry_state[i]==IQS_AGEN ? "A"  :
8849
                  iqentry_state[i]==IQS_MEM ? "M"  :
8850
                  iqentry_state[i]==IQS_DONE ? "D"  :
8851
                  iqentry_state[i]==IQS_CMT ? "C"  : "?",
8852
//               iqentry_v[i] ? "v" : "-",
8853 60 robfinch
                 iqentry_iv[i] ? "I" : "-",
8854
                 iqentry_done[i]?"d":"-",
8855
                 iqentry_out[i]?"o":"-",
8856
                 iqentry_bt[i],
8857
                 iqentry_memissue[i],
8858
                 iqentry_agen[i] ? "a": "-",
8859
                 iqentry_alu0_issue[i]?"0":iqentry_alu1_issue[i]?"1":"-",
8860
                 iqentry_stomp[i]?"s":"-",
8861
                iqentry_fc[i] ? "F" : iqentry_mem[i] ? "M" : (iqentry_alu[i]==1'b1) ? "a" : (iqentry_alu[i]==1'bx) ? "X" : iqentry_fpu[i] ? "f" : "O",
8862
                iqentry_instr[i], iqentry_tgt[i][4:0],
8863
                iqentry_exc[i], iqentry_res[i], iqentry_a0[i], iqentry_a1[i], iqentry_a1_v[i],
8864
                iqentry_a1_s[i],
8865
                iqentry_a2[i], iqentry_a2_v[i], iqentry_a2_s[i],
8866
                iqentry_a3[i], iqentry_a3_v[i], iqentry_a3_s[i],
8867
                iqentry_thrd[i],
8868
                iqentry_pc[i],
8869
                iqentry_sn[i], iqentry_ven[i]
8870
                );
8871
    $display("DRAM");
8872
        $display("%d %h %h %c%h %o #",
8873
            dram0, dram0_addr, dram0_data, (IsFlowCtrl(dram0_instr) ? 98 : (IsMem(dram0_instr)) ? 109 : 97),
8874
            dram0_instr, dram0_id);
8875
          if (`NUM_MEM > 1)
8876
        $display("%d %h %h %c%h %o #",
8877
            dram1, dram1_addr, dram1_data, (IsFlowCtrl(dram1_instr) ? 98 : (IsMem(dram1_instr)) ? 109 : 97),
8878
            dram1_instr, dram1_id);
8879
          if (`NUM_MEM > 2)
8880
        $display("%d %h %h %c%h %o #",
8881
            dram2, dram2_addr, dram2_data, (IsFlowCtrl(dram2_instr) ? 98 : (IsMem(dram2_instr)) ? 109 : 97),
8882
            dram2_instr, dram2_id);
8883 61 robfinch
        $display("%d %h %o #", dramA_v, dramA_bus, dramA_id);
8884 60 robfinch
        if (`NUM_MEM > 1)
8885 61 robfinch
        $display("%d %h %o #", dramB_v, dramB_bus, dramB_id);
8886 60 robfinch
        if (`NUM_MEM > 2)
8887 61 robfinch
        $display("%d %h %o #", dramC_v, dramC_bus, dramC_id);
8888 60 robfinch
    $display("ALU");
8889
        $display("%d %h %h %h %c%h %o %h #",
8890
                alu0_dataready, alu0_argI, alu0_argA, alu0_argB,
8891
                 (IsFlowCtrl(alu0_instr) ? 98 : IsMem(alu0_instr) ? 109 : 97),
8892
                alu0_instr, alu0_sourceid, alu0_pc);
8893
        $display("%d %h %o 0 #", alu0_v, alu0_bus, alu0_id);
8894
        if (`NUM_ALU > 1) begin
8895
                $display("%d %h %h %h %c%h %o %h #",
8896
                        alu1_dataready, alu1_argI, alu1_argA, alu1_argB,
8897
                        (IsFlowCtrl(alu1_instr) ? 98 : IsMem(alu1_instr) ? 109 : 97),
8898
                        alu1_instr, alu1_sourceid, alu1_pc);
8899
                $display("%d %h %o 0 #", alu1_v, alu1_bus, alu1_id);
8900
        end
8901
        $display("FCU");
8902
        $display("%d %h %h %h %h %c%c #", fcu_v, fcu_bus, fcu_argI, fcu_argA, fcu_argB, fcu_takb?"T":"-", fcu_pt?"T":"-");
8903
        $display("%c %h %h %h %h #", fcu_branchmiss?"m":" ", fcu_sourceid, fcu_misspc, fcu_nextpc, fcu_brdisp);
8904
    $display("Commit");
8905
        $display("0: %c %h %o %d #", commit0_v?"v":" ", commit0_bus, commit0_id, commit0_tgt[4:0]);
8906
        $display("1: %c %h %o %d #", commit1_v?"v":" ", commit1_bus, commit1_id, commit1_tgt[4:0]);
8907
    $display("instructions committed: %d valid committed: %d ticks: %d ", CC, I, tick);
8908
  $display("Write Buffer:");
8909
  for (n = `WB_DEPTH-1; n >= 0; n = n - 1)
8910
        $display("%c adr: %h dat: %h", wb_v[n]?" ":"*", wb_addr[n], wb_data[n]);
8911
    $display("Write merges: %d", wb_merges);
8912
`endif  // SIM
8913
 
8914
//
8915
//      $display("\n\n\n\n\n\n\n\n");
8916
//      $display("TIME %0d", $time);
8917
//      $display("  pc0=%h", pc0);
8918
//      $display("  pc1=%h", pc1);
8919
//      $display("  reg0=%h, v=%d, src=%o", rf[0], rf_v[0], rf_source[0]);
8920
//      $display("  reg1=%h, v=%d, src=%o", rf[1], rf_v[1], rf_source[1]);
8921
//      $display("  reg2=%h, v=%d, src=%o", rf[2], rf_v[2], rf_source[2]);
8922
//      $display("  reg3=%h, v=%d, src=%o", rf[3], rf_v[3], rf_source[3]);
8923
//      $display("  reg4=%h, v=%d, src=%o", rf[4], rf_v[4], rf_source[4]);
8924
//      $display("  reg5=%h, v=%d, src=%o", rf[5], rf_v[5], rf_source[5]);
8925
//      $display("  reg6=%h, v=%d, src=%o", rf[6], rf_v[6], rf_source[6]);
8926
//      $display("  reg7=%h, v=%d, src=%o", rf[7], rf_v[7], rf_source[7]);
8927
 
8928
//      $display("Fetch Buffers:");
8929
//      $display("  %c%c fbA: v=%d instr=%h pc=%h     %c%c fbC: v=%d instr=%h pc=%h", 
8930
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc,
8931
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
8932
//      $display("  %c%c fbB: v=%d instr=%h pc=%h     %c%c fbD: v=%d instr=%h pc=%h", 
8933
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc,
8934
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
8935
//      $display("  branchback=%d backpc=%h", branchback, backpc);
8936
 
8937
//      $display("Instruction Queue:");
8938
//      for (i=0; i<8; i=i+1) 
8939
//          $display(" %c%c%d: v=%d done=%d out=%d agen=%d res=%h op=%d bt=%d tgt=%d a1=%h (v=%d/s=%o) a2=%h (v=%d/s=%o) im=%h pc=%h exc=%h",
8940
//              (i[`QBITS]==heads[0])?72:32, (i[`QBITS]==tail0)?84:32, i,
8941
//              iqentry_v[i], iqentry_done[i], iqentry_out[i], iqentry_agen[i], iqentry_res[i], iqentry_op[i], 
8942
//              iqentry_bt[i], iqentry_tgt[i], iqentry_a1[i], iqentry_a1_v[i], iqentry_a1_s[i], iqentry_a2[i], iqentry_a2_v[i], 
8943
//              iqentry_a2_s[i], iqentry_a0[i], iqentry_pc[i], iqentry_exc[i]);
8944
 
8945
//      $display("Scheduling Status:");
8946
//      $display("  iqentry0 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8947
//              iqentry_0_issue, iqentry_0_islot, iqentry_stomp[0], iqentry_source[0], iqentry_memready[0], iqentry_memissue[0]);
8948
//      $display("  iqentry1 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8949
//              iqentry_1_issue, iqentry_1_islot, iqentry_stomp[1], iqentry_source[1], iqentry_memready[1], iqentry_memissue[1]);
8950
//      $display("  iqentry2 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8951
//              iqentry_2_issue, iqentry_2_islot, iqentry_stomp[2], iqentry_source[2], iqentry_memready[2], iqentry_memissue[2]);
8952
//      $display("  iqentry3 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8953
//              iqentry_3_issue, iqentry_3_islot, iqentry_stomp[3], iqentry_source[3], iqentry_memready[3], iqentry_memissue[3]);
8954
//      $display("  iqentry4 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8955
//              iqentry_4_issue, iqentry_4_islot, iqentry_stomp[4], iqentry_source[4], iqentry_memready[4], iqentry_memissue[4]);
8956
//      $display("  iqentry5 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8957
//              iqentry_5_issue, iqentry_5_islot, iqentry_stomp[5], iqentry_source[5], iqentry_memready[5], iqentry_memissue[5]);
8958
//      $display("  iqentry6 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8959
//              iqentry_6_issue, iqentry_6_islot, iqentry_stomp[6], iqentry_source[6], iqentry_memready[6], iqentry_memissue[6]);
8960
//      $display("  iqentry7 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8961
//              iqentry_7_issue, iqentry_7_islot, iqentry_stomp[7], iqentry_source[7], iqentry_memready[7], iqentry_memissue[7]);
8962
 
8963
//      $display("ALU Inputs:");
8964
//      $display("  0: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
8965
//              alu0_available, alu0_dataready, alu0_sourceid, alu0_op, alu0_argA,
8966
//              alu0_argB, alu0_argI, alu0_bt);
8967
//      $display("  1: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
8968
//              alu1_available, alu1_dataready, alu1_sourceid, alu1_op, alu1_argA,
8969
//              alu1_argB, alu1_argI, alu1_bt);
8970
 
8971
//      $display("ALU Outputs:");
8972
//      $display("  0: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
8973
//              alu0_v, alu0_bus, alu0_id, alu0_branchmiss, alu0_misspc, alu0_sourceid);
8974
//      $display("  1: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
8975
//              alu1_v, alu1_bus, alu1_id, alu1_branchmiss, alu1_misspc, alu1_sourceid);
8976
 
8977
//      $display("DRAM Status:");
8978
//      $display("  OUT: v=%d data=%h tgt=%d id=%o", dram_v, dram_bus, dram_tgt, dram_id);
8979
//      $display("  dram0: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
8980
//          dram0, dram0_addr, dram0_data, dram0_op, dram0_tgt, dram0_id);
8981
//      $display("  dram1: status=%h addr=%h data=%h op=%d tgt=%d id=%o", 
8982
//          dram1, dram1_addr, dram1_data, dram1_op, dram1_tgt, dram1_id);
8983
//      $display("  dram2: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
8984
//          dram2, dram2_addr, dram2_data, dram2_op, dram2_tgt, dram2_id);
8985
 
8986
//      $display("Commit Buses:");
8987
//      $display("  0: v=%d id=%o data=%h", commit0_v, commit0_id, commit0_bus);
8988
//      $display("  1: v=%d id=%o data=%h", commit1_v, commit1_id, commit1_bus);
8989
 
8990
//
8991
//      $display("Memory Contents:");
8992
//      for (j=0; j<64; j=j+16)
8993
//          $display("  %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h", 
8994
//              m[j+0], m[j+1], m[j+2], m[j+3], m[j+4], m[j+5], m[j+6], m[j+7],
8995
//              m[j+8], m[j+9], m[j+10], m[j+11], m[j+12], m[j+13], m[j+14], m[j+15]);
8996
 
8997
        $display("");
8998
 
8999
        if (|panic) begin
9000
            $display("");
9001
            $display("-----------------------------------------------------------------");
9002
            $display("-----------------------------------------------------------------");
9003
            $display("---------------     PANIC:%s     -----------------", message[panic]);
9004
            $display("-----------------------------------------------------------------");
9005
            $display("-----------------------------------------------------------------");
9006
            $display("");
9007
            $display("instructions committed: %d", I);
9008
            $display("total execution cycles: %d", $time / 10);
9009
            $display("");
9010
        end
9011
        if (|panic && ~outstanding_stores) begin
9012
            $finish;
9013
        end
9014
/*
9015
    for (n = 0; n < QENTRIES; n = n + 1)
9016
        if (branchmiss) begin
9017
            if (!setpred[n]) begin
9018
                 iqentry_instr[n][`INSTRUCTION_OP] <= `NOP;
9019
                 iqentry_done[n] <= iqentry_v[n];
9020
                 iqentry_cmt[n] <= iqentry_v[n];
9021
            end
9022
        end
9023
*/
9024
        rf_source[ 0] <= {`QBIT{1'b1}};
9025
        rf_source[32] <= {`QBIT{1'b1}};
9026
        rf_source[64] <= {`QBIT{1'b1}};
9027
        rf_source[96] <= {`QBIT{1'b1}};
9028
`ifdef SUPPORTSMT
9029
        rf_source[128] <= {`QBIT{1'b1}};
9030
        rf_source[160] <= {`QBIT{1'b1}};
9031
        rf_source[192] <= {`QBIT{1'b1}};
9032
        rf_source[224] <= {`QBIT{1'b1}};
9033
`endif
9034
 
9035
end // clock domain
9036
/*
9037
always @(posedge clk)
9038
if (rst) begin
9039
     tail0 <= 3'd0;
9040
     tail1 <= 3'd1;
9041
end
9042
else begin
9043
if (!branchmiss) begin
9044
    case({fetchbuf0_v, fetchbuf1_v})
9045
    2'b00:  ;
9046
    2'b01:
9047
        if (canq1) begin
9048
             tail0 <= idp1(tail0);
9049
             tail1 <= idp1(tail1);
9050
        end
9051
    2'b10:
9052
        if (canq1) begin
9053
             tail0 <= idp1(tail0);
9054
             tail1 <= idp1(tail1);
9055
        end
9056
    2'b11:
9057
        if (canq1) begin
9058
            if (IsBranch(fetchbuf0_instr) && predict_taken0) begin
9059
                 tail0 <= idp1(tail0);
9060
                 tail1 <= idp1(tail1);
9061
            end
9062
            else begin
9063
                                if (vqe < vl || !IsVector(fetchbuf0_instr)) begin
9064
                        if (canq2) begin
9065
                             tail0 <= idp2(tail0);
9066
                             tail1 <= idp2(tail1);
9067
                        end
9068
                        else begin    // queued1 will be true
9069
                             tail0 <= idp1(tail0);
9070
                             tail1 <= idp1(tail1);
9071
                        end
9072
                end
9073
            end
9074
        end
9075
    endcase
9076
end
9077
else begin      // if branchmiss
9078
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
9079
         tail0 <= 3'd0;
9080
         tail1 <= 3'd1;
9081
    end
9082
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
9083
         tail0 <= 3'd1;
9084
         tail1 <= 3'd2;
9085
    end
9086
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
9087
         tail0 <= 3'd2;
9088
         tail1 <= 3'd3;
9089
    end
9090
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
9091
         tail0 <= 3'd3;
9092
         tail1 <= 3'd4;
9093
    end
9094
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
9095
         tail0 <= 3'd4;
9096
         tail1 <= 3'd5;
9097
    end
9098
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
9099
         tail0 <= 3'd5;
9100
         tail1 <= 3'd6;
9101
    end
9102
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
9103
         tail0 <= 3'd6;
9104
         tail1 <= 3'd7;
9105
    end
9106
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
9107
         tail0 <= 3'd7;
9108
         tail1 <= 3'd0;
9109
    end
9110
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
9111
end
9112
end
9113
*/
9114 61 robfinch
assign exc_o = iqentry_exc[heads[0]][7:0];
9115 60 robfinch
 
9116
// Update the write buffer.
9117
task wb_update;
9118
input [`QBITS] id;
9119
input rmw;
9120
input [7:0] sel;
9121
input [1:0] ol;
9122
input [`ABITS] addr;
9123
input [63:0] data;
9124
begin
9125
        if (wbm && wbptr > 1 && wb_addr[wbptr-1][AMSB:3]==addr[AMSB:3]
9126
         && wb_ol[wbptr-1]==ol && wb_rmw[wbptr-1]==rmw && wb_v[wbptr-1]) begin
9127
                // The write buffer is always shifted during the bus IDLE state. That means
9128
                // the data is out of place by a slot. The slot the data is moved from is
9129
                // invalidated.
9130
                wb_v[wbptr-2] <= `INV;
9131
                wb_v[wbptr-1] <= wb_en;
9132
                wb_id[wbptr-1] <= wb_id[wbptr-1] | (16'd1 << id);
9133
                wb_rmw[wbptr-1] <= rmw;
9134
                wb_ol[wbptr-1] <= ol;
9135
                wb_sel[wbptr-1] <= wb_sel[wbptr-1] | sel;
9136
                wb_addr[wbptr-1] <= wb_addr[wbptr-1];
9137
                wb_data[wbptr-1] <= wb_data[wbptr-1];
9138
                if (sel[0]) wb_data[wbptr-1][ 7: 0] <= data[ 7: 0];
9139
                if (sel[1]) wb_data[wbptr-1][15: 8] <= data[15: 8];
9140
                if (sel[2]) wb_data[wbptr-1][23:16] <= data[23:16];
9141
                if (sel[3]) wb_data[wbptr-1][31:24] <= data[31:24];
9142
                if (sel[4]) wb_data[wbptr-1][39:32] <= data[39:32];
9143
                if (sel[5]) wb_data[wbptr-1][47:40] <= data[47:40];
9144
                if (sel[6]) wb_data[wbptr-1][55:48] <= data[55:48];
9145
                if (sel[7]) wb_data[wbptr-1][63:56] <= data[63:56];
9146
                wb_merges <= wb_merges + 32'd1;
9147
        end
9148
        else begin
9149
                wb_v[wbptr] <= wb_en;
9150
                wb_id[wbptr] <= (16'd1 << id);
9151
                wb_rmw[wbptr] <= rmw;
9152
                wb_ol[wbptr] <= ol;
9153
                wb_sel[wbptr] <= sel;
9154
                wb_addr[wbptr] <= {addr[AMSB:3],3'b0};
9155
                wb_data[wbptr] <= data;
9156
                wbptr <= wbptr + 2'd1;
9157
        end
9158
end
9159
endtask
9160
 
9161
// Increment the head pointers
9162
// Also increments the instruction counter
9163
// Used when instructions are committed.
9164
// Also clear any outstanding state bits that foul things up.
9165
//
9166
task head_inc;
9167
input [`QBITS] amt;
9168
begin
9169
        for (n = 0; n < QENTRIES; n = n + 1)
9170
     heads[n] <= (heads[n] + amt) % QENTRIES;
9171
        CC <= CC + amt;
9172
    if (amt==3'd3) begin
9173
        I = I + iqentry_v[heads[0]] + iqentry_v[heads[1]] + iqentry_v[heads[2]];
9174
        iqentry_state[heads[0]] <= IQS_INVALID;
9175
        iqentry_state[heads[1]] <= IQS_INVALID;
9176
        iqentry_state[heads[2]] <= IQS_INVALID;
9177
        iqentry_mem[heads[0]] <= `FALSE;
9178
        iqentry_mem[heads[1]] <= `FALSE;
9179
        iqentry_mem[heads[2]] <= `FALSE;
9180
        iqentry_iv[heads[0]] <= `INV;
9181
        iqentry_iv[heads[1]] <= `INV;
9182
        iqentry_iv[heads[2]] <= `INV;
9183
        iqentry_alu[heads[0]] <= `FALSE;
9184
        iqentry_alu[heads[1]] <= `FALSE;
9185
        iqentry_alu[heads[2]] <= `FALSE;
9186
                for (n = 0; n < QENTRIES; n = n + 1)
9187
                        if (iqentry_v[n])
9188
                                iqentry_sn[n] <= iqentry_sn[n] - (iqentry_v[heads[2]] ? iqentry_sn[heads[2]]
9189
                                                                                                                                                         : iqentry_v[heads[1]] ? iqentry_sn[heads[1]]
9190
                                                                                                                                                         : iqentry_v[heads[0]] ? iqentry_sn[heads[0]]
9191
                                                                                                                                                         : 4'b0);
9192
        end
9193
    else if (amt==3'd2) begin
9194
        I = I + iqentry_v[heads[0]] + iqentry_v[heads[1]];
9195
        iqentry_state[heads[0]] <= IQS_INVALID;
9196
        iqentry_state[heads[1]] <= IQS_INVALID;
9197
     iqentry_mem[heads[0]] <= `FALSE;
9198
     iqentry_mem[heads[1]] <= `FALSE;
9199
     iqentry_iv[heads[0]] <= `INV;
9200
     iqentry_iv[heads[1]] <= `INV;
9201
        iqentry_alu[heads[0]] <= `FALSE;
9202
     iqentry_alu[heads[1]] <= `FALSE;
9203
                for (n = 0; n < QENTRIES; n = n + 1)
9204
                        if (iqentry_v[n])
9205
                                iqentry_sn[n] <= iqentry_sn[n] - (iqentry_v[heads[1]] ? iqentry_sn[heads[1]]
9206
                                                                                                                                                         : iqentry_v[heads[0]] ? iqentry_sn[heads[0]]
9207
                                                                                                                                                         : 4'b0);
9208
    end else if (amt==3'd1) begin
9209
        I = I + iqentry_v[heads[0]];
9210
        iqentry_state[heads[0]] <= IQS_INVALID;
9211
            iqentry_mem[heads[0]] <= `FALSE;
9212
        iqentry_iv[heads[0]] <= `INV;
9213
        iqentry_alu[heads[0]] <= `FALSE;
9214
                for (n = 0; n < QENTRIES; n = n + 1)
9215
                        if (iqentry_v[n])
9216
                                iqentry_sn[n] <= iqentry_sn[n] - (iqentry_v[heads[0]] ? iqentry_sn[heads[0]]
9217
                                                                                                                                                         : 4'b0);
9218
        end
9219
end
9220
endtask
9221
 
9222
task setargs;
9223
input [`QBITS] nn;
9224
input [`QBITSP1] id;
9225
input v;
9226
input [63:0] bus;
9227
begin
9228
  if (iqentry_a1_v[nn] == `INV && iqentry_a1_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9229
                iqentry_a1[nn] <= bus;
9230
                iqentry_a1_v[nn] <= `VAL;
9231
  end
9232
  if (iqentry_a2_v[nn] == `INV && iqentry_a2_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9233
                iqentry_a2[nn] <= bus;
9234
                iqentry_a2_v[nn] <= `VAL;
9235
  end
9236
  if (iqentry_a3_v[nn] == `INV && iqentry_a3_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9237
                iqentry_a3[nn] <= bus;
9238
                iqentry_a3_v[nn] <= `VAL;
9239
  end
9240
end
9241
endtask
9242
 
9243
task setinsn1;
9244
input [`QBITS] nn;
9245
input [143:0] bus;
9246
begin
9247
        iqentry_iv   [nn]  <= `VAL;
9248
//      iqentry_Rt   [nn]  <= bus[`IB_RT];
9249
//      iqentry_Rc   [nn]  <= bus[`IB_RC];
9250
//      iqentry_Ra   [nn]  <= bus[`IB_RA];
9251
        iqentry_a0       [nn]  <= bus[`IB_CONST];
9252
        iqentry_imm  [nn]  <= bus[`IB_IMM];
9253
//              iqentry_insln[nn]  <= bus[`IB_LN];
9254
`ifndef INLINE_DECODE
9255
        if (iqentry_insln[nn] != bus[`IB_LN]) begin
9256
                $display("Insn length mismatch.");
9257
                $stop;
9258
        end
9259
`endif
9260
        iqentry_cmp      [nn]  <= bus[`IB_CMP];
9261
        iqentry_tlb  [nn]  <= bus[`IB_TLB];
9262
        iqentry_sz   [nn]  <= bus[`IB_SZ];
9263
        iqentry_jal      [nn]  <= bus[`IB_JAL];
9264
        iqentry_ret  [nn]  <= bus[`IB_RET];
9265
        iqentry_irq  [nn]  <= bus[`IB_IRQ];
9266
        iqentry_brk      [nn]  <= bus[`IB_BRK];
9267
        iqentry_rti  [nn]  <= bus[`IB_RTI];
9268
        iqentry_bt   [nn]  <= bus[`IB_BT];
9269
        iqentry_alu  [nn]  <= bus[`IB_ALU];
9270
        iqentry_alu0 [nn]  <= bus[`IB_ALU0];
9271
        iqentry_fpu  [nn]  <= bus[`IB_FPU];
9272
        iqentry_fc   [nn]  <= bus[`IB_FC];
9273
        iqentry_canex[nn]  <= bus[`IB_CANEX];
9274
        iqentry_loadv[nn]  <= bus[`IB_LOADV];
9275
        iqentry_load [nn]  <= bus[`IB_LOAD];
9276 61 robfinch
        iqentry_loadseg[nn]<= bus[`IB_LOADSEG];
9277 60 robfinch
        iqentry_preload[nn]<= bus[`IB_PRELOAD];
9278
        iqentry_store[nn]  <= bus[`IB_STORE];
9279
        iqentry_push [nn]  <= bus[`IB_PUSH];
9280
        iqentry_oddball[nn] <= bus[`IB_ODDBALL];
9281
        iqentry_memsz[nn]  <= bus[`IB_MEMSZ];
9282
        iqentry_mem  [nn]  <= bus[`IB_MEM];
9283
        iqentry_memndx[nn] <= bus[`IB_MEMNDX];
9284
        iqentry_rmw  [nn]  <= bus[`IB_RMW];
9285
        iqentry_memdb[nn]  <= bus[`IB_MEMDB];
9286
        iqentry_memsb[nn]  <= bus[`IB_MEMSB];
9287
        iqentry_shft [nn]  <= bus[`IB_SHFT];    // 48 bit shift instructions
9288
        iqentry_sei      [nn]    <= bus[`IB_SEI];
9289
        iqentry_aq   [nn]  <= bus[`IB_AQ];
9290
        iqentry_rl   [nn]  <= bus[`IB_RL];
9291
        iqentry_jmp  [nn]  <= bus[`IB_JMP];
9292
        iqentry_br   [nn]  <= bus[`IB_BR];
9293
        iqentry_sync [nn]  <= bus[`IB_SYNC];
9294
        iqentry_fsync[nn]  <= bus[`IB_FSYNC];
9295
        iqentry_rfw  [nn]  <= bus[`IB_RFW];
9296
        iqentry_we   [nn]  <= bus[`IB_WE];
9297
end
9298
endtask
9299
 
9300
task setinsn;
9301
input [`QBITS] nn;
9302
input [4:0] id;
9303
input v;
9304
input [143:0] bus;
9305
begin
9306
  if (iqentry_iv[nn] == `INV && iqentry_is[nn] == id && iqentry_v[nn] == `VAL && v == `VAL)
9307
        setinsn1(nn,bus);
9308
end
9309
endtask
9310
 
9311
task a1_vs;
9312
begin
9313
        // if there is not an overlapping write to the register file.
9314
        if (Ra1s != Rt0s || !fetchbuf0_rfw) begin
9315
                iqentry_a1_v [tail1] <= regIsValid[Ra1s];
9316
                iqentry_a1_s [tail1] <= rf_source [Ra1s];
9317
        end
9318
        else begin
9319
                iqentry_a1_v [tail1] <= `INV;
9320
                iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_mem, tail0 };
9321
        end
9322
end
9323
endtask
9324
 
9325
task a2_vs;
9326
begin
9327
        // if there is not an overlapping write to the register file.
9328
        if (Rb1s != Rt0s || !fetchbuf0_rfw) begin
9329
                iqentry_a2_v [tail1] <= regIsValid[Rb1s];
9330
                iqentry_a2_s [tail1] <= rf_source [Rb1s];
9331
        end
9332
        else begin
9333
                iqentry_a2_v [tail1] <= `INV;
9334
                iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_mem, tail0 };
9335
        end
9336
end
9337
endtask
9338
 
9339
task a3_vs;
9340
begin
9341
        // if there is not an overlapping write to the register file.
9342
        if (Rc1s != Rt0s || !fetchbuf0_rfw) begin
9343
                iqentry_a3_v [tail1] <= regIsValid[Rc1s];
9344
                iqentry_a3_s [tail1] <= rf_source [Rc1s];
9345
        end
9346
        else begin
9347
                iqentry_a3_v [tail1] <= `INV;
9348
                iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_mem, tail0 };
9349
        end
9350
end
9351
endtask
9352
 
9353
task enque0x;
9354
begin
9355
        if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
9356
                vqe0 <= vqe0 + 4'd1;
9357
                if (IsVCmprss(fetchbuf0_instr)) begin
9358
                        if (vm[fetchbuf0_instr[25:23]][vqe0])
9359
                        vqet0 <= vqet0 + 4'd1;
9360
                end
9361
                else
9362
                        vqet0 <= vqet0 + 4'd1;
9363
                if (vqe0 >= vl-2)
9364
                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
9365
                enque0(tail0, fetchbuf0_thrd ? maxsn[1]+4'd1 : maxsn[0]+4'd1, vqe0);
9366
                iq_ctr = iq_ctr + 4'd1;
9367
                if (fetchbuf0_rfw) begin
9368
                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_mem, tail0 };    // top bit indicates ALU/MEM bus
9369
                        rf_v[Rt0s] <= `INV;
9370
                end
9371
                if (canq2) begin
9372
                        if (vqe0 < vl-2) begin
9373
                                vqe0 <= vqe0 + 4'd2;
9374
                                if (IsVCmprss(fetchbuf0_instr)) begin
9375
                                        if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
9376
                                                vqet0 <= vqet0 + 4'd2;
9377
                                end
9378
                                else
9379
                                        vqet0 <= vqet0 + 4'd2;
9380
                                enque0(tail1, fetchbuf0_thrd ? maxsn[1] + 4'd2 : maxsn[0]+4'd2, vqe0 + 6'd1);
9381
                                iq_ctr = iq_ctr + 4'd2;
9382
                                if (fetchbuf0_rfw) begin
9383
                                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_mem, tail1 };    // top bit indicates ALU/MEM bus
9384
                                        rf_v[Rt0s] <= `INV;
9385
                                end
9386
                        end
9387
                end
9388
        end
9389
        else begin
9390
                enque0(tail0, fetchbuf0_thrd ? maxsn[1]+4'd1 : maxsn[0]+4'd1, 6'd0);
9391
                iq_ctr = iq_ctr + 4'd1;
9392
                if (fetchbuf0_rfw) begin
9393
                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_mem, tail0 };    // top bit indicates ALU/MEM bus
9394
                        rf_v[Rt0s] <= `INV;
9395
                end
9396
        end
9397
end
9398
endtask
9399
 
9400
// Enqueue fetchbuf0 onto the tail of the instruction queue
9401
task enque0;
9402
input [`QBITS] tail;
9403
input [`SNBITS] seqnum;
9404
input [5:0] venno;
9405
begin
9406 61 robfinch
        iqentry_exc[tail] <= `FLT_NONE;
9407 60 robfinch
`ifdef SUPPORT_DBG
9408
    if (dbg_imatchA)
9409
        iqentry_exc[tail] <= `FLT_DBG;
9410
    else if (dbg_ctrl[63])
9411
        iqentry_exc[tail] <= `FLT_SSM;
9412
`endif
9413
        iqentry_state[tail]    <= IQS_QUEUED;
9414
        iqentry_sn   [tail]    <=  seqnum;
9415
        iqentry_iv       [tail]    <=   `INV;
9416
        iqentry_is   [tail]    <= tail;
9417
        iqentry_thrd [tail]    <=   fetchbuf0_thrd;
9418
        iqentry_res  [tail]    <=    `ZERO;
9419
        iqentry_instr[tail]    <=    IsVLS(fetchbuf0_instr) ? (vm[fnM2(fetchbuf0_instr)] ? fetchbuf0_instr : `NOP_INSN) : fetchbuf0_instr;
9420
        iqentry_insln[tail]              <=  fetchbuf0_insln;
9421
        iqentry_fc   [tail]    <=  `INV;
9422
        iqentry_mem      [tail]          <=  `INV;
9423 61 robfinch
        iqentry_memissue[tail] <=  `INV;
9424 60 robfinch
        iqentry_alu      [tail]          <=  `INV;
9425
        iqentry_fpu      [tail]          <=  `INV;
9426
        iqentry_load [tail]              <=  `INV;
9427
        iqentry_pt   [tail]    <=  predict_taken0;
9428
// If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9429
// inherit the previous pc.
9430
//if (IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15] &&
9431
//   (IsBrk(iqentry_instr[idm1(tail)]) && !iqentry_instr[idm1(tail1)][15] && iqentry_v[idm1(tail)]))
9432
//   iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
9433
//else
9434
         iqentry_pc   [tail] <= fetchbuf0_pc;
9435
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf0_instr);
9436
        iqentry_tgt  [tail]    <=       Rt0;
9437
        iqentry_Ra   [tail]    <= Ra0;
9438
        iqentry_Rb   [tail]    <= Rb0;
9439
        iqentry_Rc   [tail]    <= Rc0;
9440
        iqentry_vl   [tail]    <=  vl;
9441
        iqentry_ven  [tail]    <=   venno;
9442
        iqentry_exc  [tail]    <=    `EXC_NONE;
9443
        iqentry_a1   [tail]    <=    rfoa0;
9444
        iqentry_a1_v [tail]    <=    Source1Valid(fetchbuf0_instr) | regIsValid[Ra0s];
9445
        iqentry_a1_s [tail]    <=    rf_source[Ra0s];
9446
        iqentry_a2   [tail]    <=    rfob0;
9447
        iqentry_a2_v [tail]    <=    Source2Valid(fetchbuf0_instr) | regIsValid[Rb0s];
9448
        iqentry_a2_s [tail]    <=    rf_source[Rb0s];
9449
        iqentry_a3   [tail]    <=    rfoc0;
9450
        iqentry_a3_v [tail]    <=    Source3Valid(fetchbuf0_instr) | regIsValid[Rc0s];
9451
        iqentry_a3_s [tail]    <=    rf_source[Rc0s];
9452
`ifdef INLINE_DECODE
9453
/* This decoding cannot be done here because it'll introduce a 1 cycle delay
9454
        id1_Rt <= Rt0[4:0];
9455
        id1_vl <= vl;
9456
        id1_ven <= venno;
9457
        id1_id <= tail;
9458
        id1_pt <= predict_taken0;
9459
        id1_thrd <= fetchbuf0_thrd;
9460
*/
9461
        setinsn1(tail,id1_bus);
9462
`endif
9463
end
9464
endtask
9465
 
9466
// Enque fetchbuf1. Fetchbuf1 might be the second instruction to queue so some
9467
// of this code checks to see which tail it is being queued on.
9468
task enque1;
9469
input [`QBITS] tail;
9470
input [`SNBITS] seqnum;
9471
input [5:0] venno;
9472
begin
9473
 iqentry_exc[tail] <= `FLT_NONE;
9474
`ifdef SUPPORT_DBG
9475
    if (dbg_imatchB)
9476
        iqentry_exc[tail] <= `FLT_DBG;
9477
    else if (dbg_ctrl[63])
9478
        iqentry_exc[tail] <= `FLT_SSM;
9479
`endif
9480
        iqentry_state[tail]    <= IQS_QUEUED;
9481
        iqentry_sn   [tail]    <=   seqnum;
9482
        iqentry_iv       [tail]    <=   `INV;
9483
        iqentry_is   [tail]    <= tail;
9484
        iqentry_thrd [tail]    <=   fetchbuf1_thrd;
9485
        iqentry_res  [tail]    <=   `ZERO;
9486
        iqentry_instr[tail]    <=   IsVLS(fetchbuf1_instr) ? (vm[fnM2(fetchbuf1_instr)] ? fetchbuf1_instr : `NOP_INSN) : fetchbuf1_instr;
9487
        iqentry_insln[tail]              <=  fetchbuf1_insln;
9488
        iqentry_fc   [tail]    <=  `INV;
9489
        iqentry_mem      [tail]          <=  `INV;
9490 61 robfinch
        iqentry_memissue[tail] <=  `INV;
9491 60 robfinch
        iqentry_alu      [tail]          <=  `INV;
9492
        iqentry_fpu      [tail]          <=  `INV;
9493
        iqentry_load [tail]              <=  `INV;
9494
        iqentry_pt   [tail]    <=  predict_taken1;
9495
// If queing 2nd instruction must read from first
9496
if (tail==tail1) begin
9497
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9498
    // inherit the previous pc.
9499
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
9500
//        IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15])
9501
//       iqentry_pc   [tail]    <= fetchbuf0_pc;
9502
//    else
9503
                iqentry_pc   [tail] <= fetchbuf1_pc;
9504
end
9505
else begin
9506
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9507
    // inherit the previous pc.
9508
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
9509
//       (IsBrk(iqentry_instr[idp7(tail)]) && !iqentry_instr[idm1(tail)][15] && iqentry_v[idm1(tail)]))
9510
//       iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
9511
//    else
9512
                iqentry_pc   [tail] <= fetchbuf1_pc;
9513
end
9514
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf1_instr);
9515
        iqentry_tgt  [tail]    <= Rt1;
9516
        iqentry_Ra   [tail]    <= Ra1;
9517
        iqentry_Rb   [tail]    <= Rb1;
9518
        iqentry_Rc   [tail]    <= Rc1;
9519
        iqentry_vl   [tail]    <=  vl;
9520
        iqentry_ven  [tail]    <=   venno;
9521
        iqentry_exc  [tail]    <=   `EXC_NONE;
9522
        iqentry_a1   [tail]    <=       rfoa1;
9523
        iqentry_a1_v [tail]    <=       Source1Valid(fetchbuf1_instr) | regIsValid[Ra1s];
9524
        iqentry_a1_s [tail]    <=       rf_source[Ra1s];
9525
        iqentry_a2   [tail]    <=       rfob1;
9526
        iqentry_a2_v [tail]    <=       Source2Valid(fetchbuf1_instr) | regIsValid[Rb1s];
9527
        iqentry_a2_s [tail]    <=       rf_source[Rb1s];
9528
        iqentry_a3   [tail]    <=       rfoc1;
9529
        iqentry_a3_v [tail]    <=       Source3Valid(fetchbuf1_instr) | regIsValid[Rc1s];
9530
        iqentry_a3_s [tail]    <=       rf_source[Rc1s];
9531
`ifdef INLINE_DECODE
9532
/* This decoding cannot be done here because it'll introduce a 1 cycle delay
9533
        id2_Rt <= Rt1[4:0];
9534
        id2_vl <= vl;
9535
        id2_ven <= venno;
9536
        id2_id <= tail;
9537
        id2_pt <= predict_taken1;
9538
        id2_thrd <= fetchbuf1_thrd;
9539
*/
9540
        setinsn1(tail,id2_bus);
9541
`endif
9542
end
9543
endtask
9544
 
9545 61 robfinch
task exc;
9546
input [`QBITS] head;
9547
input thread;
9548
input [7:0] causecd;
9549
begin
9550
  excmiss <= TRUE;
9551
`ifdef SUPPORT_SMT
9552
        excmisspc <= {tvec[3'd0][AMSB:8],1'b0,ol[thread],5'h00};
9553
  excthrd <= iqentry_thrd[head];
9554
  badaddr[{thread,2'd0}] <= iqentry_ma[head];
9555
  bad_instr[{thread,2'd0}] <= iqentry_instr[head];
9556
  epc0[thread] <= iqentry_pc[head];
9557
  epc1[thread] <= epc0[thread];
9558
  epc2[thread] <= epc1[thread];
9559
  epc3[thread] <= epc2[thread];
9560
  epc4[thread] <= epc3[thread];
9561
  epc5[thread] <= epc4[thread];
9562
  epc6[thread] <= epc5[thread];
9563
  epc7[thread] <= epc6[thread];
9564
  epc8[thread] <= epc7[thread];
9565
  im_stack[thread] <= {im_stack[thread][27:0],im};
9566
  ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9567
  dl_stack[thread] <= {dl_stack[thread][13:0],dl[thread]};
9568
  pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9569
  rs_stack[thread] <= {rs_stack[thread][59:0],`EXC_RGS};
9570
  brs_stack[thread] <= {brs_stack[thread][59:0],`EXC_RGS};
9571
  cause[{thread,2'd0}] <= {8'd0,causecd};
9572
  mstatus[thread][5:4] <= 2'd0;
9573
  mstatus[thread][13:6] <= 8'h00;
9574
  mstatus[thread][19:14] <= `EXC_RGS;
9575
`else
9576
        excmisspc <= {tvec[3'd0][AMSB:8],1'b0,ol,5'h00};
9577
  excthrd <= 1'b0;
9578
  badaddr[{1'b0,2'd0}] <= iqentry_ma[head];
9579
  bad_instr[3'd0] <= iqentry_instr[head];
9580
  epc0 <= iqentry_pc[head];
9581
  epc1 <= epc0;
9582
  epc2 <= epc1;
9583
  epc3 <= epc2;
9584
  epc4 <= epc3;
9585
  epc5 <= epc4;
9586
  epc6 <= epc5;
9587
  epc7 <= epc6;
9588
  epc8 <= epc7;
9589
  im_stack <= {im_stack[27:0],im};
9590
  ol_stack <= {ol_stack[13:0],ol};
9591
  dl_stack <= {dl_stack[13:0],dl};
9592
  pl_stack <= {pl_stack[55:0],cpl};
9593
  rs_stack <= {rs_stack[59:0],`EXC_RGS};
9594
  brs_stack <= {rs_stack[59:0],`EXC_RGS};
9595
  cause[3'd0] <= {8'd0,causecd};
9596
  mstatus[5:4] <= 2'd0;
9597
  mstatus[13:6] <= 8'h00;
9598
  mstatus[19:14] <= `EXC_RGS;
9599
`endif
9600
        wb_en <= `TRUE;
9601
  sema[0] <= 1'b0;
9602
  ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9603
`ifdef SUPPORT_DBG
9604
  dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9605
  dbg_ctrl[63] <= FALSE;
9606
`endif
9607
end
9608
endtask
9609
 
9610 60 robfinch
// This task takes care of commits for things other than the register file.
9611
task oddball_commit;
9612
input v;
9613
input [`QBITS] head;
9614
input [1:0] which;
9615
reg thread;
9616
begin
9617
    thread = iqentry_thrd[head];
9618
    if (v) begin
9619
        if (|iqentry_exc[head]) begin
9620 61 robfinch
                exc(head,thread,iqentry_exc[head]);
9621 60 robfinch
        end
9622
        else
9623
        case(iqentry_instr[head][`INSTRUCTION_OP])
9624
        `BRK:
9625
                        // BRK is treated as a nop unless it's a software interrupt or a
9626
                        // hardware interrupt at a higher priority than the current priority.
9627
            if ((|iqentry_instr[head][25:21]) || iqentry_instr[head][20:17] > im) begin
9628
                    excmiss <= TRUE;
9629
`ifdef SUPPORT_SMT
9630
                        excmisspc <= {tvec[3'd0][AMSB:8],1'b0,ol[thread],5'h00};
9631
                        excthrd <= iqentry_thrd[head];
9632
              epc0[thread] <= iqentry_pc[head] + {iqentry_instr[head][25:21],1'b0};
9633
              epc1[thread] <= epc0[thread];
9634
              epc2[thread] <= epc1[thread];
9635
              epc3[thread] <= epc2[thread];
9636
              epc4[thread] <= epc3[thread];
9637
              epc5[thread] <= epc4[thread];
9638
              epc6[thread] <= epc5[thread];
9639
              epc7[thread] <= epc6[thread];
9640
              epc8[thread] <= epc7[thread];
9641
              im_stack[thread] <= {im_stack[thread][27:0],im};
9642
              ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9643
              dl_stack[thread] <= {dl_stack[thread][13:0],dl[thread]};
9644
              pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9645
              rs_stack[thread] <= {rs_stack[thread][59:0],`BRK_RGS};
9646
              brs_stack[thread] <= {brs_stack[thread][59:0],`BRK_RGS};
9647
              cause[{thread,2'd0}] <= iqentry_res[head][7:0];
9648
              mstatus[thread][5:4] <= 2'd0;
9649
              mstatus[thread][13:6] <= 8'h00;
9650
              // For hardware interrupts only, set a new mask level. Setting a
9651
              // new mask level will effectively prevent subsequent brks that
9652
              // are streaming from an interrupt from being processed.
9653
              // Select register set according to interrupt level
9654
              if (iqentry_instr[head][25:21]==5'd0) begin
9655
                mstatus[thread][ 3: 0] <= iqentry_instr[head][20:17];
9656
                mstatus[thread][31:28] <= iqentry_instr[head][20:17];
9657
                mstatus[thread][19:14] <= {2'b0,iqentry_instr[head][20:17]};
9658
                rs_stack[thread][5:0] <= {2'b0,iqentry_instr[head][20:17]};
9659
                brs_stack[thread][5:0] <= {2'b0,iqentry_instr[head][20:17]};
9660
              end
9661
              else begin
9662
                mstatus[thread][19:14] <= `BRK_RGS;
9663
                rs_stack[thread][5:0] <= `BRK_RGS;
9664
                brs_stack[thread][5:0] <= `BRK_RGS;
9665
              end
9666
`else
9667
                        excmisspc <= {tvec[3'd0][AMSB:8],1'b0,ol,5'h00};
9668
                        excthrd <= 1'b0;
9669
              epc0 <= iqentry_pc[head] + {iqentry_instr[head][25:21],1'b0};
9670
              epc1 <= epc0;
9671
              epc2 <= epc1;
9672
              epc3 <= epc2;
9673
              epc4 <= epc3;
9674
              epc5 <= epc4;
9675
              epc6 <= epc5;
9676
              epc7 <= epc6;
9677
              epc8 <= epc7;
9678
              im_stack <= {im_stack[27:0],im};
9679
              ol_stack <= {ol_stack[13:0],ol};
9680
              dl_stack <= {dl_stack[13:0],dl};
9681
              pl_stack <= {pl_stack[55:0],cpl};
9682
              rs_stack <= {rs_stack[59:0],`BRK_RGS};
9683
              brs_stack <= {brs_stack[59:0],`BRK_RGS};
9684
              cause[3'd0] <= iqentry_res[head][7:0];
9685
              mstatus[5:4] <= 2'd0;
9686
              mstatus[13:6] <= 8'h00;
9687
              // For hardware interrupts only, set a new mask level. Setting a
9688
              // new mask level will effectively prevent subsequent brks that
9689
              // are streaming from an interrupt from being processed.
9690
              // Select register set according to interrupt level
9691
              if (iqentry_instr[head][25:21]==5'd0) begin
9692
                mstatus[ 3: 0] <= iqentry_instr[head][20:17];
9693
                mstatus[31:28] <= iqentry_instr[head][20:17];
9694
                mstatus[19:14] <= {2'b0,iqentry_instr[head][20:17]};
9695
                rs_stack[5:0] <= {2'b0,iqentry_instr[head][20:17]};
9696
                brs_stack[5:0] <= {2'b0,iqentry_instr[head][20:17]};
9697
              end
9698
              else begin
9699
                mstatus[19:14] <= `BRK_RGS;
9700
                rs_stack[5:0] <= `BRK_RGS;
9701
                brs_stack[5:0] <= `BRK_RGS;
9702
              end
9703
`endif
9704
              sema[0] <= 1'b0;
9705
              ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9706
`ifdef SUPPORT_DBG
9707
              dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9708
              dbg_ctrl[63] <= FALSE;
9709
`endif
9710
            end
9711
        `IVECTOR:
9712
            casez(iqentry_tgt[head])
9713
            8'b00100???:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9714
            8'b00101111:  vl <= iqentry_res[head];
9715
            default:    ;
9716
            endcase
9717
        `R2:
9718
            case(iqentry_instr[head][`INSTRUCTION_S2])
9719
            `R1:        case(iqentry_instr[head][20:16])
9720
                        `CHAIN_OFF:     cr0[18] <= 1'b0;
9721
                        `CHAIN_ON:      cr0[18] <= 1'b1;
9722
                        //`SETWB:               wbrcd[pcr[5:0]] <= 1'b1;
9723
                        default:        ;
9724
                                endcase
9725
            `VMOV:  casez(iqentry_tgt[head])
9726
                    12'b1111111_00???:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9727
                    12'b1111111_01111:  vl <= iqentry_res[head];
9728
                    default:    ;
9729
                    endcase
9730
`ifdef SUPPORT_SMT
9731
            `SEI:   mstatus[thread][3:0] <= iqentry_res[head][3:0];   // S1
9732
`else
9733
            `SEI:   mstatus[3:0] <= iqentry_res[head][3:0];   // S1
9734
`endif
9735
            `RTI:   begin
9736
                            excmiss <= TRUE;
9737 61 robfinch
                        excthrd <= thread;
9738
                                                excmisspc <= iqentry_ma[head];
9739 60 robfinch
`ifdef SUPPORT_SMT
9740 61 robfinch
//                      excmisspc <= epc0[thread];
9741 60 robfinch
                        mstatus[thread][3:0] <= im_stack[thread][3:0];
9742
                        mstatus[thread][5:4] <= ol_stack[thread][1:0];
9743
                        mstatus[thread][21:20] <= dl_stack[thread][1:0];
9744
                        mstatus[thread][13:6] <= pl_stack[thread][7:0];
9745
                        mstatus[thread][19:14] <= rs_stack[thread][5:0];
9746
                        im_stack[thread] <= {4'd15,im_stack[thread][31:4]};
9747
                        ol_stack[thread] <= {2'd0,ol_stack[thread][15:2]};
9748
                        dl_stack[thread] <= {2'd0,dl_stack[thread][15:2]};
9749
                        pl_stack[thread] <= {8'h00,pl_stack[thread][63:8]};
9750
                        rs_stack[thread] <= {6'h00,rs_stack[thread][59:6]};
9751
                        brs_stack[thread] <= {6'h00,brs_stack[thread][59:6]};
9752
                epc0[thread] <= epc1[thread];
9753
                epc1[thread] <= epc2[thread];
9754
                epc2[thread] <= epc3[thread];
9755
                epc3[thread] <= epc4[thread];
9756
                epc4[thread] <= epc5[thread];
9757
                epc5[thread] <= epc6[thread];
9758
                epc6[thread] <= epc7[thread];
9759
                epc7[thread] <= epc8[thread];
9760
                epc8[thread] <= {tvec[0][AMSB:8], 1'b0, ol[thread], 5'h0};
9761
`else
9762 61 robfinch
//                      excmisspc <= epc0;
9763 60 robfinch
                        mstatus[3:0] <= im_stack[3:0];
9764
                        mstatus[5:4] <= ol_stack[1:0];
9765
                        mstatus[21:20] <= dl_stack[1:0];
9766
                        mstatus[13:6] <= pl_stack[7:0];
9767
                        mstatus[19:14] <= rs_stack[5:0];
9768
                        im_stack <= {4'd15,im_stack[31:4]};
9769
                        ol_stack <= {2'd0,ol_stack[15:2]};
9770
                        dl_stack <= {2'd0,dl_stack[15:2]};
9771
                        pl_stack <= {8'h00,pl_stack[63:8]};
9772
                        rs_stack <= {6'h00,rs_stack[59:6]};
9773
                        brs_stack <= {6'h00,brs_stack[59:6]};
9774
                epc0 <= epc1;
9775
                epc1 <= epc2;
9776
                epc2 <= epc3;
9777
                epc3 <= epc4;
9778
                epc4 <= epc5;
9779
                epc5 <= epc6;
9780
                epc6 <= epc7;
9781
                epc7 <= epc8;
9782
                epc8 <= {tvec[0][AMSB:8], 1'b0, ol, 5'h0};
9783
`endif
9784
                sema[0] <= 1'b0;
9785
                sema[iqentry_res[head][5:0]] <= 1'b0;
9786
                vqe0  <= ve_hold[ 5: 0];
9787
                vqet0 <= ve_hold[21:16];
9788
                vqe1  <= ve_hold[37:32];
9789
                vqet1 <= ve_hold[53:48];
9790
`ifdef SUPPORT_DBG
9791
                      dbg_ctrl[62:55] <= {FALSE,dbg_ctrl[62:56]};
9792
                      dbg_ctrl[63] <= dbg_ctrl[55];
9793
`endif
9794
              end
9795
            default: ;
9796
            endcase
9797
        `MEMNDX:
9798
            case(iqentry_instr[head][`INSTRUCTION_S2])
9799
            `CACHEX:
9800
                    case(iqentry_instr[head][22:18])
9801
                    5'h03:  invic <= TRUE;
9802
                    5'h10:  cr0[30] <= FALSE;
9803
                    5'h11:  cr0[30] <= TRUE;
9804
                    default:    ;
9805
                    endcase
9806
            default: ;
9807
            endcase
9808
        `CSRRW:
9809
                        begin
9810
                        write_csr(iqentry_instr[head][31:18],iqentry_a1[head],thread);
9811
                        end
9812
        `REX:
9813
`ifdef SUPPORT_SMT
9814
            // Can only redirect to a lower level
9815
            if (ol[thread] < iqentry_instr[head][14:13]) begin
9816
                mstatus[thread][5:4] <= iqentry_instr[head][14:13];
9817
                badaddr[{thread,iqentry_instr[head][14:13]}] <= badaddr[{thread,ol[thread]}];
9818
                bad_instr[{thread,iqentry_instr[head][14:13]}] <= bad_instr[{thread,ol[thread]}];
9819
                cause[{thread,iqentry_instr[head][14:13]}] <= cause[{thread,ol[thread]}];
9820
                mstatus[thread][13:6] <= iqentry_instr[head][25:18] | iqentry_a1[head][7:0];
9821
            end
9822
`else
9823
            if (ol < iqentry_instr[head][14:13]) begin
9824
                mstatus[5:4] <= iqentry_instr[head][14:13];
9825
                badaddr[{1'b0,iqentry_instr[head][14:13]}] <= badaddr[{1'b0,ol}];
9826
                bad_instr[{1'b0,iqentry_instr[head][14:13]}] <= bad_instr[{1'b0,ol}];
9827
                cause[{1'b0,iqentry_instr[head][14:13]}] <= cause[{1'b0,ol}];
9828
                mstatus[13:6] <= iqentry_instr[head][25:18] | iqentry_a1[head][7:0];
9829
            end
9830
`endif
9831
        `CACHE:
9832
            case(iqentry_instr[head][17:13])
9833
            5'h03:  invic <= TRUE;
9834
            5'h10:  cr0[30] <= FALSE;
9835
            5'h11:  cr0[30] <= TRUE;
9836
            default:    ;
9837
            endcase
9838
        `FLOAT:
9839
            case(iqentry_instr[head][`INSTRUCTION_S2])
9840
            `FRM: begin
9841
                                fp_rm <= iqentry_res[head][2:0];
9842
                                end
9843
            `FCX:
9844
                begin
9845
                    fp_sx <= fp_sx & ~iqentry_res[head][5];
9846
                    fp_inex <= fp_inex & ~iqentry_res[head][4];
9847
                    fp_dbzx <= fp_dbzx & ~(iqentry_res[head][3]|iqentry_res[head][0]);
9848
                    fp_underx <= fp_underx & ~iqentry_res[head][2];
9849
                    fp_overx <= fp_overx & ~iqentry_res[head][1];
9850
                    fp_giopx <= fp_giopx & ~iqentry_res[head][0];
9851
                    fp_infdivx <= fp_infdivx & ~iqentry_res[head][0];
9852
                    fp_zerozerox <= fp_zerozerox & ~iqentry_res[head][0];
9853
                    fp_subinfx   <= fp_subinfx   & ~iqentry_res[head][0];
9854
                    fp_infzerox  <= fp_infzerox  & ~iqentry_res[head][0];
9855
                    fp_NaNCmpx   <= fp_NaNCmpx   & ~iqentry_res[head][0];
9856
                    fp_swtx <= 1'b0;
9857
                end
9858
            `FDX:
9859
                begin
9860
                    fp_inexe <= fp_inexe     & ~iqentry_res[head][4];
9861
                    fp_dbzxe <= fp_dbzxe     & ~iqentry_res[head][3];
9862
                    fp_underxe <= fp_underxe & ~iqentry_res[head][2];
9863
                    fp_overxe <= fp_overxe   & ~iqentry_res[head][1];
9864
                    fp_invopxe <= fp_invopxe & ~iqentry_res[head][0];
9865
                end
9866
            `FEX:
9867
                begin
9868
                    fp_inexe <= fp_inexe     | iqentry_res[head][4];
9869
                    fp_dbzxe <= fp_dbzxe     | iqentry_res[head][3];
9870
                    fp_underxe <= fp_underxe | iqentry_res[head][2];
9871
                    fp_overxe <= fp_overxe   | iqentry_res[head][1];
9872
                    fp_invopxe <= fp_invopxe | iqentry_res[head][0];
9873
                end
9874
            default:
9875
                begin
9876
                    // 31 to 29 is rounding mode
9877
                    // 28 to 24 are exception enables
9878
                    // 23 is nsfp
9879
                    // 22 is a fractie
9880
                    fp_fractie <= iqentry_ares[head][22];
9881
                    fp_raz <= iqentry_ares[head][21];
9882
                    // 20 is a 0
9883
                    fp_neg <= iqentry_ares[head][19];
9884
                    fp_pos <= iqentry_ares[head][18];
9885
                    fp_zero <= iqentry_ares[head][17];
9886
                    fp_inf <= iqentry_ares[head][16];
9887
                    // 15 swtx
9888
                    // 14 
9889
                    fp_inex <= fp_inex | (fp_inexe & iqentry_ares[head][14]);
9890
                    fp_dbzx <= fp_dbzx | (fp_dbzxe & iqentry_ares[head][13]);
9891
                    fp_underx <= fp_underx | (fp_underxe & iqentry_ares[head][12]);
9892
                    fp_overx <= fp_overx | (fp_overxe & iqentry_ares[head][11]);
9893
                    //fp_giopx <= fp_giopx | (fp_giopxe & iqentry_res2[head][10]);
9894
                    //fp_invopx <= fp_invopx | (fp_invopxe & iqentry_res2[head][24]);
9895
                    //
9896
                    fp_cvtx <= fp_cvtx |  (fp_giopxe & iqentry_ares[head][7]);
9897
                    fp_sqrtx <= fp_sqrtx |  (fp_giopxe & iqentry_ares[head][6]);
9898
                    fp_NaNCmpx <= fp_NaNCmpx |  (fp_giopxe & iqentry_ares[head][5]);
9899
                    fp_infzerox <= fp_infzerox |  (fp_giopxe & iqentry_ares[head][4]);
9900
                    fp_zerozerox <= fp_zerozerox |  (fp_giopxe & iqentry_ares[head][3]);
9901
                    fp_infdivx <= fp_infdivx | (fp_giopxe & iqentry_ares[head][2]);
9902
                    fp_subinfx <= fp_subinfx | (fp_giopxe & iqentry_ares[head][1]);
9903
                    fp_snanx <= fp_snanx | (fp_giopxe & iqentry_ares[head][0]);
9904
 
9905
                end
9906
            endcase
9907
        default:    ;
9908
        endcase
9909
        // Once the flow control instruction commits, NOP it out to allow
9910
        // pending stores to be issued.
9911
        iqentry_instr[head][5:0] <= `NOP;
9912
    end
9913
end
9914
endtask
9915
 
9916
// CSR access tasks
9917
// This task does not work. Possibly because the always block @* doesn't
9918
// evaluate into the task to see which signals are changing. The following
9919
// code is simply included as an always block above.
9920
task read_csr;
9921
input [11:0] csrno;
9922
output [63:0] dat;
9923
input thread;
9924
begin
9925
`ifdef SUPPORT_SMT
9926
    if (csrno[11:10] >= ol[thread])
9927
`else
9928
    if (csrno[11:10] >= ol)
9929
`endif
9930
    casez(csrno[9:0])
9931
    `CSR_CR0:       dat <= cr0;
9932
    `CSR_HARTID:    dat <= hartid;
9933
    `CSR_TICK:      dat <= tick;
9934
    `CSR_PCR:       dat <= pcr;
9935
    `CSR_PCR2:      dat <= pcr2;
9936
    `CSR_PMR:                           dat <= pmr;
9937
    `CSR_WBRCD:         dat <= wbrcd;
9938
    `CSR_SEMA:      dat <= sema;
9939
    `CSR_KEYS:                  dat <= keys;
9940
    `CSR_TCB:           dat <= tcb;
9941
    `CSR_FSTAT:     dat <= {fp_rgs,fp_status};
9942
`ifdef SUPPORT_DBG
9943
    `CSR_DBAD0:     dat <= dbg_adr0;
9944
    `CSR_DBAD1:     dat <= dbg_adr1;
9945
    `CSR_DBAD2:     dat <= dbg_adr2;
9946
    `CSR_DBAD3:     dat <= dbg_adr3;
9947
    `CSR_DBCTRL:    dat <= dbg_ctrl;
9948
    `CSR_DBSTAT:    dat <= dbg_stat;
9949
`endif
9950
    `CSR_CAS:       dat <= cas;
9951
    `CSR_TVEC:      dat <= tvec[csrno[2:0]];
9952
    `CSR_BADADR:    dat <= badaddr[{thread,csrno[11:10]}];
9953
    `CSR_BADINSTR:      dat <= bad_instr[{thread,csrno[11:10]}];
9954
    `CSR_CAUSE:     dat <= {48'd0,cause[{thread,csrno[11:10]}]};
9955
`ifdef SUPPORT_SMT
9956
    `CSR_IM_STACK:      dat <= im_stack[thread];
9957
    `CSR_OL_STACK:      dat <= {dl_stack[thread],ol_stack[thread]};
9958
    `CSR_PL_STACK:      dat <= pl_stack[thread];
9959
    `CSR_RS_STACK:      dat <= rs_stack[thread];
9960
    `CSR_STATUS:    dat <= mstatus[thread][63:0];
9961
    `CSR_EPC0:      dat <= epc0[thread];
9962
    `CSR_EPC1:      dat <= epc1[thread];
9963
    `CSR_EPC2:      dat <= epc2[thread];
9964
    `CSR_EPC3:      dat <= epc3[thread];
9965
    `CSR_EPC4:      dat <= epc4[thread];
9966
    `CSR_EPC5:      dat <= epc5[thread];
9967
    `CSR_EPC6:      dat <= epc6[thread];
9968
    `CSR_EPC7:      dat <= epc7[thread];
9969
`else
9970
    `CSR_IM_STACK:      dat <= im_stack;
9971
    `CSR_OL_STACK:      dat <= {dl_stack,ol_stack};
9972
    `CSR_PL_STACK:      dat <= pl_stack;
9973
    `CSR_RS_STACK:      dat <= rs_stack;
9974
    `CSR_STATUS:    dat <= mstatus[63:0];
9975
    `CSR_EPC0:      dat <= epc0;
9976
    `CSR_EPC1:      dat <= epc1;
9977
    `CSR_EPC2:      dat <= epc2;
9978
    `CSR_EPC3:      dat <= epc3;
9979
    `CSR_EPC4:      dat <= epc4;
9980
    `CSR_EPC5:      dat <= epc5;
9981
    `CSR_EPC6:      dat <= epc6;
9982
    `CSR_EPC7:      dat <= epc7;
9983
`endif
9984
    `CSR_CODEBUF:   dat <= codebuf[csrno[5:0]];
9985
`ifdef SUPPORT_BBMS
9986
                `CSR_TB:                        dat <= tb;
9987
                `CSR_CBL:                       dat <= cbl;
9988
                `CSR_CBU:                       dat <= cbu;
9989
                `CSR_RO:                        dat <= ro;
9990
                `CSR_DBL:                       dat <= dbl;
9991
                `CSR_DBU:                       dat <= dbu;
9992
                `CSR_SBL:                       dat <= sbl;
9993
                `CSR_SBU:                       dat <= sbu;
9994
                `CSR_ENU:                       dat <= en;
9995
`endif
9996
    `CSR_Q_CTR:         dat <= iq_ctr;
9997
    `CSR_BM_CTR:        dat <= bm_ctr;
9998
    `CSR_ICL_CTR:       dat <= icl_ctr;
9999
    `CSR_IRQ_CTR:       dat <= irq_ctr;
10000
    `CSR_TIME:          dat <= wc_times;
10001
    `CSR_INFO:
10002
                    case(csrno[3:0])
10003
                    4'd0:   dat <= "Finitron";  // manufacturer
10004
                    4'd1:   dat <= "        ";
10005
                    4'd2:   dat <= "64 bit  ";  // CPU class
10006
                    4'd3:   dat <= "        ";
10007
                    4'd4:   dat <= "FT64    ";  // Name
10008
                    4'd5:   dat <= "        ";
10009
                    4'd6:   dat <= 64'd1;       // model #
10010
                    4'd7:   dat <= 64'd1;       // serial number
10011
                    4'd8:   dat <= {32'd16384,32'd16384};   // cache sizes instruction,data
10012
                    4'd9:   dat <= 64'd0;
10013
                    default:    dat <= 64'd0;
10014
                    endcase
10015
    default:    begin
10016
                        $display("Unsupported CSR:%h",csrno[10:0]);
10017
                        dat <= 64'hEEEEEEEEEEEEEEEE;
10018
                        end
10019
    endcase
10020
    else
10021
        dat <= 64'h0;
10022
end
10023
endtask
10024
 
10025
task write_csr;
10026
input [13:0] csrno;
10027
input [63:0] dat;
10028
input thread;
10029
begin
10030
`ifdef SUPPORT_SMT
10031
    if (csrno[11:10] >= ol[thread])
10032
`else
10033
    if (csrno[11:10] >= ol)
10034
`endif
10035
    case(csrno[13:12])
10036
    2'd1:   // CSRRW
10037
        casez(csrno[9:0])
10038
        `CSR_CR0:       cr0 <= dat;
10039
        `CSR_PCR:       pcr <= dat[31:0];
10040
        `CSR_PCR2:      pcr2 <= dat;
10041
        `CSR_PMR:       case(`NUM_IDU)
10042
                                                0,1:     pmr[0] <= 1'b1;
10043
                                                2:
10044
                                                        begin
10045
                                                                        if (dat[1:0]==2'b00)
10046
                                                                                pmr[1:0] <= 2'b01;
10047
                                                                        else
10048
                                                                                pmr[1:0] <= dat[1:0];
10049
                                                                        pmr[63:2] <= dat[63:2];
10050
                                                                end
10051
                                                3:
10052
                                                        begin
10053
                                                                        if (dat[2:0]==3'b000)
10054
                                                                                pmr[2:0] <= 3'b001;
10055
                                                                        else
10056
                                                                                pmr[2:0] <= dat[2:0];
10057
                                                                        pmr[63:3] <= dat[63:3];
10058
                                                                end
10059
                                                default:        pmr[0] <= 1'b1;
10060
                                                endcase
10061
        `CSR_WBRCD:             wbrcd <= dat;
10062
        `CSR_SEMA:      sema <= dat;
10063
        `CSR_KEYS:      keys <= dat;
10064
        `CSR_TCB:               tcb <= dat;
10065
        `CSR_FSTAT:             fpu_csr[37:32] <= dat[37:32];
10066
        `CSR_BADADR:    badaddr[{thread,csrno[11:10]}] <= dat;
10067
        `CSR_BADINSTR:  bad_instr[{thread,csrno[11:10]}] <= dat;
10068
        `CSR_CAUSE:     cause[{thread,csrno[11:10]}] <= dat[15:0];
10069
`ifdef SUPPORT_DBG
10070
        `CSR_DBAD0:     dbg_adr0 <= dat[AMSB:0];
10071
        `CSR_DBAD1:     dbg_adr1 <= dat[AMSB:0];
10072
        `CSR_DBAD2:     dbg_adr2 <= dat[AMSB:0];
10073
        `CSR_DBAD3:     dbg_adr3 <= dat[AMSB:0];
10074
        `CSR_DBCTRL:    dbg_ctrl <= dat;
10075
`endif
10076
        `CSR_CAS:       cas <= dat;
10077
        `CSR_TVEC:      tvec[csrno[2:0]] <= dat[31:0];
10078
`ifdef SUPPORT_SMT
10079
        `CSR_IM_STACK:  im_stack[thread] <= dat[31:0];
10080
        `CSR_OL_STACK:  begin
10081
                                                                        ol_stack[thread] <= dat[15:0];
10082
                                                                        dl_stack[thread] <= dat[31:16];
10083
                                                                        end
10084
        `CSR_PL_STACK:  pl_stack[thread] <= dat;
10085
        `CSR_RS_STACK:  rs_stack[thread] <= dat;
10086
        `CSR_STATUS:    mstatus[thread][63:0] <= dat;
10087
        `CSR_EPC0:      epc0[thread] <= dat;
10088
        `CSR_EPC1:      epc1[thread] <= dat;
10089
        `CSR_EPC2:      epc2[thread] <= dat;
10090
        `CSR_EPC3:      epc3[thread] <= dat;
10091
        `CSR_EPC4:      epc4[thread] <= dat;
10092
        `CSR_EPC5:      epc5[thread] <= dat;
10093
        `CSR_EPC6:      epc6[thread] <= dat;
10094
        `CSR_EPC7:      epc7[thread] <= dat;
10095
`else
10096
        `CSR_IM_STACK:  im_stack <= dat[31:0];
10097
        `CSR_OL_STACK:  begin
10098
                                                                        ol_stack <= dat[15:0];
10099
                                                                        dl_stack <= dat[31:16];
10100
                                                                        end
10101
        `CSR_PL_STACK:  pl_stack <= dat;
10102
        `CSR_RS_STACK:  rs_stack <= dat;
10103
        `CSR_STATUS:    mstatus[63:0] <= dat;
10104
        `CSR_EPC0:      epc0 <= dat;
10105
        `CSR_EPC1:      epc1 <= dat;
10106
        `CSR_EPC2:      epc2 <= dat;
10107
        `CSR_EPC3:      epc3 <= dat;
10108
        `CSR_EPC4:      epc4 <= dat;
10109
        `CSR_EPC5:      epc5 <= dat;
10110
        `CSR_EPC6:      epc6 <= dat;
10111
        `CSR_EPC7:      epc7 <= dat;
10112
`endif
10113
`ifdef SUPPORT_BBMS
10114
                                `CSR_TB:                        prg_base[brgs] <= dat;
10115
                                `CSR_CBL:                       cl_barrier[brgs] <= dat;
10116
                                `CSR_CBU:                       cu_barrier[brgs] <= dat;
10117
                                `CSR_RO:                        ro_barrier[brgs] <= dat;
10118
                                `CSR_DBL:                       dl_barrier[brgs] <= dat;
10119
                                `CSR_DBU:                       du_barrier[brgs] <= dat;
10120
                                `CSR_SBL:                       sl_barrier[brgs] <= dat;
10121
                                `CSR_SBU:                       su_barrier[brgs] <= dat;
10122
                                `CSR_ENU:                       en_barrier[brgs] <= dat;
10123
`endif
10124
                                `CSR_TIME:              begin
10125
                                                ld_time <= 6'h3f;
10126
                                                wc_time_dat <= dat;
10127
                                                end
10128
        `CSR_CODEBUF:   codebuf[csrno[5:0]] <= dat;
10129
        default:    ;
10130
        endcase
10131
    2'd2:   // CSRRS
10132
        case(csrno[9:0])
10133
        `CSR_CR0:       cr0 <= cr0 | dat;
10134
        `CSR_PCR:       pcr[31:0] <= pcr[31:0] | dat[31:0];
10135
        `CSR_PCR2:      pcr2 <= pcr2 | dat;
10136
        `CSR_PMR:                               pmr <= pmr | dat;
10137
        `CSR_WBRCD:             wbrcd <= wbrcd | dat;
10138
`ifdef SUPPORT_DBG
10139
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl | dat;
10140
`endif
10141
        `CSR_SEMA:      sema <= sema | dat;
10142
`ifdef SUPPORT_SMT
10143
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] | dat;
10144
`else
10145
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] | dat;
10146
`endif
10147
        default:    ;
10148
        endcase
10149
    2'd3:   // CSRRC
10150
        case(csrno[9:0])
10151
        `CSR_CR0:       cr0 <= cr0 & ~dat;
10152
        `CSR_PCR:       pcr <= pcr & ~dat;
10153
        `CSR_PCR2:      pcr2 <= pcr2 & ~dat;
10154
        `CSR_PMR:                       begin
10155
                                                                if (dat[1:0]==2'b11)
10156
                                                                        pmr[1:0] <= 2'b01;
10157
                                                                else
10158
                                                                        pmr[1:0] <= pmr[1:0] & ~dat[1:0];
10159
                                                                pmr[63:2] <= pmr[63:2] & ~dat[63:2];
10160
                                                                end
10161
        `CSR_WBRCD:             wbrcd <= wbrcd & ~dat;
10162
`ifdef SUPPORT_DBG
10163
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl & ~dat;
10164
`endif
10165
        `CSR_SEMA:      sema <= sema & ~dat;
10166
`ifdef SUPPORT_SMT
10167
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] & ~dat;
10168
`else
10169
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] & ~dat;
10170
`endif
10171
        default:    ;
10172
        endcase
10173
    default:    ;
10174
    endcase
10175
end
10176
endtask
10177
 
10178
task tDram0Issue;
10179
input [`QBITSP1] n;
10180
begin
10181 61 robfinch
        if (iqentry_state[n]==IQS_AGEN) begin
10182 60 robfinch
//      dramA_v <= `INV;
10183 61 robfinch
                dram0           <= `DRAMSLOT_BUSY;
10184
                dram0_id        <= { 1'b1, n[`QBITS] };
10185
                dram0_instr <= iqentry_instr[n];
10186
                dram0_rmw  <= iqentry_rmw[n];
10187
                dram0_preload <= iqentry_preload[n];
10188
                dram0_tgt       <= iqentry_tgt[n];
10189
                if (iqentry_imm[n] & iqentry_push[n])
10190
                        dram0_data <= iqentry_a0[n];
10191
                else
10192
                        dram0_data <= iqentry_a2[n];
10193
                dram0_addr      <= iqentry_ma[n];
10194
                dram0_unc   <= iqentry_ma[n][31:20]==12'hFFD || !dce || iqentry_loadv[n];
10195
                dram0_memsize <= iqentry_memsz[n];
10196
                dram0_load <= iqentry_load[n];
10197
                dram0_loadseg <= iqentry_loadseg[n];
10198
                dram0_store <= iqentry_store[n];
10199 60 robfinch
`ifdef SUPPORT_SMT
10200 61 robfinch
                dram0_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
10201 60 robfinch
`else
10202 61 robfinch
                dram0_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol : dl;
10203 60 robfinch
`endif
10204
        // Once the memory op is issued reset the a1_v flag.
10205
        // This will cause the a1 bus to look for new data from memory (a1_s is pointed to a memory bus)
10206
        // This is used for the load and compare instructions.
10207
        // must reset the a1 source too.
10208
        //iqentry_a1_v[n] <= `INV;
10209 61 robfinch
                iqentry_state[n] <= IQS_MEM;
10210
        end
10211 60 robfinch
end
10212
endtask
10213
 
10214
task tDram1Issue;
10215
input [`QBITSP1] n;
10216
begin
10217 61 robfinch
        if (iqentry_state[n]==IQS_AGEN) begin
10218
//      dramB_v <= `INV;
10219 60 robfinch
        dram1           <= `DRAMSLOT_BUSY;
10220
        dram1_id        <= { 1'b1, n[`QBITS] };
10221
        dram1_instr <= iqentry_instr[n];
10222
        dram1_rmw  <= iqentry_rmw[n];
10223
        dram1_preload <= iqentry_preload[n];
10224
        dram1_tgt       <= iqentry_tgt[n];
10225 61 robfinch
        if (iqentry_imm[n] & iqentry_push[n])
10226
                dram1_data <= iqentry_a0[n];
10227
        else
10228
                dram1_data <= iqentry_a2[n];
10229 60 robfinch
        dram1_addr      <= iqentry_ma[n];
10230
        //                   if (ol[iqentry_thrd[n]]==`OL_USER)
10231
        //                      dram1_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
10232
        //                   else
10233
        dram1_unc   <= iqentry_ma[n][31:20]==12'hFFD || !dce || iqentry_loadv[n];
10234
        dram1_memsize <= iqentry_memsz[n];
10235
        dram1_load <= iqentry_load[n];
10236 61 robfinch
        dram1_loadseg <= iqentry_loadseg[n];
10237 60 robfinch
        dram1_store <= iqentry_store[n];
10238
`ifdef SUPPORT_SMT
10239
        dram1_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
10240
`else
10241
        dram1_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol : dl;
10242
`endif
10243
        //iqentry_a1_v[n] <= `INV;
10244
        iqentry_state[n] <= IQS_MEM;
10245 61 robfinch
        end
10246 60 robfinch
end
10247
endtask
10248
 
10249
task tDram2Issue;
10250
input [`QBITSP1] n;
10251
begin
10252 61 robfinch
        if (iqentry_state[n]==IQS_AGEN) begin
10253
//      dramC_v <= `INV;
10254 60 robfinch
        dram2           <= `DRAMSLOT_BUSY;
10255
        dram2_id        <= { 1'b1, n[`QBITS] };
10256
        dram2_instr     <= iqentry_instr[n];
10257
        dram2_rmw  <= iqentry_rmw[n];
10258
        dram2_preload <= iqentry_preload[n];
10259
        dram2_tgt       <= iqentry_tgt[n];
10260 61 robfinch
        if (iqentry_imm[n] & iqentry_push[n])
10261
                dram2_data <= iqentry_a0[n];
10262
        else
10263
                dram2_data <= iqentry_a2[n];
10264 60 robfinch
        dram2_addr      <= iqentry_ma[n];
10265
        //                   if (ol[iqentry_thrd[n]]==`OL_USER)
10266
        //                      dram2_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
10267
        //                   else
10268
        dram2_unc   <= iqentry_ma[n][31:20]==12'hFFD || !dce || iqentry_loadv[n];
10269
        dram2_memsize <= iqentry_memsz[n];
10270
        dram2_load <= iqentry_load[n];
10271 61 robfinch
        dram2_loadseg <= iqentry_loadseg[n];
10272 60 robfinch
        dram2_store <= iqentry_store[n];
10273
`ifdef SUPPORT_SMT
10274
        dram2_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
10275
`else
10276
        dram2_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol : dl;
10277
`endif
10278
        //iqentry_a1_v[n] <= `INV;
10279
        iqentry_state[n] <= IQS_MEM;
10280 61 robfinch
        end
10281 60 robfinch
end
10282
endtask
10283
 
10284
task wb_nack;
10285
begin
10286
        cti_o <= 3'b000;
10287
        bte_o <= 2'b00;
10288
        cyc <= `LOW;
10289
        stb_o <= `LOW;
10290
        we <= `LOW;
10291
        sel_o <= 8'h00;
10292 61 robfinch
//      vadr <= 32'hCCCCCCCC;
10293 60 robfinch
end
10294
endtask
10295
 
10296
endmodule
10297
 
10298
 
10299
module decoder5 (num, out);
10300
input [4:0] num;
10301
output [31:1] out;
10302
reg [31:1] out;
10303
 
10304
always @(num)
10305
case (num)
10306
    5'd0 :      out <= 31'b0000000000000000000000000000000;
10307
    5'd1 :      out <= 31'b0000000000000000000000000000001;
10308
    5'd2 :      out <= 31'b0000000000000000000000000000010;
10309
    5'd3 :      out <= 31'b0000000000000000000000000000100;
10310
    5'd4 :      out <= 31'b0000000000000000000000000001000;
10311
    5'd5 :      out <= 31'b0000000000000000000000000010000;
10312
    5'd6 :      out <= 31'b0000000000000000000000000100000;
10313
    5'd7 :      out <= 31'b0000000000000000000000001000000;
10314
    5'd8 :      out <= 31'b0000000000000000000000010000000;
10315
    5'd9 :      out <= 31'b0000000000000000000000100000000;
10316
    5'd10:      out <= 31'b0000000000000000000001000000000;
10317
    5'd11:      out <= 31'b0000000000000000000010000000000;
10318
    5'd12:      out <= 31'b0000000000000000000100000000000;
10319
    5'd13:      out <= 31'b0000000000000000001000000000000;
10320
    5'd14:      out <= 31'b0000000000000000010000000000000;
10321
    5'd15:      out <= 31'b0000000000000000100000000000000;
10322
    5'd16:      out <= 31'b0000000000000001000000000000000;
10323
    5'd17:      out <= 31'b0000000000000010000000000000000;
10324
    5'd18:      out <= 31'b0000000000000100000000000000000;
10325
    5'd19:      out <= 31'b0000000000001000000000000000000;
10326
    5'd20:      out <= 31'b0000000000010000000000000000000;
10327
    5'd21:      out <= 31'b0000000000100000000000000000000;
10328
    5'd22:      out <= 31'b0000000001000000000000000000000;
10329
    5'd23:      out <= 31'b0000000010000000000000000000000;
10330
    5'd24:      out <= 31'b0000000100000000000000000000000;
10331
    5'd25:      out <= 31'b0000001000000000000000000000000;
10332
    5'd26:      out <= 31'b0000010000000000000000000000000;
10333
    5'd27:      out <= 31'b0000100000000000000000000000000;
10334
    5'd28:      out <= 31'b0001000000000000000000000000000;
10335
    5'd29:      out <= 31'b0010000000000000000000000000000;
10336
    5'd30:      out <= 31'b0100000000000000000000000000000;
10337
    5'd31:      out <= 31'b1000000000000000000000000000000;
10338
endcase
10339
 
10340
endmodule
10341
 
10342
module decoder6 (num, out);
10343
input [5:0] num;
10344
output [63:1] out;
10345
 
10346
wire [63:0] out1;
10347
 
10348
assign out1 = 64'd1 << num;
10349
assign out = out1[63:1];
10350
 
10351
endmodule
10352
 
10353
module decoder7 (num, out);
10354
input [6:0] num;
10355
output [127:1] out;
10356
 
10357
wire [127:0] out1;
10358
 
10359
assign out1 = 128'd1 << num;
10360
assign out = out1[127:1];
10361
 
10362
endmodule
10363
 
10364
module decoder8 (num, out);
10365
input [7:0] num;
10366
output [255:1] out;
10367
 
10368
wire [255:0] out1;
10369
 
10370
assign out1 = 256'd1 << num;
10371
assign out = out1[255:1];
10372
 
10373
endmodule
10374
 

powered by: WebSVN 2.1.0

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