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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [rtl/] [twoway/] [FT64.v] - Blame information for rev 48

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

Line No. Rev Author Line
1 48 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
//  - asynchronous logic loops for issue and branch miss
23
//    re-written for synchronous operation, not as elegant
24
//    but required for operation in an FPGA
25
//      - fine-grained simultaneous multi-threading (SMT)
26
//
27
// This source file is free software: you can redistribute it and/or modify 
28
// it under the terms of the GNU Lesser General Public License as published 
29
// by the Free Software Foundation, either version 3 of the License, or     
30
// (at your option) any later version.                                      
31
//                                                                          
32
// This source file is distributed in the hope that it will be useful,      
33
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
34
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
35
// GNU General Public License for more details.                             
36
//                                                                          
37
// You should have received a copy of the GNU General Public License        
38
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
39
//
40
// Approx. 100,000 LUTs. 160,000 LC's.
41
// ============================================================================
42
//
43
`include "FT64_defines.vh"
44
//`define SUPPORT_DBG           1'b1
45
//`define FULL_ISSUE_LOGIC      1'b1
46
`define QBITS           2:0
47
`define QENTRIES        8
48
`define ID1_AVAIL       1'b1
49
`define ID2_AVAIL       1'b1
50
`define ALU0_AVAIL      1'b1
51
`define ALU1_AVAIL      1'b1
52
`define FPU1_AVAIL      1'b1
53
`define FPU2_AVAIL      1'b0
54
 
55
module FT64(hartid, rst, clk_i, clk4x, tm_clk_i, irq_i, vec_i, bte_o, cti_o, cyc_o, stb_o, ack_i, err_i, we_o, sel_o, adr_o, dat_o, dat_i,
56
    ol_o, pcr_o, pcr2_o, exv_i, rdv_i, wrv_i, icl_o, sr_o, cr_o, rbi_i, signal_i);
57
input [63:0] hartid;
58
input rst;
59
input clk_i;
60
input clk4x;
61
input tm_clk_i;
62
input [2:0] irq_i;
63
input [7:0] vec_i;
64
output reg [1:0] bte_o;
65
output reg [2:0] cti_o;
66
output reg cyc_o;
67
output reg stb_o;
68
input ack_i;
69
input err_i;
70
output reg we_o;
71
output reg [7:0] sel_o;
72
output reg [31:0] adr_o;
73
output reg [63:0] dat_o;
74
input [63:0] dat_i;
75
output reg [1:0] ol_o;
76
output [31:0] pcr_o;
77
output [63:0] pcr2_o;
78
input exv_i;
79
input rdv_i;
80
input wrv_i;
81
output reg icl_o;
82
output reg cr_o;
83
output reg sr_o;
84
input rbi_i;
85
input [31:0] signal_i;
86
 
87
parameter TM_CLKFREQ = 20000000;
88
parameter QENTRIES = `QENTRIES;
89
parameter RSTPC = 32'hFFFC0100;
90
parameter BRKPC = 32'hFFFC0000;
91
`ifdef SUPPORT_SMT
92
parameter PREGS = 256;   // number of physical registers - 1
93
parameter AREGS = 256;   // number of architectural registers
94
`else
95
parameter PREGS = 128;
96
parameter AREGS = 128;
97
`endif
98
parameter RBIT = 11;
99
parameter DEBUG = 1'b0;
100
parameter NMAP = QENTRIES;
101
parameter BRANCH_PRED = 1'b0;
102
parameter SUP_TXE = 1'b0;
103
parameter SUP_VECTOR = 1;
104
parameter DBW = 64;
105
parameter ABW = 32;
106
parameter AMSB = ABW-1;
107
parameter NTHREAD = 1;
108
reg [3:0] i;
109
integer n;
110
integer j;
111
genvar g;
112
parameter TRUE = 1'b1;
113
parameter FALSE = 1'b0;
114
// Memory access sizes
115
parameter byt = 3'd0;
116
parameter wyde = 3'd1;
117
parameter tetra = 3'd2;
118
parameter octa = 3'd3;
119
// IQ states
120
parameter IQS_IDLE = 2'd0;
121
parameter IQS_AGEN = 2'd1;
122
parameter IQS_LDDONE = 2'd2;
123
parameter IQS_S3 = 2'd3;
124
 
125
wire clk;
126
BUFG uclkb1
127
(
128
        .I(clk_i),
129
        .O(clk)
130
);
131
 
132
wire dc_ack;
133
wire acki = ack_i|dc_ack;
134
wire [RBIT:0] Ra0, Ra1;
135
wire [RBIT:0] Rb0, Rb1;
136
wire [RBIT:0] Rc0, Rc1;
137
wire [RBIT:0] Rt0, Rt1;
138
wire [63:0] rfoa0,rfob0,rfoc0,rfoc0a;
139
wire [63:0] rfoa1,rfob1,rfoc1,rfoc1a;
140
`ifdef SUPPORT_SMT
141
wire [7:0] Ra0s = {Ra0[7:0]};
142
wire [7:0] Ra1s = {Ra1[7:0]};
143
wire [7:0] Rb0s = {Rb0[7:0]};
144
wire [7:0] Rb1s = {Rb1[7:0]};
145
wire [7:0] Rc0s = {Rc0[7:0]};
146
wire [7:0] Rc1s = {Rc1[7:0]};
147
wire [7:0] Rt0s = {Rt0[7:0]};
148
wire [7:0] Rt1s = {Rt1[7:0]};
149
`else
150
wire [6:0] Ra0s = {Ra0[7],Ra0[5:0]};
151
wire [6:0] Ra1s = {Ra1[7],Ra1[5:0]};
152
wire [6:0] Rb0s = {Rb0[7],Rb0[5:0]};
153
wire [6:0] Rb1s = {Rb1[7],Rb1[5:0]};
154
wire [6:0] Rc0s = {Rc0[7],Rc0[5:0]};
155
wire [6:0] Rc1s = {Rc1[7],Rc1[5:0]};
156
wire [6:0] Rt0s = {Rt0[7],Rt0[5:0]};
157
wire [6:0] Rt1s = {Rt1[7],Rt1[5:0]};
158
/*
159
wire [5:0] Ra0s = {Ra0[5:0]};
160
wire [5:0] Ra1s = {Ra1[5:0]};
161
wire [5:0] Rb0s = {Rb0[5:0]};
162
wire [5:0] Rb1s = {Rb1[5:0]};
163
wire [5:0] Rc0s = {Rc0[5:0]};
164
wire [5:0] Rc1s = {Rc1[5:0]};
165
wire [5:0] Rt0s = {Rt0[5:0]};
166
wire [5:0] Rt1s = {Rt1[5:0]};
167
*/
168
`endif
169
 
170
reg [63:0] ds [0:NTHREAD];
171
reg [63:0] ss [0:NTHREAD];
172
reg [63:0] ptrmask [0:NTHREAD];
173
reg [63:0] ptrkey = "  OBJECT";
174
reg [63:0] wbrcd;
175
 
176
reg  [PREGS-1:0] rf_v;
177
reg  [4:0] rf_source[0:AREGS-1];
178
initial begin
179
for (n = 0; n < AREGS; n = n + 1)
180
        rf_source[n] = 5'd0;
181
end
182
wire [31:0] pc0;
183
wire [31:0] pc1;
184
 
185
reg excmiss;
186
reg [31:0] excmisspc;
187
reg excthrd;
188
reg exception_set;
189
reg rdvq;               // accumulated read violation
190
reg errq;               // accumulated err_i input status
191
reg exvq;
192
 
193
// Vector
194
reg [5:0] vqe0, vqe1;   // vector element being queued
195
reg [5:0] vqet0, vqet1;
196
reg [7:0] vl;           // vector length
197
reg [63:0] vm [0:7];    // vector mask registers
198
reg [1:0] m2;
199
 
200
// CSR's
201
reg [63:0] cr0;
202
wire snr = cr0[17];             // sequence number reset
203
wire dce = cr0[30];     // data cache enable
204
wire bpe = cr0[32];     // branch predictor enable
205
wire ctgtxe = cr0[33];
206
// Simply setting this flag to zero should strip out almost all the logic
207
// associated SMT.
208
`ifdef SUPPORT_SMT
209
wire thread_en = cr0[16];
210
`else
211
wire thread_en = 1'b0;
212
`endif
213
wire vechain = cr0[18];
214
reg [7:0] fcu_timeout;
215
reg [63:0] tick;
216
reg [63:0] wc_time;
217
reg [31:0] pcr;
218
reg [63:0] pcr2;
219
assign pcr_o = pcr;
220
assign pcr2_o = pcr2;
221
reg [63:0] aec;
222
reg [15:0] cause[0:15];
223
`ifdef SUPPORT_SMT
224
reg [31:0] epc [0:NTHREAD];
225
reg [31:0] epc0 [0:NTHREAD];
226
reg [31:0] epc1 [0:NTHREAD];
227
reg [31:0] epc2 [0:NTHREAD];
228
reg [31:0] epc3 [0:NTHREAD];
229
reg [31:0] epc4 [0:NTHREAD];
230
reg [31:0] epc5 [0:NTHREAD];
231
reg [31:0] epc6 [0:NTHREAD];
232
reg [31:0] epc7 [0:NTHREAD];
233
reg [31:0] epc8 [0:NTHREAD];                      // exception pc and stack
234
reg [63:0] mstatus [0:NTHREAD];           // machine status
235
wire [2:0] im = mstatus[0][2:0];
236
wire [1:0] ol [0:NTHREAD];
237
wire [1:0] dl [0:NTHREAD];
238
assign ol[0] = mstatus[0][5:3];   // operating level
239
assign dl[0] = mstatus[0][21:20];
240
wire [7:0] cpl [0:NTHREAD];
241
assign cpl[0] = mstatus[0][13:6]; // current privilege level
242
wire [5:0] rgs [0:NTHREAD];
243
assign rgs[0] = mstatus[0][19:14];
244
assign ol[1] = mstatus[1][5:3]; // operating level
245
assign cpl[1] = mstatus[1][13:6];       // current privilege level
246
assign rgs[1] = mstatus[1][19:14];
247
assign dl[1] = mstatus[1][21:20];
248
reg [15:0] ol_stack [0:NTHREAD];
249
reg [31:0] im_stack [0:NTHREAD];
250
reg [63:0] pl_stack [0:NTHREAD];
251
reg [63:0] rs_stack [0:NTHREAD];
252
reg [63:0] fr_stack [0:NTHREAD];
253
wire mprv = mstatus[0][55];
254
wire [5:0] fprgs = mstatus[0][25:20];
255
//assign ol_o = mprv ? ol_stack[0][2:0] : ol[0];
256
wire vca = mstatus[0][32];               // vector chaining active
257
`else
258
reg [31:0] epc ;
259
reg [31:0] epc0 ;
260
reg [31:0] epc1 ;
261
reg [31:0] epc2 ;
262
reg [31:0] epc3 ;
263
reg [31:0] epc4 ;
264
reg [31:0] epc5 ;
265
reg [31:0] epc6 ;
266
reg [31:0] epc7 ;
267
reg [31:0] epc8 ;                        // exception pc and stack
268
reg [63:0] mstatus ;             // machine status
269
wire [2:0] im = mstatus[2:0];
270
wire [1:0] ol ;
271
wire [1:0] dl;
272
assign ol = mstatus[5:3];       // operating level
273
assign dl = mstatus[21:20];
274
wire [7:0] cpl ;
275
assign cpl = mstatus[13:6];     // current privilege level
276
wire [5:0] rgs ;
277
assign rgs = mstatus[19:14];
278
reg [15:0] ol_stack ;
279
reg [31:0] im_stack ;
280
reg [63:0] pl_stack ;
281
reg [63:0] rs_stack ;
282
reg [63:0] fr_stack ;
283
wire mprv = mstatus[55];
284
wire [5:0] fprgs = mstatus[25:20];
285
//assign ol_o = mprv ? ol_stack[2:0] : ol;
286
wire vca = mstatus[32];         // vector chaining active
287
`endif
288
reg [63:0] tcb;
289
reg [31:0] badaddr[0:15];
290
reg [31:0] tvec[0:7];
291
reg [63:0] sema;
292
reg [63:0] vm_sema;
293
reg [63:0] cas;         // compare and swap
294
reg [63:0] ve_hold;
295
reg isCAS, isAMO, isInc, isSpt, isRMW;
296
reg [`QBITS] casid;
297
reg [31:0] sbl, sbu;
298
reg [4:0] regLR = 5'd29;
299
 
300
reg [2:0] fp_rm;
301
reg fp_inexe;
302
reg fp_dbzxe;
303
reg fp_underxe;
304
reg fp_overxe;
305
reg fp_invopxe;
306
reg fp_giopxe;
307
reg fp_nsfp = 1'b0;
308
reg fp_fractie;
309
reg fp_raz;
310
 
311
reg fp_neg;
312
reg fp_pos;
313
reg fp_zero;
314
reg fp_inf;
315
 
316
reg fp_inex;            // inexact exception
317
reg fp_dbzx;            // divide by zero exception
318
reg fp_underx;          // underflow exception
319
reg fp_overx;           // overflow exception
320
reg fp_giopx;           // global invalid operation exception
321
reg fp_sx;                      // summary exception
322
reg fp_swtx;        // software triggered exception
323
reg fp_gx;
324
reg fp_invopx;
325
 
326
reg fp_infzerox;
327
reg fp_zerozerox;
328
reg fp_subinfx;
329
reg fp_infdivx;
330
reg fp_NaNCmpx;
331
reg fp_cvtx;
332
reg fp_sqrtx;
333
reg fp_snanx;
334
 
335
wire [31:0] fp_status = {
336
 
337
        fp_rm,
338
        fp_inexe,
339
        fp_dbzxe,
340
        fp_underxe,
341
        fp_overxe,
342
        fp_invopxe,
343
        fp_nsfp,
344
 
345
        fp_fractie,
346
        fp_raz,
347
        1'b0,
348
        fp_neg,
349
        fp_pos,
350
        fp_zero,
351
        fp_inf,
352
 
353
        fp_swtx,
354
        fp_inex,
355
        fp_dbzx,
356
        fp_underx,
357
        fp_overx,
358
        fp_giopx,
359
        fp_gx,
360
        fp_sx,
361
 
362
        fp_cvtx,
363
        fp_sqrtx,
364
        fp_NaNCmpx,
365
        fp_infzerox,
366
        fp_zerozerox,
367
        fp_infdivx,
368
        fp_subinfx,
369
        fp_snanx
370
        };
371
 
372
reg [63:0] fpu_csr;
373
wire [5:0] fp_rgs = fpu_csr[37:32];
374
 
375
//reg [25:0] m[0:8191];
376
reg  [3:0] panic;                // indexes the message structure
377
reg [128:0] message [0:15];       // indexed by panic
378
 
379
wire int_commit;
380
reg StatusHWI;
381
reg [47:0] insn0, insn1;
382
wire [47:0] insn0a, insn1a, insn1b;
383
reg tgtq;
384
// Only need enough bits in the seqnence number to cover the instructions in
385
// the queue plus an extra count for skipping on branch misses. In this case
386
// that would be four bits minimum (count 0 to 8). 
387
reg [31:0] seq_num;
388
reg [31:0] seq_num1;
389
wire [63:0] rdat0,rdat1,rdat2;
390
reg [63:0] xdati;
391
 
392
reg canq1, canq2;
393
reg queued1;
394
reg queued2;
395
reg queuedNop;
396
 
397
reg [47:0] codebuf[0:63];
398
reg [7:0] setpred;
399
 
400
// instruction queue (ROB)
401
reg [31:0]  iqentry_sn   [0:QENTRIES-1];  // instruction sequence number
402
reg [QENTRIES-1:0] iqentry_v;                    // entry valid?  -- this should be the first bit
403
reg [QENTRIES-1:0] iqentry_iv;           // instruction is valid
404
reg [4:0]  iqentry_is   [0:QENTRIES-1];   // source of instruction
405
reg [QENTRIES-1:0] iqentry_out;  // instruction has been issued to an ALU ... 
406
reg [QENTRIES-1:0] iqentry_done; // instruction result valid
407
reg [QENTRIES-1:0] iqentry_cmt;
408
reg [QENTRIES-1:0] iqentry_thrd;         // which thread the instruction is in
409
reg [QENTRIES-1:0] iqentry_pt;           // predict taken
410
reg [QENTRIES-1:0] iqentry_bt;   // branch-taken (used only for branches)
411
reg [QENTRIES-1:0] iqentry_agen; // address-generate ... signifies that address is ready (only for LW/SW)
412
reg  [1:0] iqentry_state [0:QENTRIES-1];
413
reg [QENTRIES-1:0] iqentry_alu = 8'h00;  // alu type instruction
414
reg [QENTRIES-1:0] iqentry_alu0;  // only valid on alu #0
415
reg [QENTRIES-1:0] iqentry_fpu;  // floating point instruction
416
reg [QENTRIES-1:0] iqentry_fc;   // flow control instruction
417
reg [QENTRIES-1:0] iqentry_canex = 8'h00;        // true if it's an instruction that can exception
418
reg        iqentry_load [0:QENTRIES-1];  // is a memory load instruction
419
reg        iqentry_preload [0:QENTRIES-1];       // is a memory preload instruction
420
reg        iqentry_ldcmp [0:QENTRIES-1];
421
reg        iqentry_mem  [0:QENTRIES-1];  // touches memory: 1 if LW/SW
422
reg        iqentry_memndx   [0:QENTRIES-1];  // indexed memory operation 
423
reg        iqentry_rmw          [0:QENTRIES-1];  // memory RMW op
424
reg        iqentry_memdb    [0:QENTRIES-1];
425
reg        iqentry_memsb    [0:QENTRIES-1];
426
reg        iqentry_rtop [0:QENTRIES-1];
427
reg [QENTRIES-1:0] iqentry_sei;
428
reg [QENTRIES-1:0] iqentry_aq;   // memory aquire
429
reg [QENTRIES-1:0] iqentry_rl;   // memory release
430
reg        iqentry_shft48[0:QENTRIES-1];
431
reg        iqentry_jmp  [0:QENTRIES-1];  // changes control flow: 1 if BEQ/JALR
432
reg [QENTRIES-1:0] iqentry_br;  // Bcc (for predictor)
433
reg        iqentry_sync [0:QENTRIES-1];  // sync instruction
434
reg        iqentry_fsync[0:QENTRIES-1];
435
reg [QENTRIES-1:0] iqentry_rfw = 8'h00;  // writes to register file
436
reg  [7:0] iqentry_we   [0:QENTRIES-1];   // enable strobe
437
reg [63:0] iqentry_res   [0:QENTRIES-1];  // instruction result
438
reg [47:0] iqentry_instr[0:QENTRIES-1];   // instruction opcode
439
reg  [2:0] iqentry_insln[0:QENTRIES-1]; // instruction length
440
reg  [7:0] iqentry_exc   [0:QENTRIES-1];  // only for branches ... indicates a HALT instruction
441
reg [RBIT:0] iqentry_tgt [0:QENTRIES-1];  // Rt field or ZERO -- this is the instruction's target (if any)
442
reg  [7:0] iqentry_vl   [0:QENTRIES-1];
443
reg  [5:0] iqentry_ven  [0:QENTRIES-1];  // vector element number
444
reg [63:0] iqentry_a0    [0:QENTRIES-1];  // argument 0 (immediate)
445
reg [63:0] iqentry_a1    [0:QENTRIES-1];  // argument 1
446
reg        iqentry_a1_v [0:QENTRIES-1];  // arg1 valid
447
reg  [4:0] iqentry_a1_s  [0:QENTRIES-1];  // arg1 source (iq entry # with top bit representing ALU/DRAM bus)
448
reg [63:0] iqentry_a2    [0:QENTRIES-1];  // argument 2
449
reg        iqentry_a2_v [0:QENTRIES-1];  // arg2 valid
450
reg  [4:0] iqentry_a2_s  [0:QENTRIES-1];  // arg2 source (iq entry # with top bit representing ALU/DRAM bus)
451
reg [63:0] iqentry_a3    [0:QENTRIES-1];  // argument 3
452
reg        iqentry_a3_v [0:QENTRIES-1];  // arg3 valid
453
reg  [4:0] iqentry_a3_s  [0:QENTRIES-1];  // arg3 source (iq entry # with top bit representing ALU/DRAM bus)
454
reg [31:0] iqentry_pc    [0:QENTRIES-1];  // program counter for this instruction
455
reg [RBIT:0] iqentry_Ra [0:QENTRIES-1];
456
reg [RBIT:0] iqentry_Rb [0:QENTRIES-1];
457
reg [RBIT:0] iqentry_Rc [0:QENTRIES-1];
458
// debugging
459
//reg  [4:0] iqentry_ra   [0:7];  // Ra
460
initial begin
461
for (n = 0; n < QENTRIES; n = n + 1)
462
        iqentry_a1_s[n] = 5'd0;
463
        iqentry_a2_s[n] = 5'd0;
464
        iqentry_a3_s[n] = 5'd0;
465
end
466
 
467
wire  [QENTRIES-1:0] iqentry_source = 8'h00;
468
reg   [QENTRIES-1:0] iqentry_imm;
469
wire  [QENTRIES-1:0] iqentry_memready;
470
wire  [QENTRIES-1:0] iqentry_memopsvalid;
471
 
472
reg  [QENTRIES-1:0] memissue = 8'h00;
473
reg [1:0] missued;
474
integer last_issue;
475
reg  [QENTRIES-1:0] iqentry_memissue;
476
wire [QENTRIES-1:0] iqentry_stomp;
477
reg [3:0] stompedOnRets;
478
reg  [QENTRIES-1:0] iqentry_alu0_issue;
479
reg  [QENTRIES-1:0] iqentry_alu1_issue;
480
reg  [QENTRIES-1:0] iqentry_id1issue;
481
reg  [QENTRIES-1:0] iqentry_id2issue;
482
reg [1:0] iqentry_mem_islot [0:QENTRIES-1];
483
reg [1:0] iqentry_fpu_islot [0:QENTRIES-1];
484
reg [QENTRIES-1:0] iqentry_fcu_issue;
485
reg [QENTRIES-1:0] iqentry_fpu_issue;
486
 
487
wire [PREGS-1:1] livetarget;
488
wire  [PREGS-1:1] iqentry_0_livetarget;
489
wire  [PREGS-1:1] iqentry_1_livetarget;
490
wire  [PREGS-1:1] iqentry_2_livetarget;
491
wire  [PREGS-1:1] iqentry_3_livetarget;
492
wire  [PREGS-1:1] iqentry_4_livetarget;
493
wire  [PREGS-1:1] iqentry_5_livetarget;
494
wire  [PREGS-1:1] iqentry_6_livetarget;
495
wire  [PREGS-1:1] iqentry_7_livetarget;
496
wire  [PREGS-1:1] iqentry_0_latestID;
497
wire  [PREGS-1:1] iqentry_1_latestID;
498
wire  [PREGS-1:1] iqentry_2_latestID;
499
wire  [PREGS-1:1] iqentry_3_latestID;
500
wire  [PREGS-1:1] iqentry_4_latestID;
501
wire  [PREGS-1:1] iqentry_5_latestID;
502
wire  [PREGS-1:1] iqentry_6_latestID;
503
wire  [PREGS-1:1] iqentry_7_latestID;
504
wire  [PREGS-1:1] iqentry_0_cumulative;
505
wire  [PREGS-1:1] iqentry_1_cumulative;
506
wire  [PREGS-1:1] iqentry_2_cumulative;
507
wire  [PREGS-1:1] iqentry_3_cumulative;
508
wire  [PREGS-1:1] iqentry_4_cumulative;
509
wire  [PREGS-1:1] iqentry_5_cumulative;
510
wire  [PREGS-1:1] iqentry_6_cumulative;
511
wire  [PREGS-1:1] iqentry_7_cumulative;
512
wire  [PREGS-1:1] iq0_out;
513
wire  [PREGS-1:1] iq1_out;
514
wire  [PREGS-1:1] iq2_out;
515
wire  [PREGS-1:1] iq3_out;
516
wire  [PREGS-1:1] iq4_out;
517
wire  [PREGS-1:1] iq5_out;
518
wire  [PREGS-1:1] iq6_out;
519
wire  [PREGS-1:1] iq7_out;
520
 
521
reg  [`QBITS] tail0;
522
reg  [`QBITS] tail1;
523
reg  [`QBITS] head0;
524
reg  [`QBITS] head1;
525
reg  [`QBITS] head2;    // used only to determine memory-access ordering
526
reg  [`QBITS] head3;    // used only to determine memory-access ordering
527
reg  [`QBITS] head4;    // used only to determine memory-access ordering
528
reg  [`QBITS] head5;    // used only to determine memory-access ordering
529
reg  [`QBITS] head6;    // used only to determine memory-access ordering
530
reg  [`QBITS] head7;    // used only to determine memory-access ordering
531
 
532
wire take_branch0;
533
wire take_branch1;
534
 
535
reg [3:0] nop_fetchbuf;
536
wire        fetchbuf;   // determines which pair to read from & write to
537
 
538
wire [47:0] fetchbuf0_instr;
539
wire  [2:0] fetchbuf0_insln;
540
wire [31:0] fetchbuf0_pc;
541
wire        fetchbuf0_v;
542
wire            fetchbuf0_thrd;
543
wire        fetchbuf0_mem;
544
wire            fetchbuf0_memld;
545
wire        fetchbuf0_jmp;
546
wire        fetchbuf0_rfw;
547
wire [47:0] fetchbuf1_instr;
548
wire  [2:0] fetchbuf1_insln;
549
wire [31:0] fetchbuf1_pc;
550
wire        fetchbuf1_v;
551
wire            fetchbuf1_thrd;
552
wire        fetchbuf1_mem;
553
wire            fetchbuf1_memld;
554
wire        fetchbuf1_jmp;
555
wire        fetchbuf1_rfw;
556
 
557
wire [47:0] fetchbufA_instr;
558
wire [31:0] fetchbufA_pc;
559
wire        fetchbufA_v;
560
wire [47:0] fetchbufB_instr;
561
wire [31:0] fetchbufB_pc;
562
wire        fetchbufB_v;
563
wire [47:0] fetchbufC_instr;
564
wire [31:0] fetchbufC_pc;
565
wire        fetchbufC_v;
566
wire [47:0] fetchbufD_instr;
567
wire [31:0] fetchbufD_pc;
568
wire        fetchbufD_v;
569
 
570
//reg        did_branchback0;
571
//reg        did_branchback1;
572
 
573
reg                               id1_available;
574
reg         id1_v;
575
reg   [4:0] id1_id;
576
reg  [47:0] id1_instr;
577
reg   [5:0] id1_ven;
578
reg   [7:0] id1_vl;
579
reg         id1_thrd;
580
reg         id1_pt;
581
reg   [4:0] id1_Rt;
582
wire [127:0] id1_bus;
583
 
584
reg                                     id2_available;
585
reg         id2_v;
586
reg   [4:0] id2_id;
587
reg  [47:0] id2_instr;
588
reg   [5:0] id2_ven;
589
reg   [7:0] id2_vl;
590
reg         id2_thrd;
591
reg         id2_pt;
592
reg   [4:0] id2_Rt;
593
wire [127:0] id2_bus;
594
 
595
reg        alu0_ld;
596
reg        alu0_available;
597
reg        alu0_dataready;
598
wire       alu0_done;
599
wire       alu0_idle;
600
reg  [3:0] alu0_sourceid;
601
reg [47:0] alu0_instr;
602
reg        alu0_bt;
603
reg        alu0_mem;
604
reg        alu0_shft48;
605
reg [63:0] alu0_argA;
606
reg [63:0] alu0_argB;
607
reg [63:0] alu0_argC;
608
reg [63:0] alu0_argI;    // only used by BEQ
609
reg [RBIT:0] alu0_tgt;
610
reg [5:0]  alu0_ven;
611
reg        alu0_thrd;
612
reg [31:0] alu0_pc;
613
wire [63:0] alu0_bus;
614
wire [63:0] alu0b_bus;
615
wire  [3:0] alu0_id;
616
wire  [8:0] alu0_exc;
617
wire        alu0_v;
618
wire        alu0_branchmiss;
619
wire [31:0] alu0_misspc;
620
 
621
reg        alu1_ld;
622
reg        alu1_available;
623
reg        alu1_dataready;
624
wire       alu1_done;
625
wire       alu1_idle;
626
reg  [3:0] alu1_sourceid;
627
reg [47:0] alu1_instr;
628
reg        alu1_bt;
629
reg        alu1_mem;
630
reg        alu1_shft48;
631
reg [63:0] alu1_argA;
632
reg [63:0] alu1_argB;
633
reg [63:0] alu1_argC;
634
reg [63:0] alu1_argI;    // only used by BEQ
635
reg [RBIT:0] alu1_tgt;
636
reg [5:0]  alu1_ven;
637
reg [31:0] alu1_pc;
638
reg        alu1_thrd;
639
wire [63:0] alu1_bus;
640
wire [63:0] alu1b_bus;
641
wire  [3:0] alu1_id;
642
wire  [8:0] alu1_exc;
643
wire        alu1_v;
644
wire        alu1_branchmiss;
645
wire [31:0] alu1_misspc;
646
 
647
reg        fpu_ld;
648
reg        fpu1_available = 1'b1;
649
reg        fpu_dataready = 1'b1;
650
wire       fpu_done = 1'b1;
651
wire       fpu_idle;
652
reg  [3:0] fpu_sourceid;
653
reg [47:0] fpu_instr;
654
reg [63:0] fpu_argA;
655
reg [63:0] fpu_argB;
656
reg [63:0] fpu_argC;
657
reg [63:0] fpu_argI;     // only used by BEQ
658
reg [RBIT:0] fpu_tgt;
659
reg [31:0] fpu_pc;
660
wire [63:0] fpu_bus;
661
wire  [3:0] fpu_id;
662
wire  [8:0] fpu_exc = 9'h000;
663
wire        fpu_v;
664
wire [31:0] fpu_status;
665
 
666
reg [63:0] waitctr;
667
reg        fcu_ld;
668
reg        fcu_dataready;
669
reg        fcu_done;
670
reg         fcu_idle = 1'b1;
671
reg  [3:0] fcu_sourceid;
672
reg [47:0] fcu_instr;
673
reg  [2:0] fcu_insln;
674
reg        fcu_call;
675
reg        fcu_bt;
676
reg [63:0] fcu_argA;
677
reg [63:0] fcu_argB;
678
reg [63:0] fcu_argC;
679
reg [63:0] fcu_argI;     // only used by BEQ
680
reg [63:0] fcu_argT;
681
reg [63:0] fcu_argT2;
682
reg [31:0] fcu_retadr;
683
reg        fcu_retadr_v;
684
reg [31:0] fcu_pc;
685
reg [31:0] fcu_nextpc;
686
reg [31:0] fcu_brdisp;
687
wire [63:0] fcu_bus;
688
wire  [3:0] fcu_id;
689
reg   [8:0] fcu_exc;
690
wire        fcu_v;
691
reg        fcu_thrd;
692
reg        fcu_branchmiss;
693
reg  fcu_clearbm;
694
reg [31:0] fcu_misspc;
695
 
696
reg [63:0] rmw_argA;
697
reg [63:0] rmw_argB;
698
reg [63:0] rmw_argC;
699
wire [63:0] rmw_res;
700
reg [31:0] rmw_instr;
701
 
702
reg branchmiss = 1'b0;
703
reg branchmiss_thrd = 1'b0;
704
reg [31:0] misspc;
705
reg  [`QBITS] missid;
706
 
707
wire take_branch;
708
wire take_branchA;
709
wire take_branchB;
710
wire take_branchC;
711
wire take_branchD;
712
 
713
wire        dram_avail;
714
reg      [2:0] dram0;    // state of the DRAM request (latency = 4; can have three in pipeline)
715
reg      [2:0] dram1;    // state of the DRAM request (latency = 4; can have three in pipeline)
716
reg      [2:0] dram2;    // state of the DRAM request (latency = 4; can have three in pipeline)
717
reg [63:0] dram0_data;
718
reg [31:0] dram0_addr;
719
reg [31:0] dram0_seg;
720
reg [47:0] dram0_instr;
721
reg        dram0_rmw;
722
reg                dram0_preload;
723
reg [RBIT:0] dram0_tgt;
724
reg  [3:0] dram0_id;
725
reg  [8:0] dram0_exc;
726
reg        dram0_unc;
727
reg [2:0]  dram0_memsize;
728
reg        dram0_load;  // is a load operation
729
reg  [1:0] dram0_ol;
730
reg [63:0] dram1_data;
731
reg [31:0] dram1_addr;
732
reg [31:0] dram1_seg;
733
reg [47:0] dram1_instr;
734
reg        dram1_rmw;
735
reg                dram1_preload;
736
reg [RBIT:0] dram1_tgt;
737
reg  [3:0] dram1_id;
738
reg  [8:0] dram1_exc;
739
reg        dram1_unc;
740
reg [2:0]  dram1_memsize;
741
reg        dram1_load;
742
reg  [1:0] dram1_ol;
743
reg [63:0] dram2_data;
744
reg [31:0] dram2_addr;
745
reg [31:0] dram2_seg;
746
reg [47:0] dram2_instr;
747
reg        dram2_rmw;
748
reg                dram2_preload;
749
reg [RBIT:0] dram2_tgt;
750
reg  [3:0] dram2_id;
751
reg  [8:0] dram2_exc;
752
reg        dram2_unc;
753
reg [2:0]  dram2_memsize;
754
reg        dram2_load;
755
reg  [1:0] dram2_ol;
756
 
757
reg        dramA_v;
758
reg  [3:0] dramA_id;
759
reg [63:0] dramA_bus;
760
reg  [8:0] dramA_exc;
761
reg        dramB_v;
762
reg  [3:0] dramB_id;
763
reg [63:0] dramB_bus;
764
reg  [8:0] dramB_exc;
765
reg        dramC_v;
766
reg  [3:0] dramC_id;
767
reg [63:0] dramC_bus;
768
reg  [8:0] dramC_exc;
769
 
770
wire        outstanding_stores;
771
reg [63:0] I;    // instruction count
772
 
773
reg        commit0_v;
774
reg  [4:0] commit0_id;
775
reg [RBIT:0] commit0_tgt;
776
reg  [7:0] commit0_we = 8'h00;
777
reg [63:0] commit0_bus;
778
reg        commit1_v;
779
reg  [4:0] commit1_id;
780
reg [RBIT:0] commit1_tgt;
781
reg  [7:0] commit1_we = 8'h00;
782
reg [63:0] commit1_bus;
783
 
784
reg [4:0] bstate;
785
parameter BIDLE = 5'd0;
786
parameter B1 = 5'd1;
787
parameter B2 = 5'd2;
788
parameter B3 = 5'd3;
789
parameter B4 = 5'd4;
790
parameter B5 = 5'd5;
791
parameter B6 = 5'd6;
792
parameter B7 = 5'd7;
793
parameter B8 = 5'd8;
794
parameter B9 = 5'd9;
795
parameter B10 = 5'd10;
796
parameter B11 = 5'd11;
797
parameter B12 = 5'd12;
798
parameter B13 = 5'd13;
799
parameter B14 = 5'd14;
800
parameter B15 = 5'd15;
801
parameter B16 = 5'd16;
802
parameter B17 = 5'd17;
803
parameter B18 = 5'd18;
804
parameter B19 = 5'd19;
805
parameter B2a = 5'd20;
806
parameter B2b = 5'd21;
807
parameter B2c = 5'd22;
808
parameter B2d = 5'd23;
809
parameter B20 = 5'd24;
810
parameter B21 = 5'd25;
811
reg [1:0] bwhich;
812
reg [3:0] icstate,picstate;
813
parameter IDLE = 4'd0;
814
parameter IC1 = 4'd1;
815
parameter IC2 = 4'd2;
816
parameter IC3 = 4'd3;
817
parameter IC4 = 4'd4;
818
parameter IC5 = 4'd5;
819
parameter IC6 = 4'd6;
820
parameter IC7 = 4'd7;
821
parameter IC8 = 4'd8;
822
parameter IC9 = 4'd9;
823
parameter IC10 = 4'd10;
824
parameter IC3a = 4'd11;
825
reg invic, invdc;
826
reg icwhich,icnxt,L2_nxt;
827
wire ihit0,ihit1,ihit2;
828
wire ihit = ihit0&ihit1;
829
reg phit;
830
wire threadx;
831
always @*
832
        phit <= ihit&&icstate==IDLE;
833
reg [2:0] iccnt;
834
reg L1_wr0,L1_wr1;
835
reg L1_invline;
836
reg [9:0] L1_en;
837
reg [37:0] L1_adr, L2_adr;
838
reg [319:0] L2_rdat;
839
wire [319:0] L2_dato;
840
reg L2_xsel;
841
 
842
FT64_regfile2w6r_oc #(.RBIT(RBIT)) urf1
843
(
844
  .clk(clk),
845
  .clk4x(clk4x),
846
  .wr0(commit0_v),
847
  .wr1(commit1_v),
848
  .we0(commit0_we),
849
  .we1(commit1_we),
850
  .wa0(commit0_tgt),
851
  .wa1(commit1_tgt),
852
  .i0(commit0_bus),
853
  .i1(commit1_bus),
854
        .rclk(~clk),
855
        .ra0(Ra0),
856
        .ra1(Rb0),
857
        .ra2(Rc0),
858
        .ra3(Ra1),
859
        .ra4(Rb1),
860
        .ra5(Rc1),
861
        .o0(rfoa0),
862
        .o1(rfob0),
863
        .o2(rfoc0a),
864
        .o3(rfoa1),
865
        .o4(rfob1),
866
        .o5(rfoc1a)
867
);
868
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
869
assign rfoc1 = Rc1[11:6]==6'h3F ? vm[Rc1[2:0]] : rfoc1a;
870
 
871
function [2:0] fnInsLength;
872
input [47:0] ins;
873
case(ins[7:6])
874
2'b00:  fnInsLength = 3'd4;
875
2'b01:  fnInsLength = 3'd6;
876
2'b10:  fnInsLength = 3'd2;
877
2'b11:  fnInsLength = 3'd2;
878
endcase
879
endfunction
880
 
881
wire [31:0] pc0plus6 = pc0 + 32'd6;
882
 
883
`ifdef SUPPORT_SMT
884
assign insn1a = insn1b;
885
`else
886
assign insn1a = {insn1b,insn0a} >> {fnInsLength(insn0a),3'b0};
887
`endif
888
 
889
FT64_L1_icache uic0
890
(
891
    .rst(rst),
892
    .clk(clk),
893
    .nxt(icnxt),
894
    .wr(L1_wr0),
895
    .en(L1_en),
896
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc0} : L1_adr),
897
    .wadr(L1_adr),
898
    .i(L2_rdat),
899
    .o(insn0a),
900
    .hit(ihit0),
901
    .invall(invic),
902
    .invline(L1_invline)
903
);
904
FT64_L1_icache uic1
905
(
906
    .rst(rst),
907
    .clk(clk),
908
    .nxt(icnxt),
909
    .wr(L1_wr1),
910
    .en(L1_en),
911
`ifdef SUPPORT_SMT
912
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc1} : L1_adr),
913
`else
914
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc0plus6} : L1_adr),
915
`endif
916
    .wadr(L1_adr),
917
    .i(L2_rdat),
918
    .o(insn1b),
919
    .hit(ihit1),
920
    .invall(invic),
921
    .invline(L1_invline)
922
);
923
FT64_L2_icache uic2
924
(
925
    .rst(rst),
926
    .clk(clk),
927
    .nxt(L2_nxt),
928
    .wr(bstate==B7 && ack_i),
929
    .xsel(L2_xsel),
930
    .adr(L2_adr),
931
    .cnt(iccnt),
932
    .exv_i(exvq),
933
    .i(dat_i),
934
    .err_i(errq),
935
    .o(L2_dato),
936
    .hit(ihit2),
937
    .invall(invic),
938
    .invline()
939
);
940
 
941
wire predict_taken;
942
wire predict_taken0;
943
wire predict_taken1;
944
wire predict_takenA;
945
wire predict_takenB;
946
wire predict_takenC;
947
wire predict_takenD;
948
wire predict_takenA1;
949
wire predict_takenB1;
950
wire predict_takenC1;
951
wire predict_takenD1;
952
 
953
wire [31:0] btgtA, btgtB, btgtC, btgtD;
954
wire btbwr0 = iqentry_v[head0] && iqentry_done[head0] &&
955
        (
956
        iqentry_instr[head0][`INSTRUCTION_OP]==`JAL ||
957
        iqentry_instr[head0][`INSTRUCTION_OP]==`BRK ||
958
        IsRTI(iqentry_instr[head0]));
959
wire btbwr1 = iqentry_v[head1] && iqentry_done[head1] &&
960
        (
961
        iqentry_instr[head1][`INSTRUCTION_OP]==`JAL ||
962
        iqentry_instr[head1][`INSTRUCTION_OP]==`BRK ||
963
        IsRTI(iqentry_instr[head1]));
964
 
965
FT64_BTB ubtb1
966
(
967
    .rst(rst),
968
    .wclk(clk),
969
    .wr(btbwr0 | btbwr1),
970
    .wadr(btbwr0 ? iqentry_pc[head0] : iqentry_pc[head1]),
971
    .wdat(btbwr0 ? iqentry_a0[head0] : iqentry_a0[head1]),
972
    .valid(btbwr0 ? iqentry_bt[head0] & iqentry_v[head0] : iqentry_bt[head1] & iqentry_v[head1]),
973
    .rclk(~clk),
974
    .pcA(fetchbufA_pc),
975
    .btgtA(btgtA),
976
    .pcB(fetchbufB_pc),
977
    .btgtB(btgtB),
978
    .pcC(fetchbufC_pc),
979
    .btgtC(btgtC),
980
    .pcD(fetchbufD_pc),
981
    .btgtD(btgtD),
982
    .npcA(BRKPC),
983
    .npcB(BRKPC),
984
    .npcC(BRKPC),
985
    .npcD(BRKPC)
986
);
987
 
988
FT64_BranchPredictor ubp1
989
(
990
    .rst(rst),
991
    .clk(clk),
992
    .en(bpe),
993
    .xisBranch0(iqentry_br[head0] & commit0_v),
994
    .xisBranch1(iqentry_br[head1] & commit1_v),
995
    .pcA(fetchbufA_pc),
996
    .pcB(fetchbufB_pc),
997
    .pcC(fetchbufC_pc),
998
    .pcD(fetchbufD_pc),
999
    .xpc0(iqentry_pc[head0]),
1000
    .xpc1(iqentry_pc[head1]),
1001
    .takb0(commit0_v & iqentry_res[head0][0]),
1002
    .takb1(commit1_v & iqentry_res[head1][0]),
1003
    .predict_takenA(predict_takenA),
1004
    .predict_takenB(predict_takenB),
1005
    .predict_takenC(predict_takenC),
1006
    .predict_takenD(predict_takenD)
1007
);
1008
 
1009
//-----------------------------------------------------------------------------
1010
// Debug
1011
//-----------------------------------------------------------------------------
1012
`ifdef SUPPORT_DBG
1013
 
1014
wire [DBW-1:0] dbg_stat1x;
1015
reg [DBW-1:0] dbg_stat;
1016
reg [DBW-1:0] dbg_ctrl;
1017
reg [ABW-1:0] dbg_adr0;
1018
reg [ABW-1:0] dbg_adr1;
1019
reg [ABW-1:0] dbg_adr2;
1020
reg [ABW-1:0] dbg_adr3;
1021
reg dbg_imatchA0,dbg_imatchA1,dbg_imatchA2,dbg_imatchA3,dbg_imatchA;
1022
reg dbg_imatchB0,dbg_imatchB1,dbg_imatchB2,dbg_imatchB3,dbg_imatchB;
1023
 
1024
wire dbg_lmatch00 =
1025
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1026
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1027
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1028
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1029
                                 dbg_ctrl[19:18]==2'b11)
1030
                                 ;
1031
wire dbg_lmatch01 =
1032
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1033
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1034
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1035
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1036
                  dbg_ctrl[19:18]==2'b11)
1037
                  ;
1038
wire dbg_lmatch02 =
1039
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1040
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1041
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1042
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1043
                dbg_ctrl[19:18]==2'b11)
1044
                ;
1045
wire dbg_lmatch10 =
1046
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1047
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1048
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1049
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1050
                  dbg_ctrl[23:22]==2'b11)
1051
                  ;
1052
wire dbg_lmatch11 =
1053
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1054
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1055
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1056
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1057
                dbg_ctrl[23:22]==2'b11)
1058
                ;
1059
wire dbg_lmatch12 =
1060
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1061
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1062
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1063
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1064
                dbg_ctrl[23:22]==2'b11)
1065
                ;
1066
wire dbg_lmatch20 =
1067
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1068
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1069
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1070
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1071
                    dbg_ctrl[27:26]==2'b11)
1072
                    ;
1073
wire dbg_lmatch21 =
1074
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1075
                   ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1076
                    (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1077
                    (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1078
                    dbg_ctrl[27:26]==2'b11)
1079
                    ;
1080
wire dbg_lmatch22 =
1081
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1082
                   ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1083
                    (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1084
                    (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1085
                    dbg_ctrl[27:26]==2'b11)
1086
                    ;
1087
wire dbg_lmatch30 =
1088
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1089
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1090
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1091
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1092
                      dbg_ctrl[31:30]==2'b11)
1093
                      ;
1094
wire dbg_lmatch31 =
1095
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1096
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1097
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1098
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1099
                    dbg_ctrl[31:30]==2'b11)
1100
                    ;
1101
wire dbg_lmatch32 =
1102
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1103
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1104
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1105
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1106
                    dbg_ctrl[31:30]==2'b11)
1107
                    ;
1108
wire dbg_lmatch0 = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30;
1109
wire dbg_lmatch1 = dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31;
1110
wire dbg_lmatch2 = dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32;
1111
wire dbg_lmatch = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30|
1112
                  dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31|
1113
                  dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32
1114
                    ;
1115
 
1116
wire dbg_smatch00 =
1117
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1118
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1119
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1120
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1121
                                 dbg_ctrl[19:18]==2'b11)
1122
                                 ;
1123
wire dbg_smatch01 =
1124
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1125
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1126
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1127
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1128
                  dbg_ctrl[19:18]==2'b11)
1129
                  ;
1130
wire dbg_smatch02 =
1131
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1132
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1133
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1134
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1135
                dbg_ctrl[19:18]==2'b11)
1136
                ;
1137
wire dbg_smatch10 =
1138
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1139
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1140
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1141
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1142
                  dbg_ctrl[23:22]==2'b11)
1143
                  ;
1144
wire dbg_smatch11 =
1145
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1146
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1147
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1148
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1149
                dbg_ctrl[23:22]==2'b11)
1150
                ;
1151
wire dbg_smatch12 =
1152
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1153
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1154
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1155
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1156
                dbg_ctrl[23:22]==2'b11)
1157
                ;
1158
wire dbg_smatch20 =
1159
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1160
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1161
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1162
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1163
                    dbg_ctrl[27:26]==2'b11)
1164
                    ;
1165
wire dbg_smatch21 =
1166
           dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1167
                    ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1168
                     (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1169
                     (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1170
                     dbg_ctrl[27:26]==2'b11)
1171
                     ;
1172
wire dbg_smatch22 =
1173
            dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1174
                     ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1175
                      (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1176
                      (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1177
                      dbg_ctrl[27:26]==2'b11)
1178
                      ;
1179
wire dbg_smatch30 =
1180
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1181
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1182
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1183
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1184
                      dbg_ctrl[31:30]==2'b11)
1185
                      ;
1186
wire dbg_smatch31 =
1187
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1188
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1189
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1190
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1191
                    dbg_ctrl[31:30]==2'b11)
1192
                    ;
1193
wire dbg_smatch32 =
1194
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1195
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1196
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1197
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1198
                    dbg_ctrl[31:30]==2'b11)
1199
                    ;
1200
wire dbg_smatch0 = dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30;
1201
wire dbg_smatch1 = dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31;
1202
wire dbg_smatch2 = dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32;
1203
 
1204
wire dbg_smatch =   dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30|
1205
                    dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31|
1206
                    dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32
1207
                    ;
1208
 
1209
wire dbg_stat0 = dbg_imatchA0 | dbg_imatchB0 | dbg_lmatch00 | dbg_lmatch01 | dbg_lmatch02 | dbg_smatch00 | dbg_smatch01 | dbg_smatch02;
1210
wire dbg_stat1 = dbg_imatchA1 | dbg_imatchB1 | dbg_lmatch10 | dbg_lmatch11 | dbg_lmatch12 | dbg_smatch10 | dbg_smatch11 | dbg_smatch12;
1211
wire dbg_stat2 = dbg_imatchA2 | dbg_imatchB2 | dbg_lmatch20 | dbg_lmatch21 | dbg_lmatch22 | dbg_smatch20 | dbg_smatch21 | dbg_smatch22;
1212
wire dbg_stat3 = dbg_imatchA3 | dbg_imatchB3 | dbg_lmatch30 | dbg_lmatch31 | dbg_lmatch32 | dbg_smatch30 | dbg_smatch31 | dbg_smatch32;
1213
assign dbg_stat1x = {dbg_stat3,dbg_stat2,dbg_stat1,dbg_stat0};
1214
wire debug_on = |dbg_ctrl[3:0]|dbg_ctrl[7]|dbg_ctrl[63];
1215
 
1216
always @*
1217
begin
1218
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf0_pc==dbg_adr0)
1219
        dbg_imatchA0 = `TRUE;
1220
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf0_pc==dbg_adr1)
1221
        dbg_imatchA1 = `TRUE;
1222
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf0_pc==dbg_adr2)
1223
        dbg_imatchA2 = `TRUE;
1224
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf0_pc==dbg_adr3)
1225
        dbg_imatchA3 = `TRUE;
1226
    if (dbg_imatchA0|dbg_imatchA1|dbg_imatchA2|dbg_imatchA3)
1227
        dbg_imatchA = `TRUE;
1228
end
1229
 
1230
always @*
1231
begin
1232
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf1_pc==dbg_adr0)
1233
        dbg_imatchB0 = `TRUE;
1234
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf1_pc==dbg_adr1)
1235
        dbg_imatchB1 = `TRUE;
1236
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf1_pc==dbg_adr2)
1237
        dbg_imatchB2 = `TRUE;
1238
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf1_pc==dbg_adr3)
1239
        dbg_imatchB3 = `TRUE;
1240
    if (dbg_imatchB0|dbg_imatchB1|dbg_imatchB2|dbg_imatchB3)
1241
        dbg_imatchB = `TRUE;
1242
end
1243
`endif
1244
 
1245
//-----------------------------------------------------------------------------
1246
//-----------------------------------------------------------------------------
1247
 
1248
// hirq squashes the pc increment if there's an irq.
1249
wire hirq = (irq_i > im) && ~int_commit;
1250
always @*
1251
if (hirq)
1252
        insn0 <= {8'd0,4'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1253
else if (phit) begin
1254
        if (insn0a[`INSTRUCTION_OP]==`BRK && insn0a[23:20]==4'd0)
1255
                insn0 <= {8'd1,4'd0,3'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1256
        else
1257
                insn0 <= insn0a;
1258
end
1259
else
1260
        insn0 <= `NOP_INSN;
1261
always @*
1262
if (phit) begin
1263
        if (insn1a[`INSTRUCTION_OP]==`BRK && insn1a[23:20]==4'd0)
1264
                insn1 <= {8'd1,4'd0,3'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1265
        else
1266
                insn1 <= insn1a;
1267
end
1268
else
1269
        insn1 <= `NOP_INSN;
1270
 
1271
wire [63:0] dc0_out, dc1_out, dc2_out;
1272
assign rdat0 = dram0_unc ? xdati : dc0_out;
1273
assign rdat1 = dram1_unc ? xdati : dc1_out;
1274
assign rdat2 = dram2_unc ? xdati : dc2_out;
1275
 
1276
reg preload;
1277
reg [1:0] dccnt;
1278
wire dhit0, dhit1, dhit2;
1279
wire dhit00, dhit10, dhit20;
1280
wire dhit01, dhit11, dhit21;
1281
reg [31:0] dc_wadr;
1282
reg [63:0] dc_wdat;
1283
reg isStore;
1284
 
1285
FT64_dcache udc0
1286
(
1287
    .rst(rst),
1288
    .wclk(clk),
1289
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && dhit0)),
1290
    .sel(sel_o),
1291
    .wadr({pcr[5:0],adr_o}),
1292
    .i(bstate==B2d ? dat_i : dat_o),
1293
    .rclk(clk),
1294
    .rdsize(dram0_memsize),
1295
    .radr({pcr[5:0],dram0_addr}),
1296
    .o(dc0_out),
1297
    .hit(),
1298
    .hit0(dhit0),
1299
    .hit1()
1300
);
1301
FT64_dcache udc1
1302
(
1303
    .rst(rst),
1304
    .wclk(clk),
1305
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && dhit1)),
1306
    .sel(sel_o),
1307
    .wadr({pcr[5:0],adr_o}),
1308
    .i(bstate==B2d ? dat_i : dat_o),
1309
    .rclk(clk),
1310
    .rdsize(dram1_memsize),
1311
    .radr({pcr[5:0],dram1_addr}),
1312
    .o(dc1_out),
1313
    .hit(),
1314
    .hit0(dhit1),
1315
    .hit1()
1316
);
1317
FT64_dcache udc2
1318
(
1319
    .rst(rst),
1320
    .wclk(clk),
1321
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && dhit2)),
1322
    .sel(sel_o),
1323
    .wadr({pcr[5:0],adr_o}),
1324
    .i(bstate==B2d ? dat_i : dat_o),
1325
    .rclk(clk),
1326
    .rdsize(dram2_memsize),
1327
    .radr({pcr[5:0],dram2_addr}),
1328
    .o(dc2_out),
1329
    .hit(),
1330
    .hit0(dhit2),
1331
    .hit1()
1332
);
1333
 
1334
function [`QBITS] idp1;
1335
input [`QBITS] id;
1336
case(id)
1337
3'd0:   idp1 = 3'd1;
1338
3'd1:   idp1 = 3'd2;
1339
3'd2:   idp1 = 3'd3;
1340
3'd3:   idp1 = 3'd4;
1341
3'd4:   idp1 = 3'd5;
1342
3'd5:   idp1 = 3'd6;
1343
3'd6:   idp1 = 3'd7;
1344
3'd7:   idp1 = 3'd0;
1345
endcase
1346
endfunction
1347
 
1348
function [`QBITS] idp2;
1349
input [`QBITS] id;
1350
case(id)
1351
3'd0:   idp2 = 3'd2;
1352
3'd1:   idp2 = 3'd3;
1353
3'd2:   idp2 = 3'd4;
1354
3'd3:   idp2 = 3'd5;
1355
3'd4:   idp2 = 3'd6;
1356
3'd5:   idp2 = 3'd7;
1357
3'd6:   idp2 = 3'd0;
1358
3'd7:   idp2 = 3'd1;
1359
endcase
1360
endfunction
1361
 
1362
function [`QBITS] idp3;
1363
input [`QBITS] id;
1364
case(id)
1365
3'd0:   idp3 = 3'd3;
1366
3'd1:   idp3 = 3'd4;
1367
3'd2:   idp3 = 3'd5;
1368
3'd3:   idp3 = 3'd6;
1369
3'd4:   idp3 = 3'd7;
1370
3'd5:   idp3 = 3'd0;
1371
3'd6:   idp3 = 3'd1;
1372
3'd7:   idp3 = 3'd2;
1373
endcase
1374
endfunction
1375
 
1376
function [`QBITS] idp4;
1377
input [`QBITS] id;
1378
case(id)
1379
3'd0:   idp4 = 3'd4;
1380
3'd1:   idp4 = 3'd5;
1381
3'd2:   idp4 = 3'd6;
1382
3'd3:   idp4 = 3'd7;
1383
3'd4:   idp4 = 3'd0;
1384
3'd5:   idp4 = 3'd1;
1385
3'd6:   idp4 = 3'd2;
1386
3'd7:   idp4 = 3'd3;
1387
endcase
1388
endfunction
1389
 
1390
function [`QBITS] idp5;
1391
input [`QBITS] id;
1392
case(id)
1393
3'd0:   idp5 = 3'd5;
1394
3'd1:   idp5 = 3'd6;
1395
3'd2:   idp5 = 3'd7;
1396
3'd3:   idp5 = 3'd0;
1397
3'd4:   idp5 = 3'd1;
1398
3'd5:   idp5 = 3'd2;
1399
3'd6:   idp5 = 3'd3;
1400
3'd7:   idp5 = 3'd4;
1401
endcase
1402
endfunction
1403
 
1404
function [`QBITS] idp6;
1405
input [`QBITS] id;
1406
case(id)
1407
3'd0:   idp6 = 3'd6;
1408
3'd1:   idp6 = 3'd7;
1409
3'd2:   idp6 = 3'd0;
1410
3'd3:   idp6 = 3'd1;
1411
3'd4:   idp6 = 3'd2;
1412
3'd5:   idp6 = 3'd3;
1413
3'd6:   idp6 = 3'd4;
1414
3'd7:   idp6 = 3'd5;
1415
endcase
1416
endfunction
1417
 
1418
function [`QBITS] idp7;
1419
input [`QBITS] id;
1420
case(id)
1421
3'd0:   idp7 = 3'd7;
1422
3'd1:   idp7 = 3'd0;
1423
3'd2:   idp7 = 3'd1;
1424
3'd3:   idp7 = 3'd2;
1425
3'd4:   idp7 = 3'd3;
1426
3'd5:   idp7 = 3'd4;
1427
3'd6:   idp7 = 3'd5;
1428
3'd7:   idp7 = 3'd6;
1429
endcase
1430
endfunction
1431
 
1432
function [`QBITS] idm1;
1433
input [`QBITS] id;
1434
case(id)
1435
3'd0:   idm1 = 3'd7;
1436
3'd1:   idm1 = 3'd0;
1437
3'd2:   idm1 = 3'd1;
1438
3'd3:   idm1 = 3'd2;
1439
3'd4:   idm1 = 3'd3;
1440
3'd5:   idm1 = 3'd4;
1441
3'd6:   idm1 = 3'd5;
1442
3'd7:   idm1 = 3'd6;
1443
endcase
1444
endfunction
1445
 
1446
`ifdef SUPPORT_SMT
1447
function [RBIT:0] fnRa;
1448
input [47:0] isn;
1449
input [5:0] vqei;
1450
input [5:0] vli;
1451
input thrd;
1452
case(isn[`INSTRUCTION_OP])
1453
`IVECTOR:
1454
        case(isn[`INSTRUCTION_S2])
1455
        `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1456
        `VMxx:
1457
                case(isn[25:23])
1458
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
1459
                    fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1460
            `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1461
            default:fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1462
            endcase
1463
        `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
1464
        `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
1465
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1466
        default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1467
        endcase
1468
`R2:    case(isn[`INSTRUCTION_S2])
1469
                `MOV:
1470
                        case(isn[25:23])
1471
                        3'd0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1472
                        3'd1:   fnRa = {isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
1473
                        3'd2:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1474
                        3'd3:   fnRa = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RA]};
1475
                        3'd4:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1476
                        3'd5:   fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1477
                        3'd6:   fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1478
                        default:fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1479
                        endcase
1480
        `VMOV:
1481
            case (isn[`INSTRUCTION_S1])
1482
            5'h0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1483
            5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
1484
            endcase
1485
        default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1486
        endcase
1487
`FLOAT:         fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1488
default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1489
endcase
1490
endfunction
1491
 
1492
function [RBIT:0] fnRb;
1493
input [47:0] isn;
1494
input fb;
1495
input [5:0] vqei;
1496
input [5:0] rfoa0i;
1497
input [5:0] rfoa1i;
1498
input thrd;
1499
case(isn[`INSTRUCTION_OP])
1500
`R2:        case(isn[`INSTRUCTION_S2])
1501
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
1502
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1503
            default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1504
            endcase
1505
`IVECTOR:
1506
                        case(isn[`INSTRUCTION_S2])
1507
                        `VMxx:
1508
                                case(isn[25:23])
1509
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
1510
                        fnRb = {6'h3F,1'b1,2'b0,isn[13:11]};
1511
                default:        fnRb = 12'h000;
1512
                endcase
1513
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1514
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1515
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
1516
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
1517
                fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1518
            `VSHL,`VSHR,`VASR:
1519
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
1520
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1521
            endcase
1522
`FLOAT:         fnRb = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1523
default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1524
endcase
1525
endfunction
1526
 
1527
function [RBIT:0] fnRc;
1528
input [47:0] isn;
1529
input [5:0] vqei;
1530
input thrd;
1531
case(isn[`INSTRUCTION_OP])
1532
`R2:        case(isn[`INSTRUCTION_S2])
1533
            `SVX:       fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1534
                `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1535
                        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1536
                `CMOVEZ,`CMOVNZ,`MAJ:
1537
                        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1538
            default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1539
            endcase
1540
`IVECTOR:
1541
                        case(isn[`INSTRUCTION_S2])
1542
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[18:16]};
1543
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1544
            endcase
1545
`FLOAT:         fnRc = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1546
default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1547
endcase
1548
endfunction
1549
 
1550
function [RBIT:0] fnRt;
1551
input [47:0] isn;
1552
input [5:0] vqei;
1553
input [5:0] vli;
1554
input thrd;
1555
casez(isn[`INSTRUCTION_OP])
1556
`IVECTOR:
1557
                case(isn[`INSTRUCTION_S2])
1558
                `VMxx:
1559
                        case(isn[25:23])
1560
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
1561
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1562
            `VMPOP:     fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1563
            default:
1564
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1565
            endcase
1566
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1567
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
1568
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
1569
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
1570
        `V2BITS:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1571
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1572
        endcase
1573
 
1574
`R2:    case(isn[`INSTRUCTION_S2])
1575
                `MOV:
1576
                        case(isn[25:23])
1577
                        3'd0:   fnRt = {isn[22:18],1'b0,isn[`INSTRUCTION_RB]};
1578
                        3'd1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1579
                        3'd2:   fnRt = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RB]};
1580
                        3'd3:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1581
                        3'd4:   fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1582
                        3'd5:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1583
                        3'd6:   fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1584
                        default:fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1585
                        endcase
1586
        `VMOV:
1587
            case (isn[`INSTRUCTION_S1])
1588
            5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RB]};
1589
            5'h1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1590
            default:    fnRt = 12'h000;
1591
            endcase
1592
        `R1:
1593
                case(isn[22:18])
1594
                `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT:
1595
                        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1596
                `MEMDB,`MEMSB,`SYNC:
1597
                        fnRt = 12'd0;
1598
                default:        fnRt = 12'd0;
1599
                endcase
1600
        `CMOVEZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1601
        `CMOVNZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1602
        `MUX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1603
        `MIN:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1604
        `MAX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1605
        `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
1606
        `SHIFTR:        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1607
        `SHIFT31,`SHIFT63:
1608
                                fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1609
        `SEI:           fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1610
        `WAIT,`RTI,`CHK:
1611
                        fnRt = 12'd0;
1612
                default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1613
        endcase
1614
`MEMNDX:
1615
    case(isn[`INSTRUCTION_S2])
1616
    `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1617
                        fnRt = 12'd0;
1618
    default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1619
        endcase
1620
`FLOAT:
1621
                case(isn[31:26])
1622
                `FTX,`FCX,`FEX,`FDX,`FRM:
1623
                                        fnRt = 12'd0;
1624
                `FSYNC:         fnRt = 12'd0;
1625
                default:        fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1626
                endcase
1627
`BRK:   fnRt = 12'd0;
1628
`REX:   fnRt = 12'd0;
1629
`CHK:   fnRt = 12'd0;
1630
`EXEC:  fnRt = 12'd0;
1631
`Bcc:   fnRt = 12'd0;
1632
`BBc:   case(isn[20:19])
1633
                `IBNE:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1634
                `DBNZ:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1635
                default:        fnRt = 12'd0;
1636
                endcase
1637
`BEQI:  fnRt = 12'd0;
1638
`SB,`Sx,`SWC,`CACHE:
1639
                fnRt = 12'd0;
1640
`JMP:   fnRt = 12'd0;
1641
`CALL:  fnRt = {rgs[thrd],1'b0,regLR};  // regLR
1642
`RET:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1643
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1644
`AMO:   fnRt = isn[31] ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1645
default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1646
endcase
1647
endfunction
1648
`else
1649
function [RBIT:0] fnRa;
1650
input [47:0] isn;
1651
input [5:0] vqei;
1652
input [5:0] vli;
1653
input thrd;
1654
case(isn[`INSTRUCTION_OP])
1655
`IVECTOR:
1656
        case(isn[`INSTRUCTION_S2])
1657
        `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1658
        `VMxx:
1659
                case(isn[25:23])
1660
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
1661
                    fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1662
            `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1663
            default:fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1664
            endcase
1665
        `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
1666
        `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
1667
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1668
        default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1669
        endcase
1670
`RR:    case(isn[`INSTRUCTION_S2])
1671
                `MOV:
1672
                        case(isn[25:23])
1673
                        3'd0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1674
                        3'd1:   fnRa = {isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
1675
                        3'd2:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1676
                        3'd3:   fnRa = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RA]};
1677
                        3'd4:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1678
                        3'd5:   fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
1679
                        3'd6:   fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
1680
                        default:fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1681
                        endcase
1682
        `VMOV:
1683
            case (isn[`INSTRUCTION_S1])
1684
            5'h0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1685
            5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
1686
            endcase
1687
        default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1688
        endcase
1689
`FLOAT:         fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
1690
default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1691
endcase
1692
endfunction
1693
 
1694
function [RBIT:0] fnRb;
1695
input [47:0] isn;
1696
input fb;
1697
input [5:0] vqei;
1698
input [5:0] rfoa0i;
1699
input [5:0] rfoa1i;
1700
input thrd;
1701
case(isn[`INSTRUCTION_OP])
1702
`RR:        case(isn[`INSTRUCTION_S2])
1703
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
1704
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1705
            default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1706
            endcase
1707
`IVECTOR:
1708
                        case(isn[`INSTRUCTION_S2])
1709
                        `VMxx:
1710
                                case(isn[25:23])
1711
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
1712
                        fnRb = {6'h3F,1'b1,2'b0,isn[13:11]};
1713
                default:        fnRb = 12'h000;
1714
                endcase
1715
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1716
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1717
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
1718
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
1719
                fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1720
            `VSHL,`VSHR,`VASR:
1721
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
1722
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1723
            endcase
1724
`FLOAT:         fnRb = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
1725
default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1726
endcase
1727
endfunction
1728
 
1729
function [RBIT:0] fnRc;
1730
input [47:0] isn;
1731
input [5:0] vqei;
1732
input thrd;
1733
case(isn[`INSTRUCTION_OP])
1734
`R2:        case(isn[`INSTRUCTION_S2])
1735
            `SVX:       fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1736
                `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1737
                        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1738
                `CMOVEZ,`CMOVNZ,`MAJ:
1739
                        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1740
            default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1741
            endcase
1742
`IVECTOR:
1743
                        case(isn[`INSTRUCTION_S2])
1744
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[18:16]};
1745
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1746
            endcase
1747
`FLOAT:         fnRc = {fp_rgs,1'b0,isn[`INSTRUCTION_RC]};
1748
default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1749
endcase
1750
endfunction
1751
 
1752
function [RBIT:0] fnRt;
1753
input [47:0] isn;
1754
input [5:0] vqei;
1755
input [5:0] vli;
1756
input thrd;
1757
casez(isn[`INSTRUCTION_OP])
1758
`IVECTOR:
1759
                case(isn[`INSTRUCTION_S2])
1760
                `VMxx:
1761
                        case(isn[25:23])
1762
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
1763
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1764
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1765
            default:
1766
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1767
            endcase
1768
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1769
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
1770
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
1771
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
1772
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1773
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1774
        endcase
1775
 
1776
`FVECTOR:
1777
                case(isn[`INSTRUCTION_S2])
1778
                `VMxx:
1779
                        case(isn[25:23])
1780
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
1781
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1782
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1783
            default:
1784
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1785
            endcase
1786
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1787
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
1788
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
1789
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
1790
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1791
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1792
        endcase
1793
 
1794
`R2:    case(isn[`INSTRUCTION_S2])
1795
                `MOV:
1796
                        case(isn[25:23])
1797
                        3'd0:   fnRt = {isn[22:18],1'b0,isn[`INSTRUCTION_RB]};
1798
                        3'd1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1799
                        3'd2:   fnRt = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RB]};
1800
                        3'd3:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1801
                        3'd4:   fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
1802
                        3'd5:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1803
                        3'd6:   fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
1804
                        default:fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1805
                        endcase
1806
        `VMOV:
1807
            case (isn[`INSTRUCTION_S1])
1808
            5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RB]};
1809
            5'h1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1810
            default:    fnRt = 12'h000;
1811
            endcase
1812
        `R1:
1813
                case(isn[22:18])
1814
                `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT:
1815
                        fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1816
                `MEMDB,`MEMSB,`SYNC:
1817
                        fnRt = 12'd0;
1818
                default:        fnRt = 12'd0;
1819
                endcase
1820
        `CMOVEZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
1821
        `CMOVNZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
1822
        `MUX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
1823
        `MIN:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
1824
        `MAX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
1825
        `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
1826
        `SHIFTR:        fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1827
        `SHIFT31,`SHIFT63:
1828
                                fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1829
        `SEI:           fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1830
        `WAIT,`RTI,`CHK:
1831
                                fnRt = 12'd0;
1832
        default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1833
        endcase
1834
`MEMNDX:
1835
        case(isn[`INSTRUCTION_S2])
1836
  `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1837
                        fnRt = 12'd0;
1838
  default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1839
  endcase
1840
`FLOAT:
1841
                case(isn[31:26])
1842
                `FTX,`FCX,`FEX,`FDX,`FRM:
1843
                                        fnRt = 12'd0;
1844
                `FSYNC:         fnRt = 12'd0;
1845
                default:        fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RC]};
1846
                endcase
1847
`BRK:   fnRt = 12'd0;
1848
`REX:   fnRt = 12'd0;
1849
`CHK:   fnRt = 12'd0;
1850
`EXEC:  fnRt = 12'd0;
1851
`Bcc:   fnRt = 12'd0;
1852
`BBc:
1853
        case(isn[20:19])
1854
        `IBNE:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1855
        `DBNZ:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1856
        default:        fnRt = 12'd0;
1857
        endcase
1858
`BEQI:  fnRt = 12'd0;
1859
`SB,`Sx,`SWC,`CACHE:
1860
                fnRt = 12'd0;
1861
`JMP:   fnRt = 12'd0;
1862
`CALL:  fnRt = {rgs,1'b0,regLR};        // regLR
1863
`RET:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1864
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1865
`AMO:   fnRt = isn[31] ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {rgs,1'b0,isn[`INSTRUCTION_RC]};
1866
default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1867
endcase
1868
endfunction
1869
`endif
1870
 
1871
// Determines which lanes of the target register get updated.
1872
function [7:0] fnWe;
1873
input [47:0] isn;
1874
casez(isn[`INSTRUCTION_OP])
1875
`R2:
1876
        case(isn[`INSTRUCTION_S2])
1877
        `R1:
1878
                case(isn[22:18])
1879
                `ABS,`CNTLZ,`CNTLO,`CNTPOP:
1880
                        case(isn[25:23])
1881
                        3'b000: fnWe = 8'h01;
1882
                        3'b001: fnWe = 8'h03;
1883
                        3'b010: fnWe = 8'h0F;
1884
                        3'b011: fnWe = 8'hFF;
1885
                        default:        fnWe = 8'hFF;
1886
                        endcase
1887
                default: fnWe = 8'hFF;
1888
                endcase
1889
        `SHIFT31:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
1890
        `SHIFT63:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
1891
        `SLT,`SLTU,`SLE,`SLEU,
1892
        `ADD,`SUB,
1893
        `AND,`OR,`XOR,
1894
        `NAND,`NOR,`XNOR,
1895
        `DIVMOD,`DIVMODU,`DIVMODSU,
1896
        `MUL,`MULU,`MULSU:
1897
                case(isn[25:23])
1898
                3'b000: fnWe = 8'h01;
1899
                3'b001: fnWe = 8'h03;
1900
                3'b010: fnWe = 8'h0F;
1901
                3'b011: fnWe = 8'hFF;
1902
                default:        fnWe = 8'hFF;
1903
                endcase
1904
        default: fnWe = 8'hFF;
1905
        endcase
1906
default:        fnWe = 8'hFF;
1907
endcase
1908
endfunction
1909
 
1910
// Detect if a source is automatically valid
1911
function Source1Valid;
1912
input [47:0] isn;
1913
casez(isn[`INSTRUCTION_OP])
1914
`BRK:   Source1Valid = TRUE;
1915
`Bcc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1916
`BBc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1917
`BEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1918
`CHK:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1919
`RR:    case(isn[`INSTRUCTION_S2])
1920
        `SHIFT31:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1921
        `SHIFT63:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1922
        `SHIFTR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1923
        default:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1924
        endcase
1925
`MEMNDX:Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1926
`ADDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1927
`SLTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1928
`SLTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1929
`SGTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1930
`SGTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1931
`ANDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1932
`ORI:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1933
`XORI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1934
`XNORI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1935
`MULUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1936
`AMO:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1937
`LB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1938
`LBU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1939
`Lx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1940
`LxU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1941
`LWR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1942
`LV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1943
`LVx:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1944
`SB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1945
`Sx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1946
`SWC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1947
`SV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1948
`INC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1949
`CAS:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1950
`JAL:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1951
`RET:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1952
`CSRRW: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1953
`BITFIELD:      case(isn[31:28])
1954
                        `BFINSI:        Source1Valid = TRUE;
1955
                        default:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
1956
                        endcase
1957
`IVECTOR:
1958
                        Source1Valid = FALSE;
1959
default:    Source1Valid = TRUE;
1960
endcase
1961
endfunction
1962
 
1963
function Source2Valid;
1964
input [47:0] isn;
1965
casez(isn[`INSTRUCTION_OP])
1966
`BRK:   Source2Valid = TRUE;
1967
`Bcc:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1968
`BBc:   Source2Valid = TRUE;
1969
`BEQI:  Source2Valid = TRUE;
1970
`CHK:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1971
`RR:    case(isn[`INSTRUCTION_S2])
1972
        `R1:       Source2Valid = TRUE;
1973
        `SHIFTR:   Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
1974
        `SHIFT31:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
1975
        `SHIFT63:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
1976
        `LVX,`SVX: Source2Valid = FALSE;
1977
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1978
        endcase
1979
`MEMNDX:
1980
        case(isn[`INSTRUCTION_S2])
1981
        `LVX,`SVX: Source2Valid = FALSE;
1982
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
1983
        endcase
1984
`ADDI:  Source2Valid = TRUE;
1985
`SLTI:  Source2Valid = TRUE;
1986
`SLTUI: Source2Valid = TRUE;
1987
`SGTI:  Source2Valid = TRUE;
1988
`SGTUI: Source2Valid = TRUE;
1989
`ANDI:  Source2Valid = TRUE;
1990
`ORI:   Source2Valid = TRUE;
1991
`XORI:  Source2Valid = TRUE;
1992
`XNORI: Source2Valid = TRUE;
1993
`MULUI: Source2Valid = TRUE;
1994
`LB:    Source2Valid = TRUE;
1995
`LBU:   Source2Valid = TRUE;
1996
`Lx:    Source2Valid = TRUE;
1997
`LxU:   Source2Valid = TRUE;
1998
`LWR:   Source2Valid = TRUE;
1999
`LVx:   Source2Valid = TRUE;
2000
`INC:           Source2Valid = TRUE;
2001
`SB:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2002
`Sx:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2003
`SWC:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2004
`CAS:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2005
`JAL:   Source2Valid = TRUE;
2006
`RET:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2007
`IVECTOR:
2008
                    case(isn[`INSTRUCTION_S2])
2009
            `VABS:  Source2Valid = TRUE;
2010
            `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2011
                Source2Valid = FALSE;
2012
            `VADDS,`VSUBS,`VANDS,`VORS,`VXORS:
2013
                Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2014
            `VBITS2V:   Source2Valid = TRUE;
2015
            `V2BITS:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2016
            `VSHL,`VSHR,`VASR:  Source2Valid = isn[22:21]==2'd2;
2017
            default:    Source2Valid = FALSE;
2018
            endcase
2019
`LV:        Source2Valid = TRUE;
2020
`SV:        Source2Valid = FALSE;
2021
`AMO:           Source2Valid = isn[31] || isn[`INSTRUCTION_RB]==5'd0;
2022
default:    Source2Valid = TRUE;
2023
endcase
2024
endfunction
2025
 
2026
function Source3Valid;
2027
input [47:0] isn;
2028
case(isn[`INSTRUCTION_OP])
2029
`IVECTOR:
2030
    case(isn[`INSTRUCTION_S2])
2031
    `VEX:       Source3Valid = TRUE;
2032
    default:    Source3Valid = TRUE;
2033
    endcase
2034
`CHK:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2035
`R2:
2036
        if (isn[`INSTRUCTION_L2]==2'b01)
2037
                case(isn[47:42])
2038
    `CMOVEZ,`CMOVNZ:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2039
                default:        Source3Valid = TRUE;
2040
                endcase
2041
        else
2042
    case(isn[`INSTRUCTION_S2])
2043
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2044
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2045
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2046
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2047
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2048
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2049
    `MAJ:               Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2050
    default:    Source3Valid = TRUE;
2051
    endcase
2052
`MEMNDX:
2053
        if (isn[`INSTRUCTION_L2]==2'b00)
2054
    case(isn[`INSTRUCTION_S2])
2055
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2056
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2057
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2058
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2059
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2060
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2061
    default:    Source3Valid = TRUE;
2062
    endcase
2063
default:    Source3Valid = TRUE;
2064
endcase
2065
endfunction
2066
 
2067
function SourceTValid;
2068
input [31:0] isn;
2069
SourceTValid = FALSE;
2070
endfunction
2071
function SourceT2Valid;
2072
input [31:0] isn;
2073
case(isn[`INSTRUCTION_OP])
2074
`Bcc:       SourceT2Valid = TRUE;
2075
`ORI:       SourceT2Valid = TRUE;
2076
default:    SourceT2Valid = FALSE;
2077
endcase
2078
endfunction
2079
 
2080
// Used to indicate to the queue logic that the instruction needs to be
2081
// recycled to the queue VL number of times.
2082
function IsVector;
2083
input [47:0] isn;
2084
case(isn[`INSTRUCTION_OP])
2085
`MEMNDX:    case(isn[`INSTRUCTION_S2])
2086
            `LVX,`SVX:  IsVector = TRUE;
2087
            default:    IsVector = FALSE;
2088
            endcase
2089
`IVECTOR:
2090
                        case(isn[`INSTRUCTION_S2])
2091
                        `VMxx:
2092
                                case(isn[25:23])
2093
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2094
                        IsVector = FALSE;
2095
                default:        IsVector = TRUE;
2096
                endcase
2097
            `VEINS:     IsVector = FALSE;
2098
            `VEX:       IsVector = FALSE;
2099
            default:    IsVector = TRUE;
2100
            endcase
2101
`LV,`SV:    IsVector = TRUE;
2102
default:    IsVector = FALSE;
2103
endcase
2104
endfunction
2105
 
2106
function IsVeins;
2107
input [47:0] isn;
2108
case(isn[`INSTRUCTION_OP])
2109
`IVECTOR:   IsVeins = isn[`INSTRUCTION_S2]==`VEINS;
2110
default:    IsVeins = FALSE;
2111
endcase
2112
endfunction
2113
 
2114
function IsVex;
2115
input [47:0] isn;
2116
case(isn[`INSTRUCTION_OP])
2117
`IVECTOR:   IsVex = isn[`INSTRUCTION_S2]==`VEX;
2118
default:    IsVex = FALSE;
2119
endcase
2120
endfunction
2121
 
2122
function IsVCmprss;
2123
input [47:0] isn;
2124
case(isn[`INSTRUCTION_OP])
2125
`IVECTOR:   IsVCmprss = isn[`INSTRUCTION_S2]==`VCMPRSS || isn[`INSTRUCTION_S2]==`VCIDX;
2126
default:    IsVCmprss = FALSE;
2127
endcase
2128
endfunction
2129
 
2130
function IsVShifti;
2131
input [47:0] isn;
2132
case(isn[`INSTRUCTION_OP])
2133
`IVECTOR:
2134
                    case(isn[`INSTRUCTION_S2])
2135
            `VSHL,`VSHR,`VASR:
2136
                IsVShifti = {isn[25],isn[22]}==2'd2;
2137
            default:    IsVShifti = FALSE;
2138
            endcase
2139
default:    IsVShifti = FALSE;
2140
endcase
2141
endfunction
2142
 
2143
function IsVLS;
2144
input [47:0] isn;
2145
case(isn[`INSTRUCTION_OP])
2146
`MEMNDX:
2147
    case(isn[`INSTRUCTION_S2])
2148
    `LVX,`SVX,`LVWS,`SVWS:  IsVLS = TRUE;
2149
    default:    IsVLS = FALSE;
2150
    endcase
2151
`LV,`SV:    IsVLS = TRUE;
2152
default:    IsVLS = FALSE;
2153
endcase
2154
endfunction
2155
 
2156
function [1:0] fnM2;
2157
input [31:0] isn;
2158
case(isn[`INSTRUCTION_OP])
2159
`RR:    fnM2 = isn[24:23];
2160
default:    fnM2 = 2'b00;
2161
endcase
2162
endfunction
2163
 
2164
function [0:0] IsMem;
2165
input [47:0] isn;
2166
case(isn[`INSTRUCTION_OP])
2167
`MEMNDX:        IsMem = TRUE;
2168
`AMO:   IsMem = TRUE;
2169
`LB:    IsMem = TRUE;
2170
`LBU:   IsMem = TRUE;
2171
`Lx:    IsMem = TRUE;
2172
`LxU:   IsMem = TRUE;
2173
`LWR:   IsMem = TRUE;
2174
`LV,`SV:    IsMem = TRUE;
2175
`INC:           IsMem = TRUE;
2176
`SB:    IsMem = TRUE;
2177
`Sx:    IsMem = TRUE;
2178
`SWC:   IsMem = TRUE;
2179
`CAS:   IsMem = TRUE;
2180
`LVx:           IsMem = TRUE;
2181
default:    IsMem = FALSE;
2182
endcase
2183
endfunction
2184
 
2185
function IsMemNdx;
2186
input [47:0] isn;
2187
case(isn[`INSTRUCTION_OP])
2188
`MEMNDX:        IsMemNdx = TRUE;
2189
default:    IsMemNdx = FALSE;
2190
endcase
2191
endfunction
2192
 
2193
function IsLoad;
2194
input [47:0] isn;
2195
case(isn[`INSTRUCTION_OP])
2196
`MEMNDX:
2197
        if (isn[`INSTRUCTION_L2]==2'b00)
2198
            case(isn[`INSTRUCTION_S2])
2199
            `LBX:   IsLoad = TRUE;
2200
            `LBUX:  IsLoad = TRUE;
2201
            `LCX:   IsLoad = TRUE;
2202
            `LCUX:  IsLoad = TRUE;
2203
            `LHX:   IsLoad = TRUE;
2204
            `LHUX:  IsLoad = TRUE;
2205
            `LWX:   IsLoad = TRUE;
2206
            `LWRX:  IsLoad = TRUE;
2207
            `LVX:   IsLoad = TRUE;
2208
            `LVx:       IsLoad = TRUE;
2209
            default: IsLoad = FALSE;
2210
            endcase
2211
        else
2212
                IsLoad = FALSE;
2213
`LB:    IsLoad = TRUE;
2214
`LBU:   IsLoad = TRUE;
2215
`Lx:    IsLoad = TRUE;
2216
`LxU:   IsLoad = TRUE;
2217
`LWR:   IsLoad = TRUE;
2218
`LV:    IsLoad = TRUE;
2219
`LVx:   IsLoad = TRUE;
2220
default:    IsLoad = FALSE;
2221
endcase
2222
endfunction
2223
 
2224
function IsVolatileLoad;
2225
input [47:0] isn;
2226
case(isn[`INSTRUCTION_OP])
2227
`MEMNDX:
2228
        if (isn[`INSTRUCTION_L2]==2'b00)
2229
            case(isn[`INSTRUCTION_S2])
2230
            `LWRX:      IsVolatileLoad = TRUE;
2231
            `LVx:       IsVolatileLoad = TRUE;
2232
            default: IsVolatileLoad = FALSE;
2233
            endcase
2234
        else
2235
                IsVolatileLoad = FALSE;
2236
`LWR:   IsVolatileLoad = TRUE;
2237
`LVx:   IsVolatileLoad = TRUE;
2238
default:    IsVolatileLoad = FALSE;
2239
endcase
2240
endfunction
2241
 
2242
function [2:0] MemSize;
2243
input [47:0] isn;
2244
case(isn[`INSTRUCTION_OP])
2245
`MEMNDX:
2246
        if (isn[`INSTRUCTION_L2]==2'b00)
2247
            case(isn[`INSTRUCTION_S2])
2248
            `LBX,`LBUX,`SBX:   MemSize = byt;
2249
            `LCX,`LCUX,`SCX:   MemSize = wyde;
2250
            `LHX,`SHX:   MemSize = tetra;
2251
            `LHUX: MemSize = tetra;
2252
            `LWX,`SWX:   MemSize = octa;
2253
            `LWRX,`SWCX: MemSize = octa;
2254
            `LVX,`SVX:   MemSize = octa;
2255
            `LVx:
2256
                case(isn[25:23])
2257
                3'd0,3'd1:      MemSize = byt;
2258
                3'd2,3'd3:      MemSize = wyde;
2259
                3'd4,3'd5:      MemSize = tetra;
2260
                default:        MemSize = octa;
2261
                endcase
2262
            default: MemSize = octa;
2263
            endcase
2264
        else
2265
                MemSize = octa;
2266
`LB,`LBU,`SB:    MemSize = byt;
2267
`Lx,`LxU,`Sx:
2268
        casez(isn[20:18])
2269
        3'b100: MemSize = octa;
2270
        3'b?10: MemSize = tetra;
2271
        3'b??1: MemSize = wyde;
2272
        default:        MemSize = octa;
2273
        endcase
2274
`LWR,`SWC:  MemSize = octa;
2275
`LV,`SV:    MemSize = octa;
2276
`AMO:
2277
        case(isn[23:21])
2278
        3'd0:   MemSize = byt;
2279
        3'd1:   MemSize = wyde;
2280
        3'd2:   MemSize = tetra;
2281
        3'd3:   MemSize = octa;
2282
        default:        MemSize = octa;
2283
        endcase
2284
`LVx:
2285
        case(isn[30:28])
2286
        3'd0,3'd1:      MemSize = byt;
2287
        3'd2,3'd3:      MemSize = wyde;
2288
        3'd4,3'd5:      MemSize = tetra;
2289
        default:        MemSize = octa;
2290
        endcase
2291
default:    MemSize = octa;
2292
endcase
2293
endfunction
2294
 
2295
function IsStore;
2296
input [47:0] isn;
2297
case(isn[`INSTRUCTION_OP])
2298
`MEMNDX:
2299
        if (isn[`INSTRUCTION_L2]==2'b00)
2300
            case(isn[`INSTRUCTION_S2])
2301
            `SBX:   IsStore = TRUE;
2302
            `SCX:   IsStore = TRUE;
2303
            `SHX:   IsStore = TRUE;
2304
            `SWX:   IsStore = TRUE;
2305
            `SWCX:  IsStore = TRUE;
2306
            `SVX:   IsStore = TRUE;
2307
            `CASX:  IsStore = TRUE;
2308
            `INC:       IsStore = TRUE;
2309
            default:    IsStore = FALSE;
2310
            endcase
2311
        else
2312
                IsStore = FALSE;
2313
`SB:    IsStore = TRUE;
2314
`Sx:    IsStore = TRUE;
2315
`SWC:   IsStore = TRUE;
2316
`INC:   IsStore = TRUE;
2317
`SV:    IsStore = TRUE;
2318
`CAS:   IsStore = TRUE;
2319
`AMO:   IsStore = TRUE;
2320
default:    IsStore = FALSE;
2321
endcase
2322
endfunction
2323
 
2324
function IsInc;
2325
input [47:0] isn;
2326
case(isn[`INSTRUCTION_OP])
2327
`MEMNDX:
2328
        if (isn[`INSTRUCTION_L2]==2'b00)
2329
                case(isn[`INSTRUCTION_S2])
2330
            `INC:   IsInc = TRUE;
2331
            default:    IsInc = FALSE;
2332
            endcase
2333
        else
2334
                IsInc = FALSE;
2335
`INC:    IsInc = TRUE;
2336
default:    IsInc = FALSE;
2337
endcase
2338
endfunction
2339
 
2340
function IsSWC;
2341
input [47:0] isn;
2342
case(isn[`INSTRUCTION_OP])
2343
`MEMNDX:
2344
        if (isn[`INSTRUCTION_L2]==2'b00)
2345
                case(isn[`INSTRUCTION_S2])
2346
            `SWCX:   IsSWC = TRUE;
2347
            default:    IsSWC = FALSE;
2348
            endcase
2349
        else
2350
                IsSWC = FALSE;
2351
`SWC:    IsSWC = TRUE;
2352
default:    IsSWC = FALSE;
2353
endcase
2354
endfunction
2355
 
2356
// Aquire / release bits are only available on indexed SWC / LWR
2357
function IsSWCX;
2358
input [47:0] isn;
2359
case(isn[`INSTRUCTION_OP])
2360
`MEMNDX:
2361
        if (isn[`INSTRUCTION_L2]==2'b00)
2362
            case(isn[`INSTRUCTION_S2])
2363
            `SWCX:   IsSWCX = TRUE;
2364
            default:    IsSWCX = FALSE;
2365
            endcase
2366
        else
2367
                IsSWCX = FALSE;
2368
default:    IsSWCX = FALSE;
2369
endcase
2370
endfunction
2371
 
2372
function IsLWR;
2373
input [47:0] isn;
2374
case(isn[`INSTRUCTION_OP])
2375
`MEMNDX:
2376
        if (isn[`INSTRUCTION_L2]==2'b00)
2377
            case(isn[`INSTRUCTION_S2])
2378
            `LWRX:   IsLWR = TRUE;
2379
            default:    IsLWR = FALSE;
2380
            endcase
2381
        else
2382
                IsLWR = FALSE;
2383
`LWR:    IsLWR = TRUE;
2384
default:    IsLWR = FALSE;
2385
endcase
2386
endfunction
2387
 
2388
function IsLWRX;
2389
input [47:0] isn;
2390
case(isn[`INSTRUCTION_OP])
2391
`MEMNDX:
2392
        if (isn[`INSTRUCTION_L2]==2'b00)
2393
            case(isn[`INSTRUCTION_S2])
2394
            `LWRX:   IsLWRX = TRUE;
2395
            default:    IsLWRX = FALSE;
2396
            endcase
2397
        else
2398
                IsLWRX = FALSE;
2399
default:    IsLWRX = FALSE;
2400
endcase
2401
endfunction
2402
 
2403
function IsCAS;
2404
input [47:0] isn;
2405
case(isn[`INSTRUCTION_OP])
2406
`MEMNDX:
2407
        if (isn[`INSTRUCTION_L2]==2'b00)
2408
            case(isn[`INSTRUCTION_S2])
2409
            `CASX:   IsCAS = TRUE;
2410
            default:    IsCAS = FALSE;
2411
            endcase
2412
        else
2413
                IsCAS = FALSE;
2414
`CAS:       IsCAS = TRUE;
2415
default:    IsCAS = FALSE;
2416
endcase
2417
endfunction
2418
 
2419
function IsAMO;
2420
input [47:0] isn;
2421
case(isn[`INSTRUCTION_OP])
2422
`AMO:       IsAMO = TRUE;
2423
default:    IsAMO = FALSE;
2424
endcase
2425
endfunction
2426
 
2427
// Really IsPredictableBranch
2428
// Does not include BccR's
2429
function IsBranch;
2430
input [47:0] isn;
2431
casez(isn[`INSTRUCTION_OP])
2432
`Bcc:   IsBranch = TRUE;
2433
`BBc:   IsBranch = TRUE;
2434
`BEQI:  IsBranch = TRUE;
2435
`CHK:   IsBranch = TRUE;
2436
default:    IsBranch = FALSE;
2437
endcase
2438
endfunction
2439
 
2440
function IsWait;
2441
input [47:0] isn;
2442
IsWait = isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`WAIT;
2443
endfunction
2444
 
2445
function IsBrk;
2446
input [47:0] isn;
2447
IsBrk = isn[`INSTRUCTION_OP]==`BRK && isn[`INSTRUCTION_L2]==2'b00;
2448
endfunction
2449
 
2450
function IsIrq;
2451
input [47:0] isn;
2452
IsIrq = isn[`INSTRUCTION_OP]==`BRK && isn[`INSTRUCTION_L2]==2'b00 && isn[23:20]==4'h0;
2453
endfunction
2454
 
2455
function IsRTI;
2456
input [47:0] isn;
2457
IsRTI = isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`RTI;
2458
endfunction
2459
 
2460
function IsJAL;
2461
input [47:0] isn;
2462
IsJAL = isn[`INSTRUCTION_OP]==`JAL && isn[7]==1'b0;
2463
endfunction
2464
 
2465
function IsCall;
2466
input [47:0] isn;
2467
IsCall = isn[`INSTRUCTION_OP]==`CALL && isn[7]==1'b0;
2468
endfunction
2469
 
2470
function IsJmp;
2471
input [47:0] isn;
2472
IsJmp = isn[`INSTRUCTION_OP]==`JMP && isn[7]==1'b0;
2473
endfunction
2474
 
2475
function IsRet;
2476
input [47:0] isn;
2477
IsRet = isn[`INSTRUCTION_OP]==`RET && isn[7]==1'b0;
2478
endfunction
2479
 
2480
function IsFlowCtrl;
2481
input [47:0] isn;
2482
casez(isn[`INSTRUCTION_OP])
2483
`BRK:    IsFlowCtrl = TRUE;
2484
`RR:    case(isn[`INSTRUCTION_S2])
2485
        `RTI:   IsFlowCtrl = TRUE;
2486
        default:    IsFlowCtrl = FALSE;
2487
        endcase
2488
`Bcc:   IsFlowCtrl = TRUE;
2489
`BBc:           IsFlowCtrl = TRUE;
2490
`BEQI:  IsFlowCtrl = TRUE;
2491
`CHK:   IsFlowCtrl = TRUE;
2492
`JAL:   IsFlowCtrl = TRUE;
2493
`JMP:           IsFlowCtrl = TRUE;
2494
`CALL:  IsFlowCtrl = TRUE;
2495
`RET:   IsFlowCtrl = TRUE;
2496
default:    IsFlowCtrl = FALSE;
2497
endcase
2498
endfunction
2499
 
2500
function IsCache;
2501
input [47:0] isn;
2502
case(isn[`INSTRUCTION_OP])
2503
`MEMNDX:
2504
        if (isn[`INSTRUCTION_L2]==2'b00)
2505
            case(isn[`INSTRUCTION_S2])
2506
            `CACHEX:    IsCache = TRUE;
2507
            default:    IsCache = FALSE;
2508
            endcase
2509
        else
2510
                IsCache = FALSE;
2511
`CACHE: IsCache = TRUE;
2512
default: IsCache = FALSE;
2513
endcase
2514
endfunction
2515
 
2516
function [4:0] CacheCmd;
2517
input [47:0] isn;
2518
case(isn[`INSTRUCTION_OP])
2519
`MEMNDX:
2520
        if (isn[`INSTRUCTION_L2]==2'b00)
2521
            case(isn[`INSTRUCTION_S2])
2522
            `CACHEX:    CacheCmd = isn[22:18];
2523
            default:    CacheCmd = 5'd0;
2524
            endcase
2525
        else
2526
                CacheCmd = 5'd0;
2527
`CACHE: CacheCmd = isn[15:11];
2528
default: CacheCmd = 5'd0;
2529
endcase
2530
endfunction
2531
 
2532
function IsSync;
2533
input [47:0] isn;
2534
IsSync = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`SYNC);
2535
endfunction
2536
 
2537
function IsFSync;
2538
input [47:0] isn;
2539
IsFSync = (isn[`INSTRUCTION_OP]==`FLOAT && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`FSYNC);
2540
endfunction
2541
 
2542
function IsMemdb;
2543
input [47:0] isn;
2544
IsMemdb = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMDB);
2545
endfunction
2546
 
2547
function IsMemsb;
2548
input [47:0] isn;
2549
IsMemsb = (isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMSB);
2550
endfunction
2551
 
2552
function IsSEI;
2553
input [47:0] isn;
2554
IsSEI = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`SEI);
2555
endfunction
2556
 
2557
function IsLV;
2558
input [47:0] isn;
2559
case(isn[`INSTRUCTION_OP])
2560
`MEMNDX:
2561
        if (isn[`INSTRUCTION_L2]==2'b00)
2562
            case(isn[`INSTRUCTION_S2])
2563
            `LVX:   IsLV = TRUE;
2564
            default:    IsLV = FALSE;
2565
            endcase
2566
        else
2567
                IsLV = FALSE;
2568
`LV:        IsLV = TRUE;
2569
default:    IsLV = FALSE;
2570
endcase
2571
endfunction
2572
 
2573
function IsRFW;
2574
input [47:0] isn;
2575
input [5:0] vqei;
2576
input [5:0] vli;
2577
input thrd;
2578
if (fnRt(isn,vqei,vli,thrd)==12'd0)
2579
    IsRFW = FALSE;
2580
else
2581
casez(isn[`INSTRUCTION_OP])
2582
`IVECTOR:   IsRFW = TRUE;
2583
`FVECTOR:   IsRFW = TRUE;
2584
`R2:
2585
        if (isn[`INSTRUCTION_L2]==2'b00)
2586
            case(isn[`INSTRUCTION_S2])
2587
            `R1:    IsRFW = TRUE;
2588
            `ADD:   IsRFW = TRUE;
2589
            `SUB:   IsRFW = TRUE;
2590
            `SLT:   IsRFW = TRUE;
2591
            `SLTU:  IsRFW = TRUE;
2592
            `SLE:   IsRFW = TRUE;
2593
        `SLEU:  IsRFW = TRUE;
2594
            `AND:   IsRFW = TRUE;
2595
            `OR:    IsRFW = TRUE;
2596
            `XOR:   IsRFW = TRUE;
2597
            `MULU:  IsRFW = TRUE;
2598
            `MULSU: IsRFW = TRUE;
2599
            `MUL:   IsRFW = TRUE;
2600
            `DIVMODU:  IsRFW = TRUE;
2601
            `DIVMODSU: IsRFW = TRUE;
2602
            `DIVMOD:IsRFW = TRUE;
2603
            `MOV:       IsRFW = TRUE;
2604
            `VMOV:      IsRFW = TRUE;
2605
            `SHIFTR,`SHIFT31,`SHIFT63:
2606
                        IsRFW = TRUE;
2607
            `MIN,`MAX:    IsRFW = TRUE;
2608
            `SEI:       IsRFW = TRUE;
2609
            default:    IsRFW = FALSE;
2610
            endcase
2611
        else
2612
                IsRFW = FALSE;
2613
`MEMNDX:
2614
        if (isn[`INSTRUCTION_L2]==2'b00)
2615
            case(isn[`INSTRUCTION_S2])
2616
            `LBX:   IsRFW = TRUE;
2617
            `LBUX:  IsRFW = TRUE;
2618
            `LCX:   IsRFW = TRUE;
2619
            `LCUX:  IsRFW = TRUE;
2620
            `LHX:   IsRFW = TRUE;
2621
            `LHUX:  IsRFW = TRUE;
2622
            `LWX:   IsRFW = TRUE;
2623
            `LWRX:  IsRFW = TRUE;
2624
            `LVX:   IsRFW = TRUE;
2625
            `LVx:       IsRFW = TRUE;
2626
            `CASX:  IsRFW = TRUE;
2627
            default:    IsRFW = FALSE;
2628
            endcase
2629
        else
2630
                IsRFW = FALSE;
2631
`BBc:
2632
        case(isn[20:19])
2633
        `IBNE:  IsRFW = TRUE;
2634
        `DBNZ:  IsRFW = TRUE;
2635
        default:        IsRFW = FALSE;
2636
        endcase
2637
`BITFIELD:  IsRFW = TRUE;
2638
`ADDI:      IsRFW = TRUE;
2639
`SLTI:      IsRFW = TRUE;
2640
`SLTUI:     IsRFW = TRUE;
2641
`SGTI:      IsRFW = TRUE;
2642
`SGTUI:     IsRFW = TRUE;
2643
`ANDI:      IsRFW = TRUE;
2644
`ORI:       IsRFW = TRUE;
2645
`XORI:      IsRFW = TRUE;
2646
`MULUI:     IsRFW = TRUE;
2647
`MULI:      IsRFW = TRUE;
2648
`DIVUI:     IsRFW = TRUE;
2649
`DIVI:      IsRFW = TRUE;
2650
`MODI:      IsRFW = TRUE;
2651
`JAL:       IsRFW = TRUE;
2652
`CALL:      IsRFW = TRUE;
2653
`RET:       IsRFW = TRUE;
2654
`LB:        IsRFW = TRUE;
2655
`LBU:       IsRFW = TRUE;
2656
`Lx:        IsRFW = TRUE;
2657
`LWR:       IsRFW = TRUE;
2658
`LV:        IsRFW = TRUE;
2659
`LVx:                           IsRFW = TRUE;
2660
`CAS:       IsRFW = TRUE;
2661
`AMO:                           IsRFW = TRUE;
2662
`CSRRW:                 IsRFW = TRUE;
2663
default:    IsRFW = FALSE;
2664
endcase
2665
endfunction
2666
 
2667
function IsShifti;
2668
input [47:0] isn;
2669
case(isn[`INSTRUCTION_OP])
2670
`R2:
2671
        if (isn[`INSTRUCTION_L2]==2'b00)
2672
            case(isn[`INSTRUCTION_S2])
2673
            `SHIFT31,`SHIFT63:
2674
                IsShifti = TRUE;
2675
            default: IsShifti = FALSE;
2676
            endcase
2677
    else
2678
        IsShifti = FALSE;
2679
default: IsShifti = FALSE;
2680
endcase
2681
endfunction
2682
 
2683
function IsRtop;
2684
input [47:0] isn;
2685
case(isn[`INSTRUCTION_OP])
2686
`R2:
2687
        if (isn[`INSTRUCTION_L2]==2'b01)
2688
            case(isn[47:42])
2689
            `RTOP: IsRtop = TRUE;
2690
            default: IsRtop = FALSE;
2691
            endcase
2692
    else
2693
        IsRtop = FALSE;
2694
default: IsRtop = FALSE;
2695
endcase
2696
endfunction
2697
 
2698
function IsMul;
2699
input [47:0] isn;
2700
case(isn[`INSTRUCTION_OP])
2701
`RR:
2702
        if (isn[`INSTRUCTION_L2]==2'b00)
2703
            case(isn[`INSTRUCTION_S2])
2704
            `MULU,`MULSU,`MUL: IsMul = TRUE;
2705
            default:    IsMul = FALSE;
2706
            endcase
2707
        else
2708
                IsMul = FALSE;
2709
`MULUI,`MULI:  IsMul = TRUE;
2710
default:    IsMul = FALSE;
2711
endcase
2712
endfunction
2713
 
2714
function IsDivmod;
2715
input [47:0] isn;
2716
case(isn[`INSTRUCTION_OP])
2717
`RR:
2718
        if (isn[`INSTRUCTION_L2]==2'b00)
2719
            case(isn[`INSTRUCTION_S2])
2720
            `DIVMODU,`DIVMODSU,`DIVMOD: IsDivmod = TRUE;
2721
            default: IsDivmod = FALSE;
2722
            endcase
2723
        else
2724
                IsDivmod = FALSE;
2725
`DIVUI,`DIVI,`MODI:  IsDivmod = TRUE;
2726
default:    IsDivmod = FALSE;
2727
endcase
2728
endfunction
2729
 
2730
function IsExec;
2731
input [47:0] isn;
2732
case(isn[`INSTRUCTION_OP])
2733
`EXEC:  IsExec = TRUE;
2734
default:        IsExec = FALSE;
2735
endcase
2736
endfunction
2737
 
2738
function [7:0] fnSelect;
2739
input [47:0] ins;
2740
input [31:0] adr;
2741
begin
2742
        case(ins[`INSTRUCTION_OP])
2743
        `MEMNDX:
2744
                if (ins[`INSTRUCTION_L2]==2'b00)
2745
                   case(ins[`INSTRUCTION_S2])
2746
               `LBX,`LBUX,`SBX:
2747
                   case(adr[2:0])
2748
                   3'd0:    fnSelect = 8'h01;
2749
                   3'd1:    fnSelect = 8'h02;
2750
                   3'd2:    fnSelect = 8'h04;
2751
                   3'd3:    fnSelect = 8'h08;
2752
                   3'd4:    fnSelect = 8'h10;
2753
                   3'd5:    fnSelect = 8'h20;
2754
                   3'd6:    fnSelect = 8'h40;
2755
                   3'd7:    fnSelect = 8'h80;
2756
                   endcase
2757
                `LCX,`LCUX,`SCX:
2758
                    case(adr[2:1])
2759
                    2'd0:   fnSelect = 8'h03;
2760
                    2'd1:   fnSelect = 8'h0C;
2761
                    2'd2:   fnSelect = 8'h30;
2762
                    2'd3:   fnSelect = 8'hC0;
2763
                    endcase
2764
                `LHX,`LHUX,`SHX:
2765
                   case(adr[2])
2766
                   1'b0:    fnSelect = 8'h0F;
2767
                   1'b1:    fnSelect = 8'hF0;
2768
                   endcase
2769
               `INC,
2770
               `LWX,`SWX,`LWRX,`SWCX,`LVX,`SVX,`CASX:
2771
                   fnSelect = 8'hFF;
2772
               `LVx:   ;
2773
//                      case(ins[25:23])
2774
//                     `LVB,`LVBU:
2775
//                         case(adr[2:0])
2776
//                         3'd0:    fnSelect = 8'h01;
2777
//                         3'd1:    fnSelect = 8'h02;
2778
//                         3'd2:    fnSelect = 8'h04;
2779
//                         3'd3:    fnSelect = 8'h08;
2780
//                         3'd4:    fnSelect = 8'h10;
2781
//                         3'd5:    fnSelect = 8'h20;
2782
//                         3'd6:    fnSelect = 8'h40;
2783
//                         3'd7:    fnSelect = 8'h80;
2784
//                         endcase
2785
//                      `LVC,`LVCU:
2786
//                          case(adr[2:1])
2787
//                          2'd0:   fnSelect = 8'h03;
2788
//                          2'd1:   fnSelect = 8'h0C;
2789
//                          2'd2:   fnSelect = 8'h30;
2790
//                          2'd3:   fnSelect = 8'hC0;
2791
//                          endcase
2792
//                      `LVH,`LVHU:
2793
//                         case(adr[2])
2794
//                         1'b0:    fnSelect = 8'h0F;
2795
//                         1'b1:    fnSelect = 8'hF0;
2796
//                         endcase
2797
//                     `LVW:
2798
//                         fnSelect = 8'hFF;
2799
//                      endcase
2800
               default: fnSelect = 8'h00;
2801
                   endcase
2802
           else
2803
                fnSelect = 8'h00;
2804
    `LB,`LBU,`SB:
2805
                case(adr[2:0])
2806
                3'd0:   fnSelect = 8'h01;
2807
                3'd1:   fnSelect = 8'h02;
2808
                3'd2:   fnSelect = 8'h04;
2809
                3'd3:   fnSelect = 8'h08;
2810
                3'd4:   fnSelect = 8'h10;
2811
                3'd5:   fnSelect = 8'h20;
2812
                3'd6:   fnSelect = 8'h40;
2813
                3'd7:   fnSelect = 8'h80;
2814
                endcase
2815
    `Lx,`LxU,`Sx:
2816
        casez(ins[20:18])
2817
        3'b100: fnSelect = 8'hFF;
2818
        3'b?10: fnSelect = adr[2] ? 8'hF0 : 8'h0F;
2819
        3'b??1:
2820
        case(adr[2:1])
2821
        2'd0:   fnSelect = 8'h03;
2822
        2'd1:   fnSelect = 8'h0C;
2823
        2'd2:   fnSelect = 8'h30;
2824
        2'd3:   fnSelect = 8'hC0;
2825
        endcase
2826
      default: fnSelect = 8'h00;
2827
      endcase
2828
        `INC,
2829
        `LWR,`SWC,`CAS:   fnSelect = 8'hFF;
2830
        `LV,`SV:   fnSelect = 8'hFF;
2831
        `AMO:
2832
                case(ins[23:21])
2833
                3'd0:   fnSelect = {8'h01 << adr[2:0]};
2834
                3'd1:   fnSelect = {8'h03 << {adr[2:1],1'b0}};
2835
                3'd2:   fnSelect = {8'h0F << {adr[2],2'b00}};
2836
                3'd3:   fnSelect = 8'hFF;
2837
                default:        fnSelect = 8'hFF;
2838
                endcase
2839
//      `LVx:
2840
//       `LVB,`LVBU:
2841
//           case(adr[2:0])
2842
//           3'd0:    fnSelect = 8'h01;
2843
//           3'd1:    fnSelect = 8'h02;
2844
//           3'd2:    fnSelect = 8'h04;
2845
//           3'd3:    fnSelect = 8'h08;
2846
//           3'd4:    fnSelect = 8'h10;
2847
//           3'd5:    fnSelect = 8'h20;
2848
//           3'd6:    fnSelect = 8'h40;
2849
//           3'd7:    fnSelect = 8'h80;
2850
//           endcase
2851
//        `LVC,`LVCU:
2852
//            case(adr[2:1])
2853
//            2'd0:   fnSelect = 8'h03;
2854
//            2'd1:   fnSelect = 8'h0C;
2855
//            2'd2:   fnSelect = 8'h30;
2856
//            2'd3:   fnSelect = 8'hC0;
2857
//            endcase
2858
//      `LVH,`LVHU:
2859
//           case(adr[2])
2860
//           1'b0:    fnSelect = 8'h0F;
2861
//           1'b1:    fnSelect = 8'hF0;
2862
//           endcase
2863
//       `LVW:
2864
//           fnSelect = 8'hFF;
2865
        default:        fnSelect = 8'h00;
2866
        endcase
2867
end
2868
endfunction
2869
/*
2870
function [63:0] fnDatc;
2871
input [47:0] ins;
2872
input [63:0] dat;
2873
case(ins[`INSTRUCTION_OP])
2874
`R2:
2875
        if (isn[`INSTRUCTION_L2]==2'b01)
2876
                case(ins[47:42])
2877
                `FINDB:         fnDatc = dat[7:0];
2878
                `FINDC:         fnDatc = dat[15:0];
2879
                `FINDH:         fnDatc = dat[31:0];
2880
                `FINDW:         fnDatc = dat[63:0];
2881
                default:        fnDatc = dat[63:0];
2882
                endcase
2883
        else
2884
                fnDatc = dat[63:0];
2885
default:        fnDatc = dat[63:0];
2886
endcase
2887
endfunction
2888
*/
2889
/*
2890
function [63:0] fnMemInc;
2891
input [47:0] ins;
2892
case(ins[`INSTRUCTION_OP])
2893
`R2:
2894
        if (isn[`INSTRUCTION_L2]==2'b01)
2895
                case(ins[47:42])
2896
                `FINDB:         fnMemInc = 32'd1;
2897
                `FINDC:         fnMemInc = 32'd2;
2898
                `FINDH:         fnMemInc = 32'd4;
2899
                `FINDW:         fnMemInc = 32'd8;
2900
                default:        fnMemInc = 32'd8;
2901
                endcase
2902
        else
2903
                fnMemInc = 32'd8;
2904
default:        fnMemInc = 32'd8;
2905
endcase
2906
endfunction
2907
*/
2908
function [63:0] fnDati;
2909
input [47:0] ins;
2910
input [31:0] adr;
2911
input [63:0] dat;
2912
case(ins[`INSTRUCTION_OP])
2913
`MEMNDX:
2914
        if (ins[`INSTRUCTION_L2]==2'b00)
2915
            case(ins[`INSTRUCTION_S2])
2916
            `LBX:
2917
                case(adr[2:0])
2918
                3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
2919
                3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
2920
                3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
2921
                3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
2922
                3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
2923
                3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
2924
                3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
2925
                3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
2926
                endcase
2927
            `LBUX:
2928
                case(adr[2:0])
2929
                3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
2930
                3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
2931
                3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
2932
                3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
2933
                3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
2934
                3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
2935
                3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
2936
                3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
2937
                endcase
2938
            `LCX:
2939
                case(adr[2:1])
2940
                2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
2941
                2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
2942
                2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
2943
                2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
2944
                endcase
2945
            `LCUX:
2946
                case(adr[2:1])
2947
                2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
2948
                2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
2949
                2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
2950
                2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
2951
                endcase
2952
            `LHX:
2953
                case(adr[2])
2954
                1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
2955
                1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
2956
                endcase
2957
            `LHUX:
2958
                case(adr[2])
2959
                1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
2960
                1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
2961
                endcase
2962
            `LWX,`LWRX,`LVX,`CAS:  fnDati = dat;
2963
//          `LVx:
2964
//              case(ins[25:23])
2965
//                  `LVB:
2966
//                      case(adr[2:0])
2967
//                      3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
2968
//                      3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
2969
//                      3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
2970
//                      3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
2971
//                      3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
2972
//                      3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
2973
//                      3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
2974
//                      3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
2975
//                      endcase
2976
//                  `LVBU:
2977
//                      case(adr[2:0])
2978
//                      3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
2979
//                      3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
2980
//                      3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
2981
//                      3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
2982
//                      3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
2983
//                      3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
2984
//                      3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
2985
//                      3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
2986
//                      endcase
2987
//                  `LVC:
2988
//                      case(adr[2:1])
2989
//                      2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
2990
//                      2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
2991
//                      2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
2992
//                      2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
2993
//                      endcase
2994
//                  `LVCU:
2995
//                      case(adr[2:1])
2996
//                      2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
2997
//                      2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
2998
//                      2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
2999
//                      2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3000
//                      endcase
3001
//                  `LVH:
3002
//                      case(adr[2])
3003
//                      1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3004
//                      1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3005
//                      endcase
3006
//                  `LVHU:
3007
//                      case(adr[2])
3008
//                      1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3009
//                      1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3010
//                      endcase
3011
//                  `LVW:  fnDati = dat;
3012
//                  default:    fnDati = dat;
3013
//              endcase
3014
            default:    fnDati = dat;
3015
            endcase
3016
        else
3017
                fnDati = dat;
3018
`LB:
3019
  case(adr[2:0])
3020
  3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3021
  3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3022
  3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3023
  3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3024
  3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3025
  3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3026
  3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3027
  3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3028
  endcase
3029
`LBU:
3030
  case(adr[2:0])
3031
  3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3032
  3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3033
  3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3034
  3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3035
  3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3036
  3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3037
  3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3038
  3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3039
  endcase
3040
`Lx:
3041
        casez(ins[20:18])
3042
        3'b100: fnDati = dat;
3043
        3'b?10:
3044
          case(adr[2])
3045
          1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3046
          1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3047
          endcase
3048
        3'b??1:
3049
          case(adr[2:1])
3050
          2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3051
          2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3052
          2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3053
          2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3054
          endcase
3055
        endcase
3056
`LxU:
3057
        casez(ins[20:18])
3058
        3'b100: fnDati = dat;
3059
        3'b?10:
3060
          case(adr[2])
3061
          1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3062
          1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3063
          endcase
3064
        3'b??1:
3065
          case(adr[2:1])
3066
          2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3067
          2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3068
          2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3069
          2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3070
          endcase
3071
        endcase
3072
`LWR,`LV,`CAS,`AMO:   fnDati = dat;
3073
//`LVx:
3074
//      case(ins[30:28])
3075
//    `LVB:
3076
//        case(adr[2:0])
3077
//        3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3078
//        3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3079
//        3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3080
//        3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3081
//        3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3082
//        3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3083
//        3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3084
//        3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3085
//        endcase
3086
//    `LVBU:
3087
//        case(adr[2:0])
3088
//        3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3089
//        3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3090
//        3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3091
//        3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3092
//        3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3093
//        3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3094
//        3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3095
//        3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3096
//        endcase
3097
//    `LVC:
3098
//        case(adr[2:1])
3099
//        2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3100
//        2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3101
//        2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3102
//        2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3103
//        endcase
3104
//    `LVCU:
3105
//        case(adr[2:1])
3106
//        2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3107
//        2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3108
//        2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3109
//        2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3110
//        endcase
3111
//    `LVH:
3112
//        case(adr[2])
3113
//        1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3114
//        1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3115
//        endcase
3116
//    `LVHU:
3117
//        case(adr[2])
3118
//        1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3119
//        1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3120
//        endcase
3121
////    `LVW:  fnDati = dat;
3122
//    default:  fnDati = dat;
3123
//      endcase
3124
default:    fnDati = dat;
3125
endcase
3126
endfunction
3127
 
3128
function [63:0] fnDato;
3129
input [47:0] isn;
3130
input [63:0] dat;
3131
case(isn[`INSTRUCTION_OP])
3132
`MEMNDX:
3133
        if (isn[`INSTRUCTION_L2]==2'b00)
3134
                case(isn[`INSTRUCTION_S2])
3135
                `SBX:   fnDato = {8{dat[7:0]}};
3136
                `SCX:   fnDato = {4{dat[15:0]}};
3137
                `SHX:   fnDato = {2{dat[31:0]}};
3138
                default:    fnDato = dat;
3139
                endcase
3140
        else
3141
                fnDato = dat;
3142
`SB:   fnDato = {8{dat[7:0]}};
3143
`Sx:
3144
        case(isn[20:18])
3145
        3'b100: fnDato = dat;
3146
        3'b?10: fnDato = {2{dat[31:0]}};
3147
        3'b??1: fnDato = {4{dat[15:0]}};
3148
        default:        fnDato = dat;
3149
        endcase
3150
`AMO:
3151
        case(isn[23:21])
3152
        3'd0:   fnDato = {8{dat[7:0]}};
3153
        3'd1:   fnDato = {4{dat[15:0]}};
3154
        3'd2:   fnDato = {2{dat[31:0]}};
3155
        3'd3:   fnDato = dat;
3156
        default:        fnDato = dat;
3157
        endcase
3158
default:    fnDato = dat;
3159
endcase
3160
endfunction
3161
 
3162
// Indicate if the ALU instruction is valid immediately (single cycle operation)
3163
function IsSingleCycle;
3164
input [47:0] isn;
3165
IsSingleCycle = !(IsMul(isn)|IsDivmod(isn));
3166
endfunction
3167
 
3168
 
3169
`ifdef SUPPORT_SMT
3170
decoder8 iq0(.num({iqentry_tgt[0][8:7],iqentry_tgt[0][5:0]}), .out(iq0_out));
3171
decoder8 iq1(.num({iqentry_tgt[1][8:7],iqentry_tgt[1][5:0]}), .out(iq1_out));
3172
decoder8 iq2(.num({iqentry_tgt[2][8:7],iqentry_tgt[2][5:0]}), .out(iq2_out));
3173
decoder8 iq3(.num({iqentry_tgt[3][8:7],iqentry_tgt[3][5:0]}), .out(iq3_out));
3174
decoder8 iq4(.num({iqentry_tgt[4][8:7],iqentry_tgt[4][5:0]}), .out(iq4_out));
3175
decoder8 iq5(.num({iqentry_tgt[5][8:7],iqentry_tgt[5][5:0]}), .out(iq5_out));
3176
decoder8 iq6(.num({iqentry_tgt[6][8:7],iqentry_tgt[6][5:0]}), .out(iq6_out));
3177
decoder8 iq7(.num({iqentry_tgt[7][8:7],iqentry_tgt[7][5:0]}), .out(iq7_out));
3178
`else
3179
decoder7 iq0(.num({iqentry_tgt[0][7],iqentry_tgt[0][5:0]}), .out(iq0_out));
3180
decoder7 iq1(.num({iqentry_tgt[1][7],iqentry_tgt[1][5:0]}), .out(iq1_out));
3181
decoder7 iq2(.num({iqentry_tgt[2][7],iqentry_tgt[2][5:0]}), .out(iq2_out));
3182
decoder7 iq3(.num({iqentry_tgt[3][7],iqentry_tgt[3][5:0]}), .out(iq3_out));
3183
decoder7 iq4(.num({iqentry_tgt[4][7],iqentry_tgt[4][5:0]}), .out(iq4_out));
3184
decoder7 iq5(.num({iqentry_tgt[5][7],iqentry_tgt[5][5:0]}), .out(iq5_out));
3185
decoder7 iq6(.num({iqentry_tgt[6][7],iqentry_tgt[6][5:0]}), .out(iq6_out));
3186
decoder7 iq7(.num({iqentry_tgt[7][7],iqentry_tgt[7][5:0]}), .out(iq7_out));
3187
/*
3188
decoder6 iq0(.num({iqentry_tgt[0][5:0]}), .out(iq0_out));
3189
decoder6 iq1(.num({iqentry_tgt[1][5:0]}), .out(iq1_out));
3190
decoder6 iq2(.num({iqentry_tgt[2][5:0]}), .out(iq2_out));
3191
decoder6 iq3(.num({iqentry_tgt[3][5:0]}), .out(iq3_out));
3192
decoder6 iq4(.num({iqentry_tgt[4][5:0]}), .out(iq4_out));
3193
decoder6 iq5(.num({iqentry_tgt[5][5:0]}), .out(iq5_out));
3194
decoder6 iq6(.num({iqentry_tgt[6][5:0]}), .out(iq6_out));
3195
decoder6 iq7(.num({iqentry_tgt[7][5:0]}), .out(iq7_out));*/
3196
`endif
3197
 
3198
initial begin: Init
3199
        //
3200
        //
3201
        // set up panic messages
3202
        message[ `PANIC_NONE ]                  = "NONE            ";
3203
        message[ `PANIC_FETCHBUFBEQ ]           = "FETCHBUFBEQ     ";
3204
        message[ `PANIC_INVALIDISLOT ]          = "INVALIDISLOT    ";
3205
        message[ `PANIC_IDENTICALDRAMS ]        = "IDENTICALDRAMS  ";
3206
        message[ `PANIC_OVERRUN ]               = "OVERRUN         ";
3207
        message[ `PANIC_HALTINSTRUCTION ]       = "HALTINSTRUCTION ";
3208
        message[ `PANIC_INVALIDMEMOP ]          = "INVALIDMEMOP    ";
3209
        message[ `PANIC_INVALIDFBSTATE ]        = "INVALIDFBSTATE  ";
3210
        message[ `PANIC_INVALIDIQSTATE ]        = "INVALIDIQSTATE  ";
3211
        message[ `PANIC_BRANCHBACK ]            = "BRANCHBACK      ";
3212
        message[ `PANIC_MEMORYRACE ]            = "MEMORYRACE      ";
3213
        message[ `PANIC_ALU0ONLY ] = "ALU0 Only       ";
3214
 
3215
        for (n = 0; n < 64; n = n + 1)
3216
                codebuf[n] <= 48'h0;
3217
 
3218
end
3219
 
3220
// ---------------------------------------------------------------------------
3221
// FETCH
3222
// ---------------------------------------------------------------------------
3223
//
3224
assign fetchbuf0_mem   = IsMem(fetchbuf0_instr);
3225
assign fetchbuf0_memld = IsMem(fetchbuf0_instr) & IsLoad(fetchbuf0_instr);
3226
assign fetchbuf0_jmp   = IsFlowCtrl(fetchbuf0_instr);
3227
assign fetchbuf0_rfw   = IsRFW(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd);
3228
 
3229
assign fetchbuf1_mem   = IsMem(fetchbuf1_instr);
3230
assign fetchbuf1_memld = IsMem(fetchbuf1_instr) & IsLoad(fetchbuf1_instr);
3231
assign fetchbuf1_jmp   = IsFlowCtrl(fetchbuf1_instr);
3232
assign fetchbuf1_rfw   = IsRFW(fetchbuf1_instr,vqe1,vl,fetchbuf1_thrd);
3233
 
3234
FT64_fetchbuf #(AMSB,RSTPC) ufb1
3235
(
3236
    .rst(rst),
3237
    .clk4x(clk4x),
3238
    .clk(clk),
3239
    .cs_i(adr_o[31:16]==16'hFFFF),
3240
    .cyc_i(cyc_o),
3241
    .stb_i(stb_o),
3242
    .ack_o(dc_ack),
3243
    .we_i(we_o),
3244
    .adr_i(adr_o[15:0]),
3245
    .dat_i(dat_o[31:0]),
3246
    .hirq(hirq),
3247
    .regLR(regLR),
3248
    .thread_en(thread_en),
3249
    .insn0(insn0),
3250
    .insn1(insn1),
3251
    .phit(phit),
3252
    .threadx(threadx),
3253
    .branchmiss(branchmiss),
3254
    .misspc(misspc),
3255
    .branchmiss_thrd(branchmiss_thrd),
3256
    .predict_takenA(predict_takenA),
3257
    .predict_takenB(predict_takenB),
3258
    .predict_takenC(predict_takenC),
3259
    .predict_takenD(predict_takenD),
3260
    .predict_taken0(predict_taken0),
3261
    .predict_taken1(predict_taken1),
3262
    .queued1(queued1),
3263
    .queued2(queued2),
3264
    .queuedNop(queuedNop),
3265
    .pc0(pc0),
3266
    .pc1(pc1),
3267
    .fetchbuf(fetchbuf),
3268
    .fetchbufA_v(fetchbufA_v),
3269
    .fetchbufB_v(fetchbufB_v),
3270
    .fetchbufC_v(fetchbufC_v),
3271
    .fetchbufD_v(fetchbufD_v),
3272
    .fetchbufA_pc(fetchbufA_pc),
3273
    .fetchbufB_pc(fetchbufB_pc),
3274
    .fetchbufC_pc(fetchbufC_pc),
3275
    .fetchbufD_pc(fetchbufD_pc),
3276
    .fetchbufA_instr(fetchbufA_instr),
3277
    .fetchbufB_instr(fetchbufB_instr),
3278
    .fetchbufC_instr(fetchbufC_instr),
3279
    .fetchbufD_instr(fetchbufD_instr),
3280
    .fetchbuf0_instr(fetchbuf0_instr),
3281
    .fetchbuf1_instr(fetchbuf1_instr),
3282
    .fetchbuf0_thrd(fetchbuf0_thrd),
3283
    .fetchbuf1_thrd(fetchbuf1_thrd),
3284
    .fetchbuf0_pc(fetchbuf0_pc),
3285
    .fetchbuf1_pc(fetchbuf1_pc),
3286
    .fetchbuf0_v(fetchbuf0_v),
3287
    .fetchbuf1_v(fetchbuf1_v),
3288
    .fetchbuf0_insln(fetchbuf0_insln),
3289
    .fetchbuf1_insln(fetchbuf1_insln),
3290
    .codebuf0(codebuf[insn0[21:16]]),
3291
    .codebuf1(codebuf[insn1[21:16]]),
3292
    .btgtA(btgtA),
3293
    .btgtB(btgtB),
3294
    .btgtC(btgtC),
3295
    .btgtD(btgtD),
3296
    .nop_fetchbuf(nop_fetchbuf),
3297
    .take_branch0(take_branch0),
3298
    .take_branch1(take_branch1),
3299
    .stompedRets(stompedOnRets)
3300
);
3301
 
3302
 
3303
 
3304
//initial begin: stop_at
3305
//#1000000; panic <= `PANIC_OVERRUN;
3306
//end
3307
 
3308
//
3309
// BRANCH-MISS LOGIC: livetarget
3310
//
3311
// livetarget implies that there is a not-to-be-stomped instruction that targets the register in question
3312
// therefore, if it is zero it implies the rf_v value should become VALID on a branchmiss
3313
// 
3314
 
3315
generate begin : live_target
3316
    for (g = 1; g < PREGS; g = g + 1) begin : lvtgt
3317
    assign livetarget[g] = iqentry_0_livetarget[g] |
3318
                        iqentry_1_livetarget[g] |
3319
                        iqentry_2_livetarget[g] |
3320
                        iqentry_3_livetarget[g] |
3321
                        iqentry_4_livetarget[g] |
3322
                        iqentry_5_livetarget[g] |
3323
                        iqentry_6_livetarget[g] |
3324
                        iqentry_7_livetarget[g];
3325
    end
3326
end
3327
endgenerate
3328
 
3329
    assign  iqentry_0_livetarget = {PREGS {iqentry_v[0]}} & {PREGS {~iqentry_stomp[0] && iqentry_thrd[0]==branchmiss_thrd}} & iq0_out,
3330
            iqentry_1_livetarget = {PREGS {iqentry_v[1]}} & {PREGS {~iqentry_stomp[1] && iqentry_thrd[1]==branchmiss_thrd}} & iq1_out,
3331
            iqentry_2_livetarget = {PREGS {iqentry_v[2]}} & {PREGS {~iqentry_stomp[2] && iqentry_thrd[2]==branchmiss_thrd}} & iq2_out,
3332
            iqentry_3_livetarget = {PREGS {iqentry_v[3]}} & {PREGS {~iqentry_stomp[3] && iqentry_thrd[3]==branchmiss_thrd}} & iq3_out,
3333
            iqentry_4_livetarget = {PREGS {iqentry_v[4]}} & {PREGS {~iqentry_stomp[4] && iqentry_thrd[4]==branchmiss_thrd}} & iq4_out,
3334
            iqentry_5_livetarget = {PREGS {iqentry_v[5]}} & {PREGS {~iqentry_stomp[5] && iqentry_thrd[5]==branchmiss_thrd}} & iq5_out,
3335
            iqentry_6_livetarget = {PREGS {iqentry_v[6]}} & {PREGS {~iqentry_stomp[6] && iqentry_thrd[6]==branchmiss_thrd}} & iq6_out,
3336
            iqentry_7_livetarget = {PREGS {iqentry_v[7]}} & {PREGS {~iqentry_stomp[7] && iqentry_thrd[7]==branchmiss_thrd}} & iq7_out;
3337
 
3338
    //
3339
    // BRANCH-MISS LOGIC: latestID
3340
    //
3341
    // latestID is the instruction queue ID of the newest instruction (latest) that targets
3342
    // a particular register.  looks a lot like scheduling logic, but in reverse.
3343
    // 
3344
    assign iqentry_0_cumulative = (missid==3'd0) ? iqentry_0_livetarget :
3345
                                  (missid==3'd1) ? iqentry_0_livetarget |
3346
                                                   iqentry_1_livetarget :
3347
                                  (missid==3'd2) ? iqentry_0_livetarget |
3348
                                                   iqentry_1_livetarget |
3349
                                                   iqentry_2_livetarget :
3350
                                  (missid==3'd3) ? iqentry_0_livetarget |
3351
                                                   iqentry_1_livetarget |
3352
                                                   iqentry_2_livetarget |
3353
                                                   iqentry_3_livetarget :
3354
                                  (missid==3'd4) ? iqentry_0_livetarget |
3355
                                                   iqentry_1_livetarget |
3356
                                                   iqentry_2_livetarget |
3357
                                                   iqentry_3_livetarget |
3358
                                                   iqentry_4_livetarget :
3359
                                  (missid==3'd5) ? iqentry_0_livetarget |
3360
                                                   iqentry_1_livetarget |
3361
                                                   iqentry_2_livetarget |
3362
                                                   iqentry_3_livetarget |
3363
                                                   iqentry_4_livetarget |
3364
                                                   iqentry_5_livetarget :
3365
                                  (missid==3'd6) ? iqentry_0_livetarget |
3366
                                                   iqentry_1_livetarget |
3367
                                                   iqentry_2_livetarget |
3368
                                                   iqentry_3_livetarget |
3369
                                                   iqentry_4_livetarget |
3370
                                                   iqentry_5_livetarget |
3371
                                                   iqentry_6_livetarget :
3372
                                  (missid==3'd7) ? iqentry_0_livetarget |
3373
                                                   iqentry_1_livetarget |
3374
                                                   iqentry_2_livetarget |
3375
                                                   iqentry_3_livetarget |
3376
                                                   iqentry_4_livetarget |
3377
                                                   iqentry_5_livetarget |
3378
                                                   iqentry_6_livetarget |
3379
                                                   iqentry_7_livetarget :
3380
                                                   {PREGS{1'b0}};
3381
 
3382
    assign iqentry_1_cumulative = (missid==3'd1) ? iqentry_1_livetarget :
3383
                                  (missid==3'd2) ? iqentry_1_livetarget |
3384
                                                   iqentry_2_livetarget :
3385
                                  (missid==3'd3) ? iqentry_1_livetarget |
3386
                                                   iqentry_2_livetarget |
3387
                                                   iqentry_3_livetarget :
3388
                                  (missid==3'd4) ? iqentry_1_livetarget |
3389
                                                   iqentry_2_livetarget |
3390
                                                   iqentry_3_livetarget |
3391
                                                   iqentry_4_livetarget :
3392
                                  (missid==3'd5) ? iqentry_1_livetarget |
3393
                                                   iqentry_2_livetarget |
3394
                                                   iqentry_3_livetarget |
3395
                                                   iqentry_4_livetarget |
3396
                                                   iqentry_5_livetarget :
3397
                                  (missid==3'd6) ? iqentry_1_livetarget |
3398
                                                   iqentry_2_livetarget |
3399
                                                   iqentry_3_livetarget |
3400
                                                   iqentry_4_livetarget |
3401
                                                   iqentry_5_livetarget |
3402
                                                   iqentry_6_livetarget :
3403
                                  (missid==3'd7) ? iqentry_1_livetarget |
3404
                                                   iqentry_2_livetarget |
3405
                                                   iqentry_3_livetarget |
3406
                                                   iqentry_4_livetarget |
3407
                                                   iqentry_5_livetarget |
3408
                                                   iqentry_6_livetarget |
3409
                                                   iqentry_7_livetarget :
3410
                                  (missid==3'd0) ? iqentry_1_livetarget |
3411
                                                   iqentry_2_livetarget |
3412
                                                   iqentry_3_livetarget |
3413
                                                   iqentry_4_livetarget |
3414
                                                   iqentry_5_livetarget |
3415
                                                   iqentry_6_livetarget |
3416
                                                   iqentry_7_livetarget |
3417
                                                   iqentry_0_livetarget :
3418
                                                   {PREGS{1'b0}};
3419
 
3420
    assign iqentry_2_cumulative = (missid==3'd2) ? iqentry_2_livetarget :
3421
                                     (missid==3'd3) ? iqentry_2_livetarget |
3422
                                                      iqentry_3_livetarget :
3423
                                     (missid==3'd4) ? iqentry_2_livetarget |
3424
                                                      iqentry_3_livetarget |
3425
                                                      iqentry_4_livetarget :
3426
                                     (missid==3'd5) ? iqentry_2_livetarget |
3427
                                                      iqentry_3_livetarget |
3428
                                                      iqentry_4_livetarget |
3429
                                                      iqentry_5_livetarget :
3430
                                     (missid==3'd6) ? iqentry_2_livetarget |
3431
                                                      iqentry_3_livetarget |
3432
                                                      iqentry_4_livetarget |
3433
                                                      iqentry_5_livetarget |
3434
                                                      iqentry_6_livetarget :
3435
                                     (missid==3'd7) ? iqentry_2_livetarget |
3436
                                                      iqentry_3_livetarget |
3437
                                                      iqentry_4_livetarget |
3438
                                                      iqentry_5_livetarget |
3439
                                                      iqentry_6_livetarget |
3440
                                                      iqentry_7_livetarget :
3441
                                     (missid==3'd0) ? iqentry_2_livetarget |
3442
                                                      iqentry_3_livetarget |
3443
                                                      iqentry_4_livetarget |
3444
                                                      iqentry_5_livetarget |
3445
                                                      iqentry_6_livetarget |
3446
                                                      iqentry_7_livetarget |
3447
                                                      iqentry_0_livetarget :
3448
                                     (missid==3'd1) ? iqentry_2_livetarget |
3449
                                                      iqentry_3_livetarget |
3450
                                                      iqentry_4_livetarget |
3451
                                                      iqentry_5_livetarget |
3452
                                                      iqentry_6_livetarget |
3453
                                                      iqentry_7_livetarget |
3454
                                                      iqentry_0_livetarget |
3455
                                                      iqentry_1_livetarget :
3456
                                                      {PREGS{1'b0}};
3457
 
3458
    assign iqentry_3_cumulative = (missid==3'd3) ? iqentry_3_livetarget :
3459
                                     (missid==3'd4) ? iqentry_3_livetarget |
3460
                                                      iqentry_4_livetarget :
3461
                                     (missid==3'd5) ? iqentry_3_livetarget |
3462
                                                      iqentry_4_livetarget |
3463
                                                      iqentry_5_livetarget :
3464
                                     (missid==3'd6) ? iqentry_3_livetarget |
3465
                                                      iqentry_4_livetarget |
3466
                                                      iqentry_5_livetarget |
3467
                                                      iqentry_6_livetarget :
3468
                                     (missid==3'd7) ? iqentry_3_livetarget |
3469
                                                      iqentry_4_livetarget |
3470
                                                      iqentry_5_livetarget |
3471
                                                      iqentry_6_livetarget |
3472
                                                      iqentry_7_livetarget :
3473
                                     (missid==3'd0) ? iqentry_3_livetarget |
3474
                                                      iqentry_4_livetarget |
3475
                                                      iqentry_5_livetarget |
3476
                                                      iqentry_6_livetarget |
3477
                                                      iqentry_7_livetarget |
3478
                                                      iqentry_0_livetarget :
3479
                                     (missid==3'd1) ? iqentry_3_livetarget |
3480
                                                      iqentry_4_livetarget |
3481
                                                      iqentry_5_livetarget |
3482
                                                      iqentry_6_livetarget |
3483
                                                      iqentry_7_livetarget |
3484
                                                      iqentry_0_livetarget |
3485
                                                      iqentry_1_livetarget :
3486
                                     (missid==3'd2) ? iqentry_3_livetarget |
3487
                                                      iqentry_4_livetarget |
3488
                                                      iqentry_5_livetarget |
3489
                                                      iqentry_6_livetarget |
3490
                                                      iqentry_7_livetarget |
3491
                                                      iqentry_0_livetarget |
3492
                                                      iqentry_1_livetarget |
3493
                                                      iqentry_2_livetarget :
3494
                                                      {PREGS{1'b0}};
3495
 
3496
    assign iqentry_4_cumulative = (missid==3'd4) ? iqentry_4_livetarget :
3497
                                     (missid==3'd5) ? iqentry_4_livetarget |
3498
                                                      iqentry_5_livetarget :
3499
                                     (missid==3'd6) ? iqentry_4_livetarget |
3500
                                                      iqentry_5_livetarget |
3501
                                                      iqentry_6_livetarget :
3502
                                     (missid==3'd7) ? iqentry_4_livetarget |
3503
                                                      iqentry_5_livetarget |
3504
                                                      iqentry_6_livetarget |
3505
                                                      iqentry_7_livetarget :
3506
                                     (missid==3'd0) ? iqentry_4_livetarget |
3507
                                                      iqentry_5_livetarget |
3508
                                                      iqentry_6_livetarget |
3509
                                                      iqentry_7_livetarget |
3510
                                                      iqentry_0_livetarget :
3511
                                     (missid==3'd1) ? iqentry_4_livetarget |
3512
                                                      iqentry_5_livetarget |
3513
                                                      iqentry_6_livetarget |
3514
                                                      iqentry_7_livetarget |
3515
                                                      iqentry_0_livetarget |
3516
                                                      iqentry_1_livetarget :
3517
                                     (missid==3'd2) ? iqentry_4_livetarget |
3518
                                                      iqentry_5_livetarget |
3519
                                                      iqentry_6_livetarget |
3520
                                                      iqentry_7_livetarget |
3521
                                                      iqentry_0_livetarget |
3522
                                                      iqentry_1_livetarget |
3523
                                                      iqentry_2_livetarget :
3524
                                     (missid==3'd3) ? iqentry_4_livetarget |
3525
                                                      iqentry_5_livetarget |
3526
                                                      iqentry_6_livetarget |
3527
                                                      iqentry_7_livetarget |
3528
                                                      iqentry_0_livetarget |
3529
                                                      iqentry_1_livetarget |
3530
                                                      iqentry_2_livetarget |
3531
                                                      iqentry_3_livetarget :
3532
                                                      {PREGS{1'b0}};
3533
 
3534
    assign iqentry_5_cumulative = (missid==3'd5) ? iqentry_5_livetarget :
3535
                                     (missid==3'd6) ? iqentry_5_livetarget |
3536
                                                      iqentry_6_livetarget :
3537
                                     (missid==3'd7) ? iqentry_5_livetarget |
3538
                                                      iqentry_6_livetarget |
3539
                                                      iqentry_7_livetarget :
3540
                                     (missid==3'd0) ? iqentry_5_livetarget |
3541
                                                      iqentry_6_livetarget |
3542
                                                      iqentry_7_livetarget |
3543
                                                      iqentry_0_livetarget :
3544
                                     (missid==3'd1) ? iqentry_5_livetarget |
3545
                                                      iqentry_6_livetarget |
3546
                                                      iqentry_7_livetarget |
3547
                                                      iqentry_0_livetarget |
3548
                                                      iqentry_1_livetarget :
3549
                                     (missid==3'd2) ? iqentry_5_livetarget |
3550
                                                      iqentry_6_livetarget |
3551
                                                      iqentry_7_livetarget |
3552
                                                      iqentry_0_livetarget |
3553
                                                      iqentry_1_livetarget |
3554
                                                      iqentry_2_livetarget :
3555
                                     (missid==3'd3) ? iqentry_5_livetarget |
3556
                                                      iqentry_6_livetarget |
3557
                                                      iqentry_7_livetarget |
3558
                                                      iqentry_0_livetarget |
3559
                                                      iqentry_1_livetarget |
3560
                                                      iqentry_2_livetarget |
3561
                                                      iqentry_3_livetarget :
3562
                                     (missid==3'd4) ? iqentry_5_livetarget |
3563
                                                      iqentry_6_livetarget |
3564
                                                      iqentry_7_livetarget |
3565
                                                      iqentry_0_livetarget |
3566
                                                      iqentry_1_livetarget |
3567
                                                      iqentry_2_livetarget |
3568
                                                      iqentry_3_livetarget |
3569
                                                      iqentry_4_livetarget :
3570
                                                      {PREGS{1'b0}};
3571
    assign iqentry_6_cumulative = (missid==3'd6) ? iqentry_6_livetarget :
3572
                                       (missid==3'd7) ? iqentry_6_livetarget |
3573
                                                        iqentry_7_livetarget :
3574
                                       (missid==3'd0) ? iqentry_6_livetarget |
3575
                                                        iqentry_7_livetarget |
3576
                                                        iqentry_0_livetarget :
3577
                                       (missid==3'd1) ? iqentry_6_livetarget |
3578
                                                        iqentry_7_livetarget |
3579
                                                        iqentry_0_livetarget |
3580
                                                        iqentry_1_livetarget :
3581
                                       (missid==3'd2) ? iqentry_6_livetarget |
3582
                                                        iqentry_7_livetarget |
3583
                                                        iqentry_0_livetarget |
3584
                                                        iqentry_1_livetarget |
3585
                                                        iqentry_2_livetarget :
3586
                                       (missid==3'd3) ? iqentry_6_livetarget |
3587
                                                        iqentry_7_livetarget |
3588
                                                        iqentry_0_livetarget |
3589
                                                        iqentry_1_livetarget |
3590
                                                        iqentry_2_livetarget |
3591
                                                        iqentry_3_livetarget :
3592
                                       (missid==3'd4) ? iqentry_6_livetarget |
3593
                                                        iqentry_7_livetarget |
3594
                                                        iqentry_0_livetarget |
3595
                                                        iqentry_1_livetarget |
3596
                                                        iqentry_2_livetarget |
3597
                                                        iqentry_3_livetarget |
3598
                                                        iqentry_4_livetarget :
3599
                                       (missid==3'd5) ? iqentry_6_livetarget |
3600
                                                        iqentry_7_livetarget |
3601
                                                        iqentry_0_livetarget |
3602
                                                        iqentry_1_livetarget |
3603
                                                        iqentry_2_livetarget |
3604
                                                        iqentry_3_livetarget |
3605
                                                        iqentry_4_livetarget |
3606
                                                        iqentry_5_livetarget :
3607
                                                        {PREGS{1'b0}};
3608
 
3609
    assign iqentry_7_cumulative = (missid==3'd7) ? iqentry_7_livetarget :
3610
                                       (missid==3'd0) ? iqentry_7_livetarget |
3611
                                                        iqentry_0_livetarget :
3612
                                       (missid==3'd1) ? iqentry_7_livetarget |
3613
                                                        iqentry_0_livetarget |
3614
                                                        iqentry_1_livetarget :
3615
                                       (missid==3'd2) ? iqentry_7_livetarget |
3616
                                                        iqentry_0_livetarget |
3617
                                                        iqentry_1_livetarget |
3618
                                                        iqentry_2_livetarget :
3619
                                       (missid==3'd3) ? iqentry_7_livetarget |
3620
                                                        iqentry_0_livetarget |
3621
                                                        iqentry_1_livetarget |
3622
                                                        iqentry_2_livetarget |
3623
                                                        iqentry_3_livetarget :
3624
                                       (missid==3'd4) ? iqentry_7_livetarget |
3625
                                                        iqentry_0_livetarget |
3626
                                                        iqentry_1_livetarget |
3627
                                                        iqentry_2_livetarget |
3628
                                                        iqentry_3_livetarget |
3629
                                                        iqentry_4_livetarget :
3630
                                       (missid==3'd5) ? iqentry_7_livetarget |
3631
                                                        iqentry_0_livetarget |
3632
                                                        iqentry_1_livetarget |
3633
                                                        iqentry_2_livetarget |
3634
                                                        iqentry_3_livetarget |
3635
                                                        iqentry_4_livetarget |
3636
                                                        iqentry_5_livetarget :
3637
                                       (missid==3'd6) ? iqentry_7_livetarget |
3638
                                                        iqentry_0_livetarget |
3639
                                                        iqentry_1_livetarget |
3640
                                                        iqentry_2_livetarget |
3641
                                                        iqentry_3_livetarget |
3642
                                                        iqentry_4_livetarget |
3643
                                                        iqentry_5_livetarget |
3644
                                                        iqentry_6_livetarget :
3645
                                                        {PREGS{1'b0}};
3646
 
3647
    assign iqentry_0_latestID = (missid == 3'd0 || ((iqentry_0_livetarget & iqentry_1_cumulative) == {PREGS{1'b0}}))
3648
                                    ? iqentry_0_livetarget
3649
                                    : {PREGS{1'b0}};
3650
 
3651
    assign iqentry_1_latestID = (missid == 3'd1 || ((iqentry_1_livetarget & iqentry_2_cumulative) == {PREGS{1'b0}}))
3652
                                    ? iqentry_1_livetarget
3653
                                    : {PREGS{1'b0}};
3654
 
3655
    assign iqentry_2_latestID = (missid == 3'd2 || ((iqentry_2_livetarget & iqentry_3_cumulative) == {PREGS{1'b0}}))
3656
                                    ? iqentry_2_livetarget
3657
                                    : {PREGS{1'b0}};
3658
 
3659
    assign iqentry_3_latestID = (missid == 3'd3 || ((iqentry_3_livetarget & iqentry_4_cumulative) == {PREGS{1'b0}}))
3660
                                    ? iqentry_3_livetarget
3661
                                    : {PREGS{1'b0}};
3662
 
3663
    assign iqentry_4_latestID = (missid == 3'd4 || ((iqentry_4_livetarget & iqentry_5_cumulative) == {PREGS{1'b0}}))
3664
                                    ? iqentry_4_livetarget
3665
                                    : {PREGS{1'b0}};
3666
 
3667
    assign iqentry_5_latestID = (missid == 3'd5 || ((iqentry_5_livetarget & iqentry_6_cumulative) == {PREGS{1'b0}}))
3668
                                    ? iqentry_5_livetarget
3669
                                    : {PREGS{1'b0}};
3670
 
3671
    assign iqentry_6_latestID = (missid == 3'd6 || ((iqentry_6_livetarget & iqentry_7_cumulative) == {PREGS{1'b0}}))
3672
                                    ? iqentry_6_livetarget
3673
                                    : {PREGS{1'b0}};
3674
 
3675
    assign iqentry_7_latestID = (missid == 3'd7 || ((iqentry_7_livetarget & iqentry_0_cumulative) == {PREGS{1'b0}}))
3676
                                    ? iqentry_7_livetarget
3677
                                    : {PREGS{1'b0}};
3678
 
3679
    assign  iqentry_source[0] = | iqentry_0_latestID,
3680
            iqentry_source[1] = | iqentry_1_latestID,
3681
            iqentry_source[2] = | iqentry_2_latestID,
3682
            iqentry_source[3] = | iqentry_3_latestID,
3683
            iqentry_source[4] = | iqentry_4_latestID,
3684
            iqentry_source[5] = | iqentry_5_latestID,
3685
            iqentry_source[6] = | iqentry_6_latestID,
3686
            iqentry_source[7] = | iqentry_7_latestID;
3687
 
3688
 
3689
reg vqueued2;
3690
assign Ra0 = fnRa(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3691
assign Rb0 = fnRb(fetchbuf0_instr,1'b0,vqe0,rfoa0[5:0],rfoa1[5:0],fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3692
assign Rc0 = fnRc(fetchbuf0_instr,vqe0,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3693
assign Rt0 = fnRt(fetchbuf0_instr,vqet0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3694
assign Ra1 = fnRa(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3695
assign Rb1 = fnRb(fetchbuf1_instr,1'b1,vqueued2 ? vqe0 + 1 : vqe1,rfoa0[5:0],rfoa1[5:0],fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3696
assign Rc1 = fnRc(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3697
assign Rt1 = fnRt(fetchbuf1_instr,vqueued2 ? vqet0 + 1 : vqet1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3698
 
3699
    //
3700
    // additional logic for ISSUE
3701
    //
3702
    // for the moment, we look at ALU-input buffers to allow back-to-back issue of 
3703
    // dependent instructions ... we do not, however, look ahead for DRAM requests 
3704
    // that will become valid in the next cycle.  instead, these have to propagate
3705
    // their results into the IQ entry directly, at which point it becomes issue-able
3706
    //
3707
 
3708
    // note that, for all intents & purposes, iqentry_done == iqentry_agen ... no need to duplicate
3709
 
3710
wire [QENTRIES-1:0] args_valid;
3711
wire [QENTRIES-1:0] could_issue;
3712
wire [QENTRIES-1:0] could_issueid;
3713
 
3714
generate begin : issue_logic
3715
for (g = 0; g < QENTRIES; g = g + 1)
3716
begin
3717
assign args_valid[g] =
3718
                  (iqentry_a1_v[g]
3719
        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3720
        || (iqentry_a1_s[g] == alu1_sourceid && alu1_dataready))
3721
    && (iqentry_a2_v[g]
3722
        || (iqentry_mem[g] & ~iqentry_agen[g] & ~iqentry_memndx[g])    // a2 needs to be valid for indexed instruction
3723
        || (iqentry_a2_s[g] == alu0_sourceid && alu0_dataready)
3724
        || (iqentry_a2_s[g] == alu1_sourceid && alu1_dataready))
3725
    && (iqentry_a3_v[g]
3726
//        || (iqentry_mem[g] & ~iqentry_agen[g])
3727
        || (iqentry_a3_s[g] == alu0_sourceid && alu0_dataready)
3728
        || (iqentry_a3_s[g] == alu1_sourceid && alu1_dataready))
3729
    ;
3730
 
3731
assign could_issue[g] = iqentry_v[g] && !iqentry_done[g] && !iqentry_out[g]
3732
                                                                                                && args_valid[g]
3733
                                                                                                && iqentry_iv[g]
3734
                        && (iqentry_mem[g] ? !iqentry_agen[g] : 1'b1);
3735
 
3736
assign could_issueid[g] = iqentry_v[g] && !iqentry_iv[g];
3737
//                && (iqentry_a1_v[g] 
3738
//        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3739
//        || (iqentry_a1_s[g] == alu1_sourceid && alu1_dataready));
3740
 
3741
end
3742
end
3743
endgenerate
3744
 
3745
// The (old) simulator didn't handle the asynchronous race loop properly in the 
3746
// original code. It would issue two instructions to the same islot. So the
3747
// issue logic has been re-written to eliminate the asynchronous loop.
3748
// Can't issue to the ALU if it's busy doing a long running operation like a 
3749
// divide.
3750
// ToDo: fix the memory synchronization, see fp_issue below
3751
 
3752
wire [`QBITS] heads [QENTRIES-1:0];
3753
assign heads[0] = head0;
3754
assign heads[1] = head1;
3755
assign heads[2] = head2;
3756
assign heads[3] = head3;
3757
assign heads[4] = head4;
3758
assign heads[5] = head5;
3759
assign heads[6] = head6;
3760
assign heads[7] = head7;
3761
 
3762
always @*
3763
begin
3764
        iqentry_id1issue = 8'h00;
3765
        iqentry_id2issue = 8'h00;
3766
 
3767
        // aluissue is a task
3768
        if (id1_available) begin
3769
                for (n = 0; n < QENTRIES; n = n + 1)
3770
                        if (could_issueid[heads[n]] && iqentry_id1issue==8'h00)
3771
                          iqentry_id1issue[heads[n]] = `TRUE;
3772
        end
3773
 
3774
        if (id2_available) begin
3775
                for (n = 0; n < QENTRIES; n = n + 1)
3776
                        if (could_issueid[heads[n]] && !iqentry_id1issue[heads[n]] && iqentry_id2issue==8'h00)
3777
                          iqentry_id2issue[heads[n]] = `TRUE;
3778
        end
3779
end
3780
 
3781
always @*
3782
begin
3783
        iqentry_alu0_issue = 8'h00;
3784
        iqentry_alu1_issue = 8'h00;
3785
 
3786
        // aluissue is a task
3787
        // aluissue is a task
3788
        if (alu0_available & alu0_idle) begin
3789
                if (could_issue[head0] && iqentry_alu[head0]) begin
3790
                  iqentry_alu0_issue[head0] = `TRUE;
3791
                end
3792
                else if (could_issue[head1] && iqentry_alu[head1])
3793
                begin
3794
                  iqentry_alu0_issue[head1] = `TRUE;
3795
                end
3796
                else if (could_issue[head2] && iqentry_alu[head2]
3797
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3798
                )
3799
                begin
3800
                        iqentry_alu0_issue[head2] = `TRUE;
3801
                end
3802
                else if (could_issue[head3] && iqentry_alu[head3]
3803
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3804
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3805
                                ((!iqentry_v[head0])
3806
                        &&   (!iqentry_v[head1]))
3807
                        )
3808
                ) begin
3809
                        iqentry_alu0_issue[head3] = `TRUE;
3810
                end
3811
                else if (could_issue[head4] && iqentry_alu[head4]
3812
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3813
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3814
                                ((!iqentry_v[head0])
3815
                        &&   (!iqentry_v[head1]))
3816
                        )
3817
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3818
                                ((!iqentry_v[head0])
3819
                        &&   (!iqentry_v[head1])
3820
                        &&   (!iqentry_v[head2]))
3821
                        )
3822
                ) begin
3823
                        iqentry_alu0_issue[head4] = `TRUE;
3824
                end
3825
                else if (could_issue[head5] && iqentry_alu[head5]
3826
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3827
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3828
                                ((!iqentry_v[head0])
3829
                        &&   (!iqentry_v[head1]))
3830
                        )
3831
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3832
                                ((!iqentry_v[head0])
3833
                        &&   (!iqentry_v[head1])
3834
                        &&   (!iqentry_v[head2]))
3835
                        )
3836
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3837
                                ((!iqentry_v[head0])
3838
                        &&   (!iqentry_v[head1])
3839
                        &&   (!iqentry_v[head2])
3840
                        &&   (!iqentry_v[head3]))
3841
                        )
3842
                ) begin
3843
                        iqentry_alu0_issue[head5] = `TRUE;
3844
                end
3845
`ifdef FULL_ISSUE_LOGIC
3846
                else if (could_issue[head6] && iqentry_alu[head6]
3847
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3848
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3849
                                ((!iqentry_v[head0])
3850
                        &&   (!iqentry_v[head1]))
3851
                        )
3852
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3853
                                ((!iqentry_v[head0])
3854
                        &&   (!iqentry_v[head1])
3855
                        &&   (!iqentry_v[head2]))
3856
                        )
3857
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3858
                                ((!iqentry_v[head0])
3859
                        &&   (!iqentry_v[head1])
3860
                        &&   (!iqentry_v[head2])
3861
                        &&   (!iqentry_v[head3]))
3862
                        )
3863
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3864
                                ((!iqentry_v[head0])
3865
                        &&   (!iqentry_v[head1])
3866
                        &&   (!iqentry_v[head2])
3867
                        &&   (!iqentry_v[head3])
3868
                        &&   (!iqentry_v[head4]))
3869
                        )
3870
                ) begin
3871
                        iqentry_alu0_issue[head6] = `TRUE;
3872
                end
3873
                else if (could_issue[head7] && iqentry_alu[head7]
3874
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3875
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3876
                                ((!iqentry_v[head0])
3877
                        &&   (!iqentry_v[head1]))
3878
                        )
3879
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3880
                                ((!iqentry_v[head0])
3881
                        &&   (!iqentry_v[head1])
3882
                        &&   (!iqentry_v[head2]))
3883
                        )
3884
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3885
                                ((!iqentry_v[head0])
3886
                        &&   (!iqentry_v[head1])
3887
                        &&   (!iqentry_v[head2])
3888
                        &&   (!iqentry_v[head3]))
3889
                        )
3890
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3891
                                ((!iqentry_v[head0])
3892
                        &&   (!iqentry_v[head1])
3893
                        &&   (!iqentry_v[head2])
3894
                        &&   (!iqentry_v[head3])
3895
                        &&   (!iqentry_v[head4]))
3896
                        )
3897
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
3898
                                ((!iqentry_v[head0])
3899
                        &&   (!iqentry_v[head1])
3900
                        &&   (!iqentry_v[head2])
3901
                        &&   (!iqentry_v[head3])
3902
                        &&   (!iqentry_v[head4])
3903
                        &&   (!iqentry_v[head5]))
3904
                        )
3905
                ) begin
3906
                        iqentry_alu0_issue[head7] = `TRUE;
3907
                end
3908
`endif
3909
        end
3910
 
3911
        if (alu1_available & alu1_idle) begin
3912
                if ((could_issue & ~iqentry_alu0_issue & ~iqentry_alu0) != 8'h00) begin
3913
                if (could_issue[head0] && iqentry_alu[head0]
3914
                && !iqentry_alu0[head0] // alu0only
3915
                && !iqentry_alu0_issue[head0]) begin
3916
                  iqentry_alu1_issue[head0] = `TRUE;
3917
                end
3918
                else if (could_issue[head1] && !iqentry_alu0_issue[head1] && iqentry_alu[head1]
3919
                && !iqentry_alu0[head1])
3920
                begin
3921
                  iqentry_alu1_issue[head1] = `TRUE;
3922
                end
3923
                else if (could_issue[head2] && !iqentry_alu0_issue[head2] && iqentry_alu[head2]
3924
                && !iqentry_alu0[head2]
3925
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3926
                )
3927
                begin
3928
                        iqentry_alu1_issue[head2] = `TRUE;
3929
                end
3930
                else if (could_issue[head3] && !iqentry_alu0_issue[head3] && iqentry_alu[head3]
3931
                && !iqentry_alu0[head3]
3932
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3933
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3934
                                ((!iqentry_v[head0])
3935
                        &&   (!iqentry_v[head1]))
3936
                        )
3937
                ) begin
3938
                        iqentry_alu1_issue[head3] = `TRUE;
3939
                end
3940
                else if (could_issue[head4] && !iqentry_alu0_issue[head4] && iqentry_alu[head4]
3941
                && !iqentry_alu0[head4]
3942
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3943
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3944
                                ((!iqentry_v[head0])
3945
                        &&   (!iqentry_v[head1]))
3946
                        )
3947
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3948
                                ((!iqentry_v[head0])
3949
                        &&   (!iqentry_v[head1])
3950
                        &&   (!iqentry_v[head2]))
3951
                        )
3952
                ) begin
3953
                        iqentry_alu1_issue[head4] = `TRUE;
3954
                end
3955
                else if (could_issue[head5] && !iqentry_alu0_issue[head5] && iqentry_alu[head5]
3956
                && !iqentry_alu0[head5]
3957
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3958
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3959
                                ((!iqentry_v[head0])
3960
                        &&   (!iqentry_v[head1]))
3961
                        )
3962
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3963
                                ((!iqentry_v[head0])
3964
                        &&   (!iqentry_v[head1])
3965
                        &&   (!iqentry_v[head2]))
3966
                        )
3967
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3968
                                ((!iqentry_v[head0])
3969
                        &&   (!iqentry_v[head1])
3970
                        &&   (!iqentry_v[head2])
3971
                        &&   (!iqentry_v[head3]))
3972
                        )
3973
                ) begin
3974
                        iqentry_alu1_issue[head5] = `TRUE;
3975
                end
3976
`ifdef FULL_ISSUE_LOGIC
3977
                else if (could_issue[head6] && !iqentry_alu0_issue[head6] && iqentry_alu[head6]
3978
                && !iqentry_alu0[head6]
3979
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3980
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3981
                                ((!iqentry_v[head0])
3982
                        &&   (!iqentry_v[head1]))
3983
                        )
3984
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3985
                                ((!iqentry_v[head0])
3986
                        &&   (!iqentry_v[head1])
3987
                        &&   (!iqentry_v[head2]))
3988
                        )
3989
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3990
                                ((!iqentry_v[head0])
3991
                        &&   (!iqentry_v[head1])
3992
                        &&   (!iqentry_v[head2])
3993
                        &&   (!iqentry_v[head3]))
3994
                        )
3995
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3996
                                ((!iqentry_v[head0])
3997
                        &&   (!iqentry_v[head1])
3998
                        &&   (!iqentry_v[head2])
3999
                        &&   (!iqentry_v[head3])
4000
                        &&   (!iqentry_v[head4]))
4001
                        )
4002
                ) begin
4003
                        iqentry_alu1_issue[head6] = `TRUE;
4004
                end
4005
                else if (could_issue[head7] && !iqentry_alu0_issue[head7] && iqentry_alu[head7]
4006
                && !iqentry_alu0[head7]
4007
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4008
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4009
                                ((!iqentry_v[head0])
4010
                        &&   (!iqentry_v[head1]))
4011
                        )
4012
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4013
                                ((!iqentry_v[head0])
4014
                        &&   (!iqentry_v[head1])
4015
                        &&   (!iqentry_v[head2]))
4016
                        )
4017
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4018
                                ((!iqentry_v[head0])
4019
                        &&   (!iqentry_v[head1])
4020
                        &&   (!iqentry_v[head2])
4021
                        &&   (!iqentry_v[head3]))
4022
                        )
4023
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4024
                                ((!iqentry_v[head0])
4025
                        &&   (!iqentry_v[head1])
4026
                        &&   (!iqentry_v[head2])
4027
                        &&   (!iqentry_v[head3])
4028
                        &&   (!iqentry_v[head4]))
4029
                        )
4030
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4031
                                ((!iqentry_v[head0])
4032
                        &&   (!iqentry_v[head1])
4033
                        &&   (!iqentry_v[head2])
4034
                        &&   (!iqentry_v[head3])
4035
                        &&   (!iqentry_v[head4])
4036
                        &&   (!iqentry_v[head5]))
4037
                        )
4038
                ) begin
4039
                        iqentry_alu1_issue[head7] = `TRUE;
4040
                end
4041
`endif
4042
        end
4043
//      aluissue(alu0_idle,8'h00,2'b00);
4044
//      aluissue(alu1_idle,iqentry_alu0,2'b01);
4045
        end
4046
end
4047
 
4048
always @*
4049
begin
4050
        iqentry_fpu_issue = 8'h00;
4051
//      fpuissue(fpu_idle,2'b00);
4052
        if (fpu_idle) begin
4053
    if (could_issue[head0] && iqentry_fpu[head0]) begin
4054
      iqentry_fpu_issue[head0] = `TRUE;
4055
      iqentry_fpu_islot[head0] = 2'b00;
4056
    end
4057
    else if (could_issue[head1] && iqentry_fpu[head1])
4058
    begin
4059
      iqentry_fpu_issue[head1] = `TRUE;
4060
      iqentry_fpu_islot[head1] = 2'b00;
4061
    end
4062
    else if (could_issue[head2] && iqentry_fpu[head2]
4063
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4064
    ) begin
4065
      iqentry_fpu_issue[head2] = `TRUE;
4066
      iqentry_fpu_islot[head2] = 2'b00;
4067
    end
4068
    else if (could_issue[head3] && iqentry_fpu[head3]
4069
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4070
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4071
                ((!iqentry_v[head0])
4072
        &&   (!iqentry_v[head1]))
4073
        )
4074
    ) begin
4075
      iqentry_fpu_issue[head3] = `TRUE;
4076
      iqentry_fpu_islot[head3] = 2'b00;
4077
    end
4078
    else if (could_issue[head4] && iqentry_fpu[head4]
4079
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4080
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4081
                ((!iqentry_v[head0])
4082
        &&   (!iqentry_v[head1]))
4083
        )
4084
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4085
                ((!iqentry_v[head0])
4086
        &&   (!iqentry_v[head1])
4087
        &&   (!iqentry_v[head2]))
4088
        )
4089
    ) begin
4090
      iqentry_fpu_issue[head4] = `TRUE;
4091
      iqentry_fpu_islot[head4] = 2'b00;
4092
    end
4093
    else if (could_issue[head5] && iqentry_fpu[head5]
4094
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4095
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4096
                ((!iqentry_v[head0])
4097
        &&   (!iqentry_v[head1]))
4098
        )
4099
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4100
                ((!iqentry_v[head0])
4101
        &&   (!iqentry_v[head1])
4102
        &&   (!iqentry_v[head2]))
4103
        )
4104
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4105
                ((!iqentry_v[head0])
4106
        &&   (!iqentry_v[head1])
4107
        &&   (!iqentry_v[head2])
4108
        &&   (!iqentry_v[head3]))
4109
        )
4110
        ) begin
4111
              iqentry_fpu_issue[head5] = `TRUE;
4112
              iqentry_fpu_islot[head5] = 2'b00;
4113
    end
4114
`ifdef FULL_ISSUE_LOGIC
4115
    else if (could_issue[head6] && iqentry_fpu[head6]
4116
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4117
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4118
                ((!iqentry_v[head0])
4119
        &&   (!iqentry_v[head1]))
4120
        )
4121
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4122
                ((!iqentry_v[head0])
4123
        &&   (!iqentry_v[head1])
4124
        &&   (!iqentry_v[head2]))
4125
        )
4126
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4127
                ((!iqentry_v[head0])
4128
        &&   (!iqentry_v[head1])
4129
        &&   (!iqentry_v[head2])
4130
        &&   (!iqentry_v[head3]))
4131
        )
4132
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4133
                ((!iqentry_v[head0])
4134
        &&   (!iqentry_v[head1])
4135
        &&   (!iqentry_v[head2])
4136
        &&   (!iqentry_v[head3])
4137
        &&   (!iqentry_v[head4]))
4138
        )
4139
    ) begin
4140
        iqentry_fpu_issue[head6] = `TRUE;
4141
            iqentry_fpu_islot[head6] = 2'b00;
4142
    end
4143
    else if (could_issue[head7] && iqentry_fpu[head7]
4144
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4145
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4146
                ((!iqentry_v[head0])
4147
        &&   (!iqentry_v[head1]))
4148
        )
4149
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4150
                ((!iqentry_v[head0])
4151
        &&   (!iqentry_v[head1])
4152
        &&   (!iqentry_v[head2]))
4153
        )
4154
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4155
                ((!iqentry_v[head0])
4156
        &&   (!iqentry_v[head1])
4157
        &&   (!iqentry_v[head2])
4158
        &&   (!iqentry_v[head3]))
4159
        )
4160
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4161
                ((!iqentry_v[head0])
4162
        &&   (!iqentry_v[head1])
4163
        &&   (!iqentry_v[head2])
4164
        &&   (!iqentry_v[head3])
4165
        &&   (!iqentry_v[head4]))
4166
        )
4167
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
4168
                ((!iqentry_v[head0])
4169
        &&   (!iqentry_v[head1])
4170
        &&   (!iqentry_v[head2])
4171
        &&   (!iqentry_v[head3])
4172
        &&   (!iqentry_v[head4])
4173
        &&   (!iqentry_v[head5]))
4174
        )
4175
        )
4176
    begin
4177
                iqentry_fpu_issue[head7] = `TRUE;
4178
                iqentry_fpu_islot[head7] = 2'b00;
4179
        end
4180
`endif
4181
        end
4182
end
4183
 
4184
 
4185
wire [QENTRIES-1:0] nextqd;
4186
// Next queue id
4187
 
4188
reg [`QBITS] nid0;
4189
always @*
4190
if (iqentry_thrd[1]==iqentry_thrd[0])
4191
        nid0 = 3'd1;
4192
else if (iqentry_thrd[2]==iqentry_thrd[0])
4193
        nid0 = 3'd2;
4194
else if (iqentry_thrd[3]==iqentry_thrd[0])
4195
        nid0 = 3'd3;
4196
else if (iqentry_thrd[4]==iqentry_thrd[0])
4197
        nid0 = 3'd4;
4198
else if (iqentry_thrd[5]==iqentry_thrd[0])
4199
        nid0 = 3'd5;
4200
else if (iqentry_thrd[6]==iqentry_thrd[0])
4201
        nid0 = 3'd6;
4202
else if (iqentry_thrd[7]==iqentry_thrd[0])
4203
        nid0 = 3'd7;
4204
else
4205
        nid0 = 3'd0;
4206
 
4207
reg [`QBITS] nid1;
4208
always @*
4209
if (iqentry_thrd[2]==iqentry_thrd[1])
4210
        nid1 = 3'd2;
4211
else if (iqentry_thrd[3]==iqentry_thrd[1])
4212
        nid1 = 3'd3;
4213
else if (iqentry_thrd[4]==iqentry_thrd[1])
4214
        nid1 = 3'd4;
4215
else if (iqentry_thrd[5]==iqentry_thrd[1])
4216
        nid1 = 3'd5;
4217
else if (iqentry_thrd[6]==iqentry_thrd[1])
4218
        nid1 = 3'd6;
4219
else if (iqentry_thrd[7]==iqentry_thrd[1])
4220
        nid1 = 3'd7;
4221
else if (iqentry_thrd[0]==iqentry_thrd[1])
4222
        nid1 = 3'd0;
4223
else
4224
        nid1 = 3'd1;
4225
 
4226
reg [`QBITS] nid2;
4227
always @*
4228
if (iqentry_thrd[3]==iqentry_thrd[2])
4229
        nid2 = 3'd3;
4230
else if (iqentry_thrd[4]==iqentry_thrd[2])
4231
        nid2 = 3'd4;
4232
else if (iqentry_thrd[5]==iqentry_thrd[2])
4233
        nid2 = 3'd5;
4234
else if (iqentry_thrd[6]==iqentry_thrd[2])
4235
        nid2 = 3'd6;
4236
else if (iqentry_thrd[7]==iqentry_thrd[2])
4237
        nid2 = 3'd7;
4238
else if (iqentry_thrd[0]==iqentry_thrd[2])
4239
        nid2 = 3'd0;
4240
else if (iqentry_thrd[1]==iqentry_thrd[2])
4241
        nid2 = 3'd1;
4242
else
4243
        nid2 = 3'd2;
4244
 
4245
reg [`QBITS] nid3;
4246
always @*
4247
if (iqentry_thrd[4]==iqentry_thrd[3])
4248
        nid3 = 3'd4;
4249
else if (iqentry_thrd[5]==iqentry_thrd[3])
4250
        nid3 = 3'd5;
4251
else if (iqentry_thrd[6]==iqentry_thrd[3])
4252
        nid3 = 3'd6;
4253
else if (iqentry_thrd[7]==iqentry_thrd[3])
4254
        nid3 = 3'd7;
4255
else if (iqentry_thrd[0]==iqentry_thrd[3])
4256
        nid3 = 3'd0;
4257
else if (iqentry_thrd[1]==iqentry_thrd[3])
4258
        nid3 = 3'd1;
4259
else if (iqentry_thrd[2]==iqentry_thrd[3])
4260
        nid3 = 3'd2;
4261
else
4262
        nid3 = 3'd3;
4263
 
4264
reg [`QBITS] nid4;
4265
always @*
4266
if (iqentry_thrd[5]==iqentry_thrd[4])
4267
        nid4 = 3'd5;
4268
else if (iqentry_thrd[6]==iqentry_thrd[4])
4269
        nid4 = 3'd6;
4270
else if (iqentry_thrd[7]==iqentry_thrd[4])
4271
        nid4 = 3'd7;
4272
else if (iqentry_thrd[0]==iqentry_thrd[4])
4273
        nid4 = 3'd0;
4274
else if (iqentry_thrd[1]==iqentry_thrd[4])
4275
        nid4 = 3'd1;
4276
else if (iqentry_thrd[2]==iqentry_thrd[4])
4277
        nid4 = 3'd2;
4278
else if (iqentry_thrd[3]==iqentry_thrd[4])
4279
        nid4 = 3'd3;
4280
else
4281
        nid4 = 3'd4;
4282
 
4283
reg [`QBITS] nid5;
4284
always @*
4285
if (iqentry_thrd[6]==iqentry_thrd[5])
4286
        nid5 = 3'd6;
4287
else if (iqentry_thrd[7]==iqentry_thrd[5])
4288
        nid5 = 3'd7;
4289
else if (iqentry_thrd[0]==iqentry_thrd[5])
4290
        nid5 = 3'd0;
4291
else if (iqentry_thrd[1]==iqentry_thrd[5])
4292
        nid5 = 3'd1;
4293
else if (iqentry_thrd[2]==iqentry_thrd[5])
4294
        nid5 = 3'd2;
4295
else if (iqentry_thrd[3]==iqentry_thrd[5])
4296
        nid5 = 3'd3;
4297
else if (iqentry_thrd[4]==iqentry_thrd[5])
4298
        nid5 = 3'd4;
4299
else
4300
        nid5 = 3'd5;
4301
 
4302
reg [`QBITS] nid6;
4303
always @*
4304
if (iqentry_thrd[7]==iqentry_thrd[6])
4305
        nid6 = 3'd7;
4306
else if (iqentry_thrd[0]==iqentry_thrd[6])
4307
        nid6 = 3'd0;
4308
else if (iqentry_thrd[1]==iqentry_thrd[6])
4309
        nid6 = 3'd1;
4310
else if (iqentry_thrd[2]==iqentry_thrd[6])
4311
        nid6 = 3'd2;
4312
else if (iqentry_thrd[3]==iqentry_thrd[6])
4313
        nid6 = 3'd3;
4314
else if (iqentry_thrd[4]==iqentry_thrd[6])
4315
        nid6 = 3'd4;
4316
else if (iqentry_thrd[5]==iqentry_thrd[6])
4317
        nid6 = 3'd5;
4318
else
4319
        nid6 = 3'd6;
4320
 
4321
reg [`QBITS] nid7;
4322
always @*
4323
if (iqentry_thrd[0]==iqentry_thrd[7])
4324
        nid7 = 3'd0;
4325
else if (iqentry_thrd[1]==iqentry_thrd[7])
4326
        nid7 = 3'd1;
4327
else if (iqentry_thrd[2]==iqentry_thrd[7])
4328
        nid7 = 3'd2;
4329
else if (iqentry_thrd[3]==iqentry_thrd[7])
4330
        nid7 = 3'd3;
4331
else if (iqentry_thrd[4]==iqentry_thrd[7])
4332
        nid7 = 3'd4;
4333
else if (iqentry_thrd[5]==iqentry_thrd[7])
4334
        nid7 = 3'd5;
4335
else if (iqentry_thrd[6]==iqentry_thrd[7])
4336
        nid7 = 3'd6;
4337
else
4338
        nid7 = 3'd7;
4339
 
4340
// Search the queue for the next entry on the same thread.
4341
reg [`QBITS] nid;
4342
always @*
4343
if (iqentry_thrd[idp1(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4344
        nid = idp1(fcu_id);
4345
else if (iqentry_thrd[idp2(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4346
        nid = idp2(fcu_id);
4347
else if (iqentry_thrd[idp3(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4348
        nid = idp3(fcu_id);
4349
else if (iqentry_thrd[idp4(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4350
        nid = idp4(fcu_id);
4351
else if (iqentry_thrd[idp5(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4352
        nid = idp5(fcu_id);
4353
else if (iqentry_thrd[idp6(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4354
        nid = idp6(fcu_id);
4355
else if (iqentry_thrd[idp7(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4356
        nid = idp7(fcu_id);
4357
else
4358
        nid = fcu_id;
4359
 
4360
 
4361
assign  nextqd[0] = iqentry_sn[nid0] > iqentry_sn[0] || iqentry_v[0];
4362
assign  nextqd[1] = iqentry_sn[nid1] > iqentry_sn[1] || iqentry_v[1];
4363
assign  nextqd[2] = iqentry_sn[nid2] > iqentry_sn[2] || iqentry_v[2];
4364
assign  nextqd[3] = iqentry_sn[nid3] > iqentry_sn[3] || iqentry_v[3];
4365
assign  nextqd[4] = iqentry_sn[nid4] > iqentry_sn[4] || iqentry_v[4];
4366
assign  nextqd[5] = iqentry_sn[nid5] > iqentry_sn[5] || iqentry_v[5];
4367
assign  nextqd[6] = iqentry_sn[nid6] > iqentry_sn[6] || iqentry_v[6];
4368
assign  nextqd[7] = iqentry_sn[nid7] > iqentry_sn[7] || iqentry_v[7];
4369
 
4370
//assign nextqd = 8'hFF;
4371
 
4372
// Don't issue to the fcu until the following instruction is enqueued.
4373
// However, if the queue is full then issue anyway. A branch miss will likely occur.
4374
always @*//(could_issue or head0 or head1 or head2 or head3 or head4 or head5 or head6 or head7)
4375
begin
4376
        iqentry_fcu_issue = 8'h00;
4377
        if (fcu_done) begin
4378
    if (could_issue[head0] && iqentry_fc[head0] && nextqd[head0]) begin
4379
      iqentry_fcu_issue[head0] = `TRUE;
4380
    end
4381
    else if (could_issue[head1] && iqentry_fc[head1] && nextqd[head1])
4382
    begin
4383
      iqentry_fcu_issue[head1] = `TRUE;
4384
    end
4385
    else if (could_issue[head2] && iqentry_fc[head2] && nextqd[head2]
4386
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4387
    ) begin
4388
                iqentry_fcu_issue[head2] = `TRUE;
4389
    end
4390
    else if (could_issue[head3] && iqentry_fc[head3] && nextqd[head3]
4391
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4392
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4393
                ((!iqentry_v[head0])
4394
        &&   (!iqentry_v[head1]))
4395
        )
4396
    ) begin
4397
                iqentry_fcu_issue[head3] = `TRUE;
4398
    end
4399
    else if (could_issue[head4] && iqentry_fc[head4] && nextqd[head4]
4400
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4401
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4402
                ((!iqentry_v[head0])
4403
        &&   (!iqentry_v[head1]))
4404
        )
4405
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4406
                ((!iqentry_v[head0])
4407
        &&   (!iqentry_v[head1])
4408
        &&   (!iqentry_v[head2]))
4409
        )
4410
    ) begin
4411
                iqentry_fcu_issue[head4] = `TRUE;
4412
    end
4413
    else if (could_issue[head5] && iqentry_fc[head5] && nextqd[head5]
4414
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4415
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4416
                ((!iqentry_v[head0])
4417
        &&   (!iqentry_v[head1]))
4418
        )
4419
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4420
                ((!iqentry_v[head0])
4421
        &&   (!iqentry_v[head1])
4422
        &&   (!iqentry_v[head2]))
4423
        )
4424
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4425
                ((!iqentry_v[head0])
4426
        &&   (!iqentry_v[head1])
4427
        &&   (!iqentry_v[head2])
4428
        &&   (!iqentry_v[head3]))
4429
        )
4430
    ) begin
4431
                iqentry_fcu_issue[head5] = `TRUE;
4432
    end
4433
 
4434
`ifdef FULL_ISSUE_LOGIC
4435
    else if (could_issue[head6] && iqentry_fc[head6] && nextqd[head6]
4436
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4437
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4438
                ((!iqentry_v[head0])
4439
        &&   (!iqentry_v[head1]))
4440
        )
4441
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4442
                ((!iqentry_v[head0])
4443
        &&   (!iqentry_v[head1])
4444
        &&   (!iqentry_v[head2]))
4445
        )
4446
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4447
                ((!iqentry_v[head0])
4448
        &&   (!iqentry_v[head1])
4449
        &&   (!iqentry_v[head2])
4450
        &&   (!iqentry_v[head3]))
4451
        )
4452
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4453
                ((!iqentry_v[head0])
4454
        &&   (!iqentry_v[head1])
4455
        &&   (!iqentry_v[head2])
4456
        &&   (!iqentry_v[head3])
4457
        &&   (!iqentry_v[head4]))
4458
        )
4459
    ) begin
4460
                iqentry_fcu_issue[head6] = `TRUE;
4461
    end
4462
 
4463
    else if (could_issue[head7] && iqentry_fc[head7]
4464
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4465
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4466
                ((!iqentry_v[head0])
4467
        &&   (!iqentry_v[head1]))
4468
        )
4469
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4470
                ((!iqentry_v[head0])
4471
        &&   (!iqentry_v[head1])
4472
        &&   (!iqentry_v[head2]))
4473
        )
4474
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4475
                ((!iqentry_v[head0])
4476
        &&   (!iqentry_v[head1])
4477
        &&   (!iqentry_v[head2])
4478
        &&   (!iqentry_v[head3]))
4479
        )
4480
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4481
                ((!iqentry_v[head0])
4482
        &&   (!iqentry_v[head1])
4483
        &&   (!iqentry_v[head2])
4484
        &&   (!iqentry_v[head3])
4485
        &&   (!iqentry_v[head4]))
4486
        )
4487
    && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4488
                ((!iqentry_v[head0])
4489
        &&   (!iqentry_v[head1])
4490
        &&   (!iqentry_v[head2])
4491
        &&   (!iqentry_v[head3])
4492
        &&   (!iqentry_v[head4])
4493
        &&   (!iqentry_v[head5]))
4494
        )
4495
    ) begin
4496
                iqentry_fcu_issue[head7] = `TRUE;
4497
        end
4498
`endif
4499
        end
4500
end
4501
 
4502
//
4503
// determine if the instructions ready to issue can, in fact, issue.
4504
// "ready" means that the instruction has valid operands but has not gone yet
4505
reg [1:0] issue_count, missue_count;
4506
always @*
4507
begin
4508
        issue_count = 0;
4509
         memissue[ head0 ] =    iqentry_memready[ head0 ];              // first in line ... go as soon as ready
4510
         if (memissue[head0])
4511
                issue_count = issue_count + 1;
4512
 
4513
         memissue[ head1 ] =    ~iqentry_stomp[head1] && iqentry_memready[ head1 ]              // addr and data are valid
4514
                                        // ... and no preceding instruction is ready to go
4515
                                        //&& ~iqentry_memready[head0]
4516
                                        // ... and there is no address-overlap with any preceding instruction
4517
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4518
                                                || (iqentry_a1_v[head0] && iqentry_a1[head1] != iqentry_a1[head0]))
4519
                                        // ... if a release, any prior memory ops must be done before this one
4520
                                        && (iqentry_rl[head1] ? iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0] : 1'b1)
4521
                                        // ... if a preivous op has the aquire bit set
4522
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4523
                                        // ... and, if it is a SW, there is no chance of it being undone
4524
                                        && (iqentry_load[head1] ||
4525
                                           !(iqentry_fc[head0]||iqentry_canex[head0]));
4526
         if (memissue[head1])
4527
                issue_count = issue_count + 1;
4528
 
4529
         memissue[ head2 ] =    ~iqentry_stomp[head2] && iqentry_memready[ head2 ]              // addr and data are valid
4530
                                        // ... and no preceding instruction is ready to go
4531
                                        //&& ~iqentry_memready[head0]
4532
                                        //&& ~iqentry_memready[head1] 
4533
                                        // ... and there is no address-overlap with any preceding instruction
4534
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4535
                                                || (iqentry_a1_v[head0] && iqentry_a1[head2] != iqentry_a1[head0]))
4536
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
4537
                                                || (iqentry_a1_v[head1] && iqentry_a1[head2] != iqentry_a1[head1]))
4538
                                        // ... if a release, any prior memory ops must be done before this one
4539
                                        && (iqentry_rl[head2] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4540
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4541
                                                                                         : 1'b1)
4542
                                        // ... if a preivous op has the aquire bit set
4543
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4544
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4545
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4546
                    && (!(iqentry_v[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4547
                                && (!(iqentry_v[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4548
                                        // ... and, if it is a SW, there is no chance of it being undone
4549
                                        && (iqentry_load[head2] ||
4550
                                              !(iqentry_fc[head0]||iqentry_canex[head0])
4551
                                           && !(iqentry_fc[head1]||iqentry_canex[head1]));
4552
         if (memissue[head2])
4553
                issue_count = issue_count + 1;
4554
 
4555
         memissue[ head3 ] =    ~iqentry_stomp[head3] && iqentry_memready[ head3 ]              // addr and data are valid
4556
                                        // ... and no preceding instruction is ready to go
4557
                                        && issue_count < 3
4558
                                        //&& ~iqentry_memready[head0]
4559
                                        //&& ~iqentry_memready[head1] 
4560
                                        //&& ~iqentry_memready[head2] 
4561
                                        // ... and there is no address-overlap with any preceding instruction
4562
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4563
                                                || (iqentry_a1_v[head0] && iqentry_a1[head3] != iqentry_a1[head0]))
4564
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
4565
                                                || (iqentry_a1_v[head1] && iqentry_a1[head3] != iqentry_a1[head1]))
4566
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
4567
                                                || (iqentry_a1_v[head2] && iqentry_a1[head3] != iqentry_a1[head2]))
4568
                                        // ... if a release, any prior memory ops must be done before this one
4569
                                        && (iqentry_rl[head3] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4570
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4571
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4572
                                                                                         : 1'b1)
4573
                                        // ... if a preivous op has the aquire bit set
4574
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4575
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4576
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4577
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4578
                    && (!(iqentry_v[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4579
                    && (!(iqentry_v[head2] && iqentry_memsb[head2]) ||
4580
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4581
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4582
                                )
4583
                                && (!(iqentry_v[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4584
                    && (!(iqentry_v[head2] && iqentry_memdb[head2]) ||
4585
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4586
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4587
                                )
4588
                    // ... and, if it is a SW, there is no chance of it being undone
4589
                                        && (iqentry_load[head3] ||
4590
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4591
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4592
                       && !(iqentry_fc[head2]||iqentry_canex[head2]));
4593
         if (memissue[head3])
4594
                issue_count = issue_count + 1;
4595
 
4596
         memissue[ head4 ] =    ~iqentry_stomp[head4] && iqentry_memready[ head4 ]              // addr and data are valid
4597
                                        // ... and no preceding instruction is ready to go
4598
                                        && issue_count < 3
4599
                                        //&& ~iqentry_memready[head0]
4600
                                        //&& ~iqentry_memready[head1] 
4601
                                        //&& ~iqentry_memready[head2] 
4602
                                        //&& ~iqentry_memready[head3] 
4603
                                        // ... and there is no address-overlap with any preceding instruction
4604
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4605
                                                || (iqentry_a1_v[head0] && iqentry_a1[head4] != iqentry_a1[head0]))
4606
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
4607
                                                || (iqentry_a1_v[head1] && iqentry_a1[head4] != iqentry_a1[head1]))
4608
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
4609
                                                || (iqentry_a1_v[head2] && iqentry_a1[head4] != iqentry_a1[head2]))
4610
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])
4611
                                                || (iqentry_a1_v[head3] && iqentry_a1[head4] != iqentry_a1[head3]))
4612
                                        // ... if a release, any prior memory ops must be done before this one
4613
                                        && (iqentry_rl[head4] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4614
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4615
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4616
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4617
                                                                                         : 1'b1)
4618
                                        // ... if a preivous op has the aquire bit set
4619
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4620
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4621
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4622
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4623
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4624
                    && (!(iqentry_v[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4625
                    && (!(iqentry_v[head2] && iqentry_memsb[head2]) ||
4626
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4627
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4628
                                )
4629
                    && (!(iqentry_v[head3] && iqentry_memsb[head3]) ||
4630
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4631
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4632
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4633
                                )
4634
                                && (!(iqentry_v[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4635
                    && (!(iqentry_v[head2] && iqentry_memdb[head2]) ||
4636
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4637
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4638
                                )
4639
                    && (!(iqentry_v[head3] && iqentry_memdb[head3]) ||
4640
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4641
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4642
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4643
                                )
4644
                                        // ... and, if it is a SW, there is no chance of it being undone
4645
                                        && (iqentry_load[head4] ||
4646
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4647
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4648
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4649
                       && !(iqentry_fc[head3]||iqentry_canex[head3]));
4650
         if (memissue[head4])
4651
                issue_count = issue_count + 1;
4652
 
4653
         memissue[ head5 ] =    ~iqentry_stomp[head5] && iqentry_memready[ head5 ]              // addr and data are valid
4654
                                        // ... and no preceding instruction is ready to go
4655
                                        && issue_count < 3
4656
                                        //&& ~iqentry_memready[head0]
4657
                                        //&& ~iqentry_memready[head1] 
4658
                                        //&& ~iqentry_memready[head2] 
4659
                                        //&& ~iqentry_memready[head3] 
4660
                                        //&& ~iqentry_memready[head4] 
4661
                                        // ... and there is no address-overlap with any preceding instruction
4662
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4663
                                                || (iqentry_a1_v[head0] && iqentry_a1[head5] != iqentry_a1[head0]))
4664
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
4665
                                                || (iqentry_a1_v[head1] && iqentry_a1[head5] != iqentry_a1[head1]))
4666
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
4667
                                                || (iqentry_a1_v[head2] && iqentry_a1[head5] != iqentry_a1[head2]))
4668
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])
4669
                                                || (iqentry_a1_v[head3] && iqentry_a1[head5] != iqentry_a1[head3]))
4670
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4])
4671
                                                || (iqentry_a1_v[head4] && iqentry_a1[head5] != iqentry_a1[head4]))
4672
                                        // ... if a release, any prior memory ops must be done before this one
4673
                                        && (iqentry_rl[head5] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4674
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4675
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4676
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4677
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
4678
                                                                                         : 1'b1)
4679
                                        // ... if a preivous op has the aquire bit set
4680
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4681
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4682
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4683
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4684
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
4685
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4686
                    && (!(iqentry_v[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4687
                    && (!(iqentry_v[head2] && iqentry_memsb[head2]) ||
4688
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4689
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4690
                                )
4691
                    && (!(iqentry_v[head3] && iqentry_memsb[head3]) ||
4692
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4693
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4694
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4695
                                )
4696
                    && (!(iqentry_v[head4] && iqentry_memsb[head4]) ||
4697
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4698
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4699
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4700
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
4701
                                )
4702
                                && (!(iqentry_v[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4703
                    && (!(iqentry_v[head2] && iqentry_memdb[head2]) ||
4704
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4705
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4706
                                )
4707
                    && (!(iqentry_v[head3] && iqentry_memdb[head3]) ||
4708
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4709
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4710
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4711
                                )
4712
                    && (!(iqentry_v[head4] && iqentry_memdb[head4]) ||
4713
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4714
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4715
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4716
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
4717
                                )
4718
                                        // ... and, if it is a SW, there is no chance of it being undone
4719
                                        && (iqentry_load[head5] ||
4720
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4721
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4722
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4723
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
4724
                       && !(iqentry_fc[head4]||iqentry_canex[head4]));
4725
         if (memissue[head5])
4726
                issue_count = issue_count + 1;
4727
 
4728
`ifdef FULL_ISSUE_LOGIC
4729
         memissue[ head6 ] =    ~iqentry_stomp[head6] && iqentry_memready[ head6 ]              // addr and data are valid
4730
                                        // ... and no preceding instruction is ready to go
4731
                                        && issue_count < 3
4732
                                        //&& ~iqentry_memready[head0]
4733
                                        //&& ~iqentry_memready[head1] 
4734
                                        //&& ~iqentry_memready[head2] 
4735
                                        //&& ~iqentry_memready[head3] 
4736
                                        //&& ~iqentry_memready[head4] 
4737
                                        //&& ~iqentry_memready[head5] 
4738
                                        // ... and there is no address-overlap with any preceding instruction
4739
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4740
                                                || (iqentry_a1_v[head0] && iqentry_a1[head6] != iqentry_a1[head0]))
4741
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
4742
                                                || (iqentry_a1_v[head1] && iqentry_a1[head6] != iqentry_a1[head1]))
4743
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
4744
                                                || (iqentry_a1_v[head2] && iqentry_a1[head6] != iqentry_a1[head2]))
4745
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])
4746
                                                || (iqentry_a1_v[head3] && iqentry_a1[head6] != iqentry_a1[head3]))
4747
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4])
4748
                                                || (iqentry_a1_v[head4] && iqentry_a1[head6] != iqentry_a1[head4]))
4749
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5])
4750
                                                || (iqentry_a1_v[head5] && iqentry_a1[head6] != iqentry_a1[head5]))
4751
                                        && (iqentry_rl[head6] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4752
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4753
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4754
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4755
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
4756
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
4757
                                                                                         : 1'b1)
4758
                                        // ... if a preivous op has the aquire bit set
4759
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4760
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4761
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4762
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4763
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
4764
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
4765
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4766
                    && (!(iqentry_v[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4767
                    && (!(iqentry_v[head2] && iqentry_memsb[head2]) ||
4768
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4769
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4770
                                )
4771
                    && (!(iqentry_v[head3] && iqentry_memsb[head3]) ||
4772
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4773
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4774
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4775
                                )
4776
                    && (!(iqentry_v[head4] && iqentry_memsb[head4]) ||
4777
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4778
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4779
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4780
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
4781
                                )
4782
                    && (!(iqentry_v[head5] && iqentry_memsb[head5]) ||
4783
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4784
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4785
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4786
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
4787
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
4788
                                )
4789
                                && (!(iqentry_v[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4790
                    && (!(iqentry_v[head2] && iqentry_memdb[head2]) ||
4791
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4792
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4793
                                )
4794
                    && (!(iqentry_v[head3] && iqentry_memdb[head3]) ||
4795
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4796
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4797
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4798
                                )
4799
                    && (!(iqentry_v[head4] && iqentry_memdb[head4]) ||
4800
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4801
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4802
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4803
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
4804
                                )
4805
                    && (!(iqentry_v[head5] && iqentry_memdb[head5]) ||
4806
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4807
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4808
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4809
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
4810
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
4811
                                )
4812
                                        // ... and, if it is a SW, there is no chance of it being undone
4813
                                        && (iqentry_load[head6] ||
4814
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4815
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4816
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4817
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
4818
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
4819
                       && !(iqentry_fc[head5]||iqentry_canex[head5]));
4820
         if (memissue[head6])
4821
                issue_count = issue_count + 1;
4822
 
4823
         memissue[ head7 ] =    ~iqentry_stomp[head7] && iqentry_memready[ head7 ]              // addr and data are valid
4824
                                        // ... and no preceding instruction is ready to go
4825
                                        && issue_count < 3
4826
                                        //&& ~iqentry_memready[head0]
4827
                                        //&& ~iqentry_memready[head1] 
4828
                                        //&& ~iqentry_memready[head2] 
4829
                                        //&& ~iqentry_memready[head3] 
4830
                                        //&& ~iqentry_memready[head4] 
4831
                                        //&& ~iqentry_memready[head5] 
4832
                                        //&& ~iqentry_memready[head6] 
4833
                                        // ... and there is no address-overlap with any preceding instruction
4834
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4835
                                                || (iqentry_a1_v[head0] && iqentry_a1[head7] != iqentry_a1[head0]))
4836
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
4837
                                                || (iqentry_a1_v[head1] && iqentry_a1[head7] != iqentry_a1[head1]))
4838
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
4839
                                                || (iqentry_a1_v[head2] && iqentry_a1[head7] != iqentry_a1[head2]))
4840
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])
4841
                                                || (iqentry_a1_v[head3] && iqentry_a1[head7] != iqentry_a1[head3]))
4842
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4])
4843
                                                || (iqentry_a1_v[head4] && iqentry_a1[head7] != iqentry_a1[head4]))
4844
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5])
4845
                                                || (iqentry_a1_v[head5] && iqentry_a1[head7] != iqentry_a1[head5]))
4846
                                        && (!iqentry_mem[head6] || (iqentry_agen[head6] & iqentry_out[head6])
4847
                                                || (iqentry_a1_v[head6] && iqentry_a1[head7] != iqentry_a1[head6]))
4848
                                        && (iqentry_rl[head7] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4849
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4850
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4851
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4852
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
4853
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
4854
                                                                                 && (iqentry_done[head6] || !iqentry_v[head6] || !iqentry_mem[head6])
4855
                                                                                         : 1'b1)
4856
                                        // ... if a preivous op has the aquire bit set
4857
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4858
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4859
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4860
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4861
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
4862
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
4863
                                        && !(iqentry_aq[head6] && iqentry_v[head6])
4864
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4865
                    && (!(iqentry_v[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4866
                    && (!(iqentry_v[head2] && iqentry_memsb[head2]) ||
4867
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4868
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4869
                                )
4870
                    && (!(iqentry_v[head3] && iqentry_memsb[head3]) ||
4871
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4872
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4873
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4874
                                )
4875
                    && (!(iqentry_v[head4] && iqentry_memsb[head4]) ||
4876
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4877
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4878
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4879
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
4880
                                )
4881
                    && (!(iqentry_v[head5] && iqentry_memsb[head5]) ||
4882
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4883
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4884
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4885
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
4886
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
4887
                                )
4888
                    && (!(iqentry_v[head6] && iqentry_memsb[head6]) ||
4889
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4890
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4891
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4892
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
4893
                                &&   (iqentry_done[head4] || !iqentry_v[head4])
4894
                                &&   (iqentry_done[head5] || !iqentry_v[head5]))
4895
                                )
4896
                                && (!(iqentry_v[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4897
                    && (!(iqentry_v[head2] && iqentry_memdb[head2]) ||
4898
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4899
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4900
                                )
4901
                    && (!(iqentry_v[head3] && iqentry_memdb[head3]) ||
4902
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4903
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4904
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4905
                                )
4906
                    && (!(iqentry_v[head4] && iqentry_memdb[head4]) ||
4907
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4908
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4909
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4910
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
4911
                                )
4912
                    && (!(iqentry_v[head5] && iqentry_memdb[head5]) ||
4913
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4914
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4915
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4916
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
4917
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
4918
                                )
4919
                    && (!(iqentry_v[head6] && iqentry_memdb[head6]) ||
4920
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4921
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4922
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4923
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
4924
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4])
4925
                                && (!iqentry_mem[head5] || iqentry_done[head5] || !iqentry_v[head5]))
4926
                                )
4927
                                        // ... and, if it is a SW, there is no chance of it being undone
4928
                                        && (iqentry_load[head7] ||
4929
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4930
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4931
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4932
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
4933
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
4934
                       && !(iqentry_fc[head5]||iqentry_canex[head5])
4935
                       && !(iqentry_fc[head6]||iqentry_canex[head6]));
4936
`endif
4937
end
4938
 
4939
// Stomp logic for branch miss.
4940
 
4941
FT64_stomp #(QENTRIES) ustmp1
4942
(
4943
        .branchmiss(branchmiss),
4944
        .branchmiss_thrd(branchmiss_thrd),
4945
        .missid(missid),
4946
        .head0(head0),
4947
        .thrd(iqentry_thrd),
4948
        .iqentry_v(iqentry_v),
4949
        .stomp(iqentry_stomp)
4950
);
4951
 
4952
always @*
4953
begin
4954
        if (iqentry_stomp[0] && IsRet(iqentry_instr[0]))
4955
                stompedOnRets = stompedOnRets + 4'd1;
4956
        if (iqentry_stomp[1] && IsRet(iqentry_instr[1]))
4957
                stompedOnRets = stompedOnRets + 4'd1;
4958
        if (iqentry_stomp[2] && IsRet(iqentry_instr[2]))
4959
                stompedOnRets = stompedOnRets + 4'd1;
4960
        if (iqentry_stomp[3] && IsRet(iqentry_instr[3]))
4961
                stompedOnRets = stompedOnRets + 4'd1;
4962
        if (iqentry_stomp[4] && IsRet(iqentry_instr[4]))
4963
                stompedOnRets = stompedOnRets + 4'd1;
4964
        if (iqentry_stomp[5] && IsRet(iqentry_instr[5]))
4965
                stompedOnRets = stompedOnRets + 4'd1;
4966
        if (iqentry_stomp[6] && IsRet(iqentry_instr[6]))
4967
                stompedOnRets = stompedOnRets + 4'd1;
4968
        if (iqentry_stomp[7] && IsRet(iqentry_instr[7]))
4969
                stompedOnRets = stompedOnRets + 4'd1;
4970
end
4971
 
4972
reg id1_vi, id2_vi;
4973
wire [4:0] id1_ido, id2_ido;
4974
wire id1_vo, id2_vo;
4975
wire id1_clk, id2_clk;
4976
 
4977
BUFGCE uclkb2
4978
(
4979
        .I(clk_i),
4980
        .CE(id1_available),
4981
        .O(id1_clk)
4982
);
4983
 
4984
FT64_idecoder uid1
4985
(
4986
        .clk(id1_clk),
4987
        .idv_i(id1_vi),
4988
        .id_i(id1_id),
4989
        .instr(id1_instr),
4990
        .ven(id1_ven),
4991
        .vl(id1_vl),
4992
        .thrd(id1_thrd),
4993
        .predict_taken(id1_pt),
4994
        .Rt(id1_Rt),
4995
        .bus(id1_bus),
4996
        .id_o(id1_ido),
4997
        .idv_o(id1_vo)
4998
);
4999
 
5000
BUFGCE uclkb3
5001
(
5002
        .I(clk_i),
5003
        .CE(id2_available),
5004
        .O(id2_clk)
5005
);
5006
 
5007
FT64_idecoder uid2
5008
(
5009
        .clk(id2_clk),
5010
        .idv_i(id2_vi),
5011
        .id_i(id2_id),
5012
        .instr(id2_instr),
5013
        .ven(id2_ven),
5014
        .vl(id2_vl),
5015
        .thrd(id2_thrd),
5016
        .predict_taken(id2_pt),
5017
        .Rt(id2_Rt),
5018
        .bus(id2_bus),
5019
        .id_o(id2_ido),
5020
        .idv_o(id2_vo)
5021
);
5022
 
5023
//
5024
// EXECUTE
5025
//
5026
reg [63:0] csr_r;
5027
always @*
5028
    read_csr(alu0_instr[29:18],csr_r,alu0_thrd);
5029
FT64_alu #(.BIG(1'b1),.SUP_VECTOR(SUP_VECTOR)) ualu0 (
5030
  .rst(rst),
5031
  .clk(clk),
5032
  .ld(alu0_ld),
5033
  .abort(1'b0),
5034
  .instr(alu0_instr),
5035
  .a(alu0_argA),
5036
  .b(alu0_argB),
5037
  .c(alu0_argC),
5038
  .pc(alu0_pc),
5039
//    .imm(alu0_argI),
5040
  .tgt(alu0_tgt),
5041
  .ven(alu0_ven),
5042
  .vm(vm[alu0_instr[25:23]]),
5043
  .sbl(sbl),
5044
  .sbu(sbu),
5045
  .csr(csr_r),
5046
  .o(alu0_bus),
5047
  .ob(alu0b_bus),
5048
  .done(alu0_done),
5049
  .idle(alu0_idle),
5050
  .excen(aec[4:0]),
5051
  .exc(alu0_exc),
5052
  .thrd(alu0_thrd),
5053
  .mem(alu0_mem),
5054
  .shift48(alu0_shft48)
5055
);
5056
FT64_alu #(.BIG(1'b0),.SUP_VECTOR(SUP_VECTOR)) ualu1 (
5057
  .rst(rst),
5058
  .clk(clk),
5059
  .ld(alu1_ld),
5060
  .abort(1'b0),
5061
  .instr(alu1_instr),
5062
  .a(alu1_argA),
5063
  .b(alu1_argB),
5064
  .c(alu1_argC),
5065
  .pc(alu1_pc),
5066
  //.imm(alu1_argI),
5067
  .tgt(alu1_tgt),
5068
  .ven(alu1_ven),
5069
  .vm(vm[alu1_instr[25:23]]),
5070
  .sbl(sbl),
5071
  .sbu(sbu),
5072
  .csr(64'd0),
5073
  .o(alu1_bus),
5074
  .ob(alu1b_bus),
5075
  .done(alu1_done),
5076
  .idle(alu1_idle),
5077
  .excen(aec[4:0]),
5078
  .exc(alu1_exc),
5079
  .thrd(1'b0),
5080
  .mem(alu1_mem),
5081
  .shift48(alu1_shft48)
5082
);
5083
fpUnit ufp1
5084
(
5085
  .rst(rst),
5086
  .clk(clk),
5087
  .clk4x(clk4x),
5088
  .ce(1'b1),
5089
  .ir(fpu_instr),
5090
  .ld(fpu_ld),
5091
  .a(fpu_argA),
5092
  .b(fpu_argB),
5093
  .imm(fpu_argI),
5094
  .o(fpu_bus),
5095
  .csr_i(),
5096
  .status(fpu_status),
5097
  .exception(),
5098
  .done(fpu_done)
5099
);
5100
assign fpu_exc = |fpu_status[15:0] ? `FLT_FLT : `FLT_NONE;
5101
 
5102
assign  alu0_v = alu0_dataready,
5103
        alu1_v = alu1_dataready;
5104
assign  alu0_id = alu0_sourceid,
5105
            alu1_id = alu1_sourceid;
5106
assign  fpu_v = fpu_dataready;
5107
assign  fpu_id = fpu_sourceid;
5108
 
5109
`ifdef SUPPORT_SMT
5110
wire [1:0] olm = ol[fcu_thrd];
5111
`else
5112
wire [1:0] olm = ol;
5113
`endif
5114
 
5115
assign  fcu_v = fcu_dataready;
5116
assign  fcu_id = fcu_sourceid;
5117
 
5118
wire [4:0] fcmpo;
5119
wire fnanx;
5120
fp_cmp_unit ufcmp1 (fcu_argA, fcu_argB, fcmpo, fnanx);
5121
 
5122
wire fcu_takb;
5123
 
5124
always @*
5125
begin
5126
    fcu_exc <= `FLT_NONE;
5127
    casez(fcu_instr[`INSTRUCTION_OP])
5128
    `CHK:   begin
5129
                if (fcu_instr[21])
5130
                    fcu_exc <= fcu_argA >= fcu_argB && fcu_argA < fcu_argC ? `FLT_NONE : `FLT_CHK;
5131
            end
5132
    `REX:
5133
        case(olm)
5134
        `OL_USER:   fcu_exc <= `FLT_PRIV;
5135
        default:    ;
5136
        endcase
5137
        endcase
5138
end
5139
 
5140
FT64_EvalBranch ube1
5141
(
5142
        .instr(fcu_instr),
5143
        .a(fcu_argA),
5144
        .b(fcu_argB),
5145
        .c(fcu_argC),
5146
        .takb(fcu_takb)
5147
);
5148
 
5149
FT64_FCU_Calc ufcuc1
5150
(
5151
        .ol(olm),
5152
        .instr(fcu_instr),
5153
        .tvec(tvec[fcu_instr[14:13]]),
5154
        .a(fcu_argA),
5155
        .i(fcu_argI),
5156
        .pc(fcu_pc),
5157
        .im(im),
5158
        .waitctr(waitctr),
5159
        .bus(fcu_bus)
5160
);
5161
 
5162
always @*
5163
begin
5164
case(fcu_instr[`INSTRUCTION_OP])
5165
`R2:    fcu_misspc = fcu_argB;  // RTI (we don't bother fully decoding this as it's the only R2)
5166
`RET:   fcu_misspc = fcu_argB;
5167
`REX:   fcu_misspc = fcu_bus;
5168
`BRK:   fcu_misspc = {tvec[0][31:8], 1'b0, olm, 5'h0};
5169
`JAL:   fcu_misspc = fcu_argA + fcu_argI;
5170
//`CHK: fcu_misspc = fcu_nextpc + fcu_argI;     // Handled as an instruction exception
5171
// Default: branch
5172
default:        fcu_misspc = fcu_takb ? fcu_nextpc + fcu_brdisp : fcu_nextpc;
5173
endcase
5174
fcu_misspc[0] = 1'b0;
5175
end
5176
 
5177
// To avoid false branch mispredicts the branch isn't evaluated until the
5178
// following instruction queues. The address of the next instruction is
5179
// looked at to see if the BTB predicted correctly.
5180
 
5181
wire fcu_brk_miss = (IsBrk(fcu_instr) || IsRTI(fcu_instr)) && fcu_v;
5182
wire fcu_ret_miss = IsRet(fcu_instr) && fcu_v && (fcu_argB != iqentry_pc[idp2(fcu_id)]);
5183
wire fcu_jal_miss = IsJAL(fcu_instr) && fcu_v && fcu_argA + fcu_argI != iqentry_pc[idp2(fcu_id)];
5184
wire fcu_followed = iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]];
5185
always @*
5186
if (fcu_dataready) begin
5187
//      if (fcu_timeout[7])
5188
//              fcu_branchmiss = TRUE;
5189
        // Break and RTI switch register sets, and so are always treated as a branch miss in order to
5190
        // flush the pipeline. Hardware interrupts also stream break instructions so they need to 
5191
        // flushed from the queue so the interrupt is recognized only once.
5192
        // BRK and RTI are handled as excmiss types which are processed during the commit stage.
5193
//      else
5194
        if (fcu_brk_miss)
5195
                fcu_branchmiss = TRUE & ~fcu_clearbm;
5196
    // the following instruction is queued
5197
        else
5198
        if (fcu_followed) begin
5199
`ifdef SUPPORT_SMT
5200
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol[fcu_thrd]) && fcu_v)
5201
`else
5202
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol) && fcu_v)
5203
`endif
5204
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5205
                else if (fcu_ret_miss)
5206
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5207
                else if (IsBranch(fcu_instr) && fcu_v && (((fcu_takb && (~fcu_bt || (fcu_misspc != iqentry_pc[nid]))) ||
5208
                                            (~fcu_takb && ( fcu_bt || (fcu_pc + 32'd4 != iqentry_pc[nid])))) || iqentry_v[nid]))
5209
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5210
                else if (fcu_jal_miss)
5211
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5212
                else if (fcu_instr[`INSTRUCTION_OP] == `CHK && ~fcu_takb && fcu_v)
5213
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5214
                else
5215
                    fcu_branchmiss = FALSE;
5216
        end
5217
        else begin
5218
                // Stuck at the head and can't finish because there's still an uncommitted instruction in the queue.
5219
                // -> cause a branch miss to clear the queue.
5220
                if (iqentry_v[nid] && !IsCall(fcu_instr) && !IsJmp(fcu_instr) && fcu_v)
5221
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5222
                else
5223
                /*
5224
                if (fcu_id==head0 && iqentry_v[idp1(head0)]) begin
5225
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
5226
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
5227
                        fcu_branchmiss = FALSE;
5228
                    else
5229
                                fcu_branchmiss = TRUE;
5230
                end
5231
                else if (fcu_id==head1 && iqentry_v[idp2(head1)]) begin
5232
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
5233
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
5234
                        fcu_branchmiss = FALSE;
5235
                    else
5236
                                fcu_branchmiss = TRUE;
5237
                end
5238
                else*/
5239
                        fcu_branchmiss = FALSE;
5240
        end
5241
end
5242
else
5243
        fcu_branchmiss = FALSE;
5244
/*
5245
assign fcu_branchmiss = fcu_dataready &&
5246
            // and the following instruction is queued
5247
            iqentry_v[idp1(fcu_id)] && iqentry_sn[idp1(fcu_id)]==iqentry_sn[fcu_id[`QBITS]]+5'd1 &&
5248
            ((IsBrk(fcu_instr) || IsRTI(fcu_instr)) ||
5249
            ((fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol)) ||
5250
            (fcu_instr[`INSTRUCTION_OP] == `CHK && ~fcu_bus[0]) ||
5251
                   (IsRTI(fcu_instr) && epc != iqentry_pc[idp1(fcu_id[`QBITS])]) ||
5252
                   // If it's a ret and the return address doesn't match the address of the
5253
                   // next queued instruction then the return prediction was wrong.
5254
                   (/*IsRet(fcu_instr) &&
5255
                     IsRet(fcu_instr) && ((fcu_argB != iqentry_pc[idp1(fcu_id)]) || (iqentry_sn[fcu_id[`QBITS]]+5'd1!=iqentry_sn[idp1(fcu_id)]) || !iqentry_v[idp1(fcu_id)])) ||
5256
                   (IsBrk(fcu_instr) && {tvec[0][31:8], ol, 5'h0} != iqentry_pc[idp1(fcu_id)]) ||
5257
//                         (fcu_instr[`INSTRUCTION_OP] == `BccR && fcu_argC != iqentry_pc[(fcu_id[`QBITS]+3'd1)&7] && fcu_bus[0]) ||
5258
                    (IsBranch(fcu_instr) && ((fcu_bus[0] && (~fcu_bt || (fcu_misspc != iqentry_pc[idp1(fcu_id)]))) ||
5259
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 != iqentry_pc[idp1(fcu_id)]))))) ||
5260
                    (IsJAL(fcu_instr)) && fcu_argA + fcu_argI != iqentry_pc[idp1(fcu_id)]));
5261
*/
5262
 
5263
// Flow control ops don't issue until the next instruction queues.
5264
// The fcu_timeout tracks how long the flow control op has been in the "out" state.
5265
// It should never be that way more than a couple of cycles. Sometimes the fcu_wr pulse got missed
5266
// because the following instruction got stomped on during a branchmiss, hence iqentry_v isn't true.
5267
wire fcu_wr = (fcu_v && iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]]);//      // && iqentry_v[nid]
5268
//                                      && fcu_instr==iqentry_instr[fcu_id[`QBITS]]);// || fcu_timeout==8'h05;
5269
 
5270
FT64_RMW_alu urmwalu0 (rmw_instr, rmw_argA, rmw_argB, rmw_argC, rmw_res);
5271
 
5272
//assign fcu_done = IsWait(fcu_instr) ? ((waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]]) :
5273
//                                      fcu_v && iqentry_v[idp1(fcu_id)] && iqentry_sn[idp1(fcu_id)]==iqentry_sn[fcu_id[`QBITS]]+5'd1;
5274
 
5275
// An exception in a committing instruction takes precedence
5276
/*
5277
Too slow. Needs to be registered
5278
assign  branchmiss = excmiss|fcu_branchmiss,
5279
    misspc = excmiss ? excmisspc : fcu_misspc,
5280
    missid = excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
5281
assign branchmiss_thrd =  excmiss ? excthrd : fcu_thrd;
5282
*/
5283
 
5284
//
5285
// additional DRAM-enqueue logic
5286
 
5287
assign dram_avail = (dram0 == `DRAMSLOT_AVAIL || dram1 == `DRAMSLOT_AVAIL || dram2 == `DRAMSLOT_AVAIL);
5288
 
5289
assign  iqentry_memopsvalid[0] = (iqentry_mem[0] & iqentry_a2_v[0] & iqentry_agen[0]),
5290
    iqentry_memopsvalid[1] = (iqentry_mem[1] & iqentry_a2_v[1] & iqentry_agen[1]),
5291
    iqentry_memopsvalid[2] = (iqentry_mem[2] & iqentry_a2_v[2] & iqentry_agen[2]),
5292
    iqentry_memopsvalid[3] = (iqentry_mem[3] & iqentry_a2_v[3] & iqentry_agen[3]),
5293
    iqentry_memopsvalid[4] = (iqentry_mem[4] & iqentry_a2_v[4] & iqentry_agen[4]),
5294
    iqentry_memopsvalid[5] = (iqentry_mem[5] & iqentry_a2_v[5] & iqentry_agen[5]),
5295
    iqentry_memopsvalid[6] = (iqentry_mem[6] & iqentry_a2_v[6] & iqentry_agen[6]),
5296
    iqentry_memopsvalid[7] = (iqentry_mem[7] & iqentry_a2_v[7] & iqentry_agen[7]);
5297
 
5298
assign  iqentry_memready[0] = (iqentry_v[0] & iqentry_memopsvalid[0] & ~iqentry_memissue[0] & ~iqentry_done[0] & ~iqentry_out[0] & ~iqentry_stomp[0]),
5299
    iqentry_memready[1] = (iqentry_v[1] & iqentry_memopsvalid[1] & ~iqentry_memissue[1] & ~iqentry_done[1] & ~iqentry_out[1] & ~iqentry_stomp[1]),
5300
    iqentry_memready[2] = (iqentry_v[2] & iqentry_memopsvalid[2] & ~iqentry_memissue[2] & ~iqentry_done[2] & ~iqentry_out[2] & ~iqentry_stomp[2]),
5301
    iqentry_memready[3] = (iqentry_v[3] & iqentry_memopsvalid[3] & ~iqentry_memissue[3] & ~iqentry_done[3] & ~iqentry_out[3] & ~iqentry_stomp[3]),
5302
    iqentry_memready[4] = (iqentry_v[4] & iqentry_memopsvalid[4] & ~iqentry_memissue[4] & ~iqentry_done[4] & ~iqentry_out[4] & ~iqentry_stomp[4]),
5303
    iqentry_memready[5] = (iqentry_v[5] & iqentry_memopsvalid[5] & ~iqentry_memissue[5] & ~iqentry_done[5] & ~iqentry_out[5] & ~iqentry_stomp[5]),
5304
    iqentry_memready[6] = (iqentry_v[6] & iqentry_memopsvalid[6] & ~iqentry_memissue[6] & ~iqentry_done[6] & ~iqentry_out[6] & ~iqentry_stomp[6]),
5305
    iqentry_memready[7] = (iqentry_v[7] & iqentry_memopsvalid[7] & ~iqentry_memissue[7] & ~iqentry_done[7] & ~iqentry_out[7] & ~iqentry_stomp[7]);
5306
 
5307
assign outstanding_stores = (dram0 && IsStore(dram0_instr)) ||
5308
                            (dram1 && IsStore(dram1_instr)) ||
5309
                            (dram2 && IsStore(dram2_instr));
5310
 
5311
//
5312
// additional COMMIT logic
5313
//
5314
always @*
5315
begin
5316
    commit0_v <= ({iqentry_v[head0], iqentry_cmt[head0]} == 2'b11 && ~|panic);
5317
    commit0_id <= {iqentry_mem[head0], head0};  // if a memory op, it has a DRAM-bus id
5318
    commit0_tgt <= iqentry_tgt[head0];
5319
    commit0_we  <= iqentry_we[head0];
5320
    commit0_bus <= iqentry_res[head0];
5321
    commit1_v <= ({iqentry_v[head0], iqentry_cmt[head0]} != 2'b10
5322
               && {iqentry_v[head1], iqentry_cmt[head1]} == 2'b11
5323
               && ~|panic);
5324
    commit1_id <= {iqentry_mem[head1], head1};
5325
    commit1_tgt <= iqentry_tgt[head1];
5326
    commit1_we  <= iqentry_we[head1];
5327
    commit1_bus <= iqentry_res[head1];
5328
end
5329
 
5330
assign int_commit = (commit0_v && IsIrq(iqentry_instr[head0])) ||
5331
                    (commit0_v && commit1_v && IsIrq(iqentry_instr[head1]));
5332
 
5333
// Detect if a given register will become valid during the current cycle.
5334
// We want a signal that is active during the current clock cycle for the read
5335
// through register file, which trims a cycle off register access for every
5336
// instruction. But two different kinds of assignment statements can't be
5337
// placed under the same always block, it's a bad practice and may not work.
5338
// So a signal is created here with it's own always block.
5339
reg [AREGS-1:0] regIsValid;
5340
always @*
5341
begin
5342
        for (n = 1; n < AREGS; n = n + 1)
5343
        begin
5344
                regIsValid[n] = rf_v[n];
5345
                if (branchmiss)
5346
               if (~livetarget[n]) begin
5347
                        if (branchmiss_thrd) begin
5348
                                if (n >= 128)
5349
                                        regIsValid[n] = `VAL;
5350
                        end
5351
                        else begin
5352
                                if (n < 128)
5353
                                        regIsValid[n] = `VAL;
5354
                        end
5355
               end
5356
                if (commit0_v && n=={commit0_tgt[7:0]})
5357
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit0_tgt[7:0]} ] == commit0_id
5358
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit0_id[`QBITS] ]));
5359
                if (commit1_v && n=={commit1_tgt[7:0]})
5360
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit1_tgt[7:0]} ] == commit1_id
5361
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit1_id[`QBITS] ]));
5362
        end
5363
        regIsValid[0] = `VAL;
5364
end
5365
 
5366
// Wait until the cycle after Ra becomes valid to give time to read
5367
// the vector element from the register file.
5368
reg rf_vra0, rf_vra1;
5369
/*always @(posedge clk)
5370
    rf_vra0 <= regIsValid[Ra0s];
5371
always @(posedge clk)
5372
    rf_vra1 <= regIsValid[Ra1s];
5373
*/
5374
// Check how many instructions can be queued. This might be fewer than the
5375
// number ready to queue from the fetch stage if queue slots aren't
5376
// available or if there are no more physical registers left for remapping.
5377
// The fetch stage needs to know how many instructions will queue so this
5378
// logic is placed here.
5379
// NOPs are filtered out and do not enter the instruction queue. The core
5380
// will stream NOPs on a cache miss and they would mess up the queue order
5381
// if there are immediate prefixes in the queue.
5382
// For the VEX instruction, the instruction can't queue until register Ra
5383
// is valid, because register Ra is used to specify the vector element to
5384
// read.
5385
wire q2open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV;
5386
wire q3open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV && iqentry_v[idp1(tail1)]==`INV;
5387
always @*
5388
begin
5389
        canq1 <= FALSE;
5390
        canq2 <= FALSE;
5391
        queued1 <= FALSE;
5392
        queued2 <= FALSE;
5393
        queuedNop <= FALSE;
5394
        vqueued2 <= FALSE;
5395
        if (!branchmiss) begin
5396
      // Two available
5397
      if (fetchbuf1_v & fetchbuf0_v) begin
5398
          // Is there a pair of NOPs ? (cache miss)
5399
          if ((fetchbuf0_instr[`INSTRUCTION_OP]==`NOP) && (fetchbuf1_instr[`INSTRUCTION_OP]==`NOP))
5400
              queuedNop <= TRUE;
5401
          else begin
5402
              // If it's a predicted branch queue only the first instruction, the second
5403
              // instruction will be stomped on.
5404
              if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
5405
                  if (iqentry_v[tail0]==`INV) begin
5406
                      canq1 <= TRUE;
5407
                      queued1 <= TRUE;
5408
                  end
5409
              end
5410
              // This is where a single NOP is allowed through to simplify the code. A
5411
              // single NOP can't be a cache miss. Otherwise it would be necessary to queue
5412
              // fetchbuf1 on tail0 it would add a nightmare to the enqueue code.
5413
              // Not a branch and there are two instructions fetched, see whether or not
5414
              // both instructions can be queued.
5415
              else begin
5416
                  if (iqentry_v[tail0]==`INV) begin
5417
                      canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5418
                      queued1 <= (
5419
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5420
                      if (iqentry_v[tail1]==`INV) begin
5421
                          canq2 <= ((!IsVex(fetchbuf1_instr) || rf_vra1)) || !SUP_VECTOR;
5422
                          queued2 <= (
5423
                                (!IsVector(fetchbuf1_instr) && (!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5424
                          vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5425
                      end
5426
                  end
5427
                  // If an irq is active during a vector instruction fetch, claim the vector instruction
5428
                  // is finished queueing even though it may not be. It'll pick up where it left off after
5429
                  // the exception is processed.
5430
                  if (hirq) begin
5431
                        if (IsVector(fetchbuf0_instr) && IsVector(fetchbuf1_instr) && vechain) begin
5432
                                queued1 <= TRUE;
5433
                                queued2 <= TRUE;
5434
                        end
5435
                        else if (IsVector(fetchbuf0_instr)) begin
5436
                                queued1 <= TRUE;
5437
                                if (vqe0 < vl-2)
5438
                                        queued2 <= TRUE;
5439
                                else
5440
                                        queued2 <= iqentry_v[tail1]==`INV;
5441
                        end
5442
                  end
5443
              end
5444
          end
5445
      end
5446
      // One available
5447
      else if (fetchbuf0_v) begin
5448
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
5449
              if (iqentry_v[tail0]==`INV) begin
5450
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5451
                  queued1 <=
5452
                        (((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5453
              end
5454
              if (iqentry_v[tail1]==`INV) begin
5455
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
5456
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5457
                end
5458
                if (hirq) begin
5459
                if (IsVector(fetchbuf0_instr)) begin
5460
                        queued1 <= TRUE;
5461
                        if (vqe0 < vl-2)
5462
                                queued2 <= iqentry_v[tail1]==`INV;
5463
                end
5464
                end
5465
          end
5466
          else
5467
              queuedNop <= TRUE;
5468
      end
5469
      else if (fetchbuf1_v) begin
5470
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
5471
              if (iqentry_v[tail0]==`INV) begin
5472
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
5473
                  queued1 <= (
5474
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
5475
              end
5476
              if (iqentry_v[tail1]==`INV) begin
5477
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
5478
                  vqueued2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2;
5479
                end
5480
                if (hirq) begin
5481
                if (IsVector(fetchbuf1_instr)) begin
5482
                        queued1 <= TRUE;
5483
                        if (vqe1 < vl-2)
5484
                                queued2 <= iqentry_v[tail1]==`INV;
5485
                end
5486
                end
5487
          end
5488
          else
5489
              queuedNop <= TRUE;
5490
      end
5491
      //else no instructions available to queue
5492
    end
5493
    else begin
5494
      // One available
5495
      if (fetchbuf0_v && fetchbuf0_thrd != branchmiss_thrd) begin
5496
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
5497
              if (iqentry_v[tail0]==`INV) begin
5498
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5499
                  queued1 <= (
5500
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5501
              end
5502
              if (iqentry_v[tail1]==`INV) begin
5503
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
5504
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5505
                end
5506
          end
5507
          else
5508
              queuedNop <= TRUE;
5509
      end
5510
      else if (fetchbuf1_v && fetchbuf1_thrd != branchmiss_thrd) begin
5511
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
5512
              if (iqentry_v[tail0]==`INV) begin
5513
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
5514
                  queued1 <= (
5515
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
5516
              end
5517
              if (iqentry_v[tail1]==`INV) begin
5518
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
5519
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5520
                end
5521
          end
5522
          else
5523
              queuedNop <= TRUE;
5524
      end
5525
        else
5526
                queuedNop <= TRUE;
5527
    end
5528
end
5529
 
5530
//
5531
// Branchmiss seems to be sticky sometimes during simulation. For instance branch miss
5532
// and cache miss at same time. The branchmiss should clear before the core continues
5533
// so the positive edge is detected to avoid incrementing the sequnce number too many
5534
// times.
5535
wire pebm;
5536
edge_det uedbm (.rst(rst), .clk(clk), .ce(1'b1), .i(branchmiss), .pe(pebm), .ne(), .ee() );
5537
 
5538
reg [5:0] ld_time;
5539
reg [63:0] wc_time_dat;
5540
reg [63:0] wc_times;
5541
always @(posedge tm_clk_i)
5542
begin
5543
        if (|ld_time)
5544
                wc_time <= wc_time_dat;
5545
        else begin
5546
                wc_time[31:0] <= wc_time[31:0] + 32'd1;
5547
                if (wc_time[31:0] >= TM_CLKFREQ-1) begin
5548
                        wc_time[31:0] <= 32'd0;
5549
                        wc_time[63:32] <= wc_time[63:32] + 32'd1;
5550
                end
5551
        end
5552
end
5553
 
5554
 
5555
// Monster clock domain.
5556
// Like to move some of this to clocking under different always blocks in order
5557
// to help out the toolset's synthesis, but it ain't gonna be easy.
5558
// Simulation doesn't like it if things are under separate always blocks.
5559
// Synthesis doesn't like it if things are under the same always block.
5560
 
5561
always @(posedge clk)
5562
begin
5563
        branchmiss <= excmiss|fcu_branchmiss;
5564
    misspc <= excmiss ? excmisspc : fcu_misspc;
5565
    missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
5566
        branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
5567
end
5568
 
5569
always @(posedge clk)
5570
if (rst) begin
5571
`ifdef SUPPORT_SMT
5572
     mstatus[0] <= 64'h0007;     // select register set #0 for thread 0
5573
     mstatus[1] <= 64'h8007;    // select register set #2 for thread 1
5574
`else
5575
     mstatus <= 64'h0007;       // select register set #0 for thread 0
5576
`endif
5577
    for (n = 0; n < QENTRIES; n = n + 1) begin
5578
         iqentry_v[n] <= `INV;
5579
         iqentry_iv[n] <= `INV;
5580
         iqentry_is[n] <= 3'b00;
5581
         iqentry_done[n] <= FALSE;
5582
         iqentry_cmt[n] <= FALSE;
5583
         iqentry_out[n] <= FALSE;
5584
         iqentry_agen[n] <= FALSE;
5585
         iqentry_sn[n] <= 32'd0;
5586
         iqentry_pt[n] <= FALSE;
5587
         iqentry_bt[n] <= FALSE;
5588
         iqentry_br[n] <= FALSE;
5589
         iqentry_aq[n] <= FALSE;
5590
         iqentry_rl[n] <= FALSE;
5591
         iqentry_alu0[n] <= FALSE;
5592
         iqentry_alu[n] <= FALSE;
5593
         iqentry_alu0_issue[n] <= FALSE;
5594
         iqentry_alu1_issue[n] <= FALSE;
5595
         iqentry_fpu[n] <= FALSE;
5596
         iqentry_fpu_islot[n] <= 2'b00;
5597
         iqentry_fpu_issue[n] <= FALSE;
5598
         iqentry_fsync[n] <= FALSE;
5599
         iqentry_fc[n] <= FALSE;
5600
         iqentry_fcu_issue[n] <= FALSE;
5601
         iqentry_jmp[n] <= FALSE;
5602
         iqentry_ldcmp[n] <= FALSE;
5603
         iqentry_load[n] <= FALSE;
5604
         iqentry_rtop[n] <= FALSE;
5605
         iqentry_sei[n] <= FALSE;
5606
         iqentry_shft48[n] <= FALSE;
5607
         iqentry_sync[n] <= FALSE;
5608
         iqentry_ven[n] <= 6'd0;
5609
         iqentry_vl[n] <= 8'd0;
5610
         iqentry_we[n] <= 8'h00;
5611
         iqentry_rfw[n] <= FALSE;
5612
         iqentry_rmw[n] <= FALSE;
5613
         iqentry_pc[n] <= RSTPC;
5614
         iqentry_instr[n] <= `NOP_INSN;
5615
         iqentry_insln[n] <= 4'd4;
5616
         iqentry_preload[n] <= FALSE;
5617
         iqentry_mem[n] <= FALSE;
5618
         iqentry_memndx[n] <= FALSE;
5619
         iqentry_memissue[n] <= FALSE;
5620
         iqentry_mem_islot[n] <= 3'd0;
5621
         iqentry_tgt[n] <= 6'd0;
5622
         iqentry_imm[n] <= 1'b0;
5623
         iqentry_a0[n] <= 64'd0;
5624
         iqentry_a1[n] <= 64'd0;
5625
         iqentry_a2[n] <= 64'd0;
5626
         iqentry_a3[n] <= 64'd0;
5627
         iqentry_a1_v[n] <= `INV;
5628
         iqentry_a2_v[n] <= `INV;
5629
         iqentry_a3_v[n] <= `INV;
5630
         iqentry_a1_s[n] <= 5'd0;
5631
         iqentry_a2_s[n] <= 5'd0;
5632
         iqentry_a3_s[n] <= 5'd0;
5633
         iqentry_canex[n] <= FALSE;
5634
    end
5635
     dram0 <= `DRAMSLOT_AVAIL;
5636
     dram1 <= `DRAMSLOT_AVAIL;
5637
     dram2 <= `DRAMSLOT_AVAIL;
5638
     dram0_instr <= `NOP_INSN;
5639
     dram1_instr <= `NOP_INSN;
5640
     dram2_instr <= `NOP_INSN;
5641
     dram0_addr <= 32'h0;
5642
     dram1_addr <= 32'h0;
5643
     dram2_addr <= 32'h0;
5644
     L1_adr <= RSTPC;
5645
     invic <= FALSE;
5646
     tail0 <= 3'd0;
5647
     tail1 <= 3'd1;
5648
     head0 <= 0;
5649
     head1 <= 1;
5650
     head2 <= 2;
5651
     head3 <= 3;
5652
     head4 <= 4;
5653
     head5 <= 5;
5654
     head6 <= 6;
5655
     head7 <= 7;
5656
     panic = `PANIC_NONE;
5657
     id1_available <= `ID1_AVAIL;
5658
     id2_available <= `ID2_AVAIL;
5659
     alu0_available <= `ALU0_AVAIL;
5660
     alu0_dataready <= 0;
5661
     alu1_available <= `ALU1_AVAIL;
5662
     alu1_dataready <= 0;
5663
     alu0_sourceid <= 5'd0;
5664
     alu1_sourceid <= 5'd0;
5665
`ifdef SIM
5666
                alu0_pc <= RSTPC;
5667
                alu0_instr <= `NOP_INSN;
5668
                alu0_argA <= 64'h0;
5669
                alu0_argB <= 64'h0;
5670
                alu0_argC <= 64'h0;
5671
                alu0_argI <= 64'h0;
5672
                alu0_bt <= 1'b0;
5673
                alu0_mem <= 1'b0;
5674
                alu0_shft48 <= 1'b0;
5675
                alu0_thrd <= 1'b0;
5676
                alu0_tgt <= 6'h00;
5677
                alu0_ven <= 6'd0;
5678
                alu1_pc <= RSTPC;
5679
                alu1_instr <= `NOP_INSN;
5680
                alu1_argA <= 64'h0;
5681
                alu1_argB <= 64'h0;
5682
                alu1_argC <= 64'h0;
5683
                alu1_argI <= 64'h0;
5684
                alu1_bt <= 1'b0;
5685
                alu1_mem <= 1'b0;
5686
                alu1_shft48 <= 1'b0;
5687
                alu1_thrd <= 1'b0;
5688
                alu1_tgt <= 6'h00;
5689
                alu1_ven <= 6'd0;
5690
`endif
5691
     fpu1_available <= `FPU1_AVAIL;
5692
     fcu_dataready <= 0;
5693
     fcu_instr <= `NOP_INSN;
5694
     fcu_retadr_v <= 0;
5695
     dramA_v <= 0;
5696
     dramB_v <= 0;
5697
     dramC_v <= 0;
5698
     I <= 0;
5699
     icstate <= IDLE;
5700
     bstate <= BIDLE;
5701
     tick <= 64'd0;
5702
     bte_o <= 2'b00;
5703
     cti_o <= 3'b000;
5704
     cyc_o <= `LOW;
5705
     stb_o <= `LOW;
5706
     we_o <= `LOW;
5707
     sel_o <= 8'h00;
5708
     sr_o <= `LOW;
5709
     cr_o <= `LOW;
5710
     adr_o <= RSTPC;
5711
     icl_o <= `LOW;             // instruction cache load
5712
     cr0 <= 64'd0;
5713
     cr0[13:8] <= 6'd0;         // select register set #0
5714
     cr0[30] <= TRUE;           // enable data caching
5715
     cr0[32] <= TRUE;           // enable branch predictor
5716
     cr0[16] <= 1'b0;           // disable SMT
5717
     cr0[17] <= 1'b0;           // sequence number reset = 1
5718
     pcr <= 32'd0;
5719
     pcr2 <= 64'd0;
5720
    for (n = 0; n < PREGS; n = n + 1)
5721
         rf_v[n] <= `VAL;
5722
     tgtq <= FALSE;
5723
     fp_rm <= 3'd0;                     // round nearest even - default rounding mode
5724
     waitctr <= 64'd0;
5725
    for (n = 0; n < 16; n = n + 1)
5726
         badaddr[n] <= 64'd0;
5727
     sbl <= 32'h0;
5728
     sbu <= 32'hFFFFFFFF;
5729
    // Vector
5730
     vqe0 <= 6'd0;
5731
     vqet0 <= 6'd0;
5732
     vqe1 <= 6'd0;
5733
     vqet1 <= 6'd0;
5734
     vl <= 7'd62;
5735
    for (n = 0; n < 8; n = n + 1)
5736
         vm[n] <= 64'h7FFFFFFFFFFFFFFF;
5737
     nop_fetchbuf <= 4'h0;
5738
     seq_num <= 5'd0;
5739
     seq_num1 <= 5'd0;
5740
     fcu_done <= `TRUE;
5741
     sema <= 64'h0;
5742
     tvec[0] <= RSTPC;
5743
end
5744
else begin
5745
        // The following signals only pulse
5746
 
5747
        // Instruction decode output should only pulse once for a queue entry. We
5748
        // want the decode to be invalidated after a clock cycle so that it isn't
5749
        // inadvertently used to update the queue at a later point.
5750
        id1_vi <= `INV;
5751
        id2_vi <= `INV;
5752
        ld_time <= {ld_time[4:0],1'b0};
5753
        wc_times <= wc_time;
5754
     rf_vra0 <= regIsValid[Ra0s];
5755
     rf_vra1 <= regIsValid[Ra1s];
5756
    if (vqe0 >= vl) begin
5757
         vqe0 <= 6'd0;
5758
         vqet0 <= 6'h0;
5759
    end
5760
    if (vqe1 >= vl) begin
5761
         vqe1 <= 6'd0;
5762
         vqet1 <= 6'h0;
5763
    end
5764
    // Turn off vector chaining indicator when chained instructions are done.
5765
    if ((vqe0 >= vl || vqe0==6'd0) && (vqe1 >= vl || vqe1==6'd0))
5766
`ifdef SUPPORT_SMT
5767
        mstatus[0][32] <= 1'b0;
5768
`else
5769
        mstatus[32] <= 1'b0;
5770
`endif
5771
 
5772
     nop_fetchbuf <= 4'h0;
5773
     excmiss <= FALSE;
5774
     invic <= FALSE;
5775
     tick <= tick + 64'd1;
5776
     alu0_ld <= FALSE;
5777
     alu1_ld <= FALSE;
5778
     fpu_ld <= FALSE;
5779
     fcu_ld <= FALSE;
5780
     fcu_retadr_v <= FALSE;
5781
     dramA_v <= FALSE;
5782
     dramB_v <= FALSE;
5783
     dramC_v <= FALSE;
5784
     cr0[17] <= 1'b0;
5785
    if (waitctr != 64'd0)
5786
         waitctr <= waitctr - 64'd1;
5787
 
5788
 
5789
    if (IsFlowCtrl(iqentry_instr[fcu_id[`QBITS]]) && iqentry_v[fcu_id[`QBITS]] && !iqentry_done[fcu_id[`QBITS]] && iqentry_out[fcu_id[`QBITS]])
5790
        fcu_timeout <= fcu_timeout + 8'd1;
5791
 
5792
        if (branchmiss) begin
5793
        for (n = 1; n < PREGS; n = n + 1)
5794
           if (~livetarget[n]) begin
5795
                        if (branchmiss_thrd) begin
5796
                                if (n >= 128)
5797
                                rf_v[n] <= `VAL;
5798
                        end
5799
                        else begin
5800
                                if (n < 128)
5801
                                rf_v[n] <= `VAL;
5802
                end
5803
           end
5804
 
5805
            if (|iqentry_0_latestID)     if (iqentry_thrd[0]==branchmiss_thrd) rf_source[ {iqentry_tgt[0][7:0]} ] <= { 1'b0, iqentry_mem[0], 3'd0 };
5806
        if (|iqentry_1_latestID)     if (iqentry_thrd[1]==branchmiss_thrd) rf_source[ {iqentry_tgt[1][7:0]} ] <= { 1'b0, iqentry_mem[1], 3'd1 };
5807
        if (|iqentry_2_latestID)     if (iqentry_thrd[2]==branchmiss_thrd) rf_source[ {iqentry_tgt[2][7:0]} ] <= { 1'b0, iqentry_mem[2], 3'd2 };
5808
        if (|iqentry_3_latestID)     if (iqentry_thrd[3]==branchmiss_thrd) rf_source[ {iqentry_tgt[3][7:0]} ] <= { 1'b0, iqentry_mem[3], 3'd3 };
5809
        if (|iqentry_4_latestID)     if (iqentry_thrd[4]==branchmiss_thrd) rf_source[ {iqentry_tgt[4][7:0]} ] <= { 1'b0, iqentry_mem[4], 3'd4 };
5810
        if (|iqentry_5_latestID)     if (iqentry_thrd[5]==branchmiss_thrd) rf_source[ {iqentry_tgt[5][7:0]} ] <= { 1'b0, iqentry_mem[5], 3'd5 };
5811
        if (|iqentry_6_latestID)     if (iqentry_thrd[6]==branchmiss_thrd) rf_source[ {iqentry_tgt[6][7:0]} ] <= { 1'b0, iqentry_mem[6], 3'd6 };
5812
        if (|iqentry_7_latestID)     if (iqentry_thrd[7]==branchmiss_thrd) rf_source[ {iqentry_tgt[7][7:0]} ] <= { 1'b0, iqentry_mem[7], 3'd7 };
5813
 
5814
    end
5815
 
5816
    // The source for the register file data might have changed since it was
5817
    // placed on the commit bus. So it's needed to check that the source is
5818
    // still as expected to validate the register.
5819
        if (commit0_v) begin
5820
        if (!rf_v[ {commit0_tgt[7:0]} ])
5821
//             rf_v[ {commit0_tgt[7:0]} ] <= rf_source[ commit0_tgt[7:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]);
5822
             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] ]);
5823
        if (commit0_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit0_tgt, commit0_bus, regIsValid[commit0_tgt[5:0]],
5824
        rf_source[ {commit0_tgt[7:0]} ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]));
5825
        if (commit0_tgt[5:0]==6'd30 && commit0_bus==64'd0)
5826
                $display("FP <= 0");
5827
    end
5828
    if (commit1_v) begin
5829
        if (!rf_v[ {commit1_tgt[7:0]} ]) begin
5830
                if ({commit1_tgt[7:0]}=={commit0_tgt[7:0]})
5831
                         rf_v[ {commit1_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}];
5832
                        /*
5833
                                (rf_source[ commit0_tgt[4:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ])) ||
5834
                                (rf_source[ commit1_tgt[4:0] ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
5835
                        */
5836
                else
5837
                 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] ]);
5838
        end
5839
        if (commit1_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit1_tgt, commit1_bus, regIsValid[commit1_tgt[5:0]],
5840
        rf_source[ {commit1_tgt[7:0]} ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
5841
        if (commit1_tgt[5:0]==6'd30 && commit1_bus==64'd0)
5842
                $display("FP <= 0");
5843
    end
5844
     rf_v[0] <= 1;
5845
 
5846
    //
5847
    // ENQUEUE
5848
    //
5849
    // place up to two instructions from the fetch buffer into slots in the IQ.
5850
    //   note: they are placed in-order, and they are expected to be executed
5851
    // 0, 1, or 2 of the fetch buffers may have valid data
5852
    // 0, 1, or 2 slots in the instruction queue may be available.
5853
    // if we notice that one of the instructions in the fetch buffer is a predicted branch,
5854
    // (set branchback/backpc and delete any instructions after it in fetchbuf)
5855
    //
5856
 
5857
        // enqueue fetchbuf0 and fetchbuf1, but only if there is room, 
5858
        // and ignore fetchbuf1 if fetchbuf0 has a backwards branch in it.
5859
        //
5860
        // also, do some instruction-decode ... set the operand_valid bits in the IQ
5861
        // appropriately so that the DATAINCOMING stage does not have to look at the opcode
5862
        //
5863
        if (!branchmiss)        // don't bother doing anything if there's been a branch miss
5864
 
5865
                case ({fetchbuf0_v, fetchbuf1_v})
5866
 
5867
            2'b00: ; // do nothing
5868
 
5869
            2'b01:
5870
                    if (canq1) begin
5871
                    if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
5872
                         vqe1 <= vqe1 + 4'd1;
5873
                        if (IsVCmprss(fetchbuf1_instr)) begin
5874
                            if (vm[fetchbuf1_instr[25:23]][vqe1])
5875
                                 vqet1 <= vqet1 + 4'd1;
5876
                        end
5877
                        else
5878
                             vqet1 <= vqet1 + 4'd1;
5879
                        if (vqe1 >= vl-2)
5880
                                 nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
5881
                            enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, vqe1);
5882
                            if (fetchbuf1_thrd)
5883
                                seq_num1 <= seq_num1 + 5'd1;
5884
                            else
5885
                                seq_num <= seq_num + 5'd1;
5886
                             tgtq <= FALSE;
5887
                            if (fetchbuf1_rfw) begin
5888
                                 rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail0 }; // top bit indicates ALU/MEM bus
5889
                                 rf_v [Rt1s] <= `INV;
5890
                            end
5891
                        if (canq2 && vqe1 < vl-2) begin
5892
                                 vqe1 <= vqe1 + 4'd2;
5893
                                if (IsVCmprss(fetchbuf1_instr)) begin
5894
                                    if (vm[fetchbuf1_instr[25:23]][vqe1+6'd1])
5895
                                         vqet1 <= vqet1 + 4'd2;
5896
                                end
5897
                                else
5898
                                     vqet1 <= vqet1 + 4'd2;
5899
                                    enque1(tail1, fetchbuf1_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe1 + 6'd1);
5900
                                    if (fetchbuf1_thrd)
5901
                                        seq_num1 <= seq_num1 + 5'd2;
5902
                                    else
5903
                                        seq_num <= seq_num + 5'd2;
5904
                                     tgtq <= FALSE;
5905
                                    if (fetchbuf1_rfw) begin
5906
                                         rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail1 }; // top bit indicates ALU/MEM bus
5907
                                         rf_v [Rt1s] <= `INV;
5908
                                    end
5909
                        end
5910
                    end
5911
                    else begin
5912
                            enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, 6'd0);
5913
                            if (fetchbuf1_thrd)
5914
                                seq_num1 <= seq_num1 + 5'd1;
5915
                            else
5916
                                seq_num <= seq_num + 5'd1;
5917
                             tgtq <= FALSE;
5918
                            if (fetchbuf1_rfw) begin
5919
                                 rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail0 }; // top bit indicates ALU/MEM bus
5920
                                 rf_v [Rt1s] <= `INV;
5921
                            end
5922
                        end
5923
                    end
5924
 
5925
            2'b10:
5926
                if (canq1) begin
5927
//                  $display("queued1: %d", queued1);
5928
//                      if (!IsBranch(fetchbuf0_instr))         panic <= `PANIC_FETCHBUFBEQ;
5929
//                      if (!predict_taken0)    panic <= `PANIC_FETCHBUFBEQ;
5930
                        //
5931
                        // this should only happen when the first instruction is a BEQ-backwards and the IQ
5932
                        // happened to be full on the previous cycle (thus we deleted fetchbuf1 but did not
5933
                        // enqueue fetchbuf0) ... probably no need to check for LW -- sanity check, just in case
5934
                        //
5935
                    if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
5936
                         vqe0 <= vqe0 + 4'd1;
5937
                        if (IsVCmprss(fetchbuf0_instr)) begin
5938
                            if (vm[fetchbuf0_instr[25:23]][vqe0])
5939
                                 vqet0 <= vqet0 + 4'd1;
5940
                        end
5941
                        else
5942
                             vqet0 <= vqet0 + 4'd1;
5943
                        if (vqe0 >= vl-2)
5944
                                 nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
5945
                                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
5946
                                if (fetchbuf0_thrd)
5947
                                        seq_num1 <= seq_num1 + 5'd1;
5948
                                else
5949
                                        seq_num <= seq_num + 5'd1;
5950
                             tgtq <= FALSE;
5951
                                if (fetchbuf0_rfw) begin
5952
                                 rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
5953
                                 rf_v[Rt0s] <= `INV;
5954
                            end
5955
                        if (canq2) begin
5956
                                    if (vqe0 < vl-2) begin
5957
                                         vqe0 <= vqe0 + 4'd2;
5958
                                        if (IsVCmprss(fetchbuf0_instr)) begin
5959
                                            if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
5960
                                                 vqet0 <= vqet0 + 4'd2;
5961
                                        end
5962
                                        else
5963
                                             vqet0 <= vqet0 + 4'd2;
5964
                                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num+5'd1, vqe0 + 6'd1);
5965
                                                if (fetchbuf0_thrd)
5966
                                                        seq_num1 <= seq_num1 + 5'd2;
5967
                                                else
5968
                                                        seq_num <= seq_num + 5'd2;
5969
                                             tgtq <= FALSE;
5970
                                                if (fetchbuf0_rfw) begin
5971
                                                 rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };    // top bit indicates ALU/MEM bus
5972
                                                 rf_v[Rt0s] <= `INV;
5973
                                            end
5974
                                    end
5975
                        end
5976
                    end
5977
                    else begin
5978
                                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, 6'd0);
5979
                                if (fetchbuf0_thrd)
5980
                                        seq_num1 <= seq_num1 + 5'd1;
5981
                                else
5982
                                        seq_num <= seq_num + 5'd1;
5983
                             tgtq <= FALSE;
5984
                                if (fetchbuf0_rfw) begin
5985
                                 rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
5986
                                 rf_v[Rt0s] <= `INV;
5987
                            end
5988
                        end
5989
                    end
5990
 
5991
            2'b11:
5992
                    if (canq1) begin
5993
                                //
5994
                                // if the first instruction is a predicted branch, enqueue it & stomp on all following instructions
5995
                                // but only if the following instruction is in the same thread. Otherwise we want to queue two.
5996
                                //
5997
                                if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
5998
                             tgtq <= FALSE;
5999
                            enque0(tail0,fetchbuf0_thrd ? seq_num1 : seq_num,6'd0);
6000
                                if (fetchbuf0_thrd)
6001
                                        seq_num1 <= seq_num1 + 5'd1;
6002
                                else
6003
                                        seq_num <= seq_num + 5'd1;
6004
                                        if (fetchbuf0_rfw) begin
6005
                                             rf_source[ Rt0s ] <= {1'b0,fetchbuf0_memld, tail0};
6006
                                             rf_v [ Rt0s ] <= `INV;
6007
                                        end
6008
                                end
6009
 
6010
                                else begin      // fetchbuf0 doesn't contain a predicted branch
6011
                                    //
6012
                                    // so -- we can enqueue 1 or 2 instructions, depending on space in the IQ
6013
                                    // update the rf_v and rf_source bits separately (at end)
6014
                                    //   the problem is that if we do have two instructions, 
6015
                                    //   they may interact with each other, so we have to be
6016
                                    //   careful about where things point.
6017
                                    //
6018
                                    // enqueue the first instruction ...
6019
                                    //
6020
                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
6021
                                 vqe0 <= vqe0 + 4'd1;
6022
                                if (IsVCmprss(fetchbuf0_instr)) begin
6023
                                    if (vm[fetchbuf0_instr[25:23]][vqe0])
6024
                                         vqet0 <= vqet0 + 4'd1;
6025
                                end
6026
                                else
6027
                                     vqet0 <= vqet0 + 4'd1;
6028
                                if (vqe0 >= vl-2)
6029
                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6030
                            end
6031
                            tgtq <= FALSE;
6032
                            if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
6033
                                    enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
6034
                                        if (fetchbuf0_thrd)
6035
                                                seq_num1 <= seq_num1 + 5'd1;
6036
                                        else
6037
                                                seq_num <= seq_num + 5'd1;
6038
                                            //
6039
                                            // if there is room for a second instruction, enqueue it
6040
                                            //
6041
                                            if (canq2) begin
6042
                                                if (vechain && IsVector(fetchbuf1_instr)
6043
                                                && Ra1s != Rt0s // And there is no dependency
6044
                                                && Rb1s != Rt0s
6045
                                                && Rc1s != Rt0s
6046
                                                ) begin
6047
`ifdef SUPPORT_SMT
6048
                                                        mstatus[0][32] <= 1'b1;
6049
`else
6050
                                                        mstatus[32] <= 1'b1;
6051
`endif
6052
                                                vqe1 <= vqe1 + 4'd1;
6053
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6054
                                                    if (vm[fetchbuf1_instr[25:23]][vqe1])
6055
                                                         vqet1 <= vqet1 + 4'd1;
6056
                                                end
6057
                                                else
6058
                                                     vqet1 <= vqet1 + 4'd1;
6059
                                                if (vqe1 >= vl-2)
6060
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6061
                                                        enque1(tail1,
6062
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6063
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6064
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
6065
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6066
                                                                if (fetchbuf1_thrd)
6067
                                                                        seq_num1 <= seq_num1 + 5'd2;
6068
                                                                else
6069
                                                                        seq_num <= seq_num + 5'd2;
6070
                                                        end
6071
                                                        else begin
6072
                                                                if (fetchbuf1_thrd)
6073
                                                                        seq_num1 <= seq_num1 + 5'd1;
6074
                                                                else
6075
                                                                        seq_num <= seq_num + 5'd1;
6076
                                                        end
6077
 
6078
                                                                // SOURCE 1 ...
6079
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6080
                                                                if (~fetchbuf0_rfw) begin
6081
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6082
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6083
                                                                end
6084
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6085
                                                                else if (Ra1 == Rt0) begin
6086
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6087
                                                                     iqentry_a1_v [tail1] <= `INV;
6088
                                                                     iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6089
                                                                end
6090
                                                                // if no overlap, get info from rf_v and rf_source
6091
                                                                else begin
6092
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6093
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6094
                                                                end
6095
 
6096
                                                                // SOURCE 2 ...
6097
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6098
                                                                if (~fetchbuf0_rfw) begin
6099
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6100
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6101
                                                                end
6102
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6103
                                                                else if (Rb1s == Rt0s) begin
6104
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6105
                                                                     iqentry_a2_v [tail1] <= `INV;
6106
                                                                     iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6107
                                                                end
6108
                                                                // if no overlap, get info from rf_v and rf_source
6109
                                                                else begin
6110
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6111
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6112
                                                                end
6113
 
6114
                                                                // SOURCE 3 ...
6115
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6116
                                                                if (~fetchbuf0_rfw) begin
6117
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6118
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6119
                                                                end
6120
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6121
                                                                else if (Rc1 == Rt0) begin
6122
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6123
                                                                     iqentry_a3_v [tail1] <= `INV;
6124
                                                                     iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6125
                                                                end
6126
                                                                // if no overlap, get info from rf_v and rf_source
6127
                                                                else begin
6128
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6129
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6130
                                                                end
6131
 
6132
                                                                // if the two instructions enqueued target the same register, 
6133
                                                                // make sure only the second writes to rf_v and rf_source.
6134
                                                                // first is allowed to update rf_v and rf_source only if the
6135
                                                                // second has no target
6136
                                                                //
6137
                                                            if (fetchbuf0_rfw) begin
6138
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6139
                                                                     rf_v [ Rt0s] <= `INV;
6140
                                                            end
6141
                                                            if (fetchbuf1_rfw) begin
6142
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6143
                                                                     rf_v [ Rt1s ] <= `INV;
6144
                                                            end
6145
                                                end
6146
                                                // If there was a vector instruction in fetchbuf0, we really
6147
                                                // want to queue the next vector element, not the next
6148
                                                // instruction waiting in fetchbuf1.
6149
                                            else if (IsVector(fetchbuf0_instr) && SUP_VECTOR && vqe0 < vl-1) begin
6150
                                                 vqe0 <= vqe0 + 4'd2;
6151
                                                if (IsVCmprss(fetchbuf0_instr)) begin
6152
                                                    if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
6153
                                                         vqet0 <= vqet0 + 4'd2;
6154
                                                end
6155
                                                else
6156
                                                     vqet0 <= vqet0 + 4'd2;
6157
                                                if (vqe0 >= vl-3)
6158
                                                 nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6159
                                            if (vqe0 < vl-1) begin
6160
                                                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe0 + 6'd1);
6161
                                                                if (fetchbuf0_thrd)
6162
                                                                        seq_num1 <= seq_num1 + 5'd2;
6163
                                                                else
6164
                                                                        seq_num <= seq_num + 5'd2;
6165
 
6166
                                                                        // SOURCE 1 ...
6167
                                                     iqentry_a1_v [tail1] <= regIsValid[Ra0s];
6168
                                                     iqentry_a1_s [tail1] <= rf_source [Ra0s];
6169
 
6170
                                                                        // SOURCE 2 ...
6171
                                                     iqentry_a2_v [tail1] <= regIsValid[Rb0s];
6172
                                                     iqentry_a2_s [tail1] <= rf_source[ Rb0s ];
6173
 
6174
                                                                        // SOURCE 3 ...
6175
                                                     iqentry_a3_v [tail1] <= regIsValid[Rc0s];
6176
                                                     iqentry_a3_s [tail1] <= rf_source[ Rc0s ];
6177
 
6178
                                                                        // if the two instructions enqueued target the same register, 
6179
                                                                        // make sure only the second writes to rf_v and rf_source.
6180
                                                                        // first is allowed to update rf_v and rf_source only if the
6181
                                                                        // second has no target (BEQ or SW)
6182
                                                                        //
6183
                                                                    if (fetchbuf0_rfw) begin
6184
                                                                             rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };
6185
                                                                             rf_v [ Rt0s ] <= `INV;
6186
                                                                    end
6187
                                                                end
6188
                                                end
6189
                                            else if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6190
                                                 vqe1 <= 6'd1;
6191
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6192
                                                    if (vm[fetchbuf1_instr[25:23]][IsVector(fetchbuf0_instr)? 6'd0:vqe1+6'd1])
6193
                                                         vqet1 <= 6'd1;
6194
                                                else
6195
                                                         vqet1 <= 6'd0;
6196
                                                end
6197
                                                else
6198
                                                         vqet1 <= 6'd1;
6199
                                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR)
6200
                                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6201
                                                        enque1(tail1,
6202
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6203
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6204
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
6205
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6206
                                                                if (fetchbuf1_thrd)
6207
                                                                        seq_num1 <= seq_num1 + 5'd2;
6208
                                                                else
6209
                                                                        seq_num <= seq_num + 5'd2;
6210
                                                        end
6211
                                                        else begin
6212
                                                                if (fetchbuf1_thrd)
6213
                                                                        seq_num1 <= seq_num1 + 5'd1;
6214
                                                                else
6215
                                                                        seq_num <= seq_num + 5'd1;
6216
                                                        end
6217
 
6218
                                                                // SOURCE 1 ...
6219
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6220
                                                                if (~fetchbuf0_rfw) begin
6221
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6222
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6223
                                                                end
6224
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6225
                                                                else if (Ra1 == Rt0) begin
6226
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6227
                                                                     iqentry_a1_v [tail1] <= `INV;
6228
                                                                     iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6229
                                                                end
6230
                                                                // if no overlap, get info from rf_v and rf_source
6231
                                                                else begin
6232
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6233
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6234
                                                                end
6235
 
6236
                                                                // SOURCE 2 ...
6237
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6238
                                                                if (~fetchbuf0_rfw) begin
6239
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6240
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6241
                                                                end
6242
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6243
                                                                else if (Rb1s == Rt0s) begin
6244
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6245
                                                                     iqentry_a2_v [tail1] <= `INV;
6246
                                                                     iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6247
                                                                end
6248
                                                                // if no overlap, get info from rf_v and rf_source
6249
                                                                else begin
6250
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6251
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6252
                                                                end
6253
 
6254
                                                                // SOURCE 3 ...
6255
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6256
                                                                if (~fetchbuf0_rfw) begin
6257
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6258
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6259
                                                                end
6260
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6261
                                                                else if (Rc1 == Rt0) begin
6262
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6263
                                                                     iqentry_a3_v [tail1] <= `INV;
6264
                                                                     iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6265
                                                                end
6266
                                                                // if no overlap, get info from rf_v and rf_source
6267
                                                                else begin
6268
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6269
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6270
                                                                end
6271
 
6272
                                                                // if the two instructions enqueued target the same register, 
6273
                                                                // make sure only the second writes to rf_v and rf_source.
6274
                                                                // first is allowed to update rf_v and rf_source only if the
6275
                                                                // second has no target
6276
                                                                //
6277
                                                            if (fetchbuf0_rfw) begin
6278
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6279
                                                                     rf_v [ Rt0s] <= `INV;
6280
                                                            end
6281
                                                            if (fetchbuf1_rfw) begin
6282
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6283
                                                                     rf_v [ Rt1s ] <= `INV;
6284
                                                            end
6285
                                            end
6286
                                            else begin
6287
//                                                      enque1(tail1, seq_num + 5'd1, 6'd0);
6288
                                                        enque1(tail1,
6289
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6290
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6291
                                                                fetchbuf1_thrd ? seq_num1: seq_num, 6'd0);
6292
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6293
                                                                if (fetchbuf1_thrd)
6294
                                                                        seq_num1 <= seq_num1 + 5'd2;
6295
                                                                else
6296
                                                                        seq_num <= seq_num + 5'd2;
6297
                                                        end
6298
                                                        else begin
6299
                                                                        seq_num1 <= seq_num1 + 5'd1;
6300
                                                                        seq_num <= seq_num + 5'd1;
6301
                                                        end
6302
 
6303
                                                                // SOURCE 1 ...
6304
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6305
                                                                if (~fetchbuf0_rfw) begin
6306
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6307
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6308
                                                                end
6309
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6310
                                                                else if (Ra1s == Rt0s) begin
6311
                                                                     iqentry_a1_v [tail1] <= `INV;
6312
                                                                     iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
6313
                                                                end
6314
                                                                // if no overlap, get info from regIsValid and rf_source
6315
                                                                else begin
6316
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6317
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6318
                                                                end
6319
 
6320
                                                                // SOURCE 2 ...
6321
                                                                // if the argument is an immediate or not needed, we're done
6322
                                                                $display("Rb1s=%h, Rt0s=%h", Rb1s, Rt0s);
6323
                                                                $display("instr=%h", fetchbuf1_instr);
6324
                                                                // if previous instruction writes nothing to RF, then get info from regIsValid and rf_source
6325
                                                                if (~fetchbuf0_rfw) begin
6326
                                                                        $display("fetchbuf0_rfw=0");
6327
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6328
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6329
                                                                end
6330
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6331
                                                                else if (Rb1s == Rt0s) begin
6332
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6333
                                                                     iqentry_a2_v [tail1] <= `INV;
6334
                                                                     iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
6335
                                                                end
6336
                                                                // if no overlap, get info from regIsValid and rf_source
6337
                                                                else begin
6338
                                                                                $display("No overlap");
6339
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6340
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6341
                                                                end
6342
 
6343
                                                                // SOURCE 3 ...
6344
                                                                // if previous instruction writes nothing to RF, then get info from regIsValid and rf_source
6345
                                                                if (~fetchbuf0_rfw) begin
6346
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6347
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6348
                                                                end
6349
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6350
                                                                else if (Rc1s == Rt0s) begin
6351
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6352
                                                                     iqentry_a3_v [tail1] <= `INV;
6353
                                                                     iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
6354
                                                                end
6355
                                                                // if no overlap, get info from regIsValid and rf_source
6356
                                                                else begin
6357
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6358
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6359
                                                                end
6360
 
6361
                                                                // if the two instructions enqueued target the same register, 
6362
                                                                // make sure only the second writes to regIsValid and rf_source.
6363
                                                                // first is allowed to update regIsValid and rf_source only if the
6364
                                                                // second has no target (BEQ or SW)
6365
                                                                //
6366
                                                            if (fetchbuf0_rfw) begin
6367
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6368
                                                                     rf_v [ Rt0s] <= `INV;
6369
                                                                     $display("r%dx (%d) Invalidated", Rt0s, Rt0s[4:0]);
6370
                                                            end
6371
                                                            else
6372
                                                                $display("No rfw");
6373
                                                            if (fetchbuf1_rfw) begin
6374
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6375
                                                                     $display("r%dx (%d) Invalidated", Rt1s, Rt1s[4:0]);
6376
                                                                     rf_v [ Rt1s ] <= `INV;
6377
                                                            end
6378
                                                            else
6379
                                                                $display("No rfw");
6380
                                                        end
6381
 
6382
                                            end // ends the "if IQ[tail1] is available" clause
6383
                                            else begin  // only first instruction was enqueued
6384
                                                        if (fetchbuf0_rfw) begin
6385
                                                             $display("r%dx (%d) Invalidated 1", Rt0s, Rt0s[4:0]);
6386
                                                             rf_source[ Rt0s ] <= {1'b0,fetchbuf0_memld, tail0};
6387
                                                             rf_v [ Rt0s ] <= `INV;
6388
                                                        end
6389
                                                end
6390
                                    end
6391
 
6392
                                end     // ends the "else fetchbuf0 doesn't have a backwards branch" clause
6393
                    end
6394
                endcase
6395
        if (pebm) begin
6396
                if (branchmiss_thrd==1'b0)
6397
                        seq_num <= seq_num + 5'd3;
6398
                else
6399
                        seq_num1 <= seq_num1 + 5'd3;
6400
        end
6401
 
6402
//
6403
// DATAINCOMING
6404
//
6405
// wait for operand/s to appear on alu busses and puts them into 
6406
// the iqentry_a1 and iqentry_a2 slots (if appropriate)
6407
// as well as the appropriate iqentry_res slots (and setting valid bits)
6408
//
6409
// put results into the appropriate instruction entries
6410
//
6411
// This chunk of code has to be before the enqueue stage so that the agen bit
6412
// can be reset to zero by enqueue.
6413
// put results into the appropriate instruction entries
6414
//
6415
if (IsMul(alu0_instr)|IsDivmod(alu0_instr)|alu0_shft48) begin
6416
        if (alu0_done) begin
6417
                alu0_dataready <= `TRUE;
6418
        end
6419
end
6420
 
6421
if (alu0_v) begin
6422
        iqentry_tgt [ alu0_id[`QBITS] ] <= alu0_tgt;
6423
        iqentry_res     [ alu0_id[`QBITS] ] <= alu0_bus;
6424
        iqentry_exc     [ alu0_id[`QBITS] ] <= alu0_exc;
6425
        iqentry_done[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
6426
        iqentry_cmt[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
6427
        iqentry_out     [ alu0_id[`QBITS] ] <= `INV;
6428
        iqentry_agen[ alu0_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
6429
        alu0_dataready <= FALSE;
6430
end
6431
 
6432
if (alu1_v) begin
6433
        iqentry_tgt [ alu1_id[`QBITS] ] <= alu1_tgt;
6434
        iqentry_res     [ alu1_id[`QBITS] ] <= alu1_bus;
6435
        iqentry_exc     [ alu1_id[`QBITS] ] <= alu1_exc;
6436
        iqentry_done[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
6437
        iqentry_cmt[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
6438
        iqentry_out     [ alu1_id[`QBITS] ] <= `INV;
6439
        iqentry_agen[ alu1_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
6440
        alu1_dataready <= FALSE;
6441
end
6442
 
6443
if (fpu_v) begin
6444
        iqentry_res    [ fpu_id[`QBITS] ] <= fpu_bus;
6445
        iqentry_a0     [ fpu_id[`QBITS] ] <= fpu_status;
6446
        iqentry_exc    [ fpu_id[`QBITS] ] <= fpu_exc;
6447
        iqentry_done[ fpu_id[`QBITS] ] <= fpu_done;
6448
        iqentry_cmt[ fpu_id[`QBITS] ] <= fpu_done;
6449
        iqentry_out    [ fpu_id[`QBITS] ] <= `INV;
6450
        //iqentry_agen[ fpu_id[`QBITS] ] <= `VAL;  // RET
6451
        fpu_dataready <= FALSE;
6452
end
6453
 
6454
        if (fcu_wr) begin
6455
            if (fcu_ld)
6456
                waitctr <= fcu_argA;
6457
        iqentry_res [ fcu_id[`QBITS] ] <= fcu_bus;
6458
        iqentry_exc [ fcu_id[`QBITS] ] <= fcu_exc;
6459
        if (IsWait(fcu_instr)) begin
6460
             iqentry_done [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
6461
             iqentry_cmt [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
6462
             fcu_done <= `TRUE;
6463
        end
6464
        else begin
6465
             iqentry_done[ fcu_id[`QBITS] ] <= `TRUE;
6466
             iqentry_cmt[ fcu_id[`QBITS] ] <= `TRUE;
6467
             fcu_done <= `TRUE;
6468
        end
6469
//            if (IsWait(fcu_instr) ? (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]] : !IsMem(fcu_instr) && !IsImmp(fcu_instr))
6470
//                iqentry_instr[ dram_id[`QBITS]] <= `NOP_INSN;
6471
        // Only safe place to propagate the miss pc is a0.
6472
        iqentry_a0[ fcu_id[`QBITS] ] <= fcu_misspc;
6473
        // Update branch taken indicator.
6474
        if (IsJAL(fcu_instr) || IsRet(fcu_instr) || IsBrk(fcu_instr) || IsRTI(fcu_instr) ) begin
6475
             iqentry_bt[ fcu_id[`QBITS] ] <= `VAL;
6476
            // Only safe place to propagate the miss pc is a0.
6477
//             iqentry_a0[ fcu_id[`QBITS] ] <= fcu_misspc;
6478
        end
6479
        else if (IsBranch(fcu_instr)) begin
6480
             iqentry_bt[ fcu_id[`QBITS] ] <= fcu_takb;
6481
//             iqentry_a0[ fcu_id[`QBITS] ] <= fcu_misspc;
6482
        end
6483
         iqentry_out [ fcu_id[`QBITS] ] <= `INV;
6484
         //iqentry_agen[ fcu_id[`QBITS] ] <= `VAL;//!IsRet(fcu_instr);
6485
        fcu_dataready <= `VAL;
6486
         //fcu_dataready <= fcu_branchmiss || !iqentry_agen[ fcu_id[`QBITS] ] || !(iqentry_mem[ fcu_id[`QBITS] ] && IsLoad(iqentry_instr[fcu_id[`QBITS]]));
6487
         //fcu_instr[`INSTRUCTION_OP] <= fcu_branchmiss|| (!IsMem(fcu_instr) && !IsWait(fcu_instr))? `NOP : fcu_instr[`INSTRUCTION_OP]; // to clear branchmiss
6488
        end
6489
        // Clear a branch miss when target instruction is fetched.
6490
        if (fcu_branchmiss) begin
6491
                if ((fetchbuf0_v && fetchbuf0_pc==misspc) ||
6492
                        (fetchbuf1_v && fetchbuf1_pc==misspc))
6493
                fcu_clearbm <= `TRUE;
6494
                //fcu_instr[`INSTRUCTION_OP] <= `NOP;
6495
                //iqentry_instr[fcu_id][`INSTRUCTION_OP] <= `NOP;
6496
        end
6497
//      if (dram_v && iqentry_v[ dram_id[`QBITS] ] && iqentry_mem[ dram_id[`QBITS] ] ) begin    // if data for stomped instruction, ignore
6498
        if (dramA_v && iqentry_v[ dramA_id[`QBITS] ] && iqentry_load[ dramA_id[`QBITS] ]) begin // if data for stomped instruction, ignore
6499
                iqentry_res     [ dramA_id[`QBITS] ] <= dramA_bus;
6500
        iqentry_exc     [ dramA_id[`QBITS] ] <= dramA_exc;
6501
        iqentry_done[ dramA_id[`QBITS] ] <= `VAL;
6502
        iqentry_out [ dramA_id[`QBITS] ] <= `INV;
6503
        iqentry_cmt[ dramA_id[`QBITS] ] <= `VAL;
6504
            iqentry_aq  [ dramA_id[`QBITS] ] <= `INV;
6505
//          if (iqentry_lptr[dram0_id[`QBITS]])
6506
//              wbrcd[pcr[5:0]] <= 1'b1;
6507
        end
6508
        if (dramB_v && iqentry_v[ dramB_id[`QBITS] ] && iqentry_load[ dramB_id[`QBITS] ]) begin // if data for stomped instruction, ignore
6509
        iqentry_res     [ dramB_id[`QBITS] ] <= dramB_bus;
6510
        iqentry_exc     [ dramB_id[`QBITS] ] <= dramB_exc;
6511
        iqentry_done[ dramB_id[`QBITS] ] <= `VAL;
6512
        iqentry_out [ dramB_id[`QBITS] ] <= `INV;
6513
        iqentry_cmt[ dramB_id[`QBITS] ] <= `VAL;
6514
            iqentry_aq  [ dramB_id[`QBITS] ] <= `INV;
6515
//          if (iqentry_lptr[dram1_id[`QBITS]])
6516
//              wbrcd[pcr[5:0]] <= 1'b1;
6517
        end
6518
        if (dramC_v && iqentry_v[ dramC_id[`QBITS] ] && iqentry_load[ dramC_id[`QBITS] ]) begin // if data for stomped instruction, ignore
6519
        iqentry_res     [ dramC_id[`QBITS] ] <= dramC_bus;
6520
        iqentry_exc     [ dramC_id[`QBITS] ] <= dramC_exc;
6521
        iqentry_done[ dramC_id[`QBITS] ] <= `VAL;
6522
        iqentry_out [ dramC_id[`QBITS] ] <= `INV;
6523
        iqentry_cmt[ dramC_id[`QBITS] ] <= `VAL;
6524
            iqentry_aq  [ dramC_id[`QBITS] ] <= `INV;
6525
//          if (iqentry_lptr[dram2_id[`QBITS]])
6526
//              wbrcd[pcr[5:0]] <= 1'b1;
6527
        end
6528
 
6529
//
6530
// set the IQ entry == DONE as soon as the SW is let loose to the memory system
6531
//
6532
if (dram0 == `DRAMSLOT_BUSY && IsStore(dram0_instr)) begin
6533
        if ((alu0_v && (dram0_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram0_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6534
        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
6535
        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
6536
end
6537
if (dram1 == `DRAMSLOT_BUSY && IsStore(dram1_instr)) begin
6538
        if ((alu0_v && (dram1_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram1_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6539
        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
6540
        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
6541
end
6542
if (dram2 == `DRAMSLOT_BUSY && IsStore(dram2_instr)) begin
6543
        if ((alu0_v && (dram2_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram2_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6544
        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
6545
        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
6546
end
6547
 
6548
//
6549
// see if anybody else wants the results ... look at lots of buses:
6550
//  - fpu_bus
6551
//  - alu0_bus
6552
//  - alu1_bus
6553
//  - fcu_bus
6554
//  - dram_bus
6555
//  - commit0_bus
6556
//  - commit1_bus
6557
//
6558
 
6559
for (n = 0; n < QENTRIES; n = n + 1)
6560
begin
6561
        setargs(n,{1'b0,fpu_id},fpu_v,fpu_bus);
6562
        setargs(n,{1'b0,alu0_id},alu0_v,alu0_bus);
6563
        setargs(n,{1'b0,alu1_id},alu1_v,alu1_bus);
6564
        setargs(n,{1'b0,fcu_id},fcu_wr,fcu_bus);
6565
        setargs(n,{1'b0,dramA_id},dramA_v,dramA_bus);
6566
        setargs(n,{1'b0,dramB_id},dramB_v,dramB_bus);
6567
        setargs(n,{1'b0,dramC_id},dramC_v,dramC_bus);
6568
        setargs(n,commit0_id,commit0_v,commit0_bus);
6569
        setargs(n,commit1_id,commit1_v,commit1_bus);
6570
 
6571
        setinsn(n[`QBITS],id1_ido,id1_available&id1_vo,id1_bus);
6572
        setinsn(n[`QBITS],id2_ido,id2_available&id2_vo,id2_bus);
6573
end
6574
 
6575
//
6576
// ISSUE 
6577
//
6578
// determines what instructions are ready to go, then places them
6579
// in the various ALU queues.  
6580
// also invalidates instructions following a branch-miss BEQ or any JALR (STOMP logic)
6581
//
6582
 
6583
for (n = 0; n < QENTRIES; n = n + 1)
6584
if (id1_available) begin
6585
if (iqentry_id1issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6586
                id1_vi <= `VAL;
6587
                id1_id                  <= n[4:0];
6588
                id1_instr       <= iqentry_rtop[n] ? (
6589
                                                                                iqentry_a3_v[n] ? iqentry_a3[n]
6590
                                : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
6591
                                : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
6592
                                : `NOP_INSN)
6593
                                                                 : iqentry_instr[n];
6594
                id1_ven    <= iqentry_ven[n];
6595
                id1_vl     <= iqentry_vl[n];
6596
                id1_thrd   <= iqentry_thrd[n];
6597
                id1_Rt     <= iqentry_tgt[n][4:0];
6598
                id1_pt                  <= iqentry_pt[n];
6599
  end
6600
end
6601
for (n = 0; n < QENTRIES; n = n + 1)
6602
if (id2_available) begin
6603
if (iqentry_id2issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6604
                id2_vi <= `VAL;
6605
                id2_id                  <= n[4:0];
6606
                id2_instr       <= iqentry_rtop[n] ? (
6607
                                                                                iqentry_a3_v[n] ? iqentry_a3[n]
6608
                                : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
6609
                                : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
6610
                                : `NOP_INSN)
6611
                                                                 : iqentry_instr[n];
6612
                id2_ven    <= iqentry_ven[n];
6613
                id2_vl     <= iqentry_vl[n];
6614
                id2_thrd   <= iqentry_thrd[n];
6615
                id2_Rt     <= iqentry_tgt[n][4:0];
6616
                id2_pt                  <= iqentry_pt[n];
6617
        end
6618
end
6619
 
6620
    for (n = 0; n < QENTRIES; n = n + 1)
6621
        if (iqentry_alu0_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6622
            if (alu0_available & alu0_done) begin
6623
                 alu0_sourceid  <= n[3:0];
6624
                 alu0_instr     <= iqentry_rtop[n] ? (
6625
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6626
                                                    : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus)
6627
                                                                         : iqentry_instr[n];
6628
                 alu0_bt                <= iqentry_bt[n];
6629
                 alu0_mem   <= iqentry_mem[n];
6630
                 alu0_shft48 <= iqentry_shft48[n];
6631
                 alu0_pc                <= iqentry_pc[n];
6632
                 alu0_argA      <= iqentry_a1_v[n] ? iqentry_a1[n]
6633
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6634
                 alu0_argB      <= iqentry_imm[n]
6635
                            ? iqentry_a0[n]
6636
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
6637
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus : alu1_bus);
6638
                 alu0_argC      <= iqentry_a3_v[n] ? iqentry_a3[n]
6639
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6640
                 alu0_argI      <= iqentry_a0[n];
6641
                 alu0_tgt    <= IsVeins(iqentry_instr[n]) ?
6642
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((iqentry_a2_v[n] ? iqentry_a2[n][5:0]
6643
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
6644
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
6645
                                            : {4{16'h0000}})) << 6 :
6646
                                iqentry_tgt[n];
6647
                 alu0_ven    <= iqentry_ven[n];
6648
                 alu0_thrd   <= iqentry_thrd[n];
6649
                 alu0_dataready <= IsSingleCycle(iqentry_instr[n]);
6650
                 alu0_ld <= TRUE;
6651
                 iqentry_out[n] <= `VAL;
6652
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
6653
                if (iqentry_mem[n]) begin
6654
                 iqentry_a1_v[n] <= `INV;
6655
                 iqentry_a1_s[n] <= n[3:0];
6656
                end
6657
            end
6658
        end
6659
 
6660
    for (n = 0; n < QENTRIES; n = n + 1)
6661
        if (iqentry_alu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6662
            if (alu1_available && alu1_done) begin
6663
                        if (iqentry_alu0[n])
6664
                                panic <= `PANIC_ALU0ONLY;
6665
                 alu1_sourceid  <= n[3:0];
6666
                 alu1_instr     <= iqentry_instr[n];
6667
                 alu1_bt                <= iqentry_bt[n];
6668
                 alu1_mem   <= iqentry_mem[n];
6669
                 alu1_shft48 <= iqentry_shft48[n];
6670
                 alu1_pc                <= iqentry_pc[n];
6671
                 alu1_argA      <= iqentry_a1_v[n] ? iqentry_a1[n]
6672
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6673
                 alu1_argB      <= iqentry_imm[n]
6674
                            ? iqentry_a0[n]
6675
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
6676
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus : alu1_bus);
6677
                 alu1_argC      <= iqentry_a3_v[n] ? iqentry_a3[n]
6678
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6679
                 alu1_argI      <= iqentry_a0[n];
6680
                 alu1_tgt    <= IsVeins(iqentry_instr[n]) ?
6681
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((iqentry_a2_v[n] ? iqentry_a2[n][5:0]
6682
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
6683
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
6684
                                            : {4{16'h0000}})) << 6 :
6685
                                iqentry_tgt[n];
6686
                 alu1_ven    <= iqentry_ven[n];
6687
                 alu1_dataready <= IsSingleCycle(iqentry_instr[n]);
6688
                 alu1_ld <= TRUE;
6689
                 iqentry_out[n] <= `VAL;
6690
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
6691
                if (iqentry_mem[n]) begin
6692
                 iqentry_a1_v[n] <= `INV;
6693
                 iqentry_a1_s[n] <= n[3:0];
6694
                end
6695
            end
6696
        end
6697
 
6698
    for (n = 0; n < QENTRIES; n = n + 1)
6699
        if (iqentry_fpu_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6700
            if (fpu1_available & fpu_done) begin
6701
                 fpu_sourceid   <= n[3:0];
6702
                 fpu_instr      <= iqentry_instr[n];
6703
                 fpu_pc         <= iqentry_pc[n];
6704
                 fpu_argA       <= iqentry_a1_v[n] ? iqentry_a1[n]
6705
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6706
                 fpu_argB       <= (iqentry_a2_v[n] ? iqentry_a2[n]
6707
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus : alu1_bus);
6708
                 fpu_argC       <= iqentry_a3_v[n] ? iqentry_a3[n]
6709
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6710
                 fpu_argI       <= iqentry_a0[n];
6711
                 fpu_dataready <= `VAL;
6712
                 fpu_ld <= TRUE;
6713
                 iqentry_out[n] <= `VAL;
6714
            end
6715
        end
6716
 
6717
    for (n = 0; n < QENTRIES; n = n + 1)
6718
        if (iqentry_fcu_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6719
            if (fcu_done) begin
6720
                 fcu_sourceid   <= n[3:0];
6721
                 fcu_instr      <= iqentry_instr[n];
6722
                 fcu_insln  <= iqentry_insln[n];
6723
                 fcu_pc         <= iqentry_pc[n];
6724
                 fcu_nextpc <= iqentry_pc[n] + iqentry_insln[n];
6725
                 fcu_brdisp <= {{52{iqentry_instr[n][31]}},iqentry_instr[n][31:21],1'b0};
6726
                 fcu_call    <= IsCall(iqentry_instr[n])|IsJAL(iqentry_instr[n]);
6727
                 fcu_bt         <= iqentry_bt[n];
6728
                 fcu_pc         <= iqentry_pc[n];
6729
                 fcu_argA       <= iqentry_a1_v[n] ? iqentry_a1[n]
6730
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6731
`ifdef SUPPORT_SMT
6732
                 fcu_argB       <= IsRTI(iqentry_instr[n]) ? epc0[iqentry_thrd[n]]
6733
`else
6734
                 fcu_argB       <= IsRTI(iqentry_instr[n]) ? epc0
6735
`endif
6736
                                        : (iqentry_a2_v[n] ? iqentry_a2[n]
6737
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus : alu1_bus);
6738
                 waitctr            <= iqentry_imm[n]
6739
                            ? iqentry_a0[n]
6740
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
6741
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus : alu1_bus);
6742
                 fcu_argC       <= iqentry_a3_v[n] ? iqentry_a3[n]
6743
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6744
                 fcu_argI       <= iqentry_a0[n];
6745
                 fcu_thrd   <= iqentry_thrd[n];
6746
                 fcu_dataready <= `VAL;
6747
                 fcu_clearbm <= `FALSE;
6748
                 fcu_retadr_v <= `INV;
6749
                 fcu_ld <= TRUE;
6750
                 fcu_timeout <= 8'h00;
6751
                 iqentry_out[n] <= `VAL;
6752
                 fcu_done <= `FALSE;
6753
            end
6754
        end
6755
//
6756
// MEMORY
6757
//
6758
// update the memory queues and put data out on bus if appropriate
6759
//
6760
 
6761
//
6762
// dram0, dram1, dram2 are the "state machines" that keep track
6763
// of three pipelined DRAM requests.  if any has the value "00", 
6764
// then it can accept a request (which bumps it up to the value "01"
6765
// at the end of the cycle).  once it hits the value "11" the request
6766
// is finished and the dram_bus takes the value.  if it is a store, the 
6767
// dram_bus value is not used, but the dram_v value along with the
6768
// dram_id value signals the waiting memq entry that the store is
6769
// completed and the instruction can commit.
6770
//
6771
 
6772
//      if (dram0 != `DRAMSLOT_AVAIL)   dram0 <= dram0 + 2'd1;
6773
//      if (dram1 != `DRAMSLOT_AVAIL)   dram1 <= dram1 + 2'd1;
6774
//      if (dram2 != `DRAMSLOT_AVAIL)   dram2 <= dram2 + 2'd1;
6775
 
6776
//
6777
// grab requests that have finished and put them on the dram_bus
6778
if (dram0 == `DRAMREQ_READY) begin
6779
        dram0 <= `DRAMSLOT_AVAIL;
6780
        dramA_v <= dram0_load;
6781
        dramA_id <= dram0_id;
6782
        dramA_exc <= dram0_exc;
6783
        dramA_bus <= fnDati(dram0_instr,dram0_addr,rdat0);
6784
        if (IsStore(dram0_instr))       $display("m[%h] <- %h", dram0_addr, dram0_data);
6785
end
6786
//    else
6787
//      dramA_v <= `INV;
6788
if (dram1 == `DRAMREQ_READY) begin
6789
        dram1 <= `DRAMSLOT_AVAIL;
6790
        dramB_v <= dram1_load;
6791
        dramB_id <= dram1_id;
6792
        dramB_exc <= dram1_exc;
6793
        dramB_bus <= fnDati(dram1_instr,dram1_addr,rdat1);
6794
        if (IsStore(dram1_instr))     $display("m[%h] <- %h", dram1_addr, dram1_data);
6795
end
6796
//    else
6797
//      dramB_v <= `INV;
6798
if (dram2 == `DRAMREQ_READY) begin
6799
        dram2 <= `DRAMSLOT_AVAIL;
6800
        dramC_v <= dram2_load;
6801
        dramC_id <= dram2_id;
6802
        dramC_exc <= dram2_exc;
6803
        dramC_bus <= fnDati(dram2_instr,dram2_addr,rdat2);
6804
        if (IsStore(dram2_instr))     $display("m[%h] <- %h", dram2_addr, dram2_data);
6805
end
6806
//    else
6807
//      dramC_v <= `INV;
6808
 
6809
        //
6810
        // determine if the instructions ready to issue can, in fact, issue.
6811
        // "ready" means that the instruction has valid operands but has not gone yet
6812
        iqentry_memissue <= memissue;
6813
        missue_count <= issue_count;
6814
 
6815
 
6816
        //
6817
        // take requests that are ready and put them into DRAM slots
6818
 
6819
        if (dram0 == `DRAMSLOT_AVAIL)    dram0_exc <= `FLT_NONE;
6820
        if (dram1 == `DRAMSLOT_AVAIL)    dram1_exc <= `FLT_NONE;
6821
        if (dram2 == `DRAMSLOT_AVAIL)    dram2_exc <= `FLT_NONE;
6822
 
6823
        for (n = 0; n < QENTRIES; n = n + 1)
6824
                if (iqentry_v[n] && iqentry_stomp[n]) begin
6825
                        iqentry_v[n] <= `INV;
6826
                        iqentry_iv[n] <= `INV;
6827
                        if (dram0_id[`QBITS] == n[`QBITS])  dram0 <= `DRAMSLOT_AVAIL;
6828
                        if (dram1_id[`QBITS] == n[`QBITS])  dram1 <= `DRAMSLOT_AVAIL;
6829
                        if (dram2_id[`QBITS] == n[`QBITS])  dram2 <= `DRAMSLOT_AVAIL;
6830
                end
6831
 
6832
        last_issue = 8;
6833
    for (n = 0; n < QENTRIES; n = n + 1)
6834
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n]) begin
6835
            if (dram0 == `DRAMSLOT_AVAIL) begin
6836
                dramA_v <= `INV;
6837
             dram0              <= `DRAMSLOT_BUSY;
6838
             dram0_id   <= { 1'b1, n[`QBITS] };
6839
             dram0_instr <= iqentry_instr[n];
6840
             dram0_rmw  <= iqentry_rmw[n];
6841
             dram0_preload <= iqentry_preload[n];
6842
             dram0_tgt  <= iqentry_tgt[n];
6843
             dram0_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
6844
             dram0_addr <= iqentry_a1[n];
6845
//             if (ol[iqentry_thrd[n]]==`OL_USER)
6846
//              dram0_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
6847
//             else
6848
                dram0_seg   <= 64'd0;
6849
             dram0_unc   <= iqentry_a1[n][31:20]==12'hFFD || !dce || IsVolatileLoad(iqentry_instr[n]);
6850
             dram0_memsize <= MemSize(iqentry_instr[n]);
6851
             dram0_load <= iqentry_load[n];
6852
             dram0_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
6853
             // Once the memory op is issued reset the a1_v flag.
6854
             // This will cause the a1 bus to look for new data from memory (a1_s is pointed to a memory bus)
6855
             // This is used for the load and compare instructions.
6856
             iqentry_a1_v[n] <= `INV;
6857
             last_issue = n;
6858
            end
6859
        end
6860
    if (last_issue < 8)
6861
        iqentry_out[last_issue] <= `VAL;
6862
    for (n = 0; n < QENTRIES; n = n + 1)
6863
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n]) begin
6864
                if (n < last_issue) begin
6865
                    if (dram1 == `DRAMSLOT_AVAIL) begin
6866
                        dramB_v <= `INV;
6867
                     dram1              <= `DRAMSLOT_BUSY;
6868
                     dram1_id   <= { 1'b1, n[`QBITS] };
6869
                     dram1_instr <= iqentry_instr[n];
6870
                     dram1_rmw  <= iqentry_rmw[n];
6871
                     dram1_preload <= iqentry_preload[n];
6872
                     dram1_tgt  <= iqentry_tgt[n];
6873
                     dram1_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
6874
                     dram1_addr <= iqentry_a1[n];
6875
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
6876
//                      dram1_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
6877
//                   else
6878
                        dram1_seg   <= 64'd0;
6879
                     dram1_unc   <= iqentry_a1[n][31:20]==12'hFFD || !dce || IsVolatileLoad(iqentry_instr[n]);
6880
                     dram1_memsize <= MemSize(iqentry_instr[n]);
6881
                     dram1_load <= iqentry_load[n];
6882
                     dram1_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
6883
                     iqentry_a1_v[n] <= `INV;
6884
                     last_issue = n;
6885
                    end
6886
                end
6887
        end
6888
    if (last_issue < 8)
6889
        iqentry_out[last_issue] <= `VAL;
6890
    for (n = 0; n < QENTRIES; n = n + 1)
6891
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n]) begin
6892
                if (n < last_issue) begin
6893
                    if (dram2 == `DRAMSLOT_AVAIL) begin
6894
                        dramC_v <= `INV;
6895
                     dram2              <= `DRAMSLOT_BUSY;
6896
                     dram2_id   <= { 1'b1, n[`QBITS] };
6897
                     dram2_instr        <= iqentry_instr[n];
6898
                     dram2_rmw  <= iqentry_rmw[n];
6899
                     dram2_preload <= iqentry_preload[n];
6900
                     dram2_tgt  <= iqentry_tgt[n];
6901
                     dram2_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
6902
                     dram2_addr <= iqentry_a1[n];
6903
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
6904
//                      dram2_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
6905
//                   else
6906
                        dram2_seg   <= 64'd0;
6907
                     dram2_unc   <= iqentry_a1[n][31:20]==12'hFFD || !dce || IsVolatileLoad(iqentry_instr[n]);
6908
                     dram2_memsize <= MemSize(iqentry_instr[n]);
6909
                     dram2_load <= iqentry_load[n];
6910
                     dram2_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
6911
                     iqentry_a1_v[n] <= `INV;
6912
                    end
6913
                end
6914
        end
6915
    if (last_issue < 8)
6916
        iqentry_out[last_issue] <= `VAL;
6917
 
6918
    // It's better to check a sequence number here because if the code is in a
6919
    // loop that such that the previous iteration of the loop is still in the
6920
    // queue the PC could match when we don;t really want a prefix for that
6921
    // iteration.
6922
    for (n = 0; n < QENTRIES; n = n + 1)
6923
    begin
6924
        if (!iqentry_v[n])
6925
             iqentry_done[n] <= FALSE;
6926
    end
6927
 
6928
 
6929
 
6930
    //
6931
    // COMMIT PHASE (dequeue only ... not register-file update)
6932
    //
6933
    // look at head0 and head1 and let 'em write to the register file if they are ready
6934
    //
6935
//    always @(posedge clk) begin: commit_phase
6936
 
6937
    oddball_commit(commit0_v, head0);
6938
    oddball_commit(commit1_v, head1);
6939
 
6940
// Fetch and queue are limited to two instructions per cycle, so we might as
6941
// well limit retiring to two instructions max to conserve logic.
6942
//
6943
if (~|panic)
6944
    casez ({ iqentry_v[head0],
6945
        iqentry_cmt[head0],
6946
        iqentry_v[head1],
6947
        iqentry_cmt[head1]})
6948
 
6949
        // retire 3
6950
        4'b0?_0?:
6951
                if (head0 != tail0 && head1 != tail0) begin
6952
                    head_inc(2);
6953
                end
6954
                else if (head0 != tail0) begin
6955
                    head_inc(1);
6956
                end
6957
 
6958
        // retire 1 (wait for regfile for head1)
6959
        4'b0?_10:
6960
                    head_inc(1);
6961
 
6962
        // retire 2
6963
        4'b0?_11:
6964
        begin
6965
            iqentry_v[head1] <= `INV;
6966
            iqentry_iv[head1] <= `INV;
6967
            iqentry_alu[head1] <= `INV;
6968
            head_inc(2);
6969
        end
6970
 
6971
        // retire 0 (stuck on head0)
6972
        4'b10_??:       ;
6973
 
6974
        // retire 1 or 2
6975
        4'b11_0?:
6976
                if (head1 != tail0) begin
6977
                        iqentry_v[head0] <= `INV;
6978
                        iqentry_iv[head0] <= `INV;
6979
      iqentry_alu[head0] <= `INV;
6980
                        head_inc(2);
6981
                end
6982
                else begin
6983
                        iqentry_v[head0] <= `INV;
6984
                        iqentry_iv[head0] <= `INV;
6985
      iqentry_alu[head0] <= `INV;
6986
                        head_inc(1);
6987
                end
6988
 
6989
        // retire 1 (wait for regfile for head1)
6990
        4'b11_10:
6991
                begin
6992
                        iqentry_v[head0] <= `INV;
6993
                        iqentry_iv[head0] <= `INV;
6994
      iqentry_alu[head0] <= `INV;
6995
                        head_inc(1);
6996
                end
6997
 
6998
        // retire 2
6999
        4'b11_11:
7000
            begin
7001
            iqentry_v[head0] <= `INV;    // may conflict with STOMP, but since both are setting to 0, it is okay
7002
            iqentry_v[head1] <= `INV;    // may conflict with STOMP, but since both are setting to 0, it is okay
7003
                                iqentry_iv[head0] <= `INV;
7004
                                iqentry_iv[head1] <= `INV;
7005
        iqentry_alu[head0] <= `INV;
7006
        iqentry_alu[head1] <= `INV;
7007
        head_inc(2);
7008
            end
7009
    endcase
7010
 
7011
 
7012
        rf_source[0] <= 0;
7013
        L1_wr0 <= FALSE;
7014
        L1_wr1 <= FALSE;
7015
        L1_invline <= FALSE;
7016
        icnxt <= FALSE;
7017
        L2_nxt <= FALSE;
7018
// Instruction cache state machine.
7019
// On a miss first see if the instruction is in the L2 cache. No need to go to
7020
// the BIU on an L1 miss.
7021
// If not the machine will wait until the BIU loads the L2 cache.
7022
 
7023
// Capture the previous ic state, used to determine how long to wait in
7024
// icstate #4.
7025
        picstate <= icstate;
7026
case(icstate)
7027
IDLE:
7028
        // If the bus unit is busy doing an update involving L1_adr or L2_adr
7029
        // we have to wait.
7030
        if (bstate != B7 && bstate != B9) begin
7031
                if (!ihit0) begin
7032
                        L1_adr <= {pcr[5:0],pc0[31:3],3'h0};
7033
                        L2_adr <= {pcr[5:0],pc0[31:3],3'h0};
7034
                        L1_invline <= TRUE;
7035
                        icwhich <= 1'b0;
7036
                        iccnt <= 3'b00;
7037
                        icstate <= IC2;
7038
                end
7039
                else if (!ihit1) begin
7040
`ifdef SUPPORT_SMT
7041
                        L1_adr <= {pcr[5:0],pc1[31:3],3'h0};
7042
                        L2_adr <= {pcr[5:0],pc1[31:3],3'h0};
7043
`else
7044
                        L1_adr <= {pcr[5:0],pc0plus6[31:3],3'h0};
7045
                        L2_adr <= {pcr[5:0],pc0plus6[31:3],3'h0};
7046
`endif
7047
                        L1_invline <= TRUE;
7048
                        icwhich <= 1'b1;
7049
                        iccnt <= 3'b00;
7050
                        icstate <= IC2;
7051
                end
7052
        end
7053
IC2:     icstate <= IC3;
7054
IC3:     icstate <= IC3a;
7055
IC3a:     icstate <= IC4;
7056
        // If data was in the L2 cache already there's no need to wait on the
7057
        // BIU to retrieve data. It can be determined if the hit signal was
7058
        // already active when this state was entered in which case waiting
7059
        // will do no good.
7060
        // The IC machine will stall in this state until the BIU has loaded the
7061
        // L2 cache. 
7062
IC4:
7063
        if (ihit2 && picstate==IC3a) begin
7064
                L1_en <= 10'h3FF;
7065
                L1_wr1 <= TRUE;
7066
                L1_wr0 <= TRUE;
7067
                L1_adr <= L2_adr;
7068
                L2_rdat <= L2_dato;
7069
                icstate <= IC5;
7070
        end
7071
        else if (bstate!=B9)
7072
                ;
7073
        else begin
7074
                L1_en <= 10'h3FF;
7075
                L1_wr1 <= TRUE;
7076
                L1_wr0 <= TRUE;
7077
                L1_adr <= L2_adr;
7078
                L2_rdat <= L2_dato;
7079
                icstate <= IC5;
7080
        end
7081
IC5:
7082
        begin
7083
                L1_en <= 10'h000;
7084
                L1_wr0 <= FALSE;
7085
                L1_wr1 <= FALSE;
7086
                icstate <= IC6;
7087
        end
7088
IC6:  icstate <= IC7;
7089
IC7:    icstate <= IC8;
7090
IC8:    begin
7091
             icstate <= IDLE;
7092
             icnxt <= TRUE;
7093
        end
7094
default:     icstate <= IDLE;
7095
endcase
7096
 
7097
if (dram0_load)
7098
case(dram0)
7099
`DRAMSLOT_AVAIL:        ;
7100
`DRAMSLOT_BUSY:         dram0 <= dram0 + !dram0_unc;
7101
3'd2:                           dram0 <= dram0 + 3'd1;
7102
3'd3:                           dram0 <= dram0 + 3'd1;
7103
3'd4:                           if (dhit0) dram0 <= `DRAMREQ_READY; else dram0 <= `DRAMSLOT_REQBUS;
7104
`DRAMSLOT_REQBUS:       ;
7105
`DRAMSLOT_HASBUS:       ;
7106
`DRAMREQ_READY:         ;
7107
endcase
7108
 
7109
if (dram1_load)
7110
case(dram1)
7111
`DRAMSLOT_AVAIL:        ;
7112
`DRAMSLOT_BUSY:         dram1 <= dram1 + !dram1_unc;
7113
3'd2:                           dram1 <= dram1 + 3'd1;
7114
3'd3:                           dram1 <= dram1 + 3'd1;
7115
3'd4:                           if (dhit1) dram1 <= `DRAMREQ_READY; else dram1 <= `DRAMSLOT_REQBUS;
7116
`DRAMSLOT_REQBUS:       ;
7117
`DRAMSLOT_HASBUS:       ;
7118
`DRAMREQ_READY:         ;
7119
endcase
7120
 
7121
if (dram2_load)
7122
case(dram2)
7123
`DRAMSLOT_AVAIL:        ;
7124
`DRAMSLOT_BUSY:         dram2 <= dram2 + !dram2_unc;
7125
3'd2:                           dram2 <= dram2 + 3'd1;
7126
3'd3:                           dram2 <= dram2 + 3'd1;
7127
3'd4:                           if (dhit2) dram2 <= `DRAMREQ_READY; else dram2 <= `DRAMSLOT_REQBUS;
7128
`DRAMSLOT_REQBUS:       ;
7129
`DRAMSLOT_HASBUS:       ;
7130
`DRAMREQ_READY:         ;
7131
endcase
7132
 
7133
// Bus Interface Unit (BIU)
7134
// Interfaces to the external bus which is WISHBONE compatible.
7135
// Stores take precedence over other operations.
7136
// Next data cache read misses are serviced.
7137
// Uncached data reads are serviced.
7138
// Finally L2 instruction cache misses are serviced.
7139
 
7140
case(bstate)
7141
BIDLE:
7142
    begin
7143
         isCAS <= FALSE;
7144
         isAMO <= FALSE;
7145
         isInc <= FALSE;
7146
         isSpt <= FALSE;
7147
         isRMW <= FALSE;
7148
         rdvq <= 1'b0;
7149
         errq <= 1'b0;
7150
         exvq <= 1'b0;
7151
         bwhich <= 2'b11;
7152
         preload <= FALSE;
7153
        if (dram0==`DRAMSLOT_BUSY && dram0_rmw) begin
7154
`ifdef SUPPORT_DBG
7155
            if (dbg_smatch0|dbg_lmatch0) begin
7156
                 dramA_v <= `TRUE;
7157
                 dramA_id <= dram0_id;
7158
                 dramA_exc <= `FLT_DBG;
7159
                 dramA_bus <= 64'h0;
7160
                 dram0 <= `DRAMSLOT_AVAIL;
7161
            end
7162
            else
7163
`endif
7164
            begin
7165
                 dram0 <= `DRAMSLOT_HASBUS;
7166
                 isRMW <= dram0_rmw;
7167
                 isCAS <= IsCAS(dram0_instr);
7168
                 isAMO <= IsAMO(dram0_instr);
7169
                 isInc <= IsInc(dram0_instr);
7170
                 casid <= dram0_id;
7171
                 bwhich <= 2'b00;
7172
                 cyc_o <= `HIGH;
7173
                 stb_o <= `HIGH;
7174
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7175
                 adr_o <= dram0_addr;
7176
                 dat_o <= fnDato(dram0_instr,dram0_data);
7177
                 ol_o  <= dram0_ol;
7178
                 bstate <= B12;
7179
            end
7180
        end
7181
        else if (dram1==`DRAMSLOT_BUSY && dram1_rmw) begin
7182
`ifdef SUPPORT_DBG
7183
            if (dbg_smatch1|dbg_lmatch1) begin
7184
                 dramB_v <= `TRUE;
7185
                 dramB_id <= dram1_id;
7186
                 dramB_exc <= `FLT_DBG;
7187
                 dramB_bus <= 64'h0;
7188
                 dram1 <= `DRAMSLOT_AVAIL;
7189
            end
7190
            else
7191
`endif
7192
            begin
7193
                 dram1 <= `DRAMSLOT_HASBUS;
7194
                 isRMW <= dram1_rmw;
7195
                 isCAS <= IsCAS(dram1_instr);
7196
                 isAMO <= IsAMO(dram1_instr);
7197
                 isInc <= IsInc(dram1_instr);
7198
                 casid <= dram1_id;
7199
                 bwhich <= 2'b01;
7200
                 cyc_o <= `HIGH;
7201
                 stb_o <= `HIGH;
7202
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7203
                 adr_o <= dram1_addr;
7204
                 dat_o <= fnDato(dram1_instr,dram1_data);
7205
                 ol_o  <= dram1_ol;
7206
                 bstate <= B12;
7207
            end
7208
        end
7209
        else if (dram2==`DRAMSLOT_BUSY && dram2_rmw) begin
7210
`ifdef SUPPORT_DBG
7211
            if (dbg_smatch2|dbg_lmatch2) begin
7212
                 dramC_v <= `TRUE;
7213
                 dramC_id <= dram2_id;
7214
                 dramC_exc <= `FLT_DBG;
7215
                 dramC_bus <= 64'h0;
7216
                 dram2 <= `DRAMSLOT_AVAIL;
7217
            end
7218
            else
7219
`endif
7220
            begin
7221
                 dram2 <= `DRAMSLOT_HASBUS;
7222
                 isRMW <= dram2_rmw;
7223
                 isCAS <= IsCAS(dram2_instr);
7224
                 isAMO <= IsAMO(dram2_instr);
7225
                 isInc <= IsInc(dram2_instr);
7226
                 casid <= dram2_id;
7227
                 bwhich <= 2'b10;
7228
                 cyc_o <= `HIGH;
7229
                 stb_o <= `HIGH;
7230
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
7231
                 adr_o <= dram2_addr;
7232
                 dat_o <= fnDato(dram2_instr,dram2_data);
7233
                 ol_o  <= dram2_ol;
7234
                 bstate <= B12;
7235
            end
7236
        end
7237
        else if (dram0==`DRAMSLOT_BUSY && IsStore(dram0_instr)) begin
7238
`ifdef SUPPORT_DBG
7239
            if (dbg_smatch0) begin
7240
                 dramA_v <= `TRUE;
7241
                 dramA_id <= dram0_id;
7242
                 dramA_exc <= `FLT_DBG;
7243
                 dramA_bus <= 64'h0;
7244
                 dram0 <= `DRAMSLOT_AVAIL;
7245
            end
7246
            else
7247
`endif
7248
            begin
7249
                 dram0 <= `DRAMSLOT_HASBUS;
7250
                 dram0_instr[`INSTRUCTION_OP] <= `NOP;
7251
                 bwhich <= 2'b00;
7252
                                 cyc_o <= `HIGH;
7253
                                 stb_o <= `HIGH;
7254
                 we_o <= `HIGH;
7255
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7256
                 adr_o <= dram0_addr;
7257
                 dat_o <= fnDato(dram0_instr,dram0_data);
7258
                 cr_o <= IsSWC(dram0_instr);
7259
                 ol_o  <= dram0_ol;
7260
                 bstate <= B1;
7261
            end
7262
        end
7263
        else if (dram1==`DRAMSLOT_BUSY && IsStore(dram1_instr)) begin
7264
`ifdef SUPPORT_DBG
7265
            if (dbg_smatch1) begin
7266
                 dramB_v <= `TRUE;
7267
                 dramB_id <= dram1_id;
7268
                 dramB_exc <= `FLT_DBG;
7269
                 dramB_bus <= 64'h0;
7270
                 dram1 <= `DRAMSLOT_AVAIL;
7271
            end
7272
            else
7273
`endif
7274
            begin
7275
                 dram1 <= `DRAMSLOT_HASBUS;
7276
                 dram1_instr[`INSTRUCTION_OP] <= `NOP;
7277
                 bwhich <= 2'b01;
7278
                                 cyc_o <= `HIGH;
7279
                                 stb_o <= `HIGH;
7280
                 we_o <= `HIGH;
7281
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7282
                 adr_o <= dram1_addr;
7283
                 dat_o <= fnDato(dram1_instr,dram1_data);
7284
                 cr_o <= IsSWC(dram1_instr);
7285
                 ol_o  <= dram1_ol;
7286
                 bstate <= B1;
7287
            end
7288
        end
7289
        else if (dram2==`DRAMSLOT_BUSY && IsStore(dram2_instr)) begin
7290
`ifdef SUPPORT_DBG
7291
            if (dbg_smatch2) begin
7292
                 dramC_v <= `TRUE;
7293
                 dramC_id <= dram2_id;
7294
                 dramC_exc <= `FLT_DBG;
7295
                 dramC_bus <= 64'h0;
7296
                 dram2 <= `DRAMSLOT_AVAIL;
7297
            end
7298
            else
7299
`endif
7300
            begin
7301
                 dram2 <= `DRAMSLOT_HASBUS;
7302
                 dram2_instr[`INSTRUCTION_OP] <= `NOP;
7303
                 bwhich <= 2'b10;
7304
                                 cyc_o <= `HIGH;
7305
                                 stb_o <= `HIGH;
7306
                 we_o <= `HIGH;
7307
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
7308
                 adr_o <= dram2_addr;
7309
                 dat_o <= fnDato(dram2_instr,dram2_data);
7310
                 cr_o <= IsSWC(dram2_instr);
7311
                 ol_o  <= dram2_ol;
7312
                 bstate <= B1;
7313
            end
7314
        end
7315
        // Check for read misses on the data cache
7316
        else if (!dram0_unc && dram0==`DRAMSLOT_REQBUS && dram0_load) begin
7317
`ifdef SUPPORT_DBG
7318
            if (dbg_lmatch0) begin
7319
                 dramA_v <= `TRUE;
7320
                 dramA_id <= dram0_id;
7321
                 dramA_exc <= `FLT_DBG;
7322
                 dramA_bus <= 64'h0;
7323
                 dram0 <= `DRAMSLOT_AVAIL;
7324
            end
7325
            else
7326
`endif
7327
            begin
7328
                 dram0 <= `DRAMSLOT_HASBUS;
7329
                 bwhich <= 2'b00;
7330
                 preload <= dram0_preload;
7331
                 bstate <= B2;
7332
            end
7333
        end
7334
        else if (!dram1_unc && dram1==`DRAMSLOT_REQBUS && dram1_load) begin
7335
`ifdef SUPPORT_DBG
7336
            if (dbg_lmatch1) begin
7337
                 dramB_v <= `TRUE;
7338
                 dramB_id <= dram1_id;
7339
                 dramB_exc <= `FLT_DBG;
7340
                 dramB_bus <= 64'h0;
7341
                 dram1 <= `DRAMSLOT_AVAIL;
7342
            end
7343
            else
7344
`endif
7345
            begin
7346
                 dram1 <= `DRAMSLOT_HASBUS;
7347
                 bwhich <= 2'b01;
7348
                 preload <= dram1_preload;
7349
                 bstate <= B2;
7350
            end
7351
        end
7352
        else if (!dram2_unc && dram2==`DRAMSLOT_REQBUS && dram2_load) begin
7353
`ifdef SUPPORT_DBG
7354
            if (dbg_lmatch2) begin
7355
                 dramC_v <= `TRUE;
7356
                 dramC_id <= dram2_id;
7357
                 dramC_exc <= `FLT_DBG;
7358
                 dramC_bus <= 64'h0;
7359
                 dram2 <= `DRAMSLOT_AVAIL;
7360
            end
7361
            else
7362
`endif
7363
            begin
7364
                 dram2 <= `DRAMSLOT_HASBUS;
7365
                 preload <= dram2_preload;
7366
                 bwhich <= 2'b10;
7367
                 bstate <= B2;
7368
            end
7369
        end
7370
        else if (dram0_unc && dram0==`DRAMSLOT_BUSY && dram0_load) begin
7371
`ifdef SUPPORT_DBG
7372
            if (dbg_lmatch0) begin
7373
                 dramA_v <= `TRUE;
7374
                 dramA_id <= dram0_id;
7375
                 dramA_exc <= `FLT_DBG;
7376
                 dramA_bus <= 64'h0;
7377
                 dram0 <= `DRAMSLOT_AVAIL;
7378
            end
7379
            else
7380
`endif
7381
            begin
7382
                 bwhich <= 2'b00;
7383
                 cyc_o <= `HIGH;
7384
                 stb_o <= `HIGH;
7385
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7386
                 adr_o <= {dram0_addr[31:3],3'b0};
7387
                 sr_o <=  IsLWR(dram0_instr);
7388
                 ol_o  <= dram0_ol;
7389
                 bstate <= B12;
7390
            end
7391
        end
7392
        else if (dram1_unc && dram1==`DRAMSLOT_BUSY && dram1_load) begin
7393
`ifdef SUPPORT_DBG
7394
            if (dbg_lmatch1) begin
7395
                 dramB_v <= `TRUE;
7396
                 dramB_id <= dram1_id;
7397
                 dramB_exc <= `FLT_DBG;
7398
                 dramB_bus <= 64'h0;
7399
                 dram1 <= `DRAMSLOT_AVAIL;
7400
            end
7401
            else
7402
`endif
7403
            begin
7404
                 bwhich <= 2'b01;
7405
                 cyc_o <= `HIGH;
7406
                 stb_o <= `HIGH;
7407
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7408
                 adr_o <= {dram1_addr[31:3],3'b0};
7409
                 sr_o <=  IsLWR(dram1_instr);
7410
                 ol_o  <= dram1_ol;
7411
                 bstate <= B12;
7412
            end
7413
        end
7414
        else if (dram2_unc && dram2==`DRAMSLOT_BUSY && dram2_load) begin
7415
`ifdef SUPPORT_DBG
7416
            if (dbg_lmatch2) begin
7417
                 dramC_v <= `TRUE;
7418
                 dramC_id <= dram2_id;
7419
                 dramC_exc <= `FLT_DBG;
7420
                 dramC_bus <= 64'h0;
7421
                 dram2 <= 2'd0;
7422
            end
7423
            else
7424
`endif
7425
            begin
7426
                 bwhich <= 2'b10;
7427
                 cyc_o <= `HIGH;
7428
                 stb_o <= `HIGH;
7429
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
7430
                 adr_o <= {dram2_addr[31:3],3'b0};
7431
                 sr_o <=  IsLWR(dram2_instr);
7432
                 ol_o  <= dram2_ol;
7433
                 bstate <= B12;
7434
            end
7435
        end
7436
        // Check for L2 cache miss
7437
        else if (!ihit2) begin
7438
             cti_o <= 3'b001;
7439
             bte_o <= 2'b01;    // 4 beat burst wrap
7440
             cyc_o <= `HIGH;
7441
             stb_o <= `HIGH;
7442
             sel_o <= 8'hFF;
7443
             icl_o <= `HIGH;
7444
//            adr_o <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
7445
//            L2_adr <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
7446
             adr_o <= {pcr[5:0],L1_adr[31:5],5'h0};
7447
             ol_o  <= ol[0];
7448
             L2_adr <= {pcr[5:0],L1_adr[31:5],5'h0};
7449
             L2_xsel <= 1'b0;
7450
             bstate <= B7;
7451
        end
7452
    end
7453
// Terminal state for a store operation.
7454
B1:
7455
    if (acki|err_i) begin
7456
         isStore <= `TRUE;
7457
         cyc_o <= `LOW;
7458
         stb_o <= `LOW;
7459
         we_o <= `LOW;
7460
         sel_o <= 8'h00;
7461
         cr_o <= 1'b0;
7462
        // This isn't a good way of doing things; the state should be propagated
7463
        // to the commit stage, however since this is a store we know there will
7464
        // be no change of program flow. So the reservation status bit is set
7465
        // here. The author wanted to avoid the complexity of propagating the
7466
        // input signal to the commit stage. It does mean that the SWC
7467
        // instruction should be surrounded by SYNC's.
7468
        if (cr_o)
7469
             sema[0] <= rbi_i;
7470
        case(bwhich)
7471
        2'd0:   begin
7472
                 dram0 <= `DRAMREQ_READY;
7473
                 iqentry_exc[dram0_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7474
                if (err_i|wrv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
7475
                            iqentry_cmt[ dram0_id[`QBITS] ] <= `VAL;
7476
                            iqentry_aq[ dram0_id[`QBITS] ] <= `INV;
7477
                        //iqentry_out[ dram0_id[`QBITS] ] <= `INV;
7478
                end
7479
        2'd1:   begin
7480
                 dram1 <= `DRAMREQ_READY;
7481
                 iqentry_exc[dram1_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7482
                if (err_i|wrv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
7483
                            iqentry_cmt[ dram1_id[`QBITS] ] <= `VAL;
7484
                            iqentry_aq[ dram1_id[`QBITS] ] <= `INV;
7485
                        //iqentry_out[ dram1_id[`QBITS] ] <= `INV;
7486
                end
7487
        2'd2:   begin
7488
                 dram2 <= `DRAMREQ_READY;
7489
                 iqentry_exc[dram2_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7490
                if (err_i|wrv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
7491
                            iqentry_cmt[ dram2_id[`QBITS] ] <= `VAL;
7492
                            iqentry_aq[ dram2_id[`QBITS] ] <= `INV;
7493
                        //iqentry_out[ dram2_id[`QBITS] ] <= `INV;
7494
                end
7495
        default:    ;
7496
        endcase
7497
         bstate <= B19;
7498
    end
7499
B2:
7500
    begin
7501
    dccnt <= 2'd0;
7502
    case(bwhich)
7503
    2'd0:   begin
7504
             cti_o <= 3'b001;
7505
             bte_o <= 2'b01;
7506
             cyc_o <= `HIGH;
7507
             stb_o <= `HIGH;
7508
             sel_o <= fnSelect(dram0_instr,dram0_addr);
7509
             adr_o <= {dram0_addr[31:5],5'b0};
7510
             ol_o  <= dram0_ol;
7511
             bstate <= B2d;
7512
            end
7513
    2'd1:   begin
7514
             cti_o <= 3'b001;
7515
             bte_o <= 2'b01;
7516
             cyc_o <= `HIGH;
7517
             stb_o <= `HIGH;
7518
             sel_o <= fnSelect(dram1_instr,dram1_addr);
7519
             adr_o <= {dram1_addr[31:5],5'b0};
7520
             ol_o  <= dram1_ol;
7521
             bstate <= B2d;
7522
            end
7523
    2'd2:   begin
7524
             cti_o <= 3'b001;
7525
             bte_o <= 2'b01;
7526
             cyc_o <= `HIGH;
7527
             stb_o <= `HIGH;
7528
             sel_o <= fnSelect(dram2_instr,dram2_addr);
7529
             adr_o <= {dram2_addr[31:5],5'b0};
7530
             ol_o  <= dram2_ol;
7531
             bstate <= B2d;
7532
            end
7533
    default:    if (~acki)  bstate <= BIDLE;
7534
    endcase
7535
    end
7536
// Data cache load terminal state
7537
B2d:
7538
    if (ack_i|err_i) begin
7539
        errq <= errq | err_i;
7540
        rdvq <= rdvq | rdv_i;
7541
        if (!preload)   // A preload instruction ignores any error
7542
        case(bwhich)
7543
        2'd0:   if (err_i|rdv_i) begin
7544
                     iqentry_a1[dram0_id[`QBITS]] <= adr_o;
7545
                     iqentry_exc[dram0_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
7546
                end
7547
        2'd1:   if (err_i|rdv_i) begin
7548
                     iqentry_a1[dram1_id[`QBITS]] <= adr_o;
7549
                     iqentry_exc[dram1_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
7550
                end
7551
        2'd2:   if (err_i|rdv_i) begin
7552
                     iqentry_a1[dram2_id[`QBITS]] <= adr_o;
7553
                     iqentry_exc[dram2_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
7554
                end
7555
        default:    ;
7556
        endcase
7557
        dccnt <= dccnt + 2'd1;
7558
        adr_o[4:3] <= adr_o[4:3] + 2'd1;
7559
        bstate <= B2d;
7560
        if (dccnt==2'd2)
7561
             cti_o <= 3'b111;
7562
        if (dccnt==2'd3) begin
7563
             cti_o <= 3'b000;
7564
             bte_o <= 2'b00;
7565
             cyc_o <= `LOW;
7566
             stb_o <= `LOW;
7567
             sel_o <= 8'h00;
7568
             bstate <= B4;
7569
        end
7570
    end
7571
B3: begin
7572
         stb_o <= `HIGH;
7573
         bstate <= B2d;
7574
    end
7575
B4:  bstate <= B5;
7576
B5:  bstate <= B6;
7577
B6: begin
7578
    case(bwhich)
7579
    2'd0:    dram0 <= `DRAMSLOT_BUSY;  // causes retest of dhit
7580
    2'd1:    dram1 <= `DRAMSLOT_BUSY;
7581
    2'd2:    dram2 <= `DRAMSLOT_BUSY;
7582
    default:    ;
7583
    endcase
7584
    if (~ack_i)  bstate <= BIDLE;
7585
    end
7586
 
7587
// Ack state for instruction cache load
7588
B7:
7589
    if (ack_i|err_i) begin
7590
        errq <= errq | err_i;
7591
        exvq <= exvq | exv_i;
7592
//        L1_en <= 8'h3 << {L2_adr[4:3],1'b0};
7593
//        L1_wr0 <= `TRUE;
7594
//        L1_wr1 <= `TRUE;
7595
//        L1_adr <= L2_adr;
7596
        if (err_i)
7597
                L2_rdat <= {8{13'b0,3'd7,3'b0,`FLT_IBE,`BRK}};
7598
        else
7599
                L2_rdat <= {4{dat_i}};
7600
        iccnt <= iccnt + 3'd1;
7601
        //stb_o <= `LOW;
7602
        if (iccnt==3'd3)
7603
            cti_o <= 3'b111;
7604
        if (iccnt==3'd4) begin
7605
            cti_o <= 3'b000;
7606
            bte_o <= 2'b00;             // linear burst
7607
            cyc_o <= `LOW;
7608
            stb_o <= `LOW;
7609
            sel_o <= 8'h00;
7610
            icl_o <= `LOW;
7611
            bstate <= B9;
7612
        end
7613
        else begin
7614
            L2_adr[4:3] <= L2_adr[4:3] + 2'd1;
7615
            if (L2_adr[4:3]==2'b11)
7616
                L2_xsel <= 1'b1;
7617
        end
7618
    end
7619
B9:
7620
        begin
7621
                L1_wr0 <= `FALSE;
7622
                L1_wr1 <= `FALSE;
7623
                L1_en <= 8'hFF;
7624
                L2_xsel <= 1'b0;
7625
                if (~ack_i) begin
7626
                        bstate <= BIDLE;
7627
                        L2_nxt <= TRUE;
7628
                end
7629
        end
7630
B12:
7631
    if (ack_i|err_i) begin
7632
        if (isCAS) begin
7633
             iqentry_res        [ casid[`QBITS] ] <= (dat_i == cas);
7634
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
7635
             iqentry_done[ casid[`QBITS] ] <= `VAL;
7636
             iqentry_instr[ casid[`QBITS]] <= `NOP_INSN;
7637
             iqentry_out [ casid[`QBITS] ] <= `INV;
7638
            if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
7639
            if (dat_i == cas) begin
7640
                 stb_o <= `LOW;
7641
                 we_o <= `TRUE;
7642
                 bstate <= B15;
7643
            end
7644
            else begin
7645
                 cas <= dat_i;
7646
                 cyc_o <= `LOW;
7647
                 stb_o <= `LOW;
7648
                 sel_o <= 8'h00;
7649
                case(bwhich)
7650
                2'b00:   dram0 <= `DRAMREQ_READY;
7651
                2'b01:   dram1 <= `DRAMREQ_READY;
7652
                2'b10:   dram2 <= `DRAMREQ_READY;
7653
                default:    ;
7654
                endcase
7655
                 bstate <= B19;
7656
            end
7657
        end
7658
        else if (isRMW) begin
7659
             rmw_instr <= iqentry_instr[casid[`QBITS]];
7660
             rmw_argA <= dat_i;
7661
                 if (isSpt) begin
7662
                        rmw_argB <= 64'd1 << iqentry_a1[casid[`QBITS]][63:58];
7663
                        rmw_argC <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ?
7664
                                                iqentry_a3[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58] :
7665
                                                iqentry_a2[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58];
7666
                 end
7667
                 else if (isInc) begin
7668
                        rmw_argB <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ? {{59{iqentry_instr[casid[`QBITS]][22]}},iqentry_instr[casid[`QBITS]][22:18]} :
7669
                                                                                                                                 {{59{iqentry_instr[casid[`QBITS]][17]}},iqentry_instr[casid[`QBITS]][17:13]};
7670
                 end
7671
                 else begin // isAMO
7672
                     iqentry_res [ casid[`QBITS] ] <= dat_i;
7673
                     rmw_argB <= iqentry_instr[casid[`QBITS]][31] ? {{59{iqentry_instr[casid[`QBITS]][20:16]}},iqentry_instr[casid[`QBITS]][20:16]} : iqentry_a2[casid[`QBITS]];
7674
                 end
7675
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
7676
             if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
7677
             stb_o <= `LOW;
7678
             bstate <= B20;
7679
                end
7680
        else begin
7681
             cyc_o <= `LOW;
7682
             stb_o <= `LOW;
7683
             sel_o <= 8'h00;
7684
             sr_o <= `LOW;
7685
             xdati <= dat_i;
7686
            case(bwhich)
7687
            2'b00:  begin
7688
                     dram0 <= `DRAMREQ_READY;
7689
                     iqentry_exc [ dram0_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
7690
                    if (err_i|rdv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
7691
                    end
7692
            2'b01:  begin
7693
                     dram1 <= `DRAMREQ_READY;
7694
                     iqentry_exc [ dram1_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
7695
                    if (err_i|rdv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
7696
                    end
7697
            2'b10:  begin
7698
                     dram2 <= `DRAMREQ_READY;
7699
                     iqentry_exc [ dram2_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
7700
                    if (err_i|rdv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
7701
                    end
7702
            default:    ;
7703
            endcase
7704
             bstate <= B19;
7705
        end
7706
    end
7707
// Three cycles to detemrine if there's a cache hit during a store.
7708
B16:    begin
7709
            case(bwhich)
7710
            2'd0:      if (dhit0) begin  dram0 <= `DRAMREQ_READY; bstate <= B17; end
7711
            2'd1:      if (dhit1) begin  dram1 <= `DRAMREQ_READY; bstate <= B17; end
7712
            2'd2:      if (dhit2) begin  dram2 <= `DRAMREQ_READY; bstate <= B17; end
7713
            default:    bstate <= BIDLE;
7714
            endcase
7715
            end
7716
B17:     bstate <= B18;
7717
B18:     bstate <= B19;
7718
B19:    if (~acki)  begin bstate <= BIDLE; isStore <= `FALSE; end
7719
B20:
7720
        if (~ack_i) begin
7721
                stb_o <= `HIGH;
7722
                we_o  <= `HIGH;
7723
                dat_o <= fnDato(rmw_instr,rmw_res);
7724
                bstate <= B1;
7725
        end
7726
B21:
7727
        if (~ack_i) begin
7728
                stb_o <= `HIGH;
7729
                bstate <= B12;
7730
        end
7731
default:     bstate <= BIDLE;
7732
endcase
7733
 
7734
if (!branchmiss) begin
7735
    case({fetchbuf0_v, fetchbuf1_v})
7736
    2'b00:  ;
7737
    2'b01:
7738
        if (canq1) begin
7739
                tail0 <= idp1(tail0);
7740
                tail1 <= idp1(tail1);
7741
        end
7742
    2'b10:
7743
        if (canq1) begin
7744
            tail0 <= idp1(tail0);
7745
            tail1 <= idp1(tail1);
7746
        end
7747
    2'b11:
7748
        if (canq1) begin
7749
            if (IsBranch(fetchbuf0_instr) && predict_taken0 && fetchbuf0_thrd==fetchbuf1_thrd) begin
7750
                 tail0 <= idp1(tail0);
7751
                 tail1 <= idp1(tail1);
7752
            end
7753
            else begin
7754
                                if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
7755
                        if (canq2) begin
7756
                             tail0 <= idp2(tail0);
7757
                             tail1 <= idp2(tail1);
7758
                        end
7759
                        else begin    // queued1 will be true
7760
                             tail0 <= idp1(tail0);
7761
                             tail1 <= idp1(tail1);
7762
                        end
7763
                end
7764
            end
7765
        end
7766
    endcase
7767
end
7768
`ifndef SUPPORT_SMT
7769
else begin      // if branchmiss
7770
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
7771
         tail0 <= 3'd0;
7772
         tail1 <= 3'd1;
7773
    end
7774
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
7775
         tail0 <= 3'd1;
7776
         tail1 <= 3'd2;
7777
    end
7778
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
7779
         tail0 <= 3'd2;
7780
         tail1 <= 3'd3;
7781
    end
7782
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
7783
         tail0 <= 3'd3;
7784
         tail1 <= 3'd4;
7785
    end
7786
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
7787
         tail0 <= 3'd4;
7788
         tail1 <= 3'd5;
7789
    end
7790
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
7791
         tail0 <= 3'd5;
7792
         tail1 <= 3'd6;
7793
    end
7794
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
7795
         tail0 <= 3'd6;
7796
         tail1 <= 3'd7;
7797
    end
7798
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
7799
         tail0 <= 3'd7;
7800
         tail1 <= 3'd0;
7801
    end
7802
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
7803
end
7804
`endif
7805
/*
7806
    if (pebm)
7807
         seq_num <= seq_num + 5'd3;
7808
    else if (queued2)
7809
         seq_num <= seq_num + 5'd2;
7810
    else if (queued1)
7811
         seq_num <= seq_num + 5'd1;
7812
*/
7813
//      #5 rf[0] = 0; rf_v[0] = 1; rf_source[0] = 0;
7814
        $display("\n\n\n\n\n\n\n\n");
7815
        $display("TIME %0d", $time);
7816
        $display("%h #", pc0);
7817
`ifdef SUPPORT_SMT
7818
    $display ("Regfile: %d", rgs[0]);
7819
        for (n=0; n < 32; n=n+4) begin
7820
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
7821
               n[4:0]+0, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
7822
               n[4:0]+1, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
7823
               n[4:0]+2, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
7824
               n[4:0]+3, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
7825
               );
7826
        end
7827
    $display ("Regfile: %d", rgs[1]);
7828
        for (n=128; n < 160; n=n+4) begin
7829
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
7830
               n[4:0]+0, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
7831
               n[4:0]+1, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
7832
               n[4:0]+2, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
7833
               n[4:0]+3, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
7834
               );
7835
        end
7836
`else
7837
    $display ("Regfile: %d", rgs);
7838
        for (n=0; n < 32; n=n+4) begin
7839
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
7840
               n[4:0]+0, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
7841
               n[4:0]+1, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
7842
               n[4:0]+2, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
7843
               n[4:0]+3, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
7844
               );
7845
        end
7846
`endif
7847
        $display("Call Stack:");
7848
        for (n = 0; n < 32; n = n + 4)
7849
                $display("%c%d: %h   %c%d: %h   %c%d: %h   %c%d: %h",
7850
                        ufb1.ursb1.rasp==n+0 ?">" : " ", n[4:0]+0, ufb1.ursb1.ras[n+0],
7851
                        ufb1.ursb1.rasp==n+1 ?">" : " ", n[4:0]+1, ufb1.ursb1.ras[n+1],
7852
                        ufb1.ursb1.rasp==n+2 ?">" : " ", n[4:0]+2, ufb1.ursb1.ras[n+2],
7853
                        ufb1.ursb1.rasp==n+3 ?">" : " ", n[4:0]+3, ufb1.ursb1.ras[n+3]
7854
                );
7855
        $display("\n");
7856
 
7857
//    $display("Return address stack:");
7858
//    for (n = 0; n < 16; n = n + 1)
7859
//        $display("%d %h", rasp+n[3:0], ras[rasp+n[3:0]]);
7860
        $display("TakeBr:%d #", take_branch);//, backpc);
7861
        $display("%c%c A: %d %h %h #",
7862
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
7863
        $display("%c%c B: %d %h %h #",
7864
            45, fetchbuf?45:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
7865
        $display("%c%c C: %d %h %h #",
7866
            45, fetchbuf?62:45, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
7867
        $display("%c%c D: %d %h %h #",
7868
            45, fetchbuf?62:45, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
7869
 
7870
        for (i=0; i<QENTRIES; i=i+1)
7871
            $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#",
7872
                 (i[`QBITS]==head0)?"C":".",
7873
                 (i[`QBITS]==tail0)?"Q":".",
7874
                  i[`QBITS],
7875
                 iqentry_v[i] ? "v" : "-",
7876
                 iqentry_iv[i] ? "I" : "-",
7877
                 iqentry_done[i]?"d":"-",
7878
                 iqentry_out[i]?"o":"-",
7879
                 iqentry_bt[i],
7880
                 iqentry_memissue[i],
7881
                 iqentry_agen[i] ? "a": "-",
7882
                 iqentry_alu0_issue[i]?"0":iqentry_alu1_issue[i]?"1":"-",
7883
                 iqentry_stomp[i]?"s":"-",
7884
                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",
7885
                iqentry_instr[i], iqentry_tgt[i][4:0],
7886
                iqentry_exc[i], iqentry_res[i], iqentry_a0[i], iqentry_a1[i], iqentry_a1_v[i],
7887
                iqentry_a1_s[i],
7888
                iqentry_a2[i], iqentry_a2_v[i], iqentry_a2_s[i],
7889
                iqentry_a3[i], iqentry_a3_v[i], iqentry_a3_s[i],
7890
                iqentry_thrd[i],
7891
                iqentry_pc[i],
7892
                iqentry_sn[i], iqentry_ven[i]
7893
                );
7894
    $display("DRAM");
7895
        $display("%d %h %h %c%h %o #",
7896
            dram0, dram0_addr, dram0_data, (IsFlowCtrl(dram0_instr) ? 98 : (IsMem(dram0_instr)) ? 109 : 97),
7897
            dram0_instr, dram0_id);
7898
        $display("%d %h %h %c%h %o #",
7899
            dram1, dram1_addr, dram1_data, (IsFlowCtrl(dram1_instr) ? 98 : (IsMem(dram1_instr)) ? 109 : 97),
7900
            dram1_instr, dram1_id);
7901
        $display("%d %h %h %c%h %o #",
7902
            dram2, dram2_addr, dram2_data, (IsFlowCtrl(dram2_instr) ? 98 : (IsMem(dram2_instr)) ? 109 : 97),
7903
            dram2_instr, dram2_id);
7904
        $display("%d %h %o %h #", dramA_v, dramA_bus, dramA_id, dramA_exc);
7905
        $display("%d %h %o %h #", dramB_v, dramB_bus, dramB_id, dramB_exc);
7906
        $display("%d %h %o %h #", dramC_v, dramC_bus, dramC_id, dramC_exc);
7907
    $display("ALU");
7908
        $display("%d %h %h %h %c%h %d %o %h #",
7909
                alu0_dataready, alu0_argI, alu0_argA, alu0_argB,
7910
                 (IsFlowCtrl(alu0_instr) ? 98 : IsMem(alu0_instr) ? 109 : 97),
7911
                alu0_instr, alu0_bt, alu0_sourceid, alu0_pc);
7912
        $display("%d %h %o 0 #", alu0_v, alu0_bus, alu0_id);
7913
 
7914
        $display("%d %h %h %h %c%h %d %o %h #",
7915
                alu1_dataready, alu1_argI, alu1_argA, alu1_argB,
7916
                 (IsFlowCtrl(alu1_instr) ? 98 : IsMem(alu1_instr) ? 109 : 97),
7917
                alu1_instr, alu1_bt, alu1_sourceid, alu1_pc);
7918
        $display("%d %h %o 0 #", alu1_v, alu1_bus, alu1_id);
7919
        $display("FCU");
7920
        $display("%d %h %h %h %h #", fcu_v, fcu_bus, fcu_argI, fcu_argA, fcu_argB);
7921
        $display("%c %h %h #", fcu_branchmiss?"m":" ", fcu_sourceid, fcu_misspc);
7922
    $display("Commit");
7923
        $display("0: %c %h %o %d #", commit0_v?"v":" ", commit0_bus, commit0_id, commit0_tgt[4:0]);
7924
        $display("1: %c %h %o %d #", commit1_v?"v":" ", commit1_bus, commit1_id, commit1_tgt[4:0]);
7925
    $display("instructions committed: %d ticks: %d ", I, tick);
7926
 
7927
//
7928
//      $display("\n\n\n\n\n\n\n\n");
7929
//      $display("TIME %0d", $time);
7930
//      $display("  pc0=%h", pc0);
7931
//      $display("  pc1=%h", pc1);
7932
//      $display("  reg0=%h, v=%d, src=%o", rf[0], rf_v[0], rf_source[0]);
7933
//      $display("  reg1=%h, v=%d, src=%o", rf[1], rf_v[1], rf_source[1]);
7934
//      $display("  reg2=%h, v=%d, src=%o", rf[2], rf_v[2], rf_source[2]);
7935
//      $display("  reg3=%h, v=%d, src=%o", rf[3], rf_v[3], rf_source[3]);
7936
//      $display("  reg4=%h, v=%d, src=%o", rf[4], rf_v[4], rf_source[4]);
7937
//      $display("  reg5=%h, v=%d, src=%o", rf[5], rf_v[5], rf_source[5]);
7938
//      $display("  reg6=%h, v=%d, src=%o", rf[6], rf_v[6], rf_source[6]);
7939
//      $display("  reg7=%h, v=%d, src=%o", rf[7], rf_v[7], rf_source[7]);
7940
 
7941
//      $display("Fetch Buffers:");
7942
//      $display("  %c%c fbA: v=%d instr=%h pc=%h     %c%c fbC: v=%d instr=%h pc=%h", 
7943
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc,
7944
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
7945
//      $display("  %c%c fbB: v=%d instr=%h pc=%h     %c%c fbD: v=%d instr=%h pc=%h", 
7946
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc,
7947
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
7948
//      $display("  branchback=%d backpc=%h", branchback, backpc);
7949
 
7950
//      $display("Instruction Queue:");
7951
//      for (i=0; i<8; i=i+1) 
7952
//          $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",
7953
//              (i[`QBITS]==head0)?72:32, (i[`QBITS]==tail0)?84:32, i,
7954
//              iqentry_v[i], iqentry_done[i], iqentry_out[i], iqentry_agen[i], iqentry_res[i], iqentry_op[i], 
7955
//              iqentry_bt[i], iqentry_tgt[i], iqentry_a1[i], iqentry_a1_v[i], iqentry_a1_s[i], iqentry_a2[i], iqentry_a2_v[i], 
7956
//              iqentry_a2_s[i], iqentry_a0[i], iqentry_pc[i], iqentry_exc[i]);
7957
 
7958
//      $display("Scheduling Status:");
7959
//      $display("  iqentry0 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
7960
//              iqentry_0_issue, iqentry_0_islot, iqentry_stomp[0], iqentry_source[0], iqentry_memready[0], iqentry_memissue[0]);
7961
//      $display("  iqentry1 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
7962
//              iqentry_1_issue, iqentry_1_islot, iqentry_stomp[1], iqentry_source[1], iqentry_memready[1], iqentry_memissue[1]);
7963
//      $display("  iqentry2 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
7964
//              iqentry_2_issue, iqentry_2_islot, iqentry_stomp[2], iqentry_source[2], iqentry_memready[2], iqentry_memissue[2]);
7965
//      $display("  iqentry3 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
7966
//              iqentry_3_issue, iqentry_3_islot, iqentry_stomp[3], iqentry_source[3], iqentry_memready[3], iqentry_memissue[3]);
7967
//      $display("  iqentry4 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
7968
//              iqentry_4_issue, iqentry_4_islot, iqentry_stomp[4], iqentry_source[4], iqentry_memready[4], iqentry_memissue[4]);
7969
//      $display("  iqentry5 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
7970
//              iqentry_5_issue, iqentry_5_islot, iqentry_stomp[5], iqentry_source[5], iqentry_memready[5], iqentry_memissue[5]);
7971
//      $display("  iqentry6 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
7972
//              iqentry_6_issue, iqentry_6_islot, iqentry_stomp[6], iqentry_source[6], iqentry_memready[6], iqentry_memissue[6]);
7973
//      $display("  iqentry7 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
7974
//              iqentry_7_issue, iqentry_7_islot, iqentry_stomp[7], iqentry_source[7], iqentry_memready[7], iqentry_memissue[7]);
7975
 
7976
//      $display("ALU Inputs:");
7977
//      $display("  0: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
7978
//              alu0_available, alu0_dataready, alu0_sourceid, alu0_op, alu0_argA,
7979
//              alu0_argB, alu0_argI, alu0_bt);
7980
//      $display("  1: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
7981
//              alu1_available, alu1_dataready, alu1_sourceid, alu1_op, alu1_argA,
7982
//              alu1_argB, alu1_argI, alu1_bt);
7983
 
7984
//      $display("ALU Outputs:");
7985
//      $display("  0: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
7986
//              alu0_v, alu0_bus, alu0_id, alu0_branchmiss, alu0_misspc, alu0_sourceid);
7987
//      $display("  1: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
7988
//              alu1_v, alu1_bus, alu1_id, alu1_branchmiss, alu1_misspc, alu1_sourceid);
7989
 
7990
//      $display("DRAM Status:");
7991
//      $display("  OUT: v=%d data=%h tgt=%d id=%o", dram_v, dram_bus, dram_tgt, dram_id);
7992
//      $display("  dram0: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
7993
//          dram0, dram0_addr, dram0_data, dram0_op, dram0_tgt, dram0_id);
7994
//      $display("  dram1: status=%h addr=%h data=%h op=%d tgt=%d id=%o", 
7995
//          dram1, dram1_addr, dram1_data, dram1_op, dram1_tgt, dram1_id);
7996
//      $display("  dram2: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
7997
//          dram2, dram2_addr, dram2_data, dram2_op, dram2_tgt, dram2_id);
7998
 
7999
//      $display("Commit Buses:");
8000
//      $display("  0: v=%d id=%o data=%h", commit0_v, commit0_id, commit0_bus);
8001
//      $display("  1: v=%d id=%o data=%h", commit1_v, commit1_id, commit1_bus);
8002
 
8003
//
8004
//      $display("Memory Contents:");
8005
//      for (j=0; j<64; j=j+16)
8006
//          $display("  %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h", 
8007
//              m[j+0], m[j+1], m[j+2], m[j+3], m[j+4], m[j+5], m[j+6], m[j+7],
8008
//              m[j+8], m[j+9], m[j+10], m[j+11], m[j+12], m[j+13], m[j+14], m[j+15]);
8009
 
8010
        $display("");
8011
 
8012
        if (|panic) begin
8013
            $display("");
8014
            $display("-----------------------------------------------------------------");
8015
            $display("-----------------------------------------------------------------");
8016
            $display("---------------     PANIC:%s     -----------------", message[panic]);
8017
            $display("-----------------------------------------------------------------");
8018
            $display("-----------------------------------------------------------------");
8019
            $display("");
8020
            $display("instructions committed: %d", I);
8021
            $display("total execution cycles: %d", $time / 10);
8022
            $display("");
8023
        end
8024
        if (|panic && ~outstanding_stores) begin
8025
            $finish;
8026
        end
8027
    for (n = 0; n < QENTRIES; n = n + 1)
8028
        if (branchmiss) begin
8029
            if (!setpred[n]) begin
8030
                 iqentry_instr[n][`INSTRUCTION_OP] <= `NOP;
8031
                 iqentry_done[n] <= `VAL;
8032
                 iqentry_cmt[n] <= `VAL;
8033
            end
8034
        end
8035
 
8036
        if (snr) begin
8037
                seq_num <= 32'd0;
8038
                seq_num1 <= 32'd0;
8039
        end
8040
end // clock domain
8041
/*
8042
always @(posedge clk)
8043
if (rst) begin
8044
     tail0 <= 3'd0;
8045
     tail1 <= 3'd1;
8046
end
8047
else begin
8048
if (!branchmiss) begin
8049
    case({fetchbuf0_v, fetchbuf1_v})
8050
    2'b00:  ;
8051
    2'b01:
8052
        if (canq1) begin
8053
             tail0 <= idp1(tail0);
8054
             tail1 <= idp1(tail1);
8055
        end
8056
    2'b10:
8057
        if (canq1) begin
8058
             tail0 <= idp1(tail0);
8059
             tail1 <= idp1(tail1);
8060
        end
8061
    2'b11:
8062
        if (canq1) begin
8063
            if (IsBranch(fetchbuf0_instr) && predict_taken0) begin
8064
                 tail0 <= idp1(tail0);
8065
                 tail1 <= idp1(tail1);
8066
            end
8067
            else begin
8068
                                if (vqe < vl || !IsVector(fetchbuf0_instr)) begin
8069
                        if (canq2) begin
8070
                             tail0 <= idp2(tail0);
8071
                             tail1 <= idp2(tail1);
8072
                        end
8073
                        else begin    // queued1 will be true
8074
                             tail0 <= idp1(tail0);
8075
                             tail1 <= idp1(tail1);
8076
                        end
8077
                end
8078
            end
8079
        end
8080
    endcase
8081
end
8082
else begin      // if branchmiss
8083
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
8084
         tail0 <= 3'd0;
8085
         tail1 <= 3'd1;
8086
    end
8087
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
8088
         tail0 <= 3'd1;
8089
         tail1 <= 3'd2;
8090
    end
8091
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
8092
         tail0 <= 3'd2;
8093
         tail1 <= 3'd3;
8094
    end
8095
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
8096
         tail0 <= 3'd3;
8097
         tail1 <= 3'd4;
8098
    end
8099
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
8100
         tail0 <= 3'd4;
8101
         tail1 <= 3'd5;
8102
    end
8103
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
8104
         tail0 <= 3'd5;
8105
         tail1 <= 3'd6;
8106
    end
8107
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
8108
         tail0 <= 3'd6;
8109
         tail1 <= 3'd7;
8110
    end
8111
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
8112
         tail0 <= 3'd7;
8113
         tail1 <= 3'd0;
8114
    end
8115
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
8116
end
8117
end
8118
*/
8119
/*
8120
always @(posedge clk)
8121
if (rst)
8122
     seq_num <= 5'd0;
8123
else begin
8124
    if (pebm)
8125
         seq_num <= seq_num + 5'd3;
8126
    else if (queued2)
8127
         seq_num <= seq_num + 5'd2;
8128
    else if (queued1)
8129
         seq_num <= seq_num + 5'd1;
8130
end
8131
*/
8132
// Increment the head pointers
8133
// Also increments the instruction counter
8134
// Used when instructions are committed.
8135
// Also clear any outstanding state bits that foul things up.
8136
//
8137
task head_inc;
8138
input [`QBITS] amt;
8139
begin
8140
     head0 <= head0 + amt;
8141
     head1 <= head1 + amt;
8142
     head2 <= head2 + amt;
8143
     head3 <= head3 + amt;
8144
     head4 <= head4 + amt;
8145
     head5 <= head5 + amt;
8146
     head6 <= head6 + amt;
8147
     head7 <= head7 + amt;
8148
     I <= I + amt;
8149
    if (amt==3'd2) begin
8150
     iqentry_agen[head0] <= `INV;
8151
     iqentry_agen[head1] <= `INV;
8152
    end else if (amt==3'd1) begin
8153
             iqentry_agen[head0] <= `INV;
8154
        end
8155
end
8156
endtask
8157
 
8158
task setargs;
8159
input [`QBITS] nn;
8160
input [4:0] id;
8161
input v;
8162
input [63:0] bus;
8163
begin
8164
  if (iqentry_a1_v[nn] == `INV && iqentry_a1_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8165
                iqentry_a1[nn] <= bus;
8166
                iqentry_a1_v[nn] <= `VAL;
8167
  end
8168
  if (iqentry_a2_v[nn] == `INV && iqentry_a2_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8169
                iqentry_a2[nn] <= bus;
8170
                iqentry_a2_v[nn] <= `VAL;
8171
  end
8172
  if (iqentry_a3_v[nn] == `INV && iqentry_a3_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8173
                iqentry_a3[nn] <= bus;
8174
                iqentry_a3_v[nn] <= `VAL;
8175
  end
8176
end
8177
endtask
8178
 
8179
task setinsn;
8180
input [`QBITS] nn;
8181
input [4:0] id;
8182
input v;
8183
input [127:0] bus;
8184
begin
8185
  if (iqentry_iv[nn] == `INV && iqentry_is[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8186
        iqentry_iv   [nn]  <= `VAL;
8187
//      iqentry_Rt   [nn]  <= bus[`IB_RT];
8188
//      iqentry_Rc   [nn]  <= bus[`IB_RC];
8189
//      iqentry_Ra   [nn]  <= bus[`IB_RA];
8190
        iqentry_a0       [nn]  <= bus[`IB_CONST];
8191
        iqentry_imm  [nn]  <= bus[`IB_IMM];
8192
                iqentry_insln[nn]  <= bus[`IB_LN];
8193
                iqentry_bt   [nn]  <= bus[`IB_BT];
8194
                iqentry_alu  [nn]  <= bus[`IB_ALU];
8195
                iqentry_alu0 [nn]  <= bus[`IB_ALU0];
8196
                iqentry_fpu  [nn]  <= bus[`IB_FPU];
8197
                iqentry_fc   [nn]  <= bus[`IB_FC];
8198
                iqentry_canex[nn]  <= bus[`IB_CANEX];
8199
                iqentry_load [nn]  <= bus[`IB_LOAD];
8200
                iqentry_preload[nn]<= bus[`IB_PRELOAD];
8201
                iqentry_mem  [nn]  <= bus[`IB_MEM];
8202
                iqentry_memndx[nn] <= bus[`IB_MEMNDX];
8203
                iqentry_rmw  [nn]  <= bus[`IB_RMW];
8204
                iqentry_memdb[nn]  <= bus[`IB_MEMDB];
8205
                iqentry_memsb[nn]  <= bus[`IB_MEMSB];
8206
                iqentry_shft48[nn] <= bus[`IB_SHFT48];
8207
                iqentry_sei      [nn]    <= bus[`IB_SEI];
8208
                iqentry_aq   [nn]  <= bus[`IB_AQ];
8209
                iqentry_rl   [nn]  <= bus[`IB_RL];
8210
                iqentry_jmp  [nn]  <= bus[`IB_JMP];
8211
                iqentry_br   [nn]  <= bus[`IB_BR];
8212
                iqentry_sync [nn]  <= bus[`IB_SYNC];
8213
                iqentry_fsync[nn]  <= bus[`IB_FSYNC];
8214
        iqentry_rfw  [nn]  <= bus[`IB_RFW];
8215
        iqentry_we   [nn]  <= bus[`IB_WE];
8216
  end
8217
end
8218
endtask
8219
 
8220
// Enqueue fetchbuf0 onto the tail of the instruction queue
8221
task enque0;
8222
input [`QBITS] tail;
8223
input [63:0] seqnum;
8224
input [5:0] venno;
8225
begin
8226
        iqentry_exc[tail] <= `FLT_NONE;
8227
`ifdef SUPPORT_DBG
8228
    if (dbg_imatchA)
8229
        iqentry_exc[tail] <= `FLT_DBG;
8230
    else if (dbg_ctrl[63])
8231
        iqentry_exc[tail] <= `FLT_SSM;
8232
`endif
8233
        iqentry_sn   [tail]    <=  seqnum;
8234
        iqentry_v    [tail]    <=   `VAL;
8235
        iqentry_iv       [tail]    <=   `INV;
8236
        iqentry_is   [tail]    <= tail;
8237
        iqentry_thrd [tail]    <=   fetchbuf0_thrd;
8238
        iqentry_done [tail]    <=    `INV;
8239
        iqentry_cmt  [tail]    <=       `INV;
8240
        iqentry_out  [tail]    <=    `INV;
8241
        iqentry_res  [tail]    <=    `ZERO;
8242
        iqentry_instr[tail]    <=    IsVLS(fetchbuf0_instr) ? (vm[fnM2(fetchbuf0_instr)] ? fetchbuf0_instr : `NOP_INSN) : fetchbuf0_instr;
8243
        iqentry_pt   [tail]    <=  predict_taken0;
8244
        iqentry_agen [tail]    <=    `INV;
8245
        iqentry_state[tail]    <=   IQS_IDLE;
8246
// If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
8247
// inherit the previous pc.
8248
//if (IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15] &&
8249
//   (IsBrk(iqentry_instr[idm1(tail)]) && !iqentry_instr[idm1(tail1)][15] && iqentry_v[idm1(tail)]))
8250
//   iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
8251
//else
8252
         iqentry_pc   [tail] <= fetchbuf0_pc;
8253
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf0_instr);
8254
        iqentry_tgt  [tail]    <=       Rt0;
8255
        iqentry_Ra   [tail]    <= Ra0;
8256
        iqentry_Rb   [tail]    <= Rb0;
8257
        iqentry_Rc   [tail]    <= Rc0;
8258
        iqentry_vl   [tail]    <=  vl;
8259
        iqentry_ven  [tail]    <=   venno;
8260
        iqentry_exc  [tail]    <=    `EXC_NONE;
8261
        iqentry_a1   [tail]    <=    rfoa0;
8262
        iqentry_a1_v [tail]    <=    Source1Valid(fetchbuf0_instr) | regIsValid[Ra0s];
8263
        iqentry_a1_s [tail]    <=    rf_source[Ra0s];
8264
        iqentry_a2   [tail]    <=    rfob0;
8265
        iqentry_a2_v [tail]    <=    Source2Valid(fetchbuf0_instr) | regIsValid[Rb0s];
8266
        iqentry_a2_s [tail]    <=    rf_source[Rb0s];
8267
        iqentry_a3   [tail]    <=    rfoc0;
8268
        iqentry_a3_v [tail]    <=    Source3Valid(fetchbuf0_instr) | regIsValid[Rc0s];
8269
        iqentry_a3_s [tail]    <=    rf_source[Rc0s];
8270
end
8271
endtask
8272
 
8273
// Enque fetchbuf1. Fetchbuf1 might be the second instruction to queue so some
8274
// of this code checks to see which tail it is being queued on.
8275
task enque1;
8276
input [`QBITS] tail;
8277
input [63:0] seqnum;
8278
input [5:0] venno;
8279
begin
8280
 iqentry_exc[tail] <= `FLT_NONE;
8281
`ifdef SUPPORT_DBG
8282
    if (dbg_imatchB)
8283
        iqentry_exc[tail] <= `FLT_DBG;
8284
    else if (dbg_ctrl[63])
8285
        iqentry_exc[tail] <= `FLT_SSM;
8286
`endif
8287
        iqentry_sn   [tail]    <=   seqnum;
8288
        iqentry_v    [tail]    <=   `VAL;
8289
        iqentry_iv       [tail]    <=   `INV;
8290
        iqentry_is   [tail]    <= tail;
8291
        iqentry_thrd [tail]    <=   fetchbuf1_thrd;
8292
        iqentry_done [tail]    <=   `INV;
8293
        iqentry_cmt  [tail]    <=       `INV;
8294
        iqentry_out  [tail]    <=   `INV;
8295
        iqentry_res  [tail]    <=   `ZERO;
8296
        iqentry_instr[tail]    <=   IsVLS(fetchbuf1_instr) ? (vm[fnM2(fetchbuf1_instr)] ? fetchbuf1_instr : `NOP_INSN) : fetchbuf1_instr;
8297
        iqentry_pt   [tail]    <=  predict_taken1;
8298
        iqentry_agen [tail]    <=   `INV;
8299
        iqentry_state[tail]    <=   IQS_IDLE;
8300
// If queing 2nd instruction must read from first
8301
if (tail==tail1) begin
8302
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
8303
    // inherit the previous pc.
8304
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
8305
//        IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15])
8306
//       iqentry_pc   [tail]    <= fetchbuf0_pc;
8307
//    else
8308
                iqentry_pc   [tail] <= fetchbuf1_pc;
8309
end
8310
else begin
8311
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
8312
    // inherit the previous pc.
8313
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
8314
//       (IsBrk(iqentry_instr[idp7(tail)]) && !iqentry_instr[idm1(tail)][15] && iqentry_v[idm1(tail)]))
8315
//       iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
8316
//    else
8317
                iqentry_pc   [tail] <= fetchbuf1_pc;
8318
end
8319
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf1_instr);
8320
        iqentry_tgt  [tail]    <= Rt1;
8321
        iqentry_Ra   [tail]    <= Ra1;
8322
        iqentry_Rb   [tail]    <= Rb1;
8323
        iqentry_Rc   [tail]    <= Rc1;
8324
        iqentry_vl   [tail]    <=  vl;
8325
        iqentry_ven  [tail]    <=   venno;
8326
        iqentry_exc  [tail]    <=   `EXC_NONE;
8327
        iqentry_a1   [tail]    <=       rfoa1;
8328
        iqentry_a1_v [tail]    <=       Source1Valid(fetchbuf1_instr) | regIsValid[Ra1s];
8329
        iqentry_a1_s [tail]    <=       rf_source[Ra1s];
8330
        iqentry_a2   [tail]    <=       rfob1;
8331
        iqentry_a2_v [tail]    <=       Source2Valid(fetchbuf1_instr) | regIsValid[Rb1s];
8332
        iqentry_a2_s [tail]    <=       rf_source[Rb1s];
8333
        iqentry_a3   [tail]    <=       rfoc1;
8334
        iqentry_a3_v [tail]    <=       Source3Valid(fetchbuf1_instr) | regIsValid[Rc1s];
8335
        iqentry_a3_s [tail]    <=       rf_source[Rc1s];
8336
end
8337
endtask
8338
 
8339
function IsOddball;
8340
input [`QBITS] head;
8341
if (|iqentry_exc[head])
8342
    IsOddball = TRUE;
8343
else
8344
case(iqentry_instr[head][`INSTRUCTION_OP])
8345
`BRK:   IsOddball = TRUE;
8346
`IVECTOR:
8347
    case(iqentry_instr[head][`INSTRUCTION_S2])
8348
    `VSxx:  IsOddball = TRUE;
8349
    default:    IsOddball = FALSE;
8350
    endcase
8351
`RR:
8352
    case(iqentry_instr[head][`INSTRUCTION_S2])
8353
    `VMOV:  IsOddball = TRUE;
8354
    `SEI,`RTI,`CACHEX: IsOddball = TRUE;
8355
    default:    IsOddball = FALSE;
8356
    endcase
8357
`CSRRW,`REX,`CACHE,`FLOAT:  IsOddball = TRUE;
8358
default:    IsOddball = FALSE;
8359
endcase
8360
endfunction
8361
 
8362
// This task takes care of commits for things other than the register file.
8363
task oddball_commit;
8364
input v;
8365
input [`QBITS] head;
8366
reg thread;
8367
begin
8368
    thread = iqentry_thrd[head];
8369
    if (v) begin
8370
        if (|iqentry_exc[head]) begin
8371
            excmiss <= TRUE;
8372
`ifdef SUPPORT_SMT
8373
                excmisspc <= {tvec[3'd0][31:8],ol[thread],5'h00};
8374
            excthrd <= iqentry_thrd[head];
8375
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
8376
            epc0[thread] <= iqentry_pc[head]+ 32'd4;
8377
            epc1[thread] <= epc0[thread];
8378
            epc2[thread] <= epc1[thread];
8379
            epc3[thread] <= epc2[thread];
8380
            epc4[thread] <= epc3[thread];
8381
            epc5[thread] <= epc4[thread];
8382
            epc6[thread] <= epc5[thread];
8383
            epc7[thread] <= epc6[thread];
8384
            epc8[thread] <= epc7[thread];
8385
            im_stack[thread] <= {im_stack[thread][27:0],im};
8386
            ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
8387
            pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
8388
            rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
8389
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
8390
            mstatus[thread][5:3] <= 3'd0;
8391
            mstatus[thread][13:6] <= 8'h00;
8392
            mstatus[thread][19:14] <= 6'd0;
8393
`else
8394
                excmisspc <= {tvec[3'd0][31:8],ol,5'h00};
8395
            excthrd <= iqentry_thrd[head];
8396
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
8397
            epc0 <= iqentry_pc[head]+ 32'd4;
8398
            epc1 <= epc0;
8399
            epc2 <= epc1;
8400
            epc3 <= epc2;
8401
            epc4 <= epc3;
8402
            epc5 <= epc4;
8403
            epc6 <= epc5;
8404
            epc7 <= epc6;
8405
            epc8 <= epc7;
8406
            im_stack <= {im_stack[27:0],im};
8407
            ol_stack <= {ol_stack[13:0],ol};
8408
            pl_stack <= {pl_stack[55:0],cpl};
8409
            rs_stack <= {rs_stack[55:0],rgs};
8410
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
8411
            mstatus[5:3] <= 3'd0;
8412
            mstatus[13:6] <= 8'h00;
8413
            mstatus[19:14] <= 6'd0;
8414
`endif
8415
            sema[0] <= 1'b0;
8416
            ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
8417
`ifdef SUPPORT_DBG
8418
            dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
8419
            dbg_ctrl[63] <= FALSE;
8420
`endif
8421
        end
8422
        else
8423
        case(iqentry_instr[head][`INSTRUCTION_OP])
8424
        `BRK:
8425
                        // BRK is treated as a nop unless it's a software interrupt or a
8426
                        // hardware interrupt at a higher priority than the current priority.
8427
                if ((iqentry_instr[head][23:19] > 5'd0) || iqentry_instr[head][18:16] > im) begin
8428
                            excmiss <= TRUE;
8429
`ifdef SUPPORT_SMT
8430
                        excmisspc <= {tvec[3'd0][31:8],ol[thread],5'h00};
8431
                        excthrd <= iqentry_thrd[head];
8432
                    epc0[thread] <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
8433
                    epc1[thread] <= epc0[thread];
8434
                    epc2[thread] <= epc1[thread];
8435
                    epc3[thread] <= epc2[thread];
8436
                    epc4[thread] <= epc3[thread];
8437
                    epc5[thread] <= epc4[thread];
8438
                    epc6[thread] <= epc5[thread];
8439
                    epc7[thread] <= epc6[thread];
8440
                    epc8[thread] <= epc7[thread];
8441
                    im_stack[thread] <= {im_stack[thread][27:0],im};
8442
                    ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
8443
                    pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
8444
                    rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
8445
                    mstatus[thread][19:14] <= 6'd0;
8446
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
8447
                    mstatus[thread][5:3] <= 3'd0;
8448
                        mstatus[thread][13:6] <= 8'h00;
8449
                    // For hardware interrupts only, set a new mask level
8450
                    // Select register set according to interrupt level
8451
                    if (iqentry_instr[head][23:19]==5'd0) begin
8452
                        mstatus[thread][2:0] <= 3'd7;//iqentry_instr[head][18:16];
8453
                        mstatus[thread][42:40] <= iqentry_instr[head][18:16];
8454
                        mstatus[thread][19:14] <= {3'b0,iqentry_instr[head][18:16]};
8455
                    end
8456
                    else
8457
                        mstatus[thread][19:14] <= 6'd0;
8458
`else
8459
                        excmisspc <= {tvec[3'd0][31:8],ol,5'h00};
8460
                        excthrd <= iqentry_thrd[head];
8461
                    epc0 <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
8462
                    epc1 <= epc0;
8463
                    epc2 <= epc1;
8464
                    epc3 <= epc2;
8465
                    epc4 <= epc3;
8466
                    epc5 <= epc4;
8467
                    epc6 <= epc5;
8468
                    epc7 <= epc6;
8469
                    epc8 <= epc7;
8470
                    im_stack <= {im_stack[27:0],im};
8471
                    ol_stack <= {ol_stack[13:0],ol};
8472
                    pl_stack <= {pl_stack[55:0],cpl};
8473
                    rs_stack <= {rs_stack[55:0],rgs};
8474
                    mstatus[19:14] <= 6'd0;
8475
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
8476
                    mstatus[5:3] <= 3'd0;
8477
                        mstatus[13:6] <= 8'h00;
8478
                    // For hardware interrupts only, set a new mask level
8479
                    // Select register set according to interrupt level
8480
                    if (iqentry_instr[head][23:19]==5'd0) begin
8481
                        mstatus[2:0] <= 3'd7;//iqentry_instr[head][18:16];
8482
                        mstatus[42:40] <= iqentry_instr[head][18:16];
8483
                        mstatus[19:14] <= {3'b0,iqentry_instr[head][18:16]};
8484
                    end
8485
                    else
8486
                        mstatus[19:14] <= 6'd0;
8487
`endif
8488
                    sema[0] <= 1'b0;
8489
                    ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
8490
`ifdef SUPPORT_DBG
8491
                    dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
8492
                    dbg_ctrl[63] <= FALSE;
8493
`endif
8494
                end
8495
        `IVECTOR:
8496
            casez(iqentry_tgt[head])
8497
            8'b00100xxx:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
8498
            8'b00101111:  vl <= iqentry_res[head];
8499
            default:    ;
8500
            endcase
8501
        `R2:
8502
            case(iqentry_instr[head][`INSTRUCTION_S2])
8503
            `R1:        case(iqentry_instr[head][20:16])
8504
                        `CHAIN_OFF:     cr0[18] <= 1'b0;
8505
                        `CHAIN_ON:      cr0[18] <= 1'b1;
8506
                        //`SETWB:               wbrcd[pcr[5:0]] <= 1'b1;
8507
                        default:        ;
8508
                                endcase
8509
            `VMOV:  casez(iqentry_tgt[head])
8510
                    12'b1111111_00???:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
8511
                    12'b1111111_01111:  vl <= iqentry_res[head];
8512
                    default:    ;
8513
                    endcase
8514
`ifdef SUPPORT_SMT
8515
            `SEI:   mstatus[thread][2:0] <= iqentry_res[head][2:0];   // S1
8516
`else
8517
            `SEI:   mstatus[2:0] <= iqentry_res[head][2:0];   // S1
8518
`endif
8519
            `RTI:   begin
8520
                            excmiss <= TRUE;
8521
`ifdef SUPPORT_SMT
8522
                        excmisspc <= epc0[thread];
8523
                        excthrd <= thread;
8524
                        mstatus[thread][3:0] <= im_stack[thread][3:0];
8525
                        mstatus[thread][5:4] <= ol_stack[thread][1:0];
8526
                        mstatus[thread][13:6] <= pl_stack[thread][7:0];
8527
                        mstatus[thread][19:14] <= rs_stack[thread][5:0];
8528
                        im_stack[thread] <= {4'd15,im_stack[thread][27:4]};
8529
                        ol_stack[thread] <= {2'd0,ol_stack[thread][15:2]};
8530
                        pl_stack[thread] <= {8'h00,pl_stack[thread][63:8]};
8531
                        rs_stack[thread] <= {8'h00,rs_stack[thread][63:8]};
8532
                    epc0[thread] <= epc1[thread];
8533
                    epc1[thread] <= epc2[thread];
8534
                    epc2[thread] <= epc3[thread];
8535
                    epc3[thread] <= epc4[thread];
8536
                    epc4[thread] <= epc5[thread];
8537
                    epc5[thread] <= epc6[thread];
8538
                    epc6[thread] <= epc7[thread];
8539
                    epc7[thread] <= epc8[thread];
8540
                    epc8[thread] <= {tvec[0][31:8], ol[thread], 5'h0};
8541
`else
8542
                        excmisspc <= epc0;
8543
                        excthrd <= thread;
8544
                        mstatus[3:0] <= im_stack[3:0];
8545
                        mstatus[5:4] <= ol_stack[1:0];
8546
                        mstatus[13:6] <= pl_stack[7:0];
8547
                        mstatus[19:14] <= rs_stack[5:0];
8548
                        im_stack <= {4'd15,im_stack[31:4]};
8549
                        ol_stack <= {2'd0,ol_stack[15:2]};
8550
                        pl_stack <= {8'h00,pl_stack[63:8]};
8551
                        rs_stack <= {8'h00,rs_stack[63:8]};
8552
                    epc0 <= epc1;
8553
                    epc1 <= epc2;
8554
                    epc2 <= epc3;
8555
                    epc3 <= epc4;
8556
                    epc4 <= epc5;
8557
                    epc5 <= epc6;
8558
                    epc6 <= epc7;
8559
                    epc7 <= epc8;
8560
                    epc8 <= {tvec[0][31:8], ol, 5'h0};
8561
`endif
8562
                    sema[0] <= 1'b0;
8563
                    sema[iqentry_res[head][5:0]] <= 1'b0;
8564
                    vqe0  <= ve_hold[ 5: 0];
8565
                    vqet0 <= ve_hold[21:16];
8566
                    vqe1  <= ve_hold[37:32];
8567
                    vqet1 <= ve_hold[53:48];
8568
`ifdef SUPPORT_DBG
8569
                    dbg_ctrl[62:55] <= {FALSE,dbg_ctrl[62:56]};
8570
                    dbg_ctrl[63] <= dbg_ctrl[55];
8571
`endif
8572
                    end
8573
            `CACHEX:
8574
                    case(iqentry_instr[head][20:16])
8575
                    5'h03:  invic <= TRUE;
8576
                    5'h10:  cr0[30] <= FALSE;
8577
                    5'h11:  cr0[30] <= TRUE;
8578
                    default:    ;
8579
                    endcase
8580
            default: ;
8581
            endcase
8582
        `CSRRW:
8583
                        begin
8584
                        write_csr(iqentry_instr[head][31:16],iqentry_a1[head],thread);
8585
                        end
8586
        `REX:
8587
`ifdef SUPPORT_SMT
8588
            // Can only redirect to a lower level
8589
            if (ol[thread] < iqentry_instr[head][13:11]) begin
8590
                mstatus[thread][5:3] <= iqentry_instr[head][13:11];
8591
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol[thread]}];
8592
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol[thread]}];
8593
                mstatus[thread][13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
8594
            end
8595
`else
8596
            if (ol < iqentry_instr[head][13:11]) begin
8597
                mstatus[5:3] <= iqentry_instr[head][13:11];
8598
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol}];
8599
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol}];
8600
                mstatus[13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
8601
            end
8602
`endif
8603
        `CACHE:
8604
            case(iqentry_instr[head][15:11])
8605
            5'h03:  invic <= TRUE;
8606
            5'h10:  cr0[30] <= FALSE;
8607
            5'h11:  cr0[30] <= TRUE;
8608
            default:    ;
8609
            endcase
8610
        `FLOAT:
8611
            case(iqentry_instr[head][`INSTRUCTION_S2])
8612
            `FRM:   fp_rm <= iqentry_res[head][2:0];
8613
            `FCX:
8614
                begin
8615
                    fp_sx <= fp_sx & ~iqentry_res[head][5];
8616
                    fp_inex <= fp_inex & ~iqentry_res[head][4];
8617
                    fp_dbzx <= fp_dbzx & ~(iqentry_res[head][3]|iqentry_res[head][0]);
8618
                    fp_underx <= fp_underx & ~iqentry_res[head][2];
8619
                    fp_overx <= fp_overx & ~iqentry_res[head][1];
8620
                    fp_giopx <= fp_giopx & ~iqentry_res[head][0];
8621
                    fp_infdivx <= fp_infdivx & ~iqentry_res[head][0];
8622
                    fp_zerozerox <= fp_zerozerox & ~iqentry_res[head][0];
8623
                    fp_subinfx   <= fp_subinfx   & ~iqentry_res[head][0];
8624
                    fp_infzerox  <= fp_infzerox  & ~iqentry_res[head][0];
8625
                    fp_NaNCmpx   <= fp_NaNCmpx   & ~iqentry_res[head][0];
8626
                    fp_swtx <= 1'b0;
8627
                end
8628
            `FDX:
8629
                begin
8630
                    fp_inexe <= fp_inexe     & ~iqentry_res[head][4];
8631
                    fp_dbzxe <= fp_dbzxe     & ~iqentry_res[head][3];
8632
                    fp_underxe <= fp_underxe & ~iqentry_res[head][2];
8633
                    fp_overxe <= fp_overxe   & ~iqentry_res[head][1];
8634
                    fp_invopxe <= fp_invopxe & ~iqentry_res[head][0];
8635
                end
8636
            `FEX:
8637
                begin
8638
                    fp_inexe <= fp_inexe     | iqentry_res[head][4];
8639
                    fp_dbzxe <= fp_dbzxe     | iqentry_res[head][3];
8640
                    fp_underxe <= fp_underxe | iqentry_res[head][2];
8641
                    fp_overxe <= fp_overxe   | iqentry_res[head][1];
8642
                    fp_invopxe <= fp_invopxe | iqentry_res[head][0];
8643
                end
8644
            default:
8645
                begin
8646
                    // 31 to 29 is rounding mode
8647
                    // 28 to 24 are exception enables
8648
                    // 23 is nsfp
8649
                    // 22 is a fractie
8650
                    fp_fractie <= iqentry_a0[head][22];
8651
                    fp_raz <= iqentry_a0[head][21];
8652
                    // 20 is a 0
8653
                    fp_neg <= iqentry_a0[head][19];
8654
                    fp_pos <= iqentry_a0[head][18];
8655
                    fp_zero <= iqentry_a0[head][17];
8656
                    fp_inf <= iqentry_a0[head][16];
8657
                    // 15 swtx
8658
                    // 14 
8659
                    fp_inex <= fp_inex | (fp_inexe & iqentry_a0[head][14]);
8660
                    fp_dbzx <= fp_dbzx | (fp_dbzxe & iqentry_a0[head][13]);
8661
                    fp_underx <= fp_underx | (fp_underxe & iqentry_a0[head][12]);
8662
                    fp_overx <= fp_overx | (fp_overxe & iqentry_a0[head][11]);
8663
                    //fp_giopx <= fp_giopx | (fp_giopxe & iqentry_res2[head][10]);
8664
                    //fp_invopx <= fp_invopx | (fp_invopxe & iqentry_res2[head][24]);
8665
                    //
8666
                    fp_cvtx <= fp_cvtx |  (fp_giopxe & iqentry_a0[head][7]);
8667
                    fp_sqrtx <= fp_sqrtx |  (fp_giopxe & iqentry_a0[head][6]);
8668
                    fp_NaNCmpx <= fp_NaNCmpx |  (fp_giopxe & iqentry_a0[head][5]);
8669
                    fp_infzerox <= fp_infzerox |  (fp_giopxe & iqentry_a0[head][4]);
8670
                    fp_zerozerox <= fp_zerozerox |  (fp_giopxe & iqentry_a0[head][3]);
8671
                    fp_infdivx <= fp_infdivx | (fp_giopxe & iqentry_a0[head][2]);
8672
                    fp_subinfx <= fp_subinfx | (fp_giopxe & iqentry_a0[head][1]);
8673
                    fp_snanx <= fp_snanx | (fp_giopxe & iqentry_a0[head][0]);
8674
 
8675
                end
8676
            endcase
8677
        default:    ;
8678
        endcase
8679
        // Once the flow control instruction commits, NOP it out to allow
8680
        // pending stores to be issued.
8681
        iqentry_instr[head][5:0] <= `NOP;
8682
    end
8683
end
8684
endtask
8685
 
8686
// CSR access tasks
8687
task read_csr;
8688
input [13:0] csrno;
8689
output [63:0] dat;
8690
input thread;
8691
begin
8692
`ifdef SUPPORT_SMT
8693
    if (csrno[11:10] >= ol[thread])
8694
`else
8695
    if (csrno[11:10] >= ol)
8696
`endif
8697
    casez(csrno[9:0])
8698
    `CSR_CR0:       dat <= cr0;
8699
    `CSR_HARTID:    dat <= hartid;
8700
    `CSR_TICK:      dat <= tick;
8701
    `CSR_PCR:       dat <= pcr;
8702
    `CSR_PCR2:      dat <= pcr2;
8703
    `CSR_WBRCD:         dat <= wbrcd;
8704
    `CSR_SEMA:      dat <= sema;
8705
    `CSR_SBL:       dat <= sbl;
8706
    `CSR_SBU:       dat <= sbu;
8707
    `CSR_TCB:           dat <= tcb;
8708
    `CSR_FSTAT:     dat <= {fp_rgs,fp_status};
8709
`ifdef SUPPORT_DBG
8710
    `CSR_DBAD0:     dat <= dbg_adr0;
8711
    `CSR_DBAD1:     dat <= dbg_adr1;
8712
    `CSR_DBAD2:     dat <= dbg_adr2;
8713
    `CSR_DBAD3:     dat <= dbg_adr3;
8714
    `CSR_DBCTRL:    dat <= dbg_ctrl;
8715
    `CSR_DBSTAT:    dat <= dbg_stat;
8716
`endif
8717
    `CSR_CAS:       dat <= cas;
8718
    `CSR_TVEC:      dat <= tvec[csrno[2:0]];
8719
    `CSR_BADADR:    dat <= badaddr[{thread,csrno[13:11]}];
8720
    `CSR_CAUSE:     dat <= {48'd0,cause[{thread,csrno[13:11]}]};
8721
`ifdef SUPPORT_SMT
8722
    `CSR_IM_STACK:      dat <= im_stack[thread];
8723
    `CSR_OL_STACK:      dat <= ol_stack[thread];
8724
    `CSR_PL_STACK:      dat <= pl_stack[thread];
8725
    `CSR_RS_STACK:      dat <= rs_stack[thread];
8726
    `CSR_STATUS:    dat <= mstatus[thread][63:0];
8727
    `CSR_EPC0:      dat <= epc0[thread];
8728
    `CSR_EPC1:      dat <= epc1[thread];
8729
    `CSR_EPC2:      dat <= epc2[thread];
8730
    `CSR_EPC3:      dat <= epc3[thread];
8731
    `CSR_EPC4:      dat <= epc4[thread];
8732
    `CSR_EPC5:      dat <= epc5[thread];
8733
    `CSR_EPC6:      dat <= epc6[thread];
8734
    `CSR_EPC7:      dat <= epc7[thread];
8735
`else
8736
    `CSR_IM_STACK:      dat <= im_stack;
8737
    `CSR_OL_STACK:      dat <= ol_stack;
8738
    `CSR_PL_STACK:      dat <= pl_stack;
8739
    `CSR_RS_STACK:      dat <= rs_stack;
8740
    `CSR_STATUS:    dat <= mstatus[63:0];
8741
    `CSR_EPC0:      dat <= epc0;
8742
    `CSR_EPC1:      dat <= epc1;
8743
    `CSR_EPC2:      dat <= epc2;
8744
    `CSR_EPC3:      dat <= epc3;
8745
    `CSR_EPC4:      dat <= epc4;
8746
    `CSR_EPC5:      dat <= epc5;
8747
    `CSR_EPC6:      dat <= epc6;
8748
    `CSR_EPC7:      dat <= epc7;
8749
`endif
8750
    `CSR_CODEBUF:   dat <= codebuf[csrno[5:0]];
8751
    `CSR_TIME:          dat <= wc_times;
8752
    `CSR_INFO:
8753
                    case(csrno[3:0])
8754
                    4'd0:   dat <= "Finitron";  // manufacturer
8755
                    4'd1:   dat <= "        ";
8756
                    4'd2:   dat <= "64 bit  ";  // CPU class
8757
                    4'd3:   dat <= "        ";
8758
                    4'd4:   dat <= "FT64    ";  // Name
8759
                    4'd5:   dat <= "        ";
8760
                    4'd6:   dat <= 64'd1;       // model #
8761
                    4'd7:   dat <= 64'd1;       // serial number
8762
                    4'd8:   dat <= {32'd16384,32'd16384};   // cache sizes instruction,data
8763
                    4'd9:   dat <= 64'd0;
8764
                    default:    dat <= 64'd0;
8765
                    endcase
8766
    default:    begin
8767
                        $display("Unsupported CSR:%h",csrno[10:0]);
8768
                        dat <= 64'hEEEEEEEEEEEEEEEE;
8769
                        end
8770
    endcase
8771
    else
8772
        dat <= 64'h0;
8773
end
8774
endtask
8775
 
8776
task write_csr;
8777
input [13:0] csrno;
8778
input [63:0] dat;
8779
input thread;
8780
begin
8781
`ifdef SUPPORT_SMT
8782
    if (csrno[11:10] >= ol[thread])
8783
`else
8784
    if (csrno[11:10] >= ol)
8785
`endif
8786
    case(csrno[13:12])
8787
    2'd1:   // CSRRW
8788
        casez(csrno[9:0])
8789
        `CSR_CR0:       cr0 <= dat;
8790
        `CSR_PCR:       pcr <= dat[31:0];
8791
        `CSR_PCR2:      pcr2 <= dat;
8792
        `CSR_WBRCD:             wbrcd <= dat;
8793
        `CSR_SEMA:      sema <= dat;
8794
        `CSR_SBL:       sbl <= dat[31:0];
8795
        `CSR_SBU:       sbu <= dat[31:0];
8796
        `CSR_TCB:               tcb <= dat;
8797
        `CSR_FSTAT:             fpu_csr[37:32] <= dat[37:32];
8798
        `CSR_BADADR:    badaddr[{thread,csrno[13:11]}] <= dat;
8799
        `CSR_CAUSE:     cause[{thread,csrno[13:11]}] <= dat[15:0];
8800
`ifdef SUPPORT_DBG
8801
        `CSR_DBAD0:     dbg_adr0 <= dat[AMSB:0];
8802
        `CSR_DBAD1:     dbg_adr1 <= dat[AMSB:0];
8803
        `CSR_DBAD2:     dbg_adr2 <= dat[AMSB:0];
8804
        `CSR_DBAD3:     dbg_adr3 <= dat[AMSB:0];
8805
        `CSR_DBCTRL:    dbg_ctrl <= dat;
8806
`endif
8807
        `CSR_CAS:       cas <= dat;
8808
        `CSR_TVEC:      tvec[csrno[2:0]] <= dat[31:0];
8809
`ifdef SUPPORT_SMT
8810
        `CSR_IM_STACK:  im_stack[thread] <= dat[31:0];
8811
        `CSR_OL_STACK:  ol_stack[thread] <= dat[15:0];
8812
        `CSR_PL_STACK:  pl_stack[thread] <= dat;
8813
        `CSR_RS_STACK:  rs_stack[thread] <= dat;
8814
        `CSR_STATUS:    mstatus[thread][63:0] <= dat;
8815
        `CSR_EPC0:      epc0[thread] <= dat;
8816
        `CSR_EPC1:      epc1[thread] <= dat;
8817
        `CSR_EPC2:      epc2[thread] <= dat;
8818
        `CSR_EPC3:      epc3[thread] <= dat;
8819
        `CSR_EPC4:      epc4[thread] <= dat;
8820
        `CSR_EPC5:      epc5[thread] <= dat;
8821
        `CSR_EPC6:      epc6[thread] <= dat;
8822
        `CSR_EPC7:      epc7[thread] <= dat;
8823
`else
8824
        `CSR_IM_STACK:  im_stack <= dat[31:0];
8825
        `CSR_OL_STACK:  ol_stack <= dat[15:0];
8826
        `CSR_PL_STACK:  pl_stack <= dat;
8827
        `CSR_RS_STACK:  rs_stack <= dat;
8828
        `CSR_STATUS:    mstatus[63:0] <= dat;
8829
        `CSR_EPC0:      epc0 <= dat;
8830
        `CSR_EPC1:      epc1 <= dat;
8831
        `CSR_EPC2:      epc2 <= dat;
8832
        `CSR_EPC3:      epc3 <= dat;
8833
        `CSR_EPC4:      epc4 <= dat;
8834
        `CSR_EPC5:      epc5 <= dat;
8835
        `CSR_EPC6:      epc6 <= dat;
8836
        `CSR_EPC7:      epc7 <= dat;
8837
`endif
8838
                `CSR_TIME:              begin
8839
                                                ld_time <= 6'h3f;
8840
                                                wc_time_dat <= dat;
8841
                                                end
8842
        `CSR_CODEBUF:   codebuf[csrno[5:0]] <= dat;
8843
        default:    ;
8844
        endcase
8845
    2'd2:   // CSRRS
8846
        case(csrno[9:0])
8847
        `CSR_CR0:       cr0 <= cr0 | dat;
8848
        `CSR_PCR:       pcr[31:0] <= pcr[31:0] | dat[31:0];
8849
        `CSR_PCR2:      pcr2 <= pcr2 | dat;
8850
        `CSR_WBRCD:             wbrcd <= wbrcd | dat;
8851
`ifdef SUPPORT_DBG
8852
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl | dat;
8853
`endif
8854
        `CSR_SEMA:      sema <= sema | dat;
8855
`ifdef SUPPORT_SMT
8856
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] | dat;
8857
`else
8858
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] | dat;
8859
`endif
8860
        default:    ;
8861
        endcase
8862
    2'd3:   // CSRRC
8863
        case(csrno[9:0])
8864
        `CSR_CR0:       cr0 <= cr0 & ~dat;
8865
        `CSR_PCR:       pcr <= pcr & ~dat;
8866
        `CSR_PCR2:      pcr2 <= pcr2 & ~dat;
8867
        `CSR_WBRCD:             wbrcd <= wbrcd & ~dat;
8868
`ifdef SUPPORT_DBG
8869
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl & ~dat;
8870
`endif
8871
        `CSR_SEMA:      sema <= sema & ~dat;
8872
`ifdef SUPPORT_SMT
8873
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] & ~dat;
8874
`else
8875
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] & ~dat;
8876
`endif
8877
        default:    ;
8878
        endcase
8879
    default:    ;
8880
    endcase
8881
end
8882
endtask
8883
 
8884
/*
8885
function [63:0] assign_a0;
8886
input [31:0] fb_instr;
8887
begin
8888
    if (IsShifti(fb_instr)||IsVShifti(fb_instr)||IsSEI(fb_instr)||IsRTI(fb_instr))
8889
        assign_a0 = {58'd0,fb_instr[21:16]};
8890
//    else if (IsBranch(fb_instr))
8891
//        assign_a0 = {{51{fb_instr[`INSTRUCTION_SB]}},fb_instr[31:22],fb_instr[0],2'b00};
8892
//    else if (fb_instr[`INSTRUCTION_OP] == `CALL || fb_instr[`INSTRUCTION_OP] == `JMP)
8893
//        assign_a0 = {{36{fb_instr[31]}},fb_instr[31:6],2'd0};
8894
    else
8895
        assign_a0 = {{48{fb_instr[`INSTRUCTION_SB]}},fb_instr[31:16]};
8896
end
8897
endfunction
8898
*/
8899
/*
8900
task aluissue;
8901
input alu_idle;
8902
input [QENTRIES-1:0] iq_alu0;
8903
input [1:0] slot;
8904
begin
8905
        if (alu_idle) begin
8906
                if (could_issue[head0] && iqentry_alu[head0]
8907
                && !iq_alu0[head0]      // alu0only
8908
                && !iqentry_issue[head0]) begin
8909
                  iqentry_issue[head0] = `TRUE;
8910
                  iqentry_islot[head0] = slot;
8911
                end
8912
                else if (could_issue[head1] && !iqentry_issue[head1] && iqentry_alu[head1]
8913
                && !iq_alu0[head1])
8914
                begin
8915
                  iqentry_issue[head1] = `TRUE;
8916
                  iqentry_islot[head1] = slot;
8917
                end
8918
                else if (could_issue[head2] && !iqentry_issue[head2] && iqentry_alu[head2]
8919
                && !iq_alu0[head2]
8920
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
8921
                )
8922
                begin
8923
                        iqentry_issue[head2] = `TRUE;
8924
                        iqentry_islot[head2] = slot;
8925
                end
8926
                else if (could_issue[head3] && !iqentry_issue[head3] && iqentry_alu[head3]
8927
                && !iq_alu0[head3]
8928
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
8929
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
8930
                                ((!iqentry_v[head0])
8931
                        &&   (!iqentry_v[head1]))
8932
                        )
8933
                ) begin
8934
                        iqentry_issue[head3] = `TRUE;
8935
                        iqentry_islot[head3] = slot;
8936
                end
8937
                else if (could_issue[head4] && !iqentry_issue[head4] && iqentry_alu[head4]
8938
                && !iq_alu0[head4]
8939
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
8940
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
8941
                                ((!iqentry_v[head0])
8942
                        &&   (!iqentry_v[head1]))
8943
                        )
8944
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
8945
                                ((!iqentry_v[head0])
8946
                        &&   (!iqentry_v[head1])
8947
                        &&   (!iqentry_v[head2]))
8948
                        )
8949
                ) begin
8950
                        iqentry_issue[head4] = `TRUE;
8951
                        iqentry_islot[head4] = slot;
8952
                end
8953
                else if (could_issue[head5] && !iqentry_issue[head5] && iqentry_alu[head5]
8954
                && !iq_alu0[head5]
8955
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
8956
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
8957
                                ((!iqentry_v[head0])
8958
                        &&   (!iqentry_v[head1]))
8959
                        )
8960
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
8961
                                ((!iqentry_v[head0])
8962
                        &&   (!iqentry_v[head1])
8963
                        &&   (!iqentry_v[head2]))
8964
                        )
8965
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
8966
                                ((!iqentry_v[head0])
8967
                        &&   (!iqentry_v[head1])
8968
                        &&   (!iqentry_v[head2])
8969
                        &&   (!iqentry_v[head3]))
8970
                        )
8971
                ) begin
8972
                        iqentry_issue[head5] = `TRUE;
8973
                        iqentry_islot[head5] = slot;
8974
                end
8975
                else if (could_issue[head6] && !iqentry_issue[head6] && iqentry_alu[head6]
8976
                && !iq_alu0[head6]
8977
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
8978
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
8979
                                ((!iqentry_v[head0])
8980
                        &&   (!iqentry_v[head1]))
8981
                        )
8982
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
8983
                                ((!iqentry_v[head0])
8984
                        &&   (!iqentry_v[head1])
8985
                        &&   (!iqentry_v[head2]))
8986
                        )
8987
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
8988
                                ((!iqentry_v[head0])
8989
                        &&   (!iqentry_v[head1])
8990
                        &&   (!iqentry_v[head2])
8991
                        &&   (!iqentry_v[head3]))
8992
                        )
8993
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
8994
                                ((!iqentry_v[head0])
8995
                        &&   (!iqentry_v[head1])
8996
                        &&   (!iqentry_v[head2])
8997
                        &&   (!iqentry_v[head3])
8998
                        &&   (!iqentry_v[head4]))
8999
                        )
9000
                ) begin
9001
                        iqentry_issue[head6] = `TRUE;
9002
                        iqentry_islot[head6] = slot;
9003
                end
9004
                else if (could_issue[head7] && !iqentry_issue[head7] && iqentry_alu[head7]
9005
                && !iq_alu0[head7]
9006
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
9007
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
9008
                                ((!iqentry_v[head0])
9009
                        &&   (!iqentry_v[head1]))
9010
                        )
9011
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
9012
                                ((!iqentry_v[head0])
9013
                        &&   (!iqentry_v[head1])
9014
                        &&   (!iqentry_v[head2]))
9015
                        )
9016
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
9017
                                ((!iqentry_v[head0])
9018
                        &&   (!iqentry_v[head1])
9019
                        &&   (!iqentry_v[head2])
9020
                        &&   (!iqentry_v[head3]))
9021
                        )
9022
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
9023
                                ((!iqentry_v[head0])
9024
                        &&   (!iqentry_v[head1])
9025
                        &&   (!iqentry_v[head2])
9026
                        &&   (!iqentry_v[head3])
9027
                        &&   (!iqentry_v[head4]))
9028
                        )
9029
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
9030
                                ((!iqentry_v[head0])
9031
                        &&   (!iqentry_v[head1])
9032
                        &&   (!iqentry_v[head2])
9033
                        &&   (!iqentry_v[head3])
9034
                        &&   (!iqentry_v[head4])
9035
                        &&   (!iqentry_v[head5]))
9036
                        )
9037
                ) begin
9038
                        iqentry_issue[head7] = `TRUE;
9039
                        iqentry_islot[head7] = slot;
9040
                end
9041
        end
9042
end
9043
endtask
9044
 
9045
task fpuissue;
9046
input fp_idle;
9047
input [1:0] slot;
9048
begin
9049
        if (fp_idle) begin
9050
    if (could_issue[head0] && iqentry_fpu[head0]) begin
9051
      iqentry_fpu_issue[head0] = `TRUE;
9052
      iqentry_fpu_islot[head0] = slot;
9053
    end
9054
    else if (could_issue[head1] && iqentry_fpu[head1])
9055
    begin
9056
      iqentry_fpu_issue[head1] = `TRUE;
9057
      iqentry_fpu_islot[head1] = slot;
9058
    end
9059
    else if (could_issue[head2] && iqentry_fpu[head2]
9060
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
9061
    ) begin
9062
      iqentry_fpu_issue[head2] = `TRUE;
9063
      iqentry_fpu_islot[head2] = slot;
9064
    end
9065
    else if (could_issue[head3] && iqentry_fpu[head3]
9066
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
9067
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
9068
                ((!iqentry_v[head0])
9069
        &&   (!iqentry_v[head1]))
9070
        )
9071
    ) begin
9072
      iqentry_fpu_issue[head3] = `TRUE;
9073
      iqentry_fpu_islot[head3] = slot;
9074
    end
9075
    else if (could_issue[head4] && iqentry_fpu[head4]
9076
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
9077
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
9078
                ((!iqentry_v[head0])
9079
        &&   (!iqentry_v[head1]))
9080
        )
9081
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
9082
                ((!iqentry_v[head0])
9083
        &&   (!iqentry_v[head1])
9084
        &&   (!iqentry_v[head2]))
9085
        )
9086
    ) begin
9087
      iqentry_fpu_issue[head4] = `TRUE;
9088
      iqentry_fpu_islot[head4] = slot;
9089
    end
9090
    else if (could_issue[head5] && iqentry_fpu[head5]
9091
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
9092
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
9093
                ((!iqentry_v[head0])
9094
        &&   (!iqentry_v[head1]))
9095
        )
9096
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
9097
                ((!iqentry_v[head0])
9098
        &&   (!iqentry_v[head1])
9099
        &&   (!iqentry_v[head2]))
9100
        )
9101
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
9102
                ((!iqentry_v[head0])
9103
        &&   (!iqentry_v[head1])
9104
        &&   (!iqentry_v[head2])
9105
        &&   (!iqentry_v[head3]))
9106
        )
9107
        ) begin
9108
              iqentry_fpu_issue[head5] = `TRUE;
9109
              iqentry_fpu_islot[head5] = slot;
9110
    end
9111
    else if (could_issue[head6] && iqentry_fpu[head6]
9112
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
9113
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
9114
                ((!iqentry_v[head0])
9115
        &&   (!iqentry_v[head1]))
9116
        )
9117
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
9118
                ((!iqentry_v[head0])
9119
        &&   (!iqentry_v[head1])
9120
        &&   (!iqentry_v[head2]))
9121
        )
9122
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
9123
                ((!iqentry_v[head0])
9124
        &&   (!iqentry_v[head1])
9125
        &&   (!iqentry_v[head2])
9126
        &&   (!iqentry_v[head3]))
9127
        )
9128
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
9129
                ((!iqentry_v[head0])
9130
        &&   (!iqentry_v[head1])
9131
        &&   (!iqentry_v[head2])
9132
        &&   (!iqentry_v[head3])
9133
        &&   (!iqentry_v[head4]))
9134
        )
9135
    ) begin
9136
        iqentry_fpu_issue[head6] = `TRUE;
9137
            iqentry_fpu_islot[head6] = slot;
9138
    end
9139
    else if (could_issue[head7] && iqentry_fpu[head7]
9140
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
9141
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
9142
                ((!iqentry_v[head0])
9143
        &&   (!iqentry_v[head1]))
9144
        )
9145
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
9146
                ((!iqentry_v[head0])
9147
        &&   (!iqentry_v[head1])
9148
        &&   (!iqentry_v[head2]))
9149
        )
9150
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
9151
                ((!iqentry_v[head0])
9152
        &&   (!iqentry_v[head1])
9153
        &&   (!iqentry_v[head2])
9154
        &&   (!iqentry_v[head3]))
9155
        )
9156
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
9157
                ((!iqentry_v[head0])
9158
        &&   (!iqentry_v[head1])
9159
        &&   (!iqentry_v[head2])
9160
        &&   (!iqentry_v[head3])
9161
        &&   (!iqentry_v[head4]))
9162
        )
9163
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
9164
                ((!iqentry_v[head0])
9165
        &&   (!iqentry_v[head1])
9166
        &&   (!iqentry_v[head2])
9167
        &&   (!iqentry_v[head3])
9168
        &&   (!iqentry_v[head4])
9169
        &&   (!iqentry_v[head5]))
9170
        )
9171
        )
9172
    begin
9173
                iqentry_fpu_issue[head7] = `TRUE;
9174
                iqentry_fpu_islot[head7] = slot;
9175
        end
9176
        end
9177
end
9178
endtask
9179
*/
9180
endmodule
9181
 
9182
 
9183
module decoder5 (num, out);
9184
input [4:0] num;
9185
output [31:1] out;
9186
reg [31:1] out;
9187
 
9188
always @(num)
9189
case (num)
9190
    5'd0 :      out <= 31'b0000000000000000000000000000000;
9191
    5'd1 :      out <= 31'b0000000000000000000000000000001;
9192
    5'd2 :      out <= 31'b0000000000000000000000000000010;
9193
    5'd3 :      out <= 31'b0000000000000000000000000000100;
9194
    5'd4 :      out <= 31'b0000000000000000000000000001000;
9195
    5'd5 :      out <= 31'b0000000000000000000000000010000;
9196
    5'd6 :      out <= 31'b0000000000000000000000000100000;
9197
    5'd7 :      out <= 31'b0000000000000000000000001000000;
9198
    5'd8 :      out <= 31'b0000000000000000000000010000000;
9199
    5'd9 :      out <= 31'b0000000000000000000000100000000;
9200
    5'd10:      out <= 31'b0000000000000000000001000000000;
9201
    5'd11:      out <= 31'b0000000000000000000010000000000;
9202
    5'd12:      out <= 31'b0000000000000000000100000000000;
9203
    5'd13:      out <= 31'b0000000000000000001000000000000;
9204
    5'd14:      out <= 31'b0000000000000000010000000000000;
9205
    5'd15:      out <= 31'b0000000000000000100000000000000;
9206
    5'd16:      out <= 31'b0000000000000001000000000000000;
9207
    5'd17:      out <= 31'b0000000000000010000000000000000;
9208
    5'd18:      out <= 31'b0000000000000100000000000000000;
9209
    5'd19:      out <= 31'b0000000000001000000000000000000;
9210
    5'd20:      out <= 31'b0000000000010000000000000000000;
9211
    5'd21:      out <= 31'b0000000000100000000000000000000;
9212
    5'd22:      out <= 31'b0000000001000000000000000000000;
9213
    5'd23:      out <= 31'b0000000010000000000000000000000;
9214
    5'd24:      out <= 31'b0000000100000000000000000000000;
9215
    5'd25:      out <= 31'b0000001000000000000000000000000;
9216
    5'd26:      out <= 31'b0000010000000000000000000000000;
9217
    5'd27:      out <= 31'b0000100000000000000000000000000;
9218
    5'd28:      out <= 31'b0001000000000000000000000000000;
9219
    5'd29:      out <= 31'b0010000000000000000000000000000;
9220
    5'd30:      out <= 31'b0100000000000000000000000000000;
9221
    5'd31:      out <= 31'b1000000000000000000000000000000;
9222
endcase
9223
 
9224
endmodule
9225
 
9226
module decoder6 (num, out);
9227
input [5:0] num;
9228
output [63:1] out;
9229
 
9230
wire [63:0] out1;
9231
 
9232
assign out1 = 64'd1 << num;
9233
assign out = out1[63:1];
9234
 
9235
endmodule
9236
 
9237
module decoder7 (num, out);
9238
input [6:0] num;
9239
output [127:1] out;
9240
 
9241
wire [127:0] out1;
9242
 
9243
assign out1 = 128'd1 << num;
9244
assign out = out1[127:1];
9245
 
9246
endmodule
9247
 
9248
module decoder8 (num, out);
9249
input [7:0] num;
9250
output [255:1] out;
9251
 
9252
wire [255:0] out1;
9253
 
9254
assign out1 = 256'd1 << num;
9255
assign out = out1[255:1];
9256
 
9257
endmodule
9258
 

powered by: WebSVN 2.1.0

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