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

Subversion Repositories thor

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

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

Line No. Rev Author Line
1 60 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2017-2018  Robert Finch, Waterloo
4
//    \  __ /    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
    ol_o, pcr_o, pcr2_o, pkeys_o, icl_o, sr_o, cr_o, rbi_i, signal_i);
46
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
 
75
parameter TM_CLKFREQ = 20000000;
76
parameter QENTRIES = `QENTRIES;
77
parameter RSTPC = 64'hFFFFFFFFFFFC0100;
78
parameter BRKPC = 64'hFFFFFFFFFFFC0000;
79
`ifdef SUPPORT_SMT
80
parameter PREGS = 256;   // number of physical registers - 1
81
parameter AREGS = 256;   // number of architectural registers
82
`else
83
parameter PREGS = 128;
84
parameter AREGS = 128;
85
`endif
86
parameter RBIT = 11;
87
parameter DEBUG = 1'b0;
88
parameter NMAP = QENTRIES;
89
parameter BRANCH_PRED = 1'b0;
90
parameter SUP_TXE = 1'b0;
91
`ifdef SUPPORT_VECTOR
92
parameter SUP_VECTOR = 1'b1;
93
`else
94
parameter SUP_VECTOR = 1'b0;
95
`endif
96
parameter DBW = 64;
97
parameter ABW = 64;
98
parameter AMSB = ABW-1;
99
parameter NTHREAD = 1;
100
reg [7:0] i;
101
integer n;
102
integer j, k;
103
genvar g, h;
104
parameter TRUE = 1'b1;
105
parameter FALSE = 1'b0;
106
// Memory access sizes
107
parameter byt = 3'd0;
108
parameter wyde = 3'd1;
109
parameter tetra = 3'd2;
110
parameter octa = 3'd3;
111
// IQ states
112
parameter IQS_INVALID = 3'd0;
113
parameter IQS_QUEUED = 3'd1;
114
parameter IQS_OUT = 3'd2;
115
parameter IQS_AGEN = 3'd3;
116
parameter IQS_MEM = 3'd4;
117
parameter IQS_DONE = 3'd5;
118
parameter IQS_CMT = 3'd6;
119
 
120
wire clk;
121
//BUFG uclkb1
122
//(
123
//      .I(clk_i),
124
//      .O(clk)
125
//);
126
assign clk = clk_i;
127
 
128
wire exv_i;
129
wire rdv_i;
130
wire wrv_i;
131
reg [ABW-1:0] vadr;
132
reg cyc;
133
reg we;
134
 
135
wire dc_ack;
136
wire acki = ack_i|dc_ack;
137
wire [RBIT:0] Ra0, Ra1, Ra2;
138
wire [RBIT:0] Rb0, Rb1, Rb2;
139
wire [RBIT:0] Rc0, Rc1, Rc2;
140
wire [RBIT:0] Rt0, Rt1, Rt2;
141
wire [63:0] rfoa0,rfob0,rfoc0,rfoc0a,rfot0;
142
wire [63:0] rfoa1,rfob1,rfoc1,rfoc1a,rfot1;
143
wire [63:0] rfoa2,rfob2,rfoc2,rfoc2a,rfot2;
144
`ifdef SUPPORT_SMT
145
wire [7:0] Ra0s = {Ra0[7:0]};
146
wire [7:0] Ra1s = {Ra1[7:0]};
147
wire [7:0] Ra2s = {Ra2[7:0]};
148
wire [7:0] Rb0s = {Rb0[7:0]};
149
wire [7:0] Rb1s = {Rb1[7:0]};
150
wire [7:0] Rb2s = {Rb2[7:0]};
151
wire [7:0] Rc0s = {Rc0[7:0]};
152
wire [7:0] Rc1s = {Rc1[7:0]};
153
wire [7:0] Rc2s = {Rc2[7:0]};
154
wire [7:0] Rt0s = {Rt0[7:0]};
155
wire [7:0] Rt1s = {Rt1[7:0]};
156
wire [7:0] Rt2s = {Rt2[7:0]};
157
`else
158
wire [6:0] Ra0s = {Ra0[7],Ra0[5:0]};
159
wire [6:0] Ra1s = {Ra1[7],Ra1[5:0]};
160
wire [6:0] Ra2s = {Ra2[7],Ra2[5:0]};
161
wire [6:0] Rb0s = {Rb0[7],Rb0[5:0]};
162
wire [6:0] Rb1s = {Rb1[7],Rb1[5:0]};
163
wire [6:0] Rb2s = {Rb2[7],Rb2[5:0]};
164
wire [6:0] Rc0s = {Rc0[7],Rc0[5:0]};
165
wire [6:0] Rc1s = {Rc1[7],Rc1[5:0]};
166
wire [6:0] Rc2s = {Rc2[7],Rc2[5:0]};
167
wire [6:0] Rt0s = {Rt0[7],Rt0[5:0]};
168
wire [6:0] Rt1s = {Rt1[7],Rt1[5:0]};
169
wire [6:0] Rt2s = {Rt2[7],Rt2[5:0]};
170
/*
171
wire [5:0] Ra0s = {Ra0[5:0]};
172
wire [5:0] Ra1s = {Ra1[5:0]};
173
wire [5:0] Rb0s = {Rb0[5:0]};
174
wire [5:0] Rb1s = {Rb1[5:0]};
175
wire [5:0] Rc0s = {Rc0[5:0]};
176
wire [5:0] Rc1s = {Rc1[5:0]};
177
wire [5:0] Rt0s = {Rt0[5:0]};
178
wire [5:0] Rt1s = {Rt1[5:0]};
179
*/
180
`endif
181
 
182
`ifdef SUPPORT_PREDICATION
183
reg [3:0] pregs [0:1023];
184
`endif
185
 
186
reg [63:0] wbrcd;
187
wire [5:0] brgs;
188
`ifdef SUPPORT_SEGMENTATION
189
reg [23:0] currentCSSelector;
190
reg [63:0] zs_base [0:63];
191
reg [63:0] ds_base [0:63];
192
reg [63:0] es_base [0:63];
193
reg [63:0] fs_base [0:63];
194
reg [63:0] gs_base [0:63];
195
reg [63:0] hs_base [0:63];
196
reg [63:0] ss_base [0:63];
197
reg [63:0] cs_base [0:63];
198
reg [63:0] zsx_base;
199
reg [63:0] dsx_base;
200
reg [63:0] esx_base;
201
reg [63:0] fsx_base;
202
reg [63:0] gsx_base;
203
reg [63:0] hsx_base;
204
reg [63:0] ssx_base;
205
reg [63:0] csx_base;
206
reg [63:0] zs_lb [0:63];
207
reg [63:0] ds_lb [0:63];
208
reg [63:0] es_lb [0:63];
209
reg [63:0] fs_lb [0:63];
210
reg [63:0] gs_lb [0:63];
211
reg [63:0] hs_lb [0:63];
212
reg [63:0] ss_lb [0:63];
213
reg [63:0] cs_lb [0:63];
214
reg [63:0] zslb;
215
reg [63:0] dslb;
216
reg [63:0] eslb;
217
reg [63:0] fslb;
218
reg [63:0] gslb;
219
reg [63:0] hslb;
220
reg [63:0] sslb;
221
reg [63:0] cslb;
222
reg [63:0] zs_ub [0:63];
223
reg [63:0] ds_ub [0:63];
224
reg [63:0] es_ub [0:63];
225
reg [63:0] fs_ub [0:63];
226
reg [63:0] gs_ub [0:63];
227
reg [63:0] hs_ub [0:63];
228
reg [63:0] ss_ub [0:63];
229
reg [63:0] cs_ub [0:63];
230
reg [63:0] zsub;
231
reg [63:0] dsub;
232
reg [63:0] esub;
233
reg [63:0] fsub;
234
reg [63:0] gsub;
235
reg [63:0] hsub;
236
reg [63:0] ssub;
237
reg [63:0] csub;
238
reg [23:0] zs_sel [0:63];
239
reg [23:0] ds_sel [0:63];
240
reg [23:0] es_sel [0:63];
241
reg [23:0] fs_sel [0:63];
242
reg [23:0] gs_sel [0:63];
243
reg [23:0] hs_sel [0:63];
244
reg [23:0] ss_sel [0:63];
245
reg [23:0] cs_sel [0:63];
246
reg [15:0] zs_acr [0:63];
247
reg [15:0] ds_acr [0:63];
248
reg [15:0] es_acr [0:63];
249
reg [15:0] fs_acr [0:63];
250
reg [15:0] gs_acr [0:63];
251
reg [15:0] hs_acr [0:63];
252
reg [15:0] ss_acr [0:63];
253
reg [15:0] cs_acr [0:63];
254
initial begin
255
        for (n = 0; n < 64; n = n + 1) begin
256
                zs_base[n] <= 64'h0;
257
                ds_base[n] <= 64'h0;
258
                es_base[n] <= 64'h0;
259
                fs_base[n] <= 64'h0;
260
                gs_base[n] <= 64'h0;
261
                hs_base[n] <= 64'h0;
262
                ss_base[n] <= 64'h0;
263
                cs_base[n] <= 64'h0;
264
                zs_lb[n] <= 64'h0;
265
                ds_lb[n] <= 64'h0;
266
                es_lb[n] <= 64'h0;
267
                fs_lb[n] <= 64'h0;
268
                gs_lb[n] <= 64'h0;
269
                hs_lb[n] <= 64'h0;
270
                ss_lb[n] <= 64'h0;
271
                cs_lb[n] <= 64'h0;
272
                zs_ub[n] <= 64'hFFFFFFFFFFFFFFFF;
273
                ds_ub[n] <= 64'hFFFFFFFFFFFFFFFF;
274
                es_ub[n] <= 64'hFFFFFFFFFFFFFFFF;
275
                fs_ub[n] <= 64'hFFFFFFFFFFFFFFFF;
276
                gs_ub[n] <= 64'hFFFFFFFFFFFFFFFF;
277
                hs_ub[n] <= 64'hFFFFFFFFFFFFFFFF;
278
                ss_ub[n] <= 64'hFFFFFFFFFFFFFFFF;
279
                cs_ub[n] <= 64'hFFFFFFFFFFFFFFFF;
280
                zs_sel[n] <= 24'h0;
281
                ds_sel[n] <= 24'h0;
282
                es_sel[n] <= 24'h0;
283
                fs_sel[n] <= 24'h0;
284
                gs_sel[n] <= 24'h0;
285
                hs_sel[n] <= 24'h0;
286
                ss_sel[n] <= 24'h0;
287
                cs_sel[n] <= 24'h0;
288
                zs_acr[n] <= 16'h8000;
289
                ds_acr[n] <= 16'h9200;
290
                es_acr[n] <= 16'h8000;
291
                fs_acr[n] <= 16'h8000;
292
                gs_acr[n] <= 16'h8000;
293
                hs_acr[n] <= 16'h8000;
294
                ss_acr[n] <= 16'h9600;
295
                cs_acr[n] <= 16'h9A00;
296
        end
297
end
298
always @(posedge clk_i)
299
begin
300
        zsx_base <= zs_base[brgs];
301
        dsx_base <= ds_base[brgs];
302
        esx_base <= es_base[brgs];
303
        fsx_base <= fs_base[brgs];
304
        gsx_base <= gs_base[brgs];
305
        hsx_base <= hs_base[brgs];
306
        ssx_base <= ss_base[brgs];
307
        csx_base <= cs_base[brgs];
308
        zsub <= zs_ub[brgs];
309
        dsub <= ds_ub[brgs];
310
        esub <= es_ub[brgs];
311
        fsub <= fs_ub[brgs];
312
        gsub <= gs_ub[brgs];
313
        hsub <= hs_ub[brgs];
314
        ssub <= ss_ub[brgs];
315
        csub <= cs_ub[brgs];
316
        zslb <= zs_lb[brgs];
317
        dslb <= ds_lb[brgs];
318
        eslb <= es_lb[brgs];
319
        fslb <= fs_lb[brgs];
320
        gslb <= gs_lb[brgs];
321
        hslb <= hs_lb[brgs];
322
        sslb <= ss_lb[brgs];
323
        cslb <= cs_lb[brgs];
324
        currentCSSelector <= cs_sel[brgs];
325
end
326
`endif
327
`ifdef SUPPORT_BBMS
328
reg [15:0] thrd_handle [0:63];
329
reg [63:0] prg_base [0:63];
330
reg [63:0] prg_limit [0:63];
331
reg [63:0] en_barrier [0:63];                                     // environment bound
332
reg [63:0] cl_barrier [0:63];
333
reg [63:0] cu_barrier [0:63];
334
reg [63:0] ro_barrier [0:63];
335
reg [63:0] dl_barrier [0:63];
336
reg [63:0] du_barrier [0:63];
337
reg [63:0] sl_barrier [0:63];
338
reg [63:0] su_barrier [0:63];
339
reg [7:0] env_priv [0:63];
340
reg [7:0] cod_priv [0:63];
341
reg [7:0] rdo_priv [0:63];
342
reg [7:0] dat_priv [0:63];
343
reg [7:0] stk_priv [0:63];
344
reg [15:0] th;
345
reg [63:0] pb;
346
reg [63:0] cbl;
347
reg [63:0] cbu;
348
reg [63:0] ro;
349
reg [63:0] dbl;
350
reg [63:0] dbu;
351
reg [63:0] sbl;
352
reg [63:0] sbu;
353
reg [63:0] en;
354
reg [7:0] env_pl;
355
reg [7:0] cod_pl;
356
reg [7:0] rdo_pl;
357
reg [7:0] dat_pl;
358
reg [7:0] stk_pl;
359
initial begin
360
        for (n = 0; n < 64; n = n + 1)
361
        begin
362
                thrd_handle[n] <= 1'd0;
363
                prg_base[n] <= 1'd0;
364
                cl_barrier[n] <= 1'd0;
365
                cu_barrier[n] <= 64'hFFFFFFFFFFFFFFFF;
366
                ro_barrier[n] <= 1'd0;
367
                dl_barrier[n] <= 1'd0;
368
                du_barrier[n] <= 64'hFFFFFFFFFFFFFFFF;
369
                sl_barrier[n] <= 1'd0;
370
                su_barrier[n] <= 64'hFFFFFFFFFFFFFFFF;
371
                env_priv[n] <= 8'h00;
372
                cod_priv[n] <= 8'h00;
373
                rdo_priv[n] <= 8'h00;
374
                dat_priv[n] <= 8'h00;
375
                stk_priv[n] <= 8'h00;
376
        end
377
end
378
always @(posedge clk_i)
379
begin
380
        th <= thrd_handle[brgs];
381
        pb <= prg_base[brgs];
382
        cbl <= cl_barrier[brgs];
383
        cbu <= cu_barrier[brgs];
384
        ro <= ro_barrier[brgs];
385
        dbl <= dl_barrier[brgs];
386
        dbu <= du_barrier[brgs];
387
        sbl <= sl_barrier[brgs];
388
        sbu <= su_barrier[brgs];
389
        en <= en_barrier[brgs];
390
        env_pl <= env_priv[brgs];
391
        cod_pl <= cod_priv[brgs];
392
        rdo_pl <= rdo_priv[brgs];
393
        dat_pl <= dat_priv[brgs];
394
        stk_pl <= stk_priv[brgs];
395
end
396
//wire [23:0] currentPrgSelector = prg_selector[brgs];
397
`else
398
wire [63:0] pb = 1'd0;
399
wire [63:0] cbl = 1'd0;
400
wire [63:0] cbu = 64'hFFFFFFFFFFFFFFFF;
401
wire [63:0] ro = 1'd0;
402
wire [63:0] dbl = 1'd0;
403
wire [63:0] dbu = 64'hFFFFFFFFFFFFFFFF;
404
wire [63:0] sbl = 1'd0;
405
wire [63:0] sbu = 64'hFFFFFFFFFFFFFFFF;
406
wire [63:0] en = 1'd0;
407
wire [7:0] env_pl = 8'h00;
408
wire [7:0] cod_pl = 8'h00;
409
wire [7:0] rdo_pl = 8'h00;
410
wire [7:0] dat_pl = 8'h00;
411
wire [7:0] stk_pl = 8'h00;
412
`endif
413
 
414
reg  [PREGS-1:0] rf_v;
415
reg  [`QBITSP1] rf_source[0:AREGS-1];
416
reg  [15:0] prf_v;
417
reg  [`QBITSP1] prf_source[0:15];
418
initial begin
419
for (n = 0; n < AREGS; n = n + 1)
420
        rf_source[n] = 1'b0;
421
for (n = 0; n < 16; n = n + 1)
422
        prf_source[n] <= 1'b0;
423
end
424
wire [`ABITS] pc0a;
425
wire [`ABITS] pc1a;
426
wire [`ABITS] pc2a;
427
`ifdef SUPPORT_SEGMENTATION
428
wire [`ABITS] pc0 = (pc0a[47:40]==8'hFF||ol==2'b00) ? pc0a : {csx_base[50:0],13'd0} + pc0a[47:0];
429
wire [`ABITS] pc1 = (pc1a[47:40]==8'hFF||ol==2'b00) ? pc1a : {csx_base[50:0],13'd0} + pc1a[47:0];
430
wire [`ABITS] pc2 = (pc2a[47:40]==8'hFF||ol==2'b00) ? pc2a : {csx_base[50:0],13'd0} + pc2a[47:0];
431
`else
432
`ifdef SUPPORT_BBMS
433
wire [`ABITS] pc0 = (pc0a[47:40]==8'hFF||ol==2'b00) ? pc0a : {pb[50:0],13'd0} + pc0a[47:0];
434
wire [`ABITS] pc1 = (pc1a[47:40]==8'hFF||ol==2'b00) ? pc1a : {pb[50:0],13'd0} + pc1a[47:0];
435
wire [`ABITS] pc2 = (pc2a[47:40]==8'hFF||ol==2'b00) ? pc2a : {pb[50:0],13'd0} + pc2a[47:0];
436
`else
437
wire [`ABITS] pc0 = pc0a;
438
wire [`ABITS] pc1 = pc1a;
439
wire [`ABITS] pc2 = pc2a;
440
`endif
441
`endif
442
 
443
reg excmiss;
444
reg [`ABITS] excmisspc;
445
reg excthrd;
446
reg exception_set;
447
reg rdvq;               // accumulated read violation
448
reg errq;               // accumulated err_i input status
449
reg exvq;
450
 
451
// Vector
452
reg [5:0] vqe0, vqe1, vqe2;   // vector element being queued
453
reg [5:0] vqet0, vqet1, vqet2;
454
reg [7:0] vl;           // vector length
455
reg [63:0] vm [0:7];    // vector mask registers
456
reg [1:0] m2;
457
 
458
reg [31:0] wb_merges;
459
// CSR's
460
reg [63:0] cr0;
461
wire snr = cr0[17];             // sequence number reset
462
wire dce = cr0[30];     // data cache enable
463
wire bpe = cr0[32];     // branch predictor enable
464
wire wbm = cr0[34];
465
wire sple = cr0[35];            // speculative load enable
466
wire ctgtxe = cr0[33];
467
`ifdef SUPPORT_PREDICATION
468
wire pred_on = cr0[36]; // predicated execution mode on
469
`else
470
wire pred_on = 1'b0;
471
`endif
472
reg [63:0] pmr;
473
wire id1_available = pmr[0];
474
wire id2_available = pmr[1];
475
wire id3_available = pmr[2];
476
wire alu0_available = pmr[8];
477
wire alu1_available = pmr[9];
478
wire fpu1_available = pmr[16];
479
wire fpu2_available = pmr[17];
480
wire mem1_available = pmr[24];
481
wire mem2_available = pmr[25];
482
wire mem3_available = pmr[26];
483
wire fcu_available = pmr[32];
484
// Simply setting this flag to zero should strip out almost all the logic
485
// associated SMT.
486
`ifdef SUPPORT_SMT
487
wire thread_en = cr0[16];
488
`else
489
wire thread_en = 1'b0;
490
`endif
491
wire vechain = cr0[18];
492
reg [39:0] iq_ctr;
493
reg [39:0] irq_ctr;                                      // count of number of interrupts
494
reg [39:0] bm_ctr;                                       // branch miss counter
495
reg [39:0] icl_ctr;                                      // instruction cache load counter
496
 
497
reg [7:0] fcu_timeout;
498
reg [63:0] tick;
499
reg [63:0] wc_time;
500
reg [31:0] pcr;
501
reg [63:0] pcr2;
502
assign pcr_o = pcr;
503
assign pcr2_o = pcr2;
504
reg [63:0] aec;
505
reg [15:0] cause[0:15];
506
`ifdef SUPPORT_SMT
507
reg [`ABITS] epc [0:NTHREAD];
508
reg [`ABITS] epc0 [0:NTHREAD];
509
reg [`ABITS] epc1 [0:NTHREAD];
510
reg [`ABITS] epc2 [0:NTHREAD];
511
reg [`ABITS] epc3 [0:NTHREAD];
512
reg [`ABITS] epc4 [0:NTHREAD];
513
reg [`ABITS] epc5 [0:NTHREAD];
514
reg [`ABITS] epc6 [0:NTHREAD];
515
reg [`ABITS] epc7 [0:NTHREAD];
516
reg [`ABITS] epc8 [0:NTHREAD];                   // exception pc and stack
517
reg [63:0] mstatus [0:NTHREAD];           // machine status
518
wire [3:0] im = mstatus[0][3:0];
519
wire [1:0] ol [0:NTHREAD];
520
wire [1:0] dl [0:NTHREAD];
521
assign ol[0] = mstatus[0][5:4];   // operating level
522
assign dl[0] = mstatus[0][21:20];
523
wire [7:0] cpl [0:NTHREAD];
524
assign cpl[0] = mstatus[0][13:6]; // current privilege level
525
wire [5:0] rgs [0:NTHREAD];
526
assign ol[1] = mstatus[1][5:4]; // operating level
527
assign cpl[1] = mstatus[1][13:6];       // current privilege level
528
assign dl[1] = mstatus[1][21:20];
529
wire [7:0] ASID = mstatus[0][47:40];
530
reg [15:0] ol_stack [0:NTHREAD];
531
reg [15:0] dl_stack [0:NTHREAD];
532
reg [31:0] im_stack [0:NTHREAD];
533
reg [63:0] pl_stack [0:NTHREAD];
534
reg [63:0] rs_stack [0:NTHREAD];
535
reg [63:0] brs_stack [0:NTHREAD];
536
reg [63:0] fr_stack [0:NTHREAD];
537
assign rgs[0] = rs_stack[0][5:0];
538
assign rgs[1] = rs_stack[1][5:0];
539
wire mprv = mstatus[0][55];
540
wire [5:0] fprgs = mstatus[0][25:20];
541
//assign ol_o = mprv ? ol_stack[0][2:0] : ol[0];
542
wire vca = mstatus[0][32];               // vector chaining active
543
`else
544
reg [`ABITS] epc ;
545
reg [`ABITS] epc0 ;
546
reg [`ABITS] epc1 ;
547
reg [`ABITS] epc2 ;
548
reg [`ABITS] epc3 ;
549
reg [`ABITS] epc4 ;
550
reg [`ABITS] epc5 ;
551
reg [`ABITS] epc6 ;
552
reg [`ABITS] epc7 ;
553
reg [`ABITS] epc8 ;                     // exception pc and stack
554
reg [63:0] mstatus ;             // machine status
555
wire [3:0] im = mstatus[3:0];
556
wire [1:0] ol ;
557
wire [1:0] dl;
558
assign ol = mstatus[5:4];       // operating level
559
assign dl = mstatus[21:20];
560
wire [7:0] cpl ;
561
assign cpl = mstatus[13:6];     // current privilege level
562
wire [5:0] rgs ;
563
reg [15:0] ol_stack ;
564
reg [15:0] dl_stack ;
565
reg [31:0] im_stack ;
566
reg [63:0] pl_stack ;
567
reg [63:0] rs_stack ;
568
reg [63:0] brs_stack ;
569
reg [63:0] fr_stack ;
570
assign rgs = rs_stack[5:0];
571
assign brgs = brs_stack[5:0];
572
wire mprv = mstatus[55];
573
wire [7:0] ASID = mstatus[47:40];
574
wire [5:0] fprgs = mstatus[25:20];
575
//assign ol_o = mprv ? ol_stack[2:0] : ol;
576
wire vca = mstatus[32];         // vector chaining active
577
`endif
578
reg [63:0] keys;
579
assign pkeys_o = keys;
580
reg [63:0] tcb;
581
reg [47:0] bad_instr[0:15];
582
reg [`ABITS] badaddr[0:15];
583
reg [`ABITS] tvec[0:7];
584
reg [63:0] sema;
585
reg [63:0] vm_sema;
586
reg [63:0] cas;         // compare and swap
587
reg [63:0] ve_hold;
588
reg isCAS, isAMO, isInc, isSpt, isRMW;
589
reg [`QBITS] casid;
590
reg [4:0] regLR = 5'd29;
591
 
592
 
593
reg [2:0] fp_rm;
594
reg fp_inexe;
595
reg fp_dbzxe;
596
reg fp_underxe;
597
reg fp_overxe;
598
reg fp_invopxe;
599
reg fp_giopxe;
600
reg fp_nsfp = 1'b0;
601
reg fp_fractie;
602
reg fp_raz;
603
 
604
reg fp_neg;
605
reg fp_pos;
606
reg fp_zero;
607
reg fp_inf;
608
 
609
reg fp_inex;            // inexact exception
610
reg fp_dbzx;            // divide by zero exception
611
reg fp_underx;          // underflow exception
612
reg fp_overx;           // overflow exception
613
reg fp_giopx;           // global invalid operation exception
614
reg fp_sx;                      // summary exception
615
reg fp_swtx;        // software triggered exception
616
reg fp_gx;
617
reg fp_invopx;
618
 
619
reg fp_infzerox;
620
reg fp_zerozerox;
621
reg fp_subinfx;
622
reg fp_infdivx;
623
reg fp_NaNCmpx;
624
reg fp_cvtx;
625
reg fp_sqrtx;
626
reg fp_snanx;
627
 
628
wire [31:0] fp_status = {
629
 
630
        fp_rm,
631
        fp_inexe,
632
        fp_dbzxe,
633
        fp_underxe,
634
        fp_overxe,
635
        fp_invopxe,
636
        fp_nsfp,
637
 
638
        fp_fractie,
639
        fp_raz,
640
        1'b0,
641
        fp_neg,
642
        fp_pos,
643
        fp_zero,
644
        fp_inf,
645
 
646
        fp_swtx,
647
        fp_inex,
648
        fp_dbzx,
649
        fp_underx,
650
        fp_overx,
651
        fp_giopx,
652
        fp_gx,
653
        fp_sx,
654
 
655
        fp_cvtx,
656
        fp_sqrtx,
657
        fp_NaNCmpx,
658
        fp_infzerox,
659
        fp_zerozerox,
660
        fp_infdivx,
661
        fp_subinfx,
662
        fp_snanx
663
        };
664
 
665
reg [63:0] fpu_csr;
666
wire [5:0] fp_rgs = fpu_csr[37:32];
667
 
668
//reg [25:0] m[0:8191];
669
reg  [3:0] panic;                // indexes the message structure
670
reg [128:0] message [0:15];       // indexed by panic
671
 
672
wire int_commit;
673
reg StatusHWI;
674
(* mark_debug = "true" *)
675
reg [55:0] insn0, insn1, insn2;
676
wire [55:0] insn0a, insn1b, insn2b;
677
reg [55:0] insn1a, insn2a;
678
// Only need enough bits in the seqnence number to cover the instructions in
679
// the queue plus an extra count for skipping on branch misses. In this case
680
// that would be four bits minimum (count 0 to 8). 
681
wire [63:0] rdat0,rdat1,rdat2;
682
reg [63:0] xdati;
683
 
684
reg canq1, canq2, canq3;
685
(* mark_debug = "true" *)
686
reg queued1;
687
reg queued2;
688
reg queued3;
689
(* mark_debug = "true" *)
690
reg queuedNop;
691
 
692
reg [47:0] codebuf[0:63];
693
reg [QENTRIES-1:0] setpred;
694
 
695
// instruction queue (ROB)
696
// State and stqte decodes
697
reg [2:0] iqentry_state [0:QENTRIES-1];
698
reg [QENTRIES-1:0] iqentry_v;                    // entry valid?  -- this should be the first bit
699
reg [QENTRIES-1:0] iqentry_done;
700
reg [QENTRIES-1:0] iqentry_out;
701
reg [QENTRIES-1:0] iqentry_agen;
702
reg [`SNBITS] iqentry_sn [0:QENTRIES-1];  // instruction sequence number
703
reg [QENTRIES-1:0] iqentry_iv;           // instruction is valid
704
reg [`QBITSP1] iqentry_is [0:QENTRIES-1];        // source of instruction
705
reg [QENTRIES-1:0] iqentry_thrd;         // which thread the instruction is in
706
reg [QENTRIES-1:0] iqentry_pt;           // predict taken
707
reg [QENTRIES-1:0] iqentry_bt;           // update branch target buffer
708
reg [QENTRIES-1:0] iqentry_takb; // take branch record
709
reg [QENTRIES-1:0] iqentry_jal;
710
reg [2:0] iqentry_sz [0:QENTRIES-1];
711
reg [QENTRIES-1:0] iqentry_alu = 8'h00;  // alu type instruction
712
reg [QENTRIES-1:0] iqentry_alu0;  // only valid on alu #0
713
reg [QENTRIES-1:0] iqentry_fpu;  // floating point instruction
714
reg [QENTRIES-1:0] iqentry_fc;   // flow control instruction
715
reg [QENTRIES-1:0] iqentry_canex = 8'h00;        // true if it's an instruction that can exception
716
reg [QENTRIES-1:0] iqentry_oddball = 8'h00;      // writes to register file
717
reg [QENTRIES-1:0] iqentry_load; // is a memory load instruction
718
reg [QENTRIES-1:0] iqentry_loadv;        // is a volatile memory load instruction
719
reg [QENTRIES-1:0] iqentry_store;        // is a memory store instruction
720
reg [QENTRIES-1:0] iqentry_preload;      // is a memory preload instruction
721
reg [QENTRIES-1:0] iqentry_ldcmp;
722
reg [QENTRIES-1:0] iqentry_mem;  // touches memory: 1 if LW/SW
723
reg [QENTRIES-1:0] iqentry_memndx;  // indexed memory operation 
724
reg [2:0] iqentry_memsz [0:QENTRIES-1];   // size of memory op
725
reg [QENTRIES-1:0] iqentry_rmw;  // memory RMW op
726
reg [QENTRIES-1:0] iqentry_push;
727
reg [QENTRIES-1:0] iqentry_memdb;
728
reg [QENTRIES-1:0] iqentry_memsb;
729
reg [QENTRIES-1:0] iqentry_rtop;
730
reg [QENTRIES-1:0] iqentry_sei;
731
reg [QENTRIES-1:0] iqentry_aq;   // memory aquire
732
reg [QENTRIES-1:0] iqentry_rl;   // memory release
733
reg [QENTRIES-1:0] iqentry_shft;
734
reg [QENTRIES-1:0] iqentry_jmp;  // changes control flow: 1 if BEQ/JALR
735
reg [QENTRIES-1:0] iqentry_br;  // Bcc (for predictor)
736
reg [QENTRIES-1:0] iqentry_ret;
737
reg [QENTRIES-1:0] iqentry_irq;
738
reg [QENTRIES-1:0] iqentry_brk;
739
reg [QENTRIES-1:0] iqentry_rti;
740
reg [QENTRIES-1:0] iqentry_sync;  // sync instruction
741
reg [QENTRIES-1:0] iqentry_fsync;
742
reg [QENTRIES-1:0] iqentry_tlb;
743
reg [QENTRIES-1:0] iqentry_cmp;
744
reg [QENTRIES-1:0] iqentry_rfw = 1'b0;   // writes to register file
745
reg [QENTRIES-1:0] iqentry_prfw = 1'b0;
746
reg  [7:0] iqentry_we   [0:QENTRIES-1];   // enable strobe
747
reg [63:0] iqentry_res   [0:QENTRIES-1];  // instruction result
748
reg [63:0] iqentry_ares  [0:QENTRIES-1];  // alternate instruction result
749
reg [47:0] iqentry_instr[0:QENTRIES-1];   // instruction opcode
750
reg  [2:0] iqentry_insln[0:QENTRIES-1]; // instruction length
751
reg  [7:0] iqentry_exc   [0:QENTRIES-1];  // only for branches ... indicates a HALT instruction
752
reg [RBIT:0] iqentry_tgt[0:QENTRIES-1];   // Rt field or ZERO -- this is the instruction's target (if any)
753
reg  [7:0] iqentry_vl   [0:QENTRIES-1];
754
reg  [5:0] iqentry_ven  [0:QENTRIES-1];  // vector element number
755
reg [AMSB:0] iqentry_ma [0:QENTRIES-1];   // memory address
756
reg [63:0] iqentry_a0    [0:QENTRIES-1];  // argument 0 (immediate)
757
reg [63:0] iqentry_a1    [0:QENTRIES-1];  // argument 1
758
reg [QENTRIES-1:0] iqentry_a1_v; // arg1 valid
759
reg [`QBITSP1] iqentry_a1_s     [0:QENTRIES-1];  // arg1 source (iq entry # with top bit representing ALU/DRAM bus)
760
reg [63:0] iqentry_a2    [0:QENTRIES-1];  // argument 2
761
reg        iqentry_a2_v [0:QENTRIES-1];  // arg2 valid
762
reg  [`QBITSP1] iqentry_a2_s    [0:QENTRIES-1];  // arg2 source (iq entry # with top bit representing ALU/DRAM bus)
763
reg [63:0] iqentry_a3    [0:QENTRIES-1];  // argument 3
764
reg        iqentry_a3_v [0:QENTRIES-1];  // arg3 valid
765
reg  [`QBITSP1] iqentry_a3_s    [0:QENTRIES-1];  // arg3 source (iq entry # with top bit representing ALU/DRAM bus)
766
reg [`ABITS] iqentry_pc [0:QENTRIES-1];  // program counter for this instruction
767
reg [RBIT:0] iqentry_Ra [0:QENTRIES-1];
768
reg [RBIT:0] iqentry_Rb [0:QENTRIES-1];
769
reg [RBIT:0] iqentry_Rc [0:QENTRIES-1];
770
 
771
// debugging
772
//reg  [4:0] iqentry_ra   [0:7];  // Ra
773
initial begin
774
for (n = 0; n < QENTRIES; n = n + 1)
775
        iqentry_a1_s[n] <= 5'd0;
776
        iqentry_a2_s[n] <= 5'd0;
777
        iqentry_a3_s[n] <= 5'd0;
778
end
779
 
780
reg [QENTRIES-1:0] iqentry_source = {QENTRIES{1'b0}};
781
reg [QENTRIES-1:0] iqentry_imm;
782
reg [QENTRIES-1:0] iqentry_memready;
783
reg [QENTRIES-1:0] iqentry_memopsvalid;
784
 
785
reg  [QENTRIES-1:0] memissue = {QENTRIES{1'b0}};
786
reg [1:0] missued;
787
reg [7:0] last_issue0, last_issue1, last_issue2;
788
reg  [QENTRIES-1:0] iqentry_memissue;
789
reg [QENTRIES-1:0] iqentry_stomp;
790
reg [3:0] stompedOnRets;
791
reg  [QENTRIES-1:0] iqentry_alu0_issue;
792
reg  [QENTRIES-1:0] iqentry_alu1_issue;
793
reg  [QENTRIES-1:0] iqentry_alu2_issue;
794
reg  [QENTRIES-1:0] iqentry_id1issue;
795
reg  [QENTRIES-1:0] iqentry_id2issue;
796
reg  [QENTRIES-1:0] iqentry_id3issue;
797
reg [1:0] iqentry_mem_islot [0:QENTRIES-1];
798
reg [QENTRIES-1:0] iqentry_fcu_issue;
799
reg [QENTRIES-1:0] iqentry_fpu1_issue;
800
reg [QENTRIES-1:0] iqentry_fpu2_issue;
801
 
802
reg [PREGS-1:1] livetarget;
803
reg [PREGS-1:1] iqentry_livetarget [0:QENTRIES-1];
804
reg [PREGS-1:1] iqentry_latestID [0:QENTRIES-1];
805
reg [PREGS-1:1] iqentry_cumulative [0:QENTRIES-1];
806
`ifdef SUPPORT_PREDICATION
807
reg [QENTRIES-1:0] iqentry_psource = {QENTRIES{1'b0}};
808
reg [15:0] plivetarget;
809
reg [15:0] iqentry_plivetarget [0:QENTRIES-1];
810
reg [15:0] iqentry_platestID [0:QENTRIES-1];
811
reg [15:0] iqentry_pcumulative [0:QENTRIES-1];
812
`endif
813
wire  [PREGS-1:1] iq_out [0:QENTRIES-1];
814
 
815
reg  [`QBITS] tail0;
816
reg  [`QBITS] tail1;
817
reg  [`QBITS] tail2;
818
reg  [`QBITS] heads[0:QENTRIES-1];
819
 
820
// To detect a head change at time of commit. Some values need to pulsed
821
// with a single pulse.
822
reg  [`QBITS] ohead[0:2];
823
reg ocommit0_v, ocommit1_v, ocommit2_v;
824
reg [11:0] cmt_timer;
825
 
826
wire take_branch0;
827
wire take_branch1;
828
 
829
reg [3:0] nop_fetchbuf;
830
wire        fetchbuf;   // determines which pair to read from & write to
831
wire [3:0] fb_panic;
832
 
833
wire [47:0] fetchbuf0_instr;
834
wire  [2:0] fetchbuf0_insln;
835
wire [`ABITS] fetchbuf0_pc;
836
(* mark_debug = "true" *)
837
wire        fetchbuf0_v;
838
wire            fetchbuf0_thrd;
839
wire            fetchbuf0_mem;
840
wire        fetchbuf0_rfw;
841
wire [47:0] fetchbuf1_instr;
842
wire  [2:0] fetchbuf1_insln;
843
wire [`ABITS] fetchbuf1_pc;
844
wire        fetchbuf1_v;
845
wire            fetchbuf1_thrd;
846
wire            fetchbuf1_mem;
847
wire        fetchbuf1_rfw;
848
wire [47:0] fetchbuf2_instr;
849
wire  [2:0] fetchbuf2_insln;
850
wire [`ABITS] fetchbuf2_pc;
851
wire        fetchbuf2_v;
852
wire            fetchbuf2_thrd;
853
wire            fetchbuf2_mem;
854
wire        fetchbuf2_rfw;
855
`ifdef SUPPORT_PREDICATION
856
wire        fetchbuf0_prfw;
857
wire [7:0] fetchbuf0_pbyte;
858
wire        fetchbuf1_prfw;
859
wire [7:0] fetchbuf1_pbyte;
860
wire        fetchbuf2_prfw;
861
wire [7:0] fetchbuf2_pbyte;
862
`endif
863
wire [47:0] fetchbufA_instr;
864
wire [`ABITS] fetchbufA_pc;
865
wire        fetchbufA_v;
866
wire [47:0] fetchbufB_instr;
867
wire [`ABITS] fetchbufB_pc;
868
wire        fetchbufB_v;
869
wire [47:0] fetchbufC_instr;
870
wire [`ABITS] fetchbufC_pc;
871
wire        fetchbufC_v;
872
wire [47:0] fetchbufD_instr;
873
wire [`ABITS] fetchbufD_pc;
874
wire        fetchbufD_v;
875
wire [47:0] fetchbufE_instr;
876
wire [`ABITS] fetchbufE_pc;
877
wire        fetchbufE_v;
878
wire [47:0] fetchbufF_instr;
879
wire [`ABITS] fetchbufF_pc;
880
wire        fetchbufF_v;
881
 
882
//reg        did_branchback0;
883
//reg        did_branchback1;
884
 
885
reg         id1_v;
886
reg   [`QBITSP1] id1_id;
887
reg  [47:0] id1_instr;
888
reg   [5:0] id1_ven;
889
reg   [7:0] id1_vl;
890
reg         id1_thrd;
891
reg         id1_pt;
892
reg   [4:0] id1_Rt;
893
wire [143:0] id1_bus;
894
 
895
reg         id2_v;
896
reg   [`QBITSP1] id2_id;
897
reg  [47:0] id2_instr;
898
reg   [5:0] id2_ven;
899
reg   [7:0] id2_vl;
900
reg         id2_thrd;
901
reg         id2_pt;
902
reg   [4:0] id2_Rt;
903
wire [143:0] id2_bus;
904
 
905
reg         id3_v;
906
reg   [`QBITSP1] id3_id;
907
reg  [47:0] id3_instr;
908
reg   [5:0] id3_ven;
909
reg   [7:0] id3_vl;
910
reg         id3_thrd;
911
reg         id3_pt;
912
reg   [4:0] id3_Rt;
913
wire [143:0] id3_bus;
914
 
915
reg [63:0] alu0_xs = 64'd0;
916
reg [63:0] alu1_xs = 64'd0;
917
 
918
reg [3:0]  alu0_pred;
919
reg                             alu0_cmt;
920
wire                            alu0_abort;
921
reg        alu0_ld;
922
reg        alu0_dataready;
923
wire       alu0_done;
924
wire       alu0_idle;
925
reg  [`QBITSP1] alu0_sourceid;
926
reg [47:0] alu0_instr;
927
reg                              alu0_tlb;
928
reg        alu0_mem;
929
reg        alu0_load;
930
reg        alu0_store;
931
reg                      alu0_push;
932
reg        alu0_shft;
933
reg [RBIT:0] alu0_Ra;
934
reg [63:0] alu0_argA;
935
reg [63:0] alu0_argB;
936
reg [63:0] alu0_argC;
937
reg [63:0] alu0_argT;
938
reg [63:0] alu0_argI;    // only used by BEQ
939
reg [2:0]  alu0_sz;
940
reg [RBIT:0] alu0_tgt;
941
reg [5:0]  alu0_ven;
942
reg        alu0_thrd;
943
reg [`ABITS] alu0_pc;
944
reg [63:0] alu0_bus;
945
wire [63:0] alu0b_bus;
946
wire [63:0] alu0_out;
947
wire  [`QBITSP1] alu0_id;
948
wire  [`XBITS] alu0_exc;
949
wire        alu0_v;
950
wire        alu0_branchmiss;
951
wire [`ABITS] alu0_misspc;
952
 
953
reg [3:0]  alu1_pred;
954
reg                             alu1_cmt;
955
wire                            alu1_abort;
956
reg        alu1_ld;
957
reg        alu1_dataready;
958
wire       alu1_done;
959
wire       alu1_idle;
960
reg  [`QBITSP1] alu1_sourceid;
961
reg [47:0] alu1_instr;
962
reg        alu1_mem;
963
reg        alu1_load;
964
reg        alu1_store;
965
reg                      alu1_push;
966
reg        alu1_shft;
967
reg [RBIT:0] alu1_Ra;
968
reg [63:0] alu1_argA;
969
reg [63:0] alu1_argB;
970
reg [63:0] alu1_argC;
971
reg [63:0] alu1_argT;
972
reg [63:0] alu1_argI;    // only used by BEQ
973
reg [2:0]  alu1_sz;
974
reg [RBIT:0] alu1_tgt;
975
reg [5:0]  alu1_ven;
976
reg [`ABITS] alu1_pc;
977
reg        alu1_thrd;
978
reg [63:0] alu1_bus;
979
wire [63:0] alu1b_bus;
980
wire [63:0] alu1_out;
981
wire  [`QBITSP1] alu1_id;
982
wire  [`XBITS] alu1_exc;
983
wire        alu1_v;
984
wire        alu1_branchmiss;
985
wire [`ABITS] alu1_misspc;
986
 
987
wire [`XBITS] fpu_exc;
988
reg [3:0] fpu1_pred;
989
reg                             fpu1_cmt;
990
reg        fpu1_ld;
991
reg        fpu1_dataready = 1'b1;
992
wire       fpu1_done = 1'b1;
993
wire       fpu1_idle;
994
reg [`QBITSP1] fpu1_sourceid;
995
reg [47:0] fpu1_instr;
996
reg [63:0] fpu1_argA;
997
reg [63:0] fpu1_argB;
998
reg [63:0] fpu1_argC;
999
reg [63:0] fpu1_argT;
1000
reg [63:0] fpu1_argI;    // only used by BEQ
1001
reg [RBIT:0] fpu1_tgt;
1002
reg [`ABITS] fpu1_pc;
1003
wire [63:0] fpu1_out = 64'h0;
1004
reg [63:0] fpu1_bus = 64'h0;
1005
wire  [`QBITSP1] fpu1_id;
1006
wire  [`XBITS] fpu1_exc = 9'h000;
1007
wire        fpu1_v;
1008
wire [31:0] fpu1_status;
1009
 
1010
reg [3:0] fpu2_pred;
1011
reg                             fpu2_cmt;
1012
reg        fpu2_ld;
1013
reg        fpu2_dataready = 1'b1;
1014
wire       fpu2_done = 1'b1;
1015
wire       fpu2_idle;
1016
reg [`QBITSP1] fpu2_sourceid;
1017
reg [47:0] fpu2_instr;
1018
reg [63:0] fpu2_argA;
1019
reg [63:0] fpu2_argB;
1020
reg [63:0] fpu2_argC;
1021
reg [63:0] fpu2_argT;
1022
reg [63:0] fpu2_argI;    // only used by BEQ
1023
reg [RBIT:0] fpu2_tgt;
1024
reg [`ABITS] fpu2_pc;
1025
wire [63:0] fpu2_out = 64'h0;
1026
reg [63:0] fpu2_bus = 64'h0;
1027
wire  [`QBITSP1] fpu2_id;
1028
wire  [`XBITS] fpu2_exc = 9'h000;
1029
wire        fpu2_v;
1030
wire [31:0] fpu2_status;
1031
 
1032
reg [7:0] fccnt;
1033
reg [47:0] waitctr;
1034
reg [3:0] fcu_pred;
1035
reg                             fcu_cmt;
1036
reg        fcu_ld;
1037
reg        fcu_dataready;
1038
reg        fcu_done;
1039
reg         fcu_idle = 1'b1;
1040
reg [`QBITSP1] fcu_sourceid;
1041
reg [47:0] fcu_instr;
1042
reg [47:0] fcu_prevInstr;
1043
reg  [2:0] fcu_insln;
1044
reg        fcu_pt;                      // predict taken
1045
reg        fcu_branch;
1046
reg        fcu_call;
1047
reg        fcu_ret;
1048
reg        fcu_jal;
1049
reg        fcu_brk;
1050
reg        fcu_rti;
1051
reg [63:0] fcu_argA;
1052
reg [63:0] fcu_argB;
1053
reg [63:0] fcu_argC;
1054
reg [63:0] fcu_argI;     // only used by BEQ
1055
reg [63:0] fcu_argT;
1056
reg [63:0] fcu_argT2;
1057
reg [`ABITS] fcu_pc;
1058
reg [`ABITS] fcu_nextpc;
1059
reg [`ABITS] fcu_brdisp;
1060
wire [63:0] fcu_out;
1061
reg [63:0] fcu_bus;
1062
wire  [`QBITSP1] fcu_id;
1063
reg   [`XBITS] fcu_exc;
1064
wire        fcu_v;
1065
reg        fcu_thrd;
1066
reg        fcu_branchmiss;
1067
reg  fcu_clearbm;
1068
reg [`ABITS] fcu_misspc;
1069
 
1070
reg [63:0] rmw_argA;
1071
reg [63:0] rmw_argB;
1072
reg [63:0] rmw_argC;
1073
wire [63:0] rmw_res;
1074
reg [47:0] rmw_instr;
1075
 
1076
// write buffer
1077
reg [63:0] wb_data [0:`WB_DEPTH-1];
1078
reg [`ABITS] wb_addr [0:`WB_DEPTH-1];
1079
reg [1:0] wb_ol [0:`WB_DEPTH-1];
1080
reg [`WB_DEPTH-1:0] wb_v;
1081
reg [`WB_DEPTH-1:0] wb_rmw;
1082
reg [QENTRIES-1:0] wb_id [0:`WB_DEPTH-1];
1083
reg [QENTRIES-1:0] wbo_id;
1084
reg [7:0] wb_sel [0:`WB_DEPTH-1];
1085
reg wb_en;
1086
reg wb_shift;
1087
 
1088
reg branchmiss = 1'b0;
1089
reg branchmiss_thrd = 1'b0;
1090
reg [`ABITS] misspc;
1091
reg  [`QBITS] missid;
1092
 
1093
wire take_branch;
1094
wire take_branchA;
1095
wire take_branchB;
1096
wire take_branchC;
1097
wire take_branchD;
1098
 
1099
wire        dram_avail;
1100
reg      [2:0] dram0;    // state of the DRAM request (latency = 4; can have three in pipeline)
1101
reg      [2:0] dram1;    // state of the DRAM request (latency = 4; can have three in pipeline)
1102
reg      [2:0] dram2;    // state of the DRAM request (latency = 4; can have three in pipeline)
1103
reg [63:0] dram0_data;
1104
reg [`ABITS] dram0_addr;
1105
reg [47:0] dram0_instr;
1106
reg        dram0_rmw;
1107
reg                dram0_preload;
1108
reg [RBIT:0] dram0_tgt;
1109
reg  [`QBITSP1] dram0_id;
1110
reg  [`XBITS] dram0_exc;
1111
reg        dram0_unc;
1112
reg [2:0]  dram0_memsize;
1113
reg        dram0_load;  // is a load operation
1114
reg        dram0_store;
1115
reg  [1:0] dram0_ol;
1116
reg [63:0] dram1_data;
1117
reg [`ABITS] dram1_addr;
1118
reg [47:0] dram1_instr;
1119
reg        dram1_rmw;
1120
reg                dram1_preload;
1121
reg [RBIT:0] dram1_tgt;
1122
reg  [`QBITSP1] dram1_id;
1123
reg  [`XBITS] dram1_exc;
1124
reg        dram1_unc;
1125
reg [2:0]  dram1_memsize;
1126
reg        dram1_load;
1127
reg        dram1_store;
1128
reg  [1:0] dram1_ol;
1129
reg [63:0] dram2_data;
1130
reg [`ABITS] dram2_addr;
1131
reg [47:0] dram2_instr;
1132
reg        dram2_rmw;
1133
reg                dram2_preload;
1134
reg [RBIT:0] dram2_tgt;
1135
reg  [`QBITSP1] dram2_id;
1136
reg  [`XBITS] dram2_exc;
1137
reg        dram2_unc;
1138
reg [2:0]  dram2_memsize;
1139
reg        dram2_load;
1140
reg        dram2_store;
1141
reg  [1:0] dram2_ol;
1142
 
1143
reg        dramA_v;
1144
reg  [`QBITSP1] dramA_id;
1145
reg [63:0] dramA_bus;
1146
reg  [`XBITS] dramA_exc;
1147
reg        dramB_v;
1148
reg  [`QBITSP1] dramB_id;
1149
reg [63:0] dramB_bus;
1150
reg  [`XBITS] dramB_exc;
1151
reg        dramC_v;
1152
reg  [`QBITSP1] dramC_id;
1153
reg [63:0] dramC_bus;
1154
reg  [`XBITS] dramC_exc;
1155
 
1156
wire        outstanding_stores;
1157
reg [63:0] I;            // instruction count
1158
reg [63:0] CC;   // commit count
1159
 
1160
reg        commit0_v;
1161
reg  [`QBITSP1] commit0_id;
1162
reg [RBIT:0] commit0_tgt;
1163
reg  [7:0] commit0_we = 8'h00;
1164
reg [63:0] commit0_bus;
1165
reg        commit1_v;
1166
reg  [`QBITSP1] commit1_id;
1167
reg [RBIT:0] commit1_tgt;
1168
reg  [7:0] commit1_we = 8'h00;
1169
reg [63:0] commit1_bus;
1170
reg        commit2_v;
1171
reg  [`QBITSP1] commit2_id;
1172
reg [RBIT:0] commit2_tgt;
1173
reg  [7:0] commit2_we = 8'h00;
1174
reg [63:0] commit2_bus;
1175
 
1176
reg StoreAck1;
1177
reg [4:0] bstate;
1178
parameter BIDLE = 5'd0;
1179
parameter B_StoreAck = 5'd1;
1180
parameter B_DCacheLoadStart = 5'd2;
1181
parameter B_DCacheLoadStb = 5'd3;
1182
parameter B_DCacheLoadWait1 = 5'd4;
1183
parameter B_DCacheLoadWait2 = 5'd5;
1184
parameter B_DCacheLoadResetBusy = 5'd6;
1185
parameter B_ICacheAck = 5'd7;
1186
parameter B8 = 5'd8;
1187
parameter B_ICacheNack = 5'd9;
1188
parameter B_ICacheNack2 = 5'd10;
1189
parameter B11 = 5'd11;
1190
parameter B12 = 5'd12;
1191
parameter B_DLoadAck = 5'd13;
1192
parameter B14 = 5'd14;
1193
parameter B15 = 5'd15;
1194
parameter B16 = 5'd16;
1195
parameter B17 = 5'd17;
1196
parameter B18 = 5'd18;
1197
parameter B19 = 5'd19;
1198
parameter B2a = 5'd20;
1199
parameter B2b = 5'd21;
1200
parameter B2c = 5'd22;
1201
parameter B_DCacheLoadAck = 5'd23;
1202
parameter B20 = 5'd24;
1203
parameter B21 = 5'd25;
1204
parameter B_DCacheLoadWait3 = 5'd26;
1205
reg [1:0] bwhich;
1206
reg [3:0] icstate,picstate;
1207
parameter IDLE = 4'd0;
1208
parameter IC1 = 4'd1;
1209
parameter IC2 = 4'd2;
1210
parameter IC3 = 4'd3;
1211
parameter IC_WaitL2 = 4'd4;
1212
parameter IC5 = 4'd5;
1213
parameter IC6 = 4'd6;
1214
parameter IC7 = 4'd7;
1215
parameter IC_Next = 4'd8;
1216
parameter IC9 = 4'd9;
1217
parameter IC10 = 4'd10;
1218
parameter IC3a = 4'd11;
1219
reg invic, invdc;
1220
reg [1:0] icwhich;
1221
reg icnxt,L2_nxt;
1222
wire ihit0,ihit1,ihit2,ihitL2;
1223
wire ihit = ihit0&ihit1&ihit2;
1224
reg phit;
1225
wire threadx;
1226
always @*
1227
        phit <= ihit&&icstate==IDLE;
1228
reg [2:0] iccnt;
1229
reg L1_wr0,L1_wr1,L1_wr2;
1230
reg L1_invline;
1231
wire [1:0] ic0_fault,ic1_fault,ic2_fault;
1232
reg [8:0] L1_en;
1233
reg [71:0] L1_adr, L2_adr;
1234
reg [297:0] L2_rdat;
1235
wire [297:0] L2_dato;
1236
reg L2_xsel;
1237
 
1238
generate begin : gRegfileInst
1239
if (`WAYS > 2) begin : gb1
1240
FT64_regfile2w9r_oc #(.RBIT(RBIT)) urf1
1241
(
1242
  .clk(clk),
1243
  .clk4x(clk4x),
1244
  .wr0(commit0_v),
1245
  .wr1(commit1_v),
1246
  .we0(commit0_we),
1247
  .we1(commit1_we),
1248
  .wa0(commit0_tgt),
1249
  .wa1(commit1_tgt),
1250
  .i0(commit0_bus),
1251
  .i1(commit1_bus),
1252
        .rclk(~clk),
1253
        .ra0(Ra0),
1254
        .ra1(Rb0),
1255
        .ra2(Rc0),
1256
        .o0(rfoa0),
1257
        .o1(rfob0),
1258
        .o2(rfoc0a),
1259
        .ra3(Ra1),
1260
        .ra4(Rb1),
1261
        .ra5(Rc1),
1262
        .o3(rfoa1),
1263
        .o4(rfob1),
1264
        .o5(rfoc1a),
1265
        .ra6(Ra2),
1266
        .ra7(Rb2),
1267
        .ra8(Rc2),
1268
        .o6(rfoa2),
1269
        .o7(rfob2),
1270
        .o8(rfoc2a)
1271
);
1272
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
1273
assign rfoc1 = Rc1[11:6]==6'h3F ? vm[Rc1[2:0]] : rfoc1a;
1274
assign rfoc2 = Rc2[11:6]==6'h3F ? vm[Rc2[2:0]] : rfoc2a;
1275
end
1276
else if (`WAYS > 1) begin : gb1
1277
FT64_regfile2w6r_oc #(.RBIT(RBIT)) urf1
1278
(
1279
  .clk(clk),
1280
  .clk4x(clk4x),
1281
  .wr0(commit0_v),
1282
  .wr1(commit1_v),
1283
  .we0(commit0_we),
1284
  .we1(commit1_we),
1285
  .wa0(commit0_tgt),
1286
  .wa1(commit1_tgt),
1287
  .i0(commit0_bus),
1288
  .i1(commit1_bus),
1289
        .rclk(~clk),
1290
        .ra0(Ra0),
1291
        .ra1(Rb0),
1292
        .ra2(Rc0),
1293
        .o0(rfoa0),
1294
        .o1(rfob0),
1295
        .o2(rfoc0a),
1296
        .ra3(Ra1),
1297
        .ra4(Rb1),
1298
        .ra5(Rc1),
1299
        .o3(rfoa1),
1300
        .o4(rfob1),
1301
        .o5(rfoc1a)
1302
);
1303
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
1304
assign rfoc1 = Rc1[11:6]==6'h3F ? vm[Rc1[2:0]] : rfoc1a;
1305
end
1306
else begin : gb1
1307
FT64_regfile1w4r_oc #(.RBIT(RBIT)) urf1
1308
(
1309
  .clk(clk),
1310
  .wr0(commit0_v),
1311
  .wa0(commit0_tgt),
1312
  .we0(8'hFF),
1313
  .i0(commit0_bus),
1314
  .rclk(~clk),
1315
        .ra0(Ra0),
1316
        .ra1(Rb0),
1317
        .ra2(Rc0),
1318
        .ra3(Rt0),
1319
        .o0(rfoa0),
1320
        .o1(rfob0),
1321
        .o2(rfoc0a),
1322
        .o3(rfot0)
1323
);
1324
end
1325
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
1326
end
1327
endgenerate
1328
 
1329
function [3:0] fnInsLength;
1330
input [47:0] ins;
1331
`ifdef SUPPORT_DCI
1332
if (ins[`INSTRUCTION_OP]==`CMPRSSD)
1333
        fnInsLength = 4'd2 | pred_on;
1334
else
1335
`endif
1336
        case(ins[7:6])
1337
        2'd0:   fnInsLength = 4'd4 | pred_on;
1338
        2'd1:   fnInsLength = 4'd6 | pred_on;
1339
        default:        fnInsLength = 4'd2 | pred_on;
1340
        endcase
1341
endfunction
1342
 
1343
wire [`ABITS] pc0plus6 = pc0 + 32'd7;
1344
wire [`ABITS] pc0plus12 = pc0 + 32'd14;
1345
 
1346
generate begin : gInsnVar
1347
        if (`WAYS > 1) begin
1348
                always @*
1349
                        if (thread_en)
1350
                                insn1a <= insn1b;
1351
                        else
1352
                                insn1a <= {insn1b,insn0a} >> {fnInsLength(insn0a),3'b0};
1353
        end
1354
        if (`WAYS > 2) begin
1355
                always @*
1356
                        if (thread_en)
1357
                                insn2a <= insn2b;
1358
                        else
1359
                                insn2a <= {insn2b,insn1b,insn0a} >> {fnInsLength(insn0a) + fnInsLength(insn1a),3'b0};
1360
        end
1361
end
1362
endgenerate
1363
 
1364
FT64_L1_icache #(.pSize(`L1_ICACHE_SIZE)) uic0
1365
(
1366
  .rst(rst),
1367
  .clk(clk),
1368
  .nxt(icnxt),
1369
  .wr(L1_wr0),
1370
  .wr_ack(),
1371
  .en(L1_en),
1372
  .adr((icstate==IDLE||icstate==IC_Next) ? {pcr[7:0],pc0} : L1_adr),
1373
  .wadr(L1_adr),
1374
  .i(L2_rdat),
1375
  .o(insn0a),
1376
  .fault(ic0_fault),
1377
  .hit(ihit0),
1378
  .invall(invic),
1379
  .invline(L1_invline)
1380
);
1381
generate begin : gICacheInst
1382
if (`WAYS > 1) begin
1383
FT64_L1_icache #(.pSize(`L1_ICACHE_SIZE)) uic1
1384
(
1385
  .rst(rst),
1386
  .clk(clk),
1387
  .nxt(icnxt),
1388
  .wr(L1_wr1),
1389
  .wr_ack(),
1390
  .en(L1_en),
1391
  .adr((icstate==IDLE||icstate==IC_Next) ? (thread_en ? {pcr[7:0],pc1}: {pcr[7:0],pc0plus6} ): L1_adr),
1392
  .wadr(L1_adr),
1393
  .i(L2_rdat),
1394
  .o(insn1b),
1395
  .fault(ic1_fault),
1396
  .hit(ihit1),
1397
  .invall(invic),
1398
  .invline(L1_invline)
1399
);
1400
end
1401
else begin
1402
assign ihit1 = 1'b1;
1403
end
1404
if (`WAYS > 2) begin
1405
FT64_L1_icache #(.pSize(`L1_ICACHE_SIZE)) uic2
1406
(
1407
  .rst(rst),
1408
  .clk(clk),
1409
  .nxt(icnxt),
1410
  .wr(L1_wr2),
1411
  .wr_ack(),
1412
  .en(L1_en),
1413
  .adr((icstate==IDLE||icstate==IC_Next) ? (thread_en ? {pcr[7:0],pc2} : {pcr[7:0],pc0plus12}) : L1_adr),
1414
  .wadr(L1_adr),
1415
  .i(L2_rdat),
1416
  .o(insn2b),
1417
  .fault(ic2_fault),
1418
  .hit(ihit2),
1419
  .invall(invic),
1420
  .invline(L1_invline)
1421
);
1422
end
1423
else
1424
assign ihit2 = 1'b1;
1425
end
1426
endgenerate
1427
 
1428
FT64_L2_icache uic2
1429
(
1430
  .rst(rst),
1431
  .clk(clk),
1432
  .nxt(L2_nxt),
1433
  .wr(bstate==B_ICacheAck && (ack_i|err_i)),
1434
  .xsel(L2_xsel),
1435
  .adr(L2_adr),
1436
  .cnt(iccnt),
1437
  .exv_i(exvq),
1438
  .i(dat_i),
1439
  .err_i(errq),
1440
  .o(L2_dato),
1441
  .hit(ihitL2),
1442
  .invall(invic),
1443
  .invline()
1444
);
1445
 
1446
wire predict_taken;
1447
wire predict_taken0;
1448
wire predict_taken1;
1449
wire predict_taken2;
1450
wire predict_takenA;
1451
wire predict_takenB;
1452
wire predict_takenC;
1453
wire predict_takenD;
1454
wire predict_takenE;
1455
wire predict_takenF;
1456
wire predict_takenA1;
1457
wire predict_takenB1;
1458
wire predict_takenC1;
1459
wire predict_takenD1;
1460
 
1461
wire [`ABITS] btgtA, btgtB, btgtC, btgtD, btgtE, btgtF;
1462
wire btbwr0 = iqentry_v[heads[0]] && iqentry_state[heads[0]]==IQS_CMT &&
1463
        (iqentry_fc[heads[0]]);
1464
generate begin: gbtbvar
1465
if (`WAYS > 1) begin
1466
wire btbwr1 = iqentry_v[heads[1]] && iqentry_state[heads[1]]==IQS_CMT &&
1467
        (iqentry_fc[heads[1]]);
1468
end
1469
if (`WAYS > 2) begin
1470
wire btbwr2 = iqentry_v[heads[2]] && iqentry_state[heads[2]]==IQS_CMT &&
1471
        (iqentry_fc[heads[2]]);
1472
end
1473
end
1474
endgenerate
1475
 
1476
wire fcu_clk;
1477
`ifdef FCU_ENH
1478
//BUFGCE ufcuclk
1479
//(
1480
//      .I(clk_i),
1481
//      .CE(fcu_available),
1482
//      .O(fcu_clk)
1483
//);
1484
`endif
1485
assign fcu_clk = clk_i;
1486
 
1487
generate begin: gBTBInst
1488
if (`WAYS > 2) begin
1489
`ifdef FCU_ENH
1490
FT64_BTB #(.AMSB(AMSB)) ubtb1
1491
(
1492
  .rst(rst),
1493
  .wclk(fcu_clk),
1494
  .wr0(btbwr0),
1495
  .wadr0(iqentry_pc[heads[0]]),
1496
  .wdat0(iqentry_ma[heads[0]]),
1497
  .valid0((iqentry_br[heads[0]] ? iqentry_takb[heads[0]] : iqentry_bt[heads[0]]) & iqentry_v[heads[0]]),
1498
  .wr1(btbwr1),
1499
  .wadr1(iqentry_pc[heads[1]]),
1500
  .wdat1(iqentry_ma[heads[1]]),
1501
  .valid1((iqentry_br[heads[1]] ? iqentry_takb[heads[1]] : iqentry_bt[heads[1]]) & iqentry_v[heads[1]]),
1502
  .wr2(btbwr2),
1503
  .wadr2(iqentry_pc[heads[2]]),
1504
  .wdat2(iqentry_ma[heads[2]]),
1505
  .valid2((iqentry_br[heads[2]] ? iqentry_takb[heads[2]] : iqentry_bt[heads[2]]) & iqentry_v[heads[2]]),
1506
  .rclk(~clk),
1507
  .pcA(fetchbufA_pc),
1508
  .btgtA(btgtA),
1509
  .pcB(fetchbufB_pc),
1510
  .btgtB(btgtB),
1511
  .pcC(fetchbufC_pc),
1512
  .btgtC(btgtC),
1513
  .pcD(fetchbufD_pc),
1514
  .btgtD(btgtD),
1515
  .pcE(fetchbufE_pc),
1516
  .btgtE(btgtE),
1517
  .pcF(fetchbufF_pc),
1518
  .btgtF(btgtF),
1519
  .npcA(BRKPC),
1520
  .npcB(BRKPC),
1521
  .npcC(BRKPC),
1522
  .npcD(BRKPC),
1523
  .npcE(BRKPC),
1524
  .npcF(BRKPC)
1525
);
1526
`else
1527
// Branch tergets are picked up by fetchbuf logic and need to be present.
1528
// Without a target predictor they are just set to the reset address.
1529
// This virtually guarentees a miss.
1530
assign btgtA = RSTPC;
1531
assign btgtB = RSTPC;
1532
assign btgtC = RSTPC;
1533
assign btgtD = RSTPC;
1534
assign btgtE = RSTPC;
1535
assign btgtF = RSTPC;
1536
`endif
1537
end
1538
else if (`WAYS > 1) begin
1539
`ifdef FCU_ENH
1540
FT64_BTB #(.AMSB(AMSB)) ubtb1
1541
(
1542
  .rst(rst),
1543
  .wclk(fcu_clk),
1544
  .wr0(btbwr0),
1545
  .wadr0(iqentry_pc[heads[0]]),
1546
  .wdat0(iqentry_ma[heads[0]]),
1547
  .valid0((iqentry_br[heads[0]] ? iqentry_takb[heads[0]] : iqentry_bt[heads[0]]) & iqentry_v[heads[0]]),
1548
  .wr1(btbwr1),
1549
  .wadr1(iqentry_pc[heads[1]]),
1550
  .wdat1(iqentry_ma[heads[1]]),
1551
  .valid1((iqentry_br[heads[1]] ? iqentry_takb[heads[1]] : iqentry_bt[heads[1]]) & iqentry_v[heads[1]]),
1552
  .rclk(~clk),
1553
  .pcA(fetchbufA_pc),
1554
  .btgtA(btgtA),
1555
  .pcB(fetchbufB_pc),
1556
  .btgtB(btgtB),
1557
  .pcC(fetchbufC_pc),
1558
  .btgtC(btgtC),
1559
  .pcD(fetchbufD_pc),
1560
  .btgtD(btgtD),
1561
  .pcE(32'd0),
1562
  .btgtE(),
1563
  .pcF(32'd0),
1564
  .btgtF(),
1565
  .npcA(BRKPC),
1566
  .npcB(BRKPC),
1567
  .npcC(BRKPC),
1568
  .npcD(BRKPC),
1569
  .npcE(BRKPC),
1570
  .npcF(BRKPC)
1571
);
1572
`else
1573
// Branch tergets are picked up by fetchbuf logic and need to be present.
1574
// Without a target predictor they are just set to the reset address.
1575
// This virtually guarentees a miss.
1576
assign btgtA = RSTPC;
1577
assign btgtB = RSTPC;
1578
assign btgtC = RSTPC;
1579
assign btgtD = RSTPC;
1580
`endif
1581
end
1582
else begin
1583
`ifdef FCU_ENH
1584
FT64_BTB #(.AMSB(AMSB)) ubtb1
1585
(
1586
  .rst(rst),
1587
  .wclk(fcu_clk),
1588
  .wr0(btbwr0),
1589
  .wadr0(iqentry_pc[heads[0]]),
1590
  .wdat0(iqentry_ma[heads[0]]),
1591
  .valid0((iqentry_br[heads[0]] ? iqentry_takb[heads[0]] : iqentry_bt[heads[0]]) & iqentry_v[heads[0]]),
1592
  .wr1(1'b0);
1593
  .wadr1(RSTPC),
1594
  .wdat1(RSTPC),
1595
  .valid1(1'b0),
1596
  .wr2(1'b0);
1597
  .wadr2(RSTPC),
1598
  .wdat2(RSTPC),
1599
  .valid2(1'b0),
1600
  .rclk(~clk),
1601
  .pcA(fetchbufA_pc),
1602
  .btgtA(btgtA),
1603
  .pcB(fetchbufB_pc),
1604
  .btgtB(btgtB),
1605
  .pcC(32'd0),
1606
  .btgtC(),
1607
  .pcD(32'd0),
1608
  .btgtD(),
1609
  .pcE(32'd0),
1610
  .btgtE(),
1611
  .pcF(32'd0),
1612
  .btgtF(),
1613
  .hitA(),
1614
  .hitB(),
1615
  .hitC(),
1616
  .hitD(),
1617
  .hitE(),
1618
  .hitF(),
1619
  .npcA(BRKPC),
1620
  .npcB(BRKPC),
1621
  .npcC(BRKPC),
1622
  .npcD(BRKPC),
1623
  .npcE(BRKPC),
1624
  .npcF(BRKPC)
1625
);
1626
`else
1627
// Branch tergets are picked up by fetchbuf logic and need to be present.
1628
// Without a target predictor they are just set to the reset address.
1629
// This virtually guarentees a miss.
1630
assign btgtA = RSTPC;
1631
assign btgtB = RSTPC;
1632
`endif
1633
end
1634
end
1635
endgenerate
1636
 
1637
generate begin: gBPInst
1638
if (`WAYS > 2) begin
1639
`ifdef FCU_ENH
1640
FT64_BranchPredictor ubp1
1641
(
1642
  .rst(rst),
1643
  .clk(fcu_clk),
1644
  .en(bpe),
1645
  .xisBranch0(iqentry_br[heads[0]] & commit0_v),
1646
  .xisBranch1(iqentry_br[heads[1]] & commit1_v),
1647
  .xisBranch2(iqentry_br[heads[2]] & commit2_v),
1648
  .pcA(fetchbufA_pc),
1649
  .pcB(fetchbufB_pc),
1650
  .pcC(fetchbufC_pc),
1651
  .pcD(fetchbufD_pc),
1652
  .pcE(fetchbufE_pc),
1653
  .pcF(fetchbufF_pc),
1654
  .xpc0(iqentry_pc[heads[0]]),
1655
  .xpc1(iqentry_pc[heads[1]]),
1656
  .xpc2(iqentry_pc[heads[2]]),
1657
  .takb0(commit0_v & iqentry_takb[heads[0]]),
1658
  .takb1(commit1_v & iqentry_takb[heads[1]]),
1659
  .takb2(commit2_v & iqentry_takb[heads[2]]),
1660
  .predict_takenA(predict_takenA),
1661
  .predict_takenB(predict_takenB),
1662
  .predict_takenC(predict_takenC),
1663
  .predict_takenD(predict_takenD),
1664
  .predict_takenE(predict_takenE),
1665
  .predict_takenF(predict_takenF)
1666
);
1667
`else
1668
// Predict based on sign of displacement
1669
assign predict_takenA = fetchbufA_instr[6] ? fetchbufA_instr[47] : fetchbufA_instr[31];
1670
assign predict_takenB = fetchbufB_instr[6] ? fetchbufB_instr[47] : fetchbufB_instr[31];
1671
assign predict_takenC = fetchbufC_instr[6] ? fetchbufC_instr[47] : fetchbufC_instr[31];
1672
assign predict_takenD = fetchbufD_instr[6] ? fetchbufD_instr[47] : fetchbufD_instr[31];
1673
assign predict_takenE = fetchbufE_instr[6] ? fetchbufE_instr[47] : fetchbufE_instr[31];
1674
assign predict_takenF = fetchbufF_instr[6] ? fetchbufF_instr[47] : fetchbufF_instr[31];
1675
`endif
1676
end
1677
else if (`WAYS > 1) begin
1678
`ifdef FCU_ENH
1679
FT64_BranchPredictor ubp1
1680
(
1681
  .rst(rst),
1682
  .clk(fcu_clk),
1683
  .en(bpe),
1684
  .xisBranch0(iqentry_br[heads[0]] & commit0_v),
1685
  .xisBranch1(iqentry_br[heads[1]] & commit1_v),
1686
  .xisBranch2(iqentry_br[heads[2]] & commit2_v),
1687
  .pcA(fetchbufA_pc),
1688
  .pcB(fetchbufB_pc),
1689
  .pcC(fetchbufC_pc),
1690
  .pcD(fetchbufD_pc),
1691
  .pcE(32'd0),
1692
  .pcF(32'd0),
1693
  .xpc0(iqentry_pc[heads[0]]),
1694
  .xpc1(iqentry_pc[heads[1]]),
1695
  .xpc2(iqentry_pc[heads[2]]),
1696
  .takb0(commit0_v & iqentry_takb[heads[0]]),
1697
  .takb1(commit1_v & iqentry_takb[heads[1]]),
1698
  .takb2(commit2_v & iqentry_takb[heads[2]]),
1699
  .predict_takenA(predict_takenA),
1700
  .predict_takenB(predict_takenB),
1701
  .predict_takenC(predict_takenC),
1702
  .predict_takenD(predict_takenD),
1703
  .predict_takenE(),
1704
  .predict_takenF()
1705
);
1706
`else
1707
// Predict based on sign of displacement
1708
assign predict_takenA = fetchbufA_instr[6] ? fetchbufA_instr[47] : fetchbufA_instr[31];
1709
assign predict_takenB = fetchbufB_instr[6] ? fetchbufB_instr[47] : fetchbufB_instr[31];
1710
assign predict_takenC = fetchbufC_instr[6] ? fetchbufC_instr[47] : fetchbufC_instr[31];
1711
assign predict_takenD = fetchbufD_instr[6] ? fetchbufD_instr[47] : fetchbufD_instr[31];
1712
`endif
1713
end
1714
else begin
1715
`ifdef FCU_ENH
1716
FT64_BranchPredictor ubp1
1717
(
1718
  .rst(rst),
1719
  .clk(fcu_clk),
1720
  .en(bpe),
1721
  .xisBranch0(iqentry_br[heads[0]] & commit0_v),
1722
  .xisBranch1(iqentry_br[heads[1]] & commit1_v),
1723
  .xisBranch2(iqentry_br[heads[2]] & commit2_v),
1724
  .pcA(fetchbufA_pc),
1725
  .pcB(fetchbufB_pc),
1726
  .pcC(32'd0),
1727
  .pcD(32'd0),
1728
  .pcE(32'd0),
1729
  .pcF(32'd0),
1730
  .xpc0(iqentry_pc[heads[0]]),
1731
  .xpc1(iqentry_pc[heads[1]]),
1732
  .xpc2(iqentry_pc[heads[2]]),
1733
  .takb0(commit0_v & iqentry_takb[heads[0]]),
1734
  .takb1(commit1_v & iqentry_takb[heads[1]]),
1735
  .takb2(commit2_v & iqentry_takb[heads[2]]),
1736
  .predict_takenA(predict_takenA),
1737
  .predict_takenB(predict_takenB),
1738
  .predict_takenC(),
1739
  .predict_takenD(),
1740
  .predict_takenE(),
1741
  .predict_takenF()
1742
);
1743
`else
1744
// Predict based on sign of displacement
1745
assign predict_takenA = fetchbufA_instr[6] ? fetchbufA_instr[47] : fetchbufA_instr[31];
1746
assign predict_takenB = fetchbufB_instr[6] ? fetchbufB_instr[47] : fetchbufB_instr[31];
1747
`endif
1748
end
1749
end
1750
endgenerate
1751
 
1752
//-----------------------------------------------------------------------------
1753
// Debug
1754
//-----------------------------------------------------------------------------
1755
`ifdef SUPPORT_DBG
1756
 
1757
wire [DBW-1:0] dbg_stat1x;
1758
reg [DBW-1:0] dbg_stat;
1759
reg [DBW-1:0] dbg_ctrl;
1760
reg [ABW-1:0] dbg_adr0;
1761
reg [ABW-1:0] dbg_adr1;
1762
reg [ABW-1:0] dbg_adr2;
1763
reg [ABW-1:0] dbg_adr3;
1764
reg dbg_imatchA0,dbg_imatchA1,dbg_imatchA2,dbg_imatchA3,dbg_imatchA;
1765
reg dbg_imatchB0,dbg_imatchB1,dbg_imatchB2,dbg_imatchB3,dbg_imatchB;
1766
 
1767
wire dbg_lmatch00 =
1768
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1769
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1770
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1771
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1772
                                 dbg_ctrl[19:18]==2'b11)
1773
                                 ;
1774
wire dbg_lmatch01 =
1775
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1776
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1777
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1778
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1779
                  dbg_ctrl[19:18]==2'b11)
1780
                  ;
1781
wire dbg_lmatch02 =
1782
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1783
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1784
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1785
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1786
                dbg_ctrl[19:18]==2'b11)
1787
                ;
1788
wire dbg_lmatch10 =
1789
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1790
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1791
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1792
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1793
                  dbg_ctrl[23:22]==2'b11)
1794
                  ;
1795
wire dbg_lmatch11 =
1796
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1797
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1798
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1799
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1800
                dbg_ctrl[23:22]==2'b11)
1801
                ;
1802
wire dbg_lmatch12 =
1803
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1804
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1805
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1806
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1807
                dbg_ctrl[23:22]==2'b11)
1808
                ;
1809
wire dbg_lmatch20 =
1810
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1811
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1812
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1813
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1814
                    dbg_ctrl[27:26]==2'b11)
1815
                    ;
1816
wire dbg_lmatch21 =
1817
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1818
                   ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1819
                    (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1820
                    (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1821
                    dbg_ctrl[27:26]==2'b11)
1822
                    ;
1823
wire dbg_lmatch22 =
1824
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1825
                   ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1826
                    (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1827
                    (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1828
                    dbg_ctrl[27:26]==2'b11)
1829
                    ;
1830
wire dbg_lmatch30 =
1831
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1832
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1833
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1834
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1835
                      dbg_ctrl[31:30]==2'b11)
1836
                      ;
1837
wire dbg_lmatch31 =
1838
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1839
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1840
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1841
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1842
                    dbg_ctrl[31:30]==2'b11)
1843
                    ;
1844
wire dbg_lmatch32 =
1845
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1846
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1847
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1848
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1849
                    dbg_ctrl[31:30]==2'b11)
1850
                    ;
1851
wire dbg_lmatch0 = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30;
1852
wire dbg_lmatch1 = dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31;
1853
wire dbg_lmatch2 = dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32;
1854
wire dbg_lmatch = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30|
1855
                  dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31|
1856
                  dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32
1857
                    ;
1858
 
1859
wire dbg_smatch00 =
1860
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1861
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1862
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1863
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1864
                                 dbg_ctrl[19:18]==2'b11)
1865
                                 ;
1866
wire dbg_smatch01 =
1867
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1868
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1869
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1870
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1871
                  dbg_ctrl[19:18]==2'b11)
1872
                  ;
1873
wire dbg_smatch02 =
1874
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1875
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1876
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1877
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1878
                dbg_ctrl[19:18]==2'b11)
1879
                ;
1880
wire dbg_smatch10 =
1881
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1882
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1883
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1884
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1885
                  dbg_ctrl[23:22]==2'b11)
1886
                  ;
1887
wire dbg_smatch11 =
1888
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1889
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1890
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1891
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1892
                dbg_ctrl[23:22]==2'b11)
1893
                ;
1894
wire dbg_smatch12 =
1895
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1896
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1897
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1898
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1899
                dbg_ctrl[23:22]==2'b11)
1900
                ;
1901
wire dbg_smatch20 =
1902
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1903
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1904
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1905
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1906
                    dbg_ctrl[27:26]==2'b11)
1907
                    ;
1908
wire dbg_smatch21 =
1909
           dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1910
                    ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1911
                     (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1912
                     (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1913
                     dbg_ctrl[27:26]==2'b11)
1914
                     ;
1915
wire dbg_smatch22 =
1916
            dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1917
                     ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1918
                      (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1919
                      (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1920
                      dbg_ctrl[27:26]==2'b11)
1921
                      ;
1922
wire dbg_smatch30 =
1923
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1924
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1925
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1926
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1927
                      dbg_ctrl[31:30]==2'b11)
1928
                      ;
1929
wire dbg_smatch31 =
1930
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1931
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1932
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1933
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1934
                    dbg_ctrl[31:30]==2'b11)
1935
                    ;
1936
wire dbg_smatch32 =
1937
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1938
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1939
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1940
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1941
                    dbg_ctrl[31:30]==2'b11)
1942
                    ;
1943
wire dbg_smatch0 = dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30;
1944
wire dbg_smatch1 = dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31;
1945
wire dbg_smatch2 = dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32;
1946
 
1947
wire dbg_smatch =   dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30|
1948
                    dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31|
1949
                    dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32
1950
                    ;
1951
 
1952
wire dbg_stat0 = dbg_imatchA0 | dbg_imatchB0 | dbg_lmatch00 | dbg_lmatch01 | dbg_lmatch02 | dbg_smatch00 | dbg_smatch01 | dbg_smatch02;
1953
wire dbg_stat1 = dbg_imatchA1 | dbg_imatchB1 | dbg_lmatch10 | dbg_lmatch11 | dbg_lmatch12 | dbg_smatch10 | dbg_smatch11 | dbg_smatch12;
1954
wire dbg_stat2 = dbg_imatchA2 | dbg_imatchB2 | dbg_lmatch20 | dbg_lmatch21 | dbg_lmatch22 | dbg_smatch20 | dbg_smatch21 | dbg_smatch22;
1955
wire dbg_stat3 = dbg_imatchA3 | dbg_imatchB3 | dbg_lmatch30 | dbg_lmatch31 | dbg_lmatch32 | dbg_smatch30 | dbg_smatch31 | dbg_smatch32;
1956
assign dbg_stat1x = {dbg_stat3,dbg_stat2,dbg_stat1,dbg_stat0};
1957
wire debug_on = |dbg_ctrl[3:0]|dbg_ctrl[7]|dbg_ctrl[63];
1958
 
1959
always @*
1960
begin
1961
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf0_pc==dbg_adr0)
1962
        dbg_imatchA0 = `TRUE;
1963
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf0_pc==dbg_adr1)
1964
        dbg_imatchA1 = `TRUE;
1965
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf0_pc==dbg_adr2)
1966
        dbg_imatchA2 = `TRUE;
1967
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf0_pc==dbg_adr3)
1968
        dbg_imatchA3 = `TRUE;
1969
    if (dbg_imatchA0|dbg_imatchA1|dbg_imatchA2|dbg_imatchA3)
1970
        dbg_imatchA = `TRUE;
1971
end
1972
 
1973
always @*
1974
begin
1975
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf1_pc==dbg_adr0)
1976
        dbg_imatchB0 = `TRUE;
1977
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf1_pc==dbg_adr1)
1978
        dbg_imatchB1 = `TRUE;
1979
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf1_pc==dbg_adr2)
1980
        dbg_imatchB2 = `TRUE;
1981
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf1_pc==dbg_adr3)
1982
        dbg_imatchB3 = `TRUE;
1983
    if (dbg_imatchB0|dbg_imatchB1|dbg_imatchB2|dbg_imatchB3)
1984
        dbg_imatchB = `TRUE;
1985
end
1986
`endif
1987
 
1988
//-----------------------------------------------------------------------------
1989
//-----------------------------------------------------------------------------
1990
 
1991
// freezePC squashes the pc increment if there's an irq.
1992
// If there is a segment prefix present then defer the freezing of the pc.
1993
// If a hardware interrupt instruction is encountered in the instruction stream
1994
// flag it as a privilege violation.
1995
wire freezePC = (irq_i > im) && !int_commit;
1996
always @*
1997
if (freezePC) begin
1998
        insn0 <= {8'h00,6'd0,5'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1999
end
2000
else if (phit) begin
2001
//      if (insn0a[`INSTRUCTION_OP]==`BRK && insn0a[25:21]==5'd0 && insn0a[`INSTRUCTION_L2]==2'b00)
2002
//              insn0 <= {6'd1,5'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
2003
//      else
2004
                insn0 <= insn0a;
2005
end
2006
else begin
2007
        insn0 <= {8'h00,`NOP_INSN};
2008
end
2009
generate begin : gInsnMux
2010
if (`WAYS > 1) begin
2011
always @*
2012
if (freezePC && !thread_en) begin
2013
        insn1 <= {8'h00,6'd0,5'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
2014
end
2015
else if (phit) begin
2016
//      if (insn1a[`INSTRUCTION_OP]==`BRK && insn1a[25:21]==5'd0 && insn1a[`INSTRUCTION_L2]==2'b00)
2017
//              insn1 <= {6'd1,5'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
2018
//      else
2019
                insn1 <= insn1a;
2020
end
2021
else begin
2022
        insn1 <= {8'h00,`NOP_INSN};
2023
end
2024
end
2025
if (`WAYS > 2) begin
2026
always @*
2027
if (freezePC && !thread_en)
2028
        insn2 <= {6'd0,5'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
2029
else if (phit) begin
2030
//      if (insn2a[`INSTRUCTION_OP]==`BRK && insn1a[25:21]==5'd0 && insn2a[`INSTRUCTION_L2]==2'b00)
2031
//              insn2 <= {6'd1,5'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
2032
//      else
2033
                insn2 <= insn2a;
2034
end
2035
else
2036
        insn2 <= `NOP_INSN;
2037
end
2038
end
2039
endgenerate
2040
 
2041
wire [63:0] dc0_out, dc1_out, dc2_out;
2042
assign rdat0 = dram0_unc ? xdati : dc0_out;
2043
assign rdat1 = dram1_unc ? xdati : dc1_out;
2044
assign rdat2 = dram2_unc ? xdati : dc2_out;
2045
 
2046
reg preload;
2047
reg [1:0] dccnt;
2048
wire dhit0, dhit1, dhit2;
2049
wire dhit0a, dhit1a, dhit2a;
2050
wire dhit00, dhit10, dhit20;
2051
wire dhit01, dhit11, dhit21;
2052
reg [`ABITS] dc_wadr;
2053
reg [63:0] dc_wdat;
2054
reg isStore;
2055
 
2056
// If the data is in the write buffer, give the buffer a chance to
2057
// write out the data before trying to load from the cache.
2058
reg wb_hit0, wb_hit1, wb_hit2;
2059
always @*
2060
begin
2061
        wb_hit0 <= FALSE;
2062
        wb_hit1 <= FALSE;
2063
        wb_hit2 <= FALSE;
2064
        for (n = 0; n < `WB_DEPTH; n = n + 1) begin
2065
                if (wb_v[n] && wb_addr[n][AMSB:3]==dram0_addr[AMSB:3])
2066
                        wb_hit0 <= TRUE;
2067
                if (`NUM_MEM > 1 && wb_v[n] && wb_addr[n][AMSB:3]==dram1_addr[AMSB:3])
2068
                        wb_hit1 <= TRUE;
2069
                if (`NUM_MEM > 2 && wb_v[n] && wb_addr[n][AMSB:3]==dram2_addr[AMSB:3])
2070
                        wb_hit2 <= TRUE;
2071
        end
2072
end
2073
 
2074
assign dhit0 = dhit0a && !wb_hit0;
2075
assign dhit1 = dhit1a && !wb_hit1;
2076
assign dhit2 = dhit2a && !wb_hit2;
2077
wire whit0, whit1, whit2;
2078
 
2079
wire wr_dcache0 = (bstate==B_DCacheLoadAck && ack_i)||(((bstate==B_StoreAck && StoreAck1) || (bstate==B19 && isStore)) && whit0);
2080
wire wr_dcache1 = (bstate==B_DCacheLoadAck && ack_i)||(((bstate==B_StoreAck && StoreAck1) || (bstate==B19 && isStore)) && whit1);
2081
wire wr_dcache2 = (bstate==B_DCacheLoadAck && ack_i)||(((bstate==B_StoreAck && StoreAck1) || (bstate==B19 && isStore)) && whit2);
2082
 
2083
FT64_dcache udc0
2084
(
2085
  .rst(rst),
2086
  .wclk(clk),
2087
  .dce(dce),
2088
  .wr(wr_dcache0),
2089
  .sel(sel_o),
2090
  .wadr({pcr[7:0],vadr}),
2091
  .whit(whit0),
2092
  .i((bstate==B_DCacheLoadAck) ? dat_i : dat_o),
2093
  .rclk(clk),
2094
  .rdsize(dram0_memsize),
2095
  .radr({pcr[7:0],dram0_addr}),
2096
  .o(dc0_out),
2097
  .rhit(dhit0a)
2098
);
2099
generate begin : gDCacheInst
2100
if (`NUM_MEM > 1) begin
2101
FT64_dcache udc1
2102
(
2103
  .rst(rst),
2104
  .wclk(clk),
2105
  .dce(dce),
2106
  .wr(wr_dcache1),
2107
  .sel(sel_o),
2108
  .wadr({pcr[7:0],vadr}),
2109
  .whit(whit1),
2110
  .i((bstate==B_DCacheLoadAck) ? dat_i : dat_o),
2111
  .rclk(clk),
2112
  .rdsize(dram1_memsize),
2113
  .radr({pcr[7:0],dram1_addr}),
2114
  .o(dc1_out),
2115
  .rhit(dhit1a)
2116
);
2117
end
2118
if (`NUM_MEM > 2) begin
2119
FT64_dcache udc2
2120
(
2121
  .rst(rst),
2122
  .wclk(clk),
2123
  .dce(dce),
2124
  .wr(wr_dcache2),
2125
  .sel(sel_o),
2126
  .wadr({pcr[7:0],vadr}),
2127
  .whit(whit2),
2128
  .i((bstate==B_DCacheLoadAck) ? dat_i : dat_o),
2129
  .rclk(clk),
2130
  .rdsize(dram2_memsize),
2131
  .radr({pcr[7:0],dram2_addr}),
2132
  .o(dc2_out),
2133
  .rhit(dhit2a)
2134
);
2135
end
2136
end
2137
endgenerate
2138
 
2139
`ifdef SUPPORT_SMT
2140
function [RBIT:0] fnRa;
2141
input [47:0] isn;
2142
input [5:0] vqei;
2143
input [5:0] vli;
2144
input thrd;
2145
case(isn[`INSTRUCTION_OP])
2146
`IVECTOR:
2147
        case(isn[`INSTRUCTION_S2])
2148
        `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
2149
        `VMxx:
2150
                case(isn[25:23])
2151
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
2152
                    fnRa = {6'h3F,1'b1,2'b0,isn[10:8]};
2153
            `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
2154
            default:fnRa = {6'h3F,1'b1,2'b0,isn[10:8]};
2155
            endcase
2156
        `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
2157
        `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
2158
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
2159
        default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
2160
        endcase
2161
`R2:    casez(isn[`INSTRUCTION_S2])
2162
                `MOV:
2163
                        case(isn[25:23])
2164
                        3'd0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2165
                        3'd1:   fnRa = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
2166
                        3'd2:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2167
                        3'd3:   fnRa = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RA]};
2168
                        3'd4:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2169
                        3'd5:   fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2170
                        3'd6:   fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2171
                        default:fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2172
                        endcase
2173
        `VMOV:
2174
            case (isn[`INSTRUCTION_S1])
2175
            5'h0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2176
            5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
2177
            endcase
2178
        default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2179
        endcase
2180
`FLOAT:         fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2181
default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2182
endcase
2183
endfunction
2184
 
2185
function [RBIT:0] fnRb;
2186
input [47:0] isn;
2187
input fb;
2188
input [5:0] vqei;
2189
input [5:0] rfoa0i;
2190
input [5:0] rfoa1i;
2191
input thrd;
2192
case(isn[`INSTRUCTION_OP])
2193
`R2:        case(isn[`INSTRUCTION_S2])
2194
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
2195
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2196
            default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2197
            endcase
2198
`IVECTOR:
2199
                        case(isn[`INSTRUCTION_S2])
2200
                        `VMxx:
2201
                                case(isn[25:23])
2202
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2203
                        fnRb = {6'h3F,1'b1,2'b0,isn[20:18]};
2204
                default:        fnRb = 12'h000;
2205
                endcase
2206
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2207
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2208
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
2209
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
2210
                fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2211
            `VSHL,`VSHR,`VASR:
2212
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
2213
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2214
            endcase
2215
`FLOAT:         fnRb = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2216
default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2217
endcase
2218
endfunction
2219
 
2220
function [RBIT:0] fnRc;
2221
input [47:0] isn;
2222
input [5:0] vqei;
2223
input thrd;
2224
case(isn[`INSTRUCTION_OP])
2225
`R2:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2226
`MEMNDX:        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};   // SVX not implemented
2227
`IVECTOR:
2228
                        case(isn[`INSTRUCTION_S2])
2229
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[25:23]};
2230
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2231
            endcase
2232
`FLOAT:         fnRc = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2233
default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2234
endcase
2235
endfunction
2236
 
2237
function [RBIT:0] fnRt;
2238
input [47:0] isn;
2239
input [5:0] vqei;
2240
input [5:0] vli;
2241
input thrd;
2242
casez(isn[`INSTRUCTION_OP])
2243
`IVECTOR:
2244
                case(isn[`INSTRUCTION_S2])
2245
                `VMxx:
2246
                        case(isn[25:23])
2247
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
2248
                    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2249
            `VMPOP:     fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2250
            default:
2251
                    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2252
            endcase
2253
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2254
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RT]};
2255
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RT]};
2256
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};    // ToDo: add element # from Ra
2257
        `V2BITS:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2258
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_Rt]};
2259
        endcase
2260
 
2261
`R2:
2262
        if (isn[`INSTRUCTION_L2]==2'b01)
2263
                case(isn[47:42])
2264
          `CMOVEZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2265
        `CMOVNZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2266
        default:                fnRt = 12'd0;
2267
                endcase
2268
        else
2269
    casez(isn[`INSTRUCTION_S2])
2270
                `MOV:
2271
                        case(isn[25:23])
2272
                        3'd0:   fnRt = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RT]};
2273
                        3'd1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2274
                        3'd2:   fnRt = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RT]};
2275
                        3'd3:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2276
                        3'd4:   fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2277
                        3'd5:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2278
                        3'd6:   fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2279
                        default:fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2280
                        endcase
2281
        `VMOV:
2282
            case (isn[`INSTRUCTION_S1])
2283
            5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RT]};
2284
            5'h1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2285
            default:    fnRt = 12'h000;
2286
            endcase
2287
        `R1:
2288
                case(isn[22:18])
2289
                `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT,`NEG,`REDOR,`ZXB,`ZXC,`ZXH,`SXB,`SXC,`SXH:
2290
                        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2291
                `MEMDB,`MEMSB,`SYNC:
2292
                        fnRt = 12'd0;
2293
                default:        fnRt = 12'd0;
2294
                endcase
2295
        `CMOVEZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2296
        `CMOVNZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2297
        `MUX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2298
        `MIN:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2299
        `MAX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2300
        `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
2301
        `SHIFTR:        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2302
        `SHIFT31,`SHIFT63:
2303
                                fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2304
        `SEI:           fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2305
        `WAIT,`RTI,`CHK:
2306
                        fnRt = 12'd0;
2307
                default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2308
        endcase
2309
`MEMNDX:
2310
        begin
2311
                if (!isn[31])
2312
                        case({isn[31:28],isn[22:21]})
2313
                        `LVX,
2314
                        `CACHEX,
2315
                        `LVBX,`LVBUX,`LVCX,`LVCUX,`LVHX,`LVHUX,`LVWX,
2316
                        `LBX,`LBUX,`LCX,`LCUX,`LHX,`LHUX,`LWX,`LWRX:
2317
                                fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2318
                        default: fnRt = 12'd0;
2319
                        endcase
2320
                else
2321
                        case({isn[31:28],isn[17:16]})
2322
                        `PUSH:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2323
                  `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
2324
                                        fnRt = 12'd0;
2325
                  default:    fnRt = 12'd0;
2326
                  endcase
2327
        end
2328
`FLOAT:
2329
                case(isn[31:26])
2330
                `FTX,`FCX,`FEX,`FDX,`FRM:
2331
                                        fnRt = 12'd0;
2332
                `FSYNC:         fnRt = 12'd0;
2333
                default:        fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2334
                endcase
2335
`BRK:   fnRt = 12'd0;
2336
`REX:   fnRt = 12'd0;
2337
`CHK:   fnRt = 12'd0;
2338
`EXEC:  fnRt = 12'd0;
2339
`Bcc:   fnRt = 12'd0;
2340
`BBc:   fnRt = 12'd0;
2341
`NOP:  fnRt = 12'd0;
2342
`BEQI:  fnRt = 12'd0;
2343
`SB,`Sx,`SWC,`CACHE:
2344
                fnRt = 12'd0;
2345
`JMP:   fnRt = 12'd0;
2346
`CALL:  fnRt = {rgs[thrd],1'b0,5'd29};  // regLR
2347
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};
2348
`AMO:   fnRt = isn[31] ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]} : {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2349
`AUIPC,`LUI:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2350
default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RT]};
2351
endcase
2352
endfunction
2353
`else
2354
function [RBIT:0] fnRa;
2355
input [47:0] isn;
2356
input [5:0] vqei;
2357
input [5:0] vli;
2358
input thrd;
2359
case(isn[`INSTRUCTION_OP])
2360
`IVECTOR:
2361
        case(isn[`INSTRUCTION_S2])
2362
  `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
2363
  `VMxx:
2364
        case(isn[25:23])
2365
        `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
2366
              fnRa = {6'h3F,1'b1,2'b0,isn[10:8]};
2367
      `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
2368
      default:fnRa = {6'h3F,1'b1,2'b0,isn[10:8]};
2369
      endcase
2370
  `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
2371
  `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
2372
  `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
2373
  default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
2374
  endcase
2375
`R2:
2376
        casez(isn[`INSTRUCTION_S2])
2377
        `MOV:
2378
                case(isn[25:23])
2379
                3'd0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2380
                3'd1:   fnRa = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
2381
                3'd2:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2382
                3'd3:   fnRa = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RA]};
2383
                3'd4:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2384
                3'd5:   fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2385
                3'd6:   fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2386
                default:fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2387
                endcase
2388
  `VMOV:
2389
    case (isn[`INSTRUCTION_S1])
2390
    5'h0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2391
    5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
2392
    default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2393
    endcase
2394
  default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2395
  endcase
2396
`FLOAT:         fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2397
default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2398
endcase
2399
endfunction
2400
 
2401
function [RBIT:0] fnRb;
2402
input [47:0] isn;
2403
input fb;
2404
input [5:0] vqei;
2405
input [5:0] rfoa0i;
2406
input [5:0] rfoa1i;
2407
input thrd;
2408
case(isn[`INSTRUCTION_OP])
2409
`RR:        case(isn[`INSTRUCTION_S2])
2410
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
2411
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2412
            default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2413
            endcase
2414
`IVECTOR:
2415
                        case(isn[`INSTRUCTION_S2])
2416
                        `VMxx:
2417
                                case(isn[25:23])
2418
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2419
                        fnRb = {6'h3F,1'b1,2'b0,isn[20:18]};
2420
                default:        fnRb = 12'h000;
2421
                endcase
2422
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2423
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2424
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
2425
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
2426
                fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2427
            `VSHL,`VSHR,`VASR:
2428
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
2429
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2430
            endcase
2431
`FLOAT:         fnRb = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
2432
default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2433
endcase
2434
endfunction
2435
 
2436
function [RBIT:0] fnRc;
2437
input [47:0] isn;
2438
input [5:0] vqei;
2439
input thrd;
2440
case(isn[`INSTRUCTION_OP])
2441
`R2:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2442
`MEMNDX:        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]}; // SVX not implemented
2443
`IVECTOR:
2444
                        case(isn[`INSTRUCTION_S2])
2445
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[25:23]};
2446
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2447
            endcase
2448
`FLOAT:         fnRc = {fp_rgs,1'b0,isn[`INSTRUCTION_RC]};
2449
default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2450
endcase
2451
endfunction
2452
 
2453
function [RBIT:0] fnRt;
2454
input [47:0] isn;
2455
input [5:0] vqei;
2456
input [5:0] vli;
2457
input thrd;
2458
casez(isn[`INSTRUCTION_OP])
2459
`IVECTOR:
2460
                case(isn[`INSTRUCTION_S2])
2461
                `VMxx:
2462
                        case(isn[25:23])
2463
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
2464
                    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2465
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2466
            default:
2467
                    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2468
            endcase
2469
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2470
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RT]};
2471
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RT]};
2472
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};    // ToDo: add element # from Ra
2473
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2474
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};
2475
        endcase
2476
 
2477
`FVECTOR:
2478
                case(isn[`INSTRUCTION_S2])
2479
                `VMxx:
2480
                        case(isn[25:23])
2481
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
2482
                    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2483
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2484
            default:
2485
                    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2486
            endcase
2487
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[15:13]};
2488
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RT]};
2489
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RT]};
2490
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};    // ToDo: add element # from Ra
2491
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2492
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};
2493
        endcase
2494
 
2495
`R2:
2496
        if (isn[`INSTRUCTION_L2]==2'b01)
2497
                case(isn[47:42])
2498
          `CMOVEZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2499
        `CMOVNZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2500
        default:                fnRt = 12'd0;
2501
                endcase
2502
        else
2503
        casez(isn[`INSTRUCTION_S2])
2504
        `MOV:
2505
                case(isn[25:23])
2506
                3'd0:   fnRt = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RT]};
2507
                3'd1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2508
                3'd2:   fnRt = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RT]};
2509
                3'd3:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2510
                3'd4:   fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RT]};
2511
                3'd5:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2512
                3'd6:   fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RT]};
2513
                default:fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2514
                endcase
2515
  `VMOV:
2516
    case (isn[`INSTRUCTION_S1])
2517
    5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RT]};
2518
    5'h1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2519
    default:    fnRt = 12'h000;
2520
    endcase
2521
  `R1:
2522
        case(isn[22:18])
2523
        `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT,`NEG,`REDOR,`ZXB,`ZXC,`ZXH,`SXB,`SXC,`SXH:
2524
                fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2525
        `MEMDB,`MEMSB,`SYNC:
2526
                fnRt = 12'd0;
2527
        default:        fnRt = 12'd0;
2528
        endcase
2529
  `MUX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2530
  `MIN:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2531
  `MAX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2532
  `LVX:       fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};
2533
  `SHIFTR:      fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2534
  `SHIFT31,`SHIFT63:
2535
                        fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2536
  `SEI:         fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2537
  `WAIT,`RTI,`CHK:
2538
                        fnRt = 12'd0;
2539
  default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2540
  endcase
2541
`MEMNDX:
2542
        begin
2543
                if (!isn[31])
2544
                        case({isn[31:28],isn[22:21]})
2545
                        `LVX,
2546
                        `CACHEX,
2547
                        `LVBX,`LVBUX,`LVCX,`LVCUX,`LVHX,`LVHUX,`LVWX,
2548
                        `LBX,`LBUX,`LCX,`LCUX,`LHX,`LHUX,`LWX,`LWRX:
2549
                                fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2550
                        default: fnRt = 12'd0;
2551
                        endcase
2552
                else
2553
                        case({isn[31:28],isn[17:16]})
2554
                        `PUSH:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2555
                  `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
2556
                                        fnRt = 12'd0;
2557
                  default:    fnRt = 12'd0;
2558
                  endcase
2559
        end
2560
`FLOAT:
2561
                case(isn[31:26])
2562
                `FTX,`FCX,`FEX,`FDX,`FRM:
2563
                                        fnRt = 12'd0;
2564
                `FSYNC:         fnRt = 12'd0;
2565
                default:        fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RT]};
2566
                endcase
2567
`BRK:   fnRt = 12'd0;
2568
`REX:   fnRt = 12'd0;
2569
`CHK:   fnRt = 12'd0;
2570
`EXEC:  fnRt = 12'd0;
2571
`Bcc:   fnRt = 12'd0;
2572
`BBc:   fnRt = 12'd0;
2573
`NOP:  fnRt = 12'd0;
2574
`BEQI:  fnRt = 12'd0;
2575
`SB,`Sx,`SWC,`CACHE:
2576
                fnRt = 12'd0;
2577
`JMP:   fnRt = 12'd0;
2578
`CALL:  fnRt = {rgs,1'b0,5'd29};        // regLR
2579
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RT]};
2580
`AMO:   fnRt = isn[31] ? {rgs,1'b0,isn[`INSTRUCTION_RT]} : {rgs,1'b0,isn[`INSTRUCTION_RT]};
2581
`AUIPC,`LUI:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2582
default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RT]};
2583
endcase
2584
endfunction
2585
`endif
2586
 
2587
// Determines which lanes of the target register get updated.
2588
// Duh, all the lanes.
2589
function [7:0] fnWe;
2590
input [47:0] isn;
2591
casez(isn[`INSTRUCTION_OP])
2592
`R2:
2593
        case(isn[`INSTRUCTION_S2])
2594
        `CMP:   fnWe = 8'h00;
2595
        default: fnWe = 8'hFF;
2596
        endcase
2597
`CMPI:  fnWe = 8'h00;
2598
default: fnWe = 8'hFF;
2599
endcase
2600
/*
2601
casez(isn[`INSTRUCTION_OP])
2602
`R2:
2603
        case(isn[`INSTRUCTION_S2])
2604
        `R1:
2605
                case(isn[22:18])
2606
                `ABS,`CNTLZ,`CNTLO,`CNTPOP:
2607
                        case(isn[25:23])
2608
                        3'b000: fnWe = 8'h01;
2609
                        3'b001: fnWe = 8'h03;
2610
                        3'b010: fnWe = 8'h0F;
2611
                        3'b011: fnWe = 8'hFF;
2612
                        default:        fnWe = 8'hFF;
2613
                        endcase
2614
                default: fnWe = 8'hFF;
2615
                endcase
2616
        `SHIFT31:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2617
        `SHIFT63:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2618
        `SLT,`SLTU,`SLE,`SLEU,
2619
        `ADD,`SUB,
2620
        `AND,`OR,`XOR,
2621
        `NAND,`NOR,`XNOR,
2622
        `DIV,`DIVU,`DIVSU,
2623
        `MOD,`MODU,`MODSU,
2624
        `MUL,`MULU,`MULSU,
2625
        `MULH,`MULUH,`MULSUH,
2626
        `FXMUL:
2627
                case(isn[25:23])
2628
                3'b000: fnWe = 8'h01;
2629
                3'b001: fnWe = 8'h03;
2630
                3'b010: fnWe = 8'h0F;
2631
                3'b011: fnWe = 8'hFF;
2632
                default:        fnWe = 8'hFF;
2633
                endcase
2634
        default: fnWe = 8'hFF;
2635
        endcase
2636
default:        fnWe = 8'hFF;
2637
endcase
2638
*/
2639
endfunction
2640
 
2641
// Detect if a source is automatically valid
2642
function Source1Valid;
2643
input [47:0] isn;
2644
casez(isn[`INSTRUCTION_OP])
2645
`BRK:   Source1Valid = isn[16] ? isn[`INSTRUCTION_RA]==5'd0 : TRUE;
2646
`Bcc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2647
`BBc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2648
`BEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2649
`CHK:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2650
`RR:    case(isn[`INSTRUCTION_S2])
2651
        `SHIFT31:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2652
        `SHIFT63:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2653
        `SHIFTR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2654
        default:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2655
        endcase
2656
`MEMNDX:Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2657
`ADDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2658
`SLTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2659
`SLTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2660
`SGTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2661
`SGTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2662
`ANDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2663
`ORI:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2664
`XORI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2665
`XNORI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2666
`MULI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2667
`MULUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2668
`MULFI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2669
`DIVI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2670
`DIVUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2671
`AMO:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2672
`LB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2673
`LBU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2674
`Lx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2675
`LxU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2676
`LWR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2677
`LV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2678
`LVx:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2679
`LVxU:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2680
`SB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2681
`Sx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2682
`SWC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2683
`SV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2684
`INC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2685
`CAS:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2686
`CACHE: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2687
`JAL:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2688
`RET:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2689
`CSRRW: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2690
`BITFIELD:      case(isn[47:44])
2691
        `BFINSI:        Source1Valid = TRUE;
2692
        default:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0 || isn[30]==1'b0;
2693
        endcase
2694
`IVECTOR:
2695
        Source1Valid = FALSE;
2696
default:    Source1Valid = TRUE;
2697
endcase
2698
endfunction
2699
 
2700
function Source2Valid;
2701
input [47:0] isn;
2702
casez(isn[`INSTRUCTION_OP])
2703
`BRK:   Source2Valid = TRUE;
2704
`Bcc:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2705
`BBc:   Source2Valid = TRUE;
2706
`BEQI:  Source2Valid = TRUE;
2707
`CHK:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2708
`R2:    casez(isn[`INSTRUCTION_S2])
2709
                                `TLB:                           Source2Valid = TRUE;
2710
        `R1:            Source2Valid = TRUE;
2711
        `MOV:                           Source2Valid = TRUE;
2712
        `SHIFTR:        Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2713
        `SHIFT31:       Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2714
        `SHIFT63:       Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2715
        `LVX,`SVX:      Source2Valid = FALSE;
2716
        default:        Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2717
        endcase
2718
`MEMNDX:
2719
        begin
2720
                if (!isn[31])
2721
                        case({isn[31:28],isn[22:21]})
2722
                        `LVX: Source2Valid = FALSE;
2723
                        `CACHEX,
2724
                        `LVBX,`LVBUX,`LVCX,`LVCUX,`LVHX,`LVHUX,`LVWX,
2725
                        `LBX,`LBUX,`LCX,`LCUX,`LHX,`LHUX,`LWX,`LWRX:    Source2Valid = TRUE;
2726
                        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2727
                        endcase
2728
                else
2729
                        case({isn[31:28],isn[17:16]})
2730
                        `SVX: Source2Valid = FALSE;
2731
                        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2732
                        endcase
2733
        end
2734
`ADDI:  Source2Valid = TRUE;
2735
`SLTI:  Source2Valid = TRUE;
2736
`SLTUI: Source2Valid = TRUE;
2737
`SGTI:  Source2Valid = TRUE;
2738
`SGTUI: Source2Valid = TRUE;
2739
`ANDI:  Source2Valid = TRUE;
2740
`ORI:   Source2Valid = TRUE;
2741
`XORI:  Source2Valid = TRUE;
2742
`XNORI: Source2Valid = TRUE;
2743
`MULUI: Source2Valid = TRUE;
2744
`MULFI: Source2Valid = TRUE;
2745
`LB:    Source2Valid = TRUE;
2746
`LBU:   Source2Valid = TRUE;
2747
`Lx:    Source2Valid = TRUE;
2748
`LxU:   Source2Valid = TRUE;
2749
`LWR:   Source2Valid = TRUE;
2750
`LVx:   Source2Valid = TRUE;
2751
`LVxU:  Source2Valid = TRUE;
2752
`INC:           Source2Valid = TRUE;
2753
`SB:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2754
`Sx:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2755
`SWC:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2756
`CAS:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2757
`JAL:   Source2Valid = TRUE;
2758
`RET:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2759
`IVECTOR:
2760
                    case(isn[`INSTRUCTION_S2])
2761
        `VABS:  Source2Valid = TRUE;
2762
        `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2763
            Source2Valid = FALSE;
2764
        `VADDS,`VSUBS,`VANDS,`VORS,`VXORS:
2765
            Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2766
        `VBITS2V:   Source2Valid = TRUE;
2767
        `V2BITS:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2768
        `VSHL,`VSHR,`VASR:  Source2Valid = isn[22:21]==2'd2;
2769
        default:    Source2Valid = FALSE;
2770
        endcase
2771
`LV:        Source2Valid = TRUE;
2772
`SV:        Source2Valid = FALSE;
2773
`AMO:           Source2Valid = isn[31] || isn[`INSTRUCTION_RB]==5'd0;
2774
`BITFIELD:      Source2Valid = isn[`INSTRUCTION_RB]==5'd0 || isn[31]==1'b0;
2775
default:    Source2Valid = TRUE;
2776
endcase
2777
endfunction
2778
 
2779
function Source3Valid;
2780
input [47:0] isn;
2781
case(isn[`INSTRUCTION_OP])
2782
`IVECTOR:
2783
    case(isn[`INSTRUCTION_S2])
2784
    `VEX:       Source3Valid = TRUE;
2785
    default:    Source3Valid = TRUE;
2786
    endcase
2787
`CHK:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2788
`R2:
2789
        if (isn[`INSTRUCTION_L2]==2'b01)
2790
                case(isn[47:42])
2791
    `CMOVEZ,`CMOVNZ:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2792
                default:        Source3Valid = TRUE;
2793
                endcase
2794
        else
2795
    case(isn[`INSTRUCTION_S2])
2796
    `MAJ:               Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2797
    default:    Source3Valid = TRUE;
2798
    endcase
2799
`MEMNDX:
2800
                if (!isn[31])
2801
                        case({isn[31:28],isn[22:21]})
2802
                        `CACHEX,
2803
                        `LVBX,`LVBUX,`LVCX,`LVCUX,`LVHX,`LVHUX,`LVWX,
2804
                        `LBX,`LBUX,`LCX,`LCUX,`LHX,`LHUX,`LWX,`LWRX:
2805
                                Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2806
            default:    Source3Valid = TRUE;
2807
                        endcase
2808
                else
2809
            case({isn[31:28],isn[17:16]})
2810
            `PUSH:      Source3Valid = TRUE;
2811
            `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2812
            `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2813
            `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2814
            `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2815
            `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2816
            `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2817
            default:    Source3Valid = TRUE;
2818
            endcase
2819
`BITFIELD:      Source3Valid = isn[`INSTRUCTION_RC]==5'd0 || isn[32]==1'b0;
2820
default:    Source3Valid = TRUE;
2821
endcase
2822
endfunction
2823
 
2824
// For predication logic
2825
function SourceTValid;
2826
input [47:0] isn;
2827
case(isn[`INSTRUCTION_OP])
2828
`BRK:   SourceTValid = TRUE;
2829
`Bcc:   SourceTValid = TRUE;
2830
`BBc:   SourceTValid = TRUE;
2831
`BEQI:  SourceTValid = TRUE;
2832
`IVECTOR:
2833
    case(isn[`INSTRUCTION_S2])
2834
    `VEX:       SourceTValid = TRUE;
2835
    default:    SourceTValid = TRUE;
2836
    endcase
2837
`CHK:   SourceTValid = isn[`INSTRUCTION_RT]==5'd0;
2838
`R2:
2839
        if (isn[`INSTRUCTION_L2]==2'b01)
2840
                case(isn[47:42])
2841
    `CMOVEZ,`CMOVNZ:  SourceTValid = isn[`INSTRUCTION_RT]==5'd0;
2842
                default:        SourceTValid = TRUE;
2843
                endcase
2844
        else
2845
    case(isn[`INSTRUCTION_S2])
2846
    `MAJ:               SourceTValid = isn[`INSTRUCTION_RT]==5'd0;
2847
    default:    SourceTValid = TRUE;
2848
    endcase
2849
`MEMNDX:
2850
                if (!isn[31])
2851
                        case({isn[31:28],isn[22:21]})
2852
                        `CACHEX,
2853
                        `LVBX,`LVBUX,`LVCX,`LVCUX,`LVHX,`LVHUX,`LVWX,
2854
                        `LBX,`LBUX,`LCX,`LCUX,`LHX,`LHUX,`LWX,`LWRX:
2855
                                SourceTValid = isn[`INSTRUCTION_RT]==5'd0;
2856
            default:    SourceTValid = TRUE;
2857
                        endcase
2858
                else
2859
            SourceTValid = TRUE;
2860
`SB:    SourceTValid = TRUE;
2861
`Sx:    SourceTValid = TRUE;
2862
`SWC:   SourceTValid = TRUE;
2863
`CAS:   SourceTValid = TRUE;
2864
`BITFIELD:      SourceTValid = isn[`INSTRUCTION_RT]==5'd0 || isn[32]==1'b0;
2865
default:    SourceTValid = isn[`INSTRUCTION_RT]==5'd0;
2866
endcase
2867
endfunction
2868
 
2869
// Used to indicate to the queue logic that the instruction needs to be
2870
// recycled to the queue VL number of times.
2871
function IsVector;
2872
input [47:0] isn;
2873
case(isn[`INSTRUCTION_OP])
2874
`MEMNDX:
2875
  case(isn[`INSTRUCTION_S2])
2876
  `LVX,`SVX:  IsVector = TRUE;
2877
  default:    IsVector = FALSE;
2878
  endcase
2879
`IVECTOR:
2880
        case(isn[`INSTRUCTION_S2])
2881
        `VMxx:
2882
                case(isn[25:23])
2883
        `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2884
              IsVector = FALSE;
2885
    default:    IsVector = TRUE;
2886
    endcase
2887
  `VEINS:     IsVector = FALSE;
2888
  `VEX:       IsVector = FALSE;
2889
  default:    IsVector = TRUE;
2890
  endcase
2891
`LV,`SV:    IsVector = TRUE;
2892
default:    IsVector = FALSE;
2893
endcase
2894
endfunction
2895
 
2896
function IsVeins;
2897
input [47:0] isn;
2898
case(isn[`INSTRUCTION_OP])
2899
`IVECTOR:   IsVeins = isn[`INSTRUCTION_S2]==`VEINS;
2900
default:    IsVeins = FALSE;
2901
endcase
2902
endfunction
2903
 
2904
function IsVex;
2905
input [47:0] isn;
2906
case(isn[`INSTRUCTION_OP])
2907
`IVECTOR:   IsVex = isn[`INSTRUCTION_S2]==`VEX;
2908
default:    IsVex = FALSE;
2909
endcase
2910
endfunction
2911
 
2912
function IsVCmprss;
2913
input [47:0] isn;
2914
case(isn[`INSTRUCTION_OP])
2915
`IVECTOR:   IsVCmprss = isn[`INSTRUCTION_S2]==`VCMPRSS || isn[`INSTRUCTION_S2]==`VCIDX;
2916
default:    IsVCmprss = FALSE;
2917
endcase
2918
endfunction
2919
 
2920
function IsVShifti;
2921
input [47:0] isn;
2922
case(isn[`INSTRUCTION_OP])
2923
`IVECTOR:
2924
                    case(isn[`INSTRUCTION_S2])
2925
            `VSHL,`VSHR,`VASR:
2926
                IsVShifti = {isn[25],isn[22]}==2'd2;
2927
            default:    IsVShifti = FALSE;
2928
            endcase
2929
default:    IsVShifti = FALSE;
2930
endcase
2931
endfunction
2932
 
2933
function IsVLS;
2934
input [47:0] isn;
2935
case(isn[`INSTRUCTION_OP])
2936
`MEMNDX:
2937
                if (IsLoad(isn))
2938
            case({isn[31:28],isn[22:21]})
2939
            `LVX,`LVWS:  IsVLS = TRUE;
2940
            default:    IsVLS = FALSE;
2941
            endcase
2942
    else
2943
            case({isn[31:28],isn[17:16]})
2944
            `SVX,`SVWS:  IsVLS = TRUE;
2945
            default:    IsVLS = FALSE;
2946
            endcase
2947
`LV,`SV:    IsVLS = TRUE;
2948
default:    IsVLS = FALSE;
2949
endcase
2950
endfunction
2951
 
2952
function [1:0] fnM2;
2953
input [31:0] isn;
2954
case(isn[`INSTRUCTION_OP])
2955
`RR:    fnM2 = isn[24:23];
2956
default:    fnM2 = 2'b00;
2957
endcase
2958
endfunction
2959
 
2960
function IsCmp;
2961
input [47:0] isn;
2962
case(isn[`INSTRUCTION_OP])
2963
`R2:
2964
        if (isn[`INSTRUCTION_L2]==2'b00)
2965
    case(isn[31:26])
2966
    `CMP: IsCmp = TRUE;
2967
    default: IsCmp = FALSE;
2968
    endcase
2969
  else
2970
        IsCmp = FALSE;
2971
`CMPI:  IsCmp = TRUE;
2972
default: IsCmp = FALSE;
2973
endcase
2974
endfunction
2975
 
2976
function [0:0] IsMem;
2977
input [47:0] isn;
2978
case(isn[`INSTRUCTION_OP])
2979
`MEMNDX:        IsMem = TRUE;
2980
`AMO:   IsMem = TRUE;
2981
`LB:    IsMem = TRUE;
2982
`LBU:   IsMem = TRUE;
2983
`Lx:    IsMem = TRUE;
2984
`LxU:   IsMem = TRUE;
2985
`LWR:   IsMem = TRUE;
2986
`LV,`SV:    IsMem = TRUE;
2987
`INC:           IsMem = TRUE;
2988
`SB:    IsMem = TRUE;
2989
`Sx:    IsMem = TRUE;
2990
`SWC:   IsMem = TRUE;
2991
`CAS:   IsMem = TRUE;
2992
`LVx:           IsMem = TRUE;
2993
`LVxU:  IsMem = TRUE;
2994
default:    IsMem = FALSE;
2995
endcase
2996
endfunction
2997
 
2998
function IsMemNdx;
2999
input [47:0] isn;
3000
case(isn[`INSTRUCTION_OP])
3001
`MEMNDX:        IsMemNdx = TRUE;
3002
default:    IsMemNdx = FALSE;
3003
endcase
3004
endfunction
3005
 
3006
function IsLoad;
3007
input [47:0] isn;
3008
case(isn[`INSTRUCTION_OP])
3009
`MEMNDX:        IsLoad = !isn[31];
3010
`LB:    IsLoad = TRUE;
3011
`LBU:   IsLoad = TRUE;
3012
`Lx:    IsLoad = TRUE;
3013
`LxU:   IsLoad = TRUE;
3014
`LWR:   IsLoad = TRUE;
3015
`LV:    IsLoad = TRUE;
3016
`LVx:   IsLoad = TRUE;
3017
`LVxU:  IsLoad = TRUE;
3018
default:    IsLoad = FALSE;
3019
endcase
3020
endfunction
3021
 
3022
function IsInc;
3023
input [47:0] isn;
3024
case(isn[`INSTRUCTION_OP])
3025
`MEMNDX:
3026
        if (isn[`INSTRUCTION_L2]==2'b00)
3027
                case({isn[31:28],isn[17:16]})
3028
    `INC:   IsInc = TRUE;
3029
    default:    IsInc = FALSE;
3030
    endcase
3031
        else
3032
                IsInc = FALSE;
3033
`INC:    IsInc = TRUE;
3034
default:    IsInc = FALSE;
3035
endcase
3036
endfunction
3037
 
3038
function IsSWC;
3039
input [47:0] isn;
3040
case(isn[`INSTRUCTION_OP])
3041
`MEMNDX:
3042
        if (isn[`INSTRUCTION_L2]==2'b00)
3043
                case({isn[31:28],isn[17:16]})
3044
    `SWCX:   IsSWC = TRUE;
3045
    default:    IsSWC = FALSE;
3046
    endcase
3047
        else
3048
                IsSWC = FALSE;
3049
`SWC:    IsSWC = TRUE;
3050
default:    IsSWC = FALSE;
3051
endcase
3052
endfunction
3053
 
3054
// Aquire / release bits are only available on indexed SWC / LWR
3055
function IsSWCX;
3056
input [47:0] isn;
3057
case(isn[`INSTRUCTION_OP])
3058
`MEMNDX:
3059
        if (isn[`INSTRUCTION_L2]==2'b00)
3060
                case({isn[31:28],isn[17:16]})
3061
    `SWCX:   IsSWCX = TRUE;
3062
    default:    IsSWCX = FALSE;
3063
    endcase
3064
        else
3065
                IsSWCX = FALSE;
3066
default:    IsSWCX = FALSE;
3067
endcase
3068
endfunction
3069
 
3070
function IsLWR;
3071
input [47:0] isn;
3072
case(isn[`INSTRUCTION_OP])
3073
`MEMNDX:
3074
        if (isn[`INSTRUCTION_L2]==2'b00)
3075
            case({isn[31:28],isn[22:21]})
3076
            `LWRX:   IsLWR = TRUE;
3077
            default:    IsLWR = FALSE;
3078
            endcase
3079
        else
3080
                IsLWR = FALSE;
3081
`LWR:    IsLWR = TRUE;
3082
default:    IsLWR = FALSE;
3083
endcase
3084
endfunction
3085
 
3086
function IsLWRX;
3087
input [47:0] isn;
3088
case(isn[`INSTRUCTION_OP])
3089
`MEMNDX:
3090
        if (isn[`INSTRUCTION_L2]==2'b00)
3091
            case({isn[31:28],isn[22:21]})
3092
            `LWRX:   IsLWRX = TRUE;
3093
            default:    IsLWRX = FALSE;
3094
            endcase
3095
        else
3096
                IsLWRX = FALSE;
3097
default:    IsLWRX = FALSE;
3098
endcase
3099
endfunction
3100
 
3101
function IsCAS;
3102
input [47:0] isn;
3103
case(isn[`INSTRUCTION_OP])
3104
`MEMNDX:
3105
        if (isn[`INSTRUCTION_L2]==2'b00)
3106
                case({isn[31:28],isn[17:16]})
3107
    `CASX:   IsCAS = TRUE;
3108
    default:    IsCAS = FALSE;
3109
    endcase
3110
        else
3111
                IsCAS = FALSE;
3112
`CAS:       IsCAS = TRUE;
3113
default:    IsCAS = FALSE;
3114
endcase
3115
endfunction
3116
 
3117
function IsAMO;
3118
input [47:0] isn;
3119
case(isn[`INSTRUCTION_OP])
3120
`AMO:       IsAMO = TRUE;
3121
default:    IsAMO = FALSE;
3122
endcase
3123
endfunction
3124
 
3125
// Really IsPredictableBranch
3126
// Does not include BccR's
3127
function IsBranch;
3128
input [47:0] isn;
3129
casez(isn[`INSTRUCTION_OP])
3130
`Bcc:   IsBranch = TRUE;
3131
`BBc:   IsBranch = TRUE;
3132
`BEQI:  IsBranch = TRUE;
3133
`CHK:   IsBranch = TRUE;
3134
default:    IsBranch = FALSE;
3135
endcase
3136
endfunction
3137
 
3138
function IsWait;
3139
input [47:0] isn;
3140
IsWait = isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`WAIT;
3141
endfunction
3142
 
3143
function IsCall;
3144
input [47:0] isn;
3145
IsCall = isn[`INSTRUCTION_OP]==`CALL && isn[7]==1'b0;
3146
endfunction
3147
 
3148
function IsJmp;
3149
input [47:0] isn;
3150
IsJmp = isn[`INSTRUCTION_OP]==`JMP && isn[7]==1'b0;
3151
endfunction
3152
 
3153
function IsFlowCtrl;
3154
input [47:0] isn;
3155
casez(isn[`INSTRUCTION_OP])
3156
`BRK:    IsFlowCtrl = TRUE;
3157
`R2:    case(isn[`INSTRUCTION_S2])
3158
        `RTI:   IsFlowCtrl = TRUE;
3159
        default:    IsFlowCtrl = FALSE;
3160
        endcase
3161
`Bcc:   IsFlowCtrl = TRUE;
3162
`BBc:           IsFlowCtrl = TRUE;
3163
`BEQI:  IsFlowCtrl = TRUE;
3164
`CHK:   IsFlowCtrl = TRUE;
3165
`JAL:   IsFlowCtrl = TRUE;
3166
`JMP:           IsFlowCtrl = TRUE;
3167
`CALL:  IsFlowCtrl = TRUE;
3168
`RET:   IsFlowCtrl = TRUE;
3169
default:    IsFlowCtrl = FALSE;
3170
endcase
3171
endfunction
3172
 
3173
function IsCache;
3174
input [47:0] isn;
3175
case(isn[`INSTRUCTION_OP])
3176
`MEMNDX:
3177
        if (isn[`INSTRUCTION_L2]==2'b00)
3178
            case({isn[31:28],isn[22:21]})
3179
            `CACHEX:    IsCache = TRUE;
3180
            default:    IsCache = FALSE;
3181
            endcase
3182
        else
3183
                IsCache = FALSE;
3184
`CACHE: IsCache = TRUE;
3185
default: IsCache = FALSE;
3186
endcase
3187
endfunction
3188
 
3189
function [4:0] CacheCmd;
3190
input [47:0] isn;
3191
case(isn[`INSTRUCTION_OP])
3192
`MEMNDX:
3193
        if (isn[`INSTRUCTION_L2]==2'b00)
3194
            case({isn[31:28],isn[22:21]})
3195
            `CACHEX:    CacheCmd = isn[17:13];
3196
            default:    CacheCmd = 5'd0;
3197
            endcase
3198
        else
3199
                CacheCmd = 5'd0;
3200
`CACHE: CacheCmd = isn[15:11];
3201
default: CacheCmd = 5'd0;
3202
endcase
3203
endfunction
3204
 
3205
function IsMemsb;
3206
input [47:0] isn;
3207
IsMemsb = (isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMSB);
3208
endfunction
3209
 
3210
function IsSEI;
3211
input [47:0] isn;
3212
IsSEI = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`SEI);
3213
endfunction
3214
 
3215
function IsLV;
3216
input [47:0] isn;
3217
case(isn[`INSTRUCTION_OP])
3218
`MEMNDX:
3219
        if (isn[`INSTRUCTION_L2]==2'b00)
3220
            case({isn[31:28],isn[22:21]})
3221
            `LVX:   IsLV = TRUE;
3222
            default:    IsLV = FALSE;
3223
            endcase
3224
        else
3225
                IsLV = FALSE;
3226
`LV:        IsLV = TRUE;
3227
default:    IsLV = FALSE;
3228
endcase
3229
endfunction
3230
 
3231
function IsRFW;
3232
input [47:0] isn;
3233
input [5:0] vqei;
3234
input [5:0] vli;
3235
input thrd;
3236
if (fnRt(isn,vqei,vli,thrd)==12'd0)
3237
    IsRFW = FALSE;
3238
else
3239
casez(isn[`INSTRUCTION_OP])
3240
`IVECTOR:   IsRFW = TRUE;
3241
`FVECTOR:   IsRFW = TRUE;
3242
`R2:
3243
        if (isn[`INSTRUCTION_L2]==2'b00)
3244
            casez(isn[`INSTRUCTION_S2])
3245
            `TLB:               IsRFW = TRUE;
3246
            `R1:
3247
                case(isn[22:18])
3248
                `MEMDB,`MEMSB,`SYNC,`SETWB,5'h14,5'h15: IsRFW = FALSE;
3249
                default:        IsRFW = TRUE;
3250
                endcase
3251
            `ADD:   IsRFW = TRUE;
3252
            `SUB:   IsRFW = TRUE;
3253
            `SLT:   IsRFW = TRUE;
3254
            `SLTU:  IsRFW = TRUE;
3255
            `SLE:   IsRFW = TRUE;
3256
        `SLEU:  IsRFW = TRUE;
3257
            `AND:   IsRFW = TRUE;
3258
            `OR:    IsRFW = TRUE;
3259
            `XOR:   IsRFW = TRUE;
3260
            `NAND:      IsRFW = TRUE;
3261
            `NOR:               IsRFW = TRUE;
3262
            `XNOR:      IsRFW = TRUE;
3263
            `MULU:  IsRFW = TRUE;
3264
            `MULSU: IsRFW = TRUE;
3265
            `MUL:   IsRFW = TRUE;
3266
            `MULUH:  IsRFW = TRUE;
3267
            `MULSUH: IsRFW = TRUE;
3268
            `MULH:   IsRFW = TRUE;
3269
            `MULF:      IsRFW = TRUE;
3270
            `FXMUL:     IsRFW = TRUE;
3271
            `DIVU:  IsRFW = TRUE;
3272
            `DIVSU: IsRFW = TRUE;
3273
            `DIV:IsRFW = TRUE;
3274
            `MODU:  IsRFW = TRUE;
3275
            `MODSU: IsRFW = TRUE;
3276
            `MOD:IsRFW = TRUE;
3277
            `MOV:       IsRFW = TRUE;
3278
            `VMOV:      IsRFW = TRUE;
3279
            `SHIFTR,`SHIFT31,`SHIFT63:
3280
                        IsRFW = TRUE;
3281
            `MIN,`MAX:    IsRFW = TRUE;
3282
            `SEI:       IsRFW = TRUE;
3283
            default:    IsRFW = FALSE;
3284
            endcase
3285
        else if (isn[`INSTRUCTION_L2]==2'b01)
3286
                case(isn[47:42])
3287
                `CMOVEZ:        IsRFW = TRUE;
3288
                `CMOVNZ:        IsRFW = TRUE;
3289
                default:        IsRFW = FALSE;
3290
                endcase
3291
        else if (isn[7]==1'b1)
3292
        // The following instructions might come from a compressed version.
3293
            casez(isn[`INSTRUCTION_S2])
3294
            `ADD:   IsRFW = TRUE;
3295
            `SUB:   IsRFW = TRUE;
3296
            `AND:   IsRFW = TRUE;
3297
            `OR:    IsRFW = TRUE;
3298
            `XOR:   IsRFW = TRUE;
3299
            `MOV:       IsRFW = TRUE;
3300
            `SHIFTR,`SHIFT31,`SHIFT63:
3301
                        IsRFW = TRUE;
3302
            default:    IsRFW = FALSE;
3303
            endcase
3304
        else
3305
                IsRFW = FALSE;
3306
`MEMNDX:
3307
        if (isn[`INSTRUCTION_L2]==2'b10) begin
3308
                if (!isn[31])
3309
                        IsRFW = TRUE;
3310
                else
3311
                        case({isn[31:28],isn[17:16]})
3312
                        `PUSH:  IsRFW = TRUE;
3313
            `CASX:  IsRFW = TRUE;
3314
            default:    IsRFW = FALSE;
3315
            endcase
3316
        end
3317
        else if (isn[`INSTRUCTION_L2]==2'b00) begin
3318
                if (!isn[31])
3319
            case({isn[31:28],isn[22:21]})
3320
            `LBX:   IsRFW = TRUE;
3321
            `LBUX:  IsRFW = TRUE;
3322
            `LCX:   IsRFW = TRUE;
3323
            `LCUX:  IsRFW = TRUE;
3324
            `LHX:   IsRFW = TRUE;
3325
            `LHUX:  IsRFW = TRUE;
3326
            `LWX:   IsRFW = TRUE;
3327
            `LVBX:  IsRFW = TRUE;
3328
            `LVBUX: IsRFW = TRUE;
3329
            `LVCX:  IsRFW = TRUE;
3330
            `LVCUX: IsRFW = TRUE;
3331
            `LVHX:  IsRFW = TRUE;
3332
            `LVHUX: IsRFW = TRUE;
3333
            `LVWX:  IsRFW = TRUE;
3334
            `LWRX:  IsRFW = TRUE;
3335
            `LVX:   IsRFW = TRUE;
3336
            default:    IsRFW = FALSE;
3337
            endcase
3338
    else
3339
                        case({isn[31:28],isn[17:16]})
3340
                        `PUSH:  IsRFW = TRUE;
3341
            `CASX:  IsRFW = TRUE;
3342
            default:    IsRFW = FALSE;
3343
            endcase
3344
        end
3345
        else
3346
                IsRFW = FALSE;
3347
`BBc:   IsRFW = FALSE;
3348
`BITFIELD:  IsRFW = TRUE;
3349
`ADDI:      IsRFW = TRUE;
3350
`SLTI:      IsRFW = TRUE;
3351
`SLTUI:     IsRFW = TRUE;
3352
`SGTI:      IsRFW = TRUE;
3353
`SGTUI:     IsRFW = TRUE;
3354
`ANDI:      IsRFW = TRUE;
3355
`ORI:       IsRFW = TRUE;
3356
`XORI:      IsRFW = TRUE;
3357
`XNORI:                 IsRFW = TRUE;
3358
`MULUI:     IsRFW = TRUE;
3359
`MULI:      IsRFW = TRUE;
3360
`MULFI:                 IsRFW = TRUE;
3361
`DIVUI:     IsRFW = TRUE;
3362
`DIVI:      IsRFW = TRUE;
3363
`MODI:      IsRFW = TRUE;
3364
`JAL:       IsRFW = TRUE;
3365
`CALL:      IsRFW = TRUE;
3366
`RET:       IsRFW = TRUE;
3367
`LB:        IsRFW = TRUE;
3368
`LBU:       IsRFW = TRUE;
3369
`Lx:        IsRFW = TRUE;
3370
`LxU:       IsRFW = TRUE;
3371
`LWR:       IsRFW = TRUE;
3372
`LV:        IsRFW = TRUE;
3373
`LVx:                           IsRFW = TRUE;
3374
`LVxU:                  IsRFW = TRUE;
3375
`CAS:       IsRFW = TRUE;
3376
`AMO:                           IsRFW = TRUE;
3377
`CSRRW:                 IsRFW = TRUE;
3378
`AUIPC:                 IsRFW = TRUE;
3379
`LUI:                           IsRFW = TRUE;
3380
default:    IsRFW = FALSE;
3381
endcase
3382
endfunction
3383
 
3384
function IsShifti;
3385
input [47:0] isn;
3386
case(isn[`INSTRUCTION_OP])
3387
`R2:
3388
        if (isn[`INSTRUCTION_L2]==2'b00)
3389
            case(isn[`INSTRUCTION_S2])
3390
            `SHIFT31,`SHIFT63:
3391
                IsShifti = TRUE;
3392
            default: IsShifti = FALSE;
3393
            endcase
3394
    else
3395
        IsShifti = FALSE;
3396
default: IsShifti = FALSE;
3397
endcase
3398
endfunction
3399
 
3400
function IsShift;
3401
input [47:0] isn;
3402
case(isn[`INSTRUCTION_OP])
3403
`R2:
3404
        if (isn[`INSTRUCTION_L2]==2'b00)
3405
    case(isn[31:26])
3406
    `SHIFTR: IsShift = TRUE;
3407
    `SHIFT31: IsShift = TRUE;
3408
    `SHIFT63: IsShift = TRUE;
3409
    default: IsShift = FALSE;
3410
    endcase
3411
  else
3412
        IsShift = FALSE;
3413
default: IsShift = FALSE;
3414
endcase
3415
endfunction
3416
 
3417
function IsShift48;
3418
input [47:0] isn;
3419
case(isn[`INSTRUCTION_OP])
3420
`R2:
3421
        if (isn[`INSTRUCTION_L2]==2'b01)
3422
    case(isn[47:42])
3423
    `SHIFTR: IsShift48 = TRUE;
3424
    default: IsShift48 = FALSE;
3425
    endcase
3426
  else
3427
        IsShift48 = FALSE;
3428
default: IsShift48 = FALSE;
3429
endcase
3430
endfunction
3431
 
3432
function IsRtop;
3433
input [47:0] isn;
3434
case(isn[`INSTRUCTION_OP])
3435
`R2:
3436
        if (isn[`INSTRUCTION_L2]==2'b01)
3437
            case(isn[47:42])
3438
            `RTOP: IsRtop = TRUE;
3439
            default: IsRtop = FALSE;
3440
            endcase
3441
    else
3442
        IsRtop = FALSE;
3443
default: IsRtop = FALSE;
3444
endcase
3445
endfunction
3446
 
3447
function IsMul;
3448
input [47:0] isn;
3449
case(isn[`INSTRUCTION_OP])
3450
`R2:
3451
        if (isn[`INSTRUCTION_L2]==2'b00)
3452
    case(isn[`INSTRUCTION_S2])
3453
    `MULU,`MULSU,`MUL: IsMul = TRUE;
3454
    `MULUH,`MULSUH,`MULH: IsMul = TRUE;
3455
    default:    IsMul = FALSE;
3456
    endcase
3457
        else
3458
                IsMul = FALSE;
3459
`MULUI,`MULI:  IsMul = TRUE;
3460
default:    IsMul = FALSE;
3461
endcase
3462
endfunction
3463
 
3464
function IsDivmod;
3465
input [47:0] isn;
3466
case(isn[`INSTRUCTION_OP])
3467
`R2:
3468
        if (isn[`INSTRUCTION_L2]==2'b00)
3469
    case(isn[`INSTRUCTION_S2])
3470
    `DIVU,`DIVSU,`DIV: IsDivmod = TRUE;
3471
    `MODU,`MODSU,`MOD: IsDivmod = TRUE;
3472
    default: IsDivmod = FALSE;
3473
    endcase
3474
        else
3475
                IsDivmod = FALSE;
3476
`DIVUI,`DIVI,`MODI:  IsDivmod = TRUE;
3477
default:    IsDivmod = FALSE;
3478
endcase
3479
endfunction
3480
 
3481
function IsExec;
3482
input [47:0] isn;
3483
case(isn[`INSTRUCTION_OP])
3484
`EXEC:  IsExec = TRUE;
3485
default:        IsExec = FALSE;
3486
endcase
3487
endfunction
3488
 
3489
function [7:0] fnSelect;
3490
input [47:0] ins;
3491
input [`ABITS] adr;
3492
begin
3493
        case(ins[`INSTRUCTION_OP])
3494
        `MEMNDX:
3495
                if (ins[`INSTRUCTION_L2]==2'b10) begin
3496
                        if (ins[31]) begin
3497
                                case({ins[31:28],ins[17:16]})
3498
                                `PUSH:  fnSelect = 8'hFF;
3499
                                default: fnSelect = 8'h00;
3500
                                endcase
3501
                        end
3502
                        else
3503
                                fnSelect = 8'h00;
3504
                end
3505
                else if (ins[`INSTRUCTION_L2]==2'b00) begin
3506
                        if (!ins[31])
3507
                                case({ins[31:28],ins[22:21]})
3508
                                `LBX,`LBUX,`LVBX,`LVBUX:
3509
                                   case(adr[2:0])
3510
                                   3'd0:    fnSelect = 8'h01;
3511
                                   3'd1:    fnSelect = 8'h02;
3512
                                   3'd2:    fnSelect = 8'h04;
3513
                                   3'd3:    fnSelect = 8'h08;
3514
                                   3'd4:    fnSelect = 8'h10;
3515
                                   3'd5:    fnSelect = 8'h20;
3516
                                   3'd6:    fnSelect = 8'h40;
3517
                                   3'd7:    fnSelect = 8'h80;
3518
                                   endcase
3519
                                `LCX,`LCUX,`LVCX,`LVCUX:
3520
                                    case(adr[2:1])
3521
                                    2'd0:   fnSelect = 8'h03;
3522
                                    2'd1:   fnSelect = 8'h0C;
3523
                                    2'd2:   fnSelect = 8'h30;
3524
                                    2'd3:   fnSelect = 8'hC0;
3525
                                    endcase
3526
                                `LHX,`LHUX,`LVHX,`LVHUX:
3527
                                   case(adr[2])
3528
                                   1'b0:    fnSelect = 8'h0F;
3529
                                   1'b1:    fnSelect = 8'hF0;
3530
                                   endcase
3531
                                `INC,`LVWX,
3532
                                `LWX,`LWRX,`LVX:
3533
                                   fnSelect = 8'hFF;
3534
                                default:fnSelect = 8'hFF;
3535
                endcase
3536
            else
3537
                                case({ins[31:28],ins[17:16]})
3538
               `SBX:
3539
                   case(adr[2:0])
3540
                   3'd0:    fnSelect = 8'h01;
3541
                   3'd1:    fnSelect = 8'h02;
3542
                   3'd2:    fnSelect = 8'h04;
3543
                   3'd3:    fnSelect = 8'h08;
3544
                   3'd4:    fnSelect = 8'h10;
3545
                   3'd5:    fnSelect = 8'h20;
3546
                   3'd6:    fnSelect = 8'h40;
3547
                   3'd7:    fnSelect = 8'h80;
3548
                   endcase
3549
                `SCX:
3550
                    case(adr[2:1])
3551
                    2'd0:   fnSelect = 8'h03;
3552
                    2'd1:   fnSelect = 8'h0C;
3553
                    2'd2:   fnSelect = 8'h30;
3554
                    2'd3:   fnSelect = 8'hC0;
3555
                    endcase
3556
                `SHX:
3557
                   case(adr[2])
3558
                   1'b0:    fnSelect = 8'h0F;
3559
                   1'b1:    fnSelect = 8'hF0;
3560
                   endcase
3561
               `INC,
3562
               `SWX,`SWCX,`SVX,`CASX,`PUSH:
3563
                   fnSelect = 8'hFF;
3564
               default: fnSelect = 8'h00;
3565
                   endcase
3566
                 end
3567
           else
3568
                fnSelect = 8'h00;
3569
  `LB,`LBU,`SB:
3570
                case(adr[2:0])
3571
                3'd0:   fnSelect = 8'h01;
3572
                3'd1:   fnSelect = 8'h02;
3573
                3'd2:   fnSelect = 8'h04;
3574
                3'd3:   fnSelect = 8'h08;
3575
                3'd4:   fnSelect = 8'h10;
3576
                3'd5:   fnSelect = 8'h20;
3577
                3'd6:   fnSelect = 8'h40;
3578
                3'd7:   fnSelect = 8'h80;
3579
                endcase
3580
  `Lx,`LxU,`LVx,`LVxU:
3581
        casez(ins[20:18])
3582
        3'b100: fnSelect = 8'hFF;
3583
        3'b?10: fnSelect = adr[2] ? 8'hF0 : 8'h0F;
3584
        3'b??1:
3585
      case(adr[2:1])
3586
      2'd0:   fnSelect = 8'h03;
3587
      2'd1:   fnSelect = 8'h0C;
3588
      2'd2:   fnSelect = 8'h30;
3589
      2'd3:   fnSelect = 8'hC0;
3590
      endcase
3591
    default: fnSelect = 8'h00;
3592
    endcase
3593
  `Sx:
3594
        casez(ins[15:13])
3595
        3'b100: fnSelect = 8'hFF;
3596
        3'b?10: fnSelect = adr[2] ? 8'hF0 : 8'h0F;
3597
        3'b??1:
3598
      case(adr[2:1])
3599
      2'd0:   fnSelect = 8'h03;
3600
      2'd1:   fnSelect = 8'h0C;
3601
      2'd2:   fnSelect = 8'h30;
3602
      2'd3:   fnSelect = 8'hC0;
3603
      endcase
3604
    default: fnSelect = 8'h00;
3605
    endcase
3606
        `INC,
3607
        `LWR,`SWC,`CAS:   fnSelect = 8'hFF;
3608
        `LV,`SV:   fnSelect = 8'hFF;
3609
        `AMO:
3610
                case(ins[23:21])
3611
                3'd0:   fnSelect = {8'h01 << adr[2:0]};
3612
                3'd1:   fnSelect = {8'h03 << {adr[2:1],1'b0}};
3613
                3'd2:   fnSelect = {8'h0F << {adr[2],2'b00}};
3614
                3'd3:   fnSelect = 8'hFF;
3615
                default:        fnSelect = 8'hFF;
3616
                endcase
3617
        default:        fnSelect = 8'h00;
3618
        endcase
3619
end
3620
endfunction
3621
/*
3622
function [63:0] fnDatc;
3623
input [47:0] ins;
3624
input [63:0] dat;
3625
case(ins[`INSTRUCTION_OP])
3626
`R2:
3627
        if (isn[`INSTRUCTION_L2]==2'b01)
3628
                case(ins[47:42])
3629
                `FINDB:         fnDatc = dat[7:0];
3630
                `FINDC:         fnDatc = dat[15:0];
3631
                `FINDH:         fnDatc = dat[31:0];
3632
                `FINDW:         fnDatc = dat[63:0];
3633
                default:        fnDatc = dat[63:0];
3634
                endcase
3635
        else
3636
                fnDatc = dat[63:0];
3637
default:        fnDatc = dat[63:0];
3638
endcase
3639
endfunction
3640
*/
3641
/*
3642
function [63:0] fnMemInc;
3643
input [47:0] ins;
3644
case(ins[`INSTRUCTION_OP])
3645
`R2:
3646
        if (isn[`INSTRUCTION_L2]==2'b01)
3647
                case(ins[47:42])
3648
                `FINDB:         fnMemInc = 32'd1;
3649
                `FINDC:         fnMemInc = 32'd2;
3650
                `FINDH:         fnMemInc = 32'd4;
3651
                `FINDW:         fnMemInc = 32'd8;
3652
                default:        fnMemInc = 32'd8;
3653
                endcase
3654
        else
3655
                fnMemInc = 32'd8;
3656
default:        fnMemInc = 32'd8;
3657
endcase
3658
endfunction
3659
*/
3660
function [63:0] fnDatiAlign;
3661
input [47:0] ins;
3662
input [`ABITS] adr;
3663
input [63:0] dat;
3664
case(ins[`INSTRUCTION_OP])
3665
`MEMNDX:
3666
        if (ins[`INSTRUCTION_L2]==2'b00)
3667
            case({ins[31:28],ins[22:21]})
3668
            `LBX,`LVBX:
3669
                case(adr[2:0])
3670
                3'd0:   fnDatiAlign = {{56{dat[7]}},dat[7:0]};
3671
                3'd1:   fnDatiAlign = {{56{dat[15]}},dat[15:8]};
3672
                3'd2:   fnDatiAlign = {{56{dat[23]}},dat[23:16]};
3673
                3'd3:   fnDatiAlign = {{56{dat[31]}},dat[31:24]};
3674
                3'd4:   fnDatiAlign = {{56{dat[39]}},dat[39:32]};
3675
                3'd5:   fnDatiAlign = {{56{dat[47]}},dat[47:40]};
3676
                3'd6:   fnDatiAlign = {{56{dat[55]}},dat[55:48]};
3677
                3'd7:   fnDatiAlign = {{56{dat[63]}},dat[63:56]};
3678
                endcase
3679
            `LBUX,`LVBUX:
3680
                case(adr[2:0])
3681
                3'd0:   fnDatiAlign = {{56{1'b0}},dat[7:0]};
3682
                3'd1:   fnDatiAlign = {{56{1'b0}},dat[15:8]};
3683
                3'd2:   fnDatiAlign = {{56{1'b0}},dat[23:16]};
3684
                3'd3:   fnDatiAlign = {{56{1'b0}},dat[31:24]};
3685
                3'd4:   fnDatiAlign = {{56{1'b0}},dat[39:32]};
3686
                3'd5:   fnDatiAlign = {{56{1'b0}},dat[47:40]};
3687
                3'd6:   fnDatiAlign = {{56{1'b0}},dat[55:48]};
3688
                3'd7:   fnDatiAlign = {{56{2'b0}},dat[63:56]};
3689
                endcase
3690
            `LCX,`LVCX:
3691
                case(adr[2:1])
3692
                2'd0:   fnDatiAlign = {{48{dat[15]}},dat[15:0]};
3693
                2'd1:   fnDatiAlign = {{48{dat[31]}},dat[31:16]};
3694
                2'd2:   fnDatiAlign = {{48{dat[47]}},dat[47:32]};
3695
                2'd3:   fnDatiAlign = {{48{dat[63]}},dat[63:48]};
3696
                endcase
3697
            `LCUX,`LVCUX:
3698
                case(adr[2:1])
3699
                2'd0:   fnDatiAlign = {{48{1'b0}},dat[15:0]};
3700
                2'd1:   fnDatiAlign = {{48{1'b0}},dat[31:16]};
3701
                2'd2:   fnDatiAlign = {{48{1'b0}},dat[47:32]};
3702
                2'd3:   fnDatiAlign = {{48{1'b0}},dat[63:48]};
3703
                endcase
3704
            `LHX,`LVHX:
3705
                case(adr[2])
3706
                1'b0:   fnDatiAlign = {{32{dat[31]}},dat[31:0]};
3707
                1'b1:   fnDatiAlign = {{32{dat[63]}},dat[63:32]};
3708
                endcase
3709
            `LHUX,`LVHUX:
3710
                case(adr[2])
3711
                1'b0:   fnDatiAlign = {{32{1'b0}},dat[31:0]};
3712
                1'b1:   fnDatiAlign = {{32{1'b0}},dat[63:32]};
3713
                endcase
3714
            `LWX,`LWRX,`LVX,`CAS,`LVWX:  fnDatiAlign = dat;
3715
            default:    fnDatiAlign = dat;
3716
            endcase
3717
        else
3718
                fnDatiAlign = dat;
3719
`LB:
3720
  case(adr[2:0])
3721
  3'd0:   fnDatiAlign = {{56{dat[7]}},dat[7:0]};
3722
  3'd1:   fnDatiAlign = {{56{dat[15]}},dat[15:8]};
3723
  3'd2:   fnDatiAlign = {{56{dat[23]}},dat[23:16]};
3724
  3'd3:   fnDatiAlign = {{56{dat[31]}},dat[31:24]};
3725
  3'd4:   fnDatiAlign = {{56{dat[39]}},dat[39:32]};
3726
  3'd5:   fnDatiAlign = {{56{dat[47]}},dat[47:40]};
3727
  3'd6:   fnDatiAlign = {{56{dat[55]}},dat[55:48]};
3728
  3'd7:   fnDatiAlign = {{56{dat[63]}},dat[63:56]};
3729
  endcase
3730
`LBU:
3731
  case(adr[2:0])
3732
  3'd0:   fnDatiAlign = {{56{1'b0}},dat[7:0]};
3733
  3'd1:   fnDatiAlign = {{56{1'b0}},dat[15:8]};
3734
  3'd2:   fnDatiAlign = {{56{1'b0}},dat[23:16]};
3735
  3'd3:   fnDatiAlign = {{56{1'b0}},dat[31:24]};
3736
  3'd4:   fnDatiAlign = {{56{1'b0}},dat[39:32]};
3737
  3'd5:   fnDatiAlign = {{56{1'b0}},dat[47:40]};
3738
  3'd6:   fnDatiAlign = {{56{1'b0}},dat[55:48]};
3739
  3'd7:   fnDatiAlign = {{56{2'b0}},dat[63:56]};
3740
  endcase
3741
`Lx,`LVx:
3742
        casez(ins[20:18])
3743
        3'b100: fnDatiAlign = dat;
3744
        3'b?10:
3745
          case(adr[2])
3746
          1'b0:   fnDatiAlign = {{32{dat[31]}},dat[31:0]};
3747
          1'b1:   fnDatiAlign = {{32{dat[63]}},dat[63:32]};
3748
          endcase
3749
        3'b??1:
3750
          case(adr[2:1])
3751
          2'd0:   fnDatiAlign = {{48{dat[15]}},dat[15:0]};
3752
          2'd1:   fnDatiAlign = {{48{dat[31]}},dat[31:16]};
3753
          2'd2:   fnDatiAlign = {{48{dat[47]}},dat[47:32]};
3754
          2'd3:   fnDatiAlign = {{48{dat[63]}},dat[63:48]};
3755
          endcase
3756
        default:        fnDatiAlign = dat;
3757
        endcase
3758
`LxU,`LVxU:
3759
        casez(ins[20:18])
3760
        3'b100: fnDatiAlign = dat;
3761
        3'b?10:
3762
          case(adr[2])
3763
          1'b0:   fnDatiAlign = {{32{1'b0}},dat[31:0]};
3764
          1'b1:   fnDatiAlign = {{32{1'b0}},dat[63:32]};
3765
          endcase
3766
        3'b??1:
3767
          case(adr[2:1])
3768
          2'd0:   fnDatiAlign = {{48{1'b0}},dat[15:0]};
3769
          2'd1:   fnDatiAlign = {{48{1'b0}},dat[31:16]};
3770
          2'd2:   fnDatiAlign = {{48{1'b0}},dat[47:32]};
3771
          2'd3:   fnDatiAlign = {{48{1'b0}},dat[63:48]};
3772
          endcase
3773
        default:        fnDatiAlign = dat;
3774
        endcase
3775
`LWR,`LV,`CAS,`AMO:   fnDatiAlign = dat;
3776
default:    fnDatiAlign = dat;
3777
endcase
3778
endfunction
3779
 
3780
function [63:0] fnDato;
3781
input [47:0] isn;
3782
input [63:0] dat;
3783
case(isn[`INSTRUCTION_OP])
3784
`MEMNDX:
3785
        if (isn[`INSTRUCTION_L2]==2'b00)
3786
                case({isn[31:28],isn[17:16]})
3787
                `SBX:   fnDato = {8{dat[7:0]}};
3788
                `SCX:   fnDato = {4{dat[15:0]}};
3789
                `SHX:   fnDato = {2{dat[31:0]}};
3790
                default:    fnDato = dat;
3791
                endcase
3792
        else
3793
                fnDato = dat;
3794
`SB:   fnDato = {8{dat[7:0]}};
3795
`Sx:
3796
        casez(isn[15:13])
3797
        3'b100: fnDato = dat;
3798
        3'b?10: fnDato = {2{dat[31:0]}};
3799
        3'b??1: fnDato = {4{dat[15:0]}};
3800
        default:        fnDato = dat;
3801
        endcase
3802
`AMO:
3803
        case(isn[23:21])
3804
        3'd0:   fnDato = {8{dat[7:0]}};
3805
        3'd1:   fnDato = {4{dat[15:0]}};
3806
        3'd2:   fnDato = {2{dat[31:0]}};
3807
        3'd3:   fnDato = dat;
3808
        default:        fnDato = dat;
3809
        endcase
3810
default:    fnDato = dat;
3811
endcase
3812
endfunction
3813
 
3814
function IsTLB;
3815
input [47:0] isn;
3816
case(isn[`INSTRUCTION_OP])
3817
`R2:
3818
  case(isn[`INSTRUCTION_S2])
3819
  `TLB:   IsTLB = TRUE;
3820
  default:    IsTLB = FALSE;
3821
  endcase
3822
default:    IsTLB = FALSE;
3823
endcase
3824
endfunction
3825
 
3826
// Indicate if the ALU instruction is valid immediately (single cycle operation)
3827
function IsSingleCycle;
3828
input [47:0] isn;
3829
IsSingleCycle = !(IsMul(isn)|IsDivmod(isn)|IsTLB(isn)|IsShift48(isn));
3830
endfunction
3831
 
3832
 
3833
generate begin : gDecocderInst
3834
for (g = 0; g < QENTRIES; g = g + 1) begin
3835
`ifdef SUPPORT_SMT
3836
decoder8 iq0(.num({iqentry_tgt[g][8:7],iqentry_tgt[g][5:0]}), .out(iq_out[g]));
3837
`else
3838
decoder7 iq0(.num({iqentry_tgt[g][7],iqentry_tgt[g][5:0]}), .out(iq_out[g]));
3839
`endif
3840
end
3841
end
3842
endgenerate
3843
 
3844
initial begin: Init
3845
        //
3846
        //
3847
        // set up panic messages
3848
        message[ `PANIC_NONE ]                  = "NONE            ";
3849
        message[ `PANIC_FETCHBUFBEQ ]           = "FETCHBUFBEQ     ";
3850
        message[ `PANIC_INVALIDISLOT ]          = "INVALIDISLOT    ";
3851
        message[ `PANIC_IDENTICALDRAMS ]        = "IDENTICALDRAMS  ";
3852
        message[ `PANIC_OVERRUN ]               = "OVERRUN         ";
3853
        message[ `PANIC_HALTINSTRUCTION ]       = "HALTINSTRUCTION ";
3854
        message[ `PANIC_INVALIDMEMOP ]          = "INVALIDMEMOP    ";
3855
        message[ `PANIC_INVALIDFBSTATE ]        = "INVALIDFBSTATE  ";
3856
        message[ `PANIC_INVALIDIQSTATE ]        = "INVALIDIQSTATE  ";
3857
        message[ `PANIC_BRANCHBACK ]            = "BRANCHBACK      ";
3858
        message[ `PANIC_MEMORYRACE ]            = "MEMORYRACE      ";
3859
        message[ `PANIC_ALU0ONLY ] = "ALU0 Only       ";
3860
 
3861
        for (n = 0; n < 64; n = n + 1)
3862
                codebuf[n] <= 48'h0;
3863
 
3864
end
3865
 
3866
// ---------------------------------------------------------------------------
3867
// FETCH
3868
// ---------------------------------------------------------------------------
3869
//
3870
assign fetchbuf0_mem = IsMem(fetchbuf0_instr);// & IsLoad(fetchbuf0_instr);
3871
assign fetchbuf0_rfw   = IsRFW(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd);
3872
`ifdef SUPPORT_PREDICATION
3873
assign fetchbuf0_prfw = IsCmp(fetchbuf0_instr);
3874
`endif
3875
 
3876
generate begin: gFetchbufDec
3877
if (`WAYS > 1) begin
3878
assign fetchbuf1_mem = IsMem(fetchbuf1_instr);// & IsLoad(fetchbuf1_instr);
3879
assign fetchbuf1_rfw   = IsRFW(fetchbuf1_instr,vqe1,vl,fetchbuf1_thrd);
3880
`ifdef SUPPORT_PREDICATION
3881
assign fetchbuf1_prfw = IsCmp(fetchbuf1_instr);
3882
`endif
3883
end
3884
if (`WAYS > 2) begin
3885
assign fetchbuf2_mem = IsMem(fetchbuf2_instr);// & IsLoad(fetchbuf2_instr);
3886
assign fetchbuf2_rfw   = IsRFW(fetchbuf2_instr,vqe2,vl,fetchbuf2_thrd);
3887
`ifdef SUPPORT_PREDICATION
3888
assign fetchbuf2_prfw = IsCmp(fetchbuf2_instr);
3889
`endif
3890
end
3891
end
3892
endgenerate
3893
 
3894
generate begin : gFetchbufInst
3895
if (`WAYS > 2) begin : gb1
3896
FT64_fetchbuf_x3 #(AMSB,RSTPC) ufb1
3897
(
3898
  .rst(rst),
3899
  .clk4x(clk4x),
3900
  .clk(clk),
3901
  .fcu_clk(fcu_clk),
3902
  .cs_i(vadr[31:16]==16'hFFFF),
3903
  .cyc_i(cyc),
3904
  .stb_i(stb_o),
3905
  .ack_o(dc_ack),
3906
  .we_i(we),
3907
  .adr_i(vadr[15:0]),
3908
  .dat_i(dat_o[47:0]),
3909
  .cmpgrp(cr0[10:8]),
3910
  .freezePC(freezePC),
3911
  .regLR(regLR),
3912
  .thread_en(thread_en),
3913
  .insn0(insn0),
3914
  .insn1(insn1),
3915
  .insn1(insn2),
3916
  .phit(phit),
3917
  .threadx(threadx),
3918
  .branchmiss(branchmiss),
3919
  .misspc(misspc),
3920
  .branchmiss_thrd(branchmiss_thrd),
3921
  .predict_takenA(predict_takenA),
3922
  .predict_takenB(predict_takenB),
3923
  .predict_takenC(predict_takenC),
3924
  .predict_takenD(predict_takenD),
3925
  .predict_takenE(predict_takenE),
3926
  .predict_takenF(predict_takenF),
3927
  .predict_taken0(predict_taken0),
3928
  .predict_taken1(predict_taken1),
3929
  .predict_taken2(predict_taken2),
3930
  .queued1(queued1),
3931
  .queued2(queued2),
3932
  .queued2(queued3),
3933
  .queuedNop(queuedNop),
3934
  .pc0(pc0a),
3935
  .pc1(pc1a),
3936
  .fetchbuf(fetchbuf),
3937
  .fetchbufA_v(fetchbufA_v),
3938
  .fetchbufB_v(fetchbufB_v),
3939
  .fetchbufC_v(fetchbufC_v),
3940
  .fetchbufD_v(fetchbufD_v),
3941
  .fetchbufD_v(fetchbufE_v),
3942
  .fetchbufD_v(fetchbufF_v),
3943
  .fetchbufA_pc(fetchbufA_pc),
3944
  .fetchbufB_pc(fetchbufB_pc),
3945
  .fetchbufC_pc(fetchbufC_pc),
3946
  .fetchbufD_pc(fetchbufD_pc),
3947
  .fetchbufD_pc(fetchbufE_pc),
3948
  .fetchbufD_pc(fetchbufF_pc),
3949
  .fetchbufA_instr(fetchbufA_instr),
3950
  .fetchbufB_instr(fetchbufB_instr),
3951
  .fetchbufC_instr(fetchbufC_instr),
3952
  .fetchbufD_instr(fetchbufD_instr),
3953
  .fetchbufE_instr(fetchbufE_instr),
3954
  .fetchbufF_instr(fetchbufF_instr),
3955
  .fetchbuf0_instr(fetchbuf0_instr),
3956
  .fetchbuf1_instr(fetchbuf1_instr),
3957
  .fetchbuf0_thrd(fetchbuf0_thrd),
3958
  .fetchbuf1_thrd(fetchbuf1_thrd),
3959
  .fetchbuf2_thrd(fetchbuf2_thrd),
3960
  .fetchbuf0_pc(fetchbuf0_pc),
3961
  .fetchbuf1_pc(fetchbuf1_pc),
3962
  .fetchbuf2_pc(fetchbuf2_pc),
3963
  .fetchbuf0_v(fetchbuf0_v),
3964
  .fetchbuf1_v(fetchbuf1_v),
3965
  .fetchbuf2_v(fetchbuf2_v),
3966
  .fetchbuf0_insln(fetchbuf0_insln),
3967
  .fetchbuf1_insln(fetchbuf1_insln),
3968
  .fetchbuf2_insln(fetchbuf2_insln),
3969
  .codebuf0(codebuf[insn0[21:16]]),
3970
  .codebuf1(codebuf[insn1[21:16]]),
3971
  .codebuf2(codebuf[insn2[21:16]]),
3972
  .btgtA(btgtA),
3973
  .btgtB(btgtB),
3974
  .btgtC(btgtC),
3975
  .btgtD(btgtD),
3976
  .btgtE(btgtE),
3977
  .btgtF(btgtF),
3978
  .nop_fetchbuf(nop_fetchbuf),
3979
  .take_branch0(take_branch0),
3980
  .take_branch1(take_branch1),
3981
  .take_branch2(take_branch2),
3982
  .stompedRets(stompedOnRets),
3983
  .pred_on(pred_on),
3984
  .panic(fb_panic)
3985
);
3986
end
3987
else if (`WAYS > 1) begin : gb1
3988
FT64_fetchbuf #(AMSB,RSTPC) ufb1
3989
(
3990
  .rst(rst),
3991
  .clk4x(clk4x),
3992
  .clk(clk),
3993
  .fcu_clk(fcu_clk),
3994
  .cs_i(vadr[31:16]==16'hFFFF),
3995
  .cyc_i(cyc),
3996
  .stb_i(stb_o),
3997
  .ack_o(dc_ack),
3998
  .we_i(we),
3999
  .adr_i(vadr[15:0]),
4000
  .dat_i(dat_o[47:0]),
4001
  .cmpgrp(cr0[10:8]),
4002
  .freezePC(freezePC),
4003
  .regLR(regLR),
4004
  .thread_en(thread_en),
4005
  .insn0(insn0),
4006
  .insn1(insn1),
4007
  .phit(phit),
4008
  .threadx(threadx),
4009
  .branchmiss(branchmiss),
4010
  .misspc(misspc),
4011
  .branchmiss_thrd(branchmiss_thrd),
4012
  .predict_takenA(predict_takenA),
4013
  .predict_takenB(predict_takenB),
4014
  .predict_takenC(predict_takenC),
4015
  .predict_takenD(predict_takenD),
4016
  .predict_taken0(predict_taken0),
4017
  .predict_taken1(predict_taken1),
4018
  .queued1(queued1),
4019
  .queued2(queued2),
4020
  .queuedNop(queuedNop),
4021
  .pc0(pc0a),
4022
  .pc1(pc1a),
4023
  .fetchbuf(fetchbuf),
4024
  .fetchbufA_v(fetchbufA_v),
4025
  .fetchbufB_v(fetchbufB_v),
4026
  .fetchbufC_v(fetchbufC_v),
4027
  .fetchbufD_v(fetchbufD_v),
4028
  .fetchbufA_pc(fetchbufA_pc),
4029
  .fetchbufB_pc(fetchbufB_pc),
4030
  .fetchbufC_pc(fetchbufC_pc),
4031
  .fetchbufD_pc(fetchbufD_pc),
4032
  .fetchbufA_instr(fetchbufA_instr),
4033
  .fetchbufB_instr(fetchbufB_instr),
4034
  .fetchbufC_instr(fetchbufC_instr),
4035
  .fetchbufD_instr(fetchbufD_instr),
4036
  .fetchbuf0_instr(fetchbuf0_instr),
4037
  .fetchbuf1_instr(fetchbuf1_instr),
4038
  .fetchbuf0_thrd(fetchbuf0_thrd),
4039
  .fetchbuf1_thrd(fetchbuf1_thrd),
4040
  .fetchbuf0_pc(fetchbuf0_pc),
4041
  .fetchbuf1_pc(fetchbuf1_pc),
4042
  .fetchbuf0_v(fetchbuf0_v),
4043
  .fetchbuf1_v(fetchbuf1_v),
4044
  .fetchbuf0_insln(fetchbuf0_insln),
4045
  .fetchbuf1_insln(fetchbuf1_insln),
4046
  .codebuf0(codebuf[insn0[21:16]]),
4047
  .codebuf1(codebuf[insn1[21:16]]),
4048
  .btgtA(btgtA),
4049
  .btgtB(btgtB),
4050
  .btgtC(btgtC),
4051
  .btgtD(btgtD),
4052
  .nop_fetchbuf(nop_fetchbuf),
4053
  .take_branch0(take_branch0),
4054
  .take_branch1(take_branch1),
4055
  .stompedRets(stompedOnRets),
4056
  .pred_on(pred_on),
4057
  .panic(fb_panic)
4058
);
4059
end
4060
else begin : gb1
4061
FT64_fetchbuf_x1 #(AMSB,RSTPC) ufb1
4062
(
4063
  .rst(rst),
4064
  .clk4x(clk4x),
4065
  .clk(clk),
4066
  .fcu_clk(fcu_clk),
4067
  .cs_i(vadr[31:16]==16'hFFFF),
4068
  .cyc_i(cyc),
4069
  .stb_i(stb_o),
4070
  .ack_o(dc_ack),
4071
  .we_i(we),
4072
  .adr_i(vadr[15:0]),
4073
  .dat_i(dat_o[47:0]),
4074
  .cmpgrp(cr0[10:8]),
4075
  .freezePC(freezePC),
4076
  .regLR(regLR),
4077
  .thread_en(thread_en),
4078
  .insn0(insn0),
4079
  .phit(phit),
4080
  .threadx(threadx),
4081
  .branchmiss(branchmiss),
4082
  .misspc(misspc),
4083
  .branchmiss_thrd(branchmiss_thrd),
4084
  .predict_takenA(predict_takenA),
4085
  .predict_takenB(predict_takenB),
4086
  .predict_taken0(predict_taken0),
4087
  .queued1(queued1),
4088
  .queuedNop(queuedNop),
4089
  .pc0(pc0a),
4090
  .fetchbuf(fetchbuf),
4091
  .fetchbufA_v(fetchbufA_v),
4092
  .fetchbufB_v(fetchbufB_v),
4093
  .fetchbufA_pc(fetchbufA_pc),
4094
  .fetchbufB_pc(fetchbufB_pc),
4095
  .fetchbufA_instr(fetchbufA_instr),
4096
  .fetchbufB_instr(fetchbufB_instr),
4097
  .fetchbuf0_instr(fetchbuf0_instr),
4098
  .fetchbuf0_thrd(fetchbuf0_thrd),
4099
  .fetchbuf0_pc(fetchbuf0_pc),
4100
  .fetchbuf0_v(fetchbuf0_v),
4101
  .fetchbuf0_insln(fetchbuf0_insln),
4102
  .fetchbuf0_pbyte(fetchbuf0_pbyte),
4103
  .codebuf0(codebuf[insn0[21:16]]),
4104
  .btgtA(btgtA),
4105
  .btgtB(btgtB),
4106
  .nop_fetchbuf(nop_fetchbuf),
4107
  .take_branch0(take_branch0),
4108
  .stompedRets(stompedOnRets),
4109
  .pred_on(pred_on),
4110
  .panic(fb_panic)
4111
);
4112
assign fetchbuf1_v = `INV;
4113
end
4114
end
4115
endgenerate
4116
 
4117
wire cmt_head1 = (!iqentry_rfw[heads[1]] && !iqentry_oddball[heads[1]] && ~|iqentry_exc[heads[1]]);
4118
wire cmt_head2 = (!iqentry_rfw[heads[2]] && !iqentry_oddball[heads[2]] && ~|iqentry_exc[heads[2]]);
4119
 
4120
// Determine the head increment amount, this must match code later on.
4121
reg [2:0] hi_amt;
4122
always @*
4123
begin
4124
        hi_amt <= 4'd0;
4125
  casez ({ iqentry_v[heads[0]],
4126
                iqentry_state[heads[0]]==IQS_CMT,
4127
                iqentry_v[heads[1]],
4128
                iqentry_state[heads[1]]==IQS_CMT,
4129
                iqentry_v[heads[2]],
4130
                iqentry_state[heads[2]]==IQS_CMT})
4131
 
4132
        // retire 3
4133
        6'b0?_0?_0?:
4134
                if (heads[0] != tail0 && heads[1] != tail0 && heads[2] != tail0)
4135
                        hi_amt <= 3'd3;
4136
                else if (heads[0] != tail0 && heads[1] != tail0)
4137
                        hi_amt <= 3'd2;
4138
                else if (heads[0] != tail0)
4139
                        hi_amt <= 3'd1;
4140
        6'b0?_0?_10:
4141
                if (heads[0] != tail0 && heads[1] != tail0)
4142
                        hi_amt <= 3'd2;
4143
                else if (heads[0] != tail0)
4144
                        hi_amt <= 3'd1;
4145
                else
4146
                        hi_amt <= 3'd0;
4147
        6'b0?_0?_11:
4148
                if (`NUM_CMT > 2 || cmt_head2)
4149
                        hi_amt <= 3'd3;
4150
                else
4151
                        hi_amt <= 3'd2;
4152
 
4153
        // retire 1 (wait for regfile for heads[1])
4154
        6'b0?_10_??:
4155
                hi_amt <= 3'd1;
4156
 
4157
        // retire 2
4158
        6'b0?_11_0?,
4159
        6'b0?_11_10:
4160
    if (`NUM_CMT > 1 || cmt_head1)
4161
                        hi_amt <= 3'd2;
4162
    else
4163
                        hi_amt <= 3'd1;
4164
  6'b0?_11_11:
4165
    if (`NUM_CMT > 2 || (`NUM_CMT > 1 && cmt_head2))
4166
                        hi_amt <= 3'd3;
4167
        else if (`NUM_CMT > 1 || cmt_head1)
4168
                        hi_amt <= 3'd2;
4169
        else
4170
                        hi_amt <= 3'd1;
4171
  6'b10_??_??:  ;
4172
  6'b11_0?_0?:
4173
        if (heads[1] != tail0 && heads[2] != tail0)
4174
                        hi_amt <= 3'd3;
4175
        else if (heads[1] != tail0)
4176
                        hi_amt <= 3'd2;
4177
        else
4178
                        hi_amt <= 3'd1;
4179
  6'b11_0?_10:
4180
        if (heads[1] != tail0)
4181
                        hi_amt <= 3'd2;
4182
        else
4183
                        hi_amt <= 3'd1;
4184
  6'b11_0?_11:
4185
        if (heads[1] != tail0) begin
4186
                if (`NUM_CMT > 2 || cmt_head2)
4187
                                hi_amt <= 3'd3;
4188
                else
4189
                                hi_amt <= 3'd2;
4190
        end
4191
        else
4192
                        hi_amt <= 3'd1;
4193
  6'b11_10_??:
4194
                        hi_amt <= 3'd1;
4195
  6'b11_11_0?:
4196
        if (`NUM_CMT > 1 && heads[2] != tail0)
4197
                        hi_amt <= 3'd3;
4198
        else if (cmt_head1 && heads[2] != tail0)
4199
                        hi_amt <= 3'd3;
4200
                else if (`NUM_CMT > 1 || cmt_head1)
4201
                        hi_amt <= 3'd2;
4202
        else
4203
                        hi_amt <= 3'd1;
4204
  6'b11_11_10:
4205
                if (`NUM_CMT > 1 || cmt_head1)
4206
                        hi_amt <= 3'd2;
4207
        else
4208
                        hi_amt <= 3'd1;
4209
        6'b11_11_11:
4210
                if (`NUM_CMT > 2 || (`NUM_CMT > 1 && cmt_head2))
4211
                        hi_amt <= 3'd3;
4212
                else if (`NUM_CMT > 1 || cmt_head1)
4213
                        hi_amt <= 3'd2;
4214
                else
4215
                        hi_amt <= 3'd1;
4216
        default:
4217
                begin
4218
                        hi_amt <= 3'd0;
4219
                        $display("hi_amt: Uncoded case %h",{ iqentry_v[heads[0]],
4220
                                iqentry_state[heads[0]],
4221
                                iqentry_v[heads[1]],
4222
                                iqentry_state[heads[1]],
4223
                                iqentry_v[heads[2]],
4224
                                iqentry_state[heads[2]]});
4225
                end
4226
  endcase
4227
end
4228
 
4229
// Amount subtracted from sequence numbers
4230
reg [`SNBITS] tosub;
4231
always @*
4232
case(hi_amt)
4233
3'd3: tosub <= (iqentry_v[heads[2]] ? iqentry_sn[heads[2]]
4234
                                                         : iqentry_v[heads[1]] ? iqentry_sn[heads[1]]
4235
                                                         : iqentry_v[heads[0]] ? iqentry_sn[heads[0]]
4236
                                                         : 4'b0);
4237
3'd2: tosub <= (iqentry_v[heads[1]] ? iqentry_sn[heads[1]]
4238
                                                         : iqentry_v[heads[0]] ? iqentry_sn[heads[0]]
4239
                                                         : 4'b0);
4240
3'd1: tosub <= (iqentry_v[heads[0]] ? iqentry_sn[heads[0]]
4241
                                                         : 4'b0);
4242
default:        tosub <= 4'd0;
4243
endcase
4244
 
4245
//initial begin: stop_at
4246
//#1000000; panic <= `PANIC_OVERRUN;
4247
//end
4248
 
4249
//
4250
// BRANCH-MISS LOGIC: livetarget
4251
//
4252
// livetarget implies that there is a not-to-be-stomped instruction that targets the register in question
4253
// therefore, if it is zero it implies the rf_v value should become VALID on a branchmiss
4254
// 
4255
 
4256
always @*
4257
for (j = 1; j < PREGS; j = j + 1) begin
4258
        livetarget[j] = 1'b0;
4259
        for (n = 0; n < QENTRIES; n = n + 1)
4260
                livetarget[j] = livetarget[j] | iqentry_livetarget[n][j];
4261
end
4262
 
4263
always @*
4264
        for (n = 0; n < QENTRIES; n = n + 1)
4265
`ifdef SUPPORT_PREDICATION
4266
                iqentry_livetarget[n] = {PREGS {iqentry_v[n]}} & {PREGS {~iqentry_stomp[n] && iqentry_thrd[n]==branchmiss_thrd}} & iq_out[n] & ~{PREGS{iqentry_cmp[n]}};
4267
`else
4268
                iqentry_livetarget[n] = {PREGS {iqentry_v[n]}} & {PREGS {~iqentry_stomp[n] && iqentry_thrd[n]==branchmiss_thrd}} & iq_out[n];
4269
`endif
4270
 
4271
`ifdef SUPPORT_PREDICATION
4272
always @*
4273
for (j = 1; j < 16; j = j + 1) begin
4274
        plivetarget[j] = 1'b0;
4275
        for (n = 0; n < QENTRIES; n = n + 1)
4276
                plivetarget[j] = plivetarget[j] | iqentry_plivetarget[n][j];
4277
end
4278
 
4279
always @*
4280
        for (n = 0; n < QENTRIES; n = n + 1)
4281
                iqentry_plivetarget[n] = {16 {iqentry_v[n]}} & {16 {~iqentry_stomp[n] && iqentry_thrd[n]==branchmiss_thrd}} & iq_out[n] & {16{iqentry_cmp[n]}};
4282
`endif
4283
 
4284
//
4285
// BRANCH-MISS LOGIC: latestID
4286
//
4287
// latestID is the instruction queue ID of the newest instruction (latest) that targets
4288
// a particular register.  looks a lot like scheduling logic, but in reverse.
4289
// 
4290
always @*
4291
        for (n = 0; n < QENTRIES; n = n + 1) begin
4292
                iqentry_cumulative[n] = 1'b0;
4293
                for (j = n; j < n + QENTRIES; j = j + 1) begin
4294
                        if (missid==(j % QENTRIES))
4295
                                for (k = n; k <= j; k = k + 1)
4296
                                        iqentry_cumulative[n] = iqentry_cumulative[n] | iqentry_livetarget[k % QENTRIES];
4297
                end
4298
        end
4299
 
4300
always @*
4301
        for (n = 0; n < QENTRIES; n = n + 1)
4302
    iqentry_latestID[n] = (missid == n || ((iqentry_livetarget[n] & iqentry_cumulative[(n+1)%QENTRIES]) == {PREGS{1'b0}}))
4303
                                    ? iqentry_livetarget[n]
4304
                                    : {PREGS{1'b0}};
4305
 
4306
always @*
4307
        for (n = 0; n < QENTRIES; n = n + 1)
4308
          iqentry_source[n] = | iqentry_latestID[n];
4309
 
4310
`ifdef SUPPORT_PREDICATION
4311
always @*
4312
        for (n = 0; n < QENTRIES; n = n + 1) begin
4313
                iqentry_pcumulative[n] = 1'b0;
4314
                for (j = n; j < n + QENTRIES; j = j + 1) begin
4315
                        if (missid==(j % QENTRIES))
4316
                                for (k = n; k <= j; k = k + 1)
4317
                                        iqentry_pcumulative[n] = iqentry_pcumulative[n] | iqentry_plivetarget[k % QENTRIES];
4318
                end
4319
        end
4320
 
4321
always @*
4322
        for (n = 0; n < QENTRIES; n = n + 1)
4323
    iqentry_platestID[n] = (missid == n || ((iqentry_plivetarget[n] & iqentry_pcumulative[(n+1)%QENTRIES]) == {16{1'b0}}))
4324
                                    ? iqentry_plivetarget[n]
4325
                                    : {16{1'b0}};
4326
 
4327
always @*
4328
        for (n = 0; n < QENTRIES; n = n + 1)
4329
          iqentry_psource[n] = | iqentry_platestID[n];
4330
 
4331
`endif
4332
 
4333
reg vqueued2;
4334
assign Ra0 = fnRa(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
4335
assign Rb0 = fnRb(fetchbuf0_instr,1'b0,vqe0,rfoa0[5:0],rfoa1[5:0],fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
4336
assign Rc0 = fnRc(fetchbuf0_instr,vqe0,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
4337
assign Rt0 = fnRt(fetchbuf0_instr,vqet0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
4338
assign Ra1 = fnRa(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
4339
assign Rb1 = fnRb(fetchbuf1_instr,1'b1,vqueued2 ? vqe0 + 1 : vqe1,rfoa0[5:0],rfoa1[5:0],fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
4340
assign Rc1 = fnRc(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
4341
assign Rt1 = fnRt(fetchbuf1_instr,vqueued2 ? vqet0 + 1 : vqet1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
4342
 
4343
//
4344
// additional logic for ISSUE
4345
//
4346
// for the moment, we look at ALU-input buffers to allow back-to-back issue of 
4347
// dependent instructions ... we do not, however, look ahead for DRAM requests 
4348
// that will become valid in the next cycle.  instead, these have to propagate
4349
// their results into the IQ entry directly, at which point it becomes issue-able
4350
//
4351
 
4352
// note that, for all intents & purposes, iqentry_done == iqentry_agen ... no need to duplicate
4353
 
4354
wire [QENTRIES-1:0] args_valid;
4355
wire [QENTRIES-1:0] could_issue;
4356
wire [QENTRIES-1:0] could_issueid;
4357
 
4358
// Note that bypassing is provided only from the first fpu.
4359
generate begin : issue_logic
4360
for (g = 0; g < QENTRIES; g = g + 1)
4361
begin
4362
assign args_valid[g] =
4363
                  (iqentry_a1_v[g]
4364
`ifdef FU_BYPASS
4365
        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready && (~alu0_mem | alu0_push))
4366
        || ((iqentry_a1_s[g] == alu1_sourceid && alu1_dataready && (~alu1_mem | alu1_push)) && (`NUM_ALU > 1))
4367
        || ((iqentry_a1_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
4368
`endif
4369
        )
4370
    && (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
4371
`ifdef FU_BYPASS
4372
        || (iqentry_a2_s[g] == alu0_sourceid && alu0_dataready && (~alu0_mem | alu0_push))
4373
        || ((iqentry_a2_s[g] == alu1_sourceid && alu1_dataready && (~alu1_mem | alu1_push)) && (`NUM_ALU > 1))
4374
        || ((iqentry_a2_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
4375
`endif
4376
        )
4377
    && (iqentry_a3_v[g]
4378
        || (iqentry_mem[g] & ~iqentry_agen[g] & ~iqentry_memndx[g])    // a3 needs to be valid for indexed instruction
4379
//        || (iqentry_mem[g] & ~iqentry_agen[g])
4380
`ifdef FU_BYPASS
4381
        || (iqentry_a3_s[g] == alu0_sourceid && alu0_dataready && (~alu0_mem | alu0_push))
4382
        || ((iqentry_a3_s[g] == alu1_sourceid && alu1_dataready && (~alu1_mem | alu1_push)) && (`NUM_ALU > 1))
4383
`endif
4384
        )
4385
    ;
4386
 
4387
assign could_issue[g] = iqentry_v[g] && iqentry_state[g]==IQS_QUEUED
4388
                                                                                                && args_valid[g]
4389
                                                                                                && iqentry_iv[g];
4390
                        //&& (iqentry_mem[g] ? !iqentry_agen[g] : 1'b1);
4391
 
4392
assign could_issueid[g] = (iqentry_v[g])// || (g==tail0 && canq1))// || (g==tail1 && canq2))
4393
                                                                                                                && !iqentry_iv[g];
4394
//                && (iqentry_a1_v[g] 
4395
//        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
4396
//        || (iqentry_a1_s[g] == alu1_sourceid && alu1_dataready));
4397
 
4398
end
4399
end
4400
endgenerate
4401
 
4402
// The (old) simulator didn't handle the asynchronous race loop properly in the 
4403
// original code. It would issue two instructions to the same islot. So the
4404
// issue logic has been re-written to eliminate the asynchronous loop.
4405
// Can't issue to the ALU if it's busy doing a long running operation like a 
4406
// divide.
4407
// ToDo: fix the memory synchronization, see fp_issue below
4408
`ifndef INLINE_DECODE
4409
always @*
4410
begin
4411
        iqentry_id1issue = {QENTRIES{1'b0}};
4412
        if (id1_available) begin
4413
                for (n = 0; n < QENTRIES; n = n + 1)
4414
                        if (could_issueid[heads[n]] && iqentry_id1issue=={QENTRIES{1'b0}})
4415
                          iqentry_id1issue[heads[n]] = `TRUE;
4416
        end
4417
end
4418
generate begin : gIDUIssue
4419
        if (`NUM_IDU > 1) begin
4420
                always @*
4421
                begin
4422
                        iqentry_id2issue = {QENTRIES{1'b0}};
4423
                        if (id2_available) begin
4424
                                for (n = 0; n < QENTRIES; n = n + 1)
4425
                                        if (could_issueid[heads[n]] && !iqentry_id1issue[heads[n]] && iqentry_id2issue=={QENTRIES{1'b0}})
4426
                                          iqentry_id2issue[heads[n]] = `TRUE;
4427
                        end
4428
                end
4429
        end
4430
        if (`NUM_IDU > 2) begin
4431
                always @*
4432
                begin
4433
                        iqentry_id3issue = {QENTRIES{1'b0}};
4434
                        if (id3_available) begin
4435
                                for (n = 0; n < QENTRIES; n = n + 1)
4436
                                        if (could_issueid[heads[n]]
4437
                                        && !iqentry_id1issue[heads[n]]
4438
                                        && !iqentry_id2issue[heads[n]]
4439
                                        && iqentry_id3issue=={QENTRIES{1'b0}})
4440
                                          iqentry_id3issue[heads[n]] = `TRUE;
4441
                        end
4442
                end
4443
        end
4444
end
4445
endgenerate
4446
`endif  // not INLINE_DECODE
4447
 
4448
// Detect if there are any valid queue entries prior to the given queue entry.
4449
reg [QENTRIES-1:0] prior_valid;
4450
//generate begin : gPriorValid
4451
always @*
4452
for (j = 0; j < QENTRIES; j = j + 1)
4453
begin
4454
        prior_valid[heads[j]] = 1'b0;
4455
        if (j > 0)
4456
                for (n = j-1; n >= 0; n = n - 1)
4457
                        prior_valid[heads[j]] = prior_valid[heads[j]]|iqentry_v[heads[n]];
4458
end
4459
//end
4460
//endgenerate
4461
 
4462
// Detect if there are any valid sync instructions prior to the given queue 
4463
// entry.
4464
reg [QENTRIES-1:0] prior_sync;
4465
//generate begin : gPriorSync
4466
always @*
4467
for (j = 0; j < QENTRIES; j = j + 1)
4468
begin
4469
        prior_sync[heads[j]] = 1'b0;
4470
        if (j > 0)
4471
                for (n = j-1; n >= 0; n = n - 1)
4472
                        prior_sync[heads[j]] = prior_sync[heads[j]]|(iqentry_v[heads[n]] & iqentry_sync[heads[n]]);
4473
end
4474
//end
4475
//endgenerate
4476
 
4477
// Detect if there are any valid fsync instructions prior to the given queue 
4478
// entry.
4479
reg [QENTRIES-1:0] prior_fsync;
4480
//generate begin : gPriorFsync
4481
always @*
4482
for (j = 0; j < QENTRIES; j = j + 1)
4483
begin
4484
        prior_fsync[heads[j]] = 1'b0;
4485
        if (j > 0)
4486
                for (n = j-1; n >= 0; n = n - 1)
4487
                        prior_fsync[heads[j]] = prior_fsync[heads[j]]|(iqentry_v[heads[n]] & iqentry_fsync[heads[n]]);
4488
end
4489
//end
4490
//endgenerate
4491
 
4492
// Start search for instructions to process at head of queue (oldest instruction).
4493
always @*
4494
begin
4495
        iqentry_alu0_issue = {QENTRIES{1'b0}};
4496
        iqentry_alu1_issue = {QENTRIES{1'b0}};
4497
 
4498
        if (alu0_available & alu0_idle) begin
4499
                for (n = 0; n < QENTRIES; n = n + 1) begin
4500
                        if (could_issue[heads[n]] && iqentry_alu[heads[n]]
4501
                        && iqentry_alu0_issue == {QENTRIES{1'b0}}
4502
                        // If there are no valid queue entries prior it doesn't matter if there is
4503
                        // a sync.
4504
                        && (!prior_sync[heads[n]] || !prior_valid[heads[n]])
4505
                        )
4506
                          iqentry_alu0_issue[heads[n]] = `TRUE;
4507
                end
4508
        end
4509
 
4510
        if (alu1_available && alu1_idle && `NUM_ALU > 1) begin
4511
//              if ((could_issue & ~iqentry_alu0_issue & ~iqentry_alu0) != {QENTRIES{1'b0}}) begin
4512
                        for (n = 0; n < QENTRIES; n = n + 1) begin
4513
                                if (could_issue[heads[n]] && iqentry_alu[heads[n]]
4514
                                        && !iqentry_alu0[heads[n]]      // alu0 only
4515
                                        && !iqentry_alu0_issue[heads[n]]
4516
                                        && iqentry_alu1_issue == {QENTRIES{1'b0}}
4517
                                        && (!prior_sync[heads[n]] || !prior_valid[heads[n]])
4518
                                )
4519
                                  iqentry_alu1_issue[heads[n]] = `TRUE;
4520
                        end
4521
//              end
4522
        end
4523
end
4524
 
4525
 
4526
// Start search for instructions to process at head of queue (oldest instruction).
4527
always @*
4528
begin
4529
        iqentry_fpu1_issue = {QENTRIES{1'b0}};
4530
        iqentry_fpu2_issue = {QENTRIES{1'b0}};
4531
 
4532
        if (fpu1_available && fpu1_idle && `NUM_FPU > 0) begin
4533
                for (n = 0; n < QENTRIES; n = n + 1) begin
4534
                        if (could_issue[heads[n]] && iqentry_fpu[heads[n]]
4535
                        && iqentry_fpu1_issue == {QENTRIES{1'b0}}
4536
                        // If there are no valid queue entries prior it doesn't matter if there is
4537
                        // a sync.
4538
                        && (!(prior_sync[heads[n]]|prior_fsync[heads[n]]) || !prior_valid[heads[n]])
4539
                        )
4540
                          iqentry_fpu1_issue[heads[n]] = `TRUE;
4541
                end
4542
        end
4543
 
4544
        if (fpu2_available && fpu2_idle && `NUM_FPU > 1) begin
4545
                for (n = 0; n < QENTRIES; n = n + 1) begin
4546
                        if (could_issue[heads[n]] && iqentry_fpu[heads[n]]
4547
                        && !iqentry_fpu1_issue[heads[n]]
4548
                        && iqentry_fpu2_issue == {QENTRIES{1'b0}}
4549
                        && (!(prior_sync[heads[n]]|prior_fsync[heads[n]]) || !prior_valid[heads[n]])
4550
                        )
4551
                          iqentry_fpu2_issue[heads[n]] = `TRUE;
4552
                end
4553
        end
4554
end
4555
 
4556
reg [QENTRIES-1:0] nextqd;
4557
// Next queue id
4558
 
4559
/*
4560
reg [`QBITS] nids [0:QENTRIES-1];
4561
always @*
4562
for (n = 0; n < QENTRIES; n = n + 1)
4563
begin
4564
        nids[n] = n[`QBITS];
4565
        for (j = n; j != (n+1) % QENTRIES; j = (j - 1) % QENTRIES)
4566
                if (iqentry_thrd[(j+1)%QENTRIES]==iqentry_thrd[n])
4567
                        nids[n] = (j + 1) % QENTRIES;
4568
        // Add one more compare and set
4569
end
4570
*/
4571
 
4572
reg [`QBITS] nids [0:QENTRIES-1];
4573
always @*
4574
for (j = 0; j < QENTRIES; j = j + 1) begin
4575
        // We can't both start and stop at j
4576
        for (n = j; n != (j+1)%QENTRIES; n = (n + (QENTRIES-1)) % QENTRIES)
4577
                if (iqentry_thrd[n]==iqentry_thrd[j])
4578
                        nids[j] = n;
4579
        // Do the last one
4580
        if (iqentry_thrd[(j+1)%QENTRIES]==iqentry_thrd[j])
4581
                nids[j] = (j+1)%QENTRIES;
4582
end
4583
/*
4584
assign nids[0] = nid0;
4585
assign nids[1] = nid1;
4586
assign nids[2] = nid2;
4587
assign nids[3] = nid3;
4588
assign nids[4] = nid4;
4589
assign nids[5] = nid5;
4590
assign nids[6] = nid6;
4591
assign nids[7] = nid7;
4592
assign nids[8] = nid8;
4593
assign nids[9] = nid9;
4594
*/
4595
// Search the queue for the next entry on the same thread.
4596
reg [`QBITS] nid;
4597
always @*
4598
begin
4599
        nid = fcu_id;
4600
        for (n = QENTRIES-1; n > 0; n = n - 1)
4601
                if (iqentry_thrd[(fcu_id + n) % QENTRIES]==fcu_thrd)
4602
                        nid = (fcu_id + n) % QENTRIES;
4603
end
4604
/*
4605
always @*
4606
if (iqentry_thrd[idp1(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4607
        nid = idp1(fcu_id);
4608
else if (iqentry_thrd[idp2(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4609
        nid = idp2(fcu_id);
4610
else if (iqentry_thrd[idp3(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4611
        nid = idp3(fcu_id);
4612
else if (iqentry_thrd[idp4(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4613
        nid = idp4(fcu_id);
4614
else if (iqentry_thrd[idp5(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4615
        nid = idp5(fcu_id);
4616
else if (iqentry_thrd[idp6(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4617
        nid = idp6(fcu_id);
4618
else if (iqentry_thrd[idp7(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4619
        nid = idp7(fcu_id);
4620
else if (iqentry_thrd[idp8(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4621
        nid = idp8(fcu_id);
4622
else if (iqentry_thrd[idp9(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4623
        nid = idp9(fcu_id);
4624
else
4625
        nid = fcu_id;
4626
*/
4627
always @*
4628
for (n = 0; n < QENTRIES; n = n + 1)
4629
        nextqd[n] <= iqentry_sn[nids[n]] > iqentry_sn[n] || iqentry_v[n];
4630
 
4631
//assign nextqd = 8'hFF;
4632
 
4633
// Don't issue to the fcu until the following instruction is enqueued.
4634
// However, if the queue is full then issue anyway. A branch miss will likely occur.
4635
// Start search for instructions at head of queue (oldest instruction).
4636
always @*
4637
begin
4638
        iqentry_fcu_issue = {QENTRIES{1'b0}};
4639
 
4640
        if (fcu_done & ~branchmiss) begin
4641
                for (n = 0; n < QENTRIES; n = n + 1) begin
4642
                        if (could_issue[heads[n]] && iqentry_fc[heads[n]] && (nextqd[heads[n]] || iqentry_br[heads[n]])
4643
                        && iqentry_fcu_issue == {QENTRIES{1'b0}}
4644
                        && (!prior_sync[heads[n]] || !prior_valid[heads[n]])
4645
                        )
4646
                          iqentry_fcu_issue[heads[n]] = `TRUE;
4647
                end
4648
        end
4649
end
4650
 
4651
 
4652
// Test if a given address is in the write buffer. This is done only for the
4653
// first two queue slots to save logic on comparators.
4654
reg inwb0;
4655
always @*
4656
begin
4657
        inwb0 = FALSE;
4658
`ifdef HAS_WB
4659
        for (n = 0; n < `WB_DEPTH; n = n + 1)
4660
                if (iqentry_ma[heads[0]][AMSB:3]==wb_addr[n][AMSB:3] && wb_v[n])
4661
                        inwb0 = TRUE;
4662
`endif
4663
end
4664
 
4665
reg inwb1;
4666
always @*
4667
begin
4668
        inwb1 = FALSE;
4669
`ifdef HAS_WB
4670
        for (n = 0; n < `WB_DEPTH; n = n + 1)
4671
                if (iqentry_ma[heads[1]][AMSB:3]==wb_addr[n][AMSB:3] && wb_v[n])
4672
                        inwb1 = TRUE;
4673
`endif
4674
end
4675
 
4676
always @*
4677
begin
4678
        for (n = 0; n < QENTRIES; n = n + 1) begin
4679
                iqentry_v[n] <= iqentry_state[n] != IQS_INVALID;
4680
                iqentry_done[n] <= iqentry_state[n]==IQS_DONE || iqentry_state[n]==IQS_CMT;
4681
                iqentry_out[n] <= iqentry_state[n]==IQS_OUT;
4682
                iqentry_agen[n] <= iqentry_state[n]==IQS_AGEN;
4683
        end
4684
end
4685
 
4686
//
4687
// determine if the instructions ready to issue can, in fact, issue.
4688
// "ready" means that the instruction has valid operands but has not gone yet
4689
reg [1:0] issue_count, missue_count;
4690
generate begin : gMemIssue
4691
always @*
4692
begin
4693
        issue_count = 0;
4694
         memissue[ heads[0] ] =  iqentry_memready[ heads[0] ] && !(iqentry_load[heads[0]] && inwb0);               // first in line ... go as soon as ready
4695
         if (memissue[heads[0]])
4696
                issue_count = issue_count + 1;
4697
 
4698
         memissue[ heads[1] ] = ~iqentry_stomp[heads[1]] && iqentry_memready[ heads[1] ]                // addr and data are valid
4699
                                        && issue_count < `NUM_MEM
4700
                                        // ... and no preceding instruction is ready to go
4701
                                        //&& ~iqentry_memready[heads[0]]
4702
                                        // ... and there is no address-overlap with any preceding instruction
4703
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]]) || iqentry_done[heads[0]]
4704
                                                || ((iqentry_ma[heads[1]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
4705
                                        // ... if a release, any prior memory ops must be done before this one
4706
                                        && (iqentry_rl[heads[1]] ? iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]] : 1'b1)
4707
                                        // ... if a preivous op has the aquire bit set
4708
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
4709
                                        // ... and there's nothing in the write buffer during a load
4710
                                        && !(iqentry_load[heads[1]] && (inwb1 || iqentry_store[heads[0]]))
4711
                                        // ... and, if it is a store, there is no chance of it being undone
4712
                                        && ((iqentry_load[heads[1]] && sple) ||
4713
                                           !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]]));
4714
         if (memissue[heads[1]])
4715
                issue_count = issue_count + 1;
4716
 
4717
         memissue[ heads[2] ] = ~iqentry_stomp[heads[2]] && iqentry_memready[ heads[2] ]                // addr and data are valid
4718
                                        // ... and no preceding instruction is ready to go
4719
                                        && issue_count < `NUM_MEM
4720
                                        //&& ~iqentry_memready[heads[0]]
4721
                                        //&& ~iqentry_memready[heads[1]] 
4722
                                        // ... and there is no address-overlap with any preceding instruction
4723
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]])  || iqentry_done[heads[0]]
4724
                                                || ((iqentry_ma[heads[2]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
4725
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]])  || iqentry_done[heads[1]]
4726
                                                || ((iqentry_ma[heads[2]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3] || iqentry_out[heads[1]] || iqentry_done[heads[1]])))
4727
                                        // ... if a release, any prior memory ops must be done before this one
4728
                                        && (iqentry_rl[heads[2]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
4729
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
4730
                                                                                         : 1'b1)
4731
                                        // ... if a preivous op has the aquire bit set
4732
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
4733
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
4734
                                        // ... and there's nothing in the write buffer during a load
4735
                                        && !(iqentry_load[heads[2]] && (wb_v!=1'b0
4736
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]]))
4737
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4738
            && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4739
                                && (!(iqentry_iv[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4740
                                        // ... and, if it is a SW, there is no chance of it being undone
4741
                                        && ((iqentry_load[heads[2]] && sple) ||
4742
                                              !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
4743
                                           && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]]));
4744
         if (memissue[heads[2]])
4745
                issue_count = issue_count + 1;
4746
 
4747
         memissue[ heads[3] ] = ~iqentry_stomp[heads[3]] && iqentry_memready[ heads[3] ]                // addr and data are valid
4748
                                        // ... and no preceding instruction is ready to go
4749
                                        && issue_count < `NUM_MEM
4750
                                        //&& ~iqentry_memready[heads[0]]
4751
                                        //&& ~iqentry_memready[heads[1]] 
4752
                                        //&& ~iqentry_memready[heads[2]] 
4753
                                        // ... and there is no address-overlap with any preceding instruction
4754
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]])  || iqentry_done[heads[0]]
4755
                                                || ((iqentry_ma[heads[3]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
4756
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]])  || iqentry_done[heads[1]]
4757
                                                || ((iqentry_ma[heads[3]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3] || iqentry_out[heads[1]] || iqentry_done[heads[1]])))
4758
                                        && (!iqentry_mem[heads[2]] || (iqentry_agen[heads[2]] & iqentry_out[heads[2]])  || iqentry_done[heads[2]]
4759
                                                || ((iqentry_ma[heads[3]][AMSB:3] != iqentry_ma[heads[2]][AMSB:3] || iqentry_out[heads[2]] || iqentry_done[heads[2]])))
4760
                                        // ... if a release, any prior memory ops must be done before this one
4761
                                        && (iqentry_rl[heads[3]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
4762
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
4763
                                                                                 && (iqentry_done[heads[2]] || !iqentry_v[heads[2]] || !iqentry_mem[heads[2]])
4764
                                                                                         : 1'b1)
4765
                                        // ... if a preivous op has the aquire bit set
4766
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
4767
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
4768
                                        && !(iqentry_aq[heads[2]] && iqentry_v[heads[2]])
4769
                                        // ... and there's nothing in the write buffer during a load
4770
                                        && !(iqentry_load[heads[3]] && (wb_v!=1'b0
4771
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]] || iqentry_store[heads[2]]))
4772
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4773
                    && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4774
                    && (!(iqentry_iv[heads[2]] && iqentry_memsb[heads[2]]) ||
4775
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4776
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4777
                                )
4778
                                && (!(iqentry_iv[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4779
                    && (!(iqentry_iv[heads[2]] && iqentry_memdb[heads[2]]) ||
4780
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4781
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4782
                                )
4783
                    // ... and, if it is a SW, there is no chance of it being undone
4784
                                        && ((iqentry_load[heads[3]] && sple) ||
4785
                                      !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
4786
                       && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]])
4787
                       && !(iqentry_fc[heads[2]]||iqentry_canex[heads[2]]));
4788
         if (memissue[heads[3]])
4789
                issue_count = issue_count + 1;
4790
 
4791
        if (QENTRIES > 4) begin
4792
         memissue[ heads[4] ] = ~iqentry_stomp[heads[4]] && iqentry_memready[ heads[4] ]                // addr and data are valid
4793
                                        // ... and no preceding instruction is ready to go
4794
                                        && issue_count < `NUM_MEM
4795
                                        //&& ~iqentry_memready[heads[0]]
4796
                                        //&& ~iqentry_memready[heads[1]] 
4797
                                        //&& ~iqentry_memready[heads[2]] 
4798
                                        //&& ~iqentry_memready[heads[3]] 
4799
                                        // ... and there is no address-overlap with any preceding instruction
4800
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]])  || iqentry_done[heads[0]]
4801
                                                || ((iqentry_ma[heads[4]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
4802
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]])  || iqentry_done[heads[1]]
4803
                                                || ((iqentry_ma[heads[4]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3] || iqentry_out[heads[1]] || iqentry_done[heads[1]])))
4804
                                        && (!iqentry_mem[heads[2]] || (iqentry_agen[heads[2]] & iqentry_out[heads[2]])  || iqentry_done[heads[2]]
4805
                                                || ((iqentry_ma[heads[4]][AMSB:3] != iqentry_ma[heads[2]][AMSB:3] || iqentry_out[heads[2]] || iqentry_done[heads[2]])))
4806
                                        && (!iqentry_mem[heads[3]] || (iqentry_agen[heads[3]] & iqentry_out[heads[3]])  || iqentry_done[heads[3]]
4807
                                                || ((iqentry_ma[heads[4]][AMSB:3] != iqentry_ma[heads[3]][AMSB:3] || iqentry_out[heads[3]] || iqentry_done[heads[3]])))
4808
                                        // ... if a release, any prior memory ops must be done before this one
4809
                                        && (iqentry_rl[heads[4]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
4810
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
4811
                                                                                 && (iqentry_done[heads[2]] || !iqentry_v[heads[2]] || !iqentry_mem[heads[2]])
4812
                                                                                 && (iqentry_done[heads[3]] || !iqentry_v[heads[3]] || !iqentry_mem[heads[3]])
4813
                                                                                         : 1'b1)
4814
                                        // ... if a preivous op has the aquire bit set
4815
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
4816
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
4817
                                        && !(iqentry_aq[heads[2]] && iqentry_v[heads[2]])
4818
                                        && !(iqentry_aq[heads[3]] && iqentry_v[heads[3]])
4819
                                        // ... and there's nothing in the write buffer during a load
4820
                                        && !(iqentry_load[heads[4]] && (wb_v!=1'b0
4821
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]] || iqentry_store[heads[2]] || iqentry_store[heads[3]]))
4822
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4823
                    && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4824
                    && (!(iqentry_iv[heads[2]] && iqentry_memsb[heads[2]]) ||
4825
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4826
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4827
                                )
4828
                    && (!(iqentry_iv[heads[3]] && iqentry_memsb[heads[3]]) ||
4829
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4830
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4831
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
4832
                                )
4833
                                && (!(iqentry_v[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4834
                    && (!(iqentry_iv[heads[2]] && iqentry_memdb[heads[2]]) ||
4835
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4836
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4837
                                )
4838
                    && (!(iqentry_iv[heads[3]] && iqentry_memdb[heads[3]]) ||
4839
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4840
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4841
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
4842
                                )
4843
                                        // ... and, if it is a SW, there is no chance of it being undone
4844
                                        && ((iqentry_load[heads[4]] && sple) ||
4845
                                      !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
4846
                       && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]])
4847
                       && !(iqentry_fc[heads[2]]||iqentry_canex[heads[2]])
4848
                       && !(iqentry_fc[heads[3]]||iqentry_canex[heads[3]]));
4849
         if (memissue[heads[4]])
4850
                issue_count = issue_count + 1;
4851
        end
4852
 
4853
        if (QENTRIES > 5) begin
4854
         memissue[ heads[5] ] = ~iqentry_stomp[heads[5]] && iqentry_memready[ heads[5] ]                // addr and data are valid
4855
                                        // ... and no preceding instruction is ready to go
4856
                                        && issue_count < `NUM_MEM
4857
                                        //&& ~iqentry_memready[heads[0]]
4858
                                        //&& ~iqentry_memready[heads[1]] 
4859
                                        //&& ~iqentry_memready[heads[2]] 
4860
                                        //&& ~iqentry_memready[heads[3]] 
4861
                                        //&& ~iqentry_memready[heads[4]] 
4862
                                        // ... and there is no address-overlap with any preceding instruction
4863
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]]) || iqentry_done[heads[0]]
4864
                                                || ((iqentry_ma[heads[5]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
4865
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]]) || iqentry_done[heads[1]]
4866
                                                || ((iqentry_ma[heads[5]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3] || iqentry_out[heads[1]] || iqentry_done[heads[1]])))
4867
                                        && (!iqentry_mem[heads[2]] || (iqentry_agen[heads[2]] & iqentry_out[heads[2]]) || iqentry_done[heads[2]]
4868
                                                || ((iqentry_ma[heads[5]][AMSB:3] != iqentry_ma[heads[2]][AMSB:3] || iqentry_out[heads[2]] || iqentry_done[heads[2]])))
4869
                                        && (!iqentry_mem[heads[3]] || (iqentry_agen[heads[3]] & iqentry_out[heads[3]]) || iqentry_done[heads[3]]
4870
                                                || ((iqentry_ma[heads[5]][AMSB:3] != iqentry_ma[heads[3]][AMSB:3] || iqentry_out[heads[3]] || iqentry_done[heads[3]])))
4871
                                        && (!iqentry_mem[heads[4]] || (iqentry_agen[heads[4]] & iqentry_out[heads[4]]) || iqentry_done[heads[4]]
4872
                                                || ((iqentry_ma[heads[5]][AMSB:3] != iqentry_ma[heads[4]][AMSB:3] || iqentry_out[heads[4]] || iqentry_done[heads[4]])))
4873
                                        // ... if a release, any prior memory ops must be done before this one
4874
                                        && (iqentry_rl[heads[5]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
4875
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
4876
                                                                                 && (iqentry_done[heads[2]] || !iqentry_v[heads[2]] || !iqentry_mem[heads[2]])
4877
                                                                                 && (iqentry_done[heads[3]] || !iqentry_v[heads[3]] || !iqentry_mem[heads[3]])
4878
                                                                                 && (iqentry_done[heads[4]] || !iqentry_v[heads[4]] || !iqentry_mem[heads[4]])
4879
                                                                                         : 1'b1)
4880
                                        // ... if a preivous op has the aquire bit set
4881
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
4882
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
4883
                                        && !(iqentry_aq[heads[2]] && iqentry_v[heads[2]])
4884
                                        && !(iqentry_aq[heads[3]] && iqentry_v[heads[3]])
4885
                                        && !(iqentry_aq[heads[4]] && iqentry_v[heads[4]])
4886
                                        // ... and there's nothing in the write buffer during a load
4887
                                        && !(iqentry_load[heads[5]] && (wb_v!=1'b0
4888
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]] || iqentry_store[heads[2]] || iqentry_store[heads[3]]
4889
                                                || iqentry_store[heads[4]]))
4890
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4891
                    && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4892
                    && (!(iqentry_iv[heads[2]] && iqentry_memsb[heads[2]]) ||
4893
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4894
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4895
                                )
4896
                    && (!(iqentry_iv[heads[3]] && iqentry_memsb[heads[3]]) ||
4897
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4898
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4899
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
4900
                                )
4901
                    && (!(iqentry_iv[heads[4]] && iqentry_memsb[heads[4]]) ||
4902
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4903
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4904
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4905
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
4906
                                )
4907
                                && (!(iqentry_iv[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4908
                    && (!(iqentry_iv[heads[2]] && iqentry_memdb[heads[2]]) ||
4909
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4910
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4911
                                )
4912
                    && (!(iqentry_iv[heads[3]] && iqentry_memdb[heads[3]]) ||
4913
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4914
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4915
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
4916
                                )
4917
                    && (!(iqentry_iv[heads[4]] && iqentry_memdb[heads[4]]) ||
4918
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4919
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4920
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4921
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
4922
                                )
4923
                                        // ... and, if it is a SW, there is no chance of it being undone
4924
                                        && ((iqentry_load[heads[5]] && sple) ||
4925
                                      !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
4926
                       && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]])
4927
                       && !(iqentry_fc[heads[2]]||iqentry_canex[heads[2]])
4928
                       && !(iqentry_fc[heads[3]]||iqentry_canex[heads[3]])
4929
                       && !(iqentry_fc[heads[4]]||iqentry_canex[heads[4]]));
4930
         if (memissue[heads[5]])
4931
                issue_count = issue_count + 1;
4932
        end
4933
 
4934
`ifdef FULL_ISSUE_LOGIC
4935
if (QENTRIES > 6) begin
4936
 memissue[ heads[6] ] = ~iqentry_stomp[heads[6]] && iqentry_memready[ heads[6] ]                // addr and data are valid
4937
                                        // ... and no preceding instruction is ready to go
4938
                                        && issue_count < `NUM_MEM
4939
                                        //&& ~iqentry_memready[heads[0]]
4940
                                        //&& ~iqentry_memready[heads[1]] 
4941
                                        //&& ~iqentry_memready[heads[2]] 
4942
                                        //&& ~iqentry_memready[heads[3]] 
4943
                                        //&& ~iqentry_memready[heads[4]] 
4944
                                        //&& ~iqentry_memready[heads[5]] 
4945
                                        // ... and there is no address-overlap with any preceding instruction
4946
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]]) || iqentry_done[heads[0]]
4947
                                                || ((iqentry_ma[heads[6]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3])))
4948
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]]) || iqentry_done[heads[1]]
4949
                                                || ((iqentry_ma[heads[6]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3])))
4950
                                        && (!iqentry_mem[heads[2]] || (iqentry_agen[heads[2]] & iqentry_out[heads[2]]) || iqentry_done[heads[2]]
4951
                                                || ((iqentry_ma[heads[6]][AMSB:3] != iqentry_ma[heads[2]][AMSB:3])))
4952
                                        && (!iqentry_mem[heads[3]] || (iqentry_agen[heads[3]] & iqentry_out[heads[3]]) || iqentry_done[heads[3]]
4953
                                                || ((iqentry_ma[heads[6]][AMSB:3] != iqentry_ma[heads[3]][AMSB:3])))
4954
                                        && (!iqentry_mem[heads[4]] || (iqentry_agen[heads[4]] & iqentry_out[heads[4]]) || iqentry_done[heads[4]]
4955
                                                || ((iqentry_ma[heads[6]][AMSB:3] != iqentry_ma[heads[4]][AMSB:3])))
4956
                                        && (!iqentry_mem[heads[5]] || (iqentry_agen[heads[5]] & iqentry_out[heads[5]]) || iqentry_done[heads[5]]
4957
                                                || ((iqentry_ma[heads[6]][AMSB:3] != iqentry_ma[heads[5]][AMSB:3])))
4958
                                        && (iqentry_rl[heads[6]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
4959
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
4960
                                                                                 && (iqentry_done[heads[2]] || !iqentry_v[heads[2]] || !iqentry_mem[heads[2]])
4961
                                                                                 && (iqentry_done[heads[3]] || !iqentry_v[heads[3]] || !iqentry_mem[heads[3]])
4962
                                                                                 && (iqentry_done[heads[4]] || !iqentry_v[heads[4]] || !iqentry_mem[heads[4]])
4963
                                                                                 && (iqentry_done[heads[5]] || !iqentry_v[heads[5]] || !iqentry_mem[heads[5]])
4964
                                                                                         : 1'b1)
4965
                                        // ... if a preivous op has the aquire bit set
4966
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
4967
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
4968
                                        && !(iqentry_aq[heads[2]] && iqentry_v[heads[2]])
4969
                                        && !(iqentry_aq[heads[3]] && iqentry_v[heads[3]])
4970
                                        && !(iqentry_aq[heads[4]] && iqentry_v[heads[4]])
4971
                                        && !(iqentry_aq[heads[5]] && iqentry_v[heads[5]])
4972
                                        // ... and there's nothing in the write buffer during a load
4973
                                        && !(iqentry_load[heads[6]] && (wb_v!=1'b0
4974
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]] || iqentry_store[heads[2]] || iqentry_store[heads[3]]
4975
                                                || iqentry_store[heads[4]] || iqentry_store[heads[5]]))
4976
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4977
                    && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
4978
                    && (!(iqentry_iv[heads[2]] && iqentry_memsb[heads[2]]) ||
4979
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4980
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
4981
                                )
4982
                    && (!(iqentry_iv[heads[3]] && iqentry_memsb[heads[3]]) ||
4983
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4984
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4985
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
4986
                                )
4987
                    && (!(iqentry_iv[heads[4]] && iqentry_memsb[heads[4]]) ||
4988
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4989
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4990
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4991
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
4992
                                )
4993
                    && (!(iqentry_iv[heads[5]] && iqentry_memsb[heads[5]]) ||
4994
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
4995
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
4996
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
4997
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
4998
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
4999
                                )
5000
                                && (!(iqentry_iv[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
5001
                    && (!(iqentry_iv[heads[2]] && iqentry_memdb[heads[2]]) ||
5002
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5003
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
5004
                                )
5005
                    && (!(iqentry_iv[heads[3]] && iqentry_memdb[heads[3]]) ||
5006
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5007
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5008
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
5009
                                )
5010
                    && (!(iqentry_iv[heads[4]] && iqentry_memdb[heads[4]]) ||
5011
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5012
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5013
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5014
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
5015
                                )
5016
                    && (!(iqentry_iv[heads[5]] && iqentry_memdb[heads[5]]) ||
5017
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5018
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5019
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5020
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5021
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
5022
                                )
5023
                                        // ... and, if it is a SW, there is no chance of it being undone
5024
                                        && ((iqentry_load[heads[6]] && sple) ||
5025
                                      !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
5026
                       && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]])
5027
                       && !(iqentry_fc[heads[2]]||iqentry_canex[heads[2]])
5028
                       && !(iqentry_fc[heads[3]]||iqentry_canex[heads[3]])
5029
                       && !(iqentry_fc[heads[4]]||iqentry_canex[heads[4]])
5030
                       && !(iqentry_fc[heads[5]]||iqentry_canex[heads[5]]));
5031
         if (memissue[heads[6]])
5032
                issue_count = issue_count + 1;
5033
        end
5034
 
5035
        if (QENTRIES > 7) begin
5036
        memissue[ heads[7] ] =  ~iqentry_stomp[heads[7]] && iqentry_memready[ heads[7] ]                // addr and data are valid
5037
                                        // ... and no preceding instruction is ready to go
5038
                                        && issue_count < `NUM_MEM
5039
                                        //&& ~iqentry_memready[heads[0]]
5040
                                        //&& ~iqentry_memready[heads[1]] 
5041
                                        //&& ~iqentry_memready[heads[2]] 
5042
                                        //&& ~iqentry_memready[heads[3]] 
5043
                                        //&& ~iqentry_memready[heads[4]] 
5044
                                        //&& ~iqentry_memready[heads[5]] 
5045
                                        //&& ~iqentry_memready[heads[6]] 
5046
                                        // ... and there is no address-overlap with any preceding instruction
5047
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]]) || iqentry_done[heads[0]]
5048
                                                || ((iqentry_ma[heads[7]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
5049
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]]) || iqentry_done[heads[1]]
5050
                                                || ((iqentry_ma[heads[7]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3] || iqentry_out[heads[1]] || iqentry_done[heads[1]])))
5051
                                        && (!iqentry_mem[heads[2]] || (iqentry_agen[heads[2]] & iqentry_out[heads[2]]) || iqentry_done[heads[2]]
5052
                                                || ((iqentry_ma[heads[7]][AMSB:3] != iqentry_ma[heads[2]][AMSB:3] || iqentry_out[heads[2]] || iqentry_done[heads[2]])))
5053
                                        && (!iqentry_mem[heads[3]] || (iqentry_agen[heads[3]] & iqentry_out[heads[3]]) || iqentry_done[heads[3]]
5054
                                                || ((iqentry_ma[heads[7]][AMSB:3] != iqentry_ma[heads[3]][AMSB:3] || iqentry_out[heads[3]] || iqentry_done[heads[3]])))
5055
                                        && (!iqentry_mem[heads[4]] || (iqentry_agen[heads[4]] & iqentry_out[heads[4]]) || iqentry_done[heads[4]]
5056
                                                || ((iqentry_ma[heads[7]][AMSB:3] != iqentry_ma[heads[4]][AMSB:3] || iqentry_out[heads[4]] || iqentry_done[heads[4]])))
5057
                                        && (!iqentry_mem[heads[5]] || (iqentry_agen[heads[5]] & iqentry_out[heads[5]]) || iqentry_done[heads[5]]
5058
                                                || ((iqentry_ma[heads[7]][AMSB:3] != iqentry_ma[heads[5]][AMSB:3] || iqentry_out[heads[5]] || iqentry_done[heads[5]])))
5059
                                        && (!iqentry_mem[heads[6]] || (iqentry_agen[heads[6]] & iqentry_out[heads[6]]) || iqentry_done[heads[6]]
5060
                                                || ((iqentry_ma[heads[7]][AMSB:3] != iqentry_ma[heads[6]][AMSB:3] || iqentry_out[heads[6]] || iqentry_done[heads[6]])))
5061
                                        && (iqentry_rl[heads[7]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
5062
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
5063
                                                                                 && (iqentry_done[heads[2]] || !iqentry_v[heads[2]] || !iqentry_mem[heads[2]])
5064
                                                                                 && (iqentry_done[heads[3]] || !iqentry_v[heads[3]] || !iqentry_mem[heads[3]])
5065
                                                                                 && (iqentry_done[heads[4]] || !iqentry_v[heads[4]] || !iqentry_mem[heads[4]])
5066
                                                                                 && (iqentry_done[heads[5]] || !iqentry_v[heads[5]] || !iqentry_mem[heads[5]])
5067
                                                                                 && (iqentry_done[heads[6]] || !iqentry_v[heads[6]] || !iqentry_mem[heads[6]])
5068
                                                                                         : 1'b1)
5069
                                        // ... if a preivous op has the aquire bit set
5070
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
5071
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
5072
                                        && !(iqentry_aq[heads[2]] && iqentry_v[heads[2]])
5073
                                        && !(iqentry_aq[heads[3]] && iqentry_v[heads[3]])
5074
                                        && !(iqentry_aq[heads[4]] && iqentry_v[heads[4]])
5075
                                        && !(iqentry_aq[heads[5]] && iqentry_v[heads[5]])
5076
                                        && !(iqentry_aq[heads[6]] && iqentry_v[heads[6]])
5077
                                        // ... and there's nothing in the write buffer during a load
5078
                                        && !(iqentry_load[heads[7]] && (wb_v!=1'b0
5079
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]] || iqentry_store[heads[2]] || iqentry_store[heads[3]]
5080
                                                || iqentry_store[heads[4]] || iqentry_store[heads[5]] || iqentry_store[heads[6]]))
5081
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5082
                    && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
5083
                    && (!(iqentry_iv[heads[2]] && iqentry_memsb[heads[2]]) ||
5084
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5085
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
5086
                                )
5087
                    && (!(iqentry_iv[heads[3]] && iqentry_memsb[heads[3]]) ||
5088
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5089
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5090
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
5091
                                )
5092
                    && (!(iqentry_iv[heads[4]] && iqentry_memsb[heads[4]]) ||
5093
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5094
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5095
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5096
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
5097
                                )
5098
                    && (!(iqentry_iv[heads[5]] && iqentry_memsb[heads[5]]) ||
5099
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5100
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5101
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5102
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5103
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
5104
                                )
5105
                    && (!(iqentry_iv[heads[6]] && iqentry_memsb[heads[6]]) ||
5106
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5107
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5108
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5109
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5110
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5111
                                &&   (iqentry_done[heads[5]] || !iqentry_v[heads[5]]))
5112
                                )
5113
                                && (!(iqentry_iv[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
5114
                    && (!(iqentry_iv[heads[2]] && iqentry_memdb[heads[2]]) ||
5115
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5116
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
5117
                                )
5118
                    && (!(iqentry_iv[heads[3]] && iqentry_memdb[heads[3]]) ||
5119
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5120
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5121
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
5122
                                )
5123
                    && (!(iqentry_iv[heads[4]] && iqentry_memdb[heads[4]]) ||
5124
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5125
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5126
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5127
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
5128
                                )
5129
                    && (!(iqentry_iv[heads[5]] && iqentry_memdb[heads[5]]) ||
5130
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5131
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5132
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5133
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5134
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
5135
                                )
5136
                    && (!(iqentry_iv[heads[6]] && iqentry_memdb[heads[6]]) ||
5137
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5138
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5139
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5140
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5141
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5142
                                && (!iqentry_mem[heads[5]] || iqentry_done[heads[5]] || !iqentry_v[heads[5]]))
5143
                                )
5144
                                        // ... and, if it is a SW, there is no chance of it being undone
5145
                                        && ((iqentry_load[heads[7]] && sple) ||
5146
                                      !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
5147
                       && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]])
5148
                       && !(iqentry_fc[heads[2]]||iqentry_canex[heads[2]])
5149
                       && !(iqentry_fc[heads[3]]||iqentry_canex[heads[3]])
5150
                       && !(iqentry_fc[heads[4]]||iqentry_canex[heads[4]])
5151
                       && !(iqentry_fc[heads[5]]||iqentry_canex[heads[5]])
5152
                       && !(iqentry_fc[heads[6]]||iqentry_canex[heads[6]]));
5153
         if (memissue[heads[7]])
5154
                issue_count = issue_count + 1;
5155
        end
5156
 
5157
        if (QENTRIES > 8) begin
5158
        memissue[ heads[8] ] =  ~iqentry_stomp[heads[8]] && iqentry_memready[ heads[8] ]                // addr and data are valid
5159
                                        // ... and no preceding instruction is ready to go
5160
                                        && issue_count < `NUM_MEM
5161
                                        //&& ~iqentry_memready[heads[0]]
5162
                                        //&& ~iqentry_memready[heads[1]] 
5163
                                        //&& ~iqentry_memready[heads[2]] 
5164
                                        //&& ~iqentry_memready[heads[3]] 
5165
                                        //&& ~iqentry_memready[heads[4]] 
5166
                                        //&& ~iqentry_memready[heads[5]] 
5167
                                        //&& ~iqentry_memready[heads[6]] 
5168
                                        // ... and there is no address-overlap with any preceding instruction
5169
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]]) || iqentry_done[heads[0]]
5170
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
5171
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]]) || iqentry_done[heads[1]]
5172
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3] || iqentry_out[heads[1]] || iqentry_done[heads[1]])))
5173
                                        && (!iqentry_mem[heads[2]] || (iqentry_agen[heads[2]] & iqentry_out[heads[2]]) || iqentry_done[heads[2]]
5174
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[2]][AMSB:3] || iqentry_out[heads[2]] || iqentry_done[heads[2]])))
5175
                                        && (!iqentry_mem[heads[3]] || (iqentry_agen[heads[3]] & iqentry_out[heads[3]]) || iqentry_done[heads[3]]
5176
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[3]][AMSB:3] || iqentry_out[heads[3]] || iqentry_done[heads[3]])))
5177
                                        && (!iqentry_mem[heads[4]] || (iqentry_agen[heads[4]] & iqentry_out[heads[4]]) || iqentry_done[heads[4]]
5178
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[4]][AMSB:3] || iqentry_out[heads[4]] || iqentry_done[heads[4]])))
5179
                                        && (!iqentry_mem[heads[5]] || (iqentry_agen[heads[5]] & iqentry_out[heads[5]]) || iqentry_done[heads[5]]
5180
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[5]][AMSB:3] || iqentry_out[heads[5]] || iqentry_done[heads[5]])))
5181
                                        && (!iqentry_mem[heads[6]] || (iqentry_agen[heads[6]] & iqentry_out[heads[6]]) || iqentry_done[heads[6]]
5182
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[6]][AMSB:3] || iqentry_out[heads[6]] || iqentry_done[heads[6]])))
5183
                                        && (!iqentry_mem[heads[7]] || (iqentry_agen[heads[7]] & iqentry_out[heads[7]]) || iqentry_done[heads[7]]
5184
                                                || ((iqentry_ma[heads[8]][AMSB:3] != iqentry_ma[heads[7]][AMSB:3] || iqentry_out[heads[7]] || iqentry_done[heads[7]])))
5185
                                        && (iqentry_rl[heads[8]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
5186
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
5187
                                                                                 && (iqentry_done[heads[2]] || !iqentry_v[heads[2]] || !iqentry_mem[heads[2]])
5188
                                                                                 && (iqentry_done[heads[3]] || !iqentry_v[heads[3]] || !iqentry_mem[heads[3]])
5189
                                                                                 && (iqentry_done[heads[4]] || !iqentry_v[heads[4]] || !iqentry_mem[heads[4]])
5190
                                                                                 && (iqentry_done[heads[5]] || !iqentry_v[heads[5]] || !iqentry_mem[heads[5]])
5191
                                                                                 && (iqentry_done[heads[6]] || !iqentry_v[heads[6]] || !iqentry_mem[heads[6]])
5192
                                                                                 && (iqentry_done[heads[7]] || !iqentry_v[heads[7]] || !iqentry_mem[heads[7]])
5193
                                                                                         : 1'b1)
5194
                                        // ... if a preivous op has the aquire bit set
5195
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
5196
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
5197
                                        && !(iqentry_aq[heads[2]] && iqentry_v[heads[2]])
5198
                                        && !(iqentry_aq[heads[3]] && iqentry_v[heads[3]])
5199
                                        && !(iqentry_aq[heads[4]] && iqentry_v[heads[4]])
5200
                                        && !(iqentry_aq[heads[5]] && iqentry_v[heads[5]])
5201
                                        && !(iqentry_aq[heads[6]] && iqentry_v[heads[6]])
5202
                                        && !(iqentry_aq[heads[7]] && iqentry_v[heads[7]])
5203
                                        // ... and there's nothing in the write buffer during a load
5204
                                        && !(iqentry_load[heads[8]] && (wb_v!=1'b0
5205
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]] || iqentry_store[heads[2]] || iqentry_store[heads[3]]
5206
                                                || iqentry_store[heads[4]] || iqentry_store[heads[5]] || iqentry_store[heads[6]] || iqentry_store[heads[7]]))
5207
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5208
                    && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
5209
                    && (!(iqentry_iv[heads[2]] && iqentry_memsb[heads[2]]) ||
5210
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5211
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
5212
                                )
5213
                    && (!(iqentry_iv[heads[3]] && iqentry_memsb[heads[3]]) ||
5214
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5215
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5216
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
5217
                                )
5218
                    && (!(iqentry_iv[heads[4]] && iqentry_memsb[heads[4]]) ||
5219
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5220
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5221
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5222
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
5223
                                )
5224
                    && (!(iqentry_iv[heads[5]] && iqentry_memsb[heads[5]]) ||
5225
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5226
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5227
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5228
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5229
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
5230
                                )
5231
                    && (!(iqentry_iv[heads[6]] && iqentry_memsb[heads[6]]) ||
5232
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5233
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5234
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5235
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5236
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5237
                                &&   (iqentry_done[heads[5]] || !iqentry_v[heads[5]]))
5238
                                )
5239
                    && (!(iqentry_iv[heads[7]] && iqentry_memsb[heads[7]]) ||
5240
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5241
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5242
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5243
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5244
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5245
                                &&   (iqentry_done[heads[5]] || !iqentry_v[heads[5]])
5246
                                &&   (iqentry_done[heads[6]] || !iqentry_v[heads[6]])
5247
                                )
5248
                                )
5249
                                && (!(iqentry_iv[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
5250
                    && (!(iqentry_iv[heads[2]] && iqentry_memdb[heads[2]]) ||
5251
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5252
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
5253
                                )
5254
                    && (!(iqentry_iv[heads[3]] && iqentry_memdb[heads[3]]) ||
5255
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5256
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5257
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
5258
                                )
5259
                    && (!(iqentry_iv[heads[4]] && iqentry_memdb[heads[4]]) ||
5260
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5261
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5262
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5263
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
5264
                                )
5265
                    && (!(iqentry_iv[heads[5]] && iqentry_memdb[heads[5]]) ||
5266
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5267
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5268
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5269
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5270
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
5271
                                )
5272
                    && (!(iqentry_iv[heads[6]] && iqentry_memdb[heads[6]]) ||
5273
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5274
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5275
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5276
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5277
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5278
                                && (!iqentry_mem[heads[5]] || iqentry_done[heads[5]] || !iqentry_v[heads[5]]))
5279
                                )
5280
                    && (!(iqentry_iv[heads[7]] && iqentry_memdb[heads[7]]) ||
5281
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5282
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5283
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5284
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5285
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5286
                                && (!iqentry_mem[heads[5]] || iqentry_done[heads[5]] || !iqentry_v[heads[5]])
5287
                                && (!iqentry_mem[heads[6]] || iqentry_done[heads[6]] || !iqentry_v[heads[6]])
5288
                                )
5289
                                )
5290
                                        // ... and, if it is a SW, there is no chance of it being undone
5291
                                        && ((iqentry_load[heads[8]] && sple) ||
5292
                                      !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
5293
                       && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]])
5294
                       && !(iqentry_fc[heads[2]]||iqentry_canex[heads[2]])
5295
                       && !(iqentry_fc[heads[3]]||iqentry_canex[heads[3]])
5296
                       && !(iqentry_fc[heads[4]]||iqentry_canex[heads[4]])
5297
                       && !(iqentry_fc[heads[5]]||iqentry_canex[heads[5]])
5298
                       && !(iqentry_fc[heads[6]]||iqentry_canex[heads[6]])
5299
                       && !(iqentry_fc[heads[7]]||iqentry_canex[heads[7]])
5300
                       );
5301
         if (memissue[heads[8]])
5302
                issue_count = issue_count + 1;
5303
        end
5304
 
5305
        if (QENTRIES > 9) begin
5306
        memissue[ heads[9] ] =  ~iqentry_stomp[heads[9]] && iqentry_memready[ heads[9] ]                // addr and data are valid
5307
                                        // ... and no preceding instruction is ready to go
5308
                                        && issue_count < `NUM_MEM
5309
                                        //&& ~iqentry_memready[heads[0]]
5310
                                        //&& ~iqentry_memready[heads[1]] 
5311
                                        //&& ~iqentry_memready[heads[2]] 
5312
                                        //&& ~iqentry_memready[heads[3]] 
5313
                                        //&& ~iqentry_memready[heads[4]] 
5314
                                        //&& ~iqentry_memready[heads[5]] 
5315
                                        //&& ~iqentry_memready[heads[6]] 
5316
                                        // ... and there is no address-overlap with any preceding instruction
5317
                                        && (!iqentry_mem[heads[0]] || (iqentry_agen[heads[0]] & iqentry_out[heads[0]]) || iqentry_done[heads[0]]
5318
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[0]][AMSB:3] || iqentry_out[heads[0]] || iqentry_done[heads[0]])))
5319
                                        && (!iqentry_mem[heads[1]] || (iqentry_agen[heads[1]] & iqentry_out[heads[1]]) || iqentry_done[heads[1]]
5320
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[1]][AMSB:3] || iqentry_out[heads[1]] || iqentry_done[heads[1]])))
5321
                                        && (!iqentry_mem[heads[2]] || (iqentry_agen[heads[2]] & iqentry_out[heads[2]]) || iqentry_done[heads[2]]
5322
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[2]][AMSB:3] || iqentry_out[heads[2]] || iqentry_done[heads[2]])))
5323
                                        && (!iqentry_mem[heads[3]] || (iqentry_agen[heads[3]] & iqentry_out[heads[3]]) || iqentry_done[heads[3]]
5324
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[3]][AMSB:3] || iqentry_out[heads[3]] || iqentry_done[heads[3]])))
5325
                                        && (!iqentry_mem[heads[4]] || (iqentry_agen[heads[4]] & iqentry_out[heads[4]]) || iqentry_done[heads[4]]
5326
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[4]][AMSB:3] || iqentry_out[heads[4]] || iqentry_done[heads[4]])))
5327
                                        && (!iqentry_mem[heads[5]] || (iqentry_agen[heads[5]] & iqentry_out[heads[5]]) || iqentry_done[heads[5]]
5328
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[5]][AMSB:3] || iqentry_out[heads[5]] || iqentry_done[heads[5]])))
5329
                                        && (!iqentry_mem[heads[6]] || (iqentry_agen[heads[6]] & iqentry_out[heads[6]]) || iqentry_done[heads[6]]
5330
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[6]][AMSB:3] || iqentry_out[heads[6]] || iqentry_done[heads[6]])))
5331
                                        && (!iqentry_mem[heads[7]] || (iqentry_agen[heads[7]] & iqentry_out[heads[7]]) || iqentry_done[heads[7]]
5332
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[7]][AMSB:3] || iqentry_out[heads[7]] || iqentry_done[heads[7]])))
5333
                                        && (!iqentry_mem[heads[8]] || (iqentry_agen[heads[8]] & iqentry_out[heads[8]]) || iqentry_done[heads[8]]
5334
                                                || ((iqentry_ma[heads[9]][AMSB:3] != iqentry_ma[heads[8]][AMSB:3] || iqentry_out[heads[8]] || iqentry_done[heads[8]])))
5335
                                        && (iqentry_rl[heads[9]] ? (iqentry_done[heads[0]] || !iqentry_v[heads[0]] || !iqentry_mem[heads[0]])
5336
                                                                                 && (iqentry_done[heads[1]] || !iqentry_v[heads[1]] || !iqentry_mem[heads[1]])
5337
                                                                                 && (iqentry_done[heads[2]] || !iqentry_v[heads[2]] || !iqentry_mem[heads[2]])
5338
                                                                                 && (iqentry_done[heads[3]] || !iqentry_v[heads[3]] || !iqentry_mem[heads[3]])
5339
                                                                                 && (iqentry_done[heads[4]] || !iqentry_v[heads[4]] || !iqentry_mem[heads[4]])
5340
                                                                                 && (iqentry_done[heads[5]] || !iqentry_v[heads[5]] || !iqentry_mem[heads[5]])
5341
                                                                                 && (iqentry_done[heads[6]] || !iqentry_v[heads[6]] || !iqentry_mem[heads[6]])
5342
                                                                                 && (iqentry_done[heads[7]] || !iqentry_v[heads[7]] || !iqentry_mem[heads[7]])
5343
                                                                                 && (iqentry_done[heads[8]] || !iqentry_v[heads[8]] || !iqentry_mem[heads[8]])
5344
                                                                                         : 1'b1)
5345
                                        // ... if a preivous op has the aquire bit set
5346
                                        && !(iqentry_aq[heads[0]] && iqentry_v[heads[0]])
5347
                                        && !(iqentry_aq[heads[1]] && iqentry_v[heads[1]])
5348
                                        && !(iqentry_aq[heads[2]] && iqentry_v[heads[2]])
5349
                                        && !(iqentry_aq[heads[3]] && iqentry_v[heads[3]])
5350
                                        && !(iqentry_aq[heads[4]] && iqentry_v[heads[4]])
5351
                                        && !(iqentry_aq[heads[5]] && iqentry_v[heads[5]])
5352
                                        && !(iqentry_aq[heads[6]] && iqentry_v[heads[6]])
5353
                                        && !(iqentry_aq[heads[7]] && iqentry_v[heads[7]])
5354
                                        && !(iqentry_aq[heads[8]] && iqentry_v[heads[8]])
5355
                                        // ... and there's nothing in the write buffer during a load
5356
                                        && !(iqentry_load[heads[9]] && (wb_v!=1'b0
5357
                                                || iqentry_store[heads[0]] || iqentry_store[heads[1]] || iqentry_store[heads[2]] || iqentry_store[heads[3]]
5358
                                                || iqentry_store[heads[4]] || iqentry_store[heads[5]] || iqentry_store[heads[6]] || iqentry_store[heads[7]]
5359
                                                || iqentry_store[heads[8]]))
5360
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5361
                    && (!(iqentry_iv[heads[1]] && iqentry_memsb[heads[1]]) || (iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
5362
                    && (!(iqentry_iv[heads[2]] && iqentry_memsb[heads[2]]) ||
5363
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5364
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
5365
                                )
5366
                    && (!(iqentry_iv[heads[3]] && iqentry_memsb[heads[3]]) ||
5367
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5368
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5369
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
5370
                                )
5371
                    && (!(iqentry_iv[heads[4]] && iqentry_memsb[heads[4]]) ||
5372
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5373
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5374
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5375
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
5376
                                )
5377
                    && (!(iqentry_iv[heads[5]] && iqentry_memsb[heads[5]]) ||
5378
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5379
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5380
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5381
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5382
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
5383
                                )
5384
                    && (!(iqentry_iv[heads[6]] && iqentry_memsb[heads[6]]) ||
5385
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5386
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5387
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5388
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5389
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5390
                                &&   (iqentry_done[heads[5]] || !iqentry_v[heads[5]]))
5391
                                )
5392
                    && (!(iqentry_iv[heads[7]] && iqentry_memsb[heads[7]]) ||
5393
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5394
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5395
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5396
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5397
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5398
                                &&   (iqentry_done[heads[5]] || !iqentry_v[heads[5]])
5399
                                &&   (iqentry_done[heads[6]] || !iqentry_v[heads[6]]))
5400
                                )
5401
                    && (!(iqentry_iv[heads[8]] && iqentry_memsb[heads[8]]) ||
5402
                                        ((iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5403
                                &&   (iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5404
                                &&   (iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5405
                                &&   (iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5406
                                &&   (iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5407
                                &&   (iqentry_done[heads[5]] || !iqentry_v[heads[5]])
5408
                                &&   (iqentry_done[heads[6]] || !iqentry_v[heads[6]])
5409
                                &&   (iqentry_done[heads[7]] || !iqentry_v[heads[7]])
5410
                                )
5411
                                )
5412
                                && (!(iqentry_iv[heads[1]] && iqentry_memdb[heads[1]]) || (!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]]))
5413
                    && (!(iqentry_iv[heads[2]] && iqentry_memdb[heads[2]]) ||
5414
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5415
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]]))
5416
                                )
5417
                    && (!(iqentry_iv[heads[3]] && iqentry_memdb[heads[3]]) ||
5418
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5419
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5420
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]]))
5421
                                )
5422
                    && (!(iqentry_iv[heads[4]] && iqentry_memdb[heads[4]]) ||
5423
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5424
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5425
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5426
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]]))
5427
                                )
5428
                    && (!(iqentry_iv[heads[5]] && iqentry_memdb[heads[5]]) ||
5429
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5430
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5431
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5432
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5433
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]]))
5434
                                )
5435
                    && (!(iqentry_iv[heads[6]] && iqentry_memdb[heads[6]]) ||
5436
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5437
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5438
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5439
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5440
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5441
                                && (!iqentry_mem[heads[5]] || iqentry_done[heads[5]] || !iqentry_v[heads[5]]))
5442
                                )
5443
                    && (!(iqentry_iv[heads[7]] && iqentry_memdb[heads[7]]) ||
5444
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5445
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5446
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5447
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5448
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5449
                                && (!iqentry_mem[heads[5]] || iqentry_done[heads[5]] || !iqentry_v[heads[5]])
5450
                                && (!iqentry_mem[heads[6]] || iqentry_done[heads[6]] || !iqentry_v[heads[6]]))
5451
                                )
5452
                    && (!(iqentry_iv[heads[8]] && iqentry_memdb[heads[8]]) ||
5453
                                  ((!iqentry_mem[heads[0]] || iqentry_done[heads[0]] || !iqentry_v[heads[0]])
5454
                                && (!iqentry_mem[heads[1]] || iqentry_done[heads[1]] || !iqentry_v[heads[1]])
5455
                                && (!iqentry_mem[heads[2]] || iqentry_done[heads[2]] || !iqentry_v[heads[2]])
5456
                                && (!iqentry_mem[heads[3]] || iqentry_done[heads[3]] || !iqentry_v[heads[3]])
5457
                                && (!iqentry_mem[heads[4]] || iqentry_done[heads[4]] || !iqentry_v[heads[4]])
5458
                                && (!iqentry_mem[heads[5]] || iqentry_done[heads[5]] || !iqentry_v[heads[5]])
5459
                                && (!iqentry_mem[heads[6]] || iqentry_done[heads[6]] || !iqentry_v[heads[6]])
5460
                                && (!iqentry_mem[heads[7]] || iqentry_done[heads[7]] || !iqentry_v[heads[7]])
5461
                                )
5462
                                )
5463
                                        // ... and, if it is a store, there is no chance of it being undone
5464
                                        && ((iqentry_load[heads[9]] && sple) ||
5465
                                      !(iqentry_fc[heads[0]]||iqentry_canex[heads[0]])
5466
                       && !(iqentry_fc[heads[1]]||iqentry_canex[heads[1]])
5467
                       && !(iqentry_fc[heads[2]]||iqentry_canex[heads[2]])
5468
                       && !(iqentry_fc[heads[3]]||iqentry_canex[heads[3]])
5469
                       && !(iqentry_fc[heads[4]]||iqentry_canex[heads[4]])
5470
                       && !(iqentry_fc[heads[5]]||iqentry_canex[heads[5]])
5471
                       && !(iqentry_fc[heads[6]]||iqentry_canex[heads[6]])
5472
                       && !(iqentry_fc[heads[7]]||iqentry_canex[heads[7]])
5473
                       && !(iqentry_fc[heads[8]]||iqentry_canex[heads[8]])
5474
                       );
5475
         if (memissue[heads[9]])
5476
                issue_count = issue_count + 1;
5477
        end
5478
end
5479
end
5480
endgenerate
5481
`endif
5482
 
5483
// Starts search for instructions to issue at the head of the queue and 
5484
// progresses from there. This ensures that the oldest instructions are
5485
// selected first for processing.
5486
always @*
5487
begin
5488
        last_issue0 = QENTRIES;
5489
        last_issue1 = QENTRIES;
5490
        last_issue2 = QENTRIES;
5491
        for (n = 0; n < QENTRIES; n = n + 1)
5492
    if (~iqentry_stomp[heads[n]] && iqentry_memissue[heads[n]]) begin
5493
      if (mem1_available && dram0 == `DRAMSLOT_AVAIL) begin
5494
       last_issue0 = heads[n];
5495
      end
5496
    end
5497
        for (n = 0; n < QENTRIES; n = n + 1)
5498
    if (~iqentry_stomp[heads[n]] && iqentry_memissue[heads[n]]) begin
5499
        if (mem2_available && heads[n] != last_issue0 && `NUM_MEM > 1) begin
5500
        if (dram1 == `DRAMSLOT_AVAIL) begin
5501
                                        last_issue1 = heads[n];
5502
        end
5503
        end
5504
    end
5505
        for (n = 0; n < QENTRIES; n = n + 1)
5506
    if (~iqentry_stomp[heads[n]] && iqentry_memissue[heads[n]]) begin
5507
        if (mem3_available && heads[n] != last_issue0 && heads[n] != last_issue1 && `NUM_MEM > 2) begin
5508
        if (dram2 == `DRAMSLOT_AVAIL) begin
5509
                last_issue2 = heads[n];
5510
        end
5511
        end
5512
    end
5513
end
5514
 
5515
reg [2:0] wbptr;
5516
// Stomp logic for branch miss.
5517
/*
5518
FT64_stomp #(QENTRIES) ustmp1
5519
(
5520
        .branchmiss(branchmiss),
5521
        .branchmiss_thrd(branchmiss_thrd),
5522
        .missid(missid),
5523
        .head0(heads[0]),
5524
        .thrd(iqentry_thrd),
5525
        .iqentry_v(iqentry_v),
5526
        .stomp(iqentry_stomp)
5527
);
5528
*/
5529
always @*
5530
begin
5531
        iqentry_stomp <= 1'b0;
5532
        if (branchmiss) begin
5533
                for (n = 0; n < QENTRIES; n = n + 1) begin
5534
                        if (iqentry_v[n] && iqentry_thrd[n]==branchmiss_thrd) begin
5535
                                if (iqentry_sn[n] > iqentry_sn[missid[`QBITS]])
5536
                                        iqentry_stomp[n] <= `TRUE;
5537
                        end
5538
                end
5539
        end
5540
        /*
5541
        if (fcu_branchmiss) begin
5542
                for (n = 0; n < QENTRIES; n = n + 1) begin
5543
                        if (iqentry_v[n] && iqentry_thrd[n]==fcu_thrd) begin
5544
                                if (iqentry_sn[n] > iqentry_sn[fcu_id[`QBITS]])
5545
                                        iqentry_stomp[n] <= `TRUE;
5546
                        end
5547
                end
5548
        end
5549
        */
5550
end
5551
 
5552
always @*
5553
begin
5554
        stompedOnRets = 1'b0;
5555
        for (n = 0; n < QENTRIES; n = n + 1)
5556
                if (iqentry_stomp[n] && iqentry_ret[n])
5557
                        stompedOnRets = stompedOnRets + 4'd1;
5558
end
5559
 
5560
reg id1_vi, id2_vi, id3_vi;
5561
wire [4:0] id1_ido, id2_ido, id3_ido;
5562
wire id1_vo, id2_vo, id3_vo;
5563
wire id1_clk, id2_clk, id3_clk;
5564
 
5565
// Always at least one decoder
5566
assign id1_clk = clk_i;
5567
//BUFGCE uclkb2
5568
//(
5569
//      .I(clk_i),
5570
//      .CE(id1_available),
5571
//      .O(id1_clk)
5572
//);
5573
 
5574
FT64_idecoder uid1
5575
(
5576
        .clk(id1_clk),
5577
        .idv_i(id1_vi),
5578
        .id_i(id1_id),
5579
`ifdef INLINE_DECODE
5580
        .instr(fetchbuf0_instr),
5581
        .Rt(Rt0[4:0]),
5582
        .predict_taken(predict_taken0),
5583
        .thrd(fetchbuf0_thrd),
5584
        .vl(vl),
5585
`else
5586
        .instr(id1_instr),
5587
        .Rt(id1_Rt),
5588
        .predict_taken(id1_pt),
5589
        .thrd(id1_thrd),
5590
        .vl(id1_vl),
5591
`endif
5592
//ToDo: fix for vectors length and element number
5593
        .ven(id1_ven),
5594
        .bus(id1_bus),
5595
        .id_o(id1_ido),
5596
        .idv_o(id1_vo),
5597
        .debug_on(debug_on),
5598
        .pred_on(pred_on)
5599
);
5600
/*
5601
`ifdef INLINE_DECODE
5602
        id1_Rt <= Rt0[4:0];
5603
        id1_vl <= vl;
5604
        id1_ven <= venno;
5605
        id1_id <= tail;
5606
        id1_pt <= predict_taken0;
5607
        id1_thrd <= fetchbuf0_thrd;
5608
        setinsn1(tail,id1_bus);
5609
`endif
5610
*/
5611
generate begin : gIDUInst
5612
if (`NUM_IDU > 1) begin
5613
//BUFGCE uclkb3
5614
//(
5615
//      .I(clk_i),
5616
//      .CE(id2_available),
5617
//      .O(id2_clk)
5618
//);
5619
assign id2_clk = clk_i;
5620
 
5621
FT64_idecoder uid2
5622
(
5623
        .clk(id2_clk),
5624
        .idv_i(id2_vi),
5625
        .id_i(id2_id),
5626
`ifdef INLINE_DECODE
5627
        .instr(fetchbuf1_instr),
5628
        .Rt(Rt1[4:0]),
5629
        .predict_taken(predict_taken1),
5630
        .thrd(fetchbuf1_thrd),
5631
        .vl(vl),
5632
`else
5633
        .instr(id2_instr),
5634
        .Rt(id2_Rt),
5635
        .predict_taken(id2_pt),
5636
        .thrd(id2_thrd),
5637
        .vl(id2_vl),
5638
`endif
5639
        .ven(id2_ven),
5640
        .bus(id2_bus),
5641
        .id_o(id2_ido),
5642
        .idv_o(id2_vo),
5643
        .debug_on(debug_on),
5644
        .pred_on(pred_on)
5645
);
5646
end
5647
if (`NUM_IDU > 2) begin
5648
//BUFGCE uclkb4
5649
//(
5650
//      .I(clk_i),
5651
//      .CE(id3_available),
5652
//      .O(id3_clk)
5653
//);
5654
assign id3_clk = clk_i;
5655
 
5656
FT64_idecoder uid2
5657
(
5658
        .clk(id3_clk),
5659
        .idv_i(id3_vi),
5660
        .id_i(id3_id),
5661
`ifdef INLINE_DECODE
5662
        .instr(fetchbuf2_instr),
5663
        .Rt(Rt2[4:0]),
5664
        .predict_taken(predict_taken2),
5665
        .thrd(fetchbuf2_thrd),
5666
        .vl(vl),
5667
`else
5668
        .instr(id3_instr),
5669
        .Rt(id3_Rt),
5670
        .predict_taken(id3_pt),
5671
        .thrd(id3_thrd),
5672
        .vl(id3_vl),
5673
`endif
5674
        .ven(id3_ven),
5675
        .bus(id3_bus),
5676
        .id_o(id3_ido),
5677
        .idv_o(id3_vo),
5678
        .debug_on(debug_on),
5679
        .pred_on(pred_on)
5680
);
5681
end
5682
end
5683
endgenerate
5684
 
5685
//
5686
// EXECUTE
5687
//
5688
wire [15:0] lfsro;
5689
lfsr #(16,16'hACE4) u1 (rst, clk, 1'b1, 1'b0, lfsro);
5690
 
5691
reg [63:0] csr_r;
5692
wire [11:0] csrno = alu0_instr[29:18];
5693
always @*
5694
begin
5695
`ifdef SUPPORT_SMT
5696
    if (csrno[11:10] >= ol[alu0_thrd])
5697
`else
5698
    if (csrno[11:10] >= ol)
5699
`endif
5700
    casez(csrno[9:0])
5701
    `CSR_CR0:       csr_r <= cr0;
5702
    `CSR_HARTID:    csr_r <= hartid;
5703
    `CSR_TICK:      csr_r <= tick;
5704
    `CSR_PCR:       csr_r <= pcr;
5705
    `CSR_PCR2:      csr_r <= pcr2;
5706
    `CSR_PMR:                           csr_r <= pmr;
5707
    `CSR_WBRCD:         csr_r <= wbrcd;
5708
    `CSR_SEMA:      csr_r <= sema;
5709
    `CSR_KEYS:                  csr_r <= keys;
5710
    `CSR_TCB:           csr_r <= tcb;
5711
    `CSR_FSTAT:     csr_r <= {fp_rgs,fp_status};
5712
`ifdef SUPPORT_DBG
5713
    `CSR_DBAD0:     csr_r <= dbg_adr0;
5714
    `CSR_DBAD1:     csr_r <= dbg_adr1;
5715
    `CSR_DBAD2:     csr_r <= dbg_adr2;
5716
    `CSR_DBAD3:     csr_r <= dbg_adr3;
5717
    `CSR_DBCTRL:    csr_r <= dbg_ctrl;
5718
    `CSR_DBSTAT:    csr_r <= dbg_stat;
5719
`endif
5720
    `CSR_CAS:       csr_r <= cas;
5721
    `CSR_TVEC:      csr_r <= tvec[csrno[2:0]];
5722
    `CSR_BADADR:    csr_r <= badaddr[{alu0_thrd,csrno[11:10]}];
5723
    `CSR_BADINSTR:      csr_r <= bad_instr[{alu0_thrd,csrno[11:10]}];
5724
    `CSR_CAUSE:     csr_r <= {48'd0,cause[{alu0_thrd,csrno[11:10]}]};
5725
`ifdef SUPPORT_SMT
5726
    `CSR_IM_STACK:      csr_r <= im_stack[alu0_thrd];
5727
    `CSR_OL_STACK:      csr_r <= {dl_stack[alu0_thrd],ol_stack[alu0_thrd]};
5728
    `CSR_PL_STACK:      csr_r <= pl_stack[alu0_thrd];
5729
    `CSR_RS_STACK:      csr_r <= rs_stack[alu0_thrd];
5730
    `CSR_STATUS:    csr_r <= mstatus[alu0_thrd][63:0];
5731
    `CSR_BRS_STACK:     csr_r <= brs_stack[alu0_thrd];
5732
    `CSR_EPC0:      csr_r <= epc0[alu0_thrd];
5733
    `CSR_EPC1:      csr_r <= epc1[alu0_thrd];
5734
    `CSR_EPC2:      csr_r <= epc2[alu0_thrd];
5735
    `CSR_EPC3:      csr_r <= epc3[alu0_thrd];
5736
    `CSR_EPC4:      csr_r <= epc4[alu0_thrd];
5737
    `CSR_EPC5:      csr_r <= epc5[alu0_thrd];
5738
    `CSR_EPC6:      csr_r <= epc6[alu0_thrd];
5739
    `CSR_EPC7:      csr_r <= epc7[alu0_thrd];
5740
`else
5741
    `CSR_IM_STACK:      csr_r <= im_stack;
5742
    `CSR_OL_STACK:      csr_r <= {dl_stack,ol_stack};
5743
    `CSR_PL_STACK:      csr_r <= pl_stack;
5744
    `CSR_RS_STACK:      csr_r <= rs_stack;
5745
    `CSR_STATUS:    csr_r <= mstatus[63:0];
5746
    `CSR_BRS_STACK:     csr_r <= brs_stack;
5747
    `CSR_EPC0:      csr_r <= epc0;
5748
    `CSR_EPC1:      csr_r <= epc1;
5749
    `CSR_EPC2:      csr_r <= epc2;
5750
    `CSR_EPC3:      csr_r <= epc3;
5751
    `CSR_EPC4:      csr_r <= epc4;
5752
    `CSR_EPC5:      csr_r <= epc5;
5753
    `CSR_EPC6:      csr_r <= epc6;
5754
    `CSR_EPC7:      csr_r <= epc7;
5755
`endif
5756
    `CSR_CODEBUF:   csr_r <= codebuf[csrno[5:0]];
5757
`ifdef SUPPORT_BBMS
5758
                `CSR_TB:                        csr_r <= tb;
5759
                `CSR_CBL:                       csr_r <= cbl;
5760
                `CSR_CBU:                       csr_r <= cbu;
5761
                `CSR_RO:                        csr_r <= ro;
5762
                `CSR_DBL:                       csr_r <= dbl;
5763
                `CSR_DBU:                       csr_r <= dbu;
5764
                `CSR_SBL:                       csr_r <= sbl;
5765
                `CSR_SBU:                       csr_r <= sbu;
5766
                `CSR_ENU:                       csr_r <= en;
5767
`endif
5768
`ifdef SUPPORT_PREDICATION
5769
                `CSR_PREGS:             read_pregs(csr_r);
5770
`endif
5771
    `CSR_Q_CTR:         csr_r <= iq_ctr;
5772
    `CSR_BM_CTR:        csr_r <= bm_ctr;
5773
    `CSR_ICL_CTR:       csr_r <= icl_ctr;
5774
    `CSR_IRQ_CTR:       csr_r <= irq_ctr;
5775
    `CSR_TIME:          csr_r <= wc_times;
5776
    `CSR_INFO:
5777
                    case(csrno[3:0])
5778
                    4'd0:   csr_r <= "Finitron";  // manufacturer
5779
                    4'd1:   csr_r <= "        ";
5780
                    4'd2:   csr_r <= "64 bit  ";  // CPU class
5781
                    4'd3:   csr_r <= "        ";
5782
                    4'd4:   csr_r <= "FT64    ";  // Name
5783
                    4'd5:   csr_r <= "        ";
5784
                    4'd6:   csr_r <= 64'd1;       // model #
5785
                    4'd7:   csr_r <= 64'd1;       // serial number
5786
                    4'd8:   csr_r <= {32'd16384,32'd16384};   // cache sizes instruction,csr_ra
5787
                    4'd9:   csr_r <= 64'd0;
5788
                    default:    csr_r <= 64'd0;
5789
                    endcase
5790
    default:    begin
5791
                        $display("Unsupported CSR:%h",csrno[10:0]);
5792
                        csr_r <= 64'hEEEEEEEEEEEEEEEE;
5793
                        end
5794
    endcase
5795
    else
5796
        csr_r <= 64'h0;
5797
end
5798
 
5799
reg [63:0] alu0_xu = 1'd0, alu1_xu = 1'd0;
5800
 
5801
`ifdef SUPPORT_BBMS
5802
 
5803
`else
5804
// This always block didn't work, it left the signals as X's.
5805
// So they are set to zero where the reg declaration is.
5806
// I'm guessing the @* says there's no variables on the right
5807
// hand side, so I'm not going to evaluate it.
5808
always @*
5809
        alu0_xs <= 64'd0;
5810
always @*
5811
        alu1_xs <= 64'd0;
5812
`endif
5813
 
5814
//always @*
5815
//    read_csr(alu0_instr[29:18],csr_r,alu0_thrd);
5816
FT64_alu #(.BIG(1'b1),.SUP_VECTOR(SUP_VECTOR)) ualu0 (
5817
  .rst(rst),
5818
  .clk(clk),
5819
  .ld(alu0_ld),
5820
  .abort(alu0_abort),
5821
  .instr(alu0_instr),
5822
  .sz(alu0_sz),
5823
  .tlb(alu0_tlb),
5824
  .store(alu0_store),
5825
  .a(alu0_argA),
5826
  .b(alu0_argB),
5827
  .c(alu0_argC),
5828
  .pc(alu0_pc),
5829
//    .imm(alu0_argI),
5830
  .tgt(alu0_tgt),
5831
  .ven(alu0_ven),
5832
  .vm(vm[alu0_instr[25:23]]),
5833
  .csr(csr_r),
5834
  .o(alu0_out),
5835
  .ob(alu0b_bus),
5836
  .done(alu0_done),
5837
  .idle(alu0_idle),
5838
  .excen(aec[4:0]),
5839
  .exc(alu0_exc),
5840
  .thrd(alu0_thrd),
5841
  .mem(alu0_mem),
5842
  .shift(alu0_shft),    // 48 bit shift inst.
5843
  .ol(ol),
5844
  .ASID(ASID),
5845
  .icl_i(icl_o),
5846
  .cyc_i(cyc),
5847
  .we_i(we),
5848
  .vadr_i(vadr),
5849
  .cyc_o(cyc_o),
5850
  .we_o(we_o),
5851
  .padr_o(adr_o),
5852
  .uncached(),
5853
  .tlb_miss(tlb_miss),
5854
  .exv_o(exv_i),
5855
  .wrv_o(wrv_i),
5856
  .rdv_o(rdv_i)
5857
`ifdef SUPPORT_SEGMENTATION
5858
        ,
5859
        .zs_base(zsx_base),
5860
        .ds_base(dsx_base),
5861
        .es_base(esx_base),
5862
        .fs_base(fsx_base),
5863
        .gs_base(gsx_base),
5864
        .hs_base(hsx_base),
5865
        .ss_base(ssx_base),
5866
        .cs_base(csx_base),
5867
        .zsub(zsub),
5868
        .dsub(dsub),
5869
        .esub(esub),
5870
        .fsub(fsub),
5871
        .gsub(gsub),
5872
        .hsub(hsub),
5873
        .ssub(ssub),
5874
        .csub(csub),
5875
        .zslb(zslb),
5876
        .dslb(dslb),
5877
        .eslb(eslb),
5878
        .fslb(fslb),
5879
        .gslb(gslb),
5880
        .hslb(hslb),
5881
        .sslb(sslb),
5882
        .cslb(cslb)
5883
`endif
5884
`ifdef SUPPORT_BBMS
5885
  .pb(dl==2'b00 ? 64'd0 : pb),
5886
  .cbl(cbl),
5887
  .cbu(cbu),
5888
  .ro(ro),
5889
  .dbl(dbl),
5890
  .dbu(dbu),
5891
  .sbl(sbl),
5892
  .sbu(sbu),
5893
  .en(en)
5894
`endif
5895
);
5896
generate begin : gAluInst
5897
if (`NUM_ALU > 1) begin
5898
FT64_alu #(.BIG(1'b0),.SUP_VECTOR(SUP_VECTOR)) ualu1 (
5899
  .rst(rst),
5900
  .clk(clk),
5901
  .ld(alu1_ld),
5902
  .abort(alu1_abort),
5903
  .instr(alu1_instr),
5904
  .sz(alu1_sz),
5905
  .tlb(1'b0),
5906
  .store(alu1_store),
5907
  .a(alu1_argA),
5908
  .b(alu1_argB),
5909
  .c(alu1_argC),
5910
  .pc(alu1_pc),
5911
  //.imm(alu1_argI),
5912
  .tgt(alu1_tgt),
5913
  .ven(alu1_ven),
5914
  .vm(vm[alu1_instr[25:23]]),
5915
  .csr(64'd0),
5916
  .o(alu1_out),
5917
  .ob(alu1b_bus),
5918
  .done(alu1_done),
5919
  .idle(alu1_idle),
5920
  .excen(aec[4:0]),
5921
  .exc(alu1_exc),
5922
  .thrd(1'b0),
5923
  .mem(alu1_mem),
5924
  .shift(alu1_shft),
5925
  .ol(2'b0),
5926
  .ASID(8'h0),
5927
  .cyc_i(1'b0),
5928
  .we_i(1'b0),
5929
  .vadr_i(64'd0),
5930
  .cyc_o(),
5931
  .we_o(),
5932
  .padr_o(),
5933
  .uncached(),
5934
  .tlb_miss(),
5935
  .exv_o(),
5936
  .wrv_o(),
5937
  .rdv_o()
5938
`ifdef SUPPORT_SEGMENTATION
5939
        ,
5940
        .zs_base(zsx_base),
5941
        .ds_base(dsx_base),
5942
        .es_base(esx_base),
5943
        .fs_base(fsx_base),
5944
        .gs_base(gsx_base),
5945
        .hs_base(hsx_base),
5946
        .ss_base(ssx_base),
5947
        .cs_base(csx_base),
5948
        .zsub(zsub),
5949
        .dsub(dsub),
5950
        .esub(esub),
5951
        .fsub(fsub),
5952
        .gsub(gsub),
5953
        .hsub(hsub),
5954
        .ssub(ssub),
5955
        .csub(csub),
5956
        .zslb(zslb),
5957
        .dslb(dslb),
5958
        .eslb(eslb),
5959
        .fslb(fslb),
5960
        .gslb(gslb),
5961
        .hslb(hslb),
5962
        .sslb(sslb),
5963
        .cslb(cslb)
5964
`endif
5965
`ifdef SUPPORT_BBMS
5966
  .pb(dl==2'b00 ? 64'd0 : pb),
5967
  .cbl(cbl),
5968
  .cbu(cbu),
5969
  .ro(ro),
5970
  .dbl(dbl),
5971
  .dbu(dbu),
5972
  .sbl(sbl),
5973
  .sbu(sbu),
5974
  .en(en)
5975
`endif
5976
);
5977
end
5978
end
5979
endgenerate
5980
 
5981
always @*
5982
begin
5983
    alu0_cmt <= 1'b1;
5984
    alu1_cmt <= 1'b1;
5985
    fpu1_cmt <= 1'b1;
5986
    fpu2_cmt <= 1'b1;
5987
    fcu_cmt <= 1'b1;
5988
 
5989
    alu0_bus <= alu0_out;
5990
    alu1_bus <= alu1_out;
5991
    fpu1_bus <= fpu1_out;
5992
    fpu2_bus <= fpu2_out;
5993
    fcu_bus <= fcu_out;
5994
end
5995
 
5996
assign alu0_abort = 1'b0;
5997
assign alu1_abort = 1'b0;
5998
 
5999
generate begin : gFPUInst
6000
if (`NUM_FPU > 0) begin
6001
wire fpu1_clk;
6002
//BUFGCE ufpc1
6003
//(
6004
//      .I(clk_i),
6005
//      .CE(fpu1_available),
6006
//      .O(fpu1_clk)
6007
//);
6008
assign fpu1_clk = clk_i;
6009
 
6010
fpUnit ufp1
6011
(
6012
  .rst(rst),
6013
  .clk(fpu1_clk),
6014
  .clk4x(clk4x),
6015
  .ce(1'b1),
6016
  .ir(fpu1_instr),
6017
  .ld(fpu1_ld),
6018
  .a(fpu1_argA),
6019
  .b(fpu1_argB),
6020
  .imm(fpu1_argI),
6021
  .o(fpu1_out),
6022
  .csr_i(),
6023
  .status(fpu1_status),
6024
  .exception(),
6025
  .done(fpu1_done)
6026
);
6027
end
6028
if (`NUM_FPU > 1) begin
6029
wire fpu2_clk;
6030
//BUFGCE ufpc2
6031
//(
6032
//      .I(clk_i),
6033
//      .CE(fpu2_available),
6034
//      .O(fpu2_clk)
6035
//);
6036
assign fpu2_clk = clk_i;
6037
fpUnit ufp1
6038
(
6039
  .rst(rst),
6040
  .clk(fpu2_clk),
6041
  .clk4x(clk4x),
6042
  .ce(1'b1),
6043
  .ir(fpu2_instr),
6044
  .ld(fpu2_ld),
6045
  .a(fpu2_argA),
6046
  .b(fpu2_argB),
6047
  .imm(fpu2_argI),
6048
  .o(fpu2_out),
6049
  .csr_i(),
6050
  .status(fpu2_status),
6051
  .exception(),
6052
  .done(fpu2_done)
6053
);
6054
end
6055
end
6056
endgenerate
6057
 
6058
assign fpu1_exc = (fpu1_available) ?
6059
                                                                        ((|fpu1_status[15:0]) ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
6060
assign fpu2_exc = (fpu2_available) ?
6061
                                                                        ((|fpu2_status[15:0]) ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
6062
 
6063
assign  alu0_v = alu0_dataready,
6064
        alu1_v = alu1_dataready;
6065
assign  alu0_id = alu0_sourceid,
6066
            alu1_id = alu1_sourceid;
6067
assign  fpu1_v = fpu1_dataready;
6068
assign  fpu1_id = fpu1_sourceid;
6069
assign  fpu2_v = fpu2_dataready;
6070
assign  fpu2_id = fpu2_sourceid;
6071
 
6072
`ifdef SUPPORT_SMT
6073
wire [1:0] olm = ol[fcu_thrd];
6074
`else
6075
wire [1:0] olm = ol;
6076
`endif
6077
 
6078
reg [`SNBITS] maxsn [0:`WAYS-1];
6079
always @*
6080
begin
6081
        for (j = 0; j < `WAYS; j = j + 1) begin
6082
                maxsn[j] = 8'd0;
6083
                for (n = 0; n < QENTRIES; n = n + 1)
6084
                        if (iqentry_sn[n] > maxsn[j] && iqentry_thrd[n]==j && iqentry_v[n])
6085
                                maxsn[j] = iqentry_sn[n];
6086
                maxsn[j] = maxsn[j] - tosub;
6087
        end
6088
end
6089
 
6090
assign  fcu_v = fcu_dataready;
6091
assign  fcu_id = fcu_sourceid;
6092
 
6093
wire [4:0] fcmpo;
6094
wire fnanx;
6095
fp_cmp_unit #(64) ufcmp1 (fcu_argA, fcu_argB, fcmpo, fnanx);
6096
 
6097
wire fcu_takb;
6098
 
6099
always @*
6100
begin
6101
    fcu_exc <= `FLT_NONE;
6102
    casez(fcu_instr[`INSTRUCTION_OP])
6103
`ifdef SUPPORT_SEGMENTATION
6104
    `LDCS:  fcu_exc <= fcu_instr[31:8] != fcu_pc[63:40] ? `FLT_CS : `FLT_NONE;
6105
    `RET:               fcu_exc <= fcu_argB[63:40] != fcu_pc[63:40] ? `FLT_RET : `FLT_NONE;
6106
`endif
6107
`ifdef SUPPORT_BBMS
6108
    `LFCS:      fcu_exc <= currentCSSelector != fcu_instr[31:8] ? `FLT_CS : `FLT_NONE;
6109
    `RET:               fcu_exc <= fcu_argB[63:40] != currentCSSelector ? `FLT_RET : `FLT_NONE;
6110
`endif
6111
    `CHK:   begin
6112
                if (fcu_instr[21])
6113
                    fcu_exc <= fcu_argA >= fcu_argB && fcu_argA < fcu_argC ? `FLT_NONE : `FLT_CHK;
6114
            end
6115
    `REX:
6116
        case(olm)
6117
        `OL_USER:   fcu_exc <= `FLT_PRIV;
6118
        default:    ;
6119
        endcase
6120
   default: fcu_exc <= `FLT_NONE;
6121
        endcase
6122
end
6123
 
6124
FT64_EvalBranch ube1
6125
(
6126
        .instr(fcu_instr),
6127
        .a(fcu_argA),
6128
        .b(fcu_argB),
6129
        .c(fcu_argC),
6130
        .takb(fcu_takb)
6131
);
6132
 
6133
FT64_FCU_Calc #(.AMSB(AMSB)) ufcuc1
6134
(
6135
        .ol(olm),
6136
        .instr(fcu_instr),
6137
        .tvec(tvec[fcu_instr[14:13]]),
6138
        .a(fcu_argA),
6139
        .pc(fcu_pc),
6140
        .nextpc(fcu_nextpc),
6141
        .im(im),
6142
        .waitctr(waitctr),
6143
        .bus(fcu_out)
6144
);
6145
 
6146
wire will_clear_branchmiss = branchmiss && ((fetchbuf0_v && fetchbuf0_pc==misspc) || (fetchbuf1_v && fetchbuf1_pc==misspc));
6147
 
6148
always @*
6149
begin
6150
case(fcu_instr[`INSTRUCTION_OP])
6151
`R2:    fcu_misspc = fcu_argB;  // RTI (we don't bother fully decoding this as it's the only R2)
6152
`RET:   fcu_misspc = fcu_argB;
6153
`REX:   fcu_misspc = fcu_bus;
6154
`BRK:   fcu_misspc = {tvec[0][AMSB:8], 1'b0, olm, 5'h0};
6155
`JAL:   fcu_misspc = fcu_argA + fcu_argI;
6156
//`CHK: fcu_misspc = fcu_nextpc + fcu_argI;     // Handled as an instruction exception
6157
// Default: branch
6158
default:        fcu_misspc = fcu_takb ? {fcu_pc[31:8] + fcu_brdisp[31:8],fcu_brdisp[7:0]} : fcu_nextpc;
6159
endcase
6160
fcu_misspc[0] = 1'b0;
6161
end
6162
 
6163
// To avoid false branch mispredicts the branch isn't evaluated until the
6164
// following instruction queues. The address of the next instruction is
6165
// looked at to see if the BTB predicted correctly.
6166
 
6167
wire fcu_brk_miss = fcu_brk || fcu_rti;
6168
`ifdef FCU_ENH
6169
wire fcu_ret_miss = fcu_ret && (fcu_argB != iqentry_pc[nid]);
6170
wire fcu_jal_miss = fcu_jal && (fcu_argA + fcu_argI != iqentry_pc[nid]);
6171
wire fcu_followed = iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]];
6172
`else
6173
wire fcu_ret_miss = fcu_ret;
6174
wire fcu_jal_miss = fcu_jal;
6175
wire fcu_followed = `TRUE;
6176
`endif
6177
always @*
6178
if (fcu_v) begin
6179
        // Break and RTI switch register sets, and so are always treated as a branch miss in order to
6180
        // flush the pipeline. Hardware interrupts also stream break instructions so they need to 
6181
        // flushed from the queue so the interrupt is recognized only once.
6182
        // BRK and RTI are handled as excmiss types which are processed during the commit stage.
6183
        if (fcu_brk_miss)
6184
                fcu_branchmiss = TRUE;
6185
        else if (fcu_branch && (fcu_takb ^ fcu_pt))
6186
    fcu_branchmiss = TRUE;
6187
        else
6188
`ifdef SUPPORT_SMT
6189
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol[fcu_thrd]))
6190
`else
6191
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol))
6192
`endif
6193
                fcu_branchmiss = TRUE;
6194
        else if (fcu_ret_miss)
6195
                fcu_branchmiss = TRUE;
6196
        else if (fcu_jal_miss)
6197
    fcu_branchmiss = TRUE;
6198
        else if (fcu_instr[`INSTRUCTION_OP] == `CHK && ~fcu_takb)
6199
    fcu_branchmiss = TRUE;
6200
        else
6201
    fcu_branchmiss = FALSE;
6202
end
6203
else
6204
        fcu_branchmiss = FALSE;
6205
 
6206
FT64_RMW_alu urmwalu0 (rmw_instr, rmw_argA, rmw_argB, rmw_argC, rmw_res);
6207
 
6208
 
6209
//
6210
// additional DRAM-enqueue logic
6211
 
6212
assign dram_avail = (dram0 == `DRAMSLOT_AVAIL || dram1 == `DRAMSLOT_AVAIL || dram2 == `DRAMSLOT_AVAIL);
6213
 
6214
always @*
6215
for (n = 0; n < QENTRIES; n = n + 1)
6216
        iqentry_memopsvalid[n] <= (iqentry_mem[n] && (iqentry_store[n] ? iqentry_a2_v[n] : 1'b1) && iqentry_state[n]==IQS_AGEN);
6217
 
6218
always @*
6219
for (n = 0; n < QENTRIES; n = n + 1)
6220
        iqentry_memready[n] <= (iqentry_v[n] & iqentry_iv[n] & iqentry_memopsvalid[n] & ~iqentry_memissue[n] & ~iqentry_stomp[n]);
6221
 
6222
assign outstanding_stores = (dram0 && dram0_store) ||
6223
                            (dram1 && dram1_store) ||
6224
                            (dram2 && dram2_store);
6225
 
6226
//
6227
// additional COMMIT logic
6228
//
6229
always @*
6230
begin
6231
    commit0_v <= (iqentry_state[heads[0]] == IQS_CMT && ~|panic);
6232
    commit0_id <= {iqentry_mem[heads[0]], heads[0]};      // if a memory op, it has a DRAM-bus id
6233
    commit0_tgt <= iqentry_tgt[heads[0]];
6234
    commit0_we  <= iqentry_we[heads[0]];
6235
    commit0_bus <= iqentry_res[heads[0]];
6236
    if (`NUM_CMT > 1) begin
6237
            commit1_v <= ({iqentry_v[heads[0]],  iqentry_state[heads[0]] == IQS_CMT} != 2'b10
6238
                       && iqentry_state[heads[1]] == IQS_CMT
6239
                       && ~|panic);
6240
            commit1_id <= {iqentry_mem[heads[1]], heads[1]};
6241
            commit1_tgt <= iqentry_tgt[heads[1]];
6242
            commit1_we  <= iqentry_we[heads[1]];
6243
            commit1_bus <= iqentry_res[heads[1]];
6244
            // Need to set commit1, and commit2 valid bits for the branch predictor.
6245
            if (`NUM_CMT > 2) begin
6246
                end
6247
                else begin
6248
                        commit2_v <= ({iqentry_v[heads[0]], iqentry_state[heads[0]] == IQS_CMT} != 2'b10
6249
                                                                 && {iqentry_v[heads[1]], iqentry_state[heads[1]] == IQS_CMT} != 2'b10
6250
                                                                 && {iqentry_v[heads[2]], iqentry_br[heads[2]], iqentry_state[heads[2]] == IQS_CMT}==3'b111
6251
                               && iqentry_tgt[heads[2]][4:0]==5'd0 && ~|panic);  // watch out for dbnz and ibne
6252
                        commit2_tgt <= 12'h000;
6253
                        commit2_we <= 8'h00;
6254
                end
6255
        end
6256
        else begin
6257
                commit1_v <= ({iqentry_v[heads[0]], iqentry_state[heads[0]] == IQS_CMT} != 2'b10
6258
                                                         && {iqentry_v[heads[1]], iqentry_state[heads[1]] == IQS_CMT} == 2'b11
6259
                       && !iqentry_rfw[heads[1]] && ~|panic);   // watch out for dbnz and ibne
6260
        commit1_id <= {iqentry_mem[heads[1]], heads[1]};        // if a memory op, it has a DRAM-bus id
6261
                commit1_tgt <= 12'h000;
6262
                commit1_we <= 8'h00;
6263
                // We don't really need the bus value since nothing is being written.
6264
            commit1_bus <= iqentry_res[heads[1]];
6265
                commit2_v <= ({iqentry_v[heads[0]], iqentry_state[heads[0]] == IQS_CMT} != 2'b10
6266
                                                         && {iqentry_v[heads[1]], iqentry_state[heads[1]] == IQS_CMT} != 2'b10
6267
                                                         && {iqentry_v[heads[2]], iqentry_br[heads[2]], iqentry_state[heads[2]] == IQS_CMT}==3'b111
6268
                       && !iqentry_rfw[heads[2]] && ~|panic);   // watch out for dbnz and ibne
6269
        commit2_id <= {iqentry_mem[heads[2]], heads[2]};        // if a memory op, it has a DRAM-bus id
6270
                commit2_tgt <= 12'h000;
6271
                commit2_we <= 8'h00;
6272
            commit2_bus <= iqentry_res[heads[2]];
6273
        end
6274
end
6275
 
6276
assign int_commit = (commit0_v && iqentry_irq[heads[0]])
6277
                                                                         || (commit0_v && commit1_v && iqentry_irq[heads[1]] && `NUM_CMT > 1)
6278
                                                                         || (commit0_v && commit1_v && commit2_v && iqentry_irq[heads[2]] && `NUM_CMT > 2);
6279
 
6280
// Detect if a given register will become valid during the current cycle.
6281
// We want a signal that is active during the current clock cycle for the read
6282
// through register file, which trims a cycle off register access for every
6283
// instruction. But two different kinds of assignment statements can't be
6284
// placed under the same always block, it's a bad practice and may not work.
6285
// So a signal is created here with it's own always block.
6286
reg [AREGS-1:0] regIsValid;
6287
always @*
6288
begin
6289
        for (n = 1; n < AREGS; n = n + 1)
6290
        begin
6291
                regIsValid[n] = rf_v[n];
6292
                if (branchmiss)
6293
               if (~livetarget[n]) begin
6294
                        if (branchmiss_thrd) begin
6295
                                if (n >= 128)
6296
                                        regIsValid[n] = `VAL;
6297
                        end
6298
                        else begin
6299
                                if (n < 128)
6300
                                        regIsValid[n] = `VAL;
6301
                        end
6302
               end
6303
                if (commit0_v && n=={commit0_tgt[7:0]})
6304
                        regIsValid[n] = regIsValid[n] | ((rf_source[ {commit0_tgt[7:0]} ] == commit0_id)
6305
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit0_id[`QBITS] ]));
6306
                if (commit1_v && n=={commit1_tgt[7:0]} && `NUM_CMT > 1)
6307
                        regIsValid[n] = regIsValid[n] | ((rf_source[ {commit1_tgt[7:0]} ] == commit1_id)
6308
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit1_id[`QBITS]] && iqentry_source[ commit1_id[`QBITS] ]));
6309
                if (commit2_v && n=={commit2_tgt[7:0]} && `NUM_CMT > 2)
6310
                        regIsValid[n] = regIsValid[n] | ((rf_source[ {commit2_tgt[7:0]} ] == commit2_id)
6311
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit2_id[`QBITS]] && iqentry_source[ commit2_id[`QBITS] ]));
6312
        end
6313
        regIsValid[0] = `VAL;
6314
        regIsValid[32] = `VAL;
6315
        regIsValid[64] = `VAL;
6316
        regIsValid[96] = `VAL;
6317
`ifdef SMT
6318
        regIsValid[128] = `VAL;
6319
        regIsValid[160] = `VAL;
6320
        regIsValid[192] = `VAL;
6321
        regIsValid[224] = `VAL;
6322
`endif
6323
end
6324
 
6325
// Wait until the cycle after Ra becomes valid to give time to read
6326
// the vector element from the register file.
6327
reg rf_vra0, rf_vra1;
6328
/*always @(posedge clk)
6329
    rf_vra0 <= regIsValid[Ra0s];
6330
always @(posedge clk)
6331
    rf_vra1 <= regIsValid[Ra1s];
6332
*/
6333
// Check how many instructions can be queued. This might be fewer than the
6334
// number ready to queue from the fetch stage if queue slots aren't
6335
// available or if there are no more physical registers left for remapping.
6336
// The fetch stage needs to know how many instructions will queue so this
6337
// logic is placed here.
6338
// NOPs are filtered out and do not enter the instruction queue. The core
6339
// will stream NOPs on a cache miss and they would mess up the queue order
6340
// if there are immediate prefixes in the queue.
6341
// For the VEX instruction, the instruction can't queue until register Ra
6342
// is valid, because register Ra is used to specify the vector element to
6343
// read.
6344
wire q2open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV;
6345
wire q3open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV && iqentry_v[(tail1 + 2'd1) % QENTRIES]==`INV;
6346
always @*
6347
begin
6348
        canq1 <= FALSE;
6349
        canq2 <= FALSE;
6350
        queued1 <= FALSE;
6351
        queued2 <= FALSE;
6352
        queuedNop <= FALSE;
6353
        vqueued2 <= FALSE;
6354
        if (!branchmiss) begin
6355
      // Two available
6356
      if (fetchbuf1_v & fetchbuf0_v) begin
6357
          // Is there a pair of NOPs ? (cache miss)
6358
          if ((fetchbuf0_instr[`INSTRUCTION_OP]==`NOP) && (fetchbuf1_instr[`INSTRUCTION_OP]==`NOP))
6359
              queuedNop <= TRUE;
6360
          else begin
6361
              // If it's a predicted branch queue only the first instruction, the second
6362
              // instruction will be stomped on.
6363
              if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
6364
                  if (iqentry_v[tail0]==`INV) begin
6365
                      canq1 <= TRUE;
6366
                      queued1 <= TRUE;
6367
                  end
6368
              end
6369
              // This is where a single NOP is allowed through to simplify the code. A
6370
              // single NOP can't be a cache miss. Otherwise it would be necessary to queue
6371
              // fetchbuf1 on tail0 it would add a nightmare to the enqueue code.
6372
              // Not a branch and there are two instructions fetched, see whether or not
6373
              // both instructions can be queued.
6374
              else begin
6375
                  if (iqentry_v[tail0]==`INV) begin
6376
                      canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
6377
                      queued1 <= (
6378
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
6379
                      if (iqentry_v[tail1]==`INV) begin
6380
                          canq2 <= ((!IsVex(fetchbuf1_instr) || rf_vra1)) || !SUP_VECTOR;
6381
                          queued2 <= (
6382
                                (!IsVector(fetchbuf1_instr) && (!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
6383
                          vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
6384
                      end
6385
                  end
6386
                  // If an irq is active during a vector instruction fetch, claim the vector instruction
6387
                  // is finished queueing even though it may not be. It'll pick up where it left off after
6388
                  // the exception is processed.
6389
                  if (freezePC) begin
6390
                        if (IsVector(fetchbuf0_instr) && IsVector(fetchbuf1_instr) && vechain) begin
6391
                                queued1 <= TRUE;
6392
                                queued2 <= TRUE;
6393
                        end
6394
                        else if (IsVector(fetchbuf0_instr)) begin
6395
                                queued1 <= TRUE;
6396
                                if (vqe0 < vl-2)
6397
                                        queued2 <= TRUE;
6398
                                else
6399
                                        queued2 <= iqentry_v[tail1]==`INV;
6400
                        end
6401
                  end
6402
              end
6403
          end
6404
      end
6405
      // One available
6406
      else if (fetchbuf0_v) begin
6407
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
6408
              if (iqentry_v[tail0]==`INV) begin
6409
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
6410
                  queued1 <=
6411
                        (((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
6412
              end
6413
              if (iqentry_v[tail1]==`INV) begin
6414
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
6415
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
6416
                end
6417
                if (freezePC) begin
6418
                if (IsVector(fetchbuf0_instr)) begin
6419
                        queued1 <= TRUE;
6420
                        if (vqe0 < vl-2)
6421
                                queued2 <= iqentry_v[tail1]==`INV;
6422
                end
6423
                end
6424
          end
6425
          else
6426
              queuedNop <= TRUE;
6427
      end
6428
      else if (fetchbuf1_v) begin
6429
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
6430
              if (iqentry_v[tail0]==`INV) begin
6431
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
6432
                  queued1 <= (
6433
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
6434
              end
6435
              if (iqentry_v[tail1]==`INV) begin
6436
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
6437
                  vqueued2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2;
6438
                end
6439
                if (freezePC) begin
6440
                if (IsVector(fetchbuf1_instr)) begin
6441
                        queued1 <= TRUE;
6442
                        if (vqe1 < vl-2)
6443
                                queued2 <= iqentry_v[tail1]==`INV;
6444
                end
6445
                end
6446
          end
6447
          else
6448
              queuedNop <= TRUE;
6449
      end
6450
      //else no instructions available to queue
6451
  end
6452
  else begin
6453
    // One available
6454
    if (fetchbuf0_v && fetchbuf0_thrd != branchmiss_thrd) begin
6455
        if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
6456
            if (iqentry_v[tail0]==`INV) begin
6457
                canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
6458
                queued1 <= (
6459
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
6460
            end
6461
            if (iqentry_v[tail1]==`INV) begin
6462
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
6463
                vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
6464
                end
6465
        end
6466
        else
6467
            queuedNop <= TRUE;
6468
    end
6469
    else if (fetchbuf1_v && fetchbuf1_thrd != branchmiss_thrd) begin
6470
        if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
6471
            if (iqentry_v[tail0]==`INV) begin
6472
                canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
6473
                queued1 <= (
6474
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
6475
            end
6476
            if (iqentry_v[tail1]==`INV) begin
6477
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
6478
                vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
6479
                end
6480
        end
6481
        else
6482
            queuedNop <= TRUE;
6483
    end
6484
//      else
6485
//              queuedNop <= TRUE;
6486
  end
6487
end
6488
 
6489
//
6490
// Branchmiss seems to be sticky sometimes during simulation. For instance branch miss
6491
// and cache miss at same time. The branchmiss should clear before the core continues
6492
// so the positive edge is detected to avoid incrementing the sequnce number too many
6493
// times.
6494
wire pebm;
6495
edge_det uedbm (.rst(rst), .clk(clk), .ce(1'b1), .i(branchmiss), .pe(pebm), .ne(), .ee() );
6496
 
6497
reg [5:0] ld_time;
6498
reg [63:0] wc_time_dat;
6499
reg [63:0] wc_times;
6500
always @(posedge tm_clk_i)
6501
begin
6502
        if (|ld_time)
6503
                wc_time <= wc_time_dat;
6504
        else begin
6505
                wc_time[31:0] <= wc_time[31:0] + 32'd1;
6506
                if (wc_time[31:0] >= TM_CLKFREQ-1) begin
6507
                        wc_time[31:0] <= 32'd0;
6508
                        wc_time[63:32] <= wc_time[63:32] + 32'd1;
6509
                end
6510
        end
6511
end
6512
 
6513
wire writing_wb =
6514
                        (mem1_available && dram0==`DRAMSLOT_BUSY && dram0_store && !iqentry_stomp[dram0_id[`QBITS]] && wbptr<`WB_DEPTH-1)
6515
         || (mem2_available && dram1==`DRAMSLOT_BUSY && dram1_store && !iqentry_stomp[dram1_id[`QBITS]] && `NUM_MEM > 1 && wbptr<`WB_DEPTH-1)
6516
         || (mem3_available && dram2==`DRAMSLOT_BUSY && dram2_store && !iqentry_stomp[dram2_id[`QBITS]] && `NUM_MEM > 2 && wbptr<`WB_DEPTH-1)
6517
         ;
6518
 
6519
// Monster clock domain.
6520
// Like to move some of this to clocking under different always blocks in order
6521
// to help out the toolset's synthesis, but it ain't gonna be easy.
6522
// Simulation doesn't like it if things are under separate always blocks.
6523
// Synthesis doesn't like it if things are under the same always block.
6524
 
6525
//always @(posedge clk)
6526
//begin
6527
//      branchmiss <= excmiss|fcu_branchmiss;
6528
//    misspc <= excmiss ? excmisspc : fcu_misspc;
6529
//    missid <= excmiss ? (|iqentry_exc[heads[0]] ? heads[0] : heads[1]) : fcu_sourceid;
6530
//      branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
6531
//end
6532
wire alu0_done_pe, alu1_done_pe, pe_wait;
6533
edge_det uedalu0d (.clk(clk), .ce(1'b1), .i(alu0_done), .pe(alu0_done_pe), .ne(), .ee());
6534
edge_det uedalu1d (.clk(clk), .ce(1'b1), .i(alu1_done), .pe(alu1_done_pe), .ne(), .ee());
6535
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());
6536
 
6537
// Bus randomization to mitigate meltdown attacks
6538
wire [63:0] ralu0_bus = |alu0_exc ? {4{lfsro}} : alu0_bus;
6539
wire [63:0] ralu1_bus = |alu1_exc ? {4{lfsro}} : alu1_bus;
6540
wire [63:0] rfpu1_bus = |fpu1_exc ? {4{lfsro}} : fpu1_bus;
6541
wire [63:0] rfpu2_bus = |fpu2_exc ? {4{lfsro}} : fpu2_bus;
6542
wire [63:0] rfcu_bus = |fcu_exc ? {4{lfsro}} : fcu_bus;
6543
wire [63:0] rdramA_bus = |dramA_exc ? {4{lfsro}} : dramA_bus;
6544
wire [63:0] rdramB_bus = |dramB_exc ? {4{lfsro}} : dramB_bus;
6545
wire [63:0] rdramC_bus = |dramC_exc ? {4{lfsro}} : dramC_bus;
6546
 
6547
always @(posedge clk)
6548
if (rst) begin
6549
`ifdef SUPPORT_SMT
6550
     mstatus[0] <= 64'h4000F;    // select register set #16 for thread 0
6551
     mstatus[1] <= 64'h4800F;   // select register set #18 for thread 1
6552
     rs_stack[0] <= 64'd16;
6553
     brs_stack[0] <= 64'd16;
6554
     rs_stack[1] <= 64'd18;
6555
     brs_stack[1] <= 64'd18;
6556
`else
6557
     mstatus <= 64'h4000F;      // select register set #16 for thread 0
6558
     rs_stack <= 64'd16;
6559
     brs_stack <= 64'd16;
6560
`endif
6561
    for (n = 0; n < QENTRIES; n = n + 1) begin
6562
        iqentry_state[n] <= IQS_INVALID;
6563
       iqentry_iv[n] <= `INV;
6564
       iqentry_is[n] <= 3'b00;
6565
       iqentry_sn[n] <= 4'd0;
6566
       iqentry_pt[n] <= FALSE;
6567
       iqentry_bt[n] <= FALSE;
6568
       iqentry_br[n] <= FALSE;
6569
       iqentry_aq[n] <= FALSE;
6570
       iqentry_rl[n] <= FALSE;
6571
       iqentry_alu0[n] <= FALSE;
6572
       iqentry_alu[n] <= FALSE;
6573
       iqentry_fpu[n] <= FALSE;
6574
       iqentry_fsync[n] <= FALSE;
6575
       iqentry_fc[n] <= FALSE;
6576
       iqentry_takb[n] <= FALSE;
6577
       iqentry_jmp[n] <= FALSE;
6578
       iqentry_jal[n] <= FALSE;
6579
       iqentry_ret[n] <= FALSE;
6580
       iqentry_brk[n] <= FALSE;
6581
       iqentry_irq[n] <= FALSE;
6582
       iqentry_rti[n] <= FALSE;
6583
       iqentry_ldcmp[n] <= FALSE;
6584
       iqentry_load[n] <= FALSE;
6585
       iqentry_rtop[n] <= FALSE;
6586
       iqentry_sei[n] <= FALSE;
6587
       iqentry_shft[n] <= FALSE;
6588
       iqentry_sync[n] <= FALSE;
6589
       iqentry_ven[n] <= 6'd0;
6590
       iqentry_vl[n] <= 8'd0;
6591
       iqentry_we[n] <= 8'h00;
6592
       iqentry_rfw[n] <= FALSE;
6593
       iqentry_rmw[n] <= FALSE;
6594
       iqentry_pc[n] <= RSTPC;
6595
         iqentry_instr[n] <= `NOP_INSN;
6596
         iqentry_insln[n] <= 3'd4;
6597
         iqentry_preload[n] <= FALSE;
6598
         iqentry_mem[n] <= FALSE;
6599
         iqentry_memndx[n] <= FALSE;
6600
       iqentry_memissue[n] <= FALSE;
6601
       iqentry_mem_islot[n] <= 3'd0;
6602
       iqentry_memdb[n] <= FALSE;
6603
       iqentry_memsb[n] <= FALSE;
6604
       iqentry_tgt[n] <= 6'd0;
6605
       iqentry_imm[n] <= 1'b0;
6606
       iqentry_ma[n] <= 1'b0;
6607
       iqentry_a0[n] <= 64'd0;
6608
       iqentry_a1[n] <= 64'd0;
6609
       iqentry_a2[n] <= 64'd0;
6610
       iqentry_a3[n] <= 64'd0;
6611
       iqentry_a1_v[n] <= `INV;
6612
       iqentry_a2_v[n] <= `INV;
6613
       iqentry_a3_v[n] <= `INV;
6614
       iqentry_a1_s[n] <= 5'd0;
6615
       iqentry_a2_s[n] <= 5'd0;
6616
       iqentry_a3_s[n] <= 5'd0;
6617
`ifdef SUPPORT_PREDICATION
6618
       iqentry_aT[n] <= 64'd0;
6619
       iqentry_aT_s[n] <= 1'd0;
6620
`endif
6621
       iqentry_canex[n] <= FALSE;
6622
    end
6623
     bwhich <= 2'b00;
6624
     dram0 <= `DRAMSLOT_AVAIL;
6625
     dram1 <= `DRAMSLOT_AVAIL;
6626
     dram2 <= `DRAMSLOT_AVAIL;
6627
     dram0_instr <= `NOP_INSN;
6628
     dram1_instr <= `NOP_INSN;
6629
     dram2_instr <= `NOP_INSN;
6630
     dram0_addr <= 32'h0;
6631
     dram1_addr <= 32'h0;
6632
     dram2_addr <= 32'h0;
6633
     dram0_id <= 1'b0;
6634
     dram1_id <= 1'b0;
6635
     dram2_id <= 1'b0;
6636
     L1_adr <= RSTPC;
6637
     invic <= FALSE;
6638
     tail0 <= 3'd0;
6639
     tail1 <= 3'd1;
6640
     for (n = 0; n < QENTRIES; n = n + 1)
6641
        heads[n] <= n;
6642
     panic = `PANIC_NONE;
6643
     alu0_dataready <= 1'b0;
6644
     alu1_dataready <= 1'b0;
6645
     alu0_sourceid <= 5'd0;
6646
     alu1_sourceid <= 5'd0;
6647
`define SIM_
6648
`ifdef SIM_
6649
                alu0_pc <= RSTPC;
6650
                alu0_instr <= `NOP_INSN;
6651
                alu0_argA <= 64'h0;
6652
                alu0_argB <= 64'h0;
6653
                alu0_argC <= 64'h0;
6654
                alu0_argI <= 64'h0;
6655
                alu0_mem <= 1'b0;
6656
                alu0_shft <= 1'b0;
6657
                alu0_thrd <= 1'b0;
6658
                alu0_tgt <= 6'h00;
6659
                alu0_ven <= 6'd0;
6660
                alu1_pc <= RSTPC;
6661
                alu1_instr <= `NOP_INSN;
6662
                alu1_argA <= 64'h0;
6663
                alu1_argB <= 64'h0;
6664
                alu1_argC <= 64'h0;
6665
                alu1_argI <= 64'h0;
6666
                alu1_mem <= 1'b0;
6667
                alu1_shft <= 1'b0;
6668
                alu1_thrd <= 1'b0;
6669
                alu1_tgt <= 6'h00;
6670
                alu1_ven <= 6'd0;
6671
`endif
6672
     fcu_dataready <= 0;
6673
     fcu_instr <= `NOP_INSN;
6674
     dramA_v <= 0;
6675
     dramB_v <= 0;
6676
     dramC_v <= 0;
6677
     I <= 0;
6678
     CC <= 0;
6679
     icstate <= IDLE;
6680
     bstate <= BIDLE;
6681
     tick <= 64'd0;
6682
     ol_o <= 2'b0;
6683
     bte_o <= 2'b00;
6684
     cti_o <= 3'b000;
6685
     cyc <= `LOW;
6686
     stb_o <= `LOW;
6687
     we <= `LOW;
6688
     sel_o <= 8'h00;
6689
     dat_o <= 64'hFFFFFFFFFFFFFFFF;
6690
     sr_o <= `LOW;
6691
     cr_o <= `LOW;
6692
     vadr <= RSTPC;
6693
     icl_o <= `LOW;             // instruction cache load
6694
     cr0 <= 64'd0;
6695
     cr0[13:8] <= 6'd0;         // select compressed instruction group #0
6696
     cr0[30] <= TRUE;           // enable data caching
6697
     cr0[32] <= TRUE;           // enable branch predictor
6698
     cr0[16] <= 1'b0;           // disable SMT
6699
     cr0[17] <= 1'b0;           // sequence number reset = 1
6700
     cr0[34] <= FALSE;  // write buffer merging enable
6701
     cr0[35] <= TRUE;           // load speculation enable
6702
     pcr <= 32'd0;
6703
     pcr2 <= 64'd0;
6704
    for (n = 0; n < PREGS; n = n + 1) begin
6705
      rf_v[n] <= `VAL;
6706
      rf_source[n] <= {`QBIT{1'b1}};
6707
    end
6708
     fp_rm <= 3'd0;                     // round nearest even - default rounding mode
6709
     fpu_csr[37:32] <= 5'd31;   // register set #31
6710
     waitctr <= 48'd0;
6711
    for (n = 0; n < 16; n = n + 1) begin
6712
      badaddr[n] <= 64'd0;
6713
      bad_instr[n] <= `NOP_INSN;
6714
    end
6715
    // Vector
6716
     vqe0 <= 6'd0;
6717
     vqet0 <= 6'd0;
6718
     vqe1 <= 6'd0;
6719
     vqet1 <= 6'd0;
6720
     vl <= 7'd62;
6721
    for (n = 0; n < 8; n = n + 1)
6722
         vm[n] <= 64'h7FFFFFFFFFFFFFFF;
6723
     nop_fetchbuf <= 4'h0;
6724
     fcu_done <= `TRUE;
6725
     sema <= 64'h0;
6726
     tvec[0] <= RSTPC;
6727
     pmr <= 64'hFFFFFFFFFFFFFFFF;
6728
     pmr[0] <= `ID1_AVAIL;
6729
     pmr[1] <= `ID2_AVAIL;
6730
     pmr[2] <= `ID3_AVAIL;
6731
     pmr[8] <= `ALU0_AVAIL;
6732
     pmr[9] <= `ALU1_AVAIL;
6733
     pmr[16] <= `FPU1_AVAIL;
6734
     pmr[17] <= `FPU2_AVAIL;
6735
     pmr[24] <= `MEM1_AVAIL;
6736
     pmr[25] <= `MEM2_AVAIL;
6737
                 pmr[26] <= `MEM3_AVAIL;
6738
     pmr[32] <= `FCU_AVAIL;
6739
     for (n = 0; n < `WB_DEPTH; n = n + 1) begin
6740
        wb_v[n] <= 1'b0;
6741
        wb_rmw[n] <= 1'b0;
6742
        wb_id[n] <= {QENTRIES{1'b0}};
6743
        wb_ol[n] <= 2'b00;
6744
        wb_sel[n] <= 8'h00;
6745
        wb_addr[n] <= 32'd0;
6746
        wb_data[n] <= 64'd0;
6747
     end
6748
     wb_en <= `TRUE;
6749
     wbo_id <= {QENTRIES{1'b0}};
6750
     wbptr <= 2'd0;
6751
`ifdef SIM
6752
                wb_merges <= 32'd0;
6753
`endif
6754
                iq_ctr <= 40'd0;
6755
                icl_ctr <= 40'd0;
6756
                bm_ctr <= 40'd0;
6757
                irq_ctr <= 40'd0;
6758
                cmt_timer <= 9'd0;
6759
                StoreAck1 <= `FALSE;
6760
                keys <= 64'h0;
6761
`ifdef SUPPORT_DBG
6762
                dbg_ctrl <= 64'h0;
6763
`endif
6764
/* Initialized with initial begin above
6765
`ifdef SUPPORT_BBMS
6766
                for (n = 0; n < 64; n = n + 1) begin
6767
                        thrd_handle[n] <= 16'h0;
6768
                        prg_base[n] <= 64'h0;
6769
                        cl_barrier[n] <= 64'h0;
6770
                        cu_barrier[n] <= 64'hFFFFFFFFFFFFFFFF;
6771
                        ro_barrier[n] <= 64'h0;
6772
                        dl_barrier[n] <= 64'h0;
6773
                        du_barrier[n] <= 64'hFFFFFFFFFFFFFFFF;
6774
                        sl_barrier[n] <= 64'h0;
6775
                        su_barrier[n] <= 64'hFFFFFFFFFFFFFFFF;
6776
                end
6777
`endif
6778
*/
6779
end
6780
else begin
6781
        if (|fb_panic)
6782
                panic <= fb_panic;
6783
 
6784
        // Only one branchmiss is allowed to be processed at a time. If a second 
6785
        // branchmiss occurs while the first is being processed, it would have
6786
        // to of occurred as a speculation in the branch shadow of the first.
6787
        // The second instruction would be stomped on by the first branchmiss so
6788
        // there is no need to process it.
6789
        // The branchmiss has to be latched, then cleared later as there could
6790
        // be a cache miss at the same time meaning the switch to the new pc
6791
        // does not take place immediately.
6792
        if (!branchmiss) begin
6793
                if (excmiss) begin
6794
                        branchmiss <= `TRUE;
6795
                        misspc <= excmisspc;
6796
                        missid <= (|iqentry_exc[heads[0]] ? heads[0] : heads[1]);
6797
                        branchmiss_thrd <= excthrd;
6798
                end
6799
                else if (fcu_branchmiss) begin
6800
                        branchmiss <= `TRUE;
6801
                        misspc <= fcu_misspc;
6802
                        missid <= fcu_sourceid;
6803
                        branchmiss_thrd <= fcu_thrd;
6804
                end
6805
        end
6806
        // Clear a branch miss when target instruction is fetched.
6807
        if (will_clear_branchmiss) begin
6808
                branchmiss <= `FALSE;
6809
        end
6810
 
6811
        // The following signals only pulse
6812
 
6813
        // Instruction decode output should only pulse once for a queue entry. We
6814
        // want the decode to be invalidated after a clock cycle so that it isn't
6815
        // inadvertently used to update the queue at a later point.
6816
        dramA_v <= `INV;
6817
        dramB_v <= `INV;
6818
        dramC_v <= `INV;
6819
        id1_vi <= `INV;
6820
        if (`NUM_IDU > 1)
6821
                id2_vi <= `INV;
6822
        if (`NUM_IDU > 2)
6823
                id3_vi <= `INV;
6824
        wb_shift <= FALSE;
6825
        ld_time <= {ld_time[4:0],1'b0};
6826
        wc_times <= wc_time;
6827
     rf_vra0 <= regIsValid[Ra0s];
6828
     rf_vra1 <= regIsValid[Ra1s];
6829
    if (vqe0 >= vl) begin
6830
         vqe0 <= 6'd0;
6831
         vqet0 <= 6'h0;
6832
    end
6833
    if (vqe1 >= vl) begin
6834
         vqe1 <= 6'd0;
6835
         vqet1 <= 6'h0;
6836
    end
6837
    // Turn off vector chaining indicator when chained instructions are done.
6838
    if ((vqe0 >= vl || vqe0==6'd0) && (vqe1 >= vl || vqe1==6'd0))
6839
`ifdef SUPPORT_SMT
6840
        mstatus[0][32] <= 1'b0;
6841
`else
6842
        mstatus[32] <= 1'b0;
6843
`endif
6844
 
6845
     nop_fetchbuf <= 4'h0;
6846
     excmiss <= FALSE;
6847
     invic <= FALSE;
6848
     tick <= tick + 64'd1;
6849
     alu0_ld <= FALSE;
6850
     alu1_ld <= FALSE;
6851
     fpu1_ld <= FALSE;
6852
     fpu2_ld <= FALSE;
6853
     fcu_ld <= FALSE;
6854
     cr0[17] <= 1'b0;
6855
    if (waitctr != 48'd0)
6856
         waitctr <= waitctr - 4'd1;
6857
 
6858
 
6859
    if (iqentry_fc[fcu_id[`QBITS]] && iqentry_v[fcu_id[`QBITS]] && !iqentry_done[fcu_id[`QBITS]] && iqentry_out[fcu_id[`QBITS]])
6860
        fcu_timeout <= fcu_timeout + 8'd1;
6861
 
6862
        if (branchmiss) begin
6863
        for (n = 1; n < PREGS; n = n + 1)
6864
           if (~livetarget[n]) begin
6865
                        if (branchmiss_thrd) begin
6866
                                if (n >= 128)
6867
                                rf_v[n] <= `VAL;
6868
                        end
6869
                        else begin
6870
                                if (n < 128)
6871
                                rf_v[n] <= `VAL;
6872
                end
6873
           end
6874
                        for (n = 0; n < QENTRIES; n = n + 1)
6875
                if (|iqentry_latestID[n])
6876
                        if (iqentry_thrd[n]==branchmiss_thrd) rf_source[ {iqentry_tgt[n][7:0]} ] <= { 1'b0, iqentry_mem[n], n[`QBITS] };
6877
    end
6878
 
6879
    // The source for the register file data might have changed since it was
6880
    // placed on the commit bus. So it's needed to check that the source is
6881
    // still as expected to validate the register.
6882
                if (commit0_v) begin
6883
      if (!rf_v[ {commit0_tgt[7:0]} ]) begin
6884
//         rf_v[ {commit0_tgt[7:0]} ] <= rf_source[ commit0_tgt[7:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]);
6885
        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] ]);
6886
        if (regIsValid[{commit0_tgt[7:0]}])
6887
                rf_source[{commit0_tgt[7:0]}] <= {`QBIT{1'b1}};
6888
      end
6889
      if (commit0_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit0_tgt, commit0_bus, regIsValid[commit0_tgt[5:0]],
6890
      rf_source[ {commit0_tgt[7:0]} ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]));
6891
      if (commit0_tgt[5:0]==6'd30 && commit0_bus==64'd0)
6892
        $display("FP <= 0");
6893
    end
6894
    if (commit1_v && `NUM_CMT > 1) begin
6895
      if (!rf_v[ {commit1_tgt[7:0]} ]) begin
6896
        if ({commit1_tgt[7:0]}=={commit0_tgt[7:0]}) begin
6897
                rf_v[ {commit1_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}];
6898
                if (regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}])
6899
                rf_source[{commit1_tgt[7:0]}] <= {`QBIT{1'b1}};
6900
                /*
6901
                        (rf_source[ commit0_tgt[4:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ])) ||
6902
                        (rf_source[ commit1_tgt[4:0] ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6903
                */
6904
        end
6905
        else begin
6906
                                        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] ]);
6907
          if (regIsValid[{commit1_tgt[7:0]}])
6908
                rf_source[{commit1_tgt[7:0]}] <= {`QBIT{1'b1}};
6909
        end
6910
      end
6911
      if (commit1_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit1_tgt, commit1_bus, regIsValid[commit1_tgt[5:0]],
6912
      rf_source[ {commit1_tgt[7:0]} ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6913
      if (commit1_tgt[5:0]==6'd30 && commit1_bus==64'd0)
6914
        $display("FP <= 0");
6915
    end
6916
    if (commit2_v && `NUM_CMT > 2) begin
6917
      if (!rf_v[ {commit2_tgt[7:0]} ]) begin
6918
        if ({commit2_tgt[7:0]}=={commit1_tgt[7:0]} && {commit2_tgt[7:0]}=={commit0_tgt[7:0]}) begin
6919
                rf_v[ {commit2_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}];
6920
                if (regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}])
6921
                rf_source[{commit0_tgt[7:0]}] <= {`QBIT{1'b1}};
6922
        end
6923
        else if ({commit2_tgt[7:0]}=={commit0_tgt[7:0]}) begin
6924
                rf_v[ {commit2_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}];
6925
                if (regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}])
6926
                rf_source[{commit0_tgt[7:0]}] <= {`QBIT{1'b1}};
6927
        end
6928
        else if ({commit2_tgt[7:0]}=={commit1_tgt[7:0]}) begin
6929
                rf_v[ {commit2_tgt[7:0]} ] <= regIsValid[{commit1_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}];
6930
                if (regIsValid[{commit1_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}])
6931
                rf_source[{commit1_tgt[7:0]}] <= {`QBIT{1'b1}};
6932
        end
6933
        else begin
6934
                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] ]);
6935
                if (regIsValid[{commit2_tgt[7:0]}])
6936
                rf_source[{commit2_tgt[7:0]}] <= {`QBIT{1'b1}};
6937
        end
6938
      end
6939
      if (commit2_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit2_tgt, commit2_bus, regIsValid[commit2_tgt[5:0]],
6940
      rf_source[ {commit2_tgt[7:0]} ] == commit2_id || (branchmiss && iqentry_source[ commit2_id[`QBITS] ]));
6941
      if (commit2_tgt[5:0]==6'd30 && commit2_bus==64'd0)
6942
        $display("FP <= 0");
6943
    end
6944
     rf_v[0] <= 1;
6945
 
6946
  //
6947
  // ENQUEUE
6948
  //
6949
  // place up to two instructions from the fetch buffer into slots in the IQ.
6950
  //   note: they are placed in-order, and they are expected to be executed
6951
  // 0, 1, or 2 of the fetch buffers may have valid data
6952
  // 0, 1, or 2 slots in the instruction queue may be available.
6953
  // if we notice that one of the instructions in the fetch buffer is a predicted branch,
6954
  // (set branchback/backpc and delete any instructions after it in fetchbuf)
6955
  //
6956
 
6957
        // enqueue fetchbuf0 and fetchbuf1, but only if there is room, 
6958
        // and ignore fetchbuf1 if fetchbuf0 has a backwards branch in it.
6959
        //
6960
        // also, do some instruction-decode ... set the operand_valid bits in the IQ
6961
        // appropriately so that the DATAINCOMING stage does not have to look at the opcode
6962
        //
6963
        if (!branchmiss)        // don't bother doing anything if there's been a branch miss
6964
 
6965
                case ({fetchbuf0_v, fetchbuf1_v})
6966
 
6967
            2'b00: ; // do nothing
6968
 
6969
            2'b01:
6970
                    if (canq1) begin
6971
                                        if (fetchbuf1_rfw) begin
6972
                                                rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_mem, tail0 };    // top bit indicates ALU/MEM bus
6973
                                                rf_v [Rt1s] <= `INV;
6974
                                        end
6975
                                        if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6976
                                                vqe1 <= vqe1 + 4'd1;
6977
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6978
                                                        if (vm[fetchbuf1_instr[25:23]][vqe1])
6979
                                                                vqet1 <= vqet1 + 4'd1;
6980
                                                end
6981
                                                else
6982
                                                        vqet1 <= vqet1 + 4'd1;
6983
                                                if (vqe1 >= vl-2)
6984
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6985
                                                enque1(tail0, fetchbuf1_thrd ? maxsn[1]+4'd1 : maxsn[0]+4'd1, vqe1);
6986
                                                iq_ctr = iq_ctr + 4'd1;
6987
                                                if (canq2 && vqe1 < vl-2) begin
6988
                                                        vqe1 <= vqe1 + 4'd2;
6989
                                                        if (IsVCmprss(fetchbuf1_instr)) begin
6990
                                                                if (vm[fetchbuf1_instr[25:23]][vqe1+6'd1])
6991
                                                                        vqet1 <= vqet1 + 4'd2;
6992
                                                        end
6993
                                                        else
6994
                                                                vqet1 <= vqet1 + 4'd2;
6995
                                                        enque1(tail1, fetchbuf1_thrd ? maxsn[1] + 4'd2 : maxsn[0] + 4'd2, vqe1 + 6'd1);
6996
                                                        iq_ctr = iq_ctr + 4'd2;
6997
                                                end
6998
                                        end
6999
                                        else begin
7000
                                                enque1(tail0, fetchbuf1_thrd ? maxsn[1]+4'd1 : maxsn[0]+4'd1, 6'd0);
7001
                                                iq_ctr = iq_ctr + 4'd1;
7002
                                        end
7003
                    end
7004
 
7005
            2'b10:
7006
                if (canq1) begin
7007
                        enque0x();
7008
                    end
7009
 
7010
            2'b11:
7011
                    if (canq1) begin
7012
                                //
7013
                                // if the first instruction is a predicted branch, enqueue it & stomp on all following instructions
7014
                                // but only if the following instruction is in the same thread. Otherwise we want to queue two.
7015
                                //
7016
                                if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
7017
                                        enque0x();
7018
                                end
7019
 
7020
                                else begin      // fetchbuf0 doesn't contain a predicted branch
7021
                                    //
7022
                                    // so -- we can enqueue 1 or 2 instructions, depending on space in the IQ
7023
                                    // update the rf_v and rf_source bits separately (at end)
7024
                                    //   the problem is that if we do have two instructions, 
7025
                                    //   they may interact with each other, so we have to be
7026
                                    //   careful about where things point.
7027
                                    //
7028
                                    // enqueue the first instruction ...
7029
                                    //
7030
                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
7031
                                 vqe0 <= vqe0 + 4'd1;
7032
                                if (IsVCmprss(fetchbuf0_instr)) begin
7033
                                    if (vm[fetchbuf0_instr[25:23]][vqe0])
7034
                                         vqet0 <= vqet0 + 4'd1;
7035
                                end
7036
                                else
7037
                                     vqet0 <= vqet0 + 4'd1;
7038
                                if (vqe0 >= vl-2)
7039
                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
7040
                            end
7041
                            if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
7042
                                    enque0(tail0, fetchbuf0_thrd ? maxsn[1]+4'd1 : maxsn[0]+4'd1, vqe0);
7043
                                                                        iq_ctr = iq_ctr + 4'd1;
7044
                                            //
7045
                                            // if there is room for a second instruction, enqueue it
7046
                                            //
7047
                                            if (canq2) begin
7048
                                                if (vechain && IsVector(fetchbuf1_instr)
7049
                                                && Ra1s != Rt0s // And there is no dependency
7050
                                                && Rb1s != Rt0s
7051
                                                && Rc1s != Rt0s
7052
                                                ) begin
7053
`ifdef SUPPORT_SMT
7054
                                                        mstatus[0][32] <= 1'b1;
7055
`else
7056
                                                        mstatus[32] <= 1'b1;
7057
`endif
7058
                                                vqe1 <= vqe1 + 4'd1;
7059
                                                if (IsVCmprss(fetchbuf1_instr)) begin
7060
                                                    if (vm[fetchbuf1_instr[25:23]][vqe1])
7061
                                                         vqet1 <= vqet1 + 4'd1;
7062
                                                end
7063
                                                else
7064
                                                     vqet1 <= vqet1 + 4'd1;
7065
                                                if (vqe1 >= vl-2)
7066
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
7067
                                                        enque1(tail1,
7068
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? maxsn[1] + 4'd2 :
7069
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? maxsn[0] + 4'd2 :
7070
                                                                fetchbuf1_thrd ? maxsn[1] + 4'd2: maxsn[0] + 4'd2, 6'd0);
7071
                                                                                iq_ctr = iq_ctr + 4'd2;
7072
 
7073
                                                                // SOURCE 1 ...
7074
                                                                a1_vs();
7075
 
7076
                                                                // SOURCE 2 ...
7077
                                                                a2_vs();
7078
 
7079
                                                                // SOURCE 3 ...
7080
                                                                a3_vs();
7081
 
7082
                                                                // if the two instructions enqueued target the same register, 
7083
                                                                // make sure only the second writes to rf_v and rf_source.
7084
                                                                // first is allowed to update rf_v and rf_source only if the
7085
                                                                // second has no target
7086
                                                                //
7087
                                                            if (fetchbuf0_rfw) begin
7088
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_mem, tail0 };
7089
                                                                     rf_v [ Rt0s] <= `INV;
7090
                                                            end
7091
                                                            if (fetchbuf1_rfw) begin
7092
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_mem, tail1 };
7093
                                                                     rf_v [ Rt1s ] <= `INV;
7094
                                                            end
7095
                                                end
7096
                                                // If there was a vector instruction in fetchbuf0, we really
7097
                                                // want to queue the next vector element, not the next
7098
                                                // instruction waiting in fetchbuf1.
7099
                                            else if (IsVector(fetchbuf0_instr) && SUP_VECTOR && vqe0 < vl-1) begin
7100
                                                 vqe0 <= vqe0 + 4'd2;
7101
                                                if (IsVCmprss(fetchbuf0_instr)) begin
7102
                                                    if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
7103
                                                         vqet0 <= vqet0 + 4'd2;
7104
                                                end
7105
                                                else
7106
                                                     vqet0 <= vqet0 + 4'd2;
7107
                                                if (vqe0 >= vl-3)
7108
                                                 nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
7109
                                            if (vqe0 < vl-1) begin
7110
                                                                enque0(tail1, fetchbuf0_thrd ? maxsn[1] + 4'd2 : maxsn[0] + 4'd2, vqe0 + 6'd1);
7111
                                                                                        iq_ctr = iq_ctr + 4'd2;
7112
 
7113
                                                                        // SOURCE 1 ...
7114
                                                     iqentry_a1_v [tail1] <= regIsValid[Ra0s];
7115
                                                     iqentry_a1_s [tail1] <= rf_source [Ra0s];
7116
 
7117
                                                                        // SOURCE 2 ...
7118
                                                     iqentry_a2_v [tail1] <= regIsValid[Rb0s];
7119
                                                     iqentry_a2_s [tail1] <= rf_source[ Rb0s ];
7120
 
7121
                                                                        // SOURCE 3 ...
7122
                                                     iqentry_a3_v [tail1] <= regIsValid[Rc0s];
7123
                                                     iqentry_a3_s [tail1] <= rf_source[ Rc0s ];
7124
 
7125
 
7126
                                                                        // if the two instructions enqueued target the same register, 
7127
                                                                        // make sure only the second writes to rf_v and rf_source.
7128
                                                                        // first is allowed to update rf_v and rf_source only if the
7129
                                                                        // second has no target (BEQ or SW)
7130
                                                                        //
7131
                                                                    if (fetchbuf0_rfw) begin
7132
                                                                             rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_mem, tail1 };
7133
                                                                             rf_v [ Rt0s ] <= `INV;
7134
                                                                    end
7135
                                                                end
7136
                                                end
7137
                                            else if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
7138
                                                 vqe1 <= 6'd1;
7139
                                                if (IsVCmprss(fetchbuf1_instr)) begin
7140
                                                    if (vm[fetchbuf1_instr[25:23]][IsVector(fetchbuf0_instr)? 6'd0:vqe1+6'd1])
7141
                                                         vqet1 <= 6'd1;
7142
                                                else
7143
                                                         vqet1 <= 6'd0;
7144
                                                end
7145
                                                else
7146
                                                         vqet1 <= 6'd1;
7147
                                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR)
7148
                                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
7149
                                                        enque1(tail1,
7150
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? maxsn[1] + 4'd2 :
7151
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? maxsn[0] + 4'd2 :
7152
                                                                fetchbuf1_thrd ? maxsn[1] + 4'd2: maxsn[0] + 4'd2, 6'd0);
7153
                                                                                iq_ctr = iq_ctr + 4'd2;
7154
 
7155
                                                                // SOURCE 1 ...
7156
                                                                a1_vs();
7157
 
7158
                                                                // SOURCE 2 ..
7159
                                                                a2_vs();
7160
 
7161
                                                                // SOURCE 3 ...
7162
                                                                a3_vs();
7163
 
7164
                                                                // if the two instructions enqueued target the same register, 
7165
                                                                // make sure only the second writes to rf_v and rf_source.
7166
                                                                // first is allowed to update rf_v and rf_source only if the
7167
                                                                // second has no target
7168
                                                                //
7169
                                                            if (fetchbuf0_rfw) begin
7170
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_mem, tail0 };
7171
                                                                     rf_v [ Rt0s] <= `INV;
7172
                                                            end
7173
                                                            if (fetchbuf1_rfw) begin
7174
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_mem, tail1 };
7175
                                                                     rf_v [ Rt1s ] <= `INV;
7176
                                                            end
7177
                                            end
7178
                                            else begin
7179
//                                                      enque1(tail1, seq_num + 5'd1, 6'd0);
7180
                                                        enque1(tail1,
7181
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? maxsn[1] + 4'd2 :
7182
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? maxsn[0] + 4'd2 :
7183
                                                                fetchbuf1_thrd ? maxsn[1] + 4'd1: maxsn[0]+4'd1, 6'd0);
7184
                                                                                iq_ctr = iq_ctr + 4'd2;
7185
 
7186
                                                                // SOURCE 1 ...
7187
                                                                a1_vs();
7188
 
7189
                                                                // SOURCE 2 ...
7190
                                                                a2_vs();
7191
 
7192
                                                                // SOURCE 3 ...
7193
                                                                a3_vs();
7194
 
7195
 
7196
                                                                // if the two instructions enqueued target the same register, 
7197
                                                                // make sure only the second writes to regIsValid and rf_source.
7198
                                                                // first is allowed to update regIsValid and rf_source only if the
7199
                                                                // second has no target (BEQ or SW)
7200
                                                                //
7201
                                                            if (fetchbuf0_rfw) begin
7202
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_mem, tail0 };
7203
                                                                     rf_v [ Rt0s] <= `INV;
7204
                                                                     $display("r%dx (%d) Invalidated", Rt0s, Rt0s[4:0]);
7205
                                                            end
7206
                                                            else
7207
                                                                $display("No rfw");
7208
                                                            if (fetchbuf1_rfw) begin
7209
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_mem, tail1 };
7210
                                                                     $display("r%dx (%d) Invalidated", Rt1s, Rt1s[4:0]);
7211
                                                                     rf_v [ Rt1s ] <= `INV;
7212
                                                            end
7213
                                                            else
7214
                                                                $display("No rfw");
7215
                                                        end
7216
 
7217
                                            end // ends the "if IQ[tail1] is available" clause
7218
                                            else begin  // only first instruction was enqueued
7219
                                                        if (fetchbuf0_rfw) begin
7220
                                                             $display("r%dx (%d) Invalidated 1", Rt0s, Rt0s[4:0]);
7221
                                                             rf_source[ Rt0s ] <= {1'b0,fetchbuf0_mem, tail0};
7222
                                                             rf_v [ Rt0s ] <= `INV;
7223
                                                        end
7224
                                                end
7225
                                    end
7226
 
7227
                                end     // ends the "else fetchbuf0 doesn't have a backwards branch" clause
7228
                    end
7229
                endcase
7230
        if (pebm) begin
7231
                bm_ctr <= bm_ctr + 40'd1;
7232
        end
7233
 
7234
//
7235
// DATAINCOMING
7236
//
7237
// wait for operand/s to appear on alu busses and puts them into 
7238
// the iqentry_a1 and iqentry_a2 slots (if appropriate)
7239
// as well as the appropriate iqentry_res slots (and setting valid bits)
7240
//
7241
// put results into the appropriate instruction entries
7242
//
7243
// This chunk of code has to be before the enqueue stage so that the agen bit
7244
// can be reset to zero by enqueue.
7245
// put results into the appropriate instruction entries
7246
//
7247
if (IsMul(alu0_instr)|IsDivmod(alu0_instr)|alu0_shft|alu0_tlb) begin
7248
        if (alu0_done_pe) begin
7249
                alu0_dataready <= TRUE;
7250
        end
7251
end
7252
if (alu1_shft) begin
7253
        if (alu1_done_pe) begin
7254
                alu1_dataready <= TRUE;
7255
        end
7256
end
7257
 
7258
if (alu0_v) begin
7259
        iqentry_tgt [ alu0_id[`QBITS] ] <= alu0_tgt;
7260
        iqentry_res     [ alu0_id[`QBITS] ] <= ralu0_bus;
7261
        iqentry_exc     [ alu0_id[`QBITS] ] <= alu0_exc;
7262
        if (!iqentry_mem[ alu0_id[`QBITS] ] && alu0_done) begin
7263
//              iqentry_done[ alu0_id[`QBITS] ] <= `TRUE;
7264
                iqentry_state[alu0_id[`QBITS]] <= IQS_CMT;
7265
        end
7266
//      if (alu0_done)
7267
//              iqentry_cmt [ alu0_id[`QBITS] ] <= `TRUE;
7268
//      iqentry_out     [ alu0_id[`QBITS] ] <= `INV;
7269
//      iqentry_agen[ alu0_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
7270
        if (iqentry_mem[alu0_id[`QBITS]])
7271
                iqentry_state[alu0_id[`QBITS]] <= IQS_AGEN;
7272
        if (iqentry_mem[ alu0_id[`QBITS] ] && !iqentry_agen[ alu0_id[`QBITS] ]) begin
7273
                iqentry_ma[ alu0_id[`QBITS] ] <= alu0_bus;
7274
        end
7275
        if (|alu0_exc) begin
7276
//              iqentry_done[alu0_id[`QBITS]] <= `VAL;
7277
                iqentry_store[alu0_id[`QBITS]] <= `INV;
7278
                iqentry_state[alu0_id[`QBITS]] <= IQS_CMT;
7279
        end
7280
        alu0_dataready <= FALSE;
7281
end
7282
 
7283
if (alu1_v && `NUM_ALU > 1) begin
7284
        iqentry_tgt [ alu1_id[`QBITS] ] <= alu1_tgt;
7285
        iqentry_res     [ alu1_id[`QBITS] ] <= ralu1_bus;
7286
        iqentry_exc     [ alu1_id[`QBITS] ] <= alu1_exc;
7287
        if (!iqentry_mem[ alu1_id[`QBITS] ] && alu1_done) begin
7288
//              iqentry_done[ alu1_id[`QBITS] ] <= `TRUE;
7289
                iqentry_state[alu1_id[`QBITS]] <= IQS_CMT;
7290
        end
7291
//      iqentry_done[ alu1_id[`QBITS] ] <= (!iqentry_mem[ alu1_id[`QBITS] ] && alu1_done);
7292
//      if (alu1_done)
7293
//              iqentry_cmt [ alu1_id[`QBITS] ] <= `TRUE;
7294
//      iqentry_out     [ alu1_id[`QBITS] ] <= `INV;
7295
        if (iqentry_mem[alu1_id[`QBITS]])
7296
                iqentry_state[alu1_id[`QBITS]] <= IQS_AGEN;
7297
//      iqentry_agen[ alu1_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
7298
        if (iqentry_mem[ alu1_id[`QBITS] ] && !iqentry_agen[ alu1_id[`QBITS] ]) begin
7299
                iqentry_ma[ alu1_id[`QBITS] ] <= alu1_bus;
7300
        end
7301
        if (|alu1_exc) begin
7302
//              iqentry_done[alu1_id[`QBITS]] <= `VAL;
7303
                iqentry_store[alu1_id[`QBITS]] <= `INV;
7304
                iqentry_state[alu1_id[`QBITS]] <= IQS_CMT;
7305
        end
7306
        alu1_dataready <= FALSE;
7307
end
7308
 
7309
if (fpu1_v && `NUM_FPU > 0) begin
7310
        iqentry_res [ fpu1_id[`QBITS] ] <= rfpu1_bus;
7311
        iqentry_ares[ fpu1_id[`QBITS] ] <= fpu1_status;
7312
        iqentry_exc [ fpu1_id[`QBITS] ] <= fpu1_exc;
7313
//      iqentry_done[ fpu1_id[`QBITS] ] <= fpu1_done;
7314
//      iqentry_out [ fpu1_id[`QBITS] ] <= `INV;
7315
        iqentry_state[fpu1_id[`QBITS]] <= IQS_CMT;
7316
        fpu1_dataready <= FALSE;
7317
end
7318
 
7319
if (fpu2_v && `NUM_FPU > 1) begin
7320
        iqentry_res [ fpu2_id[`QBITS] ] <= rfpu2_bus;
7321
        iqentry_ares[ fpu2_id[`QBITS] ] <= fpu2_status;
7322
        iqentry_exc [ fpu2_id[`QBITS] ] <= fpu2_exc;
7323
//      iqentry_done[ fpu2_id[`QBITS] ] <= fpu2_done;
7324
//      iqentry_out [ fpu2_id[`QBITS] ] <= `INV;
7325
        iqentry_state[fpu2_id[`QBITS]] <= IQS_CMT;
7326
        //iqentry_agen[ fpu_id[`QBITS] ] <= `VAL;  // RET
7327
        fpu2_dataready <= FALSE;
7328
end
7329
 
7330
if (IsWait(fcu_instr)) begin
7331
        if (pe_wait)
7332
                fcu_dataready <= `TRUE;
7333
end
7334
 
7335
if (fcu_v) begin
7336
        fcu_done <= `TRUE;
7337
        iqentry_ma  [ fcu_id[`QBITS] ] <= fcu_misspc;
7338
  iqentry_res [ fcu_id[`QBITS] ] <= rfcu_bus;
7339
  iqentry_exc [ fcu_id[`QBITS] ] <= fcu_exc;
7340
//      iqentry_done[ fcu_id[`QBITS] ] <= `TRUE;
7341
//      iqentry_out [ fcu_id[`QBITS] ] <= `INV;
7342
        iqentry_state[fcu_id[`QBITS] ] <= IQS_CMT;
7343
        // takb is looked at only for branches to update the predictor. Here it is
7344
        // unconditionally set, the value will be ignored if it's not a branch.
7345
        iqentry_takb[ fcu_id[`QBITS] ] <= fcu_takb;
7346
        fcu_dataready <= `INV;
7347
end
7348
 
7349
// dramX_v only set on a load
7350
if (mem1_available && dramA_v && iqentry_v[ dramA_id[`QBITS] ]) begin
7351
        iqentry_res     [ dramA_id[`QBITS] ] <= rdramA_bus;
7352
        iqentry_exc     [ dramA_id[`QBITS] ] <= dramA_exc;
7353
//      iqentry_done[ dramA_id[`QBITS] ] <= `VAL;
7354
//      iqentry_out [ dramA_id[`QBITS] ] <= `INV;
7355
        iqentry_state[dramA_id[`QBITS] ] <= IQS_CMT;
7356
        iqentry_aq  [ dramA_id[`QBITS] ] <= `INV;
7357
end
7358
if (mem2_available && `NUM_MEM > 1 && dramB_v && iqentry_v[ dramB_id[`QBITS] ]) begin
7359
        iqentry_res     [ dramB_id[`QBITS] ] <= rdramB_bus;
7360
        iqentry_exc     [ dramB_id[`QBITS] ] <= dramB_exc;
7361
//      iqentry_done[ dramB_id[`QBITS] ] <= `VAL;
7362
        iqentry_state[dramB_id[`QBITS] ] <= IQS_CMT;
7363
//      iqentry_out [ dramB_id[`QBITS] ] <= `INV;
7364
        iqentry_aq  [ dramB_id[`QBITS] ] <= `INV;
7365
end
7366
if (mem3_available && `NUM_MEM > 2 && dramC_v && iqentry_v[ dramC_id[`QBITS] ]) begin
7367
        iqentry_res     [ dramC_id[`QBITS] ] <= rdramC_bus;
7368
        iqentry_exc     [ dramC_id[`QBITS] ] <= dramC_exc;
7369
//      iqentry_done[ dramC_id[`QBITS] ] <= `VAL;
7370
        iqentry_state[dramC_id[`QBITS] ] <= IQS_CMT;
7371
//      iqentry_out [ dramC_id[`QBITS] ] <= `INV;
7372
        iqentry_aq  [ dramC_id[`QBITS] ] <= `INV;
7373
//          if (iqentry_lptr[dram2_id[`QBITS]])
7374
//              wbrcd[pcr[5:0]] <= 1'b1;
7375
end
7376
 
7377
//
7378
// see if anybody else wants the results ... look at lots of buses:
7379
//  - fpu_bus
7380
//  - alu0_bus
7381
//  - alu1_bus
7382
//  - fcu_bus
7383
//  - dram_bus
7384
//  - commit0_bus
7385
//  - commit1_bus
7386
//
7387
 
7388
for (n = 0; n < QENTRIES; n = n + 1)
7389
begin
7390
        if (`NUM_FPU > 0)
7391
                setargs(n,{1'b0,fpu1_id},fpu1_v,rfpu1_bus);
7392
        if (`NUM_FPU > 1)
7393
                setargs(n,{1'b0,fpu2_id},fpu2_v,rfpu2_bus);
7394
 
7395
        // The memory address generated by the ALU should not be posted to be
7396
        // recieved into waiting argument registers. The arguments will be waiting
7397
        // for the result of the memory load, picked up from the dram busses. The
7398
        // only mem operation requiring the alu result bus is the push operation.
7399
        setargs(n,{1'b0,alu0_id},alu0_v & (~alu0_mem | alu0_push),ralu0_bus);
7400
        if (`NUM_ALU > 1)
7401
                setargs(n,{1'b0,alu1_id},alu1_v & (~alu1_mem | alu1_push),ralu1_bus);
7402
 
7403
        setargs(n,{1'b0,fcu_id},fcu_v,rfcu_bus);
7404
 
7405
        setargs(n,{1'b0,dramA_id},dramA_v,rdramA_bus);
7406
        if (`NUM_MEM > 1)
7407
                setargs(n,{1'b0,dramB_id},dramB_v,rdramB_bus);
7408
        if (`NUM_MEM > 2)
7409
                setargs(n,{1'b0,dramC_id},dramC_v,rdramC_bus);
7410
 
7411
        setargs(n,commit0_id,commit0_v,commit0_bus);
7412
        if (`NUM_CMT > 1)
7413
                setargs(n,commit1_id,commit1_v,commit1_bus);
7414
        if (`NUM_CMT > 2)
7415
                setargs(n,commit2_id,commit2_v,commit2_bus);
7416
`ifndef INLINE_DECODE
7417
        setinsn(n[`QBITS],id1_ido,id1_available&id1_vo,id1_bus);
7418
        if (`NUM_IDU > 1)
7419
                setinsn(n[`QBITS],id2_ido,id2_available&id2_vo,id2_bus);
7420
        if (`NUM_IDU > 2)
7421
                setinsn(n[`QBITS],id3_ido,id3_available&id3_vo,id3_bus);
7422
`endif
7423
end
7424
 
7425
 
7426
//
7427
// ISSUE 
7428
//
7429
// determines what instructions are ready to go, then places them
7430
// in the various ALU queues.  
7431
// also invalidates instructions following a branch-miss BEQ or any JALR (STOMP logic)
7432
//
7433
`ifndef INLINE_DECODE
7434
for (n = 0; n < QENTRIES; n = n + 1)
7435
if (id1_available) begin
7436
if (iqentry_id1issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7437
                id1_vi <= `VAL;
7438
                id1_id                  <= n[4:0];
7439
                id1_instr       <= iqentry_rtop[n] ? (
7440
                                                                                iqentry_a3_v[n] ? iqentry_a3[n]
7441
`ifdef FU_BYPASS
7442
                                : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7443
                                : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7444
`endif
7445
                                : `NOP_INSN)
7446
                                                                 : iqentry_instr[n];
7447
                id1_ven    <= iqentry_ven[n];
7448
                id1_vl     <= iqentry_vl[n];
7449
                id1_thrd   <= iqentry_thrd[n];
7450
                id1_Rt     <= iqentry_tgt[n][4:0];
7451
                id1_pt                  <= iqentry_pt[n];
7452
  end
7453
end
7454
if (`NUM_IDU > 1) begin
7455
for (n = 0; n < QENTRIES; n = n + 1)
7456
        if (id2_available) begin
7457
                if (iqentry_id2issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7458
                        id2_vi <= `VAL;
7459
                        id2_id                  <= n[4:0];
7460
                        id2_instr       <= iqentry_rtop[n] ? (
7461
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7462
`ifdef FU_BYPASS
7463
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7464
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7465
`endif
7466
                                        : `NOP_INSN)
7467
                                                                         : iqentry_instr[n];
7468
                        id2_ven    <= iqentry_ven[n];
7469
                        id2_vl     <= iqentry_vl[n];
7470
                        id2_thrd   <= iqentry_thrd[n];
7471
                        id2_Rt     <= iqentry_tgt[n][4:0];
7472
                        id2_pt                  <= iqentry_pt[n];
7473
                end
7474
        end
7475
end
7476
if (`NUM_IDU > 2) begin
7477
for (n = 0; n < QENTRIES; n = n + 1)
7478
        if (id3_available) begin
7479
                if (iqentry_id3issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7480
                        id3_vi <= `VAL;
7481
                        id3_id                  <= n[4:0];
7482
                        id3_instr       <= iqentry_rtop[n] ? (
7483
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7484
`ifdef FU_BYPASS
7485
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7486
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7487
`endif
7488
                                        : `NOP_INSN)
7489
                                                                         : iqentry_instr[n];
7490
                        id3_ven    <= iqentry_ven[n];
7491
                        id3_vl     <= iqentry_vl[n];
7492
                        id3_thrd   <= iqentry_thrd[n];
7493
                        id3_Rt     <= iqentry_tgt[n][4:0];
7494
                        id3_pt                  <= iqentry_pt[n];
7495
                end
7496
        end
7497
end
7498
`endif  // not INLINE_DECODE
7499
 
7500
// X's on unused busses cause problems in SIM.
7501
    for (n = 0; n < QENTRIES; n = n + 1)
7502
        if (iqentry_alu0_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7503
            if (alu0_available & alu0_done) begin
7504
                 alu0_sourceid  <= {iqentry_push[n],n[`QBITS]};
7505
                 alu0_instr     <= iqentry_rtop[n] ? (
7506
`ifdef FU_BYPASS
7507
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7508
                                                    : (iqentry_a3_s[n] == alu0_id) ? ralu0_bus
7509
                                                    : (iqentry_a3_s[n] == alu1_id) ? ralu1_bus
7510
                                                    : (iqentry_a3_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7511
                                                    : `NOP_INSN)
7512
`else
7513
                                                                                                                                        iqentry_a3[n])
7514
`endif
7515
                                                                         : iqentry_instr[n];
7516
                 alu0_sz    <= iqentry_sz[n];
7517
                 alu0_tlb   <= iqentry_tlb[n];
7518
                 alu0_mem   <= iqentry_mem[n];
7519
                 alu0_load  <= iqentry_load[n];
7520
                 alu0_store <= iqentry_store[n];
7521
                 alu0_push  <= iqentry_push[n];
7522
                 alu0_shft <= iqentry_shft[n];
7523
                 alu0_pc                <= iqentry_pc[n];
7524
                 alu0_argA      <=
7525
`ifdef FU_BYPASS
7526
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7527
                            : (iqentry_a1_s[n] == alu0_id) ? ralu0_bus
7528
                            : (iqentry_a1_s[n] == alu1_id) ? ralu1_bus
7529
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7530
                            : 64'hDEADDEADDEADDEAD;
7531
`else
7532
                                                                                                                iqentry_a1[n];
7533
`endif
7534
                 alu0_argB      <= iqentry_imm[n]
7535
                            ? iqentry_a0[n]
7536
`ifdef FU_BYPASS
7537
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7538
                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus
7539
                            : (iqentry_a2_s[n] == alu1_id) ? ralu1_bus
7540
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7541
                            : 64'hDEADDEADDEADDEAD);
7542
`else
7543
                                                                                                                : iqentry_a2[n];
7544
`endif
7545
                 alu0_argC      <=
7546
`ifdef FU_BYPASS
7547
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7548
                            : (iqentry_a3_s[n] == alu0_id) ? ralu0_bus : ralu1_bus;
7549
`else
7550
                                                                                                                        iqentry_a3[n];
7551
`endif
7552
                 alu0_argI      <= iqentry_a0[n];
7553
                 alu0_tgt    <= IsVeins(iqentry_instr[n]) ?
7554
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((
7555
                                                                                        iqentry_a2_v[n] ? iqentry_a2[n][5:0]
7556
                                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus[5:0]
7557
                                            : (iqentry_a2_s[n] == alu1_id) ? ralu1_bus[5:0]
7558
                                            : {4{16'h0000}})) << 6 :
7559
                                iqentry_tgt[n];
7560
                 alu0_ven    <= iqentry_ven[n];
7561
                 alu0_thrd   <= iqentry_thrd[n];
7562
                 alu0_dataready <= IsSingleCycle(iqentry_instr[n]);
7563
                 alu0_ld <= TRUE;
7564
                 iqentry_state[n] <= IQS_OUT;
7565
            end
7566
        end
7567
        if (`NUM_ALU > 1) begin
7568
    for (n = 0; n < QENTRIES; n = n + 1)
7569
        if (iqentry_alu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7570
            if (alu1_available && alu1_done) begin
7571
                        if (iqentry_alu0[n])
7572
                                panic <= `PANIC_ALU0ONLY;
7573
                 alu1_sourceid  <= {iqentry_push[n],n[`QBITS]};
7574
                 alu1_instr     <= iqentry_instr[n];
7575
                 alu1_sz    <= iqentry_sz[n];
7576
                 alu1_mem   <= iqentry_mem[n];
7577
                 alu1_load  <= iqentry_load[n];
7578
                 alu1_store <= iqentry_store[n];
7579
                 alu1_push  <= iqentry_push[n];
7580
                 alu1_shft  <= iqentry_shft[n];
7581
                 alu1_pc                <= iqentry_pc[n];
7582
                 alu1_argA      <=
7583
`ifdef FU_BYPASS
7584
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7585
                            : (iqentry_a1_s[n] == alu0_id) ? ralu0_bus
7586
                            : (iqentry_a1_s[n] == alu1_id) ? ralu1_bus
7587
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7588
                            : 64'hDEADDEADDEADDEAD;
7589
`else
7590
                                                                                                                        iqentry_a1[n];
7591
`endif
7592
                 alu1_argB      <= iqentry_imm[n]
7593
                            ? iqentry_a0[n]
7594
`ifdef FU_BYPASS
7595
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7596
                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus
7597
                            : (iqentry_a2_s[n] == alu1_id) ? ralu1_bus
7598
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7599
                            : 64'hDEADDEADDEADDEAD);
7600
`else
7601
                                                                                                                : iqentry_a2[n];
7602
`endif
7603
                 alu1_argC      <=
7604
`ifdef FU_BYPASS
7605
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7606
                            : (iqentry_a3_s[n] == alu0_id) ? ralu0_bus : ralu1_bus;
7607
`else
7608
                                                                                                                        iqentry_a3[n];
7609
`endif
7610
                 alu1_argI      <= iqentry_a0[n];
7611
                 alu1_tgt    <= IsVeins(iqentry_instr[n]) ?
7612
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((iqentry_a2_v[n] ? iqentry_a2[n][5:0]
7613
                                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus[5:0]
7614
                                            : (iqentry_a2_s[n] == alu1_id) ? ralu1_bus[5:0]
7615
                                            : {4{16'h0000}})) << 6 :
7616
                                iqentry_tgt[n];
7617
                 alu1_ven    <= iqentry_ven[n];
7618
                 alu1_dataready <= IsSingleCycle(iqentry_instr[n]);
7619
                 alu1_ld <= TRUE;
7620
                 iqentry_state[n] <= IQS_OUT;
7621
            end
7622
        end
7623
  end
7624
 
7625
    for (n = 0; n < QENTRIES; n = n + 1)
7626
        if (iqentry_fpu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7627
            if (fpu1_available & fpu1_done) begin
7628
                 fpu1_sourceid  <= n[`QBITS];
7629
                 fpu1_instr     <= iqentry_instr[n];
7630
                 fpu1_pc                <= iqentry_pc[n];
7631
                 fpu1_argA      <=
7632
`ifdef FU_BYPASS
7633
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7634
                            : (iqentry_a1_s[n] == alu0_id) ? ralu0_bus
7635
                            : (iqentry_a1_s[n] == alu1_id) ? ralu1_bus
7636
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7637
                            : 64'hDEADDEADDEADDEAD;
7638
`else
7639
                                                                                                                        iqentry_a1[n];
7640
`endif
7641
                 fpu1_argB      <=
7642
`ifdef FU_BYPASS
7643
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
7644
                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus
7645
                            : (iqentry_a2_s[n] == alu1_id) ? ralu1_bus
7646
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7647
                            : 64'hDEADDEADDEADDEAD);
7648
`else
7649
                                                                                                                        iqentry_a2[n];
7650
`endif
7651
                 fpu1_argC      <=
7652
`ifdef FU_BYPASS
7653
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
7654
                            : (iqentry_a3_s[n] == alu0_id) ? ralu0_bus : ralu1_bus;
7655
`else
7656
                                                                                                                        iqentry_a3[n];
7657
`endif
7658
`ifdef SUPPORT_PREDICATION
7659
                                                                 fpu1_pred   <= iqentry_p_v[n] ? iqentry_pred[n] :
7660
`ifdef FU_BYPASS
7661
                                                                                                                                (iqentry_p_s[n] == alu0_id) ? alu0nyb[iqentry_preg[n]] :
7662
                                                                                                                                (iqentry_p_s[n] == alu1_id) ? alu1nyb[iqentry_preg[n]] :
7663
`endif
7664
                                                                                                                                4'h0;
7665
                 fpu1_argT      <=
7666
`ifdef FU_BYPASS
7667
                                                                        iqentry_aT_v[n] ? iqentry_aT[n]
7668
                            : (iqentry_aT_s[n] == alu0_id) ? ralu0_bus : ralu1_bus;
7669
`else
7670
                                                                                                                        iqentry_aT[n];
7671
`endif
7672
`endif
7673
                 fpu1_argI      <= iqentry_a0[n];
7674
                 fpu1_dataready <= `VAL;
7675
                 fpu1_ld <= TRUE;
7676
                 iqentry_state[n] <= IQS_OUT;
7677
            end
7678
        end
7679
 
7680
    for (n = 0; n < QENTRIES; n = n + 1)
7681
        if (`NUM_FPU > 1 && iqentry_fpu2_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7682
            if (fpu2_available & fpu2_done) begin
7683
                 fpu2_sourceid  <= n[`QBITS];
7684
                 fpu2_instr     <= iqentry_instr[n];
7685
                 fpu2_pc                <= iqentry_pc[n];
7686
                 fpu2_argA      <=
7687
`ifdef FU_BYPASS
7688
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7689
                            : (iqentry_a1_s[n] == alu0_id) ? ralu0_bus
7690
                            : (iqentry_a1_s[n] == alu1_id) ? ralu1_bus
7691
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7692
                            : 64'hDEADDEADDEADDEAD;
7693
`else
7694
                                                                                                                        iqentry_a1[n];
7695
`endif
7696
                 fpu2_argB      <=
7697
`ifdef FU_BYPASS
7698
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
7699
                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus
7700
                            : (iqentry_a2_s[n] == alu1_id) ? ralu1_bus
7701
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7702
                            : 64'hDEADDEADDEADDEAD);
7703
`else
7704
                                                                                                                        iqentry_a2[n];
7705
`endif
7706
                 fpu2_argC      <=
7707
`ifdef FU_BYPASS
7708
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
7709
                            : (iqentry_a3_s[n] == alu0_id) ? ralu0_bus : ralu1_bus;
7710
`else
7711
                                                                                                                        iqentry_a3[n];
7712
`endif
7713
`ifdef SUPPORT_PREDICATION
7714
                                                                 fpu2_pred   <= iqentry_p_v[n] ? iqentry_pred[n] :
7715
`ifdef FU_BYPASS
7716
                                                                                                                                (iqentry_p_s[n] == alu0_id) ? alu0nyb[iqentry_preg[n]] :
7717
                                                                                                                                (iqentry_p_s[n] == alu1_id) ? alu1nyb[iqentry_preg[n]] :
7718
`endif
7719
                                                                                                                                4'h0;
7720
                 fpu2_argT      <=
7721
`ifdef FU_BYPASS
7722
                                                                        iqentry_aT_v[n] ? iqentry_aT[n]
7723
                            : (iqentry_aT_s[n] == alu0_id) ? ralu0_bus : ralu1_bus;
7724
`else
7725
                                                                                                                        iqentry_aT[n];
7726
`endif
7727
`endif
7728
                 fpu2_argI      <= iqentry_a0[n];
7729
                 fpu2_dataready <= `VAL;
7730
                 fpu2_ld <= TRUE;
7731
                 iqentry_state[n] <= IQS_OUT;
7732
            end
7733
        end
7734
 
7735
    for (n = 0; n < QENTRIES; n = n + 1)
7736
        if (iqentry_fcu_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7737
            if (fcu_done) begin
7738
                 fcu_sourceid   <= n[`QBITS];
7739
                 fcu_prevInstr <= fcu_instr;
7740
                 fcu_instr      <= iqentry_instr[n];
7741
                 fcu_insln  <= iqentry_insln[n];
7742
                 fcu_pc         <= iqentry_pc[n];
7743
                 fcu_nextpc <= iqentry_pc[n] + iqentry_insln[n];
7744
                 fcu_pt     <= iqentry_pt[n];
7745
                 fcu_brdisp <= iqentry_instr[n][6] ? {{37{iqentry_instr[n][47]}},iqentry_instr[n][47:23],iqentry_instr[n][17:16]}
7746
                                                                         : {{53{iqentry_instr[n][31]}},iqentry_instr[n][31:23],iqentry_instr[n][17:16]};
7747
                 fcu_branch <= iqentry_br[n];
7748
                 fcu_call    <= IsCall(iqentry_instr[n])|iqentry_jal[n];
7749
                 fcu_jal     <= iqentry_jal[n];
7750
                 fcu_ret    <= iqentry_ret[n];
7751
                 fcu_brk  <= iqentry_brk[n];
7752
                 fcu_rti  <= iqentry_rti[n];
7753
                 fcu_pc         <= iqentry_pc[n];
7754
                 fcu_argA       <= iqentry_a1_v[n] ? iqentry_a1[n]
7755
                            : (iqentry_a1_s[n] == alu0_id) ? ralu0_bus
7756
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7757
                            : ralu1_bus;
7758
`ifdef SUPPORT_SMT
7759
                 fcu_argB       <= iqentry_rti[n] ? epc0[iqentry_thrd[n]]
7760
`else
7761
                 fcu_argB       <= iqentry_rti[n] ? epc0
7762
`endif
7763
                                        : (iqentry_a2_v[n] ? iqentry_a2[n]
7764
                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus
7765
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus
7766
                            : ralu1_bus);
7767
                 // argB
7768
                 waitctr  <=  (iqentry_a2_v[n] ? iqentry_a2[n][47:0]
7769
                            : (iqentry_a2_s[n] == alu0_id) ? ralu0_bus[47:0]
7770
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? rfpu1_bus[47:0]
7771
                            : ralu1_bus[47:0]);
7772
                 fcu_argC       <= iqentry_a3_v[n] ? iqentry_a3[n]
7773
                            : (iqentry_a3_s[n] == alu0_id) ? ralu0_bus : ralu1_bus;
7774
`ifdef SUPPORT_PREDICATION
7775
                                                                 fcu_pred   <= iqentry_p_v[n] ? iqentry_pred[n] :
7776
`ifdef FU_BYPASS
7777
                                                                                                                                (iqentry_p_s[n] == alu0_id) ? alu0nyb[iqentry_preg[n]] :
7778
                                                                                                                                (iqentry_p_s[n] == alu1_id) ? alu1nyb[iqentry_preg[n]] :
7779
`endif
7780
                                                                                                                                4'h0;
7781
                 fcu_argT       <=
7782
`ifdef FU_BYPASS
7783
                                                                        iqentry_aT_v[n] ? iqentry_aT[n]
7784
                            : (iqentry_aT_s[n] == alu0_id) ? ralu0_bus : ralu1_bus;
7785
`else
7786
                                                                                                                        iqentry_aT[n];
7787
`endif
7788
`endif
7789
                 fcu_argI       <= iqentry_a0[n];
7790
                 fcu_thrd   <= iqentry_thrd[n];
7791
                 fcu_dataready <= !IsWait(iqentry_instr[n]);
7792
                 fcu_clearbm <= `FALSE;
7793
                 fcu_ld <= TRUE;
7794
                 fcu_timeout <= 8'h00;
7795
                 iqentry_state[n] <= IQS_OUT;
7796
                 fcu_done <= `FALSE;
7797
            end
7798
        end
7799
//
7800
// MEMORY
7801
//
7802
// update the memory queues and put data out on bus if appropriate
7803
//
7804
 
7805
//
7806
// dram0, dram1, dram2 are the "state machines" that keep track
7807
// of three pipelined DRAM requests.  if any has the value "000", 
7808
// then it can accept a request (which bumps it up to the value "001"
7809
// at the end of the cycle).  once it hits the value "111" the request
7810
// is finished and the dram_bus takes the value.  if it is a store, the 
7811
// dram_bus value is not used, but the dram_v value along with the
7812
// dram_id value signals the waiting memq entry that the store is
7813
// completed and the instruction can commit.
7814
//
7815
 
7816
//      if (dram0 != `DRAMSLOT_AVAIL)   dram0 <= dram0 + 2'd1;
7817
//      if (dram1 != `DRAMSLOT_AVAIL)   dram1 <= dram1 + 2'd1;
7818
//      if (dram2 != `DRAMSLOT_AVAIL)   dram2 <= dram2 + 2'd1;
7819
 
7820
// Flip the ready status to available. Used for loads or stores.
7821
 
7822
if (dram0 == `DRAMREQ_READY)
7823
        dram0 <= `DRAMSLOT_AVAIL;
7824
if (dram1 == `DRAMREQ_READY && `NUM_MEM > 1)
7825
        dram1 <= `DRAMSLOT_AVAIL;
7826
if (dram2 == `DRAMREQ_READY && `NUM_MEM > 2)
7827
        dram2 <= `DRAMSLOT_AVAIL;
7828
 
7829
// grab requests that have finished and put them on the dram_bus
7830
 
7831
if (dram0 == `DRAMREQ_READY && dram0_load) begin
7832
        dramA_v <= `VAL;//!iqentry_stomp[dram0_id[`QBITS]];
7833
        dramA_id <= dram0_id;
7834
        dramA_exc <= dram0_exc;
7835
        dramA_bus <= fnDatiAlign(dram0_instr,dram0_addr,rdat0);
7836
end
7837
if (dram1 == `DRAMREQ_READY && dram1_load && `NUM_MEM > 1) begin
7838
        dramB_v <= `VAL;//!iqentry_stomp[dram1_id[`QBITS]];
7839
        dramB_id <= dram1_id;
7840
        dramB_exc <= dram1_exc;
7841
        dramB_bus <= fnDatiAlign(dram1_instr,dram1_addr,rdat1);
7842
end
7843
if (dram2 == `DRAMREQ_READY && dram2_load && `NUM_MEM > 2) begin
7844
        dramC_v <= `VAL;//!iqentry_stomp[dram2_id[`QBITS]];
7845
        dramC_id <= dram2_id;
7846
        dramC_exc <= dram2_exc;
7847
        dramC_bus <= fnDatiAlign(dram2_instr,dram2_addr,rdat2);
7848
end
7849
 
7850
if (dram0 == `DRAMREQ_READY && dram0_store)
7851
        $display("m[%h] <- %h", dram0_addr, dram0_data);
7852
if (dram1 == `DRAMREQ_READY && dram1_store && `NUM_MEM > 1)
7853
        $display("m[%h] <- %h", dram1_addr, dram1_data);
7854
if (dram2 == `DRAMREQ_READY && dram2_store && `NUM_MEM > 2)
7855
        $display("m[%h] <- %h", dram2_addr, dram2_data);
7856
 
7857
//
7858
// determine if the instructions ready to issue can, in fact, issue.
7859
// "ready" means that the instruction has valid operands but has not gone yet
7860
iqentry_memissue <= memissue;
7861
missue_count <= issue_count;
7862
 
7863
if (dram0 == `DRAMSLOT_AVAIL)    dram0_exc <= `FLT_NONE;
7864
if (dram1 == `DRAMSLOT_AVAIL)    dram1_exc <= `FLT_NONE;
7865
if (dram2 == `DRAMSLOT_AVAIL)    dram2_exc <= `FLT_NONE;
7866
 
7867
for (n = 0; n < QENTRIES; n = n + 1)
7868
        if (iqentry_v[n] && iqentry_stomp[n]) begin
7869
                iqentry_iv[n] <= `INV;
7870
                iqentry_mem[n] <= `INV;
7871
                iqentry_load[n] <= `INV;
7872
                iqentry_store[n] <= `INV;
7873
                iqentry_state[n] <= IQS_INVALID;
7874
//              iqentry_agen[n] <= `INV;
7875
//              iqentry_out[n] <= `INV;
7876
//              iqentry_done[n] <= `INV;
7877
//              iqentry_cmt[n] <= `INV;
7878
                if (dram0_id[`QBITS] == n[`QBITS])  begin
7879
                        if (dram0==`DRAMSLOT_HASBUS)
7880
                                wb_nack();
7881
                        dram0_load <= `FALSE;
7882
                        dram0_store <= `FALSE;
7883
                        dram0_rmw <= `FALSE;
7884
                        dram0 <= `DRAMSLOT_AVAIL;
7885
                end
7886
                if (dram1_id[`QBITS] == n[`QBITS])  begin
7887
                        if (dram1==`DRAMSLOT_HASBUS)
7888
                                wb_nack();
7889
                        dram1_load <= `FALSE;
7890
                        dram1_store <= `FALSE;
7891
                        dram1_rmw <= `FALSE;
7892
                        dram1 <= `DRAMSLOT_AVAIL;
7893
                end
7894
                if (dram2_id[`QBITS] == n[`QBITS])  begin
7895
                        if (dram2==`DRAMSLOT_HASBUS)
7896
                                wb_nack();
7897
                        dram2_load <= `FALSE;
7898
                        dram2_store <= `FALSE;
7899
                        dram2_rmw <= `FALSE;
7900
                        dram2 <= `DRAMSLOT_AVAIL;
7901
                end
7902
        end
7903
 
7904
if (last_issue0 < QENTRIES)
7905
        tDram0Issue(last_issue0);
7906
if (last_issue1 < QENTRIES)
7907
        tDram1Issue(last_issue1);
7908
if (last_issue2 < QENTRIES)
7909
        tDram2Issue(last_issue2);
7910
 
7911
 
7912
//for (n = 0; n < QENTRIES; n = n + 1)
7913
//begin
7914
//      if (!iqentry_v[n])
7915
//              iqentry_done[n] <= FALSE;
7916
//end
7917
 
7918
if (ohead[0]==heads[0])
7919
        cmt_timer <= cmt_timer + 12'd1;
7920
else
7921
        cmt_timer <= 12'd0;
7922
 
7923
if (cmt_timer==12'd1000) begin
7924
        iqentry_state[heads[0]] <= IQS_CMT;
7925
        iqentry_exc[heads[0]] <= `FLT_CMT;
7926
        cmt_timer <= 12'd0;
7927
end
7928
 
7929
//
7930
// COMMIT PHASE (dequeue only ... not register-file update)
7931
//
7932
// look at heads[0] and heads[1] and let 'em write to the register file if they are ready
7933
//
7934
//    always @(posedge clk) begin: commit_phase
7935
ohead[0] <= heads[0];
7936
ohead[1] <= heads[1];
7937
ohead[2] <= heads[2];
7938
ocommit0_v <= commit0_v;
7939
ocommit1_v <= commit1_v;
7940
ocommit2_v <= commit2_v;
7941
 
7942
oddball_commit(commit0_v, heads[0], 2'd0);
7943
if (`NUM_CMT > 1)
7944
        oddball_commit(commit1_v, heads[1], 2'd1);
7945
if (`NUM_CMT > 2)
7946
        oddball_commit(commit2_v, heads[2], 2'd2);
7947
 
7948
// Fetch and queue are limited to two instructions per cycle, so we might as
7949
// well limit retiring to two instructions max to conserve logic.
7950
//
7951
if (~|panic)
7952
  casez ({ iqentry_v[heads[0]],
7953
                iqentry_state[heads[0]] == IQS_CMT,
7954
                iqentry_v[heads[1]],
7955
                iqentry_state[heads[1]] == IQS_CMT,
7956
                iqentry_v[heads[2]],
7957
                iqentry_state[heads[2]] == IQS_CMT})
7958
 
7959
        // retire 3
7960
        6'b0?_0?_0?:
7961
                if (heads[0] != tail0 && heads[1] != tail0 && heads[2] != tail0)
7962
                        head_inc(3);
7963
                else if (heads[0] != tail0 && heads[1] != tail0)
7964
            head_inc(2);
7965
                else if (heads[0] != tail0)
7966
            head_inc(1);
7967
        6'b0?_0?_10:
7968
                if (heads[0] != tail0 && heads[1] != tail0)
7969
                        head_inc(2);
7970
                else if (heads[0] != tail0)
7971
                        head_inc(1);
7972
        6'b0?_0?_11:
7973
                if (`NUM_CMT > 2 || cmt_head2)  // and it's not an oddball?
7974
      head_inc(3);
7975
                else
7976
      head_inc(2);
7977
 
7978
        // retire 1 (wait for regfile for heads[1])
7979
        6'b0?_10_??:
7980
                head_inc(1);
7981
 
7982
        // retire 2
7983
        6'b0?_11_0?,
7984
        6'b0?_11_10:
7985
    if (`NUM_CMT > 1 || cmt_head1)
7986
      head_inc(2);
7987
    else
7988
        head_inc(1);
7989
  6'b0?_11_11:
7990
    if (`NUM_CMT > 2 || (`NUM_CMT > 1 && cmt_head2))
7991
        head_inc(3);
7992
        else if (`NUM_CMT > 1 || cmt_head1)
7993
        head_inc(2);
7994
        else
7995
                head_inc(1);
7996
  6'b10_??_??:  ;
7997
  6'b11_0?_0?:
7998
        if (heads[1] != tail0 && heads[2] != tail0)
7999
                        head_inc(3);
8000
        else if (heads[1] != tail0)
8001
                        head_inc(2);
8002
        else
8003
                        head_inc(1);
8004
  6'b11_0?_10:
8005
        if (heads[1] != tail0)
8006
                        head_inc(2);
8007
        else
8008
                        head_inc(1);
8009
  6'b11_0?_11:
8010
        if (heads[1] != tail0) begin
8011
                if (`NUM_CMT > 2 || cmt_head2)
8012
                                head_inc(3);
8013
                else
8014
                                head_inc(2);
8015
        end
8016
        else
8017
                        head_inc(1);
8018
  6'b11_10_??:
8019
                        head_inc(1);
8020
  6'b11_11_0?:
8021
        if (`NUM_CMT > 1 && heads[2] != tail0)
8022
                        head_inc(3);
8023
        else if (cmt_head1 && heads[2] != tail0)
8024
                        head_inc(3);
8025
                else if (`NUM_CMT > 1 || cmt_head1)
8026
                        head_inc(2);
8027
        else
8028
                        head_inc(1);
8029
  6'b11_11_10:
8030
                if (`NUM_CMT > 1 || cmt_head1)
8031
                        head_inc(2);
8032
        else
8033
                        head_inc(1);
8034
        6'b11_11_11:
8035
                if (`NUM_CMT > 2 || (`NUM_CMT > 1 && cmt_head2))
8036
                        head_inc(3);
8037
                else if (`NUM_CMT > 1 || cmt_head1)
8038
                        head_inc(2);
8039
                else
8040
                        head_inc(1);
8041
        default:
8042
                begin
8043
                        $display("head_inc: Uncoded case %h",{ iqentry_v[heads[0]],
8044
                                iqentry_state[heads[0]],
8045
                                iqentry_v[heads[1]],
8046
                                iqentry_state[heads[1]],
8047
                                iqentry_v[heads[2]],
8048
                                iqentry_state[heads[2]]});
8049
                        $stop;
8050
                end
8051
  endcase
8052
 
8053
 
8054
rf_source[0] <= 0;
8055
L1_wr0 <= FALSE;
8056
L1_wr1 <= FALSE;
8057
L1_wr2 <= FALSE;
8058
L1_invline <= FALSE;
8059
icnxt <= FALSE;
8060
L2_nxt <= FALSE;
8061
// Instruction cache state machine.
8062
// On a miss first see if the instruction is in the L2 cache. No need to go to
8063
// the BIU on an L1 miss.
8064
// If not the machine will wait until the BIU loads the L2 cache.
8065
 
8066
// Capture the previous ic state, used to determine how long to wait in
8067
// icstate #4.
8068
picstate <= icstate;
8069
case(icstate)
8070
IDLE:
8071
        // If the bus unit is busy doing an update involving L1_adr or L2_adr
8072
        // we have to wait.
8073
        if (bstate != B_ICacheAck && bstate != B_ICacheNack && bstate != B_ICacheNack2) begin
8074
                if (!ihit0) begin
8075
                        L1_adr <= {pcr[7:0],pc0[AMSB:5],5'h0};
8076
                        L2_adr <= {pcr[7:0],pc0[AMSB:5],5'h0};
8077
                        L1_invline <= TRUE;
8078
                        icwhich <= 2'b00;
8079
                        iccnt <= 3'b00;
8080
                        icstate <= IC2;
8081
                end
8082
                else if (!ihit1 && `WAYS > 1) begin
8083
                        if (thread_en) begin
8084
                                L1_adr <= {pcr[7:0],pc1[AMSB:5],5'h0};
8085
                                L2_adr <= {pcr[7:0],pc1[AMSB:5],5'h0};
8086
                        end
8087
                        else begin
8088
                                L1_adr <= {pcr[7:0],pc0plus6[AMSB:5],5'h0};
8089
                                L2_adr <= {pcr[7:0],pc0plus6[AMSB:5],5'h0};
8090
                        end
8091
                        L1_invline <= TRUE;
8092
                        icwhich <= 2'b01;
8093
                        iccnt <= 3'b00;
8094
                        icstate <= IC2;
8095
                end
8096
                else if (!ihit2 && `WAYS > 2) begin
8097
                        if (thread_en) begin
8098
                                L1_adr <= {pcr[7:0],pc2[AMSB:5],5'h0};
8099
                                L2_adr <= {pcr[7:0],pc2[AMSB:5],5'h0};
8100
                        end
8101
                        else begin
8102
                                L1_adr <= {pcr[7:0],pc0plus12[AMSB:5],5'h0};
8103
                                L2_adr <= {pcr[7:0],pc0plus12[AMSB:5],5'h0};
8104
                        end
8105
                        L1_invline <= TRUE;
8106
                        icwhich <= 2'b10;
8107
                        iccnt <= 3'b00;
8108
                        icstate <= IC2;
8109
                end
8110
        end
8111
IC2:     icstate <= IC3;
8112
IC3:     icstate <= IC3a;
8113
IC3a:     icstate <= IC_WaitL2;
8114
// If data was in the L2 cache already there's no need to wait on the
8115
// BIU to retrieve data. It can be determined if the hit signal was
8116
// already active when this state was entered in which case waiting
8117
// will do no good.
8118
// The IC machine will stall in this state until the BIU has loaded the
8119
// L2 cache. 
8120
IC_WaitL2:
8121
        if (ihitL2 && picstate==IC3a) begin
8122
                L1_en <= 9'h1FF;
8123
                L1_wr0 <= TRUE;
8124
                L1_wr1 <= TRUE && `WAYS > 1;
8125
                L1_wr2 <= TRUE && `WAYS > 2;
8126
                L1_adr <= L2_adr;
8127
                L2_rdat <= L2_dato;
8128
                icstate <= IC5;
8129
        end
8130
        else if (bstate!=B_ICacheNack)
8131
                ;
8132
        else begin
8133
                L1_en <= 9'h1FF;
8134
                L1_wr0 <= TRUE;
8135
                L1_wr1 <= TRUE && `WAYS > 1;
8136
                L1_wr2 <= TRUE && `WAYS > 2;
8137
                L1_adr <= L2_adr;
8138
                // L2_rdat set below while loading cache line
8139
                //L2_rdat <= L2_dato;
8140
                icstate <= IC5;
8141
        end
8142
IC5:
8143
        begin
8144
                L1_en <= 9'h000;
8145
                L1_wr0 <= FALSE;
8146
                L1_wr1 <= FALSE;
8147
                L1_wr2 <= FALSE;
8148
                icstate <= IC6;
8149
        end
8150
IC6:  icstate <= IC7;
8151
IC7:    icstate <= IC_Next;
8152
IC_Next:
8153
  begin
8154
   icstate <= IDLE;
8155
   icnxt <= TRUE;
8156
        end
8157
default:     icstate <= IDLE;
8158
endcase
8159
 
8160
if (mem1_available && dram0_load)
8161
case(dram0)
8162
`DRAMSLOT_AVAIL:        ;
8163
`DRAMSLOT_BUSY:
8164
//      if (iqentry_v[dram0_id[`QBITS]] && !iqentry_stomp[dram0_id[`QBITS]])
8165
                dram0 <= dram0 + !dram0_unc;
8166
//      else begin
8167
//              dram0 <= `DRAMSLOT_AVAIL;
8168
//              dram0_load <= `FALSE;
8169
//      end
8170
3'd2:
8171
//      if (iqentry_v[dram0_id[`QBITS]] && !iqentry_stomp[dram0_id[`QBITS]])
8172
                dram0 <= dram0 + 3'd1;
8173
//      else begin
8174
//              dram0 <= `DRAMSLOT_AVAIL;
8175
//              dram0_load <= `FALSE;
8176
//      end
8177
3'd3:
8178
//      if (iqentry_v[dram0_id[`QBITS]] && !iqentry_stomp[dram0_id[`QBITS]])
8179
                dram0 <= dram0 + 3'd1;
8180
//      else begin
8181
//              dram0 <= `DRAMSLOT_AVAIL;
8182
//              dram0_load <= `FALSE;
8183
//      end
8184
3'd4:
8185
        if (iqentry_v[dram0_id[`QBITS]] && !iqentry_stomp[dram0_id[`QBITS]]) begin
8186
                if (dhit0)
8187
                        dram0 <= `DRAMREQ_READY;
8188
                else
8189
                        dram0 <= `DRAMSLOT_REQBUS;
8190
        end
8191
        else begin
8192
                dram0 <= `DRAMSLOT_AVAIL;
8193
                dram0_load <= `FALSE;
8194
        end
8195
`DRAMSLOT_REQBUS:       ;
8196
`DRAMSLOT_HASBUS:       ;
8197
`DRAMREQ_READY:         dram0 <= `DRAMSLOT_AVAIL;
8198
endcase
8199
 
8200
if (mem2_available && dram1_load && `NUM_MEM > 1)
8201
case(dram1)
8202
`DRAMSLOT_AVAIL:        ;
8203
`DRAMSLOT_BUSY:
8204
        dram1 <= dram1 + !dram1_unc;
8205
3'd2:
8206
        dram1 <= dram1 + 3'd1;
8207
3'd3:
8208
        dram1 <= dram1 + 3'd1;
8209
3'd4:
8210
        if (iqentry_v[dram1_id[`QBITS]] && !iqentry_stomp[dram1_id[`QBITS]]) begin
8211
                if (dhit1)
8212
                        dram1 <= `DRAMREQ_READY;
8213
                else
8214
                        dram1 <= `DRAMSLOT_REQBUS;
8215
        end
8216
        else begin
8217
                dram1 <= `DRAMSLOT_AVAIL;
8218
                dram1_load <= `FALSE;
8219
        end
8220
`DRAMSLOT_REQBUS:       ;
8221
`DRAMSLOT_HASBUS:       ;
8222
`DRAMREQ_READY:         dram1 <= `DRAMSLOT_AVAIL;
8223
endcase
8224
 
8225
if (mem3_available && dram2_load && `NUM_MEM > 2)
8226
case(dram2)
8227
`DRAMSLOT_AVAIL:        ;
8228
`DRAMSLOT_BUSY:
8229
        dram2 <= dram2 + !dram2_unc;
8230
3'd2:
8231
        dram2 <= dram2 + 3'd1;
8232
3'd3:
8233
        dram2 <= dram2 + 3'd1;
8234
3'd4:
8235
        if (iqentry_v[dram2_id[`QBITS]] && !iqentry_stomp[dram2_id[`QBITS]]) begin
8236
                if (dhit2)
8237
                        dram2 <= `DRAMREQ_READY;
8238
                else
8239
                        dram2 <= `DRAMSLOT_REQBUS;
8240
        end
8241
        else begin
8242
                dram2 <= `DRAMSLOT_AVAIL;
8243
                dram2_load <= `FALSE;
8244
        end
8245
`DRAMSLOT_REQBUS:       ;
8246
`DRAMSLOT_HASBUS:       ;
8247
`DRAMREQ_READY:         dram2 <= `DRAMSLOT_AVAIL;
8248
endcase
8249
 
8250
 
8251
// Bus Interface Unit (BIU)
8252
// Interfaces to the external bus which is WISHBONE compatible.
8253
// Stores take precedence over other operations.
8254
// Next data cache read misses are serviced.
8255
// Uncached data reads are serviced.
8256
// Finally L2 instruction cache misses are serviced.//
8257
// set the IQ entry == DONE as soon as the SW is let loose to the memory system
8258
//
8259
`ifndef HAS_WB
8260
if (mem1_available && dram0 == `DRAMSLOT_BUSY && dram0_store) begin
8261
        if ((alu0_v && (dram0_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram0_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
8262
//      iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
8263
//      iqentry_out[ dram0_id[`QBITS] ] <= `INV;
8264
        iqentry_state[ dram0_id[`QBITS] ] <= IQS_DONE;
8265
end
8266
if (mem2_available && `NUM_MEM > 1 && dram1 == `DRAMSLOT_BUSY && dram1_store) begin
8267
        if ((alu0_v && (dram1_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram1_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
8268
//      iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
8269
//      iqentry_out[ dram1_id[`QBITS] ] <= `INV;
8270
        iqentry_state[ dram1_id[`QBITS] ] <= IQS_DONE;
8271
end
8272
if (mem3_available && `NUM_MEM > 2 && dram2 == `DRAMSLOT_BUSY && dram2_store) begin
8273
        if ((alu0_v && (dram2_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram2_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
8274
//      iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
8275
//      iqentry_out[ dram2_id[`QBITS] ] <= `INV;
8276
        iqentry_state[ dram2_id[`QBITS] ] <= IQS_DONE;
8277
end
8278
`endif
8279
 
8280
`ifdef HAS_WB
8281
  if (mem1_available && dram0==`DRAMSLOT_BUSY && dram0_store && !iqentry_stomp[dram0_id[`QBITS]]) begin
8282
                if (wbptr<`WB_DEPTH-1) begin
8283
                        dram0 <= `DRAMSLOT_AVAIL;
8284
                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
8285
                        wb_update(
8286
                                dram0_id,
8287
                                `FALSE,
8288
                                fnSelect(dram0_instr,dram0_addr),
8289
                                dram0_ol,
8290
                                dram0_addr,
8291
                                fnDato(dram0_instr,dram0_data)
8292
                        );
8293
//                      iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
8294
//                      iqentry_out[ dram0_id[`QBITS] ] <= `INV;
8295
                        iqentry_state[ dram0_id[`QBITS] ] <= IQS_DONE;
8296
                end
8297
  end
8298
  else if (mem2_available && dram1==`DRAMSLOT_BUSY && dram1_store && !iqentry_stomp[dram1_id[`QBITS]] && `NUM_MEM > 1) begin
8299
                if (wbptr<`WB_DEPTH-1) begin
8300
                        dram1 <= `DRAMSLOT_AVAIL;
8301
      dram1_instr[`INSTRUCTION_OP] <= `NOP;
8302
                        wb_update(
8303
                                dram1_id,
8304
                                `FALSE,
8305
                                fnSelect(dram1_instr,dram1_addr),
8306
                                dram1_ol,
8307
                                dram1_addr,
8308
                                fnDato(dram1_instr,dram1_data)
8309
                        );
8310
                        iqentry_state[ dram1_id[`QBITS] ] <= IQS_DONE;
8311
                end
8312
  end
8313
  else if (mem3_available && dram2==`DRAMSLOT_BUSY && dram2_store && !iqentry_stomp[dram2_id[`QBITS]] && `NUM_MEM > 2) begin
8314
                if (wbptr<`WB_DEPTH-1) begin
8315
                        dram2 <= `DRAMSLOT_AVAIL;
8316
      dram2_instr[`INSTRUCTION_OP] <= `NOP;
8317
                        wb_update(
8318
                                dram2_id,
8319
                                `FALSE,
8320
                                fnSelect(dram2_instr,dram2_addr),
8321
                                dram2_ol,
8322
                                dram2_addr,
8323
                                fnDato(dram2_instr,dram2_data)
8324
                        );
8325
                        iqentry_state[ dram2_id[`QBITS] ] <= IQS_DONE;
8326
                end
8327
  end
8328
`endif
8329
 
8330
case(bstate)
8331
BIDLE:
8332
        begin
8333
                isCAS <= FALSE;
8334
                isAMO <= FALSE;
8335
                isInc <= FALSE;
8336
                isSpt <= FALSE;
8337
                isRMW <= FALSE;
8338
                rdvq <= 1'b0;
8339
                errq <= 1'b0;
8340
                exvq <= 1'b0;
8341
                bwhich <= 2'b00;
8342
                preload <= FALSE;
8343
`ifdef HAS_WB
8344
                if (wb_v[0] & wb_en & ~acki & ~cyc) begin
8345
                        cyc <= `HIGH;
8346
                        stb_o <= `HIGH;
8347
                        we <= `HIGH;
8348
                        sel_o <= wb_sel[0];
8349
                        vadr <= wb_addr[0];
8350
                        dat_o <= wb_data[0];
8351
                        ol_o  <= wb_ol[0];
8352
                        wbo_id <= wb_id[0];
8353
        isStore <= TRUE;
8354
                        bstate <= wb_rmw[0] ? B12 : B_StoreAck;
8355
                        wb_v[0] <= `INV;
8356
                end
8357
                if (wb_v[0]==`INV && !writing_wb) begin
8358
                        for (j = 1; j < `WB_DEPTH; j = j + 1) begin
8359
                wb_v[j-1] <= wb_v[j];
8360
                wb_id[j-1] <= wb_id[j];
8361
                wb_rmw[j-1] <= wb_rmw[j];
8362
                wb_sel[j-1] <= wb_sel[j];
8363
                wb_addr[j-1] <= wb_addr[j];
8364
                wb_data[j-1] <= wb_data[j];
8365
                wb_ol[j-1] <= wb_ol[j];
8366
                if (wbptr > 2'd0)
8367
                        wbptr <= wbptr - 2'd1;
8368
        end
8369
        wb_v[`WB_DEPTH-1] <= `INV;
8370
        wb_rmw[`WB_DEPTH-1] <= `FALSE;
8371
    end
8372
 
8373
`endif
8374
      if (~|wb_v && mem1_available && dram0==`DRAMSLOT_BUSY && dram0_rmw) begin
8375
`ifdef SUPPORT_DBG
8376
            if (dbg_smatch0|dbg_lmatch0) begin
8377
                 dramA_v <= `TRUE;
8378
                 dramA_id <= dram0_id;
8379
                 dramA_exc <= `FLT_DBG;
8380
                 dramA_bus <= 64'h0;
8381
                 dram0 <= `DRAMSLOT_AVAIL;
8382
            end
8383
            else
8384
`endif
8385
            if (!acki) begin
8386
                 isRMW <= dram0_rmw;
8387
                 isCAS <= IsCAS(dram0_instr);
8388
                 isAMO <= IsAMO(dram0_instr);
8389
                 isInc <= IsInc(dram0_instr);
8390
                 casid <= dram0_id;
8391
                 bwhich <= 2'b00;
8392
                 dram0 <= `DRAMSLOT_HASBUS;
8393
                 cyc <= `HIGH;
8394
                 stb_o <= `HIGH;
8395
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
8396
                 vadr <= dram0_addr;
8397
                 dat_o <= fnDato(dram0_instr,dram0_data);
8398
                 ol_o  <= dram0_ol;
8399
                 bstate <= B12;
8400
            end
8401
        end
8402
        else if (~|wb_v && mem2_available && dram1==`DRAMSLOT_BUSY && dram1_rmw && `NUM_MEM > 1) begin
8403
`ifdef SUPPORT_DBG
8404
            if (dbg_smatch1|dbg_lmatch1) begin
8405
                 dramB_v <= `TRUE;
8406
                 dramB_id <= dram1_id;
8407
                 dramB_exc <= `FLT_DBG;
8408
                 dramB_bus <= 64'h0;
8409
                 dram1 <= `DRAMSLOT_AVAIL;
8410
            end
8411
            else
8412
`endif
8413
            if (!acki) begin
8414
                 isRMW <= dram1_rmw;
8415
                 isCAS <= IsCAS(dram1_instr);
8416
                 isAMO <= IsAMO(dram1_instr);
8417
                 isInc <= IsInc(dram1_instr);
8418
                 casid <= dram1_id;
8419
                 bwhich <= 2'b01;
8420
                 dram1 <= `DRAMSLOT_HASBUS;
8421
                 cyc <= `HIGH;
8422
                 stb_o <= `HIGH;
8423
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
8424
                 vadr <= dram1_addr;
8425
                 dat_o <= fnDato(dram1_instr,dram1_data);
8426
                 ol_o  <= dram1_ol;
8427
                 bstate <= B12;
8428
            end
8429
        end
8430
        else if (~|wb_v && mem3_available && dram2==`DRAMSLOT_BUSY && dram2_rmw && `NUM_MEM > 2) begin
8431
`ifdef SUPPORT_DBG
8432
            if (dbg_smatch2|dbg_lmatch2) begin
8433
                 dramC_v <= `TRUE;
8434
                 dramC_id <= dram2_id;
8435
                 dramC_exc <= `FLT_DBG;
8436
                 dramC_bus <= 64'h0;
8437
                 dram2 <= `DRAMSLOT_AVAIL;
8438
            end
8439
            else
8440
`endif
8441
            if (!acki) begin
8442
                 isRMW <= dram2_rmw;
8443
                 isCAS <= IsCAS(dram2_instr);
8444
                 isAMO <= IsAMO(dram2_instr);
8445
                 isInc <= IsInc(dram2_instr);
8446
                 casid <= dram2_id;
8447
                 bwhich <= 2'b10;
8448
                 dram2 <= `DRAMSLOT_HASBUS;
8449
                 cyc <= `HIGH;
8450
                 stb_o <= `HIGH;
8451
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
8452
                 vadr <= dram2_addr;
8453
                 dat_o <= fnDato(dram2_instr,dram2_data);
8454
                 ol_o  <= dram2_ol;
8455
                 bstate <= B12;
8456
            end
8457
        end
8458
`ifndef HAS_WB
8459
                                // Check write buffer enable ?
8460
        else if (mem1_available && dram0==`DRAMSLOT_BUSY && dram0_store) begin
8461
`ifdef SUPPORT_DBG
8462
            if (dbg_smatch0) begin
8463
                 dramA_v <= `TRUE;
8464
                 dramA_id <= dram0_id;
8465
                 dramA_exc <= `FLT_DBG;
8466
                 dramA_bus <= 64'h0;
8467
                 dram0 <= `DRAMSLOT_AVAIL;
8468
            end
8469
            else
8470
`endif
8471
            begin
8472
                                                        bwhich <= 2'b00;
8473
                                                        if (!acki) begin
8474
                                                                dram0 <= `DRAMSLOT_HASBUS;
8475
                                                                dram0_instr[`INSTRUCTION_OP] <= `NOP;
8476
                cyc <= `HIGH;
8477
                stb_o <= `HIGH;
8478
                sel_o <= fnSelect(dram0_instr,dram0_addr);
8479
                vadr <= dram0_addr;
8480
                dat_o <= fnDato(dram0_instr,dram0_data);
8481
                ol_o  <= dram0_ol;
8482
                                        isStore <= TRUE;
8483
                bstate <= B_StoreAck;
8484
              end
8485
//                 cr_o <= IsSWC(dram0_instr);
8486
            end
8487
        end
8488
        else if (mem2_available && dram1==`DRAMSLOT_BUSY && dram1_store && `NUM_MEM > 1) begin
8489
`ifdef SUPPORT_DBG
8490
            if (dbg_smatch1) begin
8491
                 dramB_v <= `TRUE;
8492
                 dramB_id <= dram1_id;
8493
                 dramB_exc <= `FLT_DBG;
8494
                 dramB_bus <= 64'h0;
8495
                 dram1 <= `DRAMSLOT_AVAIL;
8496
            end
8497
            else
8498
`endif
8499
            begin
8500
                 bwhich <= 2'b01;
8501
                                                        if (!acki) begin
8502
                dram1 <= `DRAMSLOT_HASBUS;
8503
                dram1_instr[`INSTRUCTION_OP] <= `NOP;
8504
                cyc <= `HIGH;
8505
                stb_o <= `HIGH;
8506
                sel_o <= fnSelect(dram1_instr,dram1_addr);
8507
                vadr <= dram1_addr;
8508
                dat_o <= fnDato(dram1_instr,dram1_data);
8509
                ol_o  <= dram1_ol;
8510
                                        isStore <= TRUE;
8511
                bstate <= B_StoreAck;
8512
              end
8513
//                 cr_o <= IsSWC(dram0_instr);
8514
            end
8515
        end
8516
        else if (mem3_available && dram2==`DRAMSLOT_BUSY && dram2_store && `NUM_MEM > 2) begin
8517
`ifdef SUPPORT_DBG
8518
            if (dbg_smatch2) begin
8519
                 dramC_v <= `TRUE;
8520
                 dramC_id <= dram2_id;
8521
                 dramC_exc <= `FLT_DBG;
8522
                 dramC_bus <= 64'h0;
8523
                 dram2 <= `DRAMSLOT_AVAIL;
8524
            end
8525
            else
8526
`endif
8527
            begin
8528
                 bwhich <= 2'b10;
8529
                                                        if (!acki) begin
8530
                dram2 <= `DRAMSLOT_HASBUS;
8531
                dram2_instr[`INSTRUCTION_OP] <= `NOP;
8532
                cyc <= `HIGH;
8533
                stb_o <= `HIGH;
8534
                sel_o <= fnSelect(dram2_instr,dram2_addr);
8535
                vadr <= dram2_addr;
8536
                dat_o <= fnDato(dram2_instr,dram2_data);
8537
                ol_o  <= dram2_ol;
8538
                                        isStore <= TRUE;
8539
                bstate <= B_StoreAck;
8540
              end
8541
//                 cr_o <= IsSWC(dram0_instr);
8542
            end
8543
        end
8544
`endif
8545
        // Check for read misses on the data cache
8546
        else if (~|wb_v && mem1_available && !dram0_unc && dram0==`DRAMSLOT_REQBUS && dram0_load) begin
8547
`ifdef SUPPORT_DBG
8548
            if (dbg_lmatch0) begin
8549
               dramA_v <= `TRUE;
8550
               dramA_id <= dram0_id;
8551
               dramA_exc <= `FLT_DBG;
8552
               dramA_bus <= 64'h0;
8553
               dram0 <= `DRAMSLOT_AVAIL;
8554
            end
8555
            else
8556
`endif
8557
            begin
8558
               dram0 <= `DRAMSLOT_HASBUS;
8559
               bwhich <= 2'b00;
8560
               preload <= dram0_preload;
8561
               bstate <= B_DCacheLoadStart;
8562
            end
8563
        end
8564
        else if (~|wb_v && mem2_available && !dram1_unc && dram1==`DRAMSLOT_REQBUS && dram1_load && `NUM_MEM > 1) begin
8565
`ifdef SUPPORT_DBG
8566
            if (dbg_lmatch1) begin
8567
               dramB_v <= `TRUE;
8568
               dramB_id <= dram1_id;
8569
               dramB_exc <= `FLT_DBG;
8570
               dramB_bus <= 64'h0;
8571
               dram1 <= `DRAMSLOT_AVAIL;
8572
            end
8573
            else
8574
`endif
8575
            begin
8576
               dram1 <= `DRAMSLOT_HASBUS;
8577
               bwhich <= 2'b01;
8578
               preload <= dram1_preload;
8579
               bstate <= B_DCacheLoadStart;
8580
            end
8581
        end
8582
        else if (~|wb_v && mem3_available && !dram2_unc && dram2==`DRAMSLOT_REQBUS && dram2_load && `NUM_MEM > 2) begin
8583
`ifdef SUPPORT_DBG
8584
            if (dbg_lmatch2) begin
8585
               dramC_v <= `TRUE;
8586
               dramC_id <= dram2_id;
8587
               dramC_exc <= `FLT_DBG;
8588
               dramC_bus <= 64'h0;
8589
               dram2 <= `DRAMSLOT_AVAIL;
8590
            end
8591
            else
8592
`endif
8593
            begin
8594
               dram2 <= `DRAMSLOT_HASBUS;
8595
               preload <= dram2_preload;
8596
               bwhich <= 2'b10;
8597
               bstate <= B_DCacheLoadStart;
8598
            end
8599
        end
8600
        else if (~|wb_v && mem1_available && dram0_unc && dram0==`DRAMSLOT_BUSY && dram0_load) begin
8601
`ifdef SUPPORT_DBG
8602
            if (dbg_lmatch0) begin
8603
               dramA_v <= `TRUE;
8604
               dramA_id <= dram0_id;
8605
               dramA_exc <= `FLT_DBG;
8606
               dramA_bus <= 64'h0;
8607
               dram0 <= `DRAMSLOT_AVAIL;
8608
            end
8609
            else
8610
`endif
8611
            if (!acki) begin
8612
               bwhich <= 2'b00;
8613
               cyc <= `HIGH;
8614
               stb_o <= `HIGH;
8615
               sel_o <= fnSelect(dram0_instr,dram0_addr);
8616
               vadr <= {dram0_addr[AMSB:3],3'b0};
8617
               sr_o <=  IsLWR(dram0_instr);
8618
               ol_o  <= dram0_ol;
8619
               bstate <= B_DLoadAck;
8620
            end
8621
        end
8622
        else if (~|wb_v && mem2_available && dram1_unc && dram1==`DRAMSLOT_BUSY && dram1_load && `NUM_MEM > 1) begin
8623
`ifdef SUPPORT_DBG
8624
            if (dbg_lmatch1) begin
8625
               dramB_v <= `TRUE;
8626
               dramB_id <= dram1_id;
8627
               dramB_exc <= `FLT_DBG;
8628
               dramB_bus <= 64'h0;
8629
               dram1 <= `DRAMSLOT_AVAIL;
8630
            end
8631
            else
8632
`endif
8633
            if (!acki) begin
8634
               bwhich <= 2'b01;
8635
               cyc <= `HIGH;
8636
               stb_o <= `HIGH;
8637
               sel_o <= fnSelect(dram1_instr,dram1_addr);
8638
               vadr <= {dram1_addr[AMSB:3],3'b0};
8639
               sr_o <=  IsLWR(dram1_instr);
8640
               ol_o  <= dram1_ol;
8641
               bstate <= B_DLoadAck;
8642
            end
8643
        end
8644
        else if (~|wb_v && mem3_available && dram2_unc && dram2==`DRAMSLOT_BUSY && dram2_load && `NUM_MEM > 2) begin
8645
`ifdef SUPPORT_DBG
8646
            if (dbg_lmatch2) begin
8647
               dramC_v <= `TRUE;
8648
               dramC_id <= dram2_id;
8649
               dramC_exc <= `FLT_DBG;
8650
               dramC_bus <= 64'h0;
8651
               dram2 <= 2'd0;
8652
            end
8653
            else
8654
`endif
8655
            if (!acki) begin
8656
               bwhich <= 2'b10;
8657
               cyc <= `HIGH;
8658
               stb_o <= `HIGH;
8659
               sel_o <= fnSelect(dram2_instr,dram2_addr);
8660
               vadr <= {dram2_addr[AMSB:3],3'b0};
8661
               sr_o <=  IsLWR(dram2_instr);
8662
               ol_o  <= dram2_ol;
8663
               bstate <= B_DLoadAck;
8664
            end
8665
        end
8666
        // Check for L2 cache miss
8667
        else if (~|wb_v && !ihitL2 && !acki) begin
8668
           cti_o <= 3'b001;
8669
           bte_o <= 2'b00;//2'b01;      // 4 beat burst wrap
8670
           cyc <= `HIGH;
8671
           stb_o <= `HIGH;
8672
           sel_o <= 8'hFF;
8673
           icl_o <= `HIGH;
8674
           iccnt <= 3'd0;
8675
//            adr_o <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
8676
//            L2_adr <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
8677
           vadr <= {pcr[7:0],L1_adr[AMSB:5],5'h0};
8678
           ol_o  <= ol[0];
8679
           L2_adr <= {pcr[7:0],L1_adr[AMSB:5],5'h0};
8680
           L2_xsel <= 1'b0;
8681
           bstate <= B_ICacheAck;
8682
        end
8683
    end
8684
 
8685
// Terminal state for a store operation.
8686
// Note that if only a single memory channel is selected, bwhich will be a
8687
// constant 0. This should cause the extra code to be removed.
8688
B_StoreAck:
8689
        begin
8690
                StoreAck1 <= `TRUE;
8691
                isStore <= `TRUE;
8692
        if (acki|err_i|tlb_miss|wrv_i) begin
8693
                wb_nack();
8694
                cr_o <= 1'b0;
8695
    // This isn't a good way of doing things; the state should be propagated
8696
    // to the commit stage, however since this is a store we know there will
8697
    // be no change of program flow. So the reservation status bit is set
8698
    // here. The author wanted to avoid the complexity of propagating the
8699
    // input signal to the commit stage. It does mean that the SWC
8700
    // instruction should be surrounded by SYNC's.
8701
    if (cr_o)
8702
                        sema[0] <= rbi_i;
8703
`ifdef HAS_WB
8704
                for (n = 0; n < QENTRIES; n = n + 1) begin
8705
                        if (wbo_id[n]) begin
8706
        iqentry_exc[n] <= tlb_miss ? `FLT_TLB : wrv_i ? `FLT_DWF : err_i ? `FLT_IBE : `FLT_NONE;
8707
        if (err_i|wrv_i) begin
8708
                wb_v <= 1'b0;                   // Invalidate write buffer if there is a problem with the store
8709
                wb_en <= `FALSE;        // and disable write buffer
8710
        end
8711
        iqentry_state[n] <= IQS_CMT;
8712
                                iqentry_aq[n] <= `INV;
8713
                        end
8714
                end
8715
`else
8716
    case(bwhich)
8717
    2'd0:   begin
8718
                dram0 <= `DRAMSLOT_AVAIL;
8719
                iqentry_exc[dram0_id[`QBITS]] <= (wrv_i|err_i) ? `FLT_DWF : `FLT_NONE;
8720
                                iqentry_state[dram0_id[`QBITS]] <= IQS_CMT;
8721
                                                        iqentry_aq[ dram0_id[`QBITS] ] <= `INV;
8722
                //iqentry_out[ dram0_id[`QBITS] ] <= `INV;
8723
            end
8724
    2'd1:   if (`NUM_MEM > 1) begin
8725
                dram1 <= `DRAMSLOT_AVAIL;
8726
                iqentry_exc[dram1_id[`QBITS]] <= (wrv_i|err_i) ? `FLT_DWF : `FLT_NONE;
8727
                                iqentry_state[dram1_id[`QBITS]] <= IQS_CMT;
8728
                                                        iqentry_aq[ dram1_id[`QBITS] ] <= `INV;
8729
                //iqentry_out[ dram1_id[`QBITS] ] <= `INV;
8730
            end
8731
    2'd2:   if (`NUM_MEM > 2) begin
8732
                dram2 <= `DRAMSLOT_AVAIL;
8733
                iqentry_exc[dram2_id[`QBITS]] <= (wrv_i|err_i) ? `FLT_DWF : `FLT_NONE;
8734
                                iqentry_state[dram2_id[`QBITS]] <= IQS_CMT;
8735
                                                        iqentry_aq[ dram2_id[`QBITS] ] <= `INV;
8736
                //iqentry_out[ dram2_id[`QBITS] ] <= `INV;
8737
            end
8738
    default:    ;
8739
    endcase
8740
`endif
8741
                bstate <= B19;
8742
  end
8743
        end
8744
 
8745
B_DCacheLoadStart:
8746
  if (~acki & ~cyc) begin       // check for idle bus - it should be
8747
    dccnt <= 2'd0;
8748
    bstate <= B_DCacheLoadAck;
8749
                cti_o <= 3'b001;        // constant address burst
8750
                bte_o <= 2'b00;         // linear burst, non-wrapping
8751
                cyc <= `HIGH;
8752
                stb_o <= `HIGH;
8753
                // Select should be selecting all byte lanes for a cache load
8754
    sel_o <= 8'hFF;
8755
                // bwhich should always be one of the three channels.
8756
    case(bwhich)
8757
    2'd0:   begin
8758
             vadr <= {dram0_addr[AMSB:5],5'b0};
8759
             ol_o  <= dram0_ol;
8760
            end
8761
    2'd1:   if (`NUM_MEM > 1) begin
8762
             vadr <= {dram1_addr[AMSB:5],5'b0};
8763
             ol_o  <= dram1_ol;
8764
            end
8765
    2'd2:   if (`NUM_MEM > 2) begin
8766
             vadr <= {dram2_addr[AMSB:5],5'b0};
8767
             ol_o  <= dram2_ol;
8768
            end
8769
    default:
8770
      begin
8771
        $display("Invalid memory channel selection");
8772
        $stop;
8773
        wb_nack();
8774
                bstate <= BIDLE;
8775
        end
8776
    endcase
8777
  end
8778
 
8779
// Data cache load terminal state
8780
B_DCacheLoadAck:
8781
  if (ack_i|err_i|tlb_miss|rdv_i) begin
8782
        if (!bok_i) begin
8783
                stb_o <= `LOW;
8784
                bstate <= B_DCacheLoadStb;
8785
        end
8786
    errq <= errq | err_i;
8787
    rdvq <= rdvq | rdv_i;
8788
    if (!preload)       // A preload instruction ignores any error
8789
    case(bwhich)
8790
    2'd0:   if (err_i|rdv_i|tlb_miss) begin
8791
               iqentry_exc[dram0_id[`QBITS]] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DBE : `FLT_DRF;
8792
            end
8793
    2'd1:   if ((err_i|rdv_i|tlb_miss) && `NUM_MEM > 1) begin
8794
               iqentry_exc[dram1_id[`QBITS]] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DBE : `FLT_DRF;
8795
            end
8796
    2'd2:   if ((err_i|rdv_i|tlb_miss) && `NUM_MEM > 2) begin
8797
               iqentry_exc[dram2_id[`QBITS]] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DBE : `FLT_DRF;
8798
            end
8799
    default:    ;
8800
    endcase
8801
    dccnt <= dccnt + 2'd1;
8802
    vadr[4:3] <= vadr[4:3] + 2'd1;
8803
    bstate <= B_DCacheLoadAck;
8804
    if (dccnt==2'd2)
8805
                        cti_o <= 3'b111;
8806
    if (dccnt==2'd3) begin
8807
        wb_nack();
8808
                        bstate <= B_DCacheLoadWait1;
8809
    end
8810
  end
8811
 
8812
B_DCacheLoadStb:
8813
        begin
8814
                stb_o <= `HIGH;
8815
                bstate <= B_DCacheLoadAck;
8816
  end
8817
B_DCacheLoadWait1: bstate <= B_DCacheLoadWait2;
8818
B_DCacheLoadWait2: bstate <= B_DCacheLoadResetBusy;
8819
//B_DCacheLoadWait3: bstate <= B_DCacheLoadResetBusy;
8820
B_DCacheLoadResetBusy: begin
8821
    // There could be more than one memory cycle active. We reset the state
8822
    // of all the machines to retest for a hit because otherwise sequential
8823
    // loading of memory will cause successive machines to miss resulting in 
8824
    // multiple dcache loads that aren't needed.
8825
    if (dram0 != `DRAMSLOT_AVAIL && dram0_addr[AMSB:5]==vadr[AMSB:5]) dram0 <= `DRAMSLOT_BUSY;  // causes retest of dhit
8826
    if (dram1 != `DRAMSLOT_AVAIL && dram1_addr[AMSB:5]==vadr[AMSB:5]) dram1 <= `DRAMSLOT_BUSY;
8827
    if (dram2 != `DRAMSLOT_AVAIL && dram2_addr[AMSB:5]==vadr[AMSB:5]) dram2 <= `DRAMSLOT_BUSY;
8828
    if (~ack_i)  bstate <= BIDLE;
8829
    end
8830
 
8831
// Ack state for instruction cache load
8832
B_ICacheAck:
8833
  if (ack_i|err_i|tlb_miss|exv_i) begin
8834
        if (!bok_i) begin
8835
                stb_o <= `LOW;
8836
                bstate <= B_ICacheNack2;
8837
        end
8838
    errq <= errq | err_i;
8839
    exvq <= exvq | exv_i;
8840
//        L1_en <= 9'h3 << {L2_xsel,L2_adr[4:3],1'b0};
8841
//        L1_wr0 <= `TRUE;
8842
//        L1_wr1 <= `TRUE;
8843
//        L1_adr <= L2_adr;
8844
                if (tlb_miss) begin
8845
                        L2_rdat <= {18{`INSN_FLT_TLB}};
8846
                        wb_nack();
8847
      icl_o <= `LOW;
8848
      bstate <= B_ICacheNack;
8849
    end
8850
                else if (exv_i) begin
8851
                        L2_rdat <= {18{`INSN_FLT_EXF}};
8852
                        wb_nack();
8853
      icl_o <= `LOW;
8854
      bstate <= B_ICacheNack;
8855
                end
8856
    else if (err_i) begin
8857
        L2_rdat <= {18{`INSN_FLT_IBE}};
8858
                        wb_nack();
8859
      icl_o <= `LOW;
8860
      bstate <= B_ICacheNack;
8861
    end
8862
    else
8863
        case(iccnt)
8864
        3'd0:   L2_rdat[63:0] <= dat_i;
8865
        3'd1:   L2_rdat[127:64] <= dat_i;
8866
        3'd2:   L2_rdat[191:128] <= dat_i;
8867
        3'd3:   L2_rdat[255:192] <= dat_i;
8868
        3'd4:   L2_rdat[297:256] <= {2'b00,dat_i[39:0]};
8869
        default:        ;
8870
        endcase
8871
        //L2_rdat <= {dat_i[31:0],{4{dat_i}}};
8872
    iccnt <= iccnt + 3'd1;
8873
    //stb_o <= `LOW;
8874
    if (iccnt==3'd3)
8875
      cti_o <= 3'b111;
8876
    if (iccnt==3'd4) begin
8877
                        wb_nack();
8878
      icl_o <= `LOW;
8879
      bstate <= B_ICacheNack;
8880
    end
8881
    else begin
8882
      L2_adr[4:3] <= L2_adr[4:3] + 2'd1;
8883
      if (L2_adr[4:3]==2'b11)
8884
        L2_xsel <= 1'b1;
8885
    end
8886
  end
8887
B_ICacheNack2:
8888
        if (~acki) begin
8889
                stb_o <= `HIGH;
8890
                vadr[AMSB:3] <= vadr[AMSB:3] + 2'd1;
8891
                bstate <= B_ICacheAck;
8892
        end
8893
B_ICacheNack:
8894
        begin
8895
                L1_wr0 <= `FALSE;
8896
                L1_wr1 <= `FALSE;
8897
                L1_wr2 <= `FALSE;
8898
                L1_en <= 9'h1FF;
8899
                L2_xsel <= 1'b0;
8900
                if (~ack_i) begin
8901
                        icl_ctr <= icl_ctr + 40'd1;
8902
                        bstate <= BIDLE;
8903
                        L2_nxt <= TRUE;
8904
                end
8905
        end
8906
B12:
8907
    if (ack_i|err_i|tlb_miss|rdv_i) begin
8908
        if (isCAS) begin
8909
             iqentry_res        [ casid[`QBITS] ] <= (dat_i == cas);
8910
             iqentry_exc [ casid[`QBITS] ] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8911
//             iqentry_done[ casid[`QBITS] ] <= `VAL;
8912
//           iqentry_out [ casid[`QBITS] ] <= `INV;
8913
             iqentry_state [ casid[`QBITS] ] <= IQS_DONE;
8914
             iqentry_instr[ casid[`QBITS]] <= `NOP_INSN;
8915
            if (err_i | rdv_i) iqentry_ma[casid[`QBITS]] <= vadr;
8916
            if (dat_i == cas) begin
8917
                 stb_o <= `LOW;
8918
                 we <= `TRUE;
8919
                 bstate <= B15;
8920
            end
8921
            else begin
8922
                 cas <= dat_i;
8923
                 cyc <= `LOW;
8924
                 stb_o <= `LOW;
8925
                case(bwhich)
8926
                2'b00:   dram0 <= `DRAMREQ_READY;
8927
                2'b01:   dram1 <= `DRAMREQ_READY;
8928
                2'b10:   dram2 <= `DRAMREQ_READY;
8929
                default:    ;
8930
                endcase
8931
                 bstate <= B19;
8932
            end
8933
        end
8934
        else if (isRMW) begin
8935
             rmw_instr <= iqentry_instr[casid[`QBITS]];
8936
             rmw_argA <= dat_i;
8937
                 if (isSpt) begin
8938
                        rmw_argB <= 64'd1 << iqentry_a1[casid[`QBITS]][63:58];
8939
                        rmw_argC <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ?
8940
                                                iqentry_a3[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58] :
8941
                                                iqentry_a2[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58];
8942
                 end
8943
                 else if (isInc) begin
8944
                        rmw_argB <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ? {{59{iqentry_instr[casid[`QBITS]][22]}},iqentry_instr[casid[`QBITS]][22:18]} :
8945
                                                                                                                                 {{59{iqentry_instr[casid[`QBITS]][17]}},iqentry_instr[casid[`QBITS]][17:13]};
8946
                 end
8947
                 else begin // isAMO
8948
                     iqentry_res [ casid[`QBITS] ] <= dat_i;
8949
                     rmw_argB <= iqentry_instr[casid[`QBITS]][31] ? {{59{iqentry_instr[casid[`QBITS]][20:16]}},iqentry_instr[casid[`QBITS]][20:16]} : iqentry_a2[casid[`QBITS]];
8950
                 end
8951
             iqentry_exc [ casid[`QBITS] ] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8952
             stb_o <= `LOW;
8953
             bstate <= B20;
8954
                end
8955
    end
8956
 
8957
// Regular load
8958
B_DLoadAck:
8959
  if (ack_i|err_i|tlb_miss|rdv_i) begin
8960
        wb_nack();
8961
                sr_o <= `LOW;
8962
                xdati <= dat_i;
8963
    case(bwhich)
8964
    2'b00:  begin
8965
             dram0 <= `DRAMREQ_READY;
8966
             iqentry_exc [ dram0_id[`QBITS] ] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8967
            end
8968
    2'b01:  if (`NUM_MEM > 1) begin
8969
             dram1 <= `DRAMREQ_READY;
8970
             iqentry_exc [ dram1_id[`QBITS] ] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8971
            end
8972
    2'b10:  if (`NUM_MEM > 2) begin
8973
             dram2 <= `DRAMREQ_READY;
8974
             iqentry_exc [ dram2_id[`QBITS] ] <= tlb_miss ? `FLT_TLB : err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8975
            end
8976
    default:    ;
8977
    endcase
8978
                bstate <= B19;
8979
        end
8980
 
8981
// Three cycles to detemrine if there's a cache hit during a store.
8982
B16:    begin
8983
            case(bwhich)
8984
            2'd0:      if (dhit0) begin  dram0 <= `DRAMREQ_READY; bstate <= B17; end
8985
            2'd1:      if (dhit1) begin  dram1 <= `DRAMREQ_READY; bstate <= B17; end
8986
            2'd2:      if (dhit2) begin  dram2 <= `DRAMREQ_READY; bstate <= B17; end
8987
            default:    bstate <= BIDLE;
8988
            endcase
8989
            end
8990
B17:     bstate <= B18;
8991
B18:     bstate <= B19;
8992
B19:    if (~acki)  begin
8993
                                        sel_o <= 8'h00;
8994
                                        bstate <= BIDLE;
8995
                                        StoreAck1 <= `FALSE;
8996
                                        isStore <= `FALSE;
8997
                                end
8998
B20:
8999
        if (~ack_i) begin
9000
                stb_o <= `HIGH;
9001
                we  <= `HIGH;
9002
                dat_o <= fnDato(rmw_instr,rmw_res);
9003
                bstate <= B_StoreAck;
9004
        end
9005
B21:
9006
        if (~ack_i) begin
9007
                stb_o <= `HIGH;
9008
                bstate <= B12;
9009
        end
9010
default:     bstate <= BIDLE;
9011
endcase
9012
 
9013
if (!branchmiss) begin
9014
    case({fetchbuf0_v, fetchbuf1_v})
9015
    2'b00:  ;
9016
    2'b01:
9017
        if (canq1) begin
9018
                tail0 <= (tail0+2'd1) % QENTRIES;
9019
                tail1 <= (tail1+2'd1) % QENTRIES;
9020
        end
9021
    2'b10:
9022
        if (canq1) begin
9023
                tail0 <= (tail0+2'd1) % QENTRIES;
9024
                tail1 <= (tail1+2'd1) % QENTRIES;
9025
        end
9026
    2'b11:
9027
        if (canq1) begin
9028
            if (IsBranch(fetchbuf0_instr) && predict_taken0 && fetchbuf0_thrd==fetchbuf1_thrd) begin
9029
                        tail0 <= (tail0+2'd1) % QENTRIES;
9030
                        tail1 <= (tail1+2'd1) % QENTRIES;
9031
            end
9032
            else begin
9033
                                if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
9034
                        if (canq2) begin
9035
                          tail0 <= (tail0 + 3'd2) % QENTRIES;
9036
                          tail1 <= (tail1 + 3'd2) % QENTRIES;
9037
                        end
9038
                        else begin    // queued1 will be true
9039
                                                tail0 <= (tail0+2'd1) % QENTRIES;
9040
                                                tail1 <= (tail1+2'd1) % QENTRIES;
9041
                        end
9042
                end
9043
            end
9044
        end
9045
    endcase
9046
end
9047
else if (!thread_en) begin      // if branchmiss
9048
        for (n = QENTRIES-1; n >= 0; n = n - 1)
9049
                // (QENTRIES-1) is needed to ensure that n increments forwards so that the modulus is
9050
                // a positive number.
9051
                if (iqentry_stomp[n] & ~iqentry_stomp[(n+(QENTRIES-1))%QENTRIES]) begin
9052
                        tail0 <= n;
9053
                        tail1 <= (n + 1) % QENTRIES;
9054
                end
9055
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
9056
end
9057
 
9058
//      #5 rf[0] = 0; rf_v[0] = 1; rf_source[0] = 0;
9059
`ifdef SIM
9060
        $display("\n\n\n\n\n\n\n\n");
9061
        $display("TIME %0d", $time);
9062
        $display("%h #", pc0);
9063
`ifdef SUPPORT_SMT
9064
    $display ("Regfile: %d", rgs[0]);
9065
        for (n=0; n < 32; n=n+4) begin
9066
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
9067
               n[4:0]+0, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
9068
               n[4:0]+1, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
9069
               n[4:0]+2, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
9070
               n[4:0]+3, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
9071
               );
9072
        end
9073
    $display ("Regfile: %d", rgs[1]);
9074
        for (n=128; n < 160; n=n+4) begin
9075
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
9076
               n[4:0]+0, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
9077
               n[4:0]+1, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
9078
               n[4:0]+2, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
9079
               n[4:0]+3, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
9080
               );
9081
        end
9082
`else
9083
    $display ("Regfile: %d", rgs);
9084
        for (n=0; n < 32; n=n+4) begin
9085
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
9086
               n[4:0]+0, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
9087
               n[4:0]+1, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
9088
               n[4:0]+2, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
9089
               n[4:0]+3, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
9090
               );
9091
        end
9092
`endif
9093
`ifdef FCU_ENH
9094
        $display("Call Stack:");
9095
        for (n = 0; n < 16; n = n + 4)
9096
                $display("%c%d: %h   %c%d: %h   %c%d: %h   %c%d: %h",
9097
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+0 ?">" : " ", n[4:0]+0, gFetchbufInst.gb1.ufb1.ursb1.ras[n+0],
9098
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+1 ?">" : " ", n[4:0]+1, gFetchbufInst.gb1.ufb1.ursb1.ras[n+1],
9099
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+2 ?">" : " ", n[4:0]+2, gFetchbufInst.gb1.ufb1.ursb1.ras[n+2],
9100
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+3 ?">" : " ", n[4:0]+3, gFetchbufInst.gb1.ufb1.ursb1.ras[n+3]
9101
                );
9102
        $display("\n");
9103
`endif
9104
//    $display("Return address stack:");
9105
//    for (n = 0; n < 16; n = n + 1)
9106
//        $display("%d %h", rasp+n[3:0], ras[rasp+n[3:0]]);
9107
        $display("TakeBr:%d #", take_branch);//, backpc);
9108
        $display("Insn%d: %h", 0, insn0);
9109
        if (`WAYS==1) begin
9110
        $display("%c%c A: %d %h %h #",
9111
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
9112
        $display("%c%c B: %d %h %h #",
9113
            45, fetchbuf?62:45, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
9114
        end
9115
        else if (`WAYS > 1) begin
9116
                $display("Insn%d: %h", 1, insn1);
9117
        $display("%c%c A: %d %h %h #",
9118
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
9119
        $display("%c%c B: %d %h %h #",
9120
            45, fetchbuf?45:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
9121
        end
9122
        else if (`WAYS > 2) begin
9123
                $display("%c%c C: %d %h %h #",
9124
                    45, fetchbuf?62:45, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
9125
                $display("%c%c D: %d %h %h #",
9126
                    45, fetchbuf?62:45, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
9127
        end
9128
        for (i=0; i<QENTRIES; i=i+1)
9129
            $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#",
9130
                 (i[`QBITS]==heads[0])?"C":".",
9131
                 (i[`QBITS]==tail0)?"Q":".",
9132
                  i[`QBITS],
9133
                 iqentry_v[i] ? "v" : "-",
9134
                 iqentry_iv[i] ? "I" : "-",
9135
                 iqentry_done[i]?"d":"-",
9136
                 iqentry_out[i]?"o":"-",
9137
                 iqentry_bt[i],
9138
                 iqentry_memissue[i],
9139
                 iqentry_agen[i] ? "a": "-",
9140
                 iqentry_alu0_issue[i]?"0":iqentry_alu1_issue[i]?"1":"-",
9141
                 iqentry_stomp[i]?"s":"-",
9142
                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",
9143
                iqentry_instr[i], iqentry_tgt[i][4:0],
9144
                iqentry_exc[i], iqentry_res[i], iqentry_a0[i], iqentry_a1[i], iqentry_a1_v[i],
9145
                iqentry_a1_s[i],
9146
                iqentry_a2[i], iqentry_a2_v[i], iqentry_a2_s[i],
9147
                iqentry_a3[i], iqentry_a3_v[i], iqentry_a3_s[i],
9148
                iqentry_thrd[i],
9149
                iqentry_pc[i],
9150
                iqentry_sn[i], iqentry_ven[i]
9151
                );
9152
    $display("DRAM");
9153
        $display("%d %h %h %c%h %o #",
9154
            dram0, dram0_addr, dram0_data, (IsFlowCtrl(dram0_instr) ? 98 : (IsMem(dram0_instr)) ? 109 : 97),
9155
            dram0_instr, dram0_id);
9156
          if (`NUM_MEM > 1)
9157
        $display("%d %h %h %c%h %o #",
9158
            dram1, dram1_addr, dram1_data, (IsFlowCtrl(dram1_instr) ? 98 : (IsMem(dram1_instr)) ? 109 : 97),
9159
            dram1_instr, dram1_id);
9160
          if (`NUM_MEM > 2)
9161
        $display("%d %h %h %c%h %o #",
9162
            dram2, dram2_addr, dram2_data, (IsFlowCtrl(dram2_instr) ? 98 : (IsMem(dram2_instr)) ? 109 : 97),
9163
            dram2_instr, dram2_id);
9164
        $display("%d %h %o %h #", dramA_v, dramA_bus, dramA_id, dramA_exc);
9165
        if (`NUM_MEM > 1)
9166
        $display("%d %h %o %h #", dramB_v, dramB_bus, dramB_id, dramB_exc);
9167
        if (`NUM_MEM > 2)
9168
        $display("%d %h %o %h #", dramC_v, dramC_bus, dramC_id, dramC_exc);
9169
    $display("ALU");
9170
        $display("%d %h %h %h %c%h %o %h #",
9171
                alu0_dataready, alu0_argI, alu0_argA, alu0_argB,
9172
                 (IsFlowCtrl(alu0_instr) ? 98 : IsMem(alu0_instr) ? 109 : 97),
9173
                alu0_instr, alu0_sourceid, alu0_pc);
9174
        $display("%d %h %o 0 #", alu0_v, alu0_bus, alu0_id);
9175
        if (`NUM_ALU > 1) begin
9176
                $display("%d %h %h %h %c%h %o %h #",
9177
                        alu1_dataready, alu1_argI, alu1_argA, alu1_argB,
9178
                        (IsFlowCtrl(alu1_instr) ? 98 : IsMem(alu1_instr) ? 109 : 97),
9179
                        alu1_instr, alu1_sourceid, alu1_pc);
9180
                $display("%d %h %o 0 #", alu1_v, alu1_bus, alu1_id);
9181
        end
9182
        $display("FCU");
9183
        $display("%d %h %h %h %h %c%c #", fcu_v, fcu_bus, fcu_argI, fcu_argA, fcu_argB, fcu_takb?"T":"-", fcu_pt?"T":"-");
9184
        $display("%c %h %h %h %h #", fcu_branchmiss?"m":" ", fcu_sourceid, fcu_misspc, fcu_nextpc, fcu_brdisp);
9185
    $display("Commit");
9186
        $display("0: %c %h %o %d #", commit0_v?"v":" ", commit0_bus, commit0_id, commit0_tgt[4:0]);
9187
        $display("1: %c %h %o %d #", commit1_v?"v":" ", commit1_bus, commit1_id, commit1_tgt[4:0]);
9188
    $display("instructions committed: %d valid committed: %d ticks: %d ", CC, I, tick);
9189
  $display("Write Buffer:");
9190
  for (n = `WB_DEPTH-1; n >= 0; n = n - 1)
9191
        $display("%c adr: %h dat: %h", wb_v[n]?" ":"*", wb_addr[n], wb_data[n]);
9192
    $display("Write merges: %d", wb_merges);
9193
`endif  // SIM
9194
 
9195
//
9196
//      $display("\n\n\n\n\n\n\n\n");
9197
//      $display("TIME %0d", $time);
9198
//      $display("  pc0=%h", pc0);
9199
//      $display("  pc1=%h", pc1);
9200
//      $display("  reg0=%h, v=%d, src=%o", rf[0], rf_v[0], rf_source[0]);
9201
//      $display("  reg1=%h, v=%d, src=%o", rf[1], rf_v[1], rf_source[1]);
9202
//      $display("  reg2=%h, v=%d, src=%o", rf[2], rf_v[2], rf_source[2]);
9203
//      $display("  reg3=%h, v=%d, src=%o", rf[3], rf_v[3], rf_source[3]);
9204
//      $display("  reg4=%h, v=%d, src=%o", rf[4], rf_v[4], rf_source[4]);
9205
//      $display("  reg5=%h, v=%d, src=%o", rf[5], rf_v[5], rf_source[5]);
9206
//      $display("  reg6=%h, v=%d, src=%o", rf[6], rf_v[6], rf_source[6]);
9207
//      $display("  reg7=%h, v=%d, src=%o", rf[7], rf_v[7], rf_source[7]);
9208
 
9209
//      $display("Fetch Buffers:");
9210
//      $display("  %c%c fbA: v=%d instr=%h pc=%h     %c%c fbC: v=%d instr=%h pc=%h", 
9211
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc,
9212
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
9213
//      $display("  %c%c fbB: v=%d instr=%h pc=%h     %c%c fbD: v=%d instr=%h pc=%h", 
9214
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc,
9215
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
9216
//      $display("  branchback=%d backpc=%h", branchback, backpc);
9217
 
9218
//      $display("Instruction Queue:");
9219
//      for (i=0; i<8; i=i+1) 
9220
//          $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",
9221
//              (i[`QBITS]==heads[0])?72:32, (i[`QBITS]==tail0)?84:32, i,
9222
//              iqentry_v[i], iqentry_done[i], iqentry_out[i], iqentry_agen[i], iqentry_res[i], iqentry_op[i], 
9223
//              iqentry_bt[i], iqentry_tgt[i], iqentry_a1[i], iqentry_a1_v[i], iqentry_a1_s[i], iqentry_a2[i], iqentry_a2_v[i], 
9224
//              iqentry_a2_s[i], iqentry_a0[i], iqentry_pc[i], iqentry_exc[i]);
9225
 
9226
//      $display("Scheduling Status:");
9227
//      $display("  iqentry0 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
9228
//              iqentry_0_issue, iqentry_0_islot, iqentry_stomp[0], iqentry_source[0], iqentry_memready[0], iqentry_memissue[0]);
9229
//      $display("  iqentry1 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
9230
//              iqentry_1_issue, iqentry_1_islot, iqentry_stomp[1], iqentry_source[1], iqentry_memready[1], iqentry_memissue[1]);
9231
//      $display("  iqentry2 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
9232
//              iqentry_2_issue, iqentry_2_islot, iqentry_stomp[2], iqentry_source[2], iqentry_memready[2], iqentry_memissue[2]);
9233
//      $display("  iqentry3 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
9234
//              iqentry_3_issue, iqentry_3_islot, iqentry_stomp[3], iqentry_source[3], iqentry_memready[3], iqentry_memissue[3]);
9235
//      $display("  iqentry4 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
9236
//              iqentry_4_issue, iqentry_4_islot, iqentry_stomp[4], iqentry_source[4], iqentry_memready[4], iqentry_memissue[4]);
9237
//      $display("  iqentry5 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
9238
//              iqentry_5_issue, iqentry_5_islot, iqentry_stomp[5], iqentry_source[5], iqentry_memready[5], iqentry_memissue[5]);
9239
//      $display("  iqentry6 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
9240
//              iqentry_6_issue, iqentry_6_islot, iqentry_stomp[6], iqentry_source[6], iqentry_memready[6], iqentry_memissue[6]);
9241
//      $display("  iqentry7 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
9242
//              iqentry_7_issue, iqentry_7_islot, iqentry_stomp[7], iqentry_source[7], iqentry_memready[7], iqentry_memissue[7]);
9243
 
9244
//      $display("ALU Inputs:");
9245
//      $display("  0: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
9246
//              alu0_available, alu0_dataready, alu0_sourceid, alu0_op, alu0_argA,
9247
//              alu0_argB, alu0_argI, alu0_bt);
9248
//      $display("  1: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
9249
//              alu1_available, alu1_dataready, alu1_sourceid, alu1_op, alu1_argA,
9250
//              alu1_argB, alu1_argI, alu1_bt);
9251
 
9252
//      $display("ALU Outputs:");
9253
//      $display("  0: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
9254
//              alu0_v, alu0_bus, alu0_id, alu0_branchmiss, alu0_misspc, alu0_sourceid);
9255
//      $display("  1: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
9256
//              alu1_v, alu1_bus, alu1_id, alu1_branchmiss, alu1_misspc, alu1_sourceid);
9257
 
9258
//      $display("DRAM Status:");
9259
//      $display("  OUT: v=%d data=%h tgt=%d id=%o", dram_v, dram_bus, dram_tgt, dram_id);
9260
//      $display("  dram0: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
9261
//          dram0, dram0_addr, dram0_data, dram0_op, dram0_tgt, dram0_id);
9262
//      $display("  dram1: status=%h addr=%h data=%h op=%d tgt=%d id=%o", 
9263
//          dram1, dram1_addr, dram1_data, dram1_op, dram1_tgt, dram1_id);
9264
//      $display("  dram2: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
9265
//          dram2, dram2_addr, dram2_data, dram2_op, dram2_tgt, dram2_id);
9266
 
9267
//      $display("Commit Buses:");
9268
//      $display("  0: v=%d id=%o data=%h", commit0_v, commit0_id, commit0_bus);
9269
//      $display("  1: v=%d id=%o data=%h", commit1_v, commit1_id, commit1_bus);
9270
 
9271
//
9272
//      $display("Memory Contents:");
9273
//      for (j=0; j<64; j=j+16)
9274
//          $display("  %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h", 
9275
//              m[j+0], m[j+1], m[j+2], m[j+3], m[j+4], m[j+5], m[j+6], m[j+7],
9276
//              m[j+8], m[j+9], m[j+10], m[j+11], m[j+12], m[j+13], m[j+14], m[j+15]);
9277
 
9278
        $display("");
9279
 
9280
        if (|panic) begin
9281
            $display("");
9282
            $display("-----------------------------------------------------------------");
9283
            $display("-----------------------------------------------------------------");
9284
            $display("---------------     PANIC:%s     -----------------", message[panic]);
9285
            $display("-----------------------------------------------------------------");
9286
            $display("-----------------------------------------------------------------");
9287
            $display("");
9288
            $display("instructions committed: %d", I);
9289
            $display("total execution cycles: %d", $time / 10);
9290
            $display("");
9291
        end
9292
        if (|panic && ~outstanding_stores) begin
9293
            $finish;
9294
        end
9295
/*
9296
    for (n = 0; n < QENTRIES; n = n + 1)
9297
        if (branchmiss) begin
9298
            if (!setpred[n]) begin
9299
                 iqentry_instr[n][`INSTRUCTION_OP] <= `NOP;
9300
                 iqentry_done[n] <= iqentry_v[n];
9301
                 iqentry_cmt[n] <= iqentry_v[n];
9302
            end
9303
        end
9304
*/
9305
        rf_source[ 0] <= {`QBIT{1'b1}};
9306
        rf_source[32] <= {`QBIT{1'b1}};
9307
        rf_source[64] <= {`QBIT{1'b1}};
9308
        rf_source[96] <= {`QBIT{1'b1}};
9309
`ifdef SUPPORTSMT
9310
        rf_source[128] <= {`QBIT{1'b1}};
9311
        rf_source[160] <= {`QBIT{1'b1}};
9312
        rf_source[192] <= {`QBIT{1'b1}};
9313
        rf_source[224] <= {`QBIT{1'b1}};
9314
`endif
9315
 
9316
end // clock domain
9317
/*
9318
always @(posedge clk)
9319
if (rst) begin
9320
     tail0 <= 3'd0;
9321
     tail1 <= 3'd1;
9322
end
9323
else begin
9324
if (!branchmiss) begin
9325
    case({fetchbuf0_v, fetchbuf1_v})
9326
    2'b00:  ;
9327
    2'b01:
9328
        if (canq1) begin
9329
             tail0 <= idp1(tail0);
9330
             tail1 <= idp1(tail1);
9331
        end
9332
    2'b10:
9333
        if (canq1) begin
9334
             tail0 <= idp1(tail0);
9335
             tail1 <= idp1(tail1);
9336
        end
9337
    2'b11:
9338
        if (canq1) begin
9339
            if (IsBranch(fetchbuf0_instr) && predict_taken0) begin
9340
                 tail0 <= idp1(tail0);
9341
                 tail1 <= idp1(tail1);
9342
            end
9343
            else begin
9344
                                if (vqe < vl || !IsVector(fetchbuf0_instr)) begin
9345
                        if (canq2) begin
9346
                             tail0 <= idp2(tail0);
9347
                             tail1 <= idp2(tail1);
9348
                        end
9349
                        else begin    // queued1 will be true
9350
                             tail0 <= idp1(tail0);
9351
                             tail1 <= idp1(tail1);
9352
                        end
9353
                end
9354
            end
9355
        end
9356
    endcase
9357
end
9358
else begin      // if branchmiss
9359
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
9360
         tail0 <= 3'd0;
9361
         tail1 <= 3'd1;
9362
    end
9363
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
9364
         tail0 <= 3'd1;
9365
         tail1 <= 3'd2;
9366
    end
9367
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
9368
         tail0 <= 3'd2;
9369
         tail1 <= 3'd3;
9370
    end
9371
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
9372
         tail0 <= 3'd3;
9373
         tail1 <= 3'd4;
9374
    end
9375
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
9376
         tail0 <= 3'd4;
9377
         tail1 <= 3'd5;
9378
    end
9379
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
9380
         tail0 <= 3'd5;
9381
         tail1 <= 3'd6;
9382
    end
9383
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
9384
         tail0 <= 3'd6;
9385
         tail1 <= 3'd7;
9386
    end
9387
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
9388
         tail0 <= 3'd7;
9389
         tail1 <= 3'd0;
9390
    end
9391
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
9392
end
9393
end
9394
*/
9395
 
9396
// Update the write buffer.
9397
task wb_update;
9398
input [`QBITS] id;
9399
input rmw;
9400
input [7:0] sel;
9401
input [1:0] ol;
9402
input [`ABITS] addr;
9403
input [63:0] data;
9404
begin
9405
        if (wbm && wbptr > 1 && wb_addr[wbptr-1][AMSB:3]==addr[AMSB:3]
9406
         && wb_ol[wbptr-1]==ol && wb_rmw[wbptr-1]==rmw && wb_v[wbptr-1]) begin
9407
                // The write buffer is always shifted during the bus IDLE state. That means
9408
                // the data is out of place by a slot. The slot the data is moved from is
9409
                // invalidated.
9410
                wb_v[wbptr-2] <= `INV;
9411
                wb_v[wbptr-1] <= wb_en;
9412
                wb_id[wbptr-1] <= wb_id[wbptr-1] | (16'd1 << id);
9413
                wb_rmw[wbptr-1] <= rmw;
9414
                wb_ol[wbptr-1] <= ol;
9415
                wb_sel[wbptr-1] <= wb_sel[wbptr-1] | sel;
9416
                wb_addr[wbptr-1] <= wb_addr[wbptr-1];
9417
                wb_data[wbptr-1] <= wb_data[wbptr-1];
9418
                if (sel[0]) wb_data[wbptr-1][ 7: 0] <= data[ 7: 0];
9419
                if (sel[1]) wb_data[wbptr-1][15: 8] <= data[15: 8];
9420
                if (sel[2]) wb_data[wbptr-1][23:16] <= data[23:16];
9421
                if (sel[3]) wb_data[wbptr-1][31:24] <= data[31:24];
9422
                if (sel[4]) wb_data[wbptr-1][39:32] <= data[39:32];
9423
                if (sel[5]) wb_data[wbptr-1][47:40] <= data[47:40];
9424
                if (sel[6]) wb_data[wbptr-1][55:48] <= data[55:48];
9425
                if (sel[7]) wb_data[wbptr-1][63:56] <= data[63:56];
9426
                wb_merges <= wb_merges + 32'd1;
9427
        end
9428
        else begin
9429
                wb_v[wbptr] <= wb_en;
9430
                wb_id[wbptr] <= (16'd1 << id);
9431
                wb_rmw[wbptr] <= rmw;
9432
                wb_ol[wbptr] <= ol;
9433
                wb_sel[wbptr] <= sel;
9434
                wb_addr[wbptr] <= {addr[AMSB:3],3'b0};
9435
                wb_data[wbptr] <= data;
9436
                wbptr <= wbptr + 2'd1;
9437
        end
9438
end
9439
endtask
9440
 
9441
// Increment the head pointers
9442
// Also increments the instruction counter
9443
// Used when instructions are committed.
9444
// Also clear any outstanding state bits that foul things up.
9445
//
9446
task head_inc;
9447
input [`QBITS] amt;
9448
begin
9449
        for (n = 0; n < QENTRIES; n = n + 1)
9450
     heads[n] <= (heads[n] + amt) % QENTRIES;
9451
        CC <= CC + amt;
9452
    if (amt==3'd3) begin
9453
        I = I + iqentry_v[heads[0]] + iqentry_v[heads[1]] + iqentry_v[heads[2]];
9454
        iqentry_state[heads[0]] <= IQS_INVALID;
9455
        iqentry_state[heads[1]] <= IQS_INVALID;
9456
        iqentry_state[heads[2]] <= IQS_INVALID;
9457
        iqentry_mem[heads[0]] <= `FALSE;
9458
        iqentry_mem[heads[1]] <= `FALSE;
9459
        iqentry_mem[heads[2]] <= `FALSE;
9460
        iqentry_iv[heads[0]] <= `INV;
9461
        iqentry_iv[heads[1]] <= `INV;
9462
        iqentry_iv[heads[2]] <= `INV;
9463
        iqentry_alu[heads[0]] <= `FALSE;
9464
        iqentry_alu[heads[1]] <= `FALSE;
9465
        iqentry_alu[heads[2]] <= `FALSE;
9466
                for (n = 0; n < QENTRIES; n = n + 1)
9467
                        if (iqentry_v[n])
9468
                                iqentry_sn[n] <= iqentry_sn[n] - (iqentry_v[heads[2]] ? iqentry_sn[heads[2]]
9469
                                                                                                                                                         : iqentry_v[heads[1]] ? iqentry_sn[heads[1]]
9470
                                                                                                                                                         : iqentry_v[heads[0]] ? iqentry_sn[heads[0]]
9471
                                                                                                                                                         : 4'b0);
9472
        end
9473
    else if (amt==3'd2) begin
9474
        I = I + iqentry_v[heads[0]] + iqentry_v[heads[1]];
9475
        iqentry_state[heads[0]] <= IQS_INVALID;
9476
        iqentry_state[heads[1]] <= IQS_INVALID;
9477
     iqentry_mem[heads[0]] <= `FALSE;
9478
     iqentry_mem[heads[1]] <= `FALSE;
9479
     iqentry_iv[heads[0]] <= `INV;
9480
     iqentry_iv[heads[1]] <= `INV;
9481
        iqentry_alu[heads[0]] <= `FALSE;
9482
     iqentry_alu[heads[1]] <= `FALSE;
9483
                for (n = 0; n < QENTRIES; n = n + 1)
9484
                        if (iqentry_v[n])
9485
                                iqentry_sn[n] <= iqentry_sn[n] - (iqentry_v[heads[1]] ? iqentry_sn[heads[1]]
9486
                                                                                                                                                         : iqentry_v[heads[0]] ? iqentry_sn[heads[0]]
9487
                                                                                                                                                         : 4'b0);
9488
    end else if (amt==3'd1) begin
9489
        I = I + iqentry_v[heads[0]];
9490
        iqentry_state[heads[0]] <= IQS_INVALID;
9491
            iqentry_mem[heads[0]] <= `FALSE;
9492
        iqentry_iv[heads[0]] <= `INV;
9493
        iqentry_alu[heads[0]] <= `FALSE;
9494
                for (n = 0; n < QENTRIES; n = n + 1)
9495
                        if (iqentry_v[n])
9496
                                iqentry_sn[n] <= iqentry_sn[n] - (iqentry_v[heads[0]] ? iqentry_sn[heads[0]]
9497
                                                                                                                                                         : 4'b0);
9498
        end
9499
end
9500
endtask
9501
 
9502
task setargs;
9503
input [`QBITS] nn;
9504
input [`QBITSP1] id;
9505
input v;
9506
input [63:0] bus;
9507
begin
9508
  if (iqentry_a1_v[nn] == `INV && iqentry_a1_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9509
                iqentry_a1[nn] <= bus;
9510
                iqentry_a1_v[nn] <= `VAL;
9511
  end
9512
  if (iqentry_a2_v[nn] == `INV && iqentry_a2_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9513
                iqentry_a2[nn] <= bus;
9514
                iqentry_a2_v[nn] <= `VAL;
9515
  end
9516
  if (iqentry_a3_v[nn] == `INV && iqentry_a3_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9517
                iqentry_a3[nn] <= bus;
9518
                iqentry_a3_v[nn] <= `VAL;
9519
  end
9520
end
9521
endtask
9522
 
9523
task setinsn1;
9524
input [`QBITS] nn;
9525
input [143:0] bus;
9526
begin
9527
        iqentry_iv   [nn]  <= `VAL;
9528
//      iqentry_Rt   [nn]  <= bus[`IB_RT];
9529
//      iqentry_Rc   [nn]  <= bus[`IB_RC];
9530
//      iqentry_Ra   [nn]  <= bus[`IB_RA];
9531
        iqentry_a0       [nn]  <= bus[`IB_CONST];
9532
        iqentry_imm  [nn]  <= bus[`IB_IMM];
9533
//              iqentry_insln[nn]  <= bus[`IB_LN];
9534
`ifndef INLINE_DECODE
9535
        if (iqentry_insln[nn] != bus[`IB_LN]) begin
9536
                $display("Insn length mismatch.");
9537
                $stop;
9538
        end
9539
`endif
9540
        iqentry_cmp      [nn]  <= bus[`IB_CMP];
9541
        iqentry_tlb  [nn]  <= bus[`IB_TLB];
9542
        iqentry_sz   [nn]  <= bus[`IB_SZ];
9543
        iqentry_jal      [nn]  <= bus[`IB_JAL];
9544
        iqentry_ret  [nn]  <= bus[`IB_RET];
9545
        iqentry_irq  [nn]  <= bus[`IB_IRQ];
9546
        iqentry_brk      [nn]  <= bus[`IB_BRK];
9547
        iqentry_rti  [nn]  <= bus[`IB_RTI];
9548
        iqentry_bt   [nn]  <= bus[`IB_BT];
9549
        iqentry_alu  [nn]  <= bus[`IB_ALU];
9550
        iqentry_alu0 [nn]  <= bus[`IB_ALU0];
9551
        iqentry_fpu  [nn]  <= bus[`IB_FPU];
9552
        iqentry_fc   [nn]  <= bus[`IB_FC];
9553
        iqentry_canex[nn]  <= bus[`IB_CANEX];
9554
        iqentry_loadv[nn]  <= bus[`IB_LOADV];
9555
        iqentry_load [nn]  <= bus[`IB_LOAD];
9556
        iqentry_preload[nn]<= bus[`IB_PRELOAD];
9557
        iqentry_store[nn]  <= bus[`IB_STORE];
9558
        iqentry_push [nn]  <= bus[`IB_PUSH];
9559
        iqentry_oddball[nn] <= bus[`IB_ODDBALL];
9560
        iqentry_memsz[nn]  <= bus[`IB_MEMSZ];
9561
        iqentry_mem  [nn]  <= bus[`IB_MEM];
9562
        iqentry_memndx[nn] <= bus[`IB_MEMNDX];
9563
        iqentry_rmw  [nn]  <= bus[`IB_RMW];
9564
        iqentry_memdb[nn]  <= bus[`IB_MEMDB];
9565
        iqentry_memsb[nn]  <= bus[`IB_MEMSB];
9566
        iqentry_shft [nn]  <= bus[`IB_SHFT];    // 48 bit shift instructions
9567
        iqentry_sei      [nn]    <= bus[`IB_SEI];
9568
        iqentry_aq   [nn]  <= bus[`IB_AQ];
9569
        iqentry_rl   [nn]  <= bus[`IB_RL];
9570
        iqentry_jmp  [nn]  <= bus[`IB_JMP];
9571
        iqentry_br   [nn]  <= bus[`IB_BR];
9572
        iqentry_sync [nn]  <= bus[`IB_SYNC];
9573
        iqentry_fsync[nn]  <= bus[`IB_FSYNC];
9574
        iqentry_rfw  [nn]  <= bus[`IB_RFW];
9575
`ifdef SUPPORT_PREDICATION
9576
        iqentry_prfw [nn]  <= bus[`IB_PRFW];
9577
`endif
9578
        iqentry_we   [nn]  <= bus[`IB_WE];
9579
end
9580
endtask
9581
 
9582
task setinsn;
9583
input [`QBITS] nn;
9584
input [4:0] id;
9585
input v;
9586
input [143:0] bus;
9587
begin
9588
  if (iqentry_iv[nn] == `INV && iqentry_is[nn] == id && iqentry_v[nn] == `VAL && v == `VAL)
9589
        setinsn1(nn,bus);
9590
end
9591
endtask
9592
 
9593
task a1_vs;
9594
begin
9595
        // if there is not an overlapping write to the register file.
9596
        if (Ra1s != Rt0s || !fetchbuf0_rfw) begin
9597
                iqentry_a1_v [tail1] <= regIsValid[Ra1s];
9598
                iqentry_a1_s [tail1] <= rf_source [Ra1s];
9599
        end
9600
        else begin
9601
                iqentry_a1_v [tail1] <= `INV;
9602
                iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_mem, tail0 };
9603
        end
9604
end
9605
endtask
9606
 
9607
task a2_vs;
9608
begin
9609
        // if there is not an overlapping write to the register file.
9610
        if (Rb1s != Rt0s || !fetchbuf0_rfw) begin
9611
                iqentry_a2_v [tail1] <= regIsValid[Rb1s];
9612
                iqentry_a2_s [tail1] <= rf_source [Rb1s];
9613
        end
9614
        else begin
9615
                iqentry_a2_v [tail1] <= `INV;
9616
                iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_mem, tail0 };
9617
        end
9618
end
9619
endtask
9620
 
9621
task a3_vs;
9622
begin
9623
        // if there is not an overlapping write to the register file.
9624
        if (Rc1s != Rt0s || !fetchbuf0_rfw) begin
9625
                iqentry_a3_v [tail1] <= regIsValid[Rc1s];
9626
                iqentry_a3_s [tail1] <= rf_source [Rc1s];
9627
        end
9628
        else begin
9629
                iqentry_a3_v [tail1] <= `INV;
9630
                iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_mem, tail0 };
9631
        end
9632
end
9633
endtask
9634
 
9635
task enque0x;
9636
begin
9637
        if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
9638
                vqe0 <= vqe0 + 4'd1;
9639
                if (IsVCmprss(fetchbuf0_instr)) begin
9640
                        if (vm[fetchbuf0_instr[25:23]][vqe0])
9641
                        vqet0 <= vqet0 + 4'd1;
9642
                end
9643
                else
9644
                        vqet0 <= vqet0 + 4'd1;
9645
                if (vqe0 >= vl-2)
9646
                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
9647
                enque0(tail0, fetchbuf0_thrd ? maxsn[1]+4'd1 : maxsn[0]+4'd1, vqe0);
9648
                iq_ctr = iq_ctr + 4'd1;
9649
                if (fetchbuf0_rfw) begin
9650
                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_mem, tail0 };    // top bit indicates ALU/MEM bus
9651
                        rf_v[Rt0s] <= `INV;
9652
                end
9653
                if (canq2) begin
9654
                        if (vqe0 < vl-2) begin
9655
                                vqe0 <= vqe0 + 4'd2;
9656
                                if (IsVCmprss(fetchbuf0_instr)) begin
9657
                                        if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
9658
                                                vqet0 <= vqet0 + 4'd2;
9659
                                end
9660
                                else
9661
                                        vqet0 <= vqet0 + 4'd2;
9662
                                enque0(tail1, fetchbuf0_thrd ? maxsn[1] + 4'd2 : maxsn[0]+4'd2, vqe0 + 6'd1);
9663
                                iq_ctr = iq_ctr + 4'd2;
9664
                                if (fetchbuf0_rfw) begin
9665
                                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_mem, tail1 };    // top bit indicates ALU/MEM bus
9666
                                        rf_v[Rt0s] <= `INV;
9667
                                end
9668
                        end
9669
                end
9670
        end
9671
        else begin
9672
                enque0(tail0, fetchbuf0_thrd ? maxsn[1]+4'd1 : maxsn[0]+4'd1, 6'd0);
9673
                iq_ctr = iq_ctr + 4'd1;
9674
                if (fetchbuf0_rfw) begin
9675
                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_mem, tail0 };    // top bit indicates ALU/MEM bus
9676
                        rf_v[Rt0s] <= `INV;
9677
                end
9678
        end
9679
end
9680
endtask
9681
 
9682
// Enqueue fetchbuf0 onto the tail of the instruction queue
9683
task enque0;
9684
input [`QBITS] tail;
9685
input [`SNBITS] seqnum;
9686
input [5:0] venno;
9687
begin
9688
        iqentry_exc[tail] <= `FLT_NONE;
9689
`ifdef SUPPORT_DBG
9690
    if (dbg_imatchA)
9691
        iqentry_exc[tail] <= `FLT_DBG;
9692
    else if (dbg_ctrl[63])
9693
        iqentry_exc[tail] <= `FLT_SSM;
9694
`endif
9695
        iqentry_state[tail]    <= IQS_QUEUED;
9696
        iqentry_sn   [tail]    <=  seqnum;
9697
        iqentry_iv       [tail]    <=   `INV;
9698
        iqentry_is   [tail]    <= tail;
9699
        iqentry_thrd [tail]    <=   fetchbuf0_thrd;
9700
        iqentry_res  [tail]    <=    `ZERO;
9701
        iqentry_instr[tail]    <=    IsVLS(fetchbuf0_instr) ? (vm[fnM2(fetchbuf0_instr)] ? fetchbuf0_instr : `NOP_INSN) : fetchbuf0_instr;
9702
        iqentry_insln[tail]              <=  fetchbuf0_insln;
9703
        iqentry_fc   [tail]    <=  `INV;
9704
        iqentry_mem      [tail]          <=  `INV;
9705
        iqentry_alu      [tail]          <=  `INV;
9706
        iqentry_fpu      [tail]          <=  `INV;
9707
        iqentry_load [tail]              <=  `INV;
9708
        iqentry_pt   [tail]    <=  predict_taken0;
9709
// If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9710
// inherit the previous pc.
9711
//if (IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15] &&
9712
//   (IsBrk(iqentry_instr[idm1(tail)]) && !iqentry_instr[idm1(tail1)][15] && iqentry_v[idm1(tail)]))
9713
//   iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
9714
//else
9715
         iqentry_pc   [tail] <= fetchbuf0_pc;
9716
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf0_instr);
9717
        iqentry_tgt  [tail]    <=       Rt0;
9718
        iqentry_Ra   [tail]    <= Ra0;
9719
        iqentry_Rb   [tail]    <= Rb0;
9720
        iqentry_Rc   [tail]    <= Rc0;
9721
        iqentry_vl   [tail]    <=  vl;
9722
        iqentry_ven  [tail]    <=   venno;
9723
        iqentry_exc  [tail]    <=    `EXC_NONE;
9724
        iqentry_a1   [tail]    <=    rfoa0;
9725
        iqentry_a1_v [tail]    <=    Source1Valid(fetchbuf0_instr) | regIsValid[Ra0s];
9726
        iqentry_a1_s [tail]    <=    rf_source[Ra0s];
9727
        iqentry_a2   [tail]    <=    rfob0;
9728
        iqentry_a2_v [tail]    <=    Source2Valid(fetchbuf0_instr) | regIsValid[Rb0s];
9729
        iqentry_a2_s [tail]    <=    rf_source[Rb0s];
9730
        iqentry_a3   [tail]    <=    rfoc0;
9731
        iqentry_a3_v [tail]    <=    Source3Valid(fetchbuf0_instr) | regIsValid[Rc0s];
9732
        iqentry_a3_s [tail]    <=    rf_source[Rc0s];
9733
`ifdef INLINE_DECODE
9734
/* This decoding cannot be done here because it'll introduce a 1 cycle delay
9735
        id1_Rt <= Rt0[4:0];
9736
        id1_vl <= vl;
9737
        id1_ven <= venno;
9738
        id1_id <= tail;
9739
        id1_pt <= predict_taken0;
9740
        id1_thrd <= fetchbuf0_thrd;
9741
*/
9742
        setinsn1(tail,id1_bus);
9743
`endif
9744
end
9745
endtask
9746
 
9747
// Enque fetchbuf1. Fetchbuf1 might be the second instruction to queue so some
9748
// of this code checks to see which tail it is being queued on.
9749
task enque1;
9750
input [`QBITS] tail;
9751
input [`SNBITS] seqnum;
9752
input [5:0] venno;
9753
begin
9754
 iqentry_exc[tail] <= `FLT_NONE;
9755
`ifdef SUPPORT_DBG
9756
    if (dbg_imatchB)
9757
        iqentry_exc[tail] <= `FLT_DBG;
9758
    else if (dbg_ctrl[63])
9759
        iqentry_exc[tail] <= `FLT_SSM;
9760
`endif
9761
        iqentry_state[tail]    <= IQS_QUEUED;
9762
        iqentry_sn   [tail]    <=   seqnum;
9763
        iqentry_iv       [tail]    <=   `INV;
9764
        iqentry_is   [tail]    <= tail;
9765
        iqentry_thrd [tail]    <=   fetchbuf1_thrd;
9766
        iqentry_res  [tail]    <=   `ZERO;
9767
        iqentry_instr[tail]    <=   IsVLS(fetchbuf1_instr) ? (vm[fnM2(fetchbuf1_instr)] ? fetchbuf1_instr : `NOP_INSN) : fetchbuf1_instr;
9768
        iqentry_insln[tail]              <=  fetchbuf1_insln;
9769
        iqentry_fc   [tail]    <=  `INV;
9770
        iqentry_mem      [tail]          <=  `INV;
9771
        iqentry_alu      [tail]          <=  `INV;
9772
        iqentry_fpu      [tail]          <=  `INV;
9773
        iqentry_load [tail]              <=  `INV;
9774
        iqentry_pt   [tail]    <=  predict_taken1;
9775
// If queing 2nd instruction must read from first
9776
if (tail==tail1) begin
9777
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9778
    // inherit the previous pc.
9779
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
9780
//        IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15])
9781
//       iqentry_pc   [tail]    <= fetchbuf0_pc;
9782
//    else
9783
                iqentry_pc   [tail] <= fetchbuf1_pc;
9784
end
9785
else begin
9786
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9787
    // inherit the previous pc.
9788
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
9789
//       (IsBrk(iqentry_instr[idp7(tail)]) && !iqentry_instr[idm1(tail)][15] && iqentry_v[idm1(tail)]))
9790
//       iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
9791
//    else
9792
                iqentry_pc   [tail] <= fetchbuf1_pc;
9793
end
9794
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf1_instr);
9795
        iqentry_tgt  [tail]    <= Rt1;
9796
        iqentry_Ra   [tail]    <= Ra1;
9797
        iqentry_Rb   [tail]    <= Rb1;
9798
        iqentry_Rc   [tail]    <= Rc1;
9799
        iqentry_vl   [tail]    <=  vl;
9800
        iqentry_ven  [tail]    <=   venno;
9801
        iqentry_exc  [tail]    <=   `EXC_NONE;
9802
        iqentry_a1   [tail]    <=       rfoa1;
9803
        iqentry_a1_v [tail]    <=       Source1Valid(fetchbuf1_instr) | regIsValid[Ra1s];
9804
        iqentry_a1_s [tail]    <=       rf_source[Ra1s];
9805
        iqentry_a2   [tail]    <=       rfob1;
9806
        iqentry_a2_v [tail]    <=       Source2Valid(fetchbuf1_instr) | regIsValid[Rb1s];
9807
        iqentry_a2_s [tail]    <=       rf_source[Rb1s];
9808
        iqentry_a3   [tail]    <=       rfoc1;
9809
        iqentry_a3_v [tail]    <=       Source3Valid(fetchbuf1_instr) | regIsValid[Rc1s];
9810
        iqentry_a3_s [tail]    <=       rf_source[Rc1s];
9811
`ifdef INLINE_DECODE
9812
/* This decoding cannot be done here because it'll introduce a 1 cycle delay
9813
        id2_Rt <= Rt1[4:0];
9814
        id2_vl <= vl;
9815
        id2_ven <= venno;
9816
        id2_id <= tail;
9817
        id2_pt <= predict_taken1;
9818
        id2_thrd <= fetchbuf1_thrd;
9819
*/
9820
        setinsn1(tail,id2_bus);
9821
`endif
9822
end
9823
endtask
9824
 
9825
// This task takes care of commits for things other than the register file.
9826
task oddball_commit;
9827
input v;
9828
input [`QBITS] head;
9829
input [1:0] which;
9830
reg thread;
9831
begin
9832
    thread = iqentry_thrd[head];
9833
    if (v) begin
9834
        if (|iqentry_exc[head]) begin
9835
          excmiss <= TRUE;
9836
`ifdef SUPPORT_SMT
9837
                excmisspc <= {tvec[3'd0][AMSB:8],1'b0,ol[thread],5'h00};
9838
          excthrd <= iqentry_thrd[head];
9839
          badaddr[{thread,2'd0}] <= iqentry_ma[head];
9840
          bad_instr[{thread,2'd0}] <= iqentry_instr[head];
9841
          epc0[thread] <= iqentry_pc[head];
9842
          epc1[thread] <= epc0[thread];
9843
          epc2[thread] <= epc1[thread];
9844
          epc3[thread] <= epc2[thread];
9845
          epc4[thread] <= epc3[thread];
9846
          epc5[thread] <= epc4[thread];
9847
          epc6[thread] <= epc5[thread];
9848
          epc7[thread] <= epc6[thread];
9849
          epc8[thread] <= epc7[thread];
9850
          im_stack[thread] <= {im_stack[thread][27:0],im};
9851
          ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9852
          dl_stack[thread] <= {dl_stack[thread][13:0],dl[thread]};
9853
          pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9854
          rs_stack[thread] <= {rs_stack[thread][59:0],`EXC_RGS};
9855
          brs_stack[thread] <= {brs_stack[thread][59:0],`EXC_RGS};
9856
          cause[{thread,2'd0}] <= {8'd0,iqentry_exc[head]};
9857
          mstatus[thread][5:4] <= 2'd0;
9858
          mstatus[thread][13:6] <= 8'h00;
9859
          mstatus[thread][19:14] <= `EXC_RGS;
9860
`else
9861
                excmisspc <= {tvec[3'd0][AMSB:8],1'b0,ol,5'h00};
9862
          excthrd <= 1'b0;
9863
          badaddr[{1'b0,2'd0}] <= iqentry_ma[head];
9864
          bad_instr[3'd0] <= iqentry_instr[head];
9865
          epc0 <= iqentry_pc[head];
9866
          epc1 <= epc0;
9867
          epc2 <= epc1;
9868
          epc3 <= epc2;
9869
          epc4 <= epc3;
9870
          epc5 <= epc4;
9871
          epc6 <= epc5;
9872
          epc7 <= epc6;
9873
          epc8 <= epc7;
9874
          im_stack <= {im_stack[27:0],im};
9875
          ol_stack <= {ol_stack[13:0],ol};
9876
          dl_stack <= {dl_stack[13:0],dl};
9877
          pl_stack <= {pl_stack[55:0],cpl};
9878
          rs_stack <= {rs_stack[59:0],`EXC_RGS};
9879
          brs_stack <= {rs_stack[59:0],`EXC_RGS};
9880
          cause[3'd0] <= {8'd0,iqentry_exc[head]};
9881
          mstatus[5:4] <= 2'd0;
9882
          mstatus[13:6] <= 8'h00;
9883
          mstatus[19:14] <= `EXC_RGS;
9884
`endif
9885
                                        wb_en <= `TRUE;
9886
          sema[0] <= 1'b0;
9887
          ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9888
`ifdef SUPPORT_DBG
9889
          dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9890
          dbg_ctrl[63] <= FALSE;
9891
`endif
9892
        end
9893
        else
9894
        case(iqentry_instr[head][`INSTRUCTION_OP])
9895
`ifdef SUPPORT_PREDICATION
9896
        `CMPI:  pregs[{rgs,iqentry_tgt[head][3:0]}] <= which==2'd1 ? cmt1nyb[iqentry_tgt[head][3:0]] : cmt0nyb[iqentry_tgt[head][3:0]];//commit_bus[3:0];
9897
`endif
9898
 
9899
        `BRK:
9900
                        // BRK is treated as a nop unless it's a software interrupt or a
9901
                        // hardware interrupt at a higher priority than the current priority.
9902
            if ((|iqentry_instr[head][25:21]) || iqentry_instr[head][20:17] > im) begin
9903
                    excmiss <= TRUE;
9904
`ifdef SUPPORT_SMT
9905
                        excmisspc <= {tvec[3'd0][AMSB:8],1'b0,ol[thread],5'h00};
9906
                        excthrd <= iqentry_thrd[head];
9907
              epc0[thread] <= iqentry_pc[head] + {iqentry_instr[head][25:21],1'b0};
9908
              epc1[thread] <= epc0[thread];
9909
              epc2[thread] <= epc1[thread];
9910
              epc3[thread] <= epc2[thread];
9911
              epc4[thread] <= epc3[thread];
9912
              epc5[thread] <= epc4[thread];
9913
              epc6[thread] <= epc5[thread];
9914
              epc7[thread] <= epc6[thread];
9915
              epc8[thread] <= epc7[thread];
9916
              im_stack[thread] <= {im_stack[thread][27:0],im};
9917
              ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9918
              dl_stack[thread] <= {dl_stack[thread][13:0],dl[thread]};
9919
              pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9920
              rs_stack[thread] <= {rs_stack[thread][59:0],`BRK_RGS};
9921
              brs_stack[thread] <= {brs_stack[thread][59:0],`BRK_RGS};
9922
              cause[{thread,2'd0}] <= iqentry_res[head][7:0];
9923
              mstatus[thread][5:4] <= 2'd0;
9924
              mstatus[thread][13:6] <= 8'h00;
9925
              // For hardware interrupts only, set a new mask level. Setting a
9926
              // new mask level will effectively prevent subsequent brks that
9927
              // are streaming from an interrupt from being processed.
9928
              // Select register set according to interrupt level
9929
              if (iqentry_instr[head][25:21]==5'd0) begin
9930
                mstatus[thread][ 3: 0] <= iqentry_instr[head][20:17];
9931
                mstatus[thread][31:28] <= iqentry_instr[head][20:17];
9932
                mstatus[thread][19:14] <= {2'b0,iqentry_instr[head][20:17]};
9933
                rs_stack[thread][5:0] <= {2'b0,iqentry_instr[head][20:17]};
9934
                brs_stack[thread][5:0] <= {2'b0,iqentry_instr[head][20:17]};
9935
              end
9936
              else begin
9937
                mstatus[thread][19:14] <= `BRK_RGS;
9938
                rs_stack[thread][5:0] <= `BRK_RGS;
9939
                brs_stack[thread][5:0] <= `BRK_RGS;
9940
              end
9941
`else
9942
                        excmisspc <= {tvec[3'd0][AMSB:8],1'b0,ol,5'h00};
9943
                        excthrd <= 1'b0;
9944
              epc0 <= iqentry_pc[head] + {iqentry_instr[head][25:21],1'b0};
9945
              epc1 <= epc0;
9946
              epc2 <= epc1;
9947
              epc3 <= epc2;
9948
              epc4 <= epc3;
9949
              epc5 <= epc4;
9950
              epc6 <= epc5;
9951
              epc7 <= epc6;
9952
              epc8 <= epc7;
9953
              im_stack <= {im_stack[27:0],im};
9954
              ol_stack <= {ol_stack[13:0],ol};
9955
              dl_stack <= {dl_stack[13:0],dl};
9956
              pl_stack <= {pl_stack[55:0],cpl};
9957
              rs_stack <= {rs_stack[59:0],`BRK_RGS};
9958
              brs_stack <= {brs_stack[59:0],`BRK_RGS};
9959
              cause[3'd0] <= iqentry_res[head][7:0];
9960
              mstatus[5:4] <= 2'd0;
9961
              mstatus[13:6] <= 8'h00;
9962
              // For hardware interrupts only, set a new mask level. Setting a
9963
              // new mask level will effectively prevent subsequent brks that
9964
              // are streaming from an interrupt from being processed.
9965
              // Select register set according to interrupt level
9966
              if (iqentry_instr[head][25:21]==5'd0) begin
9967
                mstatus[ 3: 0] <= iqentry_instr[head][20:17];
9968
                mstatus[31:28] <= iqentry_instr[head][20:17];
9969
                mstatus[19:14] <= {2'b0,iqentry_instr[head][20:17]};
9970
                rs_stack[5:0] <= {2'b0,iqentry_instr[head][20:17]};
9971
                brs_stack[5:0] <= {2'b0,iqentry_instr[head][20:17]};
9972
              end
9973
              else begin
9974
                mstatus[19:14] <= `BRK_RGS;
9975
                rs_stack[5:0] <= `BRK_RGS;
9976
                brs_stack[5:0] <= `BRK_RGS;
9977
              end
9978
`endif
9979
              sema[0] <= 1'b0;
9980
              ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9981
`ifdef SUPPORT_DBG
9982
              dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9983
              dbg_ctrl[63] <= FALSE;
9984
`endif
9985
            end
9986
        `IVECTOR:
9987
            casez(iqentry_tgt[head])
9988
            8'b00100???:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9989
            8'b00101111:  vl <= iqentry_res[head];
9990
            default:    ;
9991
            endcase
9992
        `R2:
9993
            case(iqentry_instr[head][`INSTRUCTION_S2])
9994
`ifdef SUPPORT_PREDICATION
9995
                        `CMP:   pregs[{rgs,iqentry_tgt[head][3:0]}] <= which==2'd1 ? cmt1nyb[iqentry_tgt[head][3:0]] : cmt0nyb[iqentry_tgt[head][3:0]];//commit_bus[3:0];
9996
`endif
9997
            `R1:        case(iqentry_instr[head][20:16])
9998
                        `CHAIN_OFF:     cr0[18] <= 1'b0;
9999
                        `CHAIN_ON:      cr0[18] <= 1'b1;
10000
                        //`SETWB:               wbrcd[pcr[5:0]] <= 1'b1;
10001
                        default:        ;
10002
                                endcase
10003
            `VMOV:  casez(iqentry_tgt[head])
10004
                    12'b1111111_00???:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
10005
                    12'b1111111_01111:  vl <= iqentry_res[head];
10006
                    default:    ;
10007
                    endcase
10008
`ifdef SUPPORT_SMT
10009
            `SEI:   mstatus[thread][3:0] <= iqentry_res[head][3:0];   // S1
10010
`else
10011
            `SEI:   mstatus[3:0] <= iqentry_res[head][3:0];   // S1
10012
`endif
10013
            `RTI:   begin
10014
                            excmiss <= TRUE;
10015
`ifdef SUPPORT_SMT
10016
                        excmisspc <= epc0[thread];
10017
                        excthrd <= thread;
10018
                        mstatus[thread][3:0] <= im_stack[thread][3:0];
10019
                        mstatus[thread][5:4] <= ol_stack[thread][1:0];
10020
                        mstatus[thread][21:20] <= dl_stack[thread][1:0];
10021
                        mstatus[thread][13:6] <= pl_stack[thread][7:0];
10022
                        mstatus[thread][19:14] <= rs_stack[thread][5:0];
10023
                        im_stack[thread] <= {4'd15,im_stack[thread][31:4]};
10024
                        ol_stack[thread] <= {2'd0,ol_stack[thread][15:2]};
10025
                        dl_stack[thread] <= {2'd0,dl_stack[thread][15:2]};
10026
                        pl_stack[thread] <= {8'h00,pl_stack[thread][63:8]};
10027
                        rs_stack[thread] <= {6'h00,rs_stack[thread][59:6]};
10028
                        brs_stack[thread] <= {6'h00,brs_stack[thread][59:6]};
10029
                epc0[thread] <= epc1[thread];
10030
                epc1[thread] <= epc2[thread];
10031
                epc2[thread] <= epc3[thread];
10032
                epc3[thread] <= epc4[thread];
10033
                epc4[thread] <= epc5[thread];
10034
                epc5[thread] <= epc6[thread];
10035
                epc6[thread] <= epc7[thread];
10036
                epc7[thread] <= epc8[thread];
10037
                epc8[thread] <= {tvec[0][AMSB:8], 1'b0, ol[thread], 5'h0};
10038
`else
10039
                        excmisspc <= epc0;
10040
                        excthrd <= thread;
10041
                        mstatus[3:0] <= im_stack[3:0];
10042
                        mstatus[5:4] <= ol_stack[1:0];
10043
                        mstatus[21:20] <= dl_stack[1:0];
10044
                        mstatus[13:6] <= pl_stack[7:0];
10045
                        mstatus[19:14] <= rs_stack[5:0];
10046
                        im_stack <= {4'd15,im_stack[31:4]};
10047
                        ol_stack <= {2'd0,ol_stack[15:2]};
10048
                        dl_stack <= {2'd0,dl_stack[15:2]};
10049
                        pl_stack <= {8'h00,pl_stack[63:8]};
10050
                        rs_stack <= {6'h00,rs_stack[59:6]};
10051
                        brs_stack <= {6'h00,brs_stack[59:6]};
10052
                epc0 <= epc1;
10053
                epc1 <= epc2;
10054
                epc2 <= epc3;
10055
                epc3 <= epc4;
10056
                epc4 <= epc5;
10057
                epc5 <= epc6;
10058
                epc6 <= epc7;
10059
                epc7 <= epc8;
10060
                epc8 <= {tvec[0][AMSB:8], 1'b0, ol, 5'h0};
10061
`endif
10062
                sema[0] <= 1'b0;
10063
                sema[iqentry_res[head][5:0]] <= 1'b0;
10064
                vqe0  <= ve_hold[ 5: 0];
10065
                vqet0 <= ve_hold[21:16];
10066
                vqe1  <= ve_hold[37:32];
10067
                vqet1 <= ve_hold[53:48];
10068
`ifdef SUPPORT_DBG
10069
                      dbg_ctrl[62:55] <= {FALSE,dbg_ctrl[62:56]};
10070
                      dbg_ctrl[63] <= dbg_ctrl[55];
10071
`endif
10072
              end
10073
            default: ;
10074
            endcase
10075
        `MEMNDX:
10076
            case(iqentry_instr[head][`INSTRUCTION_S2])
10077
            `CACHEX:
10078
                    case(iqentry_instr[head][22:18])
10079
                    5'h03:  invic <= TRUE;
10080
                    5'h10:  cr0[30] <= FALSE;
10081
                    5'h11:  cr0[30] <= TRUE;
10082
                    default:    ;
10083
                    endcase
10084
            default: ;
10085
            endcase
10086
        `CSRRW:
10087
                        begin
10088
                        write_csr(iqentry_instr[head][31:18],iqentry_a1[head],thread);
10089
                        end
10090
        `REX:
10091
`ifdef SUPPORT_SMT
10092
            // Can only redirect to a lower level
10093
            if (ol[thread] < iqentry_instr[head][14:13]) begin
10094
                mstatus[thread][5:4] <= iqentry_instr[head][14:13];
10095
                badaddr[{thread,iqentry_instr[head][14:13]}] <= badaddr[{thread,ol[thread]}];
10096
                bad_instr[{thread,iqentry_instr[head][14:13]}] <= bad_instr[{thread,ol[thread]}];
10097
                cause[{thread,iqentry_instr[head][14:13]}] <= cause[{thread,ol[thread]}];
10098
                mstatus[thread][13:6] <= iqentry_instr[head][25:18] | iqentry_a1[head][7:0];
10099
            end
10100
`else
10101
            if (ol < iqentry_instr[head][14:13]) begin
10102
                mstatus[5:4] <= iqentry_instr[head][14:13];
10103
                badaddr[{1'b0,iqentry_instr[head][14:13]}] <= badaddr[{1'b0,ol}];
10104
                bad_instr[{1'b0,iqentry_instr[head][14:13]}] <= bad_instr[{1'b0,ol}];
10105
                cause[{1'b0,iqentry_instr[head][14:13]}] <= cause[{1'b0,ol}];
10106
                mstatus[13:6] <= iqentry_instr[head][25:18] | iqentry_a1[head][7:0];
10107
            end
10108
`endif
10109
        `CACHE:
10110
            case(iqentry_instr[head][17:13])
10111
            5'h03:  invic <= TRUE;
10112
            5'h10:  cr0[30] <= FALSE;
10113
            5'h11:  cr0[30] <= TRUE;
10114
            default:    ;
10115
            endcase
10116
        `FLOAT:
10117
            case(iqentry_instr[head][`INSTRUCTION_S2])
10118
            `FRM: begin
10119
                                fp_rm <= iqentry_res[head][2:0];
10120
                                end
10121
            `FCX:
10122
                begin
10123
                    fp_sx <= fp_sx & ~iqentry_res[head][5];
10124
                    fp_inex <= fp_inex & ~iqentry_res[head][4];
10125
                    fp_dbzx <= fp_dbzx & ~(iqentry_res[head][3]|iqentry_res[head][0]);
10126
                    fp_underx <= fp_underx & ~iqentry_res[head][2];
10127
                    fp_overx <= fp_overx & ~iqentry_res[head][1];
10128
                    fp_giopx <= fp_giopx & ~iqentry_res[head][0];
10129
                    fp_infdivx <= fp_infdivx & ~iqentry_res[head][0];
10130
                    fp_zerozerox <= fp_zerozerox & ~iqentry_res[head][0];
10131
                    fp_subinfx   <= fp_subinfx   & ~iqentry_res[head][0];
10132
                    fp_infzerox  <= fp_infzerox  & ~iqentry_res[head][0];
10133
                    fp_NaNCmpx   <= fp_NaNCmpx   & ~iqentry_res[head][0];
10134
                    fp_swtx <= 1'b0;
10135
                end
10136
            `FDX:
10137
                begin
10138
                    fp_inexe <= fp_inexe     & ~iqentry_res[head][4];
10139
                    fp_dbzxe <= fp_dbzxe     & ~iqentry_res[head][3];
10140
                    fp_underxe <= fp_underxe & ~iqentry_res[head][2];
10141
                    fp_overxe <= fp_overxe   & ~iqentry_res[head][1];
10142
                    fp_invopxe <= fp_invopxe & ~iqentry_res[head][0];
10143
                end
10144
            `FEX:
10145
                begin
10146
                    fp_inexe <= fp_inexe     | iqentry_res[head][4];
10147
                    fp_dbzxe <= fp_dbzxe     | iqentry_res[head][3];
10148
                    fp_underxe <= fp_underxe | iqentry_res[head][2];
10149
                    fp_overxe <= fp_overxe   | iqentry_res[head][1];
10150
                    fp_invopxe <= fp_invopxe | iqentry_res[head][0];
10151
                end
10152
            default:
10153
                begin
10154
                    // 31 to 29 is rounding mode
10155
                    // 28 to 24 are exception enables
10156
                    // 23 is nsfp
10157
                    // 22 is a fractie
10158
                    fp_fractie <= iqentry_ares[head][22];
10159
                    fp_raz <= iqentry_ares[head][21];
10160
                    // 20 is a 0
10161
                    fp_neg <= iqentry_ares[head][19];
10162
                    fp_pos <= iqentry_ares[head][18];
10163
                    fp_zero <= iqentry_ares[head][17];
10164
                    fp_inf <= iqentry_ares[head][16];
10165
                    // 15 swtx
10166
                    // 14 
10167
                    fp_inex <= fp_inex | (fp_inexe & iqentry_ares[head][14]);
10168
                    fp_dbzx <= fp_dbzx | (fp_dbzxe & iqentry_ares[head][13]);
10169
                    fp_underx <= fp_underx | (fp_underxe & iqentry_ares[head][12]);
10170
                    fp_overx <= fp_overx | (fp_overxe & iqentry_ares[head][11]);
10171
                    //fp_giopx <= fp_giopx | (fp_giopxe & iqentry_res2[head][10]);
10172
                    //fp_invopx <= fp_invopx | (fp_invopxe & iqentry_res2[head][24]);
10173
                    //
10174
                    fp_cvtx <= fp_cvtx |  (fp_giopxe & iqentry_ares[head][7]);
10175
                    fp_sqrtx <= fp_sqrtx |  (fp_giopxe & iqentry_ares[head][6]);
10176
                    fp_NaNCmpx <= fp_NaNCmpx |  (fp_giopxe & iqentry_ares[head][5]);
10177
                    fp_infzerox <= fp_infzerox |  (fp_giopxe & iqentry_ares[head][4]);
10178
                    fp_zerozerox <= fp_zerozerox |  (fp_giopxe & iqentry_ares[head][3]);
10179
                    fp_infdivx <= fp_infdivx | (fp_giopxe & iqentry_ares[head][2]);
10180
                    fp_subinfx <= fp_subinfx | (fp_giopxe & iqentry_ares[head][1]);
10181
                    fp_snanx <= fp_snanx | (fp_giopxe & iqentry_ares[head][0]);
10182
 
10183
                end
10184
            endcase
10185
        default:    ;
10186
        endcase
10187
        // Once the flow control instruction commits, NOP it out to allow
10188
        // pending stores to be issued.
10189
        iqentry_instr[head][5:0] <= `NOP;
10190
    end
10191
end
10192
endtask
10193
 
10194
// CSR access tasks
10195
// This task does not work. Possibly because the always block @* doesn't
10196
// evaluate into the task to see which signals are changing. The following
10197
// code is simply included as an always block above.
10198
task read_csr;
10199
input [11:0] csrno;
10200
output [63:0] dat;
10201
input thread;
10202
begin
10203
`ifdef SUPPORT_SMT
10204
    if (csrno[11:10] >= ol[thread])
10205
`else
10206
    if (csrno[11:10] >= ol)
10207
`endif
10208
    casez(csrno[9:0])
10209
    `CSR_CR0:       dat <= cr0;
10210
    `CSR_HARTID:    dat <= hartid;
10211
    `CSR_TICK:      dat <= tick;
10212
    `CSR_PCR:       dat <= pcr;
10213
    `CSR_PCR2:      dat <= pcr2;
10214
    `CSR_PMR:                           dat <= pmr;
10215
    `CSR_WBRCD:         dat <= wbrcd;
10216
    `CSR_SEMA:      dat <= sema;
10217
    `CSR_KEYS:                  dat <= keys;
10218
    `CSR_TCB:           dat <= tcb;
10219
    `CSR_FSTAT:     dat <= {fp_rgs,fp_status};
10220
`ifdef SUPPORT_DBG
10221
    `CSR_DBAD0:     dat <= dbg_adr0;
10222
    `CSR_DBAD1:     dat <= dbg_adr1;
10223
    `CSR_DBAD2:     dat <= dbg_adr2;
10224
    `CSR_DBAD3:     dat <= dbg_adr3;
10225
    `CSR_DBCTRL:    dat <= dbg_ctrl;
10226
    `CSR_DBSTAT:    dat <= dbg_stat;
10227
`endif
10228
    `CSR_CAS:       dat <= cas;
10229
    `CSR_TVEC:      dat <= tvec[csrno[2:0]];
10230
    `CSR_BADADR:    dat <= badaddr[{thread,csrno[11:10]}];
10231
    `CSR_BADINSTR:      dat <= bad_instr[{thread,csrno[11:10]}];
10232
    `CSR_CAUSE:     dat <= {48'd0,cause[{thread,csrno[11:10]}]};
10233
`ifdef SUPPORT_SMT
10234
    `CSR_IM_STACK:      dat <= im_stack[thread];
10235
    `CSR_OL_STACK:      dat <= {dl_stack[thread],ol_stack[thread]};
10236
    `CSR_PL_STACK:      dat <= pl_stack[thread];
10237
    `CSR_RS_STACK:      dat <= rs_stack[thread];
10238
    `CSR_STATUS:    dat <= mstatus[thread][63:0];
10239
    `CSR_EPC0:      dat <= epc0[thread];
10240
    `CSR_EPC1:      dat <= epc1[thread];
10241
    `CSR_EPC2:      dat <= epc2[thread];
10242
    `CSR_EPC3:      dat <= epc3[thread];
10243
    `CSR_EPC4:      dat <= epc4[thread];
10244
    `CSR_EPC5:      dat <= epc5[thread];
10245
    `CSR_EPC6:      dat <= epc6[thread];
10246
    `CSR_EPC7:      dat <= epc7[thread];
10247
`else
10248
    `CSR_IM_STACK:      dat <= im_stack;
10249
    `CSR_OL_STACK:      dat <= {dl_stack,ol_stack};
10250
    `CSR_PL_STACK:      dat <= pl_stack;
10251
    `CSR_RS_STACK:      dat <= rs_stack;
10252
    `CSR_STATUS:    dat <= mstatus[63:0];
10253
    `CSR_EPC0:      dat <= epc0;
10254
    `CSR_EPC1:      dat <= epc1;
10255
    `CSR_EPC2:      dat <= epc2;
10256
    `CSR_EPC3:      dat <= epc3;
10257
    `CSR_EPC4:      dat <= epc4;
10258
    `CSR_EPC5:      dat <= epc5;
10259
    `CSR_EPC6:      dat <= epc6;
10260
    `CSR_EPC7:      dat <= epc7;
10261
`endif
10262
    `CSR_CODEBUF:   dat <= codebuf[csrno[5:0]];
10263
`ifdef SUPPORT_BBMS
10264
                `CSR_TB:                        dat <= tb;
10265
                `CSR_CBL:                       dat <= cbl;
10266
                `CSR_CBU:                       dat <= cbu;
10267
                `CSR_RO:                        dat <= ro;
10268
                `CSR_DBL:                       dat <= dbl;
10269
                `CSR_DBU:                       dat <= dbu;
10270
                `CSR_SBL:                       dat <= sbl;
10271
                `CSR_SBU:                       dat <= sbu;
10272
                `CSR_ENU:                       dat <= en;
10273
`endif
10274
`ifdef SUPPORT_PREDICATION
10275
                `CSR_PREGS:             read_pregs(dat);
10276
`endif
10277
    `CSR_Q_CTR:         dat <= iq_ctr;
10278
    `CSR_BM_CTR:        dat <= bm_ctr;
10279
    `CSR_ICL_CTR:       dat <= icl_ctr;
10280
    `CSR_IRQ_CTR:       dat <= irq_ctr;
10281
    `CSR_TIME:          dat <= wc_times;
10282
    `CSR_INFO:
10283
                    case(csrno[3:0])
10284
                    4'd0:   dat <= "Finitron";  // manufacturer
10285
                    4'd1:   dat <= "        ";
10286
                    4'd2:   dat <= "64 bit  ";  // CPU class
10287
                    4'd3:   dat <= "        ";
10288
                    4'd4:   dat <= "FT64    ";  // Name
10289
                    4'd5:   dat <= "        ";
10290
                    4'd6:   dat <= 64'd1;       // model #
10291
                    4'd7:   dat <= 64'd1;       // serial number
10292
                    4'd8:   dat <= {32'd16384,32'd16384};   // cache sizes instruction,data
10293
                    4'd9:   dat <= 64'd0;
10294
                    default:    dat <= 64'd0;
10295
                    endcase
10296
    default:    begin
10297
                        $display("Unsupported CSR:%h",csrno[10:0]);
10298
                        dat <= 64'hEEEEEEEEEEEEEEEE;
10299
                        end
10300
    endcase
10301
    else
10302
        dat <= 64'h0;
10303
end
10304
endtask
10305
 
10306
task write_csr;
10307
input [13:0] csrno;
10308
input [63:0] dat;
10309
input thread;
10310
begin
10311
`ifdef SUPPORT_SMT
10312
    if (csrno[11:10] >= ol[thread])
10313
`else
10314
    if (csrno[11:10] >= ol)
10315
`endif
10316
    case(csrno[13:12])
10317
    2'd1:   // CSRRW
10318
        casez(csrno[9:0])
10319
        `CSR_CR0:       cr0 <= dat;
10320
        `CSR_PCR:       pcr <= dat[31:0];
10321
        `CSR_PCR2:      pcr2 <= dat;
10322
        `CSR_PMR:       case(`NUM_IDU)
10323
                                                0,1:     pmr[0] <= 1'b1;
10324
                                                2:
10325
                                                        begin
10326
                                                                        if (dat[1:0]==2'b00)
10327
                                                                                pmr[1:0] <= 2'b01;
10328
                                                                        else
10329
                                                                                pmr[1:0] <= dat[1:0];
10330
                                                                        pmr[63:2] <= dat[63:2];
10331
                                                                end
10332
                                                3:
10333
                                                        begin
10334
                                                                        if (dat[2:0]==3'b000)
10335
                                                                                pmr[2:0] <= 3'b001;
10336
                                                                        else
10337
                                                                                pmr[2:0] <= dat[2:0];
10338
                                                                        pmr[63:3] <= dat[63:3];
10339
                                                                end
10340
                                                default:        pmr[0] <= 1'b1;
10341
                                                endcase
10342
        `CSR_WBRCD:             wbrcd <= dat;
10343
        `CSR_SEMA:      sema <= dat;
10344
        `CSR_KEYS:      keys <= dat;
10345
        `CSR_TCB:               tcb <= dat;
10346
        `CSR_FSTAT:             fpu_csr[37:32] <= dat[37:32];
10347
        `CSR_BADADR:    badaddr[{thread,csrno[11:10]}] <= dat;
10348
        `CSR_BADINSTR:  bad_instr[{thread,csrno[11:10]}] <= dat;
10349
        `CSR_CAUSE:     cause[{thread,csrno[11:10]}] <= dat[15:0];
10350
`ifdef SUPPORT_DBG
10351
        `CSR_DBAD0:     dbg_adr0 <= dat[AMSB:0];
10352
        `CSR_DBAD1:     dbg_adr1 <= dat[AMSB:0];
10353
        `CSR_DBAD2:     dbg_adr2 <= dat[AMSB:0];
10354
        `CSR_DBAD3:     dbg_adr3 <= dat[AMSB:0];
10355
        `CSR_DBCTRL:    dbg_ctrl <= dat;
10356
`endif
10357
        `CSR_CAS:       cas <= dat;
10358
        `CSR_TVEC:      tvec[csrno[2:0]] <= dat[31:0];
10359
`ifdef SUPPORT_SMT
10360
        `CSR_IM_STACK:  im_stack[thread] <= dat[31:0];
10361
        `CSR_OL_STACK:  begin
10362
                                                                        ol_stack[thread] <= dat[15:0];
10363
                                                                        dl_stack[thread] <= dat[31:16];
10364
                                                                        end
10365
        `CSR_PL_STACK:  pl_stack[thread] <= dat;
10366
        `CSR_RS_STACK:  rs_stack[thread] <= dat;
10367
        `CSR_STATUS:    mstatus[thread][63:0] <= dat;
10368
        `CSR_EPC0:      epc0[thread] <= dat;
10369
        `CSR_EPC1:      epc1[thread] <= dat;
10370
        `CSR_EPC2:      epc2[thread] <= dat;
10371
        `CSR_EPC3:      epc3[thread] <= dat;
10372
        `CSR_EPC4:      epc4[thread] <= dat;
10373
        `CSR_EPC5:      epc5[thread] <= dat;
10374
        `CSR_EPC6:      epc6[thread] <= dat;
10375
        `CSR_EPC7:      epc7[thread] <= dat;
10376
`else
10377
        `CSR_IM_STACK:  im_stack <= dat[31:0];
10378
        `CSR_OL_STACK:  begin
10379
                                                                        ol_stack <= dat[15:0];
10380
                                                                        dl_stack <= dat[31:16];
10381
                                                                        end
10382
        `CSR_PL_STACK:  pl_stack <= dat;
10383
        `CSR_RS_STACK:  rs_stack <= dat;
10384
        `CSR_STATUS:    mstatus[63:0] <= dat;
10385
        `CSR_EPC0:      epc0 <= dat;
10386
        `CSR_EPC1:      epc1 <= dat;
10387
        `CSR_EPC2:      epc2 <= dat;
10388
        `CSR_EPC3:      epc3 <= dat;
10389
        `CSR_EPC4:      epc4 <= dat;
10390
        `CSR_EPC5:      epc5 <= dat;
10391
        `CSR_EPC6:      epc6 <= dat;
10392
        `CSR_EPC7:      epc7 <= dat;
10393
`endif
10394
`ifdef SUPPORT_BBMS
10395
                                `CSR_TB:                        prg_base[brgs] <= dat;
10396
                                `CSR_CBL:                       cl_barrier[brgs] <= dat;
10397
                                `CSR_CBU:                       cu_barrier[brgs] <= dat;
10398
                                `CSR_RO:                        ro_barrier[brgs] <= dat;
10399
                                `CSR_DBL:                       dl_barrier[brgs] <= dat;
10400
                                `CSR_DBU:                       du_barrier[brgs] <= dat;
10401
                                `CSR_SBL:                       sl_barrier[brgs] <= dat;
10402
                                `CSR_SBU:                       su_barrier[brgs] <= dat;
10403
                                `CSR_ENU:                       en_barrier[brgs] <= dat;
10404
`endif
10405
`ifdef SUPPORT_PREDICATION
10406
                                `CSR_PREGS:                     write_pregs(dat);
10407
`endif
10408
                                `CSR_TIME:              begin
10409
                                                ld_time <= 6'h3f;
10410
                                                wc_time_dat <= dat;
10411
                                                end
10412
        `CSR_CODEBUF:   codebuf[csrno[5:0]] <= dat;
10413
        default:    ;
10414
        endcase
10415
    2'd2:   // CSRRS
10416
        case(csrno[9:0])
10417
        `CSR_CR0:       cr0 <= cr0 | dat;
10418
        `CSR_PCR:       pcr[31:0] <= pcr[31:0] | dat[31:0];
10419
        `CSR_PCR2:      pcr2 <= pcr2 | dat;
10420
        `CSR_PMR:                               pmr <= pmr | dat;
10421
        `CSR_WBRCD:             wbrcd <= wbrcd | dat;
10422
`ifdef SUPPORT_DBG
10423
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl | dat;
10424
`endif
10425
        `CSR_SEMA:      sema <= sema | dat;
10426
`ifdef SUPPORT_SMT
10427
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] | dat;
10428
`else
10429
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] | dat;
10430
`endif
10431
        default:    ;
10432
        endcase
10433
    2'd3:   // CSRRC
10434
        case(csrno[9:0])
10435
        `CSR_CR0:       cr0 <= cr0 & ~dat;
10436
        `CSR_PCR:       pcr <= pcr & ~dat;
10437
        `CSR_PCR2:      pcr2 <= pcr2 & ~dat;
10438
        `CSR_PMR:                       begin
10439
                                                                if (dat[1:0]==2'b11)
10440
                                                                        pmr[1:0] <= 2'b01;
10441
                                                                else
10442
                                                                        pmr[1:0] <= pmr[1:0] & ~dat[1:0];
10443
                                                                pmr[63:2] <= pmr[63:2] & ~dat[63:2];
10444
                                                                end
10445
        `CSR_WBRCD:             wbrcd <= wbrcd & ~dat;
10446
`ifdef SUPPORT_DBG
10447
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl & ~dat;
10448
`endif
10449
        `CSR_SEMA:      sema <= sema & ~dat;
10450
`ifdef SUPPORT_SMT
10451
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] & ~dat;
10452
`else
10453
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] & ~dat;
10454
`endif
10455
        default:    ;
10456
        endcase
10457
    default:    ;
10458
    endcase
10459
end
10460
endtask
10461
 
10462
task tDram0Issue;
10463
input [`QBITSP1] n;
10464
begin
10465
//      dramA_v <= `INV;
10466
        dram0           <= `DRAMSLOT_BUSY;
10467
        dram0_id        <= { 1'b1, n[`QBITS] };
10468
        dram0_instr <= iqentry_instr[n];
10469
        dram0_rmw  <= iqentry_rmw[n];
10470
        dram0_preload <= iqentry_preload[n];
10471
        dram0_tgt       <= iqentry_tgt[n];
10472
        dram0_data      <= iqentry_a2[n];
10473
        dram0_addr      <= iqentry_ma[n];
10474
        //             if (ol[iqentry_thrd[n]]==`OL_USER)
10475
        //              dram0_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
10476
        //             else
10477
        dram0_unc   <= iqentry_ma[n][31:20]==12'hFFD || !dce || iqentry_loadv[n];
10478
        dram0_memsize <= iqentry_memsz[n];
10479
        dram0_load <= iqentry_load[n];
10480
        dram0_store <= iqentry_store[n];
10481
`ifdef SUPPORT_SMT
10482
        dram0_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
10483
`else
10484
        dram0_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol : dl;
10485
`endif
10486
        // Once the memory op is issued reset the a1_v flag.
10487
        // This will cause the a1 bus to look for new data from memory (a1_s is pointed to a memory bus)
10488
        // This is used for the load and compare instructions.
10489
        // must reset the a1 source too.
10490
        //iqentry_a1_v[n] <= `INV;
10491
        iqentry_state[n] <= IQS_MEM;
10492
end
10493
endtask
10494
 
10495
task tDram1Issue;
10496
input [`QBITSP1] n;
10497
begin
10498
        dramB_v <= `INV;
10499
        dram1           <= `DRAMSLOT_BUSY;
10500
        dram1_id        <= { 1'b1, n[`QBITS] };
10501
        dram1_instr <= iqentry_instr[n];
10502
        dram1_rmw  <= iqentry_rmw[n];
10503
        dram1_preload <= iqentry_preload[n];
10504
        dram1_tgt       <= iqentry_tgt[n];
10505
        dram1_data      <= iqentry_a2[n];
10506
        dram1_addr      <= iqentry_ma[n];
10507
        //                   if (ol[iqentry_thrd[n]]==`OL_USER)
10508
        //                      dram1_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
10509
        //                   else
10510
        dram1_unc   <= iqentry_ma[n][31:20]==12'hFFD || !dce || iqentry_loadv[n];
10511
        dram1_memsize <= iqentry_memsz[n];
10512
        dram1_load <= iqentry_load[n];
10513
        dram1_store <= iqentry_store[n];
10514
`ifdef SUPPORT_SMT
10515
        dram1_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
10516
`else
10517
        dram1_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol : dl;
10518
`endif
10519
        //iqentry_a1_v[n] <= `INV;
10520
        iqentry_state[n] <= IQS_MEM;
10521
end
10522
endtask
10523
 
10524
task tDram2Issue;
10525
input [`QBITSP1] n;
10526
begin
10527
        dramC_v <= `INV;
10528
        dram2           <= `DRAMSLOT_BUSY;
10529
        dram2_id        <= { 1'b1, n[`QBITS] };
10530
        dram2_instr     <= iqentry_instr[n];
10531
        dram2_rmw  <= iqentry_rmw[n];
10532
        dram2_preload <= iqentry_preload[n];
10533
        dram2_tgt       <= iqentry_tgt[n];
10534
        dram2_data      <= iqentry_a2[n];
10535
        dram2_addr      <= iqentry_ma[n];
10536
        //                   if (ol[iqentry_thrd[n]]==`OL_USER)
10537
        //                      dram2_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
10538
        //                   else
10539
        dram2_unc   <= iqentry_ma[n][31:20]==12'hFFD || !dce || iqentry_loadv[n];
10540
        dram2_memsize <= iqentry_memsz[n];
10541
        dram2_load <= iqentry_load[n];
10542
        dram2_store <= iqentry_store[n];
10543
`ifdef SUPPORT_SMT
10544
        dram2_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
10545
`else
10546
        dram2_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol : dl;
10547
`endif
10548
        //iqentry_a1_v[n] <= `INV;
10549
        iqentry_state[n] <= IQS_MEM;
10550
end
10551
endtask
10552
 
10553
task wb_nack;
10554
begin
10555
        cti_o <= 3'b000;
10556
        bte_o <= 2'b00;
10557
        cyc <= `LOW;
10558
        stb_o <= `LOW;
10559
        we <= `LOW;
10560
        sel_o <= 8'h00;
10561
end
10562
endtask
10563
 
10564
endmodule
10565
 
10566
 
10567
module decoder5 (num, out);
10568
input [4:0] num;
10569
output [31:1] out;
10570
reg [31:1] out;
10571
 
10572
always @(num)
10573
case (num)
10574
    5'd0 :      out <= 31'b0000000000000000000000000000000;
10575
    5'd1 :      out <= 31'b0000000000000000000000000000001;
10576
    5'd2 :      out <= 31'b0000000000000000000000000000010;
10577
    5'd3 :      out <= 31'b0000000000000000000000000000100;
10578
    5'd4 :      out <= 31'b0000000000000000000000000001000;
10579
    5'd5 :      out <= 31'b0000000000000000000000000010000;
10580
    5'd6 :      out <= 31'b0000000000000000000000000100000;
10581
    5'd7 :      out <= 31'b0000000000000000000000001000000;
10582
    5'd8 :      out <= 31'b0000000000000000000000010000000;
10583
    5'd9 :      out <= 31'b0000000000000000000000100000000;
10584
    5'd10:      out <= 31'b0000000000000000000001000000000;
10585
    5'd11:      out <= 31'b0000000000000000000010000000000;
10586
    5'd12:      out <= 31'b0000000000000000000100000000000;
10587
    5'd13:      out <= 31'b0000000000000000001000000000000;
10588
    5'd14:      out <= 31'b0000000000000000010000000000000;
10589
    5'd15:      out <= 31'b0000000000000000100000000000000;
10590
    5'd16:      out <= 31'b0000000000000001000000000000000;
10591
    5'd17:      out <= 31'b0000000000000010000000000000000;
10592
    5'd18:      out <= 31'b0000000000000100000000000000000;
10593
    5'd19:      out <= 31'b0000000000001000000000000000000;
10594
    5'd20:      out <= 31'b0000000000010000000000000000000;
10595
    5'd21:      out <= 31'b0000000000100000000000000000000;
10596
    5'd22:      out <= 31'b0000000001000000000000000000000;
10597
    5'd23:      out <= 31'b0000000010000000000000000000000;
10598
    5'd24:      out <= 31'b0000000100000000000000000000000;
10599
    5'd25:      out <= 31'b0000001000000000000000000000000;
10600
    5'd26:      out <= 31'b0000010000000000000000000000000;
10601
    5'd27:      out <= 31'b0000100000000000000000000000000;
10602
    5'd28:      out <= 31'b0001000000000000000000000000000;
10603
    5'd29:      out <= 31'b0010000000000000000000000000000;
10604
    5'd30:      out <= 31'b0100000000000000000000000000000;
10605
    5'd31:      out <= 31'b1000000000000000000000000000000;
10606
endcase
10607
 
10608
endmodule
10609
 
10610
module decoder6 (num, out);
10611
input [5:0] num;
10612
output [63:1] out;
10613
 
10614
wire [63:0] out1;
10615
 
10616
assign out1 = 64'd1 << num;
10617
assign out = out1[63:1];
10618
 
10619
endmodule
10620
 
10621
module decoder7 (num, out);
10622
input [6:0] num;
10623
output [127:1] out;
10624
 
10625
wire [127:0] out1;
10626
 
10627
assign out1 = 128'd1 << num;
10628
assign out = out1[127:1];
10629
 
10630
endmodule
10631
 
10632
module decoder8 (num, out);
10633
input [7:0] num;
10634
output [255:1] out;
10635
 
10636
wire [255:0] out1;
10637
 
10638
assign out1 = 256'd1 << num;
10639
assign out = out1[255:1];
10640
 
10641
endmodule
10642
 

powered by: WebSVN 2.1.0

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