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

Subversion Repositories thor

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

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 55 robfinch
// Approx 41,000 LUTs. 66,000 LC's.
41 48 robfinch
// ============================================================================
42
//
43 49 robfinch
`include "FT64_config.vh"
44 48 robfinch
`include "FT64_defines.vh"
45
 
46
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,
47
    ol_o, pcr_o, pcr2_o, exv_i, rdv_i, wrv_i, icl_o, sr_o, cr_o, rbi_i, signal_i);
48
input [63:0] hartid;
49
input rst;
50
input clk_i;
51
input clk4x;
52
input tm_clk_i;
53 49 robfinch
input [3:0] irq_i;
54 48 robfinch
input [7:0] vec_i;
55
output reg [1:0] bte_o;
56
output reg [2:0] cti_o;
57
output reg cyc_o;
58
output reg stb_o;
59
input ack_i;
60
input err_i;
61
output reg we_o;
62
output reg [7:0] sel_o;
63 49 robfinch
output reg [`ABITS] adr_o;
64 48 robfinch
output reg [63:0] dat_o;
65
input [63:0] dat_i;
66
output reg [1:0] ol_o;
67
output [31:0] pcr_o;
68
output [63:0] pcr2_o;
69
input exv_i;
70
input rdv_i;
71
input wrv_i;
72
output reg icl_o;
73
output reg cr_o;
74
output reg sr_o;
75
input rbi_i;
76
input [31:0] signal_i;
77
 
78
parameter TM_CLKFREQ = 20000000;
79
parameter QENTRIES = `QENTRIES;
80
parameter RSTPC = 32'hFFFC0100;
81
parameter BRKPC = 32'hFFFC0000;
82
`ifdef SUPPORT_SMT
83
parameter PREGS = 256;   // number of physical registers - 1
84
parameter AREGS = 256;   // number of architectural registers
85
`else
86
parameter PREGS = 128;
87
parameter AREGS = 128;
88
`endif
89
parameter RBIT = 11;
90
parameter DEBUG = 1'b0;
91
parameter NMAP = QENTRIES;
92
parameter BRANCH_PRED = 1'b0;
93
parameter SUP_TXE = 1'b0;
94 55 robfinch
parameter SUP_VECTOR = `SUPPORT_VECTOR;
95 48 robfinch
parameter DBW = 64;
96
parameter ABW = 32;
97
parameter AMSB = ABW-1;
98
parameter NTHREAD = 1;
99
reg [3:0] i;
100
integer n;
101 52 robfinch
integer j, k;
102 48 robfinch
genvar g;
103
parameter TRUE = 1'b1;
104
parameter FALSE = 1'b0;
105
// Memory access sizes
106
parameter byt = 3'd0;
107
parameter wyde = 3'd1;
108
parameter tetra = 3'd2;
109
parameter octa = 3'd3;
110
// IQ states
111
parameter IQS_IDLE = 2'd0;
112
parameter IQS_AGEN = 2'd1;
113
parameter IQS_LDDONE = 2'd2;
114
parameter IQS_S3 = 2'd3;
115
 
116
wire clk;
117 50 robfinch
//BUFG uclkb1
118
//(
119
//      .I(clk_i),
120
//      .O(clk)
121
//);
122
assign clk = clk_i;
123 48 robfinch
 
124
wire dc_ack;
125
wire acki = ack_i|dc_ack;
126 57 robfinch
wire [RBIT:0] Ra0, Ra1, Ra2;
127
wire [RBIT:0] Rb0, Rb1, Rb2;
128
wire [RBIT:0] Rc0, Rc1, Rc2;
129
wire [RBIT:0] Rt0, Rt1, Rt2;
130 48 robfinch
wire [63:0] rfoa0,rfob0,rfoc0,rfoc0a;
131
wire [63:0] rfoa1,rfob1,rfoc1,rfoc1a;
132 57 robfinch
wire [63:0] rfoa2,rfob2,rfoc2,rfoc2a;
133 48 robfinch
`ifdef SUPPORT_SMT
134
wire [7:0] Ra0s = {Ra0[7:0]};
135
wire [7:0] Ra1s = {Ra1[7:0]};
136 57 robfinch
wire [7:0] Ra2s = {Ra2[7:0]};
137 48 robfinch
wire [7:0] Rb0s = {Rb0[7:0]};
138
wire [7:0] Rb1s = {Rb1[7:0]};
139 57 robfinch
wire [7:0] Rb2s = {Rb2[7:0]};
140 48 robfinch
wire [7:0] Rc0s = {Rc0[7:0]};
141
wire [7:0] Rc1s = {Rc1[7:0]};
142 57 robfinch
wire [7:0] Rc2s = {Rc2[7:0]};
143 48 robfinch
wire [7:0] Rt0s = {Rt0[7:0]};
144
wire [7:0] Rt1s = {Rt1[7:0]};
145 57 robfinch
wire [7:0] Rt2s = {Rt2[7:0]};
146 48 robfinch
`else
147
wire [6:0] Ra0s = {Ra0[7],Ra0[5:0]};
148
wire [6:0] Ra1s = {Ra1[7],Ra1[5:0]};
149 57 robfinch
wire [6:0] Ra2s = {Ra2[7],Ra2[5:0]};
150 48 robfinch
wire [6:0] Rb0s = {Rb0[7],Rb0[5:0]};
151
wire [6:0] Rb1s = {Rb1[7],Rb1[5:0]};
152 57 robfinch
wire [6:0] Rb2s = {Rb2[7],Rb2[5:0]};
153 48 robfinch
wire [6:0] Rc0s = {Rc0[7],Rc0[5:0]};
154
wire [6:0] Rc1s = {Rc1[7],Rc1[5:0]};
155 57 robfinch
wire [6:0] Rc2s = {Rc2[7],Rc2[5:0]};
156 48 robfinch
wire [6:0] Rt0s = {Rt0[7],Rt0[5:0]};
157
wire [6:0] Rt1s = {Rt1[7],Rt1[5:0]};
158 57 robfinch
wire [6:0] Rt2s = {Rt2[7],Rt2[5:0]};
159 48 robfinch
/*
160
wire [5:0] Ra0s = {Ra0[5:0]};
161
wire [5:0] Ra1s = {Ra1[5:0]};
162
wire [5:0] Rb0s = {Rb0[5:0]};
163
wire [5:0] Rb1s = {Rb1[5:0]};
164
wire [5:0] Rc0s = {Rc0[5:0]};
165
wire [5:0] Rc1s = {Rc1[5:0]};
166
wire [5:0] Rt0s = {Rt0[5:0]};
167
wire [5:0] Rt1s = {Rt1[5:0]};
168
*/
169
`endif
170
 
171
reg [63:0] ds [0:NTHREAD];
172
reg [63:0] ss [0:NTHREAD];
173
reg [63:0] ptrmask [0:NTHREAD];
174
reg [63:0] ptrkey = "  OBJECT";
175
reg [63:0] wbrcd;
176
 
177
reg  [PREGS-1:0] rf_v;
178 52 robfinch
reg  [5:0] rf_source[0:AREGS-1];
179 48 robfinch
initial begin
180
for (n = 0; n < AREGS; n = n + 1)
181 52 robfinch
        rf_source[n] = 6'd0;
182 48 robfinch
end
183 49 robfinch
wire [`ABITS] pc0;
184
wire [`ABITS] pc1;
185
wire [`ABITS] pc2;
186 48 robfinch
 
187
reg excmiss;
188 49 robfinch
reg [`ABITS] excmisspc;
189 48 robfinch
reg excthrd;
190
reg exception_set;
191
reg rdvq;               // accumulated read violation
192
reg errq;               // accumulated err_i input status
193
reg exvq;
194
 
195
// Vector
196 57 robfinch
reg [5:0] vqe0, vqe1, vqe2;   // vector element being queued
197
reg [5:0] vqet0, vqet1, vqet2;
198 48 robfinch
reg [7:0] vl;           // vector length
199
reg [63:0] vm [0:7];    // vector mask registers
200
reg [1:0] m2;
201
 
202 49 robfinch
reg [31:0] wb_merges;
203 48 robfinch
// CSR's
204
reg [63:0] cr0;
205
wire snr = cr0[17];             // sequence number reset
206
wire dce = cr0[30];     // data cache enable
207
wire bpe = cr0[32];     // branch predictor enable
208 52 robfinch
wire wbm = cr0[34];
209 48 robfinch
wire ctgtxe = cr0[33];
210 49 robfinch
reg [63:0] pmr;
211
wire id1_available = pmr[0];
212
wire id2_available = pmr[1];
213
wire id3_available = pmr[2];
214
wire alu0_available = pmr[8];
215
wire alu1_available = pmr[9];
216
wire fpu1_available = pmr[16];
217
wire fpu2_available = pmr[17];
218
wire mem1_available = pmr[24];
219
wire mem2_available = pmr[25];
220
wire mem3_available = pmr[26];
221
wire fcu_available = pmr[32];
222 48 robfinch
// Simply setting this flag to zero should strip out almost all the logic
223
// associated SMT.
224
`ifdef SUPPORT_SMT
225
wire thread_en = cr0[16];
226
`else
227
wire thread_en = 1'b0;
228
`endif
229
wire vechain = cr0[18];
230
reg [7:0] fcu_timeout;
231
reg [63:0] tick;
232
reg [63:0] wc_time;
233
reg [31:0] pcr;
234
reg [63:0] pcr2;
235
assign pcr_o = pcr;
236
assign pcr2_o = pcr2;
237
reg [63:0] aec;
238
reg [15:0] cause[0:15];
239
`ifdef SUPPORT_SMT
240 49 robfinch
reg [`ABITS] epc [0:NTHREAD];
241
reg [`ABITS] epc0 [0:NTHREAD];
242
reg [`ABITS] epc1 [0:NTHREAD];
243
reg [`ABITS] epc2 [0:NTHREAD];
244
reg [`ABITS] epc3 [0:NTHREAD];
245
reg [`ABITS] epc4 [0:NTHREAD];
246
reg [`ABITS] epc5 [0:NTHREAD];
247
reg [`ABITS] epc6 [0:NTHREAD];
248
reg [`ABITS] epc7 [0:NTHREAD];
249
reg [`ABITS] epc8 [0:NTHREAD];                   // exception pc and stack
250 48 robfinch
reg [63:0] mstatus [0:NTHREAD];           // machine status
251 49 robfinch
wire [3:0] im = mstatus[0][3:0];
252 48 robfinch
wire [1:0] ol [0:NTHREAD];
253
wire [1:0] dl [0:NTHREAD];
254
assign ol[0] = mstatus[0][5:3];   // operating level
255
assign dl[0] = mstatus[0][21:20];
256
wire [7:0] cpl [0:NTHREAD];
257
assign cpl[0] = mstatus[0][13:6]; // current privilege level
258
wire [5:0] rgs [0:NTHREAD];
259
assign rgs[0] = mstatus[0][19:14];
260
assign ol[1] = mstatus[1][5:3]; // operating level
261
assign cpl[1] = mstatus[1][13:6];       // current privilege level
262
assign rgs[1] = mstatus[1][19:14];
263
assign dl[1] = mstatus[1][21:20];
264
reg [15:0] ol_stack [0:NTHREAD];
265
reg [31:0] im_stack [0:NTHREAD];
266
reg [63:0] pl_stack [0:NTHREAD];
267
reg [63:0] rs_stack [0:NTHREAD];
268
reg [63:0] fr_stack [0:NTHREAD];
269
wire mprv = mstatus[0][55];
270
wire [5:0] fprgs = mstatus[0][25:20];
271
//assign ol_o = mprv ? ol_stack[0][2:0] : ol[0];
272
wire vca = mstatus[0][32];               // vector chaining active
273
`else
274 49 robfinch
reg [`ABITS] epc ;
275
reg [`ABITS] epc0 ;
276
reg [`ABITS] epc1 ;
277
reg [`ABITS] epc2 ;
278
reg [`ABITS] epc3 ;
279
reg [`ABITS] epc4 ;
280
reg [`ABITS] epc5 ;
281
reg [`ABITS] epc6 ;
282
reg [`ABITS] epc7 ;
283
reg [`ABITS] epc8 ;                     // exception pc and stack
284 48 robfinch
reg [63:0] mstatus ;             // machine status
285 49 robfinch
wire [3:0] im = mstatus[3:0];
286 48 robfinch
wire [1:0] ol ;
287
wire [1:0] dl;
288
assign ol = mstatus[5:3];       // operating level
289
assign dl = mstatus[21:20];
290
wire [7:0] cpl ;
291
assign cpl = mstatus[13:6];     // current privilege level
292
wire [5:0] rgs ;
293
assign rgs = mstatus[19:14];
294
reg [15:0] ol_stack ;
295
reg [31:0] im_stack ;
296
reg [63:0] pl_stack ;
297
reg [63:0] rs_stack ;
298
reg [63:0] fr_stack ;
299
wire mprv = mstatus[55];
300
wire [5:0] fprgs = mstatus[25:20];
301
//assign ol_o = mprv ? ol_stack[2:0] : ol;
302
wire vca = mstatus[32];         // vector chaining active
303
`endif
304
reg [63:0] tcb;
305 49 robfinch
reg [`ABITS] badaddr[0:15];
306
reg [`ABITS] tvec[0:7];
307 48 robfinch
reg [63:0] sema;
308
reg [63:0] vm_sema;
309
reg [63:0] cas;         // compare and swap
310
reg [63:0] ve_hold;
311
reg isCAS, isAMO, isInc, isSpt, isRMW;
312
reg [`QBITS] casid;
313 49 robfinch
reg [`ABITS] sbl, sbu;
314 48 robfinch
reg [4:0] regLR = 5'd29;
315
 
316 51 robfinch
reg [2:0] fp_rm;
317
reg fp_inexe;
318
reg fp_dbzxe;
319
reg fp_underxe;
320
reg fp_overxe;
321
reg fp_invopxe;
322
reg fp_giopxe;
323
reg fp_nsfp = 1'b0;
324
reg fp_fractie;
325
reg fp_raz;
326 48 robfinch
 
327 51 robfinch
reg fp_neg;
328
reg fp_pos;
329
reg fp_zero;
330
reg fp_inf;
331 48 robfinch
 
332 51 robfinch
reg fp_inex;            // inexact exception
333
reg fp_dbzx;            // divide by zero exception
334
reg fp_underx;          // underflow exception
335
reg fp_overx;           // overflow exception
336
reg fp_giopx;           // global invalid operation exception
337
reg fp_sx;                      // summary exception
338
reg fp_swtx;        // software triggered exception
339
reg fp_gx;
340
reg fp_invopx;
341 48 robfinch
 
342 51 robfinch
reg fp_infzerox;
343
reg fp_zerozerox;
344
reg fp_subinfx;
345
reg fp_infdivx;
346
reg fp_NaNCmpx;
347
reg fp_cvtx;
348
reg fp_sqrtx;
349
reg fp_snanx;
350 48 robfinch
 
351 51 robfinch
wire [31:0] fp_status = {
352 48 robfinch
 
353 51 robfinch
        fp_rm,
354
        fp_inexe,
355
        fp_dbzxe,
356
        fp_underxe,
357
        fp_overxe,
358
        fp_invopxe,
359
        fp_nsfp,
360 48 robfinch
 
361 51 robfinch
        fp_fractie,
362
        fp_raz,
363 48 robfinch
        1'b0,
364 51 robfinch
        fp_neg,
365
        fp_pos,
366
        fp_zero,
367
        fp_inf,
368 48 robfinch
 
369 51 robfinch
        fp_swtx,
370
        fp_inex,
371
        fp_dbzx,
372
        fp_underx,
373
        fp_overx,
374
        fp_giopx,
375
        fp_gx,
376
        fp_sx,
377 48 robfinch
 
378 51 robfinch
        fp_cvtx,
379
        fp_sqrtx,
380
        fp_NaNCmpx,
381
        fp_infzerox,
382
        fp_zerozerox,
383
        fp_infdivx,
384
        fp_subinfx,
385
        fp_snanx
386 48 robfinch
        };
387
 
388 51 robfinch
reg [63:0] fpu_csr;
389
wire [5:0] fp_rgs = fpu_csr[37:32];
390 48 robfinch
 
391
//reg [25:0] m[0:8191];
392
reg  [3:0] panic;                // indexes the message structure
393
reg [128:0] message [0:15];       // indexed by panic
394
 
395
wire int_commit;
396
reg StatusHWI;
397 49 robfinch
reg [47:0] insn0, insn1, insn2;
398 52 robfinch
wire [47:0] insn0a, insn1b, insn2b;
399
reg [47:0] insn1a, insn2a;
400 48 robfinch
// Only need enough bits in the seqnence number to cover the instructions in
401
// the queue plus an extra count for skipping on branch misses. In this case
402
// that would be four bits minimum (count 0 to 8). 
403
reg [31:0] seq_num;
404
reg [31:0] seq_num1;
405 57 robfinch
reg [31:0] seq_num2;
406 48 robfinch
wire [63:0] rdat0,rdat1,rdat2;
407
reg [63:0] xdati;
408
 
409 57 robfinch
reg canq1, canq2, canq3;
410 48 robfinch
reg queued1;
411
reg queued2;
412 57 robfinch
reg queued3;
413 48 robfinch
reg queuedNop;
414
 
415
reg [47:0] codebuf[0:63];
416 52 robfinch
reg [QENTRIES-1:0] setpred;
417 48 robfinch
 
418
// instruction queue (ROB)
419
reg [31:0]  iqentry_sn   [0:QENTRIES-1];  // instruction sequence number
420
reg [QENTRIES-1:0] iqentry_v;                    // entry valid?  -- this should be the first bit
421
reg [QENTRIES-1:0] iqentry_iv;           // instruction is valid
422
reg [4:0]  iqentry_is   [0:QENTRIES-1];   // source of instruction
423
reg [QENTRIES-1:0] iqentry_out;  // instruction has been issued to an ALU ... 
424
reg [QENTRIES-1:0] iqentry_done; // instruction result valid
425
reg [QENTRIES-1:0] iqentry_cmt;
426
reg [QENTRIES-1:0] iqentry_thrd;         // which thread the instruction is in
427
reg [QENTRIES-1:0] iqentry_pt;           // predict taken
428 51 robfinch
reg [QENTRIES-1:0] iqentry_bt;           // update branch target buffer
429 52 robfinch
reg [QENTRIES-1:0] iqentry_takb; // take branch record
430 51 robfinch
reg [QENTRIES-1:0] iqentry_jal;
431 48 robfinch
reg [QENTRIES-1:0] iqentry_agen; // address-generate ... signifies that address is ready (only for LW/SW)
432
reg  [1:0] iqentry_state [0:QENTRIES-1];
433
reg [QENTRIES-1:0] iqentry_alu = 8'h00;  // alu type instruction
434
reg [QENTRIES-1:0] iqentry_alu0;  // only valid on alu #0
435
reg [QENTRIES-1:0] iqentry_fpu;  // floating point instruction
436
reg [QENTRIES-1:0] iqentry_fc;   // flow control instruction
437
reg [QENTRIES-1:0] iqentry_canex = 8'h00;        // true if it's an instruction that can exception
438 50 robfinch
reg [QENTRIES-1:0] iqentry_oddball = 8'h00;      // writes to register file
439 49 robfinch
reg [QENTRIES-1:0] iqentry_load; // is a memory load instruction
440 50 robfinch
reg [QENTRIES-1:0] iqentry_loadv;        // is a volatile memory load instruction
441
reg [QENTRIES-1:0] iqentry_store;        // is a memory store instruction
442 49 robfinch
reg [QENTRIES-1:0] iqentry_preload;      // is a memory preload instruction
443
reg [QENTRIES-1:0] iqentry_ldcmp;
444
reg [QENTRIES-1:0] iqentry_mem;  // touches memory: 1 if LW/SW
445
reg [QENTRIES-1:0] iqentry_memndx;  // indexed memory operation 
446 50 robfinch
reg [2:0] iqentry_memsz [0:QENTRIES-1];   // size of memory op
447 49 robfinch
reg [QENTRIES-1:0] iqentry_rmw;  // memory RMW op
448
reg [QENTRIES-1:0] iqentry_memdb;
449
reg [QENTRIES-1:0] iqentry_memsb;
450
reg [QENTRIES-1:0] iqentry_rtop;
451 48 robfinch
reg [QENTRIES-1:0] iqentry_sei;
452
reg [QENTRIES-1:0] iqentry_aq;   // memory aquire
453
reg [QENTRIES-1:0] iqentry_rl;   // memory release
454 49 robfinch
reg [QENTRIES-1:0] iqentry_shft48;
455
reg [QENTRIES-1:0] iqentry_jmp;  // changes control flow: 1 if BEQ/JALR
456 48 robfinch
reg [QENTRIES-1:0] iqentry_br;  // Bcc (for predictor)
457 51 robfinch
reg [QENTRIES-1:0] iqentry_ret;
458
reg [QENTRIES-1:0] iqentry_irq;
459
reg [QENTRIES-1:0] iqentry_brk;
460
reg [QENTRIES-1:0] iqentry_rti;
461 49 robfinch
reg [QENTRIES-1:0] iqentry_sync;  // sync instruction
462
reg [QENTRIES-1:0] iqentry_fsync;
463 48 robfinch
reg [QENTRIES-1:0] iqentry_rfw = 8'h00;  // writes to register file
464
reg  [7:0] iqentry_we   [0:QENTRIES-1];   // enable strobe
465
reg [63:0] iqentry_res   [0:QENTRIES-1];  // instruction result
466
reg [47:0] iqentry_instr[0:QENTRIES-1];   // instruction opcode
467
reg  [2:0] iqentry_insln[0:QENTRIES-1]; // instruction length
468
reg  [7:0] iqentry_exc   [0:QENTRIES-1];  // only for branches ... indicates a HALT instruction
469
reg [RBIT:0] iqentry_tgt [0:QENTRIES-1];  // Rt field or ZERO -- this is the instruction's target (if any)
470
reg  [7:0] iqentry_vl   [0:QENTRIES-1];
471
reg  [5:0] iqentry_ven  [0:QENTRIES-1];  // vector element number
472
reg [63:0] iqentry_a0    [0:QENTRIES-1];  // argument 0 (immediate)
473
reg [63:0] iqentry_a1    [0:QENTRIES-1];  // argument 1
474
reg        iqentry_a1_v [0:QENTRIES-1];  // arg1 valid
475
reg  [4:0] iqentry_a1_s  [0:QENTRIES-1];  // arg1 source (iq entry # with top bit representing ALU/DRAM bus)
476
reg [63:0] iqentry_a2    [0:QENTRIES-1];  // argument 2
477
reg        iqentry_a2_v [0:QENTRIES-1];  // arg2 valid
478
reg  [4:0] iqentry_a2_s  [0:QENTRIES-1];  // arg2 source (iq entry # with top bit representing ALU/DRAM bus)
479
reg [63:0] iqentry_a3    [0:QENTRIES-1];  // argument 3
480
reg        iqentry_a3_v [0:QENTRIES-1];  // arg3 valid
481
reg  [4:0] iqentry_a3_s  [0:QENTRIES-1];  // arg3 source (iq entry # with top bit representing ALU/DRAM bus)
482 49 robfinch
reg [`ABITS] iqentry_pc [0:QENTRIES-1];  // program counter for this instruction
483 48 robfinch
reg [RBIT:0] iqentry_Ra [0:QENTRIES-1];
484
reg [RBIT:0] iqentry_Rb [0:QENTRIES-1];
485
reg [RBIT:0] iqentry_Rc [0:QENTRIES-1];
486
// debugging
487
//reg  [4:0] iqentry_ra   [0:7];  // Ra
488
initial begin
489
for (n = 0; n < QENTRIES; n = n + 1)
490
        iqentry_a1_s[n] = 5'd0;
491
        iqentry_a2_s[n] = 5'd0;
492
        iqentry_a3_s[n] = 5'd0;
493
end
494
 
495 53 robfinch
reg [QENTRIES-1:0] iqentry_source = {QENTRIES{1'b0}};
496 48 robfinch
reg   [QENTRIES-1:0] iqentry_imm;
497 53 robfinch
reg  [QENTRIES-1:0] iqentry_memready;
498
reg  [QENTRIES-1:0] iqentry_memopsvalid;
499 48 robfinch
 
500 53 robfinch
reg  [QENTRIES-1:0] memissue = {QENTRIES{1'b0}};
501 48 robfinch
reg [1:0] missued;
502
integer last_issue;
503
reg  [QENTRIES-1:0] iqentry_memissue;
504
wire [QENTRIES-1:0] iqentry_stomp;
505
reg [3:0] stompedOnRets;
506
reg  [QENTRIES-1:0] iqentry_alu0_issue;
507
reg  [QENTRIES-1:0] iqentry_alu1_issue;
508 49 robfinch
reg  [QENTRIES-1:0] iqentry_alu2_issue;
509 48 robfinch
reg  [QENTRIES-1:0] iqentry_id1issue;
510
reg  [QENTRIES-1:0] iqentry_id2issue;
511 49 robfinch
reg  [QENTRIES-1:0] iqentry_id3issue;
512 48 robfinch
reg [1:0] iqentry_mem_islot [0:QENTRIES-1];
513
reg [QENTRIES-1:0] iqentry_fcu_issue;
514 49 robfinch
reg [QENTRIES-1:0] iqentry_fpu1_issue;
515
reg [QENTRIES-1:0] iqentry_fpu2_issue;
516 48 robfinch
 
517
wire [PREGS-1:1] livetarget;
518
wire  [PREGS-1:1] iqentry_0_livetarget;
519
wire  [PREGS-1:1] iqentry_1_livetarget;
520
wire  [PREGS-1:1] iqentry_2_livetarget;
521
wire  [PREGS-1:1] iqentry_3_livetarget;
522
wire  [PREGS-1:1] iqentry_4_livetarget;
523
wire  [PREGS-1:1] iqentry_5_livetarget;
524
wire  [PREGS-1:1] iqentry_6_livetarget;
525
wire  [PREGS-1:1] iqentry_7_livetarget;
526 52 robfinch
wire  [PREGS-1:1] iqentry_8_livetarget;
527
wire  [PREGS-1:1] iqentry_9_livetarget;
528
wire [PREGS-1:1] iqentry_livetarget [0:QENTRIES-1];
529
assign iqentry_livetarget[0] = iqentry_0_livetarget;
530
assign iqentry_livetarget[1] = iqentry_1_livetarget;
531
assign iqentry_livetarget[2] = iqentry_2_livetarget;
532
assign iqentry_livetarget[3] = iqentry_3_livetarget;
533
assign iqentry_livetarget[4] = iqentry_4_livetarget;
534
assign iqentry_livetarget[5] = iqentry_5_livetarget;
535
assign iqentry_livetarget[6] = iqentry_6_livetarget;
536
assign iqentry_livetarget[7] = iqentry_7_livetarget;
537
assign iqentry_livetarget[8] = iqentry_8_livetarget;
538
assign iqentry_livetarget[9] = iqentry_9_livetarget;
539 53 robfinch
reg [PREGS-1:1] iqentry_latestID [0:QENTRIES-1];
540 52 robfinch
reg [PREGS-1:1] iqentry_cumulative [0:QENTRIES-1];
541 53 robfinch
wire  [PREGS-1:1] iq_out [0:QENTRIES-1];
542 48 robfinch
 
543
reg  [`QBITS] tail0;
544
reg  [`QBITS] tail1;
545
reg  [`QBITS] head0;
546
reg  [`QBITS] head1;
547
reg  [`QBITS] head2;    // used only to determine memory-access ordering
548
reg  [`QBITS] head3;    // used only to determine memory-access ordering
549
reg  [`QBITS] head4;    // used only to determine memory-access ordering
550
reg  [`QBITS] head5;    // used only to determine memory-access ordering
551
reg  [`QBITS] head6;    // used only to determine memory-access ordering
552
reg  [`QBITS] head7;    // used only to determine memory-access ordering
553 52 robfinch
reg  [`QBITS] head8;
554
reg  [`QBITS] head9;
555 48 robfinch
 
556
wire take_branch0;
557
wire take_branch1;
558
 
559
reg [3:0] nop_fetchbuf;
560
wire        fetchbuf;   // determines which pair to read from & write to
561 49 robfinch
wire [3:0] fb_panic;
562 48 robfinch
 
563
wire [47:0] fetchbuf0_instr;
564
wire  [2:0] fetchbuf0_insln;
565 49 robfinch
wire [`ABITS] fetchbuf0_pc;
566 48 robfinch
wire        fetchbuf0_v;
567
wire            fetchbuf0_thrd;
568
wire        fetchbuf0_mem;
569
wire            fetchbuf0_memld;
570
wire        fetchbuf0_rfw;
571
wire [47:0] fetchbuf1_instr;
572
wire  [2:0] fetchbuf1_insln;
573 49 robfinch
wire [`ABITS] fetchbuf1_pc;
574 48 robfinch
wire        fetchbuf1_v;
575
wire            fetchbuf1_thrd;
576
wire        fetchbuf1_mem;
577
wire            fetchbuf1_memld;
578
wire        fetchbuf1_rfw;
579 57 robfinch
wire [47:0] fetchbuf2_instr;
580
wire  [2:0] fetchbuf2_insln;
581
wire [`ABITS] fetchbuf2_pc;
582
wire        fetchbuf2_v;
583
wire            fetchbuf2_thrd;
584
wire        fetchbuf2_mem;
585
wire            fetchbuf2_memld;
586
wire        fetchbuf2_rfw;
587 48 robfinch
 
588
wire [47:0] fetchbufA_instr;
589 49 robfinch
wire [`ABITS] fetchbufA_pc;
590 48 robfinch
wire        fetchbufA_v;
591
wire [47:0] fetchbufB_instr;
592 49 robfinch
wire [`ABITS] fetchbufB_pc;
593 48 robfinch
wire        fetchbufB_v;
594
wire [47:0] fetchbufC_instr;
595 49 robfinch
wire [`ABITS] fetchbufC_pc;
596 48 robfinch
wire        fetchbufC_v;
597
wire [47:0] fetchbufD_instr;
598 49 robfinch
wire [`ABITS] fetchbufD_pc;
599 48 robfinch
wire        fetchbufD_v;
600 57 robfinch
wire [47:0] fetchbufE_instr;
601
wire [`ABITS] fetchbufE_pc;
602
wire        fetchbufE_v;
603
wire [47:0] fetchbufF_instr;
604
wire [`ABITS] fetchbufF_pc;
605
wire        fetchbufF_v;
606 48 robfinch
 
607
//reg        did_branchback0;
608
//reg        did_branchback1;
609
 
610
reg         id1_v;
611
reg   [4:0] id1_id;
612
reg  [47:0] id1_instr;
613
reg   [5:0] id1_ven;
614
reg   [7:0] id1_vl;
615
reg         id1_thrd;
616
reg         id1_pt;
617
reg   [4:0] id1_Rt;
618 51 robfinch
wire [143:0] id1_bus;
619 48 robfinch
 
620
reg         id2_v;
621
reg   [4:0] id2_id;
622
reg  [47:0] id2_instr;
623
reg   [5:0] id2_ven;
624
reg   [7:0] id2_vl;
625
reg         id2_thrd;
626
reg         id2_pt;
627
reg   [4:0] id2_Rt;
628 51 robfinch
wire [143:0] id2_bus;
629 48 robfinch
 
630 49 robfinch
reg         id3_v;
631
reg   [4:0] id3_id;
632
reg  [47:0] id3_instr;
633
reg   [5:0] id3_ven;
634
reg   [7:0] id3_vl;
635
reg         id3_thrd;
636
reg         id3_pt;
637
reg   [4:0] id3_Rt;
638 51 robfinch
wire [143:0] id3_bus;
639 49 robfinch
 
640 48 robfinch
reg        alu0_ld;
641
reg        alu0_dataready;
642
wire       alu0_done;
643
wire       alu0_idle;
644
reg  [3:0] alu0_sourceid;
645
reg [47:0] alu0_instr;
646
reg        alu0_bt;
647
reg        alu0_mem;
648
reg        alu0_shft48;
649
reg [63:0] alu0_argA;
650
reg [63:0] alu0_argB;
651
reg [63:0] alu0_argC;
652
reg [63:0] alu0_argI;    // only used by BEQ
653
reg [RBIT:0] alu0_tgt;
654
reg [5:0]  alu0_ven;
655
reg        alu0_thrd;
656 49 robfinch
reg [`ABITS] alu0_pc;
657 48 robfinch
wire [63:0] alu0_bus;
658
wire [63:0] alu0b_bus;
659
wire  [3:0] alu0_id;
660 49 robfinch
wire  [`XBITS] alu0_exc;
661 48 robfinch
wire        alu0_v;
662
wire        alu0_branchmiss;
663 49 robfinch
wire [`ABITS] alu0_misspc;
664 48 robfinch
 
665
reg        alu1_ld;
666
reg        alu1_dataready;
667
wire       alu1_done;
668
wire       alu1_idle;
669
reg  [3:0] alu1_sourceid;
670
reg [47:0] alu1_instr;
671
reg        alu1_bt;
672
reg        alu1_mem;
673
reg        alu1_shft48;
674
reg [63:0] alu1_argA;
675
reg [63:0] alu1_argB;
676
reg [63:0] alu1_argC;
677
reg [63:0] alu1_argI;    // only used by BEQ
678
reg [RBIT:0] alu1_tgt;
679
reg [5:0]  alu1_ven;
680 49 robfinch
reg [`ABITS] alu1_pc;
681 48 robfinch
reg        alu1_thrd;
682
wire [63:0] alu1_bus;
683
wire [63:0] alu1b_bus;
684
wire  [3:0] alu1_id;
685 49 robfinch
wire  [`XBITS] alu1_exc;
686 48 robfinch
wire        alu1_v;
687
wire        alu1_branchmiss;
688 49 robfinch
wire [`ABITS] alu1_misspc;
689 48 robfinch
 
690 52 robfinch
wire [`XBITS] fpu_exc;
691 49 robfinch
reg        fpu1_ld;
692
reg        fpu1_dataready = 1'b1;
693
wire       fpu1_done = 1'b1;
694
wire       fpu1_idle;
695
reg  [3:0] fpu1_sourceid;
696
reg [47:0] fpu1_instr;
697
reg [63:0] fpu1_argA;
698
reg [63:0] fpu1_argB;
699
reg [63:0] fpu1_argC;
700
reg [63:0] fpu1_argI;    // only used by BEQ
701
reg [RBIT:0] fpu1_tgt;
702
reg [`ABITS] fpu1_pc;
703 53 robfinch
wire [63:0] fpu1_bus = 64'h0;
704 49 robfinch
wire  [3:0] fpu1_id;
705
wire  [`XBITS] fpu1_exc = 9'h000;
706
wire        fpu1_v;
707
wire [31:0] fpu1_status;
708 48 robfinch
 
709 49 robfinch
reg        fpu2_ld;
710
reg        fpu2_dataready = 1'b1;
711
wire       fpu2_done = 1'b1;
712
wire       fpu2_idle;
713
reg  [3:0] fpu2_sourceid;
714
reg [47:0] fpu2_instr;
715
reg [63:0] fpu2_argA;
716
reg [63:0] fpu2_argB;
717
reg [63:0] fpu2_argC;
718
reg [63:0] fpu2_argI;    // only used by BEQ
719
reg [RBIT:0] fpu2_tgt;
720
reg [`ABITS] fpu2_pc;
721 53 robfinch
wire [63:0] fpu2_bus = 64'h0;
722 49 robfinch
wire  [3:0] fpu2_id;
723
wire  [`XBITS] fpu2_exc = 9'h000;
724
wire        fpu2_v;
725
wire [31:0] fpu2_status;
726
 
727 48 robfinch
reg [63:0] waitctr;
728
reg        fcu_ld;
729
reg        fcu_dataready;
730
reg        fcu_done;
731
reg         fcu_idle = 1'b1;
732
reg  [3:0] fcu_sourceid;
733
reg [47:0] fcu_instr;
734
reg  [2:0] fcu_insln;
735 51 robfinch
reg        fcu_branch;
736 48 robfinch
reg        fcu_call;
737 51 robfinch
reg        fcu_ret;
738
reg        fcu_jal;
739
reg        fcu_brk;
740
reg        fcu_rti;
741 48 robfinch
reg        fcu_bt;
742
reg [63:0] fcu_argA;
743
reg [63:0] fcu_argB;
744
reg [63:0] fcu_argC;
745
reg [63:0] fcu_argI;     // only used by BEQ
746
reg [63:0] fcu_argT;
747
reg [63:0] fcu_argT2;
748 49 robfinch
reg [`ABITS] fcu_pc;
749
reg [`ABITS] fcu_nextpc;
750
reg [`ABITS] fcu_brdisp;
751 48 robfinch
wire [63:0] fcu_bus;
752
wire  [3:0] fcu_id;
753 49 robfinch
reg   [`XBITS] fcu_exc;
754 48 robfinch
wire        fcu_v;
755
reg        fcu_thrd;
756
reg        fcu_branchmiss;
757
reg  fcu_clearbm;
758 49 robfinch
reg [`ABITS] fcu_misspc;
759 48 robfinch
 
760
reg [63:0] rmw_argA;
761
reg [63:0] rmw_argB;
762
reg [63:0] rmw_argC;
763
wire [63:0] rmw_res;
764
reg [31:0] rmw_instr;
765
 
766 49 robfinch
// write buffer
767
reg [63:0] wb_data [0:`WB_DEPTH-1];
768
reg [`ABITS] wb_addr [0:`WB_DEPTH-1];
769
reg [1:0] wb_ol [0:`WB_DEPTH-1];
770
reg [`WB_DEPTH-1:0] wb_v;
771
reg [`WB_DEPTH-1:0] wb_rmw;
772
reg [QENTRIES-1:0] wb_id [0:`WB_DEPTH-1];
773
reg [QENTRIES-1:0] wbo_id;
774
reg [7:0] wb_sel [0:`WB_DEPTH-1];
775
reg wb_en;
776 52 robfinch
reg wb_shift;
777 49 robfinch
 
778 48 robfinch
reg branchmiss = 1'b0;
779
reg branchmiss_thrd = 1'b0;
780 49 robfinch
reg [`ABITS] misspc;
781 48 robfinch
reg  [`QBITS] missid;
782
 
783
wire take_branch;
784
wire take_branchA;
785
wire take_branchB;
786
wire take_branchC;
787
wire take_branchD;
788
 
789
wire        dram_avail;
790
reg      [2:0] dram0;    // state of the DRAM request (latency = 4; can have three in pipeline)
791
reg      [2:0] dram1;    // state of the DRAM request (latency = 4; can have three in pipeline)
792
reg      [2:0] dram2;    // state of the DRAM request (latency = 4; can have three in pipeline)
793
reg [63:0] dram0_data;
794 49 robfinch
reg [`ABITS] dram0_addr;
795 48 robfinch
reg [47:0] dram0_instr;
796
reg        dram0_rmw;
797
reg                dram0_preload;
798
reg [RBIT:0] dram0_tgt;
799
reg  [3:0] dram0_id;
800 49 robfinch
reg  [`XBITS] dram0_exc;
801 48 robfinch
reg        dram0_unc;
802
reg [2:0]  dram0_memsize;
803
reg        dram0_load;  // is a load operation
804 50 robfinch
reg        dram0_store;
805 48 robfinch
reg  [1:0] dram0_ol;
806
reg [63:0] dram1_data;
807 49 robfinch
reg [`ABITS] dram1_addr;
808 48 robfinch
reg [47:0] dram1_instr;
809
reg        dram1_rmw;
810
reg                dram1_preload;
811
reg [RBIT:0] dram1_tgt;
812
reg  [3:0] dram1_id;
813 49 robfinch
reg  [`XBITS] dram1_exc;
814 48 robfinch
reg        dram1_unc;
815
reg [2:0]  dram1_memsize;
816
reg        dram1_load;
817 50 robfinch
reg        dram1_store;
818 48 robfinch
reg  [1:0] dram1_ol;
819
reg [63:0] dram2_data;
820 49 robfinch
reg [`ABITS] dram2_addr;
821 48 robfinch
reg [47:0] dram2_instr;
822
reg        dram2_rmw;
823
reg                dram2_preload;
824
reg [RBIT:0] dram2_tgt;
825
reg  [3:0] dram2_id;
826 49 robfinch
reg  [`XBITS] dram2_exc;
827 48 robfinch
reg        dram2_unc;
828
reg [2:0]  dram2_memsize;
829
reg        dram2_load;
830 50 robfinch
reg        dram2_store;
831 48 robfinch
reg  [1:0] dram2_ol;
832
 
833
reg        dramA_v;
834
reg  [3:0] dramA_id;
835
reg [63:0] dramA_bus;
836 49 robfinch
reg  [`XBITS] dramA_exc;
837 48 robfinch
reg        dramB_v;
838
reg  [3:0] dramB_id;
839
reg [63:0] dramB_bus;
840 49 robfinch
reg  [`XBITS] dramB_exc;
841 48 robfinch
reg        dramC_v;
842
reg  [3:0] dramC_id;
843
reg [63:0] dramC_bus;
844 49 robfinch
reg  [`XBITS] dramC_exc;
845 48 robfinch
 
846
wire        outstanding_stores;
847 58 robfinch
reg [63:0] I;            // instruction count
848
reg [63:0] CC;   // commit count
849 48 robfinch
 
850
reg        commit0_v;
851
reg  [4:0] commit0_id;
852
reg [RBIT:0] commit0_tgt;
853
reg  [7:0] commit0_we = 8'h00;
854
reg [63:0] commit0_bus;
855
reg        commit1_v;
856
reg  [4:0] commit1_id;
857
reg [RBIT:0] commit1_tgt;
858
reg  [7:0] commit1_we = 8'h00;
859
reg [63:0] commit1_bus;
860 58 robfinch
reg        commit2_v;
861
reg  [4:0] commit2_id;
862
reg [RBIT:0] commit2_tgt;
863
reg  [7:0] commit2_we = 8'h00;
864
reg [63:0] commit2_bus;
865 48 robfinch
 
866
reg [4:0] bstate;
867
parameter BIDLE = 5'd0;
868 58 robfinch
parameter B_DCacheStoreAck = 5'd1;
869
parameter B_DCacheLoadStart = 5'd2;
870
parameter B_DCacheLoadStb = 5'd3;
871
parameter B_DCacheLoadWait1 = 5'd4;
872
parameter B_DCacheLoadWait2 = 5'd5;
873
parameter B_DCacheLoadResetBusy = 5'd6;
874 48 robfinch
parameter B7 = 5'd7;
875
parameter B8 = 5'd8;
876
parameter B9 = 5'd9;
877
parameter B10 = 5'd10;
878
parameter B11 = 5'd11;
879
parameter B12 = 5'd12;
880
parameter B13 = 5'd13;
881
parameter B14 = 5'd14;
882
parameter B15 = 5'd15;
883
parameter B16 = 5'd16;
884
parameter B17 = 5'd17;
885
parameter B18 = 5'd18;
886
parameter B19 = 5'd19;
887
parameter B2a = 5'd20;
888
parameter B2b = 5'd21;
889
parameter B2c = 5'd22;
890 58 robfinch
parameter B_DCacheLoadAck = 5'd23;
891 48 robfinch
parameter B20 = 5'd24;
892
parameter B21 = 5'd25;
893 58 robfinch
parameter B_DCacheLoadWait3 = 5'd26;
894 48 robfinch
reg [1:0] bwhich;
895
reg [3:0] icstate,picstate;
896
parameter IDLE = 4'd0;
897
parameter IC1 = 4'd1;
898
parameter IC2 = 4'd2;
899
parameter IC3 = 4'd3;
900
parameter IC4 = 4'd4;
901
parameter IC5 = 4'd5;
902
parameter IC6 = 4'd6;
903
parameter IC7 = 4'd7;
904
parameter IC8 = 4'd8;
905
parameter IC9 = 4'd9;
906
parameter IC10 = 4'd10;
907
parameter IC3a = 4'd11;
908
reg invic, invdc;
909 49 robfinch
reg [1:0] icwhich;
910
reg icnxt,L2_nxt;
911
wire ihit0,ihit1,ihit2,ihitL2;
912
wire ihit = ihit0&ihit1&ihit2;
913 48 robfinch
reg phit;
914
wire threadx;
915
always @*
916
        phit <= ihit&&icstate==IDLE;
917
reg [2:0] iccnt;
918 49 robfinch
reg L1_wr0,L1_wr1,L1_wr2;
919 48 robfinch
reg L1_invline;
920 49 robfinch
reg [8:0] L1_en;
921 48 robfinch
reg [37:0] L1_adr, L2_adr;
922 49 robfinch
reg [287:0] L2_rdat;
923
wire [287:0] L2_dato;
924 48 robfinch
reg L2_xsel;
925
 
926 57 robfinch
generate begin : gRegfileInst
927
if (`WAYS > 2) begin : gb1
928
FT64_regfile2w9r_oc #(.RBIT(RBIT)) urf1
929 48 robfinch
(
930
  .clk(clk),
931
  .clk4x(clk4x),
932
  .wr0(commit0_v),
933
  .wr1(commit1_v),
934
  .we0(commit0_we),
935
  .we1(commit1_we),
936
  .wa0(commit0_tgt),
937
  .wa1(commit1_tgt),
938
  .i0(commit0_bus),
939
  .i1(commit1_bus),
940
        .rclk(~clk),
941
        .ra0(Ra0),
942
        .ra1(Rb0),
943
        .ra2(Rc0),
944 57 robfinch
        .o0(rfoa0),
945
        .o1(rfob0),
946
        .o2(rfoc0a),
947 48 robfinch
        .ra3(Ra1),
948
        .ra4(Rb1),
949
        .ra5(Rc1),
950 57 robfinch
        .o3(rfoa1),
951
        .o4(rfob1),
952
        .o5(rfoc1a),
953
        .ra6(Ra2),
954
        .ra7(Rb2),
955
        .ra8(Rc2),
956
        .o6(rfoa2),
957
        .o7(rfob2),
958
        .o8(rfoc2a)
959
);
960
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
961
assign rfoc1 = Rc1[11:6]==6'h3F ? vm[Rc1[2:0]] : rfoc1a;
962
assign rfoc2 = Rc2[11:6]==6'h3F ? vm[Rc2[2:0]] : rfoc2a;
963
end
964
else if (`WAYS > 1) begin : gb1
965
FT64_regfile2w6r_oc #(.RBIT(RBIT)) urf1
966
(
967
  .clk(clk),
968
  .clk4x(clk4x),
969
  .wr0(commit0_v),
970
  .wr1(commit1_v),
971
  .we0(commit0_we),
972
  .we1(commit1_we),
973
  .wa0(commit0_tgt),
974
  .wa1(commit1_tgt),
975
  .i0(commit0_bus),
976
  .i1(commit1_bus),
977
        .rclk(~clk),
978
        .ra0(Ra0),
979
        .ra1(Rb0),
980
        .ra2(Rc0),
981 48 robfinch
        .o0(rfoa0),
982
        .o1(rfob0),
983
        .o2(rfoc0a),
984 57 robfinch
        .ra3(Ra1),
985
        .ra4(Rb1),
986
        .ra5(Rc1),
987 48 robfinch
        .o3(rfoa1),
988
        .o4(rfob1),
989
        .o5(rfoc1a)
990
);
991
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
992
assign rfoc1 = Rc1[11:6]==6'h3F ? vm[Rc1[2:0]] : rfoc1a;
993 57 robfinch
end
994
else begin : gb1
995
FT64_regfile1w3r_oc #(.RBIT(RBIT)) urf1
996
(
997
  .clk(clk),
998
  .wr0(commit0_v),
999
  .we0(commit0_we),
1000
  .wa0(commit0_tgt),
1001
  .i0(commit0_bus),
1002
        .rclk(~clk),
1003
        .ra0(Ra0),
1004
        .ra1(Rb0),
1005
        .ra2(Rc0),
1006
        .o0(rfoa0),
1007
        .o1(rfob0),
1008
        .o2(rfoc0a)
1009
);
1010
end
1011
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
1012
end
1013
endgenerate
1014 48 robfinch
 
1015 55 robfinch
function [3:0] fnInsLength;
1016 48 robfinch
input [47:0] ins;
1017 57 robfinch
`ifdef SUPPORT_DCI
1018 55 robfinch
if (ins[`INSTRUCTION_OP]==`CMPRSSD)
1019
        fnInsLength = 4'd2;
1020
else
1021 57 robfinch
`endif
1022 55 robfinch
        case(ins[7:6])
1023
        2'd0:   fnInsLength = 4'd4;
1024
        2'd1:   fnInsLength = 4'd6;
1025
        default:        fnInsLength = 4'd2;
1026
        endcase
1027 48 robfinch
endfunction
1028
 
1029 49 robfinch
wire [`ABITS] pc0plus6 = pc0 + 32'd6;
1030
wire [`ABITS] pc0plus12 = pc0 + 32'd12;
1031 48 robfinch
 
1032 49 robfinch
generate begin : gInsnVar
1033
        if (`WAYS > 1) begin
1034 52 robfinch
                always @*
1035
                        if (thread_en)
1036
                                insn1a <= insn1b;
1037
                        else
1038
                                insn1a = {insn1b,insn0a} >> {fnInsLength(insn0a),3'b0};
1039 49 robfinch
        end
1040
        if (`WAYS > 2) begin
1041 52 robfinch
                always @*
1042
                        if (thread_en)
1043
                                insn2a <= insn2b;
1044
                        else
1045
                                insn2a = {insn2b,insn1b,insn0a} >> {fnInsLength(insn0a) + fnInsLength(insn1a),3'b0};
1046 49 robfinch
        end
1047
end
1048
endgenerate
1049 48 robfinch
 
1050 58 robfinch
FT64_L1_icache #(.pSize(`L1_ICACHE_SIZE)) uic0
1051 48 robfinch
(
1052
    .rst(rst),
1053
    .clk(clk),
1054
    .nxt(icnxt),
1055
    .wr(L1_wr0),
1056
    .en(L1_en),
1057
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc0} : L1_adr),
1058
    .wadr(L1_adr),
1059
    .i(L2_rdat),
1060
    .o(insn0a),
1061
    .hit(ihit0),
1062
    .invall(invic),
1063
    .invline(L1_invline)
1064
);
1065 49 robfinch
generate begin : gICacheInst
1066
if (`WAYS > 1) begin
1067 58 robfinch
FT64_L1_icache #(.pSize(`L1_ICACHE_SIZE)) uic1
1068 48 robfinch
(
1069
    .rst(rst),
1070
    .clk(clk),
1071
    .nxt(icnxt),
1072
    .wr(L1_wr1),
1073
    .en(L1_en),
1074 52 robfinch
    .adr(icstate==IDLE||icstate==IC8 ? (thread_en ? {pcr[5:0],pc1}: {pcr[5:0],pc0plus6} ): L1_adr),
1075 48 robfinch
    .wadr(L1_adr),
1076
    .i(L2_rdat),
1077
    .o(insn1b),
1078
    .hit(ihit1),
1079
    .invall(invic),
1080
    .invline(L1_invline)
1081
);
1082 49 robfinch
end
1083
else begin
1084
assign ihit1 = 1'b1;
1085
end
1086
if (`WAYS > 2) begin
1087 58 robfinch
FT64_L1_icache #(.pSize(`L1_ICACHE_SIZE)) uic2
1088 49 robfinch
(
1089
    .rst(rst),
1090
    .clk(clk),
1091
    .nxt(icnxt),
1092
    .wr(L1_wr2),
1093
    .en(L1_en),
1094 52 robfinch
    .adr(icstate==IDLE||icstate==IC8 ? (thread_en ? {pcr[5:0],pc2} : {pcr[5:0],pc0plus12}) : L1_adr),
1095 49 robfinch
    .wadr(L1_adr),
1096
    .i(L2_rdat),
1097
    .o(insn2b),
1098
    .hit(ihit2),
1099
    .invall(invic),
1100
    .invline(L1_invline)
1101
);
1102
end
1103
else
1104
assign ihit2 = 1'b1;
1105
end
1106
endgenerate
1107
 
1108 48 robfinch
FT64_L2_icache uic2
1109
(
1110
    .rst(rst),
1111
    .clk(clk),
1112
    .nxt(L2_nxt),
1113
    .wr(bstate==B7 && ack_i),
1114
    .xsel(L2_xsel),
1115
    .adr(L2_adr),
1116
    .cnt(iccnt),
1117
    .exv_i(exvq),
1118
    .i(dat_i),
1119
    .err_i(errq),
1120
    .o(L2_dato),
1121 49 robfinch
    .hit(ihitL2),
1122 48 robfinch
    .invall(invic),
1123
    .invline()
1124
);
1125
 
1126
wire predict_taken;
1127
wire predict_taken0;
1128
wire predict_taken1;
1129 57 robfinch
wire predict_taken2;
1130 48 robfinch
wire predict_takenA;
1131
wire predict_takenB;
1132
wire predict_takenC;
1133
wire predict_takenD;
1134 57 robfinch
wire predict_takenE;
1135
wire predict_takenF;
1136 48 robfinch
wire predict_takenA1;
1137
wire predict_takenB1;
1138
wire predict_takenC1;
1139
wire predict_takenD1;
1140
 
1141 57 robfinch
wire [`ABITS] btgtA, btgtB, btgtC, btgtD, btgtE, btgtF;
1142 48 robfinch
wire btbwr0 = iqentry_v[head0] && iqentry_done[head0] &&
1143
        (
1144 51 robfinch
        iqentry_jal[head0] ||
1145
        iqentry_brk[head0] ||
1146
        iqentry_rti[head0]);
1147 57 robfinch
generate begin: gbtbvar
1148
if (`WAYS > 1) begin
1149 48 robfinch
wire btbwr1 = iqentry_v[head1] && iqentry_done[head1] &&
1150
        (
1151 51 robfinch
        iqentry_jal[head1] ||
1152
        iqentry_brk[head1] ||
1153
        iqentry_rti[head1]);
1154 57 robfinch
end
1155
end
1156
endgenerate
1157 48 robfinch
 
1158 50 robfinch
wire fcu_clk;
1159 49 robfinch
`ifdef FCU_ENH
1160 50 robfinch
//BUFGCE ufcuclk
1161
//(
1162
//      .I(clk_i),
1163
//      .CE(fcu_available),
1164
//      .O(fcu_clk)
1165
//);
1166 49 robfinch
`endif
1167 50 robfinch
assign fcu_clk = clk_i;
1168 49 robfinch
 
1169 57 robfinch
generate begin: gBTBInst
1170
if (`WAYS > 2) begin
1171 49 robfinch
`ifdef FCU_ENH
1172 48 robfinch
FT64_BTB ubtb1
1173
(
1174 49 robfinch
  .rst(rst),
1175
  .wclk(fcu_clk),
1176
  .wr(btbwr0 | btbwr1),
1177
  .wadr(btbwr0 ? iqentry_pc[head0] : iqentry_pc[head1]),
1178
  .wdat(btbwr0 ? iqentry_a0[head0] : iqentry_a0[head1]),
1179
  .valid(btbwr0 ? iqentry_bt[head0] & iqentry_v[head0] : iqentry_bt[head1] & iqentry_v[head1]),
1180
  .rclk(~clk),
1181
  .pcA(fetchbufA_pc),
1182
  .btgtA(btgtA),
1183
  .pcB(fetchbufB_pc),
1184
  .btgtB(btgtB),
1185
  .pcC(fetchbufC_pc),
1186
  .btgtC(btgtC),
1187
  .pcD(fetchbufD_pc),
1188
  .btgtD(btgtD),
1189 57 robfinch
  .pcE(fetchbufE_pc),
1190
  .btgtE(btgtE),
1191
  .pcF(fetchbufF_pc),
1192
  .btgtF(btgtF),
1193 49 robfinch
  .npcA(BRKPC),
1194
  .npcB(BRKPC),
1195
  .npcC(BRKPC),
1196 57 robfinch
  .npcD(BRKPC),
1197
  .npcE(BRKPC),
1198
  .npcF(BRKPC)
1199 48 robfinch
);
1200 49 robfinch
`else
1201
// Branch tergets are picked up by fetchbuf logic and need to be present.
1202
// Without a target predictor they are just set to the reset address.
1203
// This virtually guarentees a miss.
1204
assign btgtA = RSTPC;
1205
assign btgtB = RSTPC;
1206
assign btgtC = RSTPC;
1207
assign btgtD = RSTPC;
1208 57 robfinch
assign btgtE = RSTPC;
1209
assign btgtF = RSTPC;
1210 49 robfinch
`endif
1211 57 robfinch
end
1212
else if (`WAYS > 1) begin
1213
`ifdef FCU_ENH
1214
FT64_BTB ubtb1
1215
(
1216
  .rst(rst),
1217
  .wclk(fcu_clk),
1218
  .wr(btbwr0 | btbwr1),
1219
  .wadr(btbwr0 ? iqentry_pc[head0] : iqentry_pc[head1]),
1220
  .wdat(btbwr0 ? iqentry_a0[head0] : iqentry_a0[head1]),
1221
  .valid(btbwr0 ? iqentry_bt[head0] & iqentry_v[head0] : iqentry_bt[head1] & iqentry_v[head1]),
1222
  .rclk(~clk),
1223
  .pcA(fetchbufA_pc),
1224
  .btgtA(btgtA),
1225
  .pcB(fetchbufB_pc),
1226
  .btgtB(btgtB),
1227
  .pcC(fetchbufC_pc),
1228
  .btgtC(btgtC),
1229
  .pcD(fetchbufD_pc),
1230
  .btgtD(btgtD),
1231
  .pcE(32'd0),
1232
  .btgtE(),
1233
  .pcF(32'd0),
1234
  .btgtF(),
1235
  .npcA(BRKPC),
1236
  .npcB(BRKPC),
1237
  .npcC(BRKPC),
1238
  .npcD(BRKPC),
1239
  .npcE(BRKPC),
1240
  .npcF(BRKPC)
1241
);
1242
`else
1243
// Branch tergets are picked up by fetchbuf logic and need to be present.
1244
// Without a target predictor they are just set to the reset address.
1245
// This virtually guarentees a miss.
1246
assign btgtA = RSTPC;
1247
assign btgtB = RSTPC;
1248
assign btgtC = RSTPC;
1249
assign btgtD = RSTPC;
1250
`endif
1251
end
1252
else begin
1253
`ifdef FCU_ENH
1254
FT64_BTB ubtb1
1255
(
1256
  .rst(rst),
1257
  .wclk(fcu_clk),
1258
  .wr(btbwr0),
1259
  .wadr(iqentry_pc[head0]),
1260
  .wdat(iqentry_a0[head0]),
1261
  .valid(iqentry_bt[head0] & iqentry_v[head0]),
1262
  .rclk(~clk),
1263
  .pcA(fetchbufA_pc),
1264
  .btgtA(btgtA),
1265
  .pcB(fetchbufB_pc),
1266
  .btgtB(btgtB),
1267
  .pcC(32'd0),
1268
  .btgtC(),
1269
  .pcD(32'd0),
1270
  .btgtD(),
1271
  .pcE(32'd0),
1272
  .btgtE(),
1273
  .pcF(32'd0),
1274
  .btgtF(),
1275
  .npcA(BRKPC),
1276
  .npcB(BRKPC),
1277
  .npcC(BRKPC),
1278
  .npcD(BRKPC),
1279
  .npcE(BRKPC),
1280
  .npcF(BRKPC)
1281
);
1282
`else
1283
// Branch tergets are picked up by fetchbuf logic and need to be present.
1284
// Without a target predictor they are just set to the reset address.
1285
// This virtually guarentees a miss.
1286
assign btgtA = RSTPC;
1287
assign btgtB = RSTPC;
1288
`endif
1289
end
1290
end
1291
endgenerate
1292 48 robfinch
 
1293 57 robfinch
generate begin: gBPInst
1294
if (`WAYS > 2) begin
1295 49 robfinch
`ifdef FCU_ENH
1296 48 robfinch
FT64_BranchPredictor ubp1
1297
(
1298 49 robfinch
  .rst(rst),
1299
  .clk(fcu_clk),
1300
  .en(bpe),
1301
  .xisBranch0(iqentry_br[head0] & commit0_v),
1302
  .xisBranch1(iqentry_br[head1] & commit1_v),
1303 58 robfinch
  .xisBranch2(iqentry_br[head2] & commit2_v),
1304 49 robfinch
  .pcA(fetchbufA_pc),
1305
  .pcB(fetchbufB_pc),
1306
  .pcC(fetchbufC_pc),
1307
  .pcD(fetchbufD_pc),
1308 57 robfinch
  .pcE(fetchbufE_pc),
1309
  .pcF(fetchbufF_pc),
1310 49 robfinch
  .xpc0(iqentry_pc[head0]),
1311
  .xpc1(iqentry_pc[head1]),
1312 58 robfinch
  .xpc2(iqentry_pc[head2]),
1313 52 robfinch
  .takb0(commit0_v & iqentry_takb[head0]),
1314
  .takb1(commit1_v & iqentry_takb[head1]),
1315 58 robfinch
  .takb2(commit2_v & iqentry_takb[head2]),
1316 49 robfinch
  .predict_takenA(predict_takenA),
1317
  .predict_takenB(predict_takenB),
1318
  .predict_takenC(predict_takenC),
1319 57 robfinch
  .predict_takenD(predict_takenD),
1320
  .predict_takenE(predict_takenE),
1321
  .predict_takenF(predict_takenF)
1322 48 robfinch
);
1323 49 robfinch
`else
1324
// Predict based on sign of displacement
1325
assign predict_takenA = fetchbufA_instr[31];
1326
assign predict_takenB = fetchbufB_instr[31];
1327
assign predict_takenC = fetchbufC_instr[31];
1328
assign predict_takenD = fetchbufD_instr[31];
1329 57 robfinch
assign predict_takenE = fetchbufE_instr[31];
1330
assign predict_takenF = fetchbufF_instr[31];
1331 49 robfinch
`endif
1332 57 robfinch
end
1333
else if (`WAYS > 1) begin
1334
`ifdef FCU_ENH
1335
FT64_BranchPredictor ubp1
1336
(
1337
  .rst(rst),
1338
  .clk(fcu_clk),
1339
  .en(bpe),
1340
  .xisBranch0(iqentry_br[head0] & commit0_v),
1341
  .xisBranch1(iqentry_br[head1] & commit1_v),
1342 58 robfinch
  .xisBranch2(iqentry_br[head2] & commit2_v),
1343 57 robfinch
  .pcA(fetchbufA_pc),
1344
  .pcB(fetchbufB_pc),
1345
  .pcC(fetchbufC_pc),
1346
  .pcD(fetchbufD_pc),
1347
  .pcE(32'd0),
1348
  .pcF(32'd0),
1349
  .xpc0(iqentry_pc[head0]),
1350
  .xpc1(iqentry_pc[head1]),
1351 58 robfinch
  .xpc2(iqentry_pc[head2]),
1352 57 robfinch
  .takb0(commit0_v & iqentry_takb[head0]),
1353
  .takb1(commit1_v & iqentry_takb[head1]),
1354 58 robfinch
  .takb2(commit2_v & iqentry_takb[head2]),
1355 57 robfinch
  .predict_takenA(predict_takenA),
1356
  .predict_takenB(predict_takenB),
1357
  .predict_takenC(predict_takenC),
1358
  .predict_takenD(predict_takenD),
1359
  .predict_takenE(),
1360
  .predict_takenF()
1361
);
1362
`else
1363
// Predict based on sign of displacement
1364
assign predict_takenA = fetchbufA_instr[31];
1365
assign predict_takenB = fetchbufB_instr[31];
1366
assign predict_takenC = fetchbufC_instr[31];
1367
assign predict_takenD = fetchbufD_instr[31];
1368
`endif
1369
end
1370
else begin
1371
`ifdef FCU_ENH
1372
FT64_BranchPredictor ubp1
1373
(
1374
  .rst(rst),
1375
  .clk(fcu_clk),
1376
  .en(bpe),
1377
  .xisBranch0(iqentry_br[head0] & commit0_v),
1378 58 robfinch
  .xisBranch1(iqentry_br[head1] & commit1_v),
1379
  .xisBranch2(iqentry_br[head2] & commit2_v),
1380 57 robfinch
  .pcA(fetchbufA_pc),
1381
  .pcB(fetchbufB_pc),
1382
  .pcC(32'd0),
1383
  .pcD(32'd0),
1384
  .pcE(32'd0),
1385
  .pcF(32'd0),
1386
  .xpc0(iqentry_pc[head0]),
1387 58 robfinch
  .xpc1(iqentry_pc[head1]),
1388
  .xpc2(iqentry_pc[head2]),
1389 57 robfinch
  .takb0(commit0_v & iqentry_takb[head0]),
1390 58 robfinch
  .takb1(commit1_v & iqentry_takb[head1]),
1391
  .takb2(commit2_v & iqentry_takb[head2]),
1392 57 robfinch
  .predict_takenA(predict_takenA),
1393
  .predict_takenB(predict_takenB),
1394
  .predict_takenC(),
1395
  .predict_takenD(),
1396
  .predict_takenE(),
1397
  .predict_takenF()
1398
);
1399
`else
1400
// Predict based on sign of displacement
1401
assign predict_takenA = fetchbufA_instr[31];
1402
assign predict_takenB = fetchbufB_instr[31];
1403
`endif
1404
end
1405
end
1406
endgenerate
1407 48 robfinch
 
1408
//-----------------------------------------------------------------------------
1409
// Debug
1410
//-----------------------------------------------------------------------------
1411
`ifdef SUPPORT_DBG
1412
 
1413
wire [DBW-1:0] dbg_stat1x;
1414
reg [DBW-1:0] dbg_stat;
1415
reg [DBW-1:0] dbg_ctrl;
1416
reg [ABW-1:0] dbg_adr0;
1417
reg [ABW-1:0] dbg_adr1;
1418
reg [ABW-1:0] dbg_adr2;
1419
reg [ABW-1:0] dbg_adr3;
1420
reg dbg_imatchA0,dbg_imatchA1,dbg_imatchA2,dbg_imatchA3,dbg_imatchA;
1421
reg dbg_imatchB0,dbg_imatchB1,dbg_imatchB2,dbg_imatchB3,dbg_imatchB;
1422
 
1423
wire dbg_lmatch00 =
1424
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1425
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1426
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1427
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1428
                                 dbg_ctrl[19:18]==2'b11)
1429
                                 ;
1430
wire dbg_lmatch01 =
1431
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1432
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1433
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1434
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1435
                  dbg_ctrl[19:18]==2'b11)
1436
                  ;
1437
wire dbg_lmatch02 =
1438
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1439
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1440
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1441
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1442
                dbg_ctrl[19:18]==2'b11)
1443
                ;
1444
wire dbg_lmatch10 =
1445
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1446
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1447
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1448
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1449
                  dbg_ctrl[23:22]==2'b11)
1450
                  ;
1451
wire dbg_lmatch11 =
1452
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1453
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1454
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1455
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1456
                dbg_ctrl[23:22]==2'b11)
1457
                ;
1458
wire dbg_lmatch12 =
1459
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1460
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1461
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1462
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1463
                dbg_ctrl[23:22]==2'b11)
1464
                ;
1465
wire dbg_lmatch20 =
1466
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1467
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1468
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1469
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1470
                    dbg_ctrl[27:26]==2'b11)
1471
                    ;
1472
wire dbg_lmatch21 =
1473
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1474
                   ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1475
                    (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1476
                    (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1477
                    dbg_ctrl[27:26]==2'b11)
1478
                    ;
1479
wire dbg_lmatch22 =
1480
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1481
                   ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1482
                    (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1483
                    (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1484
                    dbg_ctrl[27:26]==2'b11)
1485
                    ;
1486
wire dbg_lmatch30 =
1487
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1488
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1489
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1490
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1491
                      dbg_ctrl[31:30]==2'b11)
1492
                      ;
1493
wire dbg_lmatch31 =
1494
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1495
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1496
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1497
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1498
                    dbg_ctrl[31:30]==2'b11)
1499
                    ;
1500
wire dbg_lmatch32 =
1501
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1502
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1503
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1504
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1505
                    dbg_ctrl[31:30]==2'b11)
1506
                    ;
1507
wire dbg_lmatch0 = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30;
1508
wire dbg_lmatch1 = dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31;
1509
wire dbg_lmatch2 = dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32;
1510
wire dbg_lmatch = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30|
1511
                  dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31|
1512
                  dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32
1513
                    ;
1514
 
1515
wire dbg_smatch00 =
1516
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1517
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1518
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1519
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1520
                                 dbg_ctrl[19:18]==2'b11)
1521
                                 ;
1522
wire dbg_smatch01 =
1523
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1524
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1525
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1526
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1527
                  dbg_ctrl[19:18]==2'b11)
1528
                  ;
1529
wire dbg_smatch02 =
1530
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1531
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1532
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1533
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1534
                dbg_ctrl[19:18]==2'b11)
1535
                ;
1536
wire dbg_smatch10 =
1537
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1538
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1539
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1540
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1541
                  dbg_ctrl[23:22]==2'b11)
1542
                  ;
1543
wire dbg_smatch11 =
1544
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1545
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1546
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1547
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1548
                dbg_ctrl[23:22]==2'b11)
1549
                ;
1550
wire dbg_smatch12 =
1551
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1552
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1553
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1554
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1555
                dbg_ctrl[23:22]==2'b11)
1556
                ;
1557
wire dbg_smatch20 =
1558
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1559
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1560
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1561
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1562
                    dbg_ctrl[27:26]==2'b11)
1563
                    ;
1564
wire dbg_smatch21 =
1565
           dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1566
                    ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1567
                     (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1568
                     (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1569
                     dbg_ctrl[27:26]==2'b11)
1570
                     ;
1571
wire dbg_smatch22 =
1572
            dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1573
                     ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1574
                      (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1575
                      (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1576
                      dbg_ctrl[27:26]==2'b11)
1577
                      ;
1578
wire dbg_smatch30 =
1579
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1580
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1581
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1582
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1583
                      dbg_ctrl[31:30]==2'b11)
1584
                      ;
1585
wire dbg_smatch31 =
1586
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1587
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1588
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1589
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1590
                    dbg_ctrl[31:30]==2'b11)
1591
                    ;
1592
wire dbg_smatch32 =
1593
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1594
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1595
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1596
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1597
                    dbg_ctrl[31:30]==2'b11)
1598
                    ;
1599
wire dbg_smatch0 = dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30;
1600
wire dbg_smatch1 = dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31;
1601
wire dbg_smatch2 = dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32;
1602
 
1603
wire dbg_smatch =   dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30|
1604
                    dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31|
1605
                    dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32
1606
                    ;
1607
 
1608
wire dbg_stat0 = dbg_imatchA0 | dbg_imatchB0 | dbg_lmatch00 | dbg_lmatch01 | dbg_lmatch02 | dbg_smatch00 | dbg_smatch01 | dbg_smatch02;
1609
wire dbg_stat1 = dbg_imatchA1 | dbg_imatchB1 | dbg_lmatch10 | dbg_lmatch11 | dbg_lmatch12 | dbg_smatch10 | dbg_smatch11 | dbg_smatch12;
1610
wire dbg_stat2 = dbg_imatchA2 | dbg_imatchB2 | dbg_lmatch20 | dbg_lmatch21 | dbg_lmatch22 | dbg_smatch20 | dbg_smatch21 | dbg_smatch22;
1611
wire dbg_stat3 = dbg_imatchA3 | dbg_imatchB3 | dbg_lmatch30 | dbg_lmatch31 | dbg_lmatch32 | dbg_smatch30 | dbg_smatch31 | dbg_smatch32;
1612
assign dbg_stat1x = {dbg_stat3,dbg_stat2,dbg_stat1,dbg_stat0};
1613
wire debug_on = |dbg_ctrl[3:0]|dbg_ctrl[7]|dbg_ctrl[63];
1614
 
1615
always @*
1616
begin
1617
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf0_pc==dbg_adr0)
1618
        dbg_imatchA0 = `TRUE;
1619
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf0_pc==dbg_adr1)
1620
        dbg_imatchA1 = `TRUE;
1621
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf0_pc==dbg_adr2)
1622
        dbg_imatchA2 = `TRUE;
1623
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf0_pc==dbg_adr3)
1624
        dbg_imatchA3 = `TRUE;
1625
    if (dbg_imatchA0|dbg_imatchA1|dbg_imatchA2|dbg_imatchA3)
1626
        dbg_imatchA = `TRUE;
1627
end
1628
 
1629
always @*
1630
begin
1631
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf1_pc==dbg_adr0)
1632
        dbg_imatchB0 = `TRUE;
1633
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf1_pc==dbg_adr1)
1634
        dbg_imatchB1 = `TRUE;
1635
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf1_pc==dbg_adr2)
1636
        dbg_imatchB2 = `TRUE;
1637
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf1_pc==dbg_adr3)
1638
        dbg_imatchB3 = `TRUE;
1639
    if (dbg_imatchB0|dbg_imatchB1|dbg_imatchB2|dbg_imatchB3)
1640
        dbg_imatchB = `TRUE;
1641
end
1642
`endif
1643
 
1644
//-----------------------------------------------------------------------------
1645
//-----------------------------------------------------------------------------
1646
 
1647 52 robfinch
// freezePC squashes the pc increment if there's an irq.
1648
wire freezePC = (irq_i > im) && ~int_commit;
1649 48 robfinch
always @*
1650 52 robfinch
if (freezePC)
1651 49 robfinch
        insn0 <= {8'd0,3'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1652 48 robfinch
else if (phit) begin
1653 49 robfinch
        if (insn0a[`INSTRUCTION_OP]==`BRK && insn0a[23:21]==3'd0 && insn0a[7:6]==2'b00)
1654
                insn0 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1655 48 robfinch
        else
1656
                insn0 <= insn0a;
1657
end
1658
else
1659
        insn0 <= `NOP_INSN;
1660 49 robfinch
generate begin : gInsnMux
1661
if (`WAYS > 1) begin
1662 48 robfinch
always @*
1663 52 robfinch
if (freezePC && !thread_en)
1664
        insn1 <= {8'd0,3'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1665
else if (phit) begin
1666 49 robfinch
        if (insn1a[`INSTRUCTION_OP]==`BRK && insn1a[23:21]==3'd0 && insn1a[7:6]==2'b00)
1667
                insn1 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1668 48 robfinch
        else
1669
                insn1 <= insn1a;
1670
end
1671
else
1672
        insn1 <= `NOP_INSN;
1673 49 robfinch
end
1674
if (`WAYS > 2) begin
1675
always @*
1676 52 robfinch
if (freezePC && !thread_en)
1677
        insn2 <= {8'd0,3'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1678
else if (phit) begin
1679 49 robfinch
        if (insn2a[`INSTRUCTION_OP]==`BRK && insn1a[23:21]==3'd0 && insn2a[7:6]==2'b00)
1680
                insn2 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1681
        else
1682
                insn2 <= insn2a;
1683
end
1684
else
1685
        insn2 <= `NOP_INSN;
1686
end
1687
end
1688
endgenerate
1689 48 robfinch
 
1690
wire [63:0] dc0_out, dc1_out, dc2_out;
1691
assign rdat0 = dram0_unc ? xdati : dc0_out;
1692
assign rdat1 = dram1_unc ? xdati : dc1_out;
1693
assign rdat2 = dram2_unc ? xdati : dc2_out;
1694
 
1695
reg preload;
1696
reg [1:0] dccnt;
1697
wire dhit0, dhit1, dhit2;
1698 57 robfinch
wire dhit0a, dhit1a, dhit2a;
1699 48 robfinch
wire dhit00, dhit10, dhit20;
1700
wire dhit01, dhit11, dhit21;
1701 49 robfinch
reg [`ABITS] dc_wadr;
1702 48 robfinch
reg [63:0] dc_wdat;
1703
reg isStore;
1704
 
1705 57 robfinch
// If the data is in the write buffer, give the buffer a chance to
1706
// write out the data before trying to load from the cache.
1707
reg wb_hit0, wb_hit1, wb_hit2;
1708
always @*
1709
begin
1710
        wb_hit0 <= FALSE;
1711
        wb_hit1 <= FALSE;
1712
        wb_hit2 <= FALSE;
1713
        for (n = 0; n < `WB_DEPTH; n = n + 1) begin
1714
                if (wb_v[n] && wb_addr[n][31:3]==dram0_addr[31:3])
1715
                        wb_hit0 <= TRUE;
1716
                if (`NUM_MEM > 1 && wb_addr[n][31:3]==dram1_addr[31:3])
1717
                        wb_hit1 <= TRUE;
1718
                if (`NUM_MEM > 2 && wb_addr[n][31:3]==dram2_addr[31:3])
1719
                        wb_hit2 <= TRUE;
1720
        end
1721
end
1722
 
1723
assign dhit0 = dhit0a & !wb_hit0;
1724
assign dhit1 = dhit1a & !wb_hit1;
1725
assign dhit2 = dhit2a & !wb_hit2;
1726
wire whit0, whit1, whit2;
1727
 
1728 48 robfinch
FT64_dcache udc0
1729
(
1730
    .rst(rst),
1731
    .wclk(clk),
1732 58 robfinch
    .wr((bstate==B_DCacheLoadAck && ack_i)||((bstate==B_DCacheStoreAck||(bstate==B19 && isStore)) && whit0)),
1733 48 robfinch
    .sel(sel_o),
1734
    .wadr({pcr[5:0],adr_o}),
1735 57 robfinch
    .whit(whit0),
1736 58 robfinch
    .i(bstate==B_DCacheLoadAck ? dat_i : dat_o),
1737 48 robfinch
    .rclk(clk),
1738
    .rdsize(dram0_memsize),
1739
    .radr({pcr[5:0],dram0_addr}),
1740
    .o(dc0_out),
1741
    .hit(),
1742 57 robfinch
    .hit0(dhit0a),
1743 48 robfinch
    .hit1()
1744
);
1745 49 robfinch
generate begin : gDCacheInst
1746
if (`NUM_MEM > 1) begin
1747 48 robfinch
FT64_dcache udc1
1748
(
1749
    .rst(rst),
1750
    .wclk(clk),
1751 58 robfinch
    .wr((bstate==B_DCacheLoadAck && ack_i)||((bstate==B_DCacheStoreAck||(bstate==B19 && isStore)) && whit1)),
1752 48 robfinch
    .sel(sel_o),
1753
    .wadr({pcr[5:0],adr_o}),
1754 57 robfinch
    .whit(whit1),
1755 58 robfinch
    .i(bstate==B_DCacheLoadAck ? dat_i : dat_o),
1756 48 robfinch
    .rclk(clk),
1757
    .rdsize(dram1_memsize),
1758
    .radr({pcr[5:0],dram1_addr}),
1759
    .o(dc1_out),
1760
    .hit(),
1761 57 robfinch
    .hit0(dhit1a),
1762 48 robfinch
    .hit1()
1763
);
1764 49 robfinch
end
1765
if (`NUM_MEM > 2) begin
1766 48 robfinch
FT64_dcache udc2
1767
(
1768
    .rst(rst),
1769
    .wclk(clk),
1770 58 robfinch
    .wr((bstate==B_DCacheLoadAck && ack_i)||((bstate==B_DCacheStoreAck||(bstate==B19 && isStore)) && whit2)),
1771 48 robfinch
    .sel(sel_o),
1772
    .wadr({pcr[5:0],adr_o}),
1773 57 robfinch
    .whit(whit2),
1774 58 robfinch
    .i(bstate==B_DCacheLoadAck ? dat_i : dat_o),
1775 48 robfinch
    .rclk(clk),
1776
    .rdsize(dram2_memsize),
1777
    .radr({pcr[5:0],dram2_addr}),
1778
    .o(dc2_out),
1779
    .hit(),
1780 57 robfinch
    .hit0(dhit2a),
1781 48 robfinch
    .hit1()
1782
);
1783 49 robfinch
end
1784
end
1785
endgenerate
1786 48 robfinch
 
1787
function [`QBITS] idp1;
1788
input [`QBITS] id;
1789 52 robfinch
idp1 = (id + 1) % QENTRIES;
1790 48 robfinch
endfunction
1791
 
1792
function [`QBITS] idp2;
1793
input [`QBITS] id;
1794 52 robfinch
idp2 = (id + 2) % QENTRIES;
1795 48 robfinch
endfunction
1796
 
1797
function [`QBITS] idp3;
1798
input [`QBITS] id;
1799 52 robfinch
idp3 = (id + 3) % QENTRIES;
1800 48 robfinch
endfunction
1801
 
1802
function [`QBITS] idp4;
1803
input [`QBITS] id;
1804 52 robfinch
idp4 = (id + 4) % QENTRIES;
1805 48 robfinch
endfunction
1806
 
1807
function [`QBITS] idp5;
1808
input [`QBITS] id;
1809 52 robfinch
idp5 = (id + 5) % QENTRIES;
1810 48 robfinch
endfunction
1811
 
1812
function [`QBITS] idp6;
1813
input [`QBITS] id;
1814 52 robfinch
idp6 = (id + 6) % QENTRIES;
1815 48 robfinch
endfunction
1816
 
1817
function [`QBITS] idp7;
1818
input [`QBITS] id;
1819 52 robfinch
idp7 = (id + 7) % QENTRIES;
1820 48 robfinch
endfunction
1821
 
1822 52 robfinch
function [`QBITS] idp8;
1823
input [`QBITS] id;
1824
idp8 = (id + 8) % QENTRIES;
1825
endfunction
1826
 
1827
function [`QBITS] idp9;
1828
input [`QBITS] id;
1829
idp9 = (id + 9) % QENTRIES;
1830
endfunction
1831
 
1832 48 robfinch
function [`QBITS] idm1;
1833
input [`QBITS] id;
1834 52 robfinch
idm1 = (id - 1) % QENTRIES;
1835 48 robfinch
endfunction
1836
 
1837
`ifdef SUPPORT_SMT
1838
function [RBIT:0] fnRa;
1839
input [47:0] isn;
1840
input [5:0] vqei;
1841
input [5:0] vli;
1842
input thrd;
1843
case(isn[`INSTRUCTION_OP])
1844
`IVECTOR:
1845
        case(isn[`INSTRUCTION_S2])
1846
        `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1847
        `VMxx:
1848
                case(isn[25:23])
1849
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
1850
                    fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1851
            `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1852
            default:fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1853
            endcase
1854
        `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
1855
        `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
1856
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1857
        default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1858
        endcase
1859 50 robfinch
`R2:    casez(isn[`INSTRUCTION_S2])
1860 48 robfinch
                `MOV:
1861
                        case(isn[25:23])
1862
                        3'd0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1863 50 robfinch
                        3'd1:   fnRa = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
1864 48 robfinch
                        3'd2:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1865
                        3'd3:   fnRa = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RA]};
1866
                        3'd4:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1867 51 robfinch
                        3'd5:   fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1868
                        3'd6:   fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1869 48 robfinch
                        default:fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1870
                        endcase
1871
        `VMOV:
1872
            case (isn[`INSTRUCTION_S1])
1873
            5'h0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1874
            5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
1875
            endcase
1876
        default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1877
        endcase
1878 51 robfinch
`FLOAT:         fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1879 48 robfinch
default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1880
endcase
1881
endfunction
1882
 
1883
function [RBIT:0] fnRb;
1884
input [47:0] isn;
1885
input fb;
1886
input [5:0] vqei;
1887
input [5:0] rfoa0i;
1888
input [5:0] rfoa1i;
1889
input thrd;
1890
case(isn[`INSTRUCTION_OP])
1891
`R2:        case(isn[`INSTRUCTION_S2])
1892
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
1893
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1894
            default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1895
            endcase
1896
`IVECTOR:
1897
                        case(isn[`INSTRUCTION_S2])
1898
                        `VMxx:
1899
                                case(isn[25:23])
1900
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
1901
                        fnRb = {6'h3F,1'b1,2'b0,isn[13:11]};
1902
                default:        fnRb = 12'h000;
1903
                endcase
1904
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1905
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1906
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
1907
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
1908
                fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1909
            `VSHL,`VSHR,`VASR:
1910
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
1911
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1912
            endcase
1913 51 robfinch
`FLOAT:         fnRb = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1914 48 robfinch
default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1915
endcase
1916
endfunction
1917
 
1918
function [RBIT:0] fnRc;
1919
input [47:0] isn;
1920
input [5:0] vqei;
1921
input thrd;
1922
case(isn[`INSTRUCTION_OP])
1923
`R2:        case(isn[`INSTRUCTION_S2])
1924
            `SVX:       fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1925
                `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1926
                        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1927
                `CMOVEZ,`CMOVNZ,`MAJ:
1928
                        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1929
            default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1930
            endcase
1931
`IVECTOR:
1932
                        case(isn[`INSTRUCTION_S2])
1933
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[18:16]};
1934
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1935
            endcase
1936 51 robfinch
`FLOAT:         fnRc = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1937 48 robfinch
default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1938
endcase
1939
endfunction
1940
 
1941
function [RBIT:0] fnRt;
1942
input [47:0] isn;
1943
input [5:0] vqei;
1944
input [5:0] vli;
1945
input thrd;
1946
casez(isn[`INSTRUCTION_OP])
1947
`IVECTOR:
1948
                case(isn[`INSTRUCTION_S2])
1949
                `VMxx:
1950
                        case(isn[25:23])
1951
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
1952
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1953
            `VMPOP:     fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1954
            default:
1955
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1956
            endcase
1957
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1958
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
1959
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
1960
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
1961
        `V2BITS:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1962
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1963
        endcase
1964
 
1965 50 robfinch
`R2:    casez(isn[`INSTRUCTION_S2])
1966 48 robfinch
                `MOV:
1967
                        case(isn[25:23])
1968 50 robfinch
                        3'd0:   fnRt = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RB]};
1969 48 robfinch
                        3'd1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1970
                        3'd2:   fnRt = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RB]};
1971
                        3'd3:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1972 51 robfinch
                        3'd4:   fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1973 48 robfinch
                        3'd5:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1974 51 robfinch
                        3'd6:   fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1975 48 robfinch
                        default:fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1976
                        endcase
1977
        `VMOV:
1978
            case (isn[`INSTRUCTION_S1])
1979
            5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RB]};
1980
            5'h1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1981
            default:    fnRt = 12'h000;
1982
            endcase
1983
        `R1:
1984
                case(isn[22:18])
1985
                `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT:
1986
                        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1987
                `MEMDB,`MEMSB,`SYNC:
1988
                        fnRt = 12'd0;
1989
                default:        fnRt = 12'd0;
1990
                endcase
1991
        `CMOVEZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1992
        `CMOVNZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1993
        `MUX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1994
        `MIN:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1995
        `MAX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1996
        `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
1997
        `SHIFTR:        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1998
        `SHIFT31,`SHIFT63:
1999
                                fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2000
        `SEI:           fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2001
        `WAIT,`RTI,`CHK:
2002
                        fnRt = 12'd0;
2003
                default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2004
        endcase
2005
`MEMNDX:
2006
    case(isn[`INSTRUCTION_S2])
2007
    `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
2008
                        fnRt = 12'd0;
2009
    default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2010
        endcase
2011
`FLOAT:
2012
                case(isn[31:26])
2013
                `FTX,`FCX,`FEX,`FDX,`FRM:
2014
                                        fnRt = 12'd0;
2015
                `FSYNC:         fnRt = 12'd0;
2016 51 robfinch
                default:        fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2017 48 robfinch
                endcase
2018
`BRK:   fnRt = 12'd0;
2019
`REX:   fnRt = 12'd0;
2020
`CHK:   fnRt = 12'd0;
2021
`EXEC:  fnRt = 12'd0;
2022
`Bcc:   fnRt = 12'd0;
2023
`BBc:   case(isn[20:19])
2024
                `IBNE:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2025
                `DBNZ:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2026
                default:        fnRt = 12'd0;
2027
                endcase
2028
`BEQI:  fnRt = 12'd0;
2029
`SB,`Sx,`SWC,`CACHE:
2030
                fnRt = 12'd0;
2031
`JMP:   fnRt = 12'd0;
2032
`CALL:  fnRt = {rgs[thrd],1'b0,regLR};  // regLR
2033
`RET:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2034
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2035
`AMO:   fnRt = isn[31] ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2036 56 robfinch
`AUIPC,`LUI:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2037 48 robfinch
default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2038
endcase
2039
endfunction
2040
`else
2041
function [RBIT:0] fnRa;
2042
input [47:0] isn;
2043
input [5:0] vqei;
2044
input [5:0] vli;
2045
input thrd;
2046
case(isn[`INSTRUCTION_OP])
2047
`IVECTOR:
2048
        case(isn[`INSTRUCTION_S2])
2049 51 robfinch
  `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
2050
  `VMxx:
2051
        case(isn[25:23])
2052
        `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
2053
              fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
2054
      `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
2055
      default:fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
2056
      endcase
2057
  `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
2058
  `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
2059
  `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
2060
  default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
2061
  endcase
2062 50 robfinch
`R2:
2063
        casez(isn[`INSTRUCTION_S2])
2064
        `MOV:
2065
                case(isn[25:23])
2066
                3'd0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2067
                3'd1:   fnRa = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
2068
                3'd2:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2069
                3'd3:   fnRa = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RA]};
2070
                3'd4:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2071 51 robfinch
                3'd5:   fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2072
                3'd6:   fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2073 50 robfinch
                default:fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2074
                endcase
2075
  `VMOV:
2076
    case (isn[`INSTRUCTION_S1])
2077
    5'h0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2078
    5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
2079
    endcase
2080
  default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2081
  endcase
2082 51 robfinch
`FLOAT:         fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2083 48 robfinch
default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2084
endcase
2085
endfunction
2086
 
2087
function [RBIT:0] fnRb;
2088
input [47:0] isn;
2089
input fb;
2090
input [5:0] vqei;
2091
input [5:0] rfoa0i;
2092
input [5:0] rfoa1i;
2093
input thrd;
2094
case(isn[`INSTRUCTION_OP])
2095
`RR:        case(isn[`INSTRUCTION_S2])
2096
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
2097
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2098
            default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2099
            endcase
2100
`IVECTOR:
2101
                        case(isn[`INSTRUCTION_S2])
2102
                        `VMxx:
2103
                                case(isn[25:23])
2104
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2105
                        fnRb = {6'h3F,1'b1,2'b0,isn[13:11]};
2106
                default:        fnRb = 12'h000;
2107
                endcase
2108
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2109
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2110
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
2111
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
2112
                fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2113
            `VSHL,`VSHR,`VASR:
2114
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
2115
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2116
            endcase
2117 51 robfinch
`FLOAT:         fnRb = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
2118 48 robfinch
default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2119
endcase
2120
endfunction
2121
 
2122
function [RBIT:0] fnRc;
2123
input [47:0] isn;
2124
input [5:0] vqei;
2125
input thrd;
2126
case(isn[`INSTRUCTION_OP])
2127
`R2:        case(isn[`INSTRUCTION_S2])
2128
            `SVX:       fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2129
                `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
2130
                        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2131
                `CMOVEZ,`CMOVNZ,`MAJ:
2132
                        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2133
            default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2134
            endcase
2135
`IVECTOR:
2136
                        case(isn[`INSTRUCTION_S2])
2137
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[18:16]};
2138
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2139
            endcase
2140 51 robfinch
`FLOAT:         fnRc = {fp_rgs,1'b0,isn[`INSTRUCTION_RC]};
2141 48 robfinch
default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2142
endcase
2143
endfunction
2144
 
2145
function [RBIT:0] fnRt;
2146
input [47:0] isn;
2147
input [5:0] vqei;
2148
input [5:0] vli;
2149
input thrd;
2150
casez(isn[`INSTRUCTION_OP])
2151
`IVECTOR:
2152
                case(isn[`INSTRUCTION_S2])
2153
                `VMxx:
2154
                        case(isn[25:23])
2155
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
2156
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2157
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2158
            default:
2159
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2160
            endcase
2161
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2162
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
2163
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
2164
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
2165
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2166
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2167
        endcase
2168
 
2169
`FVECTOR:
2170
                case(isn[`INSTRUCTION_S2])
2171
                `VMxx:
2172
                        case(isn[25:23])
2173
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
2174
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2175
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2176
            default:
2177
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2178
            endcase
2179
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2180
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
2181
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
2182
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
2183
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2184
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2185
        endcase
2186
 
2187 50 robfinch
`R2:
2188
        casez(isn[`INSTRUCTION_S2])
2189
        `MOV:
2190
                case(isn[25:23])
2191
                3'd0:   fnRt = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RB]};
2192
                3'd1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2193
                3'd2:   fnRt = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RB]};
2194
                3'd3:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2195 51 robfinch
                3'd4:   fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
2196 50 robfinch
                3'd5:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2197 51 robfinch
                3'd6:   fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
2198 50 robfinch
                default:fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2199
                endcase
2200
  `VMOV:
2201
    case (isn[`INSTRUCTION_S1])
2202
    5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RB]};
2203
    5'h1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2204
    default:    fnRt = 12'h000;
2205
    endcase
2206
  `R1:
2207
        case(isn[22:18])
2208
        `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT:
2209
                fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2210
        `MEMDB,`MEMSB,`SYNC:
2211
                fnRt = 12'd0;
2212
        default:        fnRt = 12'd0;
2213
        endcase
2214
  `CMOVEZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2215
  `CMOVNZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2216
  `MUX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2217
  `MIN:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2218
  `MAX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2219
  `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
2220
  `SHIFTR:      fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2221
  `SHIFT31,`SHIFT63:
2222
                        fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2223
  `SEI:         fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2224
  `WAIT,`RTI,`CHK:
2225
                        fnRt = 12'd0;
2226
  default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2227
  endcase
2228 48 robfinch
`MEMNDX:
2229
        case(isn[`INSTRUCTION_S2])
2230
  `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
2231
                        fnRt = 12'd0;
2232
  default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2233
  endcase
2234
`FLOAT:
2235
                case(isn[31:26])
2236
                `FTX,`FCX,`FEX,`FDX,`FRM:
2237
                                        fnRt = 12'd0;
2238
                `FSYNC:         fnRt = 12'd0;
2239 51 robfinch
                default:        fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RC]};
2240 48 robfinch
                endcase
2241
`BRK:   fnRt = 12'd0;
2242
`REX:   fnRt = 12'd0;
2243
`CHK:   fnRt = 12'd0;
2244
`EXEC:  fnRt = 12'd0;
2245
`Bcc:   fnRt = 12'd0;
2246
`BBc:
2247
        case(isn[20:19])
2248
        `IBNE:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2249
        `DBNZ:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2250
        default:        fnRt = 12'd0;
2251
        endcase
2252
`BEQI:  fnRt = 12'd0;
2253
`SB,`Sx,`SWC,`CACHE:
2254
                fnRt = 12'd0;
2255
`JMP:   fnRt = 12'd0;
2256
`CALL:  fnRt = {rgs,1'b0,regLR};        // regLR
2257
`RET:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2258
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2259
`AMO:   fnRt = isn[31] ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {rgs,1'b0,isn[`INSTRUCTION_RC]};
2260 56 robfinch
`AUIPC,`LUI:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2261 48 robfinch
default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2262
endcase
2263
endfunction
2264
`endif
2265
 
2266
// Determines which lanes of the target register get updated.
2267
function [7:0] fnWe;
2268
input [47:0] isn;
2269
casez(isn[`INSTRUCTION_OP])
2270
`R2:
2271
        case(isn[`INSTRUCTION_S2])
2272
        `R1:
2273
                case(isn[22:18])
2274
                `ABS,`CNTLZ,`CNTLO,`CNTPOP:
2275
                        case(isn[25:23])
2276
                        3'b000: fnWe = 8'h01;
2277
                        3'b001: fnWe = 8'h03;
2278
                        3'b010: fnWe = 8'h0F;
2279
                        3'b011: fnWe = 8'hFF;
2280
                        default:        fnWe = 8'hFF;
2281
                        endcase
2282
                default: fnWe = 8'hFF;
2283
                endcase
2284
        `SHIFT31:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2285
        `SHIFT63:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2286
        `SLT,`SLTU,`SLE,`SLEU,
2287
        `ADD,`SUB,
2288
        `AND,`OR,`XOR,
2289
        `NAND,`NOR,`XNOR,
2290 50 robfinch
        `DIV,`DIVU,`DIVSU,
2291
        `MOD,`MODU,`MODSU,
2292
        `MUL,`MULU,`MULSU,
2293
        `MULH,`MULUH,`MULSUH:
2294 48 robfinch
                case(isn[25:23])
2295
                3'b000: fnWe = 8'h01;
2296
                3'b001: fnWe = 8'h03;
2297
                3'b010: fnWe = 8'h0F;
2298
                3'b011: fnWe = 8'hFF;
2299
                default:        fnWe = 8'hFF;
2300
                endcase
2301
        default: fnWe = 8'hFF;
2302
        endcase
2303
default:        fnWe = 8'hFF;
2304
endcase
2305
endfunction
2306
 
2307
// Detect if a source is automatically valid
2308
function Source1Valid;
2309
input [47:0] isn;
2310
casez(isn[`INSTRUCTION_OP])
2311
`BRK:   Source1Valid = TRUE;
2312
`Bcc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2313
`BBc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2314
`BEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2315
`CHK:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2316
`RR:    case(isn[`INSTRUCTION_S2])
2317
        `SHIFT31:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2318
        `SHIFT63:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2319
        `SHIFTR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2320
        default:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2321
        endcase
2322
`MEMNDX:Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2323
`ADDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2324
`SLTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2325
`SLTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2326
`SGTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2327
`SGTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2328
`ANDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2329
`ORI:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2330
`XORI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2331
`XNORI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2332
`MULUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2333
`AMO:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2334
`LB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2335
`LBU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2336
`Lx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2337
`LxU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2338
`LWR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2339
`LV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2340
`LVx:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2341
`SB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2342
`Sx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2343
`SWC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2344
`SV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2345
`INC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2346
`CAS:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2347
`JAL:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2348
`RET:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2349
`CSRRW: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2350 51 robfinch
`BITFIELD:      case(isn[47:44])
2351
        `BFINSI:        Source1Valid = TRUE;
2352
        default:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0 || isn[30]==1'b0;
2353
        endcase
2354 48 robfinch
`IVECTOR:
2355 51 robfinch
        Source1Valid = FALSE;
2356 48 robfinch
default:    Source1Valid = TRUE;
2357
endcase
2358
endfunction
2359
 
2360
function Source2Valid;
2361
input [47:0] isn;
2362
casez(isn[`INSTRUCTION_OP])
2363
`BRK:   Source2Valid = TRUE;
2364
`Bcc:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2365
`BBc:   Source2Valid = TRUE;
2366
`BEQI:  Source2Valid = TRUE;
2367
`CHK:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2368
`RR:    case(isn[`INSTRUCTION_S2])
2369
        `R1:       Source2Valid = TRUE;
2370
        `SHIFTR:   Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2371
        `SHIFT31:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2372
        `SHIFT63:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2373
        `LVX,`SVX: Source2Valid = FALSE;
2374
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2375
        endcase
2376
`MEMNDX:
2377
        case(isn[`INSTRUCTION_S2])
2378
        `LVX,`SVX: Source2Valid = FALSE;
2379
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2380
        endcase
2381
`ADDI:  Source2Valid = TRUE;
2382
`SLTI:  Source2Valid = TRUE;
2383
`SLTUI: Source2Valid = TRUE;
2384
`SGTI:  Source2Valid = TRUE;
2385
`SGTUI: Source2Valid = TRUE;
2386
`ANDI:  Source2Valid = TRUE;
2387
`ORI:   Source2Valid = TRUE;
2388
`XORI:  Source2Valid = TRUE;
2389
`XNORI: Source2Valid = TRUE;
2390
`MULUI: Source2Valid = TRUE;
2391
`LB:    Source2Valid = TRUE;
2392
`LBU:   Source2Valid = TRUE;
2393
`Lx:    Source2Valid = TRUE;
2394
`LxU:   Source2Valid = TRUE;
2395
`LWR:   Source2Valid = TRUE;
2396
`LVx:   Source2Valid = TRUE;
2397
`INC:           Source2Valid = TRUE;
2398
`SB:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2399
`Sx:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2400
`SWC:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2401
`CAS:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2402
`JAL:   Source2Valid = TRUE;
2403
`RET:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2404
`IVECTOR:
2405
                    case(isn[`INSTRUCTION_S2])
2406
            `VABS:  Source2Valid = TRUE;
2407
            `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2408
                Source2Valid = FALSE;
2409
            `VADDS,`VSUBS,`VANDS,`VORS,`VXORS:
2410
                Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2411
            `VBITS2V:   Source2Valid = TRUE;
2412
            `V2BITS:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2413
            `VSHL,`VSHR,`VASR:  Source2Valid = isn[22:21]==2'd2;
2414
            default:    Source2Valid = FALSE;
2415
            endcase
2416
`LV:        Source2Valid = TRUE;
2417
`SV:        Source2Valid = FALSE;
2418
`AMO:           Source2Valid = isn[31] || isn[`INSTRUCTION_RB]==5'd0;
2419 51 robfinch
`BITFIELD:      Source2Valid = isn[`INSTRUCTION_RB]==5'd0 || isn[31]==1'b0;
2420 48 robfinch
default:    Source2Valid = TRUE;
2421
endcase
2422
endfunction
2423
 
2424
function Source3Valid;
2425
input [47:0] isn;
2426
case(isn[`INSTRUCTION_OP])
2427
`IVECTOR:
2428
    case(isn[`INSTRUCTION_S2])
2429
    `VEX:       Source3Valid = TRUE;
2430
    default:    Source3Valid = TRUE;
2431
    endcase
2432
`CHK:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2433
`R2:
2434
        if (isn[`INSTRUCTION_L2]==2'b01)
2435
                case(isn[47:42])
2436
    `CMOVEZ,`CMOVNZ:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2437
                default:        Source3Valid = TRUE;
2438
                endcase
2439
        else
2440
    case(isn[`INSTRUCTION_S2])
2441
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2442
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2443
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2444
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2445
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2446
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2447
    `MAJ:               Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2448
    default:    Source3Valid = TRUE;
2449
    endcase
2450
`MEMNDX:
2451
        if (isn[`INSTRUCTION_L2]==2'b00)
2452
    case(isn[`INSTRUCTION_S2])
2453
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2454
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2455
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2456
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2457
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2458
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2459
    default:    Source3Valid = TRUE;
2460
    endcase
2461 51 robfinch
`BITFIELD:      Source3Valid = isn[`INSTRUCTION_RC]==5'd0 || isn[32]==1'b0;
2462 48 robfinch
default:    Source3Valid = TRUE;
2463
endcase
2464
endfunction
2465
 
2466
// Used to indicate to the queue logic that the instruction needs to be
2467
// recycled to the queue VL number of times.
2468
function IsVector;
2469
input [47:0] isn;
2470
case(isn[`INSTRUCTION_OP])
2471 51 robfinch
`MEMNDX:
2472
  case(isn[`INSTRUCTION_S2])
2473
  `LVX,`SVX:  IsVector = TRUE;
2474
  default:    IsVector = FALSE;
2475
  endcase
2476 48 robfinch
`IVECTOR:
2477 51 robfinch
        case(isn[`INSTRUCTION_S2])
2478
        `VMxx:
2479
                case(isn[25:23])
2480
        `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2481
              IsVector = FALSE;
2482
    default:    IsVector = TRUE;
2483
    endcase
2484
  `VEINS:     IsVector = FALSE;
2485
  `VEX:       IsVector = FALSE;
2486
  default:    IsVector = TRUE;
2487
  endcase
2488 48 robfinch
`LV,`SV:    IsVector = TRUE;
2489
default:    IsVector = FALSE;
2490
endcase
2491
endfunction
2492
 
2493
function IsVeins;
2494
input [47:0] isn;
2495
case(isn[`INSTRUCTION_OP])
2496
`IVECTOR:   IsVeins = isn[`INSTRUCTION_S2]==`VEINS;
2497
default:    IsVeins = FALSE;
2498
endcase
2499
endfunction
2500
 
2501
function IsVex;
2502
input [47:0] isn;
2503
case(isn[`INSTRUCTION_OP])
2504
`IVECTOR:   IsVex = isn[`INSTRUCTION_S2]==`VEX;
2505
default:    IsVex = FALSE;
2506
endcase
2507
endfunction
2508
 
2509
function IsVCmprss;
2510
input [47:0] isn;
2511
case(isn[`INSTRUCTION_OP])
2512
`IVECTOR:   IsVCmprss = isn[`INSTRUCTION_S2]==`VCMPRSS || isn[`INSTRUCTION_S2]==`VCIDX;
2513
default:    IsVCmprss = FALSE;
2514
endcase
2515
endfunction
2516
 
2517
function IsVShifti;
2518
input [47:0] isn;
2519
case(isn[`INSTRUCTION_OP])
2520
`IVECTOR:
2521
                    case(isn[`INSTRUCTION_S2])
2522
            `VSHL,`VSHR,`VASR:
2523
                IsVShifti = {isn[25],isn[22]}==2'd2;
2524
            default:    IsVShifti = FALSE;
2525
            endcase
2526
default:    IsVShifti = FALSE;
2527
endcase
2528
endfunction
2529
 
2530
function IsVLS;
2531
input [47:0] isn;
2532
case(isn[`INSTRUCTION_OP])
2533
`MEMNDX:
2534
    case(isn[`INSTRUCTION_S2])
2535
    `LVX,`SVX,`LVWS,`SVWS:  IsVLS = TRUE;
2536
    default:    IsVLS = FALSE;
2537
    endcase
2538
`LV,`SV:    IsVLS = TRUE;
2539
default:    IsVLS = FALSE;
2540
endcase
2541
endfunction
2542
 
2543
function [1:0] fnM2;
2544
input [31:0] isn;
2545
case(isn[`INSTRUCTION_OP])
2546
`RR:    fnM2 = isn[24:23];
2547
default:    fnM2 = 2'b00;
2548
endcase
2549
endfunction
2550
 
2551
function [0:0] IsMem;
2552
input [47:0] isn;
2553
case(isn[`INSTRUCTION_OP])
2554
`MEMNDX:        IsMem = TRUE;
2555
`AMO:   IsMem = TRUE;
2556
`LB:    IsMem = TRUE;
2557
`LBU:   IsMem = TRUE;
2558
`Lx:    IsMem = TRUE;
2559
`LxU:   IsMem = TRUE;
2560
`LWR:   IsMem = TRUE;
2561
`LV,`SV:    IsMem = TRUE;
2562
`INC:           IsMem = TRUE;
2563
`SB:    IsMem = TRUE;
2564
`Sx:    IsMem = TRUE;
2565
`SWC:   IsMem = TRUE;
2566
`CAS:   IsMem = TRUE;
2567
`LVx:           IsMem = TRUE;
2568
default:    IsMem = FALSE;
2569
endcase
2570
endfunction
2571
 
2572
function IsMemNdx;
2573
input [47:0] isn;
2574
case(isn[`INSTRUCTION_OP])
2575
`MEMNDX:        IsMemNdx = TRUE;
2576
default:    IsMemNdx = FALSE;
2577
endcase
2578
endfunction
2579
 
2580
function IsLoad;
2581
input [47:0] isn;
2582
case(isn[`INSTRUCTION_OP])
2583
`MEMNDX:
2584
        if (isn[`INSTRUCTION_L2]==2'b00)
2585 50 robfinch
    case(isn[`INSTRUCTION_S2])
2586
    `LBX:   IsLoad = TRUE;
2587
    `LBUX:  IsLoad = TRUE;
2588
    `LCX:   IsLoad = TRUE;
2589
    `LCUX:  IsLoad = TRUE;
2590
    `LHX:   IsLoad = TRUE;
2591
    `LHUX:  IsLoad = TRUE;
2592
    `LWX:   IsLoad = TRUE;
2593
    `LVBX:      IsLoad = TRUE;
2594
    `LVBUX: IsLoad = TRUE;
2595
    `LVCX:  IsLoad = TRUE;
2596
    `LVCUX: IsLoad = TRUE;
2597
    `LVHX:  IsLoad = TRUE;
2598
    `LVHUX: IsLoad = TRUE;
2599
    `LVWX:  IsLoad = TRUE;
2600
    `LWRX:  IsLoad = TRUE;
2601
    `LVX:   IsLoad = TRUE;
2602
    default: IsLoad = FALSE;
2603
    endcase
2604 48 robfinch
        else
2605
                IsLoad = FALSE;
2606
`LB:    IsLoad = TRUE;
2607
`LBU:   IsLoad = TRUE;
2608
`Lx:    IsLoad = TRUE;
2609
`LxU:   IsLoad = TRUE;
2610
`LWR:   IsLoad = TRUE;
2611
`LV:    IsLoad = TRUE;
2612
`LVx:   IsLoad = TRUE;
2613
default:    IsLoad = FALSE;
2614
endcase
2615
endfunction
2616
 
2617
function IsInc;
2618
input [47:0] isn;
2619
case(isn[`INSTRUCTION_OP])
2620
`MEMNDX:
2621
        if (isn[`INSTRUCTION_L2]==2'b00)
2622
                case(isn[`INSTRUCTION_S2])
2623
            `INC:   IsInc = TRUE;
2624
            default:    IsInc = FALSE;
2625
            endcase
2626
        else
2627
                IsInc = FALSE;
2628
`INC:    IsInc = TRUE;
2629
default:    IsInc = FALSE;
2630
endcase
2631
endfunction
2632
 
2633
function IsSWC;
2634
input [47:0] isn;
2635
case(isn[`INSTRUCTION_OP])
2636
`MEMNDX:
2637
        if (isn[`INSTRUCTION_L2]==2'b00)
2638
                case(isn[`INSTRUCTION_S2])
2639
            `SWCX:   IsSWC = TRUE;
2640
            default:    IsSWC = FALSE;
2641
            endcase
2642
        else
2643
                IsSWC = FALSE;
2644
`SWC:    IsSWC = TRUE;
2645
default:    IsSWC = FALSE;
2646
endcase
2647
endfunction
2648
 
2649
// Aquire / release bits are only available on indexed SWC / LWR
2650
function IsSWCX;
2651
input [47:0] isn;
2652
case(isn[`INSTRUCTION_OP])
2653
`MEMNDX:
2654
        if (isn[`INSTRUCTION_L2]==2'b00)
2655
            case(isn[`INSTRUCTION_S2])
2656
            `SWCX:   IsSWCX = TRUE;
2657
            default:    IsSWCX = FALSE;
2658
            endcase
2659
        else
2660
                IsSWCX = FALSE;
2661
default:    IsSWCX = FALSE;
2662
endcase
2663
endfunction
2664
 
2665
function IsLWR;
2666
input [47:0] isn;
2667
case(isn[`INSTRUCTION_OP])
2668
`MEMNDX:
2669
        if (isn[`INSTRUCTION_L2]==2'b00)
2670
            case(isn[`INSTRUCTION_S2])
2671
            `LWRX:   IsLWR = TRUE;
2672
            default:    IsLWR = FALSE;
2673
            endcase
2674
        else
2675
                IsLWR = FALSE;
2676
`LWR:    IsLWR = TRUE;
2677
default:    IsLWR = FALSE;
2678
endcase
2679
endfunction
2680
 
2681
function IsLWRX;
2682
input [47:0] isn;
2683
case(isn[`INSTRUCTION_OP])
2684
`MEMNDX:
2685
        if (isn[`INSTRUCTION_L2]==2'b00)
2686
            case(isn[`INSTRUCTION_S2])
2687
            `LWRX:   IsLWRX = TRUE;
2688
            default:    IsLWRX = FALSE;
2689
            endcase
2690
        else
2691
                IsLWRX = FALSE;
2692
default:    IsLWRX = FALSE;
2693
endcase
2694
endfunction
2695
 
2696
function IsCAS;
2697
input [47:0] isn;
2698
case(isn[`INSTRUCTION_OP])
2699
`MEMNDX:
2700
        if (isn[`INSTRUCTION_L2]==2'b00)
2701
            case(isn[`INSTRUCTION_S2])
2702
            `CASX:   IsCAS = TRUE;
2703
            default:    IsCAS = FALSE;
2704
            endcase
2705
        else
2706
                IsCAS = FALSE;
2707
`CAS:       IsCAS = TRUE;
2708
default:    IsCAS = FALSE;
2709
endcase
2710
endfunction
2711
 
2712
function IsAMO;
2713
input [47:0] isn;
2714
case(isn[`INSTRUCTION_OP])
2715
`AMO:       IsAMO = TRUE;
2716
default:    IsAMO = FALSE;
2717
endcase
2718
endfunction
2719
 
2720
// Really IsPredictableBranch
2721
// Does not include BccR's
2722
function IsBranch;
2723
input [47:0] isn;
2724
casez(isn[`INSTRUCTION_OP])
2725
`Bcc:   IsBranch = TRUE;
2726
`BBc:   IsBranch = TRUE;
2727
`BEQI:  IsBranch = TRUE;
2728
`CHK:   IsBranch = TRUE;
2729
default:    IsBranch = FALSE;
2730
endcase
2731
endfunction
2732
 
2733
function IsWait;
2734
input [47:0] isn;
2735
IsWait = isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`WAIT;
2736
endfunction
2737
 
2738
function IsCall;
2739
input [47:0] isn;
2740
IsCall = isn[`INSTRUCTION_OP]==`CALL && isn[7]==1'b0;
2741
endfunction
2742
 
2743
function IsJmp;
2744
input [47:0] isn;
2745
IsJmp = isn[`INSTRUCTION_OP]==`JMP && isn[7]==1'b0;
2746
endfunction
2747
 
2748
function IsFlowCtrl;
2749
input [47:0] isn;
2750
casez(isn[`INSTRUCTION_OP])
2751
`BRK:    IsFlowCtrl = TRUE;
2752 49 robfinch
`R2:    case(isn[`INSTRUCTION_S2])
2753 48 robfinch
        `RTI:   IsFlowCtrl = TRUE;
2754
        default:    IsFlowCtrl = FALSE;
2755
        endcase
2756
`Bcc:   IsFlowCtrl = TRUE;
2757
`BBc:           IsFlowCtrl = TRUE;
2758
`BEQI:  IsFlowCtrl = TRUE;
2759
`CHK:   IsFlowCtrl = TRUE;
2760
`JAL:   IsFlowCtrl = TRUE;
2761
`JMP:           IsFlowCtrl = TRUE;
2762
`CALL:  IsFlowCtrl = TRUE;
2763
`RET:   IsFlowCtrl = TRUE;
2764
default:    IsFlowCtrl = FALSE;
2765
endcase
2766
endfunction
2767
 
2768
function IsCache;
2769
input [47:0] isn;
2770
case(isn[`INSTRUCTION_OP])
2771
`MEMNDX:
2772
        if (isn[`INSTRUCTION_L2]==2'b00)
2773
            case(isn[`INSTRUCTION_S2])
2774
            `CACHEX:    IsCache = TRUE;
2775
            default:    IsCache = FALSE;
2776
            endcase
2777
        else
2778
                IsCache = FALSE;
2779
`CACHE: IsCache = TRUE;
2780
default: IsCache = FALSE;
2781
endcase
2782
endfunction
2783
 
2784
function [4:0] CacheCmd;
2785
input [47:0] isn;
2786
case(isn[`INSTRUCTION_OP])
2787
`MEMNDX:
2788
        if (isn[`INSTRUCTION_L2]==2'b00)
2789
            case(isn[`INSTRUCTION_S2])
2790
            `CACHEX:    CacheCmd = isn[22:18];
2791
            default:    CacheCmd = 5'd0;
2792
            endcase
2793
        else
2794
                CacheCmd = 5'd0;
2795
`CACHE: CacheCmd = isn[15:11];
2796
default: CacheCmd = 5'd0;
2797
endcase
2798
endfunction
2799
 
2800
function IsMemsb;
2801
input [47:0] isn;
2802
IsMemsb = (isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMSB);
2803
endfunction
2804
 
2805
function IsSEI;
2806
input [47:0] isn;
2807
IsSEI = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`SEI);
2808
endfunction
2809
 
2810
function IsLV;
2811
input [47:0] isn;
2812
case(isn[`INSTRUCTION_OP])
2813
`MEMNDX:
2814
        if (isn[`INSTRUCTION_L2]==2'b00)
2815
            case(isn[`INSTRUCTION_S2])
2816
            `LVX:   IsLV = TRUE;
2817
            default:    IsLV = FALSE;
2818
            endcase
2819
        else
2820
                IsLV = FALSE;
2821
`LV:        IsLV = TRUE;
2822
default:    IsLV = FALSE;
2823
endcase
2824
endfunction
2825
 
2826
function IsRFW;
2827
input [47:0] isn;
2828
input [5:0] vqei;
2829
input [5:0] vli;
2830
input thrd;
2831
if (fnRt(isn,vqei,vli,thrd)==12'd0)
2832
    IsRFW = FALSE;
2833
else
2834
casez(isn[`INSTRUCTION_OP])
2835
`IVECTOR:   IsRFW = TRUE;
2836
`FVECTOR:   IsRFW = TRUE;
2837
`R2:
2838
        if (isn[`INSTRUCTION_L2]==2'b00)
2839
            case(isn[`INSTRUCTION_S2])
2840
            `R1:    IsRFW = TRUE;
2841
            `ADD:   IsRFW = TRUE;
2842
            `SUB:   IsRFW = TRUE;
2843
            `SLT:   IsRFW = TRUE;
2844
            `SLTU:  IsRFW = TRUE;
2845
            `SLE:   IsRFW = TRUE;
2846
        `SLEU:  IsRFW = TRUE;
2847
            `AND:   IsRFW = TRUE;
2848
            `OR:    IsRFW = TRUE;
2849
            `XOR:   IsRFW = TRUE;
2850
            `MULU:  IsRFW = TRUE;
2851
            `MULSU: IsRFW = TRUE;
2852
            `MUL:   IsRFW = TRUE;
2853 50 robfinch
            `MULUH:  IsRFW = TRUE;
2854
            `MULSUH: IsRFW = TRUE;
2855
            `MULH:   IsRFW = TRUE;
2856
            `DIVU:  IsRFW = TRUE;
2857
            `DIVSU: IsRFW = TRUE;
2858
            `DIV:IsRFW = TRUE;
2859
            `MODU:  IsRFW = TRUE;
2860
            `MODSU: IsRFW = TRUE;
2861
            `MOD:IsRFW = TRUE;
2862 48 robfinch
            `MOV:       IsRFW = TRUE;
2863
            `VMOV:      IsRFW = TRUE;
2864
            `SHIFTR,`SHIFT31,`SHIFT63:
2865
                        IsRFW = TRUE;
2866
            `MIN,`MAX:    IsRFW = TRUE;
2867
            `SEI:       IsRFW = TRUE;
2868
            default:    IsRFW = FALSE;
2869
            endcase
2870
        else
2871
                IsRFW = FALSE;
2872
`MEMNDX:
2873
        if (isn[`INSTRUCTION_L2]==2'b00)
2874 50 robfinch
    case(isn[`INSTRUCTION_S2])
2875
    `LBX:   IsRFW = TRUE;
2876
    `LBUX:  IsRFW = TRUE;
2877
    `LCX:   IsRFW = TRUE;
2878
    `LCUX:  IsRFW = TRUE;
2879
    `LHX:   IsRFW = TRUE;
2880
    `LHUX:  IsRFW = TRUE;
2881
    `LWX:   IsRFW = TRUE;
2882
    `LVBX:  IsRFW = TRUE;
2883
    `LVBUX: IsRFW = TRUE;
2884
    `LVCX:  IsRFW = TRUE;
2885
    `LVCUX: IsRFW = TRUE;
2886
    `LVHX:  IsRFW = TRUE;
2887
    `LVHUX: IsRFW = TRUE;
2888
    `LVWX:  IsRFW = TRUE;
2889
    `LWRX:  IsRFW = TRUE;
2890
    `LVX:   IsRFW = TRUE;
2891
    `CASX:  IsRFW = TRUE;
2892
    default:    IsRFW = FALSE;
2893
    endcase
2894 48 robfinch
        else
2895
                IsRFW = FALSE;
2896
`BBc:
2897
        case(isn[20:19])
2898
        `IBNE:  IsRFW = TRUE;
2899
        `DBNZ:  IsRFW = TRUE;
2900
        default:        IsRFW = FALSE;
2901
        endcase
2902
`BITFIELD:  IsRFW = TRUE;
2903
`ADDI:      IsRFW = TRUE;
2904
`SLTI:      IsRFW = TRUE;
2905
`SLTUI:     IsRFW = TRUE;
2906
`SGTI:      IsRFW = TRUE;
2907
`SGTUI:     IsRFW = TRUE;
2908
`ANDI:      IsRFW = TRUE;
2909
`ORI:       IsRFW = TRUE;
2910
`XORI:      IsRFW = TRUE;
2911
`MULUI:     IsRFW = TRUE;
2912
`MULI:      IsRFW = TRUE;
2913
`DIVUI:     IsRFW = TRUE;
2914
`DIVI:      IsRFW = TRUE;
2915
`MODI:      IsRFW = TRUE;
2916
`JAL:       IsRFW = TRUE;
2917
`CALL:      IsRFW = TRUE;
2918
`RET:       IsRFW = TRUE;
2919
`LB:        IsRFW = TRUE;
2920
`LBU:       IsRFW = TRUE;
2921
`Lx:        IsRFW = TRUE;
2922
`LWR:       IsRFW = TRUE;
2923
`LV:        IsRFW = TRUE;
2924
`LVx:                           IsRFW = TRUE;
2925
`CAS:       IsRFW = TRUE;
2926
`AMO:                           IsRFW = TRUE;
2927
`CSRRW:                 IsRFW = TRUE;
2928 56 robfinch
`AUIPC:                 IsRFW = TRUE;
2929 55 robfinch
`LUI:                           IsRFW = TRUE;
2930 48 robfinch
default:    IsRFW = FALSE;
2931
endcase
2932
endfunction
2933
 
2934
function IsShifti;
2935
input [47:0] isn;
2936
case(isn[`INSTRUCTION_OP])
2937
`R2:
2938
        if (isn[`INSTRUCTION_L2]==2'b00)
2939
            case(isn[`INSTRUCTION_S2])
2940
            `SHIFT31,`SHIFT63:
2941
                IsShifti = TRUE;
2942
            default: IsShifti = FALSE;
2943
            endcase
2944
    else
2945
        IsShifti = FALSE;
2946
default: IsShifti = FALSE;
2947
endcase
2948
endfunction
2949
 
2950
function IsRtop;
2951
input [47:0] isn;
2952
case(isn[`INSTRUCTION_OP])
2953
`R2:
2954
        if (isn[`INSTRUCTION_L2]==2'b01)
2955
            case(isn[47:42])
2956
            `RTOP: IsRtop = TRUE;
2957
            default: IsRtop = FALSE;
2958
            endcase
2959
    else
2960
        IsRtop = FALSE;
2961
default: IsRtop = FALSE;
2962
endcase
2963
endfunction
2964
 
2965
function IsMul;
2966
input [47:0] isn;
2967
case(isn[`INSTRUCTION_OP])
2968 50 robfinch
`R2:
2969 48 robfinch
        if (isn[`INSTRUCTION_L2]==2'b00)
2970 50 robfinch
    case(isn[`INSTRUCTION_S2])
2971
    `MULU,`MULSU,`MUL: IsMul = TRUE;
2972
    `MULUH,`MULSUH,`MULH: IsMul = TRUE;
2973
    default:    IsMul = FALSE;
2974
    endcase
2975 48 robfinch
        else
2976
                IsMul = FALSE;
2977
`MULUI,`MULI:  IsMul = TRUE;
2978
default:    IsMul = FALSE;
2979
endcase
2980
endfunction
2981
 
2982
function IsDivmod;
2983
input [47:0] isn;
2984
case(isn[`INSTRUCTION_OP])
2985 50 robfinch
`R2:
2986 48 robfinch
        if (isn[`INSTRUCTION_L2]==2'b00)
2987 50 robfinch
    case(isn[`INSTRUCTION_S2])
2988
    `DIVU,`DIVSU,`DIV: IsDivmod = TRUE;
2989
    `MODU,`MODSU,`MOD: IsDivmod = TRUE;
2990
    default: IsDivmod = FALSE;
2991
    endcase
2992 48 robfinch
        else
2993
                IsDivmod = FALSE;
2994
`DIVUI,`DIVI,`MODI:  IsDivmod = TRUE;
2995
default:    IsDivmod = FALSE;
2996
endcase
2997
endfunction
2998
 
2999
function IsExec;
3000
input [47:0] isn;
3001
case(isn[`INSTRUCTION_OP])
3002
`EXEC:  IsExec = TRUE;
3003
default:        IsExec = FALSE;
3004
endcase
3005
endfunction
3006
 
3007
function [7:0] fnSelect;
3008
input [47:0] ins;
3009 49 robfinch
input [`ABITS] adr;
3010 48 robfinch
begin
3011
        case(ins[`INSTRUCTION_OP])
3012
        `MEMNDX:
3013
                if (ins[`INSTRUCTION_L2]==2'b00)
3014
                   case(ins[`INSTRUCTION_S2])
3015 53 robfinch
               `LBX,`LBUX,`SBX,`LVBX,`LVBUX:
3016 48 robfinch
                   case(adr[2:0])
3017
                   3'd0:    fnSelect = 8'h01;
3018
                   3'd1:    fnSelect = 8'h02;
3019
                   3'd2:    fnSelect = 8'h04;
3020
                   3'd3:    fnSelect = 8'h08;
3021
                   3'd4:    fnSelect = 8'h10;
3022
                   3'd5:    fnSelect = 8'h20;
3023
                   3'd6:    fnSelect = 8'h40;
3024
                   3'd7:    fnSelect = 8'h80;
3025
                   endcase
3026 53 robfinch
                `LCX,`LCUX,`SCX,`LVCX,`LVCUX:
3027 48 robfinch
                    case(adr[2:1])
3028
                    2'd0:   fnSelect = 8'h03;
3029
                    2'd1:   fnSelect = 8'h0C;
3030
                    2'd2:   fnSelect = 8'h30;
3031
                    2'd3:   fnSelect = 8'hC0;
3032
                    endcase
3033 53 robfinch
                `LHX,`LHUX,`SHX,`LVHX,`LVHUX:
3034 48 robfinch
                   case(adr[2])
3035
                   1'b0:    fnSelect = 8'h0F;
3036
                   1'b1:    fnSelect = 8'hF0;
3037
                   endcase
3038 53 robfinch
               `INC,`LVWX,
3039 48 robfinch
               `LWX,`SWX,`LWRX,`SWCX,`LVX,`SVX,`CASX:
3040
                   fnSelect = 8'hFF;
3041
               default: fnSelect = 8'h00;
3042
                   endcase
3043
           else
3044
                fnSelect = 8'h00;
3045 52 robfinch
  `LB,`LBU,`SB:
3046 48 robfinch
                case(adr[2:0])
3047
                3'd0:   fnSelect = 8'h01;
3048
                3'd1:   fnSelect = 8'h02;
3049
                3'd2:   fnSelect = 8'h04;
3050
                3'd3:   fnSelect = 8'h08;
3051
                3'd4:   fnSelect = 8'h10;
3052
                3'd5:   fnSelect = 8'h20;
3053
                3'd6:   fnSelect = 8'h40;
3054
                3'd7:   fnSelect = 8'h80;
3055
                endcase
3056 53 robfinch
    `Lx,`LxU,`Sx,`LVx:
3057 48 robfinch
        casez(ins[20:18])
3058
        3'b100: fnSelect = 8'hFF;
3059
        3'b?10: fnSelect = adr[2] ? 8'hF0 : 8'h0F;
3060
        3'b??1:
3061
        case(adr[2:1])
3062
        2'd0:   fnSelect = 8'h03;
3063
        2'd1:   fnSelect = 8'h0C;
3064
        2'd2:   fnSelect = 8'h30;
3065
        2'd3:   fnSelect = 8'hC0;
3066
        endcase
3067
      default: fnSelect = 8'h00;
3068
      endcase
3069
        `INC,
3070
        `LWR,`SWC,`CAS:   fnSelect = 8'hFF;
3071
        `LV,`SV:   fnSelect = 8'hFF;
3072
        `AMO:
3073
                case(ins[23:21])
3074
                3'd0:   fnSelect = {8'h01 << adr[2:0]};
3075
                3'd1:   fnSelect = {8'h03 << {adr[2:1],1'b0}};
3076
                3'd2:   fnSelect = {8'h0F << {adr[2],2'b00}};
3077
                3'd3:   fnSelect = 8'hFF;
3078
                default:        fnSelect = 8'hFF;
3079
                endcase
3080
        default:        fnSelect = 8'h00;
3081
        endcase
3082
end
3083
endfunction
3084
/*
3085
function [63:0] fnDatc;
3086
input [47:0] ins;
3087
input [63:0] dat;
3088
case(ins[`INSTRUCTION_OP])
3089
`R2:
3090
        if (isn[`INSTRUCTION_L2]==2'b01)
3091
                case(ins[47:42])
3092
                `FINDB:         fnDatc = dat[7:0];
3093
                `FINDC:         fnDatc = dat[15:0];
3094
                `FINDH:         fnDatc = dat[31:0];
3095
                `FINDW:         fnDatc = dat[63:0];
3096
                default:        fnDatc = dat[63:0];
3097
                endcase
3098
        else
3099
                fnDatc = dat[63:0];
3100
default:        fnDatc = dat[63:0];
3101
endcase
3102
endfunction
3103
*/
3104
/*
3105
function [63:0] fnMemInc;
3106
input [47:0] ins;
3107
case(ins[`INSTRUCTION_OP])
3108
`R2:
3109
        if (isn[`INSTRUCTION_L2]==2'b01)
3110
                case(ins[47:42])
3111
                `FINDB:         fnMemInc = 32'd1;
3112
                `FINDC:         fnMemInc = 32'd2;
3113
                `FINDH:         fnMemInc = 32'd4;
3114
                `FINDW:         fnMemInc = 32'd8;
3115
                default:        fnMemInc = 32'd8;
3116
                endcase
3117
        else
3118
                fnMemInc = 32'd8;
3119
default:        fnMemInc = 32'd8;
3120
endcase
3121
endfunction
3122
*/
3123
function [63:0] fnDati;
3124
input [47:0] ins;
3125 49 robfinch
input [`ABITS] adr;
3126 48 robfinch
input [63:0] dat;
3127
case(ins[`INSTRUCTION_OP])
3128
`MEMNDX:
3129
        if (ins[`INSTRUCTION_L2]==2'b00)
3130
            case(ins[`INSTRUCTION_S2])
3131 53 robfinch
            `LBX,`LVBX:
3132 48 robfinch
                case(adr[2:0])
3133
                3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3134
                3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3135
                3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3136
                3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3137
                3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3138
                3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3139
                3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3140
                3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3141
                endcase
3142 53 robfinch
            `LBUX,`LVBUX:
3143 48 robfinch
                case(adr[2:0])
3144
                3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3145
                3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3146
                3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3147
                3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3148
                3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3149
                3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3150
                3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3151
                3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3152
                endcase
3153 53 robfinch
            `LCX,`LVCX:
3154 48 robfinch
                case(adr[2:1])
3155
                2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3156
                2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3157
                2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3158
                2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3159
                endcase
3160 53 robfinch
            `LCUX,`LVCUX:
3161 48 robfinch
                case(adr[2:1])
3162
                2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3163
                2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3164
                2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3165
                2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3166
                endcase
3167 53 robfinch
            `LHX,`LVHX:
3168 48 robfinch
                case(adr[2])
3169
                1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3170
                1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3171
                endcase
3172 53 robfinch
            `LHUX,`LVHUX:
3173 48 robfinch
                case(adr[2])
3174
                1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3175
                1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3176
                endcase
3177 53 robfinch
            `LWX,`LWRX,`LVX,`CAS,`LVWX:  fnDati = dat;
3178 48 robfinch
            default:    fnDati = dat;
3179
            endcase
3180
        else
3181
                fnDati = dat;
3182
`LB:
3183
  case(adr[2:0])
3184
  3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3185
  3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3186
  3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3187
  3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3188
  3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3189
  3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3190
  3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3191
  3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3192
  endcase
3193
`LBU:
3194
  case(adr[2:0])
3195
  3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3196
  3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3197
  3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3198
  3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3199
  3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3200
  3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3201
  3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3202
  3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3203
  endcase
3204 53 robfinch
`Lx,`LVx:
3205 48 robfinch
        casez(ins[20:18])
3206
        3'b100: fnDati = dat;
3207
        3'b?10:
3208
          case(adr[2])
3209
          1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3210
          1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3211
          endcase
3212
        3'b??1:
3213
          case(adr[2:1])
3214
          2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3215
          2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3216
          2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3217
          2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3218
          endcase
3219
        endcase
3220
`LxU:
3221
        casez(ins[20:18])
3222
        3'b100: fnDati = dat;
3223
        3'b?10:
3224
          case(adr[2])
3225
          1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3226
          1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3227
          endcase
3228
        3'b??1:
3229
          case(adr[2:1])
3230
          2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3231
          2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3232
          2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3233
          2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3234
          endcase
3235
        endcase
3236
`LWR,`LV,`CAS,`AMO:   fnDati = dat;
3237
default:    fnDati = dat;
3238
endcase
3239
endfunction
3240
 
3241
function [63:0] fnDato;
3242
input [47:0] isn;
3243
input [63:0] dat;
3244
case(isn[`INSTRUCTION_OP])
3245
`MEMNDX:
3246
        if (isn[`INSTRUCTION_L2]==2'b00)
3247
                case(isn[`INSTRUCTION_S2])
3248
                `SBX:   fnDato = {8{dat[7:0]}};
3249
                `SCX:   fnDato = {4{dat[15:0]}};
3250
                `SHX:   fnDato = {2{dat[31:0]}};
3251
                default:    fnDato = dat;
3252
                endcase
3253
        else
3254
                fnDato = dat;
3255
`SB:   fnDato = {8{dat[7:0]}};
3256
`Sx:
3257 49 robfinch
        casez(isn[20:18])
3258 48 robfinch
        3'b100: fnDato = dat;
3259
        3'b?10: fnDato = {2{dat[31:0]}};
3260
        3'b??1: fnDato = {4{dat[15:0]}};
3261
        default:        fnDato = dat;
3262
        endcase
3263
`AMO:
3264
        case(isn[23:21])
3265
        3'd0:   fnDato = {8{dat[7:0]}};
3266
        3'd1:   fnDato = {4{dat[15:0]}};
3267
        3'd2:   fnDato = {2{dat[31:0]}};
3268
        3'd3:   fnDato = dat;
3269
        default:        fnDato = dat;
3270
        endcase
3271
default:    fnDato = dat;
3272
endcase
3273
endfunction
3274
 
3275
// Indicate if the ALU instruction is valid immediately (single cycle operation)
3276
function IsSingleCycle;
3277
input [47:0] isn;
3278
IsSingleCycle = !(IsMul(isn)|IsDivmod(isn));
3279
endfunction
3280
 
3281
 
3282 53 robfinch
generate begin : gDecocderInst
3283
for (g = 0; g < QENTRIES; g = g + 1) begin
3284 48 robfinch
`ifdef SUPPORT_SMT
3285 53 robfinch
decoder8 iq0(.num({iqentry_tgt[g][8:7],iqentry_tgt[g][5:0]}), .out(iq_out[g]));
3286 48 robfinch
`else
3287 53 robfinch
decoder7 iq0(.num({iqentry_tgt[g][7],iqentry_tgt[g][5:0]}), .out(iq_out[g]));
3288 48 robfinch
`endif
3289 53 robfinch
end
3290
end
3291
endgenerate
3292 48 robfinch
 
3293
initial begin: Init
3294
        //
3295
        //
3296
        // set up panic messages
3297
        message[ `PANIC_NONE ]                  = "NONE            ";
3298
        message[ `PANIC_FETCHBUFBEQ ]           = "FETCHBUFBEQ     ";
3299
        message[ `PANIC_INVALIDISLOT ]          = "INVALIDISLOT    ";
3300
        message[ `PANIC_IDENTICALDRAMS ]        = "IDENTICALDRAMS  ";
3301
        message[ `PANIC_OVERRUN ]               = "OVERRUN         ";
3302
        message[ `PANIC_HALTINSTRUCTION ]       = "HALTINSTRUCTION ";
3303
        message[ `PANIC_INVALIDMEMOP ]          = "INVALIDMEMOP    ";
3304
        message[ `PANIC_INVALIDFBSTATE ]        = "INVALIDFBSTATE  ";
3305
        message[ `PANIC_INVALIDIQSTATE ]        = "INVALIDIQSTATE  ";
3306
        message[ `PANIC_BRANCHBACK ]            = "BRANCHBACK      ";
3307
        message[ `PANIC_MEMORYRACE ]            = "MEMORYRACE      ";
3308
        message[ `PANIC_ALU0ONLY ] = "ALU0 Only       ";
3309
 
3310
        for (n = 0; n < 64; n = n + 1)
3311
                codebuf[n] <= 48'h0;
3312
 
3313
end
3314
 
3315
// ---------------------------------------------------------------------------
3316
// FETCH
3317
// ---------------------------------------------------------------------------
3318
//
3319
assign fetchbuf0_mem   = IsMem(fetchbuf0_instr);
3320
assign fetchbuf0_memld = IsMem(fetchbuf0_instr) & IsLoad(fetchbuf0_instr);
3321
assign fetchbuf0_rfw   = IsRFW(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd);
3322
 
3323 57 robfinch
generate begin: gFetchbufDec
3324
if (`WAYS > 1) begin
3325 48 robfinch
assign fetchbuf1_mem   = IsMem(fetchbuf1_instr);
3326
assign fetchbuf1_memld = IsMem(fetchbuf1_instr) & IsLoad(fetchbuf1_instr);
3327
assign fetchbuf1_rfw   = IsRFW(fetchbuf1_instr,vqe1,vl,fetchbuf1_thrd);
3328 57 robfinch
end
3329
if (`WAYS > 2) begin
3330
assign fetchbuf2_mem   = IsMem(fetchbuf2_instr);
3331
assign fetchbuf2_memld = IsMem(fetchbuf2_instr) & IsLoad(fetchbuf2_instr);
3332
assign fetchbuf2_rfw   = IsRFW(fetchbuf2_instr,vqe2,vl,fetchbuf2_thrd);
3333
end
3334
end
3335
endgenerate
3336 48 robfinch
 
3337 57 robfinch
generate begin : gFetchbufInst
3338
if (`WAYS > 2) begin : gb1
3339
FT64_fetchbuf_x3 #(AMSB,RSTPC) ufb1
3340
(
3341
  .rst(rst),
3342
  .clk4x(clk4x),
3343
  .clk(clk),
3344
  .fcu_clk(fcu_clk),
3345
  .cs_i(adr_o[31:16]==16'hFFFF),
3346
  .cyc_i(cyc_o),
3347
  .stb_i(stb_o),
3348
  .ack_o(dc_ack),
3349
  .we_i(we_o),
3350
  .adr_i(adr_o[15:0]),
3351
  .dat_i(dat_o[47:0]),
3352
  .cmpgrp(cr0[10:8]),
3353
  .freezePC(freezePC),
3354
  .regLR(regLR),
3355
  .thread_en(thread_en),
3356
  .insn0(insn0),
3357
  .insn1(insn1),
3358
  .insn1(insn2),
3359
  .phit(phit),
3360
  .threadx(threadx),
3361
  .branchmiss(branchmiss),
3362
  .misspc(misspc),
3363
  .branchmiss_thrd(branchmiss_thrd),
3364
  .predict_takenA(predict_takenA),
3365
  .predict_takenB(predict_takenB),
3366
  .predict_takenC(predict_takenC),
3367
  .predict_takenD(predict_takenD),
3368
  .predict_takenE(predict_takenE),
3369
  .predict_takenF(predict_takenF),
3370
  .predict_taken0(predict_taken0),
3371
  .predict_taken1(predict_taken1),
3372
  .predict_taken1(predict_taken2),
3373
  .queued1(queued1),
3374
  .queued2(queued2),
3375
  .queued2(queued3),
3376
  .queuedNop(queuedNop),
3377
  .pc0(pc0),
3378
  .pc1(pc1),
3379
  .fetchbuf(fetchbuf),
3380
  .fetchbufA_v(fetchbufA_v),
3381
  .fetchbufB_v(fetchbufB_v),
3382
  .fetchbufC_v(fetchbufC_v),
3383
  .fetchbufD_v(fetchbufD_v),
3384
  .fetchbufD_v(fetchbufE_v),
3385
  .fetchbufD_v(fetchbufF_v),
3386
  .fetchbufA_pc(fetchbufA_pc),
3387
  .fetchbufB_pc(fetchbufB_pc),
3388
  .fetchbufC_pc(fetchbufC_pc),
3389
  .fetchbufD_pc(fetchbufD_pc),
3390
  .fetchbufD_pc(fetchbufE_pc),
3391
  .fetchbufD_pc(fetchbufF_pc),
3392
  .fetchbufA_instr(fetchbufA_instr),
3393
  .fetchbufB_instr(fetchbufB_instr),
3394
  .fetchbufC_instr(fetchbufC_instr),
3395
  .fetchbufD_instr(fetchbufD_instr),
3396
  .fetchbufE_instr(fetchbufE_instr),
3397
  .fetchbufF_instr(fetchbufF_instr),
3398
  .fetchbuf0_instr(fetchbuf0_instr),
3399
  .fetchbuf1_instr(fetchbuf1_instr),
3400
  .fetchbuf0_thrd(fetchbuf0_thrd),
3401
  .fetchbuf1_thrd(fetchbuf1_thrd),
3402
  .fetchbuf2_thrd(fetchbuf2_thrd),
3403
  .fetchbuf0_pc(fetchbuf0_pc),
3404
  .fetchbuf1_pc(fetchbuf1_pc),
3405
  .fetchbuf2_pc(fetchbuf2_pc),
3406
  .fetchbuf0_v(fetchbuf0_v),
3407
  .fetchbuf1_v(fetchbuf1_v),
3408
  .fetchbuf2_v(fetchbuf2_v),
3409
  .fetchbuf0_insln(fetchbuf0_insln),
3410
  .fetchbuf1_insln(fetchbuf1_insln),
3411
  .fetchbuf2_insln(fetchbuf2_insln),
3412
  .codebuf0(codebuf[insn0[21:16]]),
3413
  .codebuf1(codebuf[insn1[21:16]]),
3414
  .codebuf2(codebuf[insn2[21:16]]),
3415
  .btgtA(btgtA),
3416
  .btgtB(btgtB),
3417
  .btgtC(btgtC),
3418
  .btgtD(btgtD),
3419
  .btgtE(btgtE),
3420
  .btgtF(btgtF),
3421
  .nop_fetchbuf(nop_fetchbuf),
3422
  .take_branch0(take_branch0),
3423
  .take_branch1(take_branch1),
3424
  .take_branch2(take_branch2),
3425
  .stompedRets(stompedOnRets),
3426
  .panic(fb_panic)
3427
);
3428
end
3429
else if (`WAYS > 1) begin : gb1
3430 48 robfinch
FT64_fetchbuf #(AMSB,RSTPC) ufb1
3431
(
3432 49 robfinch
  .rst(rst),
3433
  .clk4x(clk4x),
3434
  .clk(clk),
3435
  .fcu_clk(fcu_clk),
3436
  .cs_i(adr_o[31:16]==16'hFFFF),
3437
  .cyc_i(cyc_o),
3438
  .stb_i(stb_o),
3439
  .ack_o(dc_ack),
3440
  .we_i(we_o),
3441
  .adr_i(adr_o[15:0]),
3442 56 robfinch
  .dat_i(dat_o[47:0]),
3443 55 robfinch
  .cmpgrp(cr0[10:8]),
3444 52 robfinch
  .freezePC(freezePC),
3445 49 robfinch
  .regLR(regLR),
3446
  .thread_en(thread_en),
3447
  .insn0(insn0),
3448
  .insn1(insn1),
3449
  .phit(phit),
3450
  .threadx(threadx),
3451
  .branchmiss(branchmiss),
3452
  .misspc(misspc),
3453
  .branchmiss_thrd(branchmiss_thrd),
3454
  .predict_takenA(predict_takenA),
3455
  .predict_takenB(predict_takenB),
3456
  .predict_takenC(predict_takenC),
3457
  .predict_takenD(predict_takenD),
3458
  .predict_taken0(predict_taken0),
3459
  .predict_taken1(predict_taken1),
3460
  .queued1(queued1),
3461
  .queued2(queued2),
3462
  .queuedNop(queuedNop),
3463
  .pc0(pc0),
3464
  .pc1(pc1),
3465
  .fetchbuf(fetchbuf),
3466
  .fetchbufA_v(fetchbufA_v),
3467
  .fetchbufB_v(fetchbufB_v),
3468
  .fetchbufC_v(fetchbufC_v),
3469
  .fetchbufD_v(fetchbufD_v),
3470
  .fetchbufA_pc(fetchbufA_pc),
3471
  .fetchbufB_pc(fetchbufB_pc),
3472
  .fetchbufC_pc(fetchbufC_pc),
3473
  .fetchbufD_pc(fetchbufD_pc),
3474
  .fetchbufA_instr(fetchbufA_instr),
3475
  .fetchbufB_instr(fetchbufB_instr),
3476
  .fetchbufC_instr(fetchbufC_instr),
3477
  .fetchbufD_instr(fetchbufD_instr),
3478
  .fetchbuf0_instr(fetchbuf0_instr),
3479
  .fetchbuf1_instr(fetchbuf1_instr),
3480
  .fetchbuf0_thrd(fetchbuf0_thrd),
3481
  .fetchbuf1_thrd(fetchbuf1_thrd),
3482
  .fetchbuf0_pc(fetchbuf0_pc),
3483
  .fetchbuf1_pc(fetchbuf1_pc),
3484
  .fetchbuf0_v(fetchbuf0_v),
3485
  .fetchbuf1_v(fetchbuf1_v),
3486
  .fetchbuf0_insln(fetchbuf0_insln),
3487
  .fetchbuf1_insln(fetchbuf1_insln),
3488
  .codebuf0(codebuf[insn0[21:16]]),
3489
  .codebuf1(codebuf[insn1[21:16]]),
3490
  .btgtA(btgtA),
3491
  .btgtB(btgtB),
3492
  .btgtC(btgtC),
3493
  .btgtD(btgtD),
3494
  .nop_fetchbuf(nop_fetchbuf),
3495
  .take_branch0(take_branch0),
3496
  .take_branch1(take_branch1),
3497
  .stompedRets(stompedOnRets),
3498
  .panic(fb_panic)
3499 48 robfinch
);
3500 57 robfinch
end
3501
else begin : gb1
3502
FT64_fetchbuf_x1 #(AMSB,RSTPC) ufb1
3503
(
3504
  .rst(rst),
3505
  .clk4x(clk4x),
3506
  .clk(clk),
3507
  .fcu_clk(fcu_clk),
3508
  .cs_i(adr_o[31:16]==16'hFFFF),
3509
  .cyc_i(cyc_o),
3510
  .stb_i(stb_o),
3511
  .ack_o(dc_ack),
3512
  .we_i(we_o),
3513
  .adr_i(adr_o[15:0]),
3514
  .dat_i(dat_o[47:0]),
3515
  .cmpgrp(cr0[10:8]),
3516
  .freezePC(freezePC),
3517
  .regLR(regLR),
3518
  .thread_en(thread_en),
3519
  .insn0(insn0),
3520
  .phit(phit),
3521
  .threadx(threadx),
3522
  .branchmiss(branchmiss),
3523
  .misspc(misspc),
3524
  .branchmiss_thrd(branchmiss_thrd),
3525
  .predict_takenA(predict_takenA),
3526
  .predict_takenB(predict_takenB),
3527
  .predict_taken0(predict_taken0),
3528
  .queued1(queued1),
3529
  .queuedNop(queuedNop),
3530
  .pc0(pc0),
3531
  .fetchbuf(fetchbuf),
3532
  .fetchbufA_v(fetchbufA_v),
3533
  .fetchbufB_v(fetchbufB_v),
3534
  .fetchbufA_pc(fetchbufA_pc),
3535
  .fetchbufB_pc(fetchbufB_pc),
3536
  .fetchbufA_instr(fetchbufA_instr),
3537
  .fetchbufB_instr(fetchbufB_instr),
3538
  .fetchbuf0_instr(fetchbuf0_instr),
3539
  .fetchbuf0_thrd(fetchbuf0_thrd),
3540
  .fetchbuf0_pc(fetchbuf0_pc),
3541
  .fetchbuf0_v(fetchbuf0_v),
3542
  .fetchbuf0_insln(fetchbuf0_insln),
3543
  .codebuf0(codebuf[insn0[21:16]]),
3544
  .btgtA(btgtA),
3545
  .btgtB(btgtB),
3546
  .nop_fetchbuf(nop_fetchbuf),
3547
  .take_branch0(take_branch0),
3548
  .stompedRets(stompedOnRets),
3549
  .panic(fb_panic)
3550
);
3551
assign fetchbuf1_v = `INV;
3552
end
3553
end
3554
endgenerate
3555 48 robfinch
 
3556
 
3557
 
3558
//initial begin: stop_at
3559
//#1000000; panic <= `PANIC_OVERRUN;
3560
//end
3561
 
3562
//
3563
// BRANCH-MISS LOGIC: livetarget
3564
//
3565
// livetarget implies that there is a not-to-be-stomped instruction that targets the register in question
3566
// therefore, if it is zero it implies the rf_v value should become VALID on a branchmiss
3567
// 
3568
 
3569
generate begin : live_target
3570
    for (g = 1; g < PREGS; g = g + 1) begin : lvtgt
3571
    assign livetarget[g] = iqentry_0_livetarget[g] |
3572
                        iqentry_1_livetarget[g] |
3573
                        iqentry_2_livetarget[g] |
3574
                        iqentry_3_livetarget[g] |
3575
                        iqentry_4_livetarget[g] |
3576
                        iqentry_5_livetarget[g] |
3577
                        iqentry_6_livetarget[g] |
3578 52 robfinch
                        iqentry_7_livetarget[g] |
3579
                        iqentry_8_livetarget[g] |
3580
                        iqentry_9_livetarget[g]
3581
                        ;
3582 48 robfinch
    end
3583
end
3584
endgenerate
3585
 
3586 53 robfinch
    assign  iqentry_0_livetarget = {PREGS {iqentry_v[0]}} & {PREGS {~iqentry_stomp[0] && iqentry_thrd[0]==branchmiss_thrd}} & iq_out[0],
3587
            iqentry_1_livetarget = {PREGS {iqentry_v[1]}} & {PREGS {~iqentry_stomp[1] && iqentry_thrd[1]==branchmiss_thrd}} & iq_out[1],
3588
            iqentry_2_livetarget = {PREGS {iqentry_v[2]}} & {PREGS {~iqentry_stomp[2] && iqentry_thrd[2]==branchmiss_thrd}} & iq_out[2],
3589
            iqentry_3_livetarget = {PREGS {iqentry_v[3]}} & {PREGS {~iqentry_stomp[3] && iqentry_thrd[3]==branchmiss_thrd}} & iq_out[3],
3590
            iqentry_4_livetarget = {PREGS {iqentry_v[4]}} & {PREGS {~iqentry_stomp[4] && iqentry_thrd[4]==branchmiss_thrd}} & iq_out[4],
3591
            iqentry_5_livetarget = {PREGS {iqentry_v[5]}} & {PREGS {~iqentry_stomp[5] && iqentry_thrd[5]==branchmiss_thrd}} & iq_out[5],
3592
            iqentry_6_livetarget = {PREGS {iqentry_v[6]}} & {PREGS {~iqentry_stomp[6] && iqentry_thrd[6]==branchmiss_thrd}} & iq_out[6],
3593
            iqentry_7_livetarget = {PREGS {iqentry_v[7]}} & {PREGS {~iqentry_stomp[7] && iqentry_thrd[7]==branchmiss_thrd}} & iq_out[7],
3594
            iqentry_8_livetarget = {PREGS {iqentry_v[8]}} & {PREGS {~iqentry_stomp[8] && iqentry_thrd[8]==branchmiss_thrd}} & iq_out[8],
3595
            iqentry_9_livetarget = {PREGS {iqentry_v[9]}} & {PREGS {~iqentry_stomp[9] && iqentry_thrd[9]==branchmiss_thrd}} & iq_out[9]
3596 52 robfinch
            ;
3597 48 robfinch
 
3598 52 robfinch
//
3599
// BRANCH-MISS LOGIC: latestID
3600
//
3601
// latestID is the instruction queue ID of the newest instruction (latest) that targets
3602
// a particular register.  looks a lot like scheduling logic, but in reverse.
3603
// 
3604
always @*
3605
        for (n = 0; n < QENTRIES; n = n + 1) begin
3606
                iqentry_cumulative[n] = 0;
3607
                for (j = n; j < n + QENTRIES; j = j + 1) begin
3608
                        if (missid==(j % QENTRIES))
3609
                                for (k = n; k <= j; k = k + 1)
3610
                                        iqentry_cumulative[n] = iqentry_cumulative[n] | iqentry_livetarget[k % QENTRIES];
3611
                end
3612
        end
3613 48 robfinch
 
3614 53 robfinch
always @*
3615
        for (n = 0; n < QENTRIES; n = n + 1)
3616
    iqentry_latestID[n] = (missid == n || ((iqentry_livetarget[n] & iqentry_cumulative[(n+1)%QENTRIES]) == {PREGS{1'b0}}))
3617
                                    ? iqentry_livetarget[n]
3618 52 robfinch
                                    : {PREGS{1'b0}};
3619 48 robfinch
 
3620 53 robfinch
always @*
3621
        for (n = 0; n < QENTRIES; n = n + 1)
3622
          iqentry_source[n] = | iqentry_latestID[n];
3623 48 robfinch
 
3624
reg vqueued2;
3625
assign Ra0 = fnRa(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3626
assign Rb0 = fnRb(fetchbuf0_instr,1'b0,vqe0,rfoa0[5:0],rfoa1[5:0],fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3627
assign Rc0 = fnRc(fetchbuf0_instr,vqe0,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3628
assign Rt0 = fnRt(fetchbuf0_instr,vqet0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3629
assign Ra1 = fnRa(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3630
assign Rb1 = fnRb(fetchbuf1_instr,1'b1,vqueued2 ? vqe0 + 1 : vqe1,rfoa0[5:0],rfoa1[5:0],fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3631
assign Rc1 = fnRc(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3632
assign Rt1 = fnRt(fetchbuf1_instr,vqueued2 ? vqet0 + 1 : vqet1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3633
 
3634 49 robfinch
//
3635
// additional logic for ISSUE
3636
//
3637
// for the moment, we look at ALU-input buffers to allow back-to-back issue of 
3638
// dependent instructions ... we do not, however, look ahead for DRAM requests 
3639
// that will become valid in the next cycle.  instead, these have to propagate
3640
// their results into the IQ entry directly, at which point it becomes issue-able
3641
//
3642 48 robfinch
 
3643 49 robfinch
// note that, for all intents & purposes, iqentry_done == iqentry_agen ... no need to duplicate
3644 48 robfinch
 
3645
wire [QENTRIES-1:0] args_valid;
3646
wire [QENTRIES-1:0] could_issue;
3647
wire [QENTRIES-1:0] could_issueid;
3648
 
3649
generate begin : issue_logic
3650
for (g = 0; g < QENTRIES; g = g + 1)
3651
begin
3652
assign args_valid[g] =
3653
                  (iqentry_a1_v[g]
3654 49 robfinch
`ifdef FU_BYPASS
3655 48 robfinch
        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3656 49 robfinch
        || ((iqentry_a1_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3657
        || ((iqentry_a1_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
3658
`endif
3659
        )
3660 48 robfinch
    && (iqentry_a2_v[g]
3661
        || (iqentry_mem[g] & ~iqentry_agen[g] & ~iqentry_memndx[g])    // a2 needs to be valid for indexed instruction
3662 49 robfinch
`ifdef FU_BYPASS
3663 48 robfinch
        || (iqentry_a2_s[g] == alu0_sourceid && alu0_dataready)
3664 49 robfinch
        || ((iqentry_a2_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3665
        || ((iqentry_a2_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
3666
`endif
3667
        )
3668 48 robfinch
    && (iqentry_a3_v[g]
3669
//        || (iqentry_mem[g] & ~iqentry_agen[g])
3670 49 robfinch
`ifdef FU_BYPASS
3671 48 robfinch
        || (iqentry_a3_s[g] == alu0_sourceid && alu0_dataready)
3672 49 robfinch
        || ((iqentry_a3_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3673
`endif
3674
        )
3675 48 robfinch
    ;
3676
 
3677
assign could_issue[g] = iqentry_v[g] && !iqentry_done[g] && !iqentry_out[g]
3678
                                                                                                && args_valid[g]
3679
                                                                                                && iqentry_iv[g]
3680
                        && (iqentry_mem[g] ? !iqentry_agen[g] : 1'b1);
3681
 
3682 52 robfinch
assign could_issueid[g] = (iqentry_v[g])// || (g==tail0 && canq1))// || (g==tail1 && canq2))
3683
                                                                                                                && !iqentry_iv[g];
3684 48 robfinch
//                && (iqentry_a1_v[g] 
3685
//        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3686
//        || (iqentry_a1_s[g] == alu1_sourceid && alu1_dataready));
3687
 
3688
end
3689
end
3690
endgenerate
3691
 
3692
// The (old) simulator didn't handle the asynchronous race loop properly in the 
3693
// original code. It would issue two instructions to the same islot. So the
3694
// issue logic has been re-written to eliminate the asynchronous loop.
3695
// Can't issue to the ALU if it's busy doing a long running operation like a 
3696
// divide.
3697
// ToDo: fix the memory synchronization, see fp_issue below
3698
 
3699
wire [`QBITS] heads [QENTRIES-1:0];
3700
assign heads[0] = head0;
3701
assign heads[1] = head1;
3702
assign heads[2] = head2;
3703
assign heads[3] = head3;
3704
assign heads[4] = head4;
3705
assign heads[5] = head5;
3706
assign heads[6] = head6;
3707
assign heads[7] = head7;
3708 52 robfinch
assign heads[8] = head8;
3709
assign heads[9] = head9;
3710 48 robfinch
 
3711
always @*
3712
begin
3713 49 robfinch
        iqentry_id1issue = {QENTRIES{1'b0}};
3714 48 robfinch
        if (id1_available) begin
3715
                for (n = 0; n < QENTRIES; n = n + 1)
3716 49 robfinch
                        if (could_issueid[heads[n]] && iqentry_id1issue=={QENTRIES{1'b0}})
3717 48 robfinch
                          iqentry_id1issue[heads[n]] = `TRUE;
3718
        end
3719 49 robfinch
end
3720
generate begin : gIDUIssue
3721
        if (`NUM_IDU > 1) begin
3722
                always @*
3723
                begin
3724
                        iqentry_id2issue = {QENTRIES{1'b0}};
3725
                        if (id2_available) begin
3726
                                for (n = 0; n < QENTRIES; n = n + 1)
3727
                                        if (could_issueid[heads[n]] && !iqentry_id1issue[heads[n]] && iqentry_id2issue=={QENTRIES{1'b0}})
3728
                                          iqentry_id2issue[heads[n]] = `TRUE;
3729
                        end
3730
                end
3731 48 robfinch
        end
3732 49 robfinch
        if (`NUM_IDU > 2) begin
3733
                always @*
3734
                begin
3735
                        iqentry_id3issue = {QENTRIES{1'b0}};
3736
                        if (id3_available) begin
3737
                                for (n = 0; n < QENTRIES; n = n + 1)
3738
                                        if (could_issueid[heads[n]]
3739
                                        && !iqentry_id1issue[heads[n]]
3740
                                        && !iqentry_id2issue[heads[n]]
3741
                                        && iqentry_id3issue=={QENTRIES{1'b0}})
3742
                                          iqentry_id3issue[heads[n]] = `TRUE;
3743
                        end
3744
                end
3745
        end
3746 48 robfinch
end
3747 49 robfinch
endgenerate
3748 48 robfinch
 
3749
always @*
3750
begin
3751 49 robfinch
        iqentry_alu0_issue = {QENTRIES{1'b0}};
3752
        iqentry_alu1_issue = {QENTRIES{1'b0}};
3753 48 robfinch
 
3754
        if (alu0_available & alu0_idle) begin
3755
                if (could_issue[head0] && iqentry_alu[head0]) begin
3756
                  iqentry_alu0_issue[head0] = `TRUE;
3757
                end
3758
                else if (could_issue[head1] && iqentry_alu[head1])
3759
                begin
3760
                  iqentry_alu0_issue[head1] = `TRUE;
3761
                end
3762
                else if (could_issue[head2] && iqentry_alu[head2]
3763
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3764
                )
3765
                begin
3766
                        iqentry_alu0_issue[head2] = `TRUE;
3767
                end
3768
                else if (could_issue[head3] && iqentry_alu[head3]
3769
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3770
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3771
                                ((!iqentry_v[head0])
3772
                        &&   (!iqentry_v[head1]))
3773
                        )
3774
                ) begin
3775
                        iqentry_alu0_issue[head3] = `TRUE;
3776
                end
3777
                else if (could_issue[head4] && iqentry_alu[head4]
3778
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3779
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3780
                                ((!iqentry_v[head0])
3781
                        &&   (!iqentry_v[head1]))
3782
                        )
3783
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3784
                                ((!iqentry_v[head0])
3785
                        &&   (!iqentry_v[head1])
3786
                        &&   (!iqentry_v[head2]))
3787
                        )
3788
                ) begin
3789
                        iqentry_alu0_issue[head4] = `TRUE;
3790
                end
3791
                else if (could_issue[head5] && iqentry_alu[head5]
3792
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3793
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3794
                                ((!iqentry_v[head0])
3795
                        &&   (!iqentry_v[head1]))
3796
                        )
3797
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3798
                                ((!iqentry_v[head0])
3799
                        &&   (!iqentry_v[head1])
3800
                        &&   (!iqentry_v[head2]))
3801
                        )
3802
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3803
                                ((!iqentry_v[head0])
3804
                        &&   (!iqentry_v[head1])
3805
                        &&   (!iqentry_v[head2])
3806
                        &&   (!iqentry_v[head3]))
3807
                        )
3808
                ) begin
3809
                        iqentry_alu0_issue[head5] = `TRUE;
3810
                end
3811
`ifdef FULL_ISSUE_LOGIC
3812
                else if (could_issue[head6] && iqentry_alu[head6]
3813
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3814
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3815
                                ((!iqentry_v[head0])
3816
                        &&   (!iqentry_v[head1]))
3817
                        )
3818
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3819
                                ((!iqentry_v[head0])
3820
                        &&   (!iqentry_v[head1])
3821
                        &&   (!iqentry_v[head2]))
3822
                        )
3823
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3824
                                ((!iqentry_v[head0])
3825
                        &&   (!iqentry_v[head1])
3826
                        &&   (!iqentry_v[head2])
3827
                        &&   (!iqentry_v[head3]))
3828
                        )
3829
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3830
                                ((!iqentry_v[head0])
3831
                        &&   (!iqentry_v[head1])
3832
                        &&   (!iqentry_v[head2])
3833
                        &&   (!iqentry_v[head3])
3834
                        &&   (!iqentry_v[head4]))
3835
                        )
3836
                ) begin
3837
                        iqentry_alu0_issue[head6] = `TRUE;
3838
                end
3839
                else if (could_issue[head7] && iqentry_alu[head7]
3840
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3841
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3842
                                ((!iqentry_v[head0])
3843
                        &&   (!iqentry_v[head1]))
3844
                        )
3845
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3846
                                ((!iqentry_v[head0])
3847
                        &&   (!iqentry_v[head1])
3848
                        &&   (!iqentry_v[head2]))
3849
                        )
3850
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3851
                                ((!iqentry_v[head0])
3852
                        &&   (!iqentry_v[head1])
3853
                        &&   (!iqentry_v[head2])
3854
                        &&   (!iqentry_v[head3]))
3855
                        )
3856
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3857
                                ((!iqentry_v[head0])
3858
                        &&   (!iqentry_v[head1])
3859
                        &&   (!iqentry_v[head2])
3860
                        &&   (!iqentry_v[head3])
3861
                        &&   (!iqentry_v[head4]))
3862
                        )
3863
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
3864
                                ((!iqentry_v[head0])
3865
                        &&   (!iqentry_v[head1])
3866
                        &&   (!iqentry_v[head2])
3867
                        &&   (!iqentry_v[head3])
3868
                        &&   (!iqentry_v[head4])
3869
                        &&   (!iqentry_v[head5]))
3870
                        )
3871
                ) begin
3872
                        iqentry_alu0_issue[head7] = `TRUE;
3873
                end
3874
`endif
3875
        end
3876
 
3877 49 robfinch
        if (alu1_available && alu1_idle && `NUM_ALU > 1) begin
3878 48 robfinch
                if ((could_issue & ~iqentry_alu0_issue & ~iqentry_alu0) != 8'h00) begin
3879
                if (could_issue[head0] && iqentry_alu[head0]
3880
                && !iqentry_alu0[head0] // alu0only
3881
                && !iqentry_alu0_issue[head0]) begin
3882
                  iqentry_alu1_issue[head0] = `TRUE;
3883
                end
3884
                else if (could_issue[head1] && !iqentry_alu0_issue[head1] && iqentry_alu[head1]
3885
                && !iqentry_alu0[head1])
3886
                begin
3887
                  iqentry_alu1_issue[head1] = `TRUE;
3888
                end
3889
                else if (could_issue[head2] && !iqentry_alu0_issue[head2] && iqentry_alu[head2]
3890
                && !iqentry_alu0[head2]
3891
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3892
                )
3893
                begin
3894
                        iqentry_alu1_issue[head2] = `TRUE;
3895
                end
3896
                else if (could_issue[head3] && !iqentry_alu0_issue[head3] && iqentry_alu[head3]
3897
                && !iqentry_alu0[head3]
3898
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3899
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3900
                                ((!iqentry_v[head0])
3901
                        &&   (!iqentry_v[head1]))
3902
                        )
3903
                ) begin
3904
                        iqentry_alu1_issue[head3] = `TRUE;
3905
                end
3906
                else if (could_issue[head4] && !iqentry_alu0_issue[head4] && iqentry_alu[head4]
3907
                && !iqentry_alu0[head4]
3908
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3909
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3910
                                ((!iqentry_v[head0])
3911
                        &&   (!iqentry_v[head1]))
3912
                        )
3913
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3914
                                ((!iqentry_v[head0])
3915
                        &&   (!iqentry_v[head1])
3916
                        &&   (!iqentry_v[head2]))
3917
                        )
3918
                ) begin
3919
                        iqentry_alu1_issue[head4] = `TRUE;
3920
                end
3921
                else if (could_issue[head5] && !iqentry_alu0_issue[head5] && iqentry_alu[head5]
3922
                && !iqentry_alu0[head5]
3923
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3924
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3925
                                ((!iqentry_v[head0])
3926
                        &&   (!iqentry_v[head1]))
3927
                        )
3928
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3929
                                ((!iqentry_v[head0])
3930
                        &&   (!iqentry_v[head1])
3931
                        &&   (!iqentry_v[head2]))
3932
                        )
3933
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3934
                                ((!iqentry_v[head0])
3935
                        &&   (!iqentry_v[head1])
3936
                        &&   (!iqentry_v[head2])
3937
                        &&   (!iqentry_v[head3]))
3938
                        )
3939
                ) begin
3940
                        iqentry_alu1_issue[head5] = `TRUE;
3941
                end
3942
`ifdef FULL_ISSUE_LOGIC
3943
                else if (could_issue[head6] && !iqentry_alu0_issue[head6] && iqentry_alu[head6]
3944
                && !iqentry_alu0[head6]
3945
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3946
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3947
                                ((!iqentry_v[head0])
3948
                        &&   (!iqentry_v[head1]))
3949
                        )
3950
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3951
                                ((!iqentry_v[head0])
3952
                        &&   (!iqentry_v[head1])
3953
                        &&   (!iqentry_v[head2]))
3954
                        )
3955
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3956
                                ((!iqentry_v[head0])
3957
                        &&   (!iqentry_v[head1])
3958
                        &&   (!iqentry_v[head2])
3959
                        &&   (!iqentry_v[head3]))
3960
                        )
3961
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3962
                                ((!iqentry_v[head0])
3963
                        &&   (!iqentry_v[head1])
3964
                        &&   (!iqentry_v[head2])
3965
                        &&   (!iqentry_v[head3])
3966
                        &&   (!iqentry_v[head4]))
3967
                        )
3968
                ) begin
3969
                        iqentry_alu1_issue[head6] = `TRUE;
3970
                end
3971
                else if (could_issue[head7] && !iqentry_alu0_issue[head7] && iqentry_alu[head7]
3972
                && !iqentry_alu0[head7]
3973
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3974
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3975
                                ((!iqentry_v[head0])
3976
                        &&   (!iqentry_v[head1]))
3977
                        )
3978
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3979
                                ((!iqentry_v[head0])
3980
                        &&   (!iqentry_v[head1])
3981
                        &&   (!iqentry_v[head2]))
3982
                        )
3983
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3984
                                ((!iqentry_v[head0])
3985
                        &&   (!iqentry_v[head1])
3986
                        &&   (!iqentry_v[head2])
3987
                        &&   (!iqentry_v[head3]))
3988
                        )
3989
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3990
                                ((!iqentry_v[head0])
3991
                        &&   (!iqentry_v[head1])
3992
                        &&   (!iqentry_v[head2])
3993
                        &&   (!iqentry_v[head3])
3994
                        &&   (!iqentry_v[head4]))
3995
                        )
3996
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
3997
                                ((!iqentry_v[head0])
3998
                        &&   (!iqentry_v[head1])
3999
                        &&   (!iqentry_v[head2])
4000
                        &&   (!iqentry_v[head3])
4001
                        &&   (!iqentry_v[head4])
4002
                        &&   (!iqentry_v[head5]))
4003
                        )
4004
                ) begin
4005
                        iqentry_alu1_issue[head7] = `TRUE;
4006
                end
4007
`endif
4008
        end
4009
//      aluissue(alu0_idle,8'h00,2'b00);
4010
//      aluissue(alu1_idle,iqentry_alu0,2'b01);
4011
        end
4012
end
4013
 
4014
always @*
4015
begin
4016 49 robfinch
        iqentry_fpu1_issue = {QENTRIES{1'b0}};
4017
//      fpu1issue(fpu1_idle,2'b00);
4018
        if (fpu1_idle && `NUM_FPU > 0) begin
4019 48 robfinch
    if (could_issue[head0] && iqentry_fpu[head0]) begin
4020 49 robfinch
      iqentry_fpu1_issue[head0] = `TRUE;
4021 48 robfinch
    end
4022
    else if (could_issue[head1] && iqentry_fpu[head1])
4023
    begin
4024 49 robfinch
      iqentry_fpu1_issue[head1] = `TRUE;
4025 48 robfinch
    end
4026
    else if (could_issue[head2] && iqentry_fpu[head2]
4027
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4028
    ) begin
4029 49 robfinch
      iqentry_fpu1_issue[head2] = `TRUE;
4030 48 robfinch
    end
4031
    else if (could_issue[head3] && iqentry_fpu[head3]
4032
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4033
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4034
                ((!iqentry_v[head0])
4035
        &&   (!iqentry_v[head1]))
4036
        )
4037
    ) begin
4038 49 robfinch
      iqentry_fpu1_issue[head3] = `TRUE;
4039 48 robfinch
    end
4040
    else if (could_issue[head4] && iqentry_fpu[head4]
4041
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4042
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4043
                ((!iqentry_v[head0])
4044
        &&   (!iqentry_v[head1]))
4045
        )
4046
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4047
                ((!iqentry_v[head0])
4048
        &&   (!iqentry_v[head1])
4049
        &&   (!iqentry_v[head2]))
4050
        )
4051
    ) begin
4052 49 robfinch
      iqentry_fpu1_issue[head4] = `TRUE;
4053 48 robfinch
    end
4054
    else if (could_issue[head5] && iqentry_fpu[head5]
4055
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4056
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4057
                ((!iqentry_v[head0])
4058
        &&   (!iqentry_v[head1]))
4059
        )
4060
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4061
                ((!iqentry_v[head0])
4062
        &&   (!iqentry_v[head1])
4063
        &&   (!iqentry_v[head2]))
4064
        )
4065
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4066
                ((!iqentry_v[head0])
4067
        &&   (!iqentry_v[head1])
4068
        &&   (!iqentry_v[head2])
4069
        &&   (!iqentry_v[head3]))
4070
        )
4071
        ) begin
4072 49 robfinch
              iqentry_fpu1_issue[head5] = `TRUE;
4073 48 robfinch
    end
4074
`ifdef FULL_ISSUE_LOGIC
4075
    else if (could_issue[head6] && iqentry_fpu[head6]
4076
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4077
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4078
                ((!iqentry_v[head0])
4079
        &&   (!iqentry_v[head1]))
4080
        )
4081
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4082
                ((!iqentry_v[head0])
4083
        &&   (!iqentry_v[head1])
4084
        &&   (!iqentry_v[head2]))
4085
        )
4086
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4087
                ((!iqentry_v[head0])
4088
        &&   (!iqentry_v[head1])
4089
        &&   (!iqentry_v[head2])
4090
        &&   (!iqentry_v[head3]))
4091
        )
4092
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4093
                ((!iqentry_v[head0])
4094
        &&   (!iqentry_v[head1])
4095
        &&   (!iqentry_v[head2])
4096
        &&   (!iqentry_v[head3])
4097
        &&   (!iqentry_v[head4]))
4098
        )
4099
    ) begin
4100 49 robfinch
        iqentry_fpu1_issue[head6] = `TRUE;
4101 48 robfinch
    end
4102
    else if (could_issue[head7] && iqentry_fpu[head7]
4103
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4104
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4105
                ((!iqentry_v[head0])
4106
        &&   (!iqentry_v[head1]))
4107
        )
4108
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4109
                ((!iqentry_v[head0])
4110
        &&   (!iqentry_v[head1])
4111
        &&   (!iqentry_v[head2]))
4112
        )
4113
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4114
                ((!iqentry_v[head0])
4115
        &&   (!iqentry_v[head1])
4116
        &&   (!iqentry_v[head2])
4117
        &&   (!iqentry_v[head3]))
4118
        )
4119
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4120
                ((!iqentry_v[head0])
4121
        &&   (!iqentry_v[head1])
4122
        &&   (!iqentry_v[head2])
4123
        &&   (!iqentry_v[head3])
4124
        &&   (!iqentry_v[head4]))
4125
        )
4126
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
4127
                ((!iqentry_v[head0])
4128
        &&   (!iqentry_v[head1])
4129
        &&   (!iqentry_v[head2])
4130
        &&   (!iqentry_v[head3])
4131
        &&   (!iqentry_v[head4])
4132
        &&   (!iqentry_v[head5]))
4133
        )
4134
        )
4135
    begin
4136 49 robfinch
                iqentry_fpu1_issue[head7] = `TRUE;
4137 48 robfinch
        end
4138
`endif
4139
        end
4140
end
4141
 
4142 49 robfinch
always @*
4143
begin
4144
        iqentry_fpu2_issue = {QENTRIES{1'b0}};
4145
//      fpu2issue(fpu2_idle,2'b00);
4146
        if (fpu2_idle && `NUM_FPU > 1) begin
4147
    if (could_issue[head0] && iqentry_fpu[head0] && !iqentry_fpu1_issue[head0]) begin
4148
      iqentry_fpu2_issue[head0] = `TRUE;
4149
    end
4150
    else if (could_issue[head1] && iqentry_fpu[head1] && !iqentry_fpu1_issue[head1])
4151
    begin
4152
      iqentry_fpu2_issue[head1] = `TRUE;
4153
    end
4154
    else if (could_issue[head2] && iqentry_fpu[head2] && !iqentry_fpu1_issue[head2]
4155
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4156
    ) begin
4157
      iqentry_fpu2_issue[head2] = `TRUE;
4158
    end
4159
    else if (could_issue[head3] && iqentry_fpu[head3] && !iqentry_fpu1_issue[head3]
4160
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4161
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4162
                ((!iqentry_v[head0])
4163
        &&   (!iqentry_v[head1]))
4164
        )
4165
    ) begin
4166
      iqentry_fpu2_issue[head3] = `TRUE;
4167
    end
4168
    else if (could_issue[head4] && iqentry_fpu[head4] && !iqentry_fpu1_issue[head4]
4169
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4170
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4171
                ((!iqentry_v[head0])
4172
        &&   (!iqentry_v[head1]))
4173
        )
4174
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4175
                ((!iqentry_v[head0])
4176
        &&   (!iqentry_v[head1])
4177
        &&   (!iqentry_v[head2]))
4178
        )
4179
    ) begin
4180
      iqentry_fpu2_issue[head4] = `TRUE;
4181
    end
4182
    else if (could_issue[head5] && iqentry_fpu[head5] && !iqentry_fpu1_issue[head5]
4183
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4184
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4185
                ((!iqentry_v[head0])
4186
        &&   (!iqentry_v[head1]))
4187
        )
4188
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4189
                ((!iqentry_v[head0])
4190
        &&   (!iqentry_v[head1])
4191
        &&   (!iqentry_v[head2]))
4192
        )
4193
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4194
                ((!iqentry_v[head0])
4195
        &&   (!iqentry_v[head1])
4196
        &&   (!iqentry_v[head2])
4197
        &&   (!iqentry_v[head3]))
4198
        )
4199
        ) begin
4200
              iqentry_fpu2_issue[head5] = `TRUE;
4201
    end
4202
`ifdef FULL_ISSUE_LOGIC
4203
    else if (could_issue[head6] && iqentry_fpu[head6] && !iqentry_fpu1_issue[head6]
4204
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4205
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4206
                ((!iqentry_v[head0])
4207
        &&   (!iqentry_v[head1]))
4208
        )
4209
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4210
                ((!iqentry_v[head0])
4211
        &&   (!iqentry_v[head1])
4212
        &&   (!iqentry_v[head2]))
4213
        )
4214
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4215
                ((!iqentry_v[head0])
4216
        &&   (!iqentry_v[head1])
4217
        &&   (!iqentry_v[head2])
4218
        &&   (!iqentry_v[head3]))
4219
        )
4220
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4221
                ((!iqentry_v[head0])
4222
        &&   (!iqentry_v[head1])
4223
        &&   (!iqentry_v[head2])
4224
        &&   (!iqentry_v[head3])
4225
        &&   (!iqentry_v[head4]))
4226
        )
4227
    ) begin
4228
        iqentry_fpu2_issue[head6] = `TRUE;
4229
    end
4230
    else if (could_issue[head7] && iqentry_fpu[head7] && !iqentry_fpu1_issue[head7]
4231
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4232
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4233
                ((!iqentry_v[head0])
4234
        &&   (!iqentry_v[head1]))
4235
        )
4236
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4237
                ((!iqentry_v[head0])
4238
        &&   (!iqentry_v[head1])
4239
        &&   (!iqentry_v[head2]))
4240
        )
4241
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4242
                ((!iqentry_v[head0])
4243
        &&   (!iqentry_v[head1])
4244
        &&   (!iqentry_v[head2])
4245
        &&   (!iqentry_v[head3]))
4246
        )
4247
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4248
                ((!iqentry_v[head0])
4249
        &&   (!iqentry_v[head1])
4250
        &&   (!iqentry_v[head2])
4251
        &&   (!iqentry_v[head3])
4252
        &&   (!iqentry_v[head4]))
4253
        )
4254
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
4255
                ((!iqentry_v[head0])
4256
        &&   (!iqentry_v[head1])
4257
        &&   (!iqentry_v[head2])
4258
        &&   (!iqentry_v[head3])
4259
        &&   (!iqentry_v[head4])
4260
        &&   (!iqentry_v[head5]))
4261
        )
4262
        )
4263
    begin
4264
                iqentry_fpu2_issue[head7] = `TRUE;
4265
        end
4266
`endif
4267
        end
4268
end
4269 48 robfinch
 
4270
wire [QENTRIES-1:0] nextqd;
4271
// Next queue id
4272
 
4273
reg [`QBITS] nid0;
4274
always @*
4275
if (iqentry_thrd[1]==iqentry_thrd[0])
4276 52 robfinch
        nid0 = 4'd1;
4277 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[0])
4278 52 robfinch
        nid0 = 4'd2;
4279 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[0])
4280 52 robfinch
        nid0 = 4'd3;
4281 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[0])
4282 52 robfinch
        nid0 = 4'd4;
4283 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[0])
4284 52 robfinch
        nid0 = 4'd5;
4285 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[0])
4286 52 robfinch
        nid0 = 4'd6;
4287 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[0])
4288 52 robfinch
        nid0 = 4'd7;
4289
else if (iqentry_thrd[8]==iqentry_thrd[0])
4290
        nid0 = 4'd8;
4291
else if (iqentry_thrd[9]==iqentry_thrd[0])
4292
        nid0 = 4'd9;
4293 48 robfinch
else
4294
        nid0 = 3'd0;
4295
 
4296
reg [`QBITS] nid1;
4297
always @*
4298
if (iqentry_thrd[2]==iqentry_thrd[1])
4299 52 robfinch
        nid1 = 4'd2;
4300 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[1])
4301 52 robfinch
        nid1 = 4'd3;
4302 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[1])
4303 52 robfinch
        nid1 = 4'd4;
4304 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[1])
4305 52 robfinch
        nid1 = 4'd5;
4306 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[1])
4307 52 robfinch
        nid1 = 4'd6;
4308 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[1])
4309 52 robfinch
        nid1 = 4'd7;
4310
else if (iqentry_thrd[8]==iqentry_thrd[1])
4311
        nid1 = 4'd8;
4312
else if (iqentry_thrd[9]==iqentry_thrd[1])
4313
        nid1 = 4'd9;
4314 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[1])
4315 52 robfinch
        nid1 = 4'd0;
4316 48 robfinch
else
4317 52 robfinch
        nid1 = 4'd1;
4318 48 robfinch
 
4319
reg [`QBITS] nid2;
4320
always @*
4321
if (iqentry_thrd[3]==iqentry_thrd[2])
4322 52 robfinch
        nid2 = 4'd3;
4323 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[2])
4324 52 robfinch
        nid2 = 4'd4;
4325 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[2])
4326 52 robfinch
        nid2 = 4'd5;
4327 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[2])
4328 52 robfinch
        nid2 = 4'd6;
4329 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[2])
4330 52 robfinch
        nid2 = 4'd7;
4331
else if (iqentry_thrd[8]==iqentry_thrd[2])
4332
        nid2 = 4'd8;
4333
else if (iqentry_thrd[9]==iqentry_thrd[2])
4334
        nid2 = 4'd9;
4335 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[2])
4336 52 robfinch
        nid2 = 4'd0;
4337 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[2])
4338 52 robfinch
        nid2 = 4'd1;
4339 48 robfinch
else
4340 52 robfinch
        nid2 = 4'd2;
4341 48 robfinch
 
4342
reg [`QBITS] nid3;
4343
always @*
4344
if (iqentry_thrd[4]==iqentry_thrd[3])
4345 52 robfinch
        nid3 = 4'd4;
4346 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[3])
4347 52 robfinch
        nid3 = 4'd5;
4348 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[3])
4349 52 robfinch
        nid3 = 4'd6;
4350 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[3])
4351 52 robfinch
        nid3 = 4'd7;
4352
else if (iqentry_thrd[8]==iqentry_thrd[3])
4353
        nid3 = 4'd8;
4354
else if (iqentry_thrd[9]==iqentry_thrd[3])
4355
        nid3 = 4'd9;
4356 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[3])
4357 52 robfinch
        nid3 = 4'd0;
4358 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[3])
4359 52 robfinch
        nid3 = 4'd1;
4360 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[3])
4361 52 robfinch
        nid3 = 4'd2;
4362 48 robfinch
else
4363 52 robfinch
        nid3 = 4'd3;
4364 48 robfinch
 
4365
reg [`QBITS] nid4;
4366
always @*
4367
if (iqentry_thrd[5]==iqentry_thrd[4])
4368 52 robfinch
        nid4 = 4'd5;
4369 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[4])
4370 52 robfinch
        nid4 = 4'd6;
4371 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[4])
4372 52 robfinch
        nid4 = 4'd7;
4373
else if (iqentry_thrd[8]==iqentry_thrd[4])
4374
        nid4 = 4'd8;
4375
else if (iqentry_thrd[9]==iqentry_thrd[4])
4376
        nid4 = 4'd9;
4377 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[4])
4378 52 robfinch
        nid4 = 4'd0;
4379 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[4])
4380 52 robfinch
        nid4 = 4'd1;
4381 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[4])
4382 52 robfinch
        nid4 = 4'd2;
4383 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[4])
4384 52 robfinch
        nid4 = 4'd3;
4385 48 robfinch
else
4386 52 robfinch
        nid4 = 4'd4;
4387 48 robfinch
 
4388
reg [`QBITS] nid5;
4389
always @*
4390
if (iqentry_thrd[6]==iqentry_thrd[5])
4391 52 robfinch
        nid5 = 4'd6;
4392 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[5])
4393 52 robfinch
        nid5 = 4'd7;
4394
else if (iqentry_thrd[8]==iqentry_thrd[5])
4395
        nid5 = 4'd8;
4396
else if (iqentry_thrd[9]==iqentry_thrd[5])
4397
        nid5 = 4'd9;
4398 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[5])
4399 52 robfinch
        nid5 = 4'd0;
4400 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[5])
4401 52 robfinch
        nid5 = 4'd1;
4402 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[5])
4403 52 robfinch
        nid5 = 4'd2;
4404 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[5])
4405 52 robfinch
        nid5 = 4'd3;
4406 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[5])
4407 52 robfinch
        nid5 = 4'd4;
4408 48 robfinch
else
4409 52 robfinch
        nid5 = 4'd5;
4410 48 robfinch
 
4411
reg [`QBITS] nid6;
4412
always @*
4413
if (iqentry_thrd[7]==iqentry_thrd[6])
4414 52 robfinch
        nid6 = 4'd7;
4415
else if (iqentry_thrd[8]==iqentry_thrd[6])
4416
        nid6 = 4'd8;
4417
else if (iqentry_thrd[9]==iqentry_thrd[6])
4418
        nid6 = 4'd9;
4419 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[6])
4420 52 robfinch
        nid6 = 4'd0;
4421 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[6])
4422 52 robfinch
        nid6 = 4'd1;
4423 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[6])
4424 52 robfinch
        nid6 = 4'd2;
4425 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[6])
4426 52 robfinch
        nid6 = 4'd3;
4427 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[6])
4428 52 robfinch
        nid6 = 4'd4;
4429 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[6])
4430 52 robfinch
        nid6 = 4'd5;
4431 48 robfinch
else
4432 52 robfinch
        nid6 = 4'd6;
4433 48 robfinch
 
4434
reg [`QBITS] nid7;
4435
always @*
4436 52 robfinch
if (iqentry_thrd[8]==iqentry_thrd[7])
4437
        nid7 = 4'd8;
4438
else if (iqentry_thrd[9]==iqentry_thrd[7])
4439
        nid7 = 4'd9;
4440
else if (iqentry_thrd[0]==iqentry_thrd[7])
4441
        nid7 = 4'd0;
4442 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[7])
4443 52 robfinch
        nid7 = 4'd1;
4444 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[7])
4445 52 robfinch
        nid7 = 4'd2;
4446 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[7])
4447 52 robfinch
        nid7 = 4'd3;
4448 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[7])
4449 52 robfinch
        nid7 = 4'd4;
4450 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[7])
4451 52 robfinch
        nid7 = 4'd5;
4452 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[7])
4453 52 robfinch
        nid7 = 4'd6;
4454 48 robfinch
else
4455 52 robfinch
        nid7 = 4'd7;
4456 48 robfinch
 
4457 52 robfinch
reg [`QBITS] nid8;
4458
always @*
4459
if (iqentry_thrd[9]==iqentry_thrd[8])
4460
        nid8 = 4'd9;
4461
else if (iqentry_thrd[0]==iqentry_thrd[8])
4462
        nid8 = 4'd0;
4463
else if (iqentry_thrd[1]==iqentry_thrd[8])
4464
        nid8 = 4'd1;
4465
else if (iqentry_thrd[2]==iqentry_thrd[8])
4466
        nid8 = 4'd2;
4467
else if (iqentry_thrd[3]==iqentry_thrd[8])
4468
        nid8 = 4'd3;
4469
else if (iqentry_thrd[4]==iqentry_thrd[8])
4470
        nid8 = 4'd4;
4471
else if (iqentry_thrd[5]==iqentry_thrd[8])
4472
        nid8 = 4'd5;
4473
else if (iqentry_thrd[6]==iqentry_thrd[8])
4474
        nid8 = 4'd6;
4475
else if (iqentry_thrd[7]==iqentry_thrd[8])
4476
        nid8 = 4'd7;
4477
else
4478
        nid8 = 4'd8;
4479
 
4480
reg [`QBITS] nid9;
4481
always @*
4482
if (iqentry_thrd[0]==iqentry_thrd[9])
4483
        nid9 = 4'd0;
4484
else if (iqentry_thrd[1]==iqentry_thrd[9])
4485
        nid9 = 4'd1;
4486
else if (iqentry_thrd[2]==iqentry_thrd[9])
4487
        nid9 = 4'd2;
4488
else if (iqentry_thrd[3]==iqentry_thrd[9])
4489
        nid9 = 4'd3;
4490
else if (iqentry_thrd[4]==iqentry_thrd[9])
4491
        nid9 = 4'd4;
4492
else if (iqentry_thrd[5]==iqentry_thrd[9])
4493
        nid9 = 4'd5;
4494
else if (iqentry_thrd[6]==iqentry_thrd[9])
4495
        nid9 = 4'd6;
4496
else if (iqentry_thrd[7]==iqentry_thrd[9])
4497
        nid9 = 4'd7;
4498
else if (iqentry_thrd[8]==iqentry_thrd[9])
4499
        nid9 = 4'd8;
4500
else
4501
        nid9 = 4'd9;
4502
 
4503 48 robfinch
// Search the queue for the next entry on the same thread.
4504
reg [`QBITS] nid;
4505
always @*
4506
if (iqentry_thrd[idp1(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4507
        nid = idp1(fcu_id);
4508
else if (iqentry_thrd[idp2(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4509
        nid = idp2(fcu_id);
4510
else if (iqentry_thrd[idp3(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4511
        nid = idp3(fcu_id);
4512
else if (iqentry_thrd[idp4(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4513
        nid = idp4(fcu_id);
4514
else if (iqentry_thrd[idp5(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4515
        nid = idp5(fcu_id);
4516
else if (iqentry_thrd[idp6(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4517
        nid = idp6(fcu_id);
4518
else if (iqentry_thrd[idp7(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4519
        nid = idp7(fcu_id);
4520 52 robfinch
else if (iqentry_thrd[idp8(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4521
        nid = idp8(fcu_id);
4522
else if (iqentry_thrd[idp9(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4523
        nid = idp9(fcu_id);
4524 48 robfinch
else
4525
        nid = fcu_id;
4526
 
4527
assign  nextqd[0] = iqentry_sn[nid0] > iqentry_sn[0] || iqentry_v[0];
4528
assign  nextqd[1] = iqentry_sn[nid1] > iqentry_sn[1] || iqentry_v[1];
4529
assign  nextqd[2] = iqentry_sn[nid2] > iqentry_sn[2] || iqentry_v[2];
4530
assign  nextqd[3] = iqentry_sn[nid3] > iqentry_sn[3] || iqentry_v[3];
4531
assign  nextqd[4] = iqentry_sn[nid4] > iqentry_sn[4] || iqentry_v[4];
4532
assign  nextqd[5] = iqentry_sn[nid5] > iqentry_sn[5] || iqentry_v[5];
4533
assign  nextqd[6] = iqentry_sn[nid6] > iqentry_sn[6] || iqentry_v[6];
4534
assign  nextqd[7] = iqentry_sn[nid7] > iqentry_sn[7] || iqentry_v[7];
4535 52 robfinch
assign  nextqd[8] = iqentry_sn[nid8] > iqentry_sn[8] || iqentry_v[8];
4536
assign  nextqd[9] = iqentry_sn[nid9] > iqentry_sn[9] || iqentry_v[9];
4537 48 robfinch
 
4538
//assign nextqd = 8'hFF;
4539
 
4540
// Don't issue to the fcu until the following instruction is enqueued.
4541
// However, if the queue is full then issue anyway. A branch miss will likely occur.
4542
always @*//(could_issue or head0 or head1 or head2 or head3 or head4 or head5 or head6 or head7)
4543
begin
4544 49 robfinch
        iqentry_fcu_issue = {QENTRIES{1'b0}};
4545 48 robfinch
        if (fcu_done) begin
4546
    if (could_issue[head0] && iqentry_fc[head0] && nextqd[head0]) begin
4547
      iqentry_fcu_issue[head0] = `TRUE;
4548
    end
4549
    else if (could_issue[head1] && iqentry_fc[head1] && nextqd[head1])
4550
    begin
4551
      iqentry_fcu_issue[head1] = `TRUE;
4552
    end
4553
    else if (could_issue[head2] && iqentry_fc[head2] && nextqd[head2]
4554
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4555
    ) begin
4556
                iqentry_fcu_issue[head2] = `TRUE;
4557
    end
4558
    else if (could_issue[head3] && iqentry_fc[head3] && nextqd[head3]
4559
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4560
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4561
                ((!iqentry_v[head0])
4562
        &&   (!iqentry_v[head1]))
4563
        )
4564
    ) begin
4565
                iqentry_fcu_issue[head3] = `TRUE;
4566
    end
4567
    else if (could_issue[head4] && iqentry_fc[head4] && nextqd[head4]
4568
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4569
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4570
                ((!iqentry_v[head0])
4571
        &&   (!iqentry_v[head1]))
4572
        )
4573
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4574
                ((!iqentry_v[head0])
4575
        &&   (!iqentry_v[head1])
4576
        &&   (!iqentry_v[head2]))
4577
        )
4578
    ) begin
4579
                iqentry_fcu_issue[head4] = `TRUE;
4580
    end
4581
    else if (could_issue[head5] && iqentry_fc[head5] && nextqd[head5]
4582
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4583
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4584
                ((!iqentry_v[head0])
4585
        &&   (!iqentry_v[head1]))
4586
        )
4587
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4588
                ((!iqentry_v[head0])
4589
        &&   (!iqentry_v[head1])
4590
        &&   (!iqentry_v[head2]))
4591
        )
4592
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4593
                ((!iqentry_v[head0])
4594
        &&   (!iqentry_v[head1])
4595
        &&   (!iqentry_v[head2])
4596
        &&   (!iqentry_v[head3]))
4597
        )
4598
    ) begin
4599
                iqentry_fcu_issue[head5] = `TRUE;
4600
    end
4601
 
4602
`ifdef FULL_ISSUE_LOGIC
4603
    else if (could_issue[head6] && iqentry_fc[head6] && nextqd[head6]
4604
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4605
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4606
                ((!iqentry_v[head0])
4607
        &&   (!iqentry_v[head1]))
4608
        )
4609
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4610
                ((!iqentry_v[head0])
4611
        &&   (!iqentry_v[head1])
4612
        &&   (!iqentry_v[head2]))
4613
        )
4614
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4615
                ((!iqentry_v[head0])
4616
        &&   (!iqentry_v[head1])
4617
        &&   (!iqentry_v[head2])
4618
        &&   (!iqentry_v[head3]))
4619
        )
4620
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4621
                ((!iqentry_v[head0])
4622
        &&   (!iqentry_v[head1])
4623
        &&   (!iqentry_v[head2])
4624
        &&   (!iqentry_v[head3])
4625
        &&   (!iqentry_v[head4]))
4626
        )
4627
    ) begin
4628
                iqentry_fcu_issue[head6] = `TRUE;
4629
    end
4630
 
4631
    else if (could_issue[head7] && iqentry_fc[head7]
4632
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4633
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4634
                ((!iqentry_v[head0])
4635
        &&   (!iqentry_v[head1]))
4636
        )
4637
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4638
                ((!iqentry_v[head0])
4639
        &&   (!iqentry_v[head1])
4640
        &&   (!iqentry_v[head2]))
4641
        )
4642
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4643
                ((!iqentry_v[head0])
4644
        &&   (!iqentry_v[head1])
4645
        &&   (!iqentry_v[head2])
4646
        &&   (!iqentry_v[head3]))
4647
        )
4648
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4649
                ((!iqentry_v[head0])
4650
        &&   (!iqentry_v[head1])
4651
        &&   (!iqentry_v[head2])
4652
        &&   (!iqentry_v[head3])
4653
        &&   (!iqentry_v[head4]))
4654
        )
4655
    && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4656
                ((!iqentry_v[head0])
4657
        &&   (!iqentry_v[head1])
4658
        &&   (!iqentry_v[head2])
4659
        &&   (!iqentry_v[head3])
4660
        &&   (!iqentry_v[head4])
4661
        &&   (!iqentry_v[head5]))
4662
        )
4663
    ) begin
4664
                iqentry_fcu_issue[head7] = `TRUE;
4665
        end
4666
`endif
4667
        end
4668
end
4669
 
4670
//
4671
// determine if the instructions ready to issue can, in fact, issue.
4672
// "ready" means that the instruction has valid operands but has not gone yet
4673
reg [1:0] issue_count, missue_count;
4674
always @*
4675
begin
4676
        issue_count = 0;
4677
         memissue[ head0 ] =    iqentry_memready[ head0 ];              // first in line ... go as soon as ready
4678
         if (memissue[head0])
4679
                issue_count = issue_count + 1;
4680
 
4681
         memissue[ head1 ] =    ~iqentry_stomp[head1] && iqentry_memready[ head1 ]              // addr and data are valid
4682 49 robfinch
                                        && issue_count < `NUM_MEM
4683 48 robfinch
                                        // ... and no preceding instruction is ready to go
4684
                                        //&& ~iqentry_memready[head0]
4685
                                        // ... and there is no address-overlap with any preceding instruction
4686 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4687
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head1][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4688 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4689
                                        && (iqentry_rl[head1] ? iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0] : 1'b1)
4690
                                        // ... if a preivous op has the aquire bit set
4691
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4692
                                        // ... and, if it is a SW, there is no chance of it being undone
4693
                                        && (iqentry_load[head1] ||
4694
                                           !(iqentry_fc[head0]||iqentry_canex[head0]));
4695
         if (memissue[head1])
4696
                issue_count = issue_count + 1;
4697
 
4698
         memissue[ head2 ] =    ~iqentry_stomp[head2] && iqentry_memready[ head2 ]              // addr and data are valid
4699
                                        // ... and no preceding instruction is ready to go
4700 49 robfinch
                                        && issue_count < `NUM_MEM
4701 48 robfinch
                                        //&& ~iqentry_memready[head0]
4702
                                        //&& ~iqentry_memready[head1] 
4703
                                        // ... and there is no address-overlap with any preceding instruction
4704 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4705
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head2][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4706
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4707
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head2][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4708 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4709
                                        && (iqentry_rl[head2] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4710
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4711
                                                                                         : 1'b1)
4712
                                        // ... if a preivous op has the aquire bit set
4713
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4714
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4715
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4716 49 robfinch
            && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4717
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4718 48 robfinch
                                        // ... and, if it is a SW, there is no chance of it being undone
4719
                                        && (iqentry_load[head2] ||
4720
                                              !(iqentry_fc[head0]||iqentry_canex[head0])
4721
                                           && !(iqentry_fc[head1]||iqentry_canex[head1]));
4722
         if (memissue[head2])
4723
                issue_count = issue_count + 1;
4724
 
4725
         memissue[ head3 ] =    ~iqentry_stomp[head3] && iqentry_memready[ head3 ]              // addr and data are valid
4726
                                        // ... and no preceding instruction is ready to go
4727 49 robfinch
                                        && issue_count < `NUM_MEM
4728 48 robfinch
                                        //&& ~iqentry_memready[head0]
4729
                                        //&& ~iqentry_memready[head1] 
4730
                                        //&& ~iqentry_memready[head2] 
4731
                                        // ... and there is no address-overlap with any preceding instruction
4732 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4733
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4734
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4735
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4736
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])  || iqentry_done[head2]
4737
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4738 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4739
                                        && (iqentry_rl[head3] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4740
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4741
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4742
                                                                                         : 1'b1)
4743
                                        // ... if a preivous op has the aquire bit set
4744
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4745
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4746
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4747
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4748 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4749
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4750 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4751
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4752
                                )
4753 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4754
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4755 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4756
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4757
                                )
4758
                    // ... and, if it is a SW, there is no chance of it being undone
4759
                                        && (iqentry_load[head3] ||
4760
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4761
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4762
                       && !(iqentry_fc[head2]||iqentry_canex[head2]));
4763
         if (memissue[head3])
4764
                issue_count = issue_count + 1;
4765
 
4766
         memissue[ head4 ] =    ~iqentry_stomp[head4] && iqentry_memready[ head4 ]              // addr and data are valid
4767
                                        // ... and no preceding instruction is ready to go
4768 49 robfinch
                                        && issue_count < `NUM_MEM
4769 48 robfinch
                                        //&& ~iqentry_memready[head0]
4770
                                        //&& ~iqentry_memready[head1] 
4771
                                        //&& ~iqentry_memready[head2] 
4772
                                        //&& ~iqentry_memready[head3] 
4773
                                        // ... and there is no address-overlap with any preceding instruction
4774 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4775
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4776
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4777
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4778
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])  || iqentry_done[head2]
4779
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4780
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])  || iqentry_done[head3]
4781
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
4782 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4783
                                        && (iqentry_rl[head4] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4784
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4785
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4786
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4787
                                                                                         : 1'b1)
4788
                                        // ... if a preivous op has the aquire bit set
4789
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4790
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4791
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4792
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4793
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4794 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4795
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4796 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4797
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4798
                                )
4799 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4800 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4801
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4802
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4803
                                )
4804
                                && (!(iqentry_v[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4805 49 robfinch
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4806 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4807
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4808
                                )
4809 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
4810 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4811
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4812
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4813
                                )
4814
                                        // ... and, if it is a SW, there is no chance of it being undone
4815
                                        && (iqentry_load[head4] ||
4816
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4817
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4818
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4819
                       && !(iqentry_fc[head3]||iqentry_canex[head3]));
4820
         if (memissue[head4])
4821
                issue_count = issue_count + 1;
4822
 
4823
         memissue[ head5 ] =    ~iqentry_stomp[head5] && iqentry_memready[ head5 ]              // addr and data are valid
4824
                                        // ... and no preceding instruction is ready to go
4825 49 robfinch
                                        && issue_count < `NUM_MEM
4826 48 robfinch
                                        //&& ~iqentry_memready[head0]
4827
                                        //&& ~iqentry_memready[head1] 
4828
                                        //&& ~iqentry_memready[head2] 
4829
                                        //&& ~iqentry_memready[head3] 
4830
                                        //&& ~iqentry_memready[head4] 
4831
                                        // ... and there is no address-overlap with any preceding instruction
4832 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4833
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4834
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
4835
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4836
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
4837
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4838
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
4839
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
4840
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
4841
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head4][AMSB:3] || iqentry_out[head4] || iqentry_done[head4])))
4842 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4843
                                        && (iqentry_rl[head5] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4844
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4845
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4846
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4847
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
4848
                                                                                         : 1'b1)
4849
                                        // ... if a preivous op has the aquire bit set
4850
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4851
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4852
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4853
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4854
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
4855
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4856 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4857
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4858 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4859
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4860
                                )
4861 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4862 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4863
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4864
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4865
                                )
4866 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
4867 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4868
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4869
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4870
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
4871
                                )
4872 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4873
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4874 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4875
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4876
                                )
4877 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
4878 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4879
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4880
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4881
                                )
4882 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
4883 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4884
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4885
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4886
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
4887
                                )
4888
                                        // ... and, if it is a SW, there is no chance of it being undone
4889
                                        && (iqentry_load[head5] ||
4890
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4891
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4892
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4893
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
4894
                       && !(iqentry_fc[head4]||iqentry_canex[head4]));
4895
         if (memissue[head5])
4896
                issue_count = issue_count + 1;
4897
 
4898
`ifdef FULL_ISSUE_LOGIC
4899
         memissue[ head6 ] =    ~iqentry_stomp[head6] && iqentry_memready[ head6 ]              // addr and data are valid
4900
                                        // ... and no preceding instruction is ready to go
4901 49 robfinch
                                        && issue_count < `NUM_MEM
4902 48 robfinch
                                        //&& ~iqentry_memready[head0]
4903
                                        //&& ~iqentry_memready[head1] 
4904
                                        //&& ~iqentry_memready[head2] 
4905
                                        //&& ~iqentry_memready[head3] 
4906
                                        //&& ~iqentry_memready[head4] 
4907
                                        //&& ~iqentry_memready[head5] 
4908
                                        // ... and there is no address-overlap with any preceding instruction
4909 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4910 53 robfinch
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head0][AMSB:3])))
4911 52 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
4912 53 robfinch
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head1][AMSB:3])))
4913 52 robfinch
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
4914 53 robfinch
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head2][AMSB:3])))
4915 52 robfinch
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
4916 53 robfinch
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head3][AMSB:3])))
4917 52 robfinch
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
4918 53 robfinch
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head4][AMSB:3])))
4919 52 robfinch
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5]) || iqentry_done[head5]
4920 53 robfinch
                                                || (iqentry_a1_v[head5] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head5][AMSB:3])))
4921 48 robfinch
                                        && (iqentry_rl[head6] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4922
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4923
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4924
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4925
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
4926
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
4927
                                                                                         : 1'b1)
4928
                                        // ... if a preivous op has the aquire bit set
4929
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4930
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4931
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4932
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4933
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
4934
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
4935
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4936 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4937
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4938 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4939
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4940
                                )
4941 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4942 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4943
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4944
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4945
                                )
4946 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
4947 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4948
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4949
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4950
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
4951
                                )
4952 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
4953 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4954
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4955
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4956
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
4957
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
4958
                                )
4959 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4960
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4961 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4962
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4963
                                )
4964 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
4965 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4966
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4967
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4968
                                )
4969 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
4970 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4971
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4972
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4973
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
4974
                                )
4975 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
4976 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4977
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4978
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4979
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
4980
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
4981
                                )
4982
                                        // ... and, if it is a SW, there is no chance of it being undone
4983
                                        && (iqentry_load[head6] ||
4984
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4985
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4986
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4987
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
4988
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
4989
                       && !(iqentry_fc[head5]||iqentry_canex[head5]));
4990
         if (memissue[head6])
4991
                issue_count = issue_count + 1;
4992
 
4993
         memissue[ head7 ] =    ~iqentry_stomp[head7] && iqentry_memready[ head7 ]              // addr and data are valid
4994
                                        // ... and no preceding instruction is ready to go
4995 49 robfinch
                                        && issue_count < `NUM_MEM
4996 48 robfinch
                                        //&& ~iqentry_memready[head0]
4997
                                        //&& ~iqentry_memready[head1] 
4998
                                        //&& ~iqentry_memready[head2] 
4999
                                        //&& ~iqentry_memready[head3] 
5000
                                        //&& ~iqentry_memready[head4] 
5001
                                        //&& ~iqentry_memready[head5] 
5002
                                        //&& ~iqentry_memready[head6] 
5003
                                        // ... and there is no address-overlap with any preceding instruction
5004 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
5005
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
5006
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
5007
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
5008
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
5009
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
5010
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
5011
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
5012
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
5013
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head4][AMSB:3] || iqentry_out[head4] || iqentry_done[head4])))
5014
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5]) || iqentry_done[head5]
5015
                                                || (iqentry_a1_v[head5] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head5][AMSB:3] || iqentry_out[head5] || iqentry_done[head5])))
5016
                                        && (!iqentry_mem[head6] || (iqentry_agen[head6] & iqentry_out[head6]) || iqentry_done[head6]
5017
                                                || (iqentry_a1_v[head6] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head6][AMSB:3] || iqentry_out[head6] || iqentry_done[head6])))
5018 48 robfinch
                                        && (iqentry_rl[head7] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
5019
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
5020
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
5021
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
5022
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
5023
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
5024
                                                                                 && (iqentry_done[head6] || !iqentry_v[head6] || !iqentry_mem[head6])
5025
                                                                                         : 1'b1)
5026
                                        // ... if a preivous op has the aquire bit set
5027
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
5028
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
5029
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5030
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5031
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
5032
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
5033
                                        && !(iqentry_aq[head6] && iqentry_v[head6])
5034
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5035 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5036
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5037 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5038
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5039
                                )
5040 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5041 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5042
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5043
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5044
                                )
5045 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
5046 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5047
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5048
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5049
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
5050
                                )
5051 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
5052 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5053
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5054
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5055
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5056
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
5057
                                )
5058 49 robfinch
                    && (!(iqentry_iv[head6] && iqentry_memsb[head6]) ||
5059 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5060
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5061
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5062
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5063
                                &&   (iqentry_done[head4] || !iqentry_v[head4])
5064
                                &&   (iqentry_done[head5] || !iqentry_v[head5]))
5065
                                )
5066 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5067
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5068 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5069
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5070
                                )
5071 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5072 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5073
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5074
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5075
                                )
5076 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
5077 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5078
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5079
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5080
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
5081
                                )
5082 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
5083 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5084
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5085
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5086
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5087
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
5088
                                )
5089 49 robfinch
                    && (!(iqentry_iv[head6] && iqentry_memdb[head6]) ||
5090 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5091
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5092
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5093
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5094
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4])
5095
                                && (!iqentry_mem[head5] || iqentry_done[head5] || !iqentry_v[head5]))
5096
                                )
5097
                                        // ... and, if it is a SW, there is no chance of it being undone
5098
                                        && (iqentry_load[head7] ||
5099
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5100
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5101
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5102
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5103
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
5104
                       && !(iqentry_fc[head5]||iqentry_canex[head5])
5105
                       && !(iqentry_fc[head6]||iqentry_canex[head6]));
5106
`endif
5107
end
5108
 
5109 49 robfinch
reg [2:0] wbptr;
5110
always @*
5111
begin
5112
        // Crashes sim
5113
//      wbptr <= `WB_DEPTH-1;
5114
//      if (wb_v==8'h0)
5115
//              wbptr <= 3'd0;
5116
//      else
5117
//      begin
5118
//              for (n = `WB_DEPTH-2; n >= 0; n = n - 1)
5119
//                      if (wb_v[n] && wbptr==`WB_DEPTH-1)
5120
//                              wbptr <= n + 1;
5121
//      end
5122
        if (wb_v[6])
5123
                wbptr <= 3'd7;
5124
        else if (wb_v[5])
5125
                wbptr <= 3'd6;
5126
        else if (wb_v[4])
5127
                wbptr <= 3'd5;
5128
        else if (wb_v[3])
5129
                wbptr <= 3'd4;
5130
        else if (wb_v[2])
5131
                wbptr <= 3'd3;
5132
        else if (wb_v[1])
5133
                wbptr <= 3'd2;
5134
        else if (wb_v[0])
5135
                wbptr <= 3'd1;
5136
        else
5137
                wbptr <= 3'd0;
5138
end
5139
 
5140 48 robfinch
// Stomp logic for branch miss.
5141
 
5142
FT64_stomp #(QENTRIES) ustmp1
5143
(
5144
        .branchmiss(branchmiss),
5145
        .branchmiss_thrd(branchmiss_thrd),
5146
        .missid(missid),
5147
        .head0(head0),
5148
        .thrd(iqentry_thrd),
5149
        .iqentry_v(iqentry_v),
5150
        .stomp(iqentry_stomp)
5151
);
5152
 
5153
always @*
5154
begin
5155 51 robfinch
        if (iqentry_stomp[0] && iqentry_ret[0])
5156 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5157 51 robfinch
        if (iqentry_stomp[1] && iqentry_ret[1])
5158 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5159 51 robfinch
        if (iqentry_stomp[2] && iqentry_ret[2])
5160 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5161 51 robfinch
        if (iqentry_stomp[3] && iqentry_ret[3])
5162 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5163 51 robfinch
        if (iqentry_stomp[4] && iqentry_ret[4])
5164 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5165 51 robfinch
        if (iqentry_stomp[5] && iqentry_ret[5])
5166 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5167 51 robfinch
        if (iqentry_stomp[6] && iqentry_ret[6])
5168 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5169 51 robfinch
        if (iqentry_stomp[7] && iqentry_ret[7])
5170 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5171 52 robfinch
        if (iqentry_stomp[8] && iqentry_ret[8])
5172
                stompedOnRets = stompedOnRets + 4'd1;
5173
        if (iqentry_stomp[9] && iqentry_ret[9])
5174
                stompedOnRets = stompedOnRets + 4'd1;
5175 48 robfinch
end
5176
 
5177 49 robfinch
reg id1_vi, id2_vi, id3_vi;
5178
wire [4:0] id1_ido, id2_ido, id3_ido;
5179
wire id1_vo, id2_vo, id3_vo;
5180
wire id1_clk, id2_clk, id3_clk;
5181 48 robfinch
 
5182 49 robfinch
// Always at least one decoder
5183 50 robfinch
assign id1_clk = clk_i;
5184
//BUFGCE uclkb2
5185
//(
5186
//      .I(clk_i),
5187
//      .CE(id1_available),
5188
//      .O(id1_clk)
5189
//);
5190 48 robfinch
 
5191
FT64_idecoder uid1
5192
(
5193
        .clk(id1_clk),
5194
        .idv_i(id1_vi),
5195
        .id_i(id1_id),
5196
        .instr(id1_instr),
5197
        .ven(id1_ven),
5198
        .vl(id1_vl),
5199
        .thrd(id1_thrd),
5200
        .predict_taken(id1_pt),
5201
        .Rt(id1_Rt),
5202
        .bus(id1_bus),
5203
        .id_o(id1_ido),
5204
        .idv_o(id1_vo)
5205
);
5206
 
5207 49 robfinch
generate begin : gIDUInst
5208
if (`NUM_IDU > 1) begin
5209 50 robfinch
//BUFGCE uclkb3
5210
//(
5211
//      .I(clk_i),
5212
//      .CE(id2_available),
5213
//      .O(id2_clk)
5214
//);
5215
assign id2_clk = clk_i;
5216 48 robfinch
 
5217
FT64_idecoder uid2
5218
(
5219
        .clk(id2_clk),
5220
        .idv_i(id2_vi),
5221
        .id_i(id2_id),
5222
        .instr(id2_instr),
5223
        .ven(id2_ven),
5224
        .vl(id2_vl),
5225
        .thrd(id2_thrd),
5226
        .predict_taken(id2_pt),
5227
        .Rt(id2_Rt),
5228
        .bus(id2_bus),
5229
        .id_o(id2_ido),
5230
        .idv_o(id2_vo)
5231
);
5232 49 robfinch
end
5233
if (`NUM_IDU > 2) begin
5234 50 robfinch
//BUFGCE uclkb4
5235
//(
5236
//      .I(clk_i),
5237
//      .CE(id3_available),
5238
//      .O(id3_clk)
5239
//);
5240
assign id3_clk = clk_i;
5241 48 robfinch
 
5242 49 robfinch
FT64_idecoder uid2
5243
(
5244
        .clk(id3_clk),
5245
        .idv_i(id3_vi),
5246
        .id_i(id3_id),
5247
        .instr(id3_instr),
5248
        .ven(id3_ven),
5249
        .vl(id3_vl),
5250
        .thrd(id3_thrd),
5251
        .predict_taken(id3_pt),
5252
        .Rt(id3_Rt),
5253
        .bus(id3_bus),
5254
        .id_o(id3_ido),
5255
        .idv_o(id3_vo)
5256
);
5257
end
5258
end
5259
endgenerate
5260
 
5261 48 robfinch
//
5262
// EXECUTE
5263
//
5264
reg [63:0] csr_r;
5265
always @*
5266
    read_csr(alu0_instr[29:18],csr_r,alu0_thrd);
5267
FT64_alu #(.BIG(1'b1),.SUP_VECTOR(SUP_VECTOR)) ualu0 (
5268
  .rst(rst),
5269
  .clk(clk),
5270
  .ld(alu0_ld),
5271
  .abort(1'b0),
5272
  .instr(alu0_instr),
5273
  .a(alu0_argA),
5274
  .b(alu0_argB),
5275
  .c(alu0_argC),
5276
  .pc(alu0_pc),
5277
//    .imm(alu0_argI),
5278
  .tgt(alu0_tgt),
5279
  .ven(alu0_ven),
5280
  .vm(vm[alu0_instr[25:23]]),
5281
  .sbl(sbl),
5282
  .sbu(sbu),
5283
  .csr(csr_r),
5284
  .o(alu0_bus),
5285
  .ob(alu0b_bus),
5286
  .done(alu0_done),
5287
  .idle(alu0_idle),
5288
  .excen(aec[4:0]),
5289
  .exc(alu0_exc),
5290
  .thrd(alu0_thrd),
5291
  .mem(alu0_mem),
5292
  .shift48(alu0_shft48)
5293
);
5294 49 robfinch
generate begin : gAluInst
5295
if (`NUM_ALU > 1) begin
5296 48 robfinch
FT64_alu #(.BIG(1'b0),.SUP_VECTOR(SUP_VECTOR)) ualu1 (
5297
  .rst(rst),
5298
  .clk(clk),
5299
  .ld(alu1_ld),
5300
  .abort(1'b0),
5301
  .instr(alu1_instr),
5302
  .a(alu1_argA),
5303
  .b(alu1_argB),
5304
  .c(alu1_argC),
5305
  .pc(alu1_pc),
5306
  //.imm(alu1_argI),
5307
  .tgt(alu1_tgt),
5308
  .ven(alu1_ven),
5309
  .vm(vm[alu1_instr[25:23]]),
5310
  .sbl(sbl),
5311
  .sbu(sbu),
5312
  .csr(64'd0),
5313
  .o(alu1_bus),
5314
  .ob(alu1b_bus),
5315
  .done(alu1_done),
5316
  .idle(alu1_idle),
5317
  .excen(aec[4:0]),
5318
  .exc(alu1_exc),
5319
  .thrd(1'b0),
5320
  .mem(alu1_mem),
5321
  .shift48(alu1_shft48)
5322
);
5323 49 robfinch
end
5324
end
5325
endgenerate
5326
 
5327
generate begin : gFPUInst
5328
if (`NUM_FPU > 0) begin
5329
wire fpu1_clk;
5330 50 robfinch
//BUFGCE ufpc1
5331
//(
5332
//      .I(clk_i),
5333
//      .CE(fpu1_available),
5334
//      .O(fpu1_clk)
5335
//);
5336
assign fpu1_clk = clk_i;
5337
 
5338 48 robfinch
fpUnit ufp1
5339
(
5340
  .rst(rst),
5341 49 robfinch
  .clk(fpu1_clk),
5342 48 robfinch
  .clk4x(clk4x),
5343
  .ce(1'b1),
5344 49 robfinch
  .ir(fpu1_instr),
5345
  .ld(fpu1_ld),
5346
  .a(fpu1_argA),
5347
  .b(fpu1_argB),
5348
  .imm(fpu1_argI),
5349
  .o(fpu1_bus),
5350 48 robfinch
  .csr_i(),
5351 52 robfinch
  .status(fpu1_status),
5352 48 robfinch
  .exception(),
5353 49 robfinch
  .done(fpu1_done)
5354 48 robfinch
);
5355 49 robfinch
end
5356
if (`NUM_FPU > 1) begin
5357
wire fpu2_clk;
5358 50 robfinch
//BUFGCE ufpc2
5359
//(
5360
//      .I(clk_i),
5361
//      .CE(fpu2_available),
5362
//      .O(fpu2_clk)
5363
//);
5364
assign fpu2_clk = clk_i;
5365 49 robfinch
fpUnit ufp1
5366
(
5367
  .rst(rst),
5368
  .clk(fpu2_clk),
5369
  .clk4x(clk4x),
5370
  .ce(1'b1),
5371
  .ir(fpu2_instr),
5372
  .ld(fpu2_ld),
5373
  .a(fpu2_argA),
5374
  .b(fpu2_argB),
5375
  .imm(fpu2_argI),
5376
  .o(fpu2_bus),
5377
  .csr_i(),
5378 52 robfinch
  .status(fpu2_status),
5379 49 robfinch
  .exception(),
5380
  .done(fpu2_done)
5381
);
5382
end
5383
end
5384
endgenerate
5385 48 robfinch
 
5386 52 robfinch
assign fpu1_exc = (fpu1_available) ?
5387
                                                                        ((|fpu1_status[15:0]) ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
5388
assign fpu2_exc = (fpu2_available) ?
5389
                                                                        ((|fpu2_status[15:0]) ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
5390 49 robfinch
 
5391 48 robfinch
assign  alu0_v = alu0_dataready,
5392
        alu1_v = alu1_dataready;
5393
assign  alu0_id = alu0_sourceid,
5394
            alu1_id = alu1_sourceid;
5395 49 robfinch
assign  fpu1_v = fpu1_dataready;
5396
assign  fpu1_id = fpu1_sourceid;
5397
assign  fpu2_v = fpu2_dataready;
5398
assign  fpu2_id = fpu2_sourceid;
5399 48 robfinch
 
5400
`ifdef SUPPORT_SMT
5401
wire [1:0] olm = ol[fcu_thrd];
5402
`else
5403
wire [1:0] olm = ol;
5404
`endif
5405
 
5406
assign  fcu_v = fcu_dataready;
5407
assign  fcu_id = fcu_sourceid;
5408
 
5409
wire [4:0] fcmpo;
5410
wire fnanx;
5411
fp_cmp_unit ufcmp1 (fcu_argA, fcu_argB, fcmpo, fnanx);
5412
 
5413
wire fcu_takb;
5414
 
5415
always @*
5416
begin
5417
    fcu_exc <= `FLT_NONE;
5418
    casez(fcu_instr[`INSTRUCTION_OP])
5419
    `CHK:   begin
5420
                if (fcu_instr[21])
5421
                    fcu_exc <= fcu_argA >= fcu_argB && fcu_argA < fcu_argC ? `FLT_NONE : `FLT_CHK;
5422
            end
5423
    `REX:
5424
        case(olm)
5425
        `OL_USER:   fcu_exc <= `FLT_PRIV;
5426
        default:    ;
5427
        endcase
5428
        endcase
5429
end
5430
 
5431
FT64_EvalBranch ube1
5432
(
5433
        .instr(fcu_instr),
5434
        .a(fcu_argA),
5435
        .b(fcu_argB),
5436
        .c(fcu_argC),
5437
        .takb(fcu_takb)
5438
);
5439
 
5440
FT64_FCU_Calc ufcuc1
5441
(
5442
        .ol(olm),
5443
        .instr(fcu_instr),
5444
        .tvec(tvec[fcu_instr[14:13]]),
5445
        .a(fcu_argA),
5446
        .i(fcu_argI),
5447
        .pc(fcu_pc),
5448
        .im(im),
5449
        .waitctr(waitctr),
5450
        .bus(fcu_bus)
5451
);
5452
 
5453
always @*
5454
begin
5455
case(fcu_instr[`INSTRUCTION_OP])
5456
`R2:    fcu_misspc = fcu_argB;  // RTI (we don't bother fully decoding this as it's the only R2)
5457
`RET:   fcu_misspc = fcu_argB;
5458
`REX:   fcu_misspc = fcu_bus;
5459
`BRK:   fcu_misspc = {tvec[0][31:8], 1'b0, olm, 5'h0};
5460
`JAL:   fcu_misspc = fcu_argA + fcu_argI;
5461
//`CHK: fcu_misspc = fcu_nextpc + fcu_argI;     // Handled as an instruction exception
5462
// Default: branch
5463
default:        fcu_misspc = fcu_takb ? fcu_nextpc + fcu_brdisp : fcu_nextpc;
5464
endcase
5465
fcu_misspc[0] = 1'b0;
5466
end
5467
 
5468
// To avoid false branch mispredicts the branch isn't evaluated until the
5469
// following instruction queues. The address of the next instruction is
5470
// looked at to see if the BTB predicted correctly.
5471
 
5472 51 robfinch
wire fcu_brk_miss = (fcu_brk || fcu_rti) && fcu_v;
5473
wire fcu_ret_miss = fcu_ret && fcu_v && (fcu_argB != iqentry_pc[nid]);
5474
wire fcu_jal_miss = fcu_jal && fcu_v && fcu_argA + fcu_argI != iqentry_pc[nid];
5475 48 robfinch
wire fcu_followed = iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]];
5476
always @*
5477
if (fcu_dataready) begin
5478
//      if (fcu_timeout[7])
5479
//              fcu_branchmiss = TRUE;
5480
        // Break and RTI switch register sets, and so are always treated as a branch miss in order to
5481
        // flush the pipeline. Hardware interrupts also stream break instructions so they need to 
5482
        // flushed from the queue so the interrupt is recognized only once.
5483
        // BRK and RTI are handled as excmiss types which are processed during the commit stage.
5484
//      else
5485
        if (fcu_brk_miss)
5486
                fcu_branchmiss = TRUE & ~fcu_clearbm;
5487
    // the following instruction is queued
5488
        else
5489
        if (fcu_followed) begin
5490
`ifdef SUPPORT_SMT
5491
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol[fcu_thrd]) && fcu_v)
5492
`else
5493
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol) && fcu_v)
5494
`endif
5495
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5496
                else if (fcu_ret_miss)
5497
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5498 52 robfinch
                else if (fcu_branch && fcu_v && (((fcu_takb && (fcu_misspc != iqentry_pc[nid])) ||
5499
                                            (~fcu_takb && (fcu_pc + fcu_insln != iqentry_pc[nid])))))// || iqentry_v[nid]))
5500 48 robfinch
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5501
                else if (fcu_jal_miss)
5502
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5503
                else if (fcu_instr[`INSTRUCTION_OP] == `CHK && ~fcu_takb && fcu_v)
5504
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5505
                else
5506
                    fcu_branchmiss = FALSE;
5507
        end
5508
        else begin
5509
                // Stuck at the head and can't finish because there's still an uncommitted instruction in the queue.
5510
                // -> cause a branch miss to clear the queue.
5511
                if (iqentry_v[nid] && !IsCall(fcu_instr) && !IsJmp(fcu_instr) && fcu_v)
5512
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5513
                else
5514
                /*
5515
                if (fcu_id==head0 && iqentry_v[idp1(head0)]) begin
5516
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
5517
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
5518
                        fcu_branchmiss = FALSE;
5519
                    else
5520
                                fcu_branchmiss = TRUE;
5521
                end
5522
                else if (fcu_id==head1 && iqentry_v[idp2(head1)]) begin
5523
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
5524
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
5525
                        fcu_branchmiss = FALSE;
5526
                    else
5527
                                fcu_branchmiss = TRUE;
5528
                end
5529
                else*/
5530
                        fcu_branchmiss = FALSE;
5531
        end
5532
end
5533
else
5534
        fcu_branchmiss = FALSE;
5535
 
5536
// Flow control ops don't issue until the next instruction queues.
5537
// The fcu_timeout tracks how long the flow control op has been in the "out" state.
5538
// It should never be that way more than a couple of cycles. Sometimes the fcu_wr pulse got missed
5539
// because the following instruction got stomped on during a branchmiss, hence iqentry_v isn't true.
5540
wire fcu_wr = (fcu_v && iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]]);//      // && iqentry_v[nid]
5541
//                                      && fcu_instr==iqentry_instr[fcu_id[`QBITS]]);// || fcu_timeout==8'h05;
5542
 
5543
FT64_RMW_alu urmwalu0 (rmw_instr, rmw_argA, rmw_argB, rmw_argC, rmw_res);
5544
 
5545
//assign fcu_done = IsWait(fcu_instr) ? ((waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]]) :
5546
//                                      fcu_v && iqentry_v[idp1(fcu_id)] && iqentry_sn[idp1(fcu_id)]==iqentry_sn[fcu_id[`QBITS]]+5'd1;
5547
 
5548
// An exception in a committing instruction takes precedence
5549
/*
5550
Too slow. Needs to be registered
5551
assign  branchmiss = excmiss|fcu_branchmiss,
5552
    misspc = excmiss ? excmisspc : fcu_misspc,
5553
    missid = excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
5554
assign branchmiss_thrd =  excmiss ? excthrd : fcu_thrd;
5555
*/
5556
 
5557
//
5558
// additional DRAM-enqueue logic
5559
 
5560
assign dram_avail = (dram0 == `DRAMSLOT_AVAIL || dram1 == `DRAMSLOT_AVAIL || dram2 == `DRAMSLOT_AVAIL);
5561
 
5562 53 robfinch
always @*
5563
for (n = 0; n < QENTRIES; n = n + 1)
5564
        iqentry_memopsvalid[n] <= (iqentry_mem[n] & iqentry_a2_v[n] & iqentry_agen[n]);
5565 48 robfinch
 
5566 53 robfinch
always @*
5567
for (n = 0; n < QENTRIES; n = n + 1)
5568
        iqentry_memready[n] <= (iqentry_v[n] & iqentry_memopsvalid[n] & ~iqentry_memissue[n] & ~iqentry_done[n] & ~iqentry_out[n] & ~iqentry_stomp[n]);
5569 48 robfinch
 
5570 50 robfinch
assign outstanding_stores = (dram0 && dram0_store) ||
5571
                            (dram1 && dram1_store) ||
5572
                            (dram2 && dram2_store);
5573 48 robfinch
 
5574
//
5575
// additional COMMIT logic
5576
//
5577
always @*
5578
begin
5579
    commit0_v <= ({iqentry_v[head0], iqentry_cmt[head0]} == 2'b11 && ~|panic);
5580
    commit0_id <= {iqentry_mem[head0], head0};  // if a memory op, it has a DRAM-bus id
5581
    commit0_tgt <= iqentry_tgt[head0];
5582
    commit0_we  <= iqentry_we[head0];
5583
    commit0_bus <= iqentry_res[head0];
5584 49 robfinch
    if (`NUM_CMT > 1) begin
5585
            commit1_v <= ({iqentry_v[head0], iqentry_cmt[head0]} != 2'b10
5586
                       && {iqentry_v[head1], iqentry_cmt[head1]} == 2'b11
5587
                       && ~|panic);
5588
            commit1_id <= {iqentry_mem[head1], head1};
5589
            commit1_tgt <= iqentry_tgt[head1];
5590
            commit1_we  <= iqentry_we[head1];
5591
            commit1_bus <= iqentry_res[head1];
5592 58 robfinch
            // Need to set commit1, and commit2 valid bits for the branch predictor.
5593
            if (`NUM_CMT > 2) begin
5594
                end
5595
                else begin
5596
                        commit2_v <= ({iqentry_v[head0], iqentry_cmt[head0]} != 2'b10
5597
                                                                 && {iqentry_v[head1], iqentry_cmt[head1]} != 2'b10
5598
                                                                 && {iqentry_v[head2], iqentry_br[head2], iqentry_cmt[head2]}==3'b111
5599
                               && iqentry_tgt[head2][4:0]==5'd0 && ~|panic);     // watch out for dbnz and ibne
5600
                        commit2_tgt <= 12'h000;
5601
                        commit2_we <= 8'h00;
5602
                end
5603 49 robfinch
        end
5604
        else begin
5605 58 robfinch
                commit1_v <= ({iqentry_v[head0], iqentry_cmt[head0]} != 2'b10
5606
                                                         && {iqentry_v[head1], iqentry_br[head1], iqentry_cmt[head1]}==3'b111
5607
                       && iqentry_tgt[head1][4:0]==5'd0 && ~|panic);     // watch out for dbnz and ibne
5608 49 robfinch
                commit1_tgt <= 12'h000;
5609
                commit1_we <= 8'h00;
5610 58 robfinch
                commit2_v <= ({iqentry_v[head0], iqentry_cmt[head0]} != 2'b10
5611
                                                         && {iqentry_v[head1], iqentry_cmt[head1]} != 2'b10
5612
                                                         && {iqentry_v[head2], iqentry_br[head2], iqentry_cmt[head2]}==3'b111
5613
                       && iqentry_tgt[head2][4:0]==5'd0 && ~|panic);     // watch out for dbnz and ibne
5614
                commit2_tgt <= 12'h000;
5615
                commit2_we <= 8'h00;
5616 49 robfinch
        end
5617 48 robfinch
end
5618
 
5619 58 robfinch
assign int_commit = (commit0_v && iqentry_irq[head0])
5620
                                                                         || (commit0_v && commit1_v && iqentry_irq[head1] && `NUM_CMT > 1)
5621
                                                                         || (commit0_v && commit1_v && commit2_v && iqentry_irq[head2] && `NUM_CMT > 2);
5622 48 robfinch
 
5623
// Detect if a given register will become valid during the current cycle.
5624
// We want a signal that is active during the current clock cycle for the read
5625
// through register file, which trims a cycle off register access for every
5626
// instruction. But two different kinds of assignment statements can't be
5627
// placed under the same always block, it's a bad practice and may not work.
5628
// So a signal is created here with it's own always block.
5629
reg [AREGS-1:0] regIsValid;
5630
always @*
5631
begin
5632
        for (n = 1; n < AREGS; n = n + 1)
5633
        begin
5634
                regIsValid[n] = rf_v[n];
5635
                if (branchmiss)
5636
               if (~livetarget[n]) begin
5637
                        if (branchmiss_thrd) begin
5638
                                if (n >= 128)
5639
                                        regIsValid[n] = `VAL;
5640
                        end
5641
                        else begin
5642
                                if (n < 128)
5643
                                        regIsValid[n] = `VAL;
5644
                        end
5645
               end
5646
                if (commit0_v && n=={commit0_tgt[7:0]})
5647
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit0_tgt[7:0]} ] == commit0_id
5648
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit0_id[`QBITS] ]));
5649 49 robfinch
                if (commit1_v && n=={commit1_tgt[7:0]} && `NUM_CMT > 1)
5650 48 robfinch
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit1_tgt[7:0]} ] == commit1_id
5651 58 robfinch
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit1_id[`QBITS]] && iqentry_source[ commit1_id[`QBITS] ]));
5652
                if (commit2_v && n=={commit2_tgt[7:0]} && `NUM_CMT > 2)
5653
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit2_tgt[7:0]} ] == commit2_id
5654
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit2_id[`QBITS]] && iqentry_source[ commit2_id[`QBITS] ]));
5655 48 robfinch
        end
5656
        regIsValid[0] = `VAL;
5657 55 robfinch
        regIsValid[32] = `VAL;
5658
        regIsValid[64] = `VAL;
5659
        regIsValid[128] = `VAL;
5660
`ifdef SMT
5661
        regIsValid[144] = `VAL;
5662
        regIsValid[160] = `VAL;
5663
        regIsValid[192] = `VAL;
5664
        regIsValid[224] = `VAL;
5665
`endif
5666 48 robfinch
end
5667
 
5668
// Wait until the cycle after Ra becomes valid to give time to read
5669
// the vector element from the register file.
5670
reg rf_vra0, rf_vra1;
5671
/*always @(posedge clk)
5672
    rf_vra0 <= regIsValid[Ra0s];
5673
always @(posedge clk)
5674
    rf_vra1 <= regIsValid[Ra1s];
5675
*/
5676
// Check how many instructions can be queued. This might be fewer than the
5677
// number ready to queue from the fetch stage if queue slots aren't
5678
// available or if there are no more physical registers left for remapping.
5679
// The fetch stage needs to know how many instructions will queue so this
5680
// logic is placed here.
5681
// NOPs are filtered out and do not enter the instruction queue. The core
5682
// will stream NOPs on a cache miss and they would mess up the queue order
5683
// if there are immediate prefixes in the queue.
5684
// For the VEX instruction, the instruction can't queue until register Ra
5685
// is valid, because register Ra is used to specify the vector element to
5686
// read.
5687
wire q2open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV;
5688
wire q3open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV && iqentry_v[idp1(tail1)]==`INV;
5689
always @*
5690
begin
5691
        canq1 <= FALSE;
5692
        canq2 <= FALSE;
5693
        queued1 <= FALSE;
5694
        queued2 <= FALSE;
5695
        queuedNop <= FALSE;
5696
        vqueued2 <= FALSE;
5697
        if (!branchmiss) begin
5698
      // Two available
5699
      if (fetchbuf1_v & fetchbuf0_v) begin
5700
          // Is there a pair of NOPs ? (cache miss)
5701
          if ((fetchbuf0_instr[`INSTRUCTION_OP]==`NOP) && (fetchbuf1_instr[`INSTRUCTION_OP]==`NOP))
5702
              queuedNop <= TRUE;
5703
          else begin
5704
              // If it's a predicted branch queue only the first instruction, the second
5705
              // instruction will be stomped on.
5706
              if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
5707
                  if (iqentry_v[tail0]==`INV) begin
5708
                      canq1 <= TRUE;
5709
                      queued1 <= TRUE;
5710
                  end
5711
              end
5712
              // This is where a single NOP is allowed through to simplify the code. A
5713
              // single NOP can't be a cache miss. Otherwise it would be necessary to queue
5714
              // fetchbuf1 on tail0 it would add a nightmare to the enqueue code.
5715
              // Not a branch and there are two instructions fetched, see whether or not
5716
              // both instructions can be queued.
5717
              else begin
5718
                  if (iqentry_v[tail0]==`INV) begin
5719
                      canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5720
                      queued1 <= (
5721
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5722
                      if (iqentry_v[tail1]==`INV) begin
5723
                          canq2 <= ((!IsVex(fetchbuf1_instr) || rf_vra1)) || !SUP_VECTOR;
5724
                          queued2 <= (
5725
                                (!IsVector(fetchbuf1_instr) && (!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5726
                          vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5727
                      end
5728
                  end
5729
                  // If an irq is active during a vector instruction fetch, claim the vector instruction
5730
                  // is finished queueing even though it may not be. It'll pick up where it left off after
5731
                  // the exception is processed.
5732 52 robfinch
                  if (freezePC) begin
5733 48 robfinch
                        if (IsVector(fetchbuf0_instr) && IsVector(fetchbuf1_instr) && vechain) begin
5734
                                queued1 <= TRUE;
5735
                                queued2 <= TRUE;
5736
                        end
5737
                        else if (IsVector(fetchbuf0_instr)) begin
5738
                                queued1 <= TRUE;
5739
                                if (vqe0 < vl-2)
5740
                                        queued2 <= TRUE;
5741
                                else
5742
                                        queued2 <= iqentry_v[tail1]==`INV;
5743
                        end
5744
                  end
5745
              end
5746
          end
5747
      end
5748
      // One available
5749
      else if (fetchbuf0_v) begin
5750
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
5751
              if (iqentry_v[tail0]==`INV) begin
5752
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5753
                  queued1 <=
5754
                        (((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5755
              end
5756
              if (iqentry_v[tail1]==`INV) begin
5757
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
5758
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5759
                end
5760 52 robfinch
                if (freezePC) begin
5761 48 robfinch
                if (IsVector(fetchbuf0_instr)) begin
5762
                        queued1 <= TRUE;
5763
                        if (vqe0 < vl-2)
5764
                                queued2 <= iqentry_v[tail1]==`INV;
5765
                end
5766
                end
5767
          end
5768
          else
5769
              queuedNop <= TRUE;
5770
      end
5771
      else if (fetchbuf1_v) begin
5772
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
5773
              if (iqentry_v[tail0]==`INV) begin
5774
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
5775
                  queued1 <= (
5776
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
5777
              end
5778
              if (iqentry_v[tail1]==`INV) begin
5779
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
5780
                  vqueued2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2;
5781
                end
5782 52 robfinch
                if (freezePC) begin
5783 48 robfinch
                if (IsVector(fetchbuf1_instr)) begin
5784
                        queued1 <= TRUE;
5785
                        if (vqe1 < vl-2)
5786
                                queued2 <= iqentry_v[tail1]==`INV;
5787
                end
5788
                end
5789
          end
5790
          else
5791
              queuedNop <= TRUE;
5792
      end
5793
      //else no instructions available to queue
5794
    end
5795
    else begin
5796
      // One available
5797
      if (fetchbuf0_v && fetchbuf0_thrd != branchmiss_thrd) begin
5798
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
5799
              if (iqentry_v[tail0]==`INV) begin
5800
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5801
                  queued1 <= (
5802
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5803
              end
5804
              if (iqentry_v[tail1]==`INV) begin
5805
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
5806
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5807
                end
5808
          end
5809
          else
5810
              queuedNop <= TRUE;
5811
      end
5812
      else if (fetchbuf1_v && fetchbuf1_thrd != branchmiss_thrd) begin
5813
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
5814
              if (iqentry_v[tail0]==`INV) begin
5815
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
5816
                  queued1 <= (
5817
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
5818
              end
5819
              if (iqentry_v[tail1]==`INV) begin
5820
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
5821
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5822
                end
5823
          end
5824
          else
5825
              queuedNop <= TRUE;
5826
      end
5827
        else
5828
                queuedNop <= TRUE;
5829
    end
5830
end
5831
 
5832
//
5833
// Branchmiss seems to be sticky sometimes during simulation. For instance branch miss
5834
// and cache miss at same time. The branchmiss should clear before the core continues
5835
// so the positive edge is detected to avoid incrementing the sequnce number too many
5836
// times.
5837
wire pebm;
5838
edge_det uedbm (.rst(rst), .clk(clk), .ce(1'b1), .i(branchmiss), .pe(pebm), .ne(), .ee() );
5839
 
5840
reg [5:0] ld_time;
5841
reg [63:0] wc_time_dat;
5842
reg [63:0] wc_times;
5843
always @(posedge tm_clk_i)
5844
begin
5845
        if (|ld_time)
5846
                wc_time <= wc_time_dat;
5847
        else begin
5848
                wc_time[31:0] <= wc_time[31:0] + 32'd1;
5849
                if (wc_time[31:0] >= TM_CLKFREQ-1) begin
5850
                        wc_time[31:0] <= 32'd0;
5851
                        wc_time[63:32] <= wc_time[63:32] + 32'd1;
5852
                end
5853
        end
5854
end
5855
 
5856
 
5857
// Monster clock domain.
5858
// Like to move some of this to clocking under different always blocks in order
5859
// to help out the toolset's synthesis, but it ain't gonna be easy.
5860
// Simulation doesn't like it if things are under separate always blocks.
5861
// Synthesis doesn't like it if things are under the same always block.
5862
 
5863 49 robfinch
//always @(posedge clk)
5864
//begin
5865
//      branchmiss <= excmiss|fcu_branchmiss;
5866
//    misspc <= excmiss ? excmisspc : fcu_misspc;
5867
//    missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
5868
//      branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
5869
//end
5870 48 robfinch
 
5871
always @(posedge clk)
5872
if (rst) begin
5873
`ifdef SUPPORT_SMT
5874 55 robfinch
     mstatus[0] <= 64'h000F;     // select register set #0 for thread 0
5875
     mstatus[1] <= 64'h800F;    // select register set #2 for thread 1
5876 48 robfinch
`else
5877 55 robfinch
     mstatus <= 64'h000F;       // select register set #0 for thread 0
5878 48 robfinch
`endif
5879
    for (n = 0; n < QENTRIES; n = n + 1) begin
5880 51 robfinch
       iqentry_v[n] <= `INV;
5881
       iqentry_iv[n] <= `INV;
5882
       iqentry_is[n] <= 3'b00;
5883
       iqentry_done[n] <= FALSE;
5884
       iqentry_cmt[n] <= FALSE;
5885
       iqentry_out[n] <= FALSE;
5886
       iqentry_agen[n] <= FALSE;
5887
       iqentry_sn[n] <= 32'd0;
5888
       iqentry_pt[n] <= FALSE;
5889
       iqentry_bt[n] <= FALSE;
5890
       iqentry_br[n] <= FALSE;
5891
       iqentry_aq[n] <= FALSE;
5892
       iqentry_rl[n] <= FALSE;
5893
       iqentry_alu0[n] <= FALSE;
5894
       iqentry_alu[n] <= FALSE;
5895
       iqentry_alu0_issue[n] <= FALSE;
5896
       iqentry_alu1_issue[n] <= FALSE;
5897
       iqentry_fpu[n] <= FALSE;
5898
       iqentry_fpu1_issue[n] <= FALSE;
5899
       iqentry_fpu2_issue[n] <= FALSE;
5900
       iqentry_fsync[n] <= FALSE;
5901
       iqentry_fc[n] <= FALSE;
5902
       iqentry_fcu_issue[n] <= FALSE;
5903 52 robfinch
       iqentry_takb[n] <= FALSE;
5904 51 robfinch
       iqentry_jmp[n] <= FALSE;
5905
       iqentry_jal[n] <= FALSE;
5906
       iqentry_ret[n] <= FALSE;
5907
       iqentry_brk[n] <= FALSE;
5908
       iqentry_irq[n] <= FALSE;
5909
       iqentry_rti[n] <= FALSE;
5910
       iqentry_ldcmp[n] <= FALSE;
5911
       iqentry_load[n] <= FALSE;
5912
       iqentry_rtop[n] <= FALSE;
5913
       iqentry_sei[n] <= FALSE;
5914
       iqentry_shft48[n] <= FALSE;
5915
       iqentry_sync[n] <= FALSE;
5916
       iqentry_ven[n] <= 6'd0;
5917
       iqentry_vl[n] <= 8'd0;
5918
       iqentry_we[n] <= 8'h00;
5919
       iqentry_rfw[n] <= FALSE;
5920
       iqentry_rmw[n] <= FALSE;
5921
       iqentry_pc[n] <= RSTPC;
5922 48 robfinch
         iqentry_instr[n] <= `NOP_INSN;
5923 56 robfinch
         iqentry_insln[n] <= 3'd4;
5924 48 robfinch
         iqentry_preload[n] <= FALSE;
5925
         iqentry_mem[n] <= FALSE;
5926
         iqentry_memndx[n] <= FALSE;
5927 51 robfinch
       iqentry_memissue[n] <= FALSE;
5928
       iqentry_mem_islot[n] <= 3'd0;
5929
       iqentry_memdb[n] <= FALSE;
5930
       iqentry_memsb[n] <= FALSE;
5931
       iqentry_tgt[n] <= 6'd0;
5932
       iqentry_imm[n] <= 1'b0;
5933
       iqentry_a0[n] <= 64'd0;
5934
       iqentry_a1[n] <= 64'd0;
5935
       iqentry_a2[n] <= 64'd0;
5936
       iqentry_a3[n] <= 64'd0;
5937
       iqentry_a1_v[n] <= `INV;
5938
       iqentry_a2_v[n] <= `INV;
5939
       iqentry_a3_v[n] <= `INV;
5940
       iqentry_a1_s[n] <= 5'd0;
5941
       iqentry_a2_s[n] <= 5'd0;
5942
       iqentry_a3_s[n] <= 5'd0;
5943
       iqentry_canex[n] <= FALSE;
5944 48 robfinch
    end
5945 49 robfinch
     bwhich <= 2'b00;
5946 48 robfinch
     dram0 <= `DRAMSLOT_AVAIL;
5947
     dram1 <= `DRAMSLOT_AVAIL;
5948
     dram2 <= `DRAMSLOT_AVAIL;
5949
     dram0_instr <= `NOP_INSN;
5950
     dram1_instr <= `NOP_INSN;
5951
     dram2_instr <= `NOP_INSN;
5952
     dram0_addr <= 32'h0;
5953
     dram1_addr <= 32'h0;
5954
     dram2_addr <= 32'h0;
5955
     L1_adr <= RSTPC;
5956
     invic <= FALSE;
5957
     tail0 <= 3'd0;
5958
     tail1 <= 3'd1;
5959
     head0 <= 0;
5960
     head1 <= 1;
5961
     head2 <= 2;
5962
     head3 <= 3;
5963
     head4 <= 4;
5964
     head5 <= 5;
5965
     head6 <= 6;
5966
     head7 <= 7;
5967 52 robfinch
     head8 <= 8;
5968
     head9 <= 9;
5969 48 robfinch
     panic = `PANIC_NONE;
5970
     alu0_dataready <= 0;
5971
     alu1_dataready <= 0;
5972
     alu0_sourceid <= 5'd0;
5973
     alu1_sourceid <= 5'd0;
5974
`ifdef SIM
5975
                alu0_pc <= RSTPC;
5976
                alu0_instr <= `NOP_INSN;
5977
                alu0_argA <= 64'h0;
5978
                alu0_argB <= 64'h0;
5979
                alu0_argC <= 64'h0;
5980
                alu0_argI <= 64'h0;
5981
                alu0_bt <= 1'b0;
5982
                alu0_mem <= 1'b0;
5983
                alu0_shft48 <= 1'b0;
5984
                alu0_thrd <= 1'b0;
5985
                alu0_tgt <= 6'h00;
5986
                alu0_ven <= 6'd0;
5987
                alu1_pc <= RSTPC;
5988
                alu1_instr <= `NOP_INSN;
5989
                alu1_argA <= 64'h0;
5990
                alu1_argB <= 64'h0;
5991
                alu1_argC <= 64'h0;
5992
                alu1_argI <= 64'h0;
5993
                alu1_bt <= 1'b0;
5994
                alu1_mem <= 1'b0;
5995
                alu1_shft48 <= 1'b0;
5996
                alu1_thrd <= 1'b0;
5997
                alu1_tgt <= 6'h00;
5998
                alu1_ven <= 6'd0;
5999
`endif
6000
     fcu_dataready <= 0;
6001
     fcu_instr <= `NOP_INSN;
6002
     dramA_v <= 0;
6003
     dramB_v <= 0;
6004
     dramC_v <= 0;
6005
     I <= 0;
6006 58 robfinch
     CC <= 0;
6007 48 robfinch
     icstate <= IDLE;
6008
     bstate <= BIDLE;
6009
     tick <= 64'd0;
6010
     bte_o <= 2'b00;
6011
     cti_o <= 3'b000;
6012
     cyc_o <= `LOW;
6013
     stb_o <= `LOW;
6014
     we_o <= `LOW;
6015
     sel_o <= 8'h00;
6016
     sr_o <= `LOW;
6017
     cr_o <= `LOW;
6018
     adr_o <= RSTPC;
6019
     icl_o <= `LOW;             // instruction cache load
6020
     cr0 <= 64'd0;
6021 55 robfinch
     cr0[13:8] <= 6'd0;         // select compressed instruction group #0
6022 48 robfinch
     cr0[30] <= TRUE;           // enable data caching
6023
     cr0[32] <= TRUE;           // enable branch predictor
6024
     cr0[16] <= 1'b0;           // disable SMT
6025
     cr0[17] <= 1'b0;           // sequence number reset = 1
6026 52 robfinch
     cr0[34] <= FALSE;  // write buffer merging enable
6027 48 robfinch
     pcr <= 32'd0;
6028
     pcr2 <= 64'd0;
6029
    for (n = 0; n < PREGS; n = n + 1)
6030
         rf_v[n] <= `VAL;
6031 51 robfinch
     fp_rm <= 3'd0;                     // round nearest even - default rounding mode
6032
     fpu_csr[37:32] <= 5'd31;   // register set #31
6033 48 robfinch
     waitctr <= 64'd0;
6034
    for (n = 0; n < 16; n = n + 1)
6035
         badaddr[n] <= 64'd0;
6036
     sbl <= 32'h0;
6037
     sbu <= 32'hFFFFFFFF;
6038
    // Vector
6039
     vqe0 <= 6'd0;
6040
     vqet0 <= 6'd0;
6041
     vqe1 <= 6'd0;
6042
     vqet1 <= 6'd0;
6043
     vl <= 7'd62;
6044
    for (n = 0; n < 8; n = n + 1)
6045
         vm[n] <= 64'h7FFFFFFFFFFFFFFF;
6046
     nop_fetchbuf <= 4'h0;
6047
     seq_num <= 5'd0;
6048
     seq_num1 <= 5'd0;
6049
     fcu_done <= `TRUE;
6050
     sema <= 64'h0;
6051
     tvec[0] <= RSTPC;
6052 49 robfinch
     pmr <= 64'hFFFFFFFFFFFFFFFF;
6053
     pmr[0] <= `ID1_AVAIL;
6054
     pmr[1] <= `ID2_AVAIL;
6055
     pmr[2] <= `ID3_AVAIL;
6056
     pmr[8] <= `ALU0_AVAIL;
6057
     pmr[9] <= `ALU1_AVAIL;
6058
     pmr[16] <= `FPU1_AVAIL;
6059
     pmr[17] <= `FPU2_AVAIL;
6060
     pmr[24] <= `MEM1_AVAIL;
6061
     pmr[25] <= `MEM2_AVAIL;
6062
                 pmr[26] <= `MEM3_AVAIL;
6063
     pmr[32] <= `FCU_AVAIL;
6064
     for (n = 0; n < `WB_DEPTH; n = n + 1) begin
6065
        wb_v[n] <= 1'b0;
6066
        wb_rmw[n] <= 1'b0;
6067
        wb_id[n] <= {QENTRIES{1'b0}};
6068
     end
6069
     wb_en <= `TRUE;
6070
     wbo_id <= {QENTRIES{1'b0}};
6071
`ifdef SIM
6072
                wb_merges <= 32'd0;
6073
`endif
6074 48 robfinch
end
6075
else begin
6076 49 robfinch
        if (|fb_panic)
6077
                panic <= fb_panic;
6078
        begin
6079
                branchmiss <= excmiss|fcu_branchmiss;
6080 51 robfinch
                misspc <= excmiss ? excmisspc : fcu_misspc;
6081
                missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
6082 49 robfinch
                branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
6083
        end
6084 48 robfinch
        // The following signals only pulse
6085
 
6086
        // Instruction decode output should only pulse once for a queue entry. We
6087
        // want the decode to be invalidated after a clock cycle so that it isn't
6088
        // inadvertently used to update the queue at a later point.
6089 57 robfinch
        dramA_v <= `INV;
6090
        dramB_v <= `INV;
6091
        dramC_v <= `INV;
6092 48 robfinch
        id1_vi <= `INV;
6093 49 robfinch
        if (`NUM_IDU > 1)
6094
                id2_vi <= `INV;
6095
        if (`NUM_IDU > 2)
6096
                id3_vi <= `INV;
6097
        if (iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]])
6098
                fcu_dataready <= `INV;
6099 52 robfinch
        wb_shift <= FALSE;
6100 48 robfinch
        ld_time <= {ld_time[4:0],1'b0};
6101
        wc_times <= wc_time;
6102
     rf_vra0 <= regIsValid[Ra0s];
6103
     rf_vra1 <= regIsValid[Ra1s];
6104
    if (vqe0 >= vl) begin
6105
         vqe0 <= 6'd0;
6106
         vqet0 <= 6'h0;
6107
    end
6108
    if (vqe1 >= vl) begin
6109
         vqe1 <= 6'd0;
6110
         vqet1 <= 6'h0;
6111
    end
6112
    // Turn off vector chaining indicator when chained instructions are done.
6113
    if ((vqe0 >= vl || vqe0==6'd0) && (vqe1 >= vl || vqe1==6'd0))
6114
`ifdef SUPPORT_SMT
6115
        mstatus[0][32] <= 1'b0;
6116
`else
6117
        mstatus[32] <= 1'b0;
6118
`endif
6119
 
6120
     nop_fetchbuf <= 4'h0;
6121
     excmiss <= FALSE;
6122
     invic <= FALSE;
6123
     tick <= tick + 64'd1;
6124
     alu0_ld <= FALSE;
6125
     alu1_ld <= FALSE;
6126 49 robfinch
     fpu1_ld <= FALSE;
6127
     fpu2_ld <= FALSE;
6128 48 robfinch
     fcu_ld <= FALSE;
6129
     dramA_v <= FALSE;
6130
     dramB_v <= FALSE;
6131
     dramC_v <= FALSE;
6132
     cr0[17] <= 1'b0;
6133
    if (waitctr != 64'd0)
6134
         waitctr <= waitctr - 64'd1;
6135
 
6136
 
6137 50 robfinch
    if (iqentry_fc[fcu_id[`QBITS]] && iqentry_v[fcu_id[`QBITS]] && !iqentry_done[fcu_id[`QBITS]] && iqentry_out[fcu_id[`QBITS]])
6138 48 robfinch
        fcu_timeout <= fcu_timeout + 8'd1;
6139
 
6140
        if (branchmiss) begin
6141
        for (n = 1; n < PREGS; n = n + 1)
6142
           if (~livetarget[n]) begin
6143
                        if (branchmiss_thrd) begin
6144
                                if (n >= 128)
6145
                                rf_v[n] <= `VAL;
6146
                        end
6147
                        else begin
6148
                                if (n < 128)
6149
                                rf_v[n] <= `VAL;
6150
                end
6151
           end
6152
 
6153 53 robfinch
                        for (n = 0; n < QENTRIES; n = n + 1)
6154
                if (|iqentry_latestID[n])
6155
                        if (iqentry_thrd[n]==branchmiss_thrd) rf_source[ {iqentry_tgt[n][7:0]} ] <= { 1'b0, iqentry_mem[n], n[3:0] };
6156 48 robfinch
 
6157
    end
6158
 
6159
    // The source for the register file data might have changed since it was
6160
    // placed on the commit bus. So it's needed to check that the source is
6161
    // still as expected to validate the register.
6162
        if (commit0_v) begin
6163
        if (!rf_v[ {commit0_tgt[7:0]} ])
6164
//             rf_v[ {commit0_tgt[7:0]} ] <= rf_source[ commit0_tgt[7:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]);
6165
             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] ]);
6166
        if (commit0_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit0_tgt, commit0_bus, regIsValid[commit0_tgt[5:0]],
6167
        rf_source[ {commit0_tgt[7:0]} ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]));
6168
        if (commit0_tgt[5:0]==6'd30 && commit0_bus==64'd0)
6169
                $display("FP <= 0");
6170
    end
6171 49 robfinch
    if (commit1_v && `NUM_CMT > 1) begin
6172 48 robfinch
        if (!rf_v[ {commit1_tgt[7:0]} ]) begin
6173
                if ({commit1_tgt[7:0]}=={commit0_tgt[7:0]})
6174
                         rf_v[ {commit1_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}];
6175
                        /*
6176
                                (rf_source[ commit0_tgt[4:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ])) ||
6177
                                (rf_source[ commit1_tgt[4:0] ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6178
                        */
6179
                else
6180
                 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] ]);
6181
        end
6182
        if (commit1_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit1_tgt, commit1_bus, regIsValid[commit1_tgt[5:0]],
6183
        rf_source[ {commit1_tgt[7:0]} ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6184
        if (commit1_tgt[5:0]==6'd30 && commit1_bus==64'd0)
6185
                $display("FP <= 0");
6186
    end
6187 58 robfinch
    if (commit2_v && `NUM_CMT > 2) begin
6188
      if (!rf_v[ {commit2_tgt[7:0]} ]) begin
6189
        if ({commit2_tgt[7:0]}=={commit1_tgt[7:0]} && {commit2_tgt[7:0]}=={commit0_tgt[7:0]})
6190
                 rf_v[ {commit2_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}];
6191
        else if ({commit2_tgt[7:0]}=={commit0_tgt[7:0]})
6192
                 rf_v[ {commit2_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}];
6193
        else if ({commit2_tgt[7:0]}=={commit1_tgt[7:0]})
6194
                 rf_v[ {commit2_tgt[7:0]} ] <= regIsValid[{commit1_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}];
6195
        else
6196
                 rf_v[ {commit2_tgt[7:0]} ] <= regIsValid[{commit2_tgt[7:0]}];//rf_source[ commit1_tgt[4:0] ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]);
6197
      end
6198
      if (commit2_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit2_tgt, commit2_bus, regIsValid[commit2_tgt[5:0]],
6199
      rf_source[ {commit2_tgt[7:0]} ] == commit2_id || (branchmiss && iqentry_source[ commit2_id[`QBITS] ]));
6200
      if (commit2_tgt[5:0]==6'd30 && commit2_bus==64'd0)
6201
        $display("FP <= 0");
6202
    end
6203 48 robfinch
     rf_v[0] <= 1;
6204
 
6205 49 robfinch
  //
6206
  // ENQUEUE
6207
  //
6208
  // place up to two instructions from the fetch buffer into slots in the IQ.
6209
  //   note: they are placed in-order, and they are expected to be executed
6210
  // 0, 1, or 2 of the fetch buffers may have valid data
6211
  // 0, 1, or 2 slots in the instruction queue may be available.
6212
  // if we notice that one of the instructions in the fetch buffer is a predicted branch,
6213
  // (set branchback/backpc and delete any instructions after it in fetchbuf)
6214
  //
6215 48 robfinch
 
6216
        // enqueue fetchbuf0 and fetchbuf1, but only if there is room, 
6217
        // and ignore fetchbuf1 if fetchbuf0 has a backwards branch in it.
6218
        //
6219
        // also, do some instruction-decode ... set the operand_valid bits in the IQ
6220
        // appropriately so that the DATAINCOMING stage does not have to look at the opcode
6221
        //
6222
        if (!branchmiss)        // don't bother doing anything if there's been a branch miss
6223
 
6224
                case ({fetchbuf0_v, fetchbuf1_v})
6225
 
6226
            2'b00: ; // do nothing
6227
 
6228
            2'b01:
6229
                    if (canq1) begin
6230 56 robfinch
          if (fetchbuf1_thrd)
6231
                seq_num1 <= seq_num1 + 5'd1;
6232
          else
6233
                seq_num <= seq_num + 5'd1;
6234
                                        if (fetchbuf1_rfw) begin
6235
                                                rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail0 };  // top bit indicates ALU/MEM bus
6236
                                                rf_v [Rt1s] <= `INV;
6237
                                        end
6238
                                        if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6239
                                                vqe1 <= vqe1 + 4'd1;
6240
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6241
                                                        if (vm[fetchbuf1_instr[25:23]][vqe1])
6242
                                                                vqet1 <= vqet1 + 4'd1;
6243
                                                end
6244
                                                else
6245
                                                        vqet1 <= vqet1 + 4'd1;
6246
                                                if (vqe1 >= vl-2)
6247
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6248
                                                enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, vqe1);
6249
                                                if (canq2 && vqe1 < vl-2) begin
6250
                                                        vqe1 <= vqe1 + 4'd2;
6251
                                                        if (IsVCmprss(fetchbuf1_instr)) begin
6252
                                                                if (vm[fetchbuf1_instr[25:23]][vqe1+6'd1])
6253
                                                                        vqet1 <= vqet1 + 4'd2;
6254
                                                        end
6255
                                                        else
6256
                                                                vqet1 <= vqet1 + 4'd2;
6257
                                                        enque1(tail1, fetchbuf1_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe1 + 6'd1);
6258
                                                        // Override the earlier udpate
6259
                                                        if (fetchbuf1_thrd)
6260
                                                                seq_num1 <= seq_num1 + 5'd2;
6261
                                                        else
6262
                                                                seq_num <= seq_num + 5'd2;
6263
                                                end
6264
                                        end
6265
                                        else begin
6266
                                                enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, 6'd0);
6267
                                        end
6268 48 robfinch
                    end
6269
 
6270
            2'b10:
6271
                if (canq1) begin
6272 55 robfinch
                        enque0x();
6273 48 robfinch
                    end
6274
 
6275
            2'b11:
6276
                    if (canq1) begin
6277
                                //
6278
                                // if the first instruction is a predicted branch, enqueue it & stomp on all following instructions
6279
                                // but only if the following instruction is in the same thread. Otherwise we want to queue two.
6280
                                //
6281
                                if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
6282 55 robfinch
                                        enque0x();
6283 48 robfinch
                                end
6284
 
6285
                                else begin      // fetchbuf0 doesn't contain a predicted branch
6286
                                    //
6287
                                    // so -- we can enqueue 1 or 2 instructions, depending on space in the IQ
6288
                                    // update the rf_v and rf_source bits separately (at end)
6289
                                    //   the problem is that if we do have two instructions, 
6290
                                    //   they may interact with each other, so we have to be
6291
                                    //   careful about where things point.
6292
                                    //
6293
                                    // enqueue the first instruction ...
6294
                                    //
6295
                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
6296
                                 vqe0 <= vqe0 + 4'd1;
6297
                                if (IsVCmprss(fetchbuf0_instr)) begin
6298
                                    if (vm[fetchbuf0_instr[25:23]][vqe0])
6299
                                         vqet0 <= vqet0 + 4'd1;
6300
                                end
6301
                                else
6302
                                     vqet0 <= vqet0 + 4'd1;
6303
                                if (vqe0 >= vl-2)
6304
                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6305
                            end
6306
                            if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
6307
                                    enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
6308
                                        if (fetchbuf0_thrd)
6309
                                                seq_num1 <= seq_num1 + 5'd1;
6310
                                        else
6311
                                                seq_num <= seq_num + 5'd1;
6312
                                            //
6313
                                            // if there is room for a second instruction, enqueue it
6314
                                            //
6315
                                            if (canq2) begin
6316
                                                if (vechain && IsVector(fetchbuf1_instr)
6317
                                                && Ra1s != Rt0s // And there is no dependency
6318
                                                && Rb1s != Rt0s
6319
                                                && Rc1s != Rt0s
6320
                                                ) begin
6321
`ifdef SUPPORT_SMT
6322
                                                        mstatus[0][32] <= 1'b1;
6323
`else
6324
                                                        mstatus[32] <= 1'b1;
6325
`endif
6326
                                                vqe1 <= vqe1 + 4'd1;
6327
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6328
                                                    if (vm[fetchbuf1_instr[25:23]][vqe1])
6329
                                                         vqet1 <= vqet1 + 4'd1;
6330
                                                end
6331
                                                else
6332
                                                     vqet1 <= vqet1 + 4'd1;
6333
                                                if (vqe1 >= vl-2)
6334
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6335
                                                        enque1(tail1,
6336
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6337
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6338
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
6339
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6340
                                                                if (fetchbuf1_thrd)
6341
                                                                        seq_num1 <= seq_num1 + 5'd2;
6342
                                                                else
6343
                                                                        seq_num <= seq_num + 5'd2;
6344
                                                        end
6345
                                                        else begin
6346
                                                                if (fetchbuf1_thrd)
6347
                                                                        seq_num1 <= seq_num1 + 5'd1;
6348
                                                                else
6349
                                                                        seq_num <= seq_num + 5'd1;
6350
                                                        end
6351
 
6352
                                                                // SOURCE 1 ...
6353 55 robfinch
                                                                a1_vs();
6354 48 robfinch
 
6355
                                                                // SOURCE 2 ...
6356 55 robfinch
                                                                a2_vs();
6357 48 robfinch
 
6358
                                                                // SOURCE 3 ...
6359 55 robfinch
                                                                a3_vs();
6360 48 robfinch
 
6361
                                                                // if the two instructions enqueued target the same register, 
6362
                                                                // make sure only the second writes to rf_v and rf_source.
6363
                                                                // first is allowed to update rf_v and rf_source only if the
6364
                                                                // second has no target
6365
                                                                //
6366
                                                            if (fetchbuf0_rfw) begin
6367
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6368
                                                                     rf_v [ Rt0s] <= `INV;
6369
                                                            end
6370
                                                            if (fetchbuf1_rfw) begin
6371
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6372
                                                                     rf_v [ Rt1s ] <= `INV;
6373
                                                            end
6374
                                                end
6375
                                                // If there was a vector instruction in fetchbuf0, we really
6376
                                                // want to queue the next vector element, not the next
6377
                                                // instruction waiting in fetchbuf1.
6378
                                            else if (IsVector(fetchbuf0_instr) && SUP_VECTOR && vqe0 < vl-1) begin
6379
                                                 vqe0 <= vqe0 + 4'd2;
6380
                                                if (IsVCmprss(fetchbuf0_instr)) begin
6381
                                                    if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
6382
                                                         vqet0 <= vqet0 + 4'd2;
6383
                                                end
6384
                                                else
6385
                                                     vqet0 <= vqet0 + 4'd2;
6386
                                                if (vqe0 >= vl-3)
6387
                                                 nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6388
                                            if (vqe0 < vl-1) begin
6389
                                                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe0 + 6'd1);
6390
                                                                if (fetchbuf0_thrd)
6391
                                                                        seq_num1 <= seq_num1 + 5'd2;
6392
                                                                else
6393
                                                                        seq_num <= seq_num + 5'd2;
6394
 
6395
                                                                        // SOURCE 1 ...
6396
                                                     iqentry_a1_v [tail1] <= regIsValid[Ra0s];
6397
                                                     iqentry_a1_s [tail1] <= rf_source [Ra0s];
6398
 
6399
                                                                        // SOURCE 2 ...
6400
                                                     iqentry_a2_v [tail1] <= regIsValid[Rb0s];
6401
                                                     iqentry_a2_s [tail1] <= rf_source[ Rb0s ];
6402
 
6403
                                                                        // SOURCE 3 ...
6404
                                                     iqentry_a3_v [tail1] <= regIsValid[Rc0s];
6405
                                                     iqentry_a3_s [tail1] <= rf_source[ Rc0s ];
6406
 
6407
                                                                        // if the two instructions enqueued target the same register, 
6408
                                                                        // make sure only the second writes to rf_v and rf_source.
6409
                                                                        // first is allowed to update rf_v and rf_source only if the
6410
                                                                        // second has no target (BEQ or SW)
6411
                                                                        //
6412
                                                                    if (fetchbuf0_rfw) begin
6413
                                                                             rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };
6414
                                                                             rf_v [ Rt0s ] <= `INV;
6415
                                                                    end
6416
                                                                end
6417
                                                end
6418
                                            else if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6419
                                                 vqe1 <= 6'd1;
6420
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6421
                                                    if (vm[fetchbuf1_instr[25:23]][IsVector(fetchbuf0_instr)? 6'd0:vqe1+6'd1])
6422
                                                         vqet1 <= 6'd1;
6423
                                                else
6424
                                                         vqet1 <= 6'd0;
6425
                                                end
6426
                                                else
6427
                                                         vqet1 <= 6'd1;
6428
                                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR)
6429
                                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6430
                                                        enque1(tail1,
6431
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6432
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6433
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
6434
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6435
                                                                if (fetchbuf1_thrd)
6436
                                                                        seq_num1 <= seq_num1 + 5'd2;
6437
                                                                else
6438
                                                                        seq_num <= seq_num + 5'd2;
6439
                                                        end
6440
                                                        else begin
6441
                                                                if (fetchbuf1_thrd)
6442
                                                                        seq_num1 <= seq_num1 + 5'd1;
6443
                                                                else
6444
                                                                        seq_num <= seq_num + 5'd1;
6445
                                                        end
6446
 
6447
                                                                // SOURCE 1 ...
6448 55 robfinch
                                                                a1_vs();
6449 48 robfinch
 
6450 55 robfinch
                                                                // SOURCE 2 ..
6451
                                                                a2_vs();
6452 48 robfinch
 
6453
                                                                // SOURCE 3 ...
6454 55 robfinch
                                                                a3_vs();
6455 48 robfinch
 
6456
                                                                // if the two instructions enqueued target the same register, 
6457
                                                                // make sure only the second writes to rf_v and rf_source.
6458
                                                                // first is allowed to update rf_v and rf_source only if the
6459
                                                                // second has no target
6460
                                                                //
6461
                                                            if (fetchbuf0_rfw) begin
6462
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6463
                                                                     rf_v [ Rt0s] <= `INV;
6464
                                                            end
6465
                                                            if (fetchbuf1_rfw) begin
6466
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6467
                                                                     rf_v [ Rt1s ] <= `INV;
6468
                                                            end
6469
                                            end
6470
                                            else begin
6471
//                                                      enque1(tail1, seq_num + 5'd1, 6'd0);
6472
                                                        enque1(tail1,
6473
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6474
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6475
                                                                fetchbuf1_thrd ? seq_num1: seq_num, 6'd0);
6476
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6477
                                                                if (fetchbuf1_thrd)
6478
                                                                        seq_num1 <= seq_num1 + 5'd2;
6479
                                                                else
6480
                                                                        seq_num <= seq_num + 5'd2;
6481
                                                        end
6482
                                                        else begin
6483
                                                                        seq_num1 <= seq_num1 + 5'd1;
6484
                                                                        seq_num <= seq_num + 5'd1;
6485
                                                        end
6486
 
6487
                                                                // SOURCE 1 ...
6488 55 robfinch
                                                                a1_vs();
6489 48 robfinch
 
6490
                                                                // SOURCE 2 ...
6491 55 robfinch
                                                                a2_vs();
6492 48 robfinch
 
6493
                                                                // SOURCE 3 ...
6494 55 robfinch
                                                                a3_vs();
6495 48 robfinch
 
6496
                                                                // if the two instructions enqueued target the same register, 
6497
                                                                // make sure only the second writes to regIsValid and rf_source.
6498
                                                                // first is allowed to update regIsValid and rf_source only if the
6499
                                                                // second has no target (BEQ or SW)
6500
                                                                //
6501
                                                            if (fetchbuf0_rfw) begin
6502
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6503
                                                                     rf_v [ Rt0s] <= `INV;
6504
                                                                     $display("r%dx (%d) Invalidated", Rt0s, Rt0s[4:0]);
6505
                                                            end
6506
                                                            else
6507
                                                                $display("No rfw");
6508
                                                            if (fetchbuf1_rfw) begin
6509
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6510
                                                                     $display("r%dx (%d) Invalidated", Rt1s, Rt1s[4:0]);
6511
                                                                     rf_v [ Rt1s ] <= `INV;
6512
                                                            end
6513
                                                            else
6514
                                                                $display("No rfw");
6515
                                                        end
6516
 
6517
                                            end // ends the "if IQ[tail1] is available" clause
6518
                                            else begin  // only first instruction was enqueued
6519
                                                        if (fetchbuf0_rfw) begin
6520
                                                             $display("r%dx (%d) Invalidated 1", Rt0s, Rt0s[4:0]);
6521
                                                             rf_source[ Rt0s ] <= {1'b0,fetchbuf0_memld, tail0};
6522
                                                             rf_v [ Rt0s ] <= `INV;
6523
                                                        end
6524
                                                end
6525
                                    end
6526
 
6527
                                end     // ends the "else fetchbuf0 doesn't have a backwards branch" clause
6528
                    end
6529
                endcase
6530
        if (pebm) begin
6531
                if (branchmiss_thrd==1'b0)
6532
                        seq_num <= seq_num + 5'd3;
6533
                else
6534
                        seq_num1 <= seq_num1 + 5'd3;
6535
        end
6536
 
6537
//
6538
// DATAINCOMING
6539
//
6540
// wait for operand/s to appear on alu busses and puts them into 
6541
// the iqentry_a1 and iqentry_a2 slots (if appropriate)
6542
// as well as the appropriate iqentry_res slots (and setting valid bits)
6543
//
6544
// put results into the appropriate instruction entries
6545
//
6546
// This chunk of code has to be before the enqueue stage so that the agen bit
6547
// can be reset to zero by enqueue.
6548
// put results into the appropriate instruction entries
6549
//
6550
if (IsMul(alu0_instr)|IsDivmod(alu0_instr)|alu0_shft48) begin
6551
        if (alu0_done) begin
6552
                alu0_dataready <= `TRUE;
6553
        end
6554
end
6555
 
6556
if (alu0_v) begin
6557
        iqentry_tgt [ alu0_id[`QBITS] ] <= alu0_tgt;
6558
        iqentry_res     [ alu0_id[`QBITS] ] <= alu0_bus;
6559
        iqentry_exc     [ alu0_id[`QBITS] ] <= alu0_exc;
6560
        iqentry_done[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
6561
        iqentry_cmt[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
6562
        iqentry_out     [ alu0_id[`QBITS] ] <= `INV;
6563
        iqentry_agen[ alu0_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
6564
        alu0_dataready <= FALSE;
6565
end
6566
 
6567 49 robfinch
if (alu1_v && `NUM_ALU > 1) begin
6568 48 robfinch
        iqentry_tgt [ alu1_id[`QBITS] ] <= alu1_tgt;
6569
        iqentry_res     [ alu1_id[`QBITS] ] <= alu1_bus;
6570
        iqentry_exc     [ alu1_id[`QBITS] ] <= alu1_exc;
6571
        iqentry_done[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
6572
        iqentry_cmt[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
6573
        iqentry_out     [ alu1_id[`QBITS] ] <= `INV;
6574
        iqentry_agen[ alu1_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
6575
        alu1_dataready <= FALSE;
6576
end
6577
 
6578 49 robfinch
if (fpu1_v) begin
6579 51 robfinch
        iqentry_res [ fpu1_id[`QBITS] ] <= fpu1_bus;
6580
        iqentry_a0  [ fpu1_id[`QBITS] ] <= fpu1_status;
6581
        iqentry_exc [ fpu1_id[`QBITS] ] <= fpu1_exc;
6582 49 robfinch
        iqentry_done[ fpu1_id[`QBITS] ] <= fpu1_done;
6583 51 robfinch
        iqentry_cmt     [ fpu1_id[`QBITS] ] <= fpu1_done;
6584
        iqentry_out [ fpu1_id[`QBITS] ] <= `INV;
6585 49 robfinch
        fpu1_dataready <= FALSE;
6586 48 robfinch
end
6587
 
6588 49 robfinch
if (fpu2_v && `NUM_FPU > 1) begin
6589 51 robfinch
        iqentry_res [ fpu2_id[`QBITS] ] <= fpu2_bus;
6590
        iqentry_a0  [ fpu2_id[`QBITS] ] <= fpu2_status;
6591
        iqentry_exc [ fpu2_id[`QBITS] ] <= fpu2_exc;
6592 49 robfinch
        iqentry_done[ fpu2_id[`QBITS] ] <= fpu2_done;
6593 51 robfinch
        iqentry_cmt [ fpu2_id[`QBITS] ] <= fpu2_done;
6594
        iqentry_out [ fpu2_id[`QBITS] ] <= `INV;
6595 49 robfinch
        //iqentry_agen[ fpu_id[`QBITS] ] <= `VAL;  // RET
6596
        fpu2_dataready <= FALSE;
6597
end
6598
 
6599 51 robfinch
if (fcu_wr & ~fcu_done) begin
6600
        fcu_done <= `TRUE;
6601
  if (fcu_ld)
6602
    waitctr <= fcu_argA;
6603
  iqentry_res [ fcu_id[`QBITS] ] <= fcu_bus;
6604
  iqentry_exc [ fcu_id[`QBITS] ] <= fcu_exc;
6605
  if (IsWait(fcu_instr)) begin
6606
                iqentry_done [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
6607
                iqentry_cmt [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
6608
  end
6609
  else begin
6610
                iqentry_done[ fcu_id[`QBITS] ] <= `TRUE;
6611
                iqentry_cmt[ fcu_id[`QBITS] ] <= `TRUE;
6612
  end
6613
        // Only safe place to propagate the miss pc is a0.
6614
        iqentry_a0[ fcu_id[`QBITS] ] <= fcu_misspc;
6615 55 robfinch
        // Update branch target update indicator.
6616 51 robfinch
        if (fcu_jal || fcu_ret || fcu_brk || fcu_rti) begin
6617
                iqentry_bt[ fcu_id[`QBITS] ] <= `VAL;
6618
        end
6619
// Branch target is only updated for branch-to-register
6620 52 robfinch
        else if (fcu_branch) begin
6621
                iqentry_takb[ fcu_id[`QBITS] ] <= fcu_takb;
6622
        end
6623 51 robfinch
        iqentry_out [ fcu_id[`QBITS] ] <= `INV;
6624
        //iqentry_agen[ fcu_id[`QBITS] ] <= `VAL;//!IsRet(fcu_instr);
6625
        fcu_dataready <= `VAL;
6626 48 robfinch
         //fcu_dataready <= fcu_branchmiss || !iqentry_agen[ fcu_id[`QBITS] ] || !(iqentry_mem[ fcu_id[`QBITS] ] && IsLoad(iqentry_instr[fcu_id[`QBITS]]));
6627
         //fcu_instr[`INSTRUCTION_OP] <= fcu_branchmiss|| (!IsMem(fcu_instr) && !IsWait(fcu_instr))? `NOP : fcu_instr[`INSTRUCTION_OP]; // to clear branchmiss
6628 51 robfinch
end
6629
// Clear a branch miss when target instruction is fetched.
6630
if (fcu_branchmiss) begin
6631
        if ((fetchbuf0_v && fetchbuf0_pc==misspc) ||
6632
                (fetchbuf1_v && fetchbuf1_pc==misspc))
6633
        fcu_clearbm <= `TRUE;
6634
end
6635
 
6636
if (mem1_available && dramA_v && iqentry_v[ dramA_id[`QBITS] ] && iqentry_load[ dramA_id[`QBITS] ]) begin
6637
        iqentry_res     [ dramA_id[`QBITS] ] <= dramA_bus;
6638
        iqentry_exc     [ dramA_id[`QBITS] ] <= dramA_exc;
6639
        iqentry_done[ dramA_id[`QBITS] ] <= `VAL;
6640
        iqentry_out [ dramA_id[`QBITS] ] <= `INV;
6641
        iqentry_cmt [ dramA_id[`QBITS] ] <= `VAL;
6642
        iqentry_aq  [ dramA_id[`QBITS] ] <= `INV;
6643
end
6644
if (mem2_available && `NUM_MEM > 1 && dramB_v && iqentry_v[ dramB_id[`QBITS] ] && iqentry_load[ dramB_id[`QBITS] ]) begin
6645
        iqentry_res     [ dramB_id[`QBITS] ] <= dramB_bus;
6646
        iqentry_exc     [ dramB_id[`QBITS] ] <= dramB_exc;
6647
        iqentry_done[ dramB_id[`QBITS] ] <= `VAL;
6648
        iqentry_out [ dramB_id[`QBITS] ] <= `INV;
6649
        iqentry_cmt [ dramB_id[`QBITS] ] <= `VAL;
6650
        iqentry_aq  [ dramB_id[`QBITS] ] <= `INV;
6651
end
6652
if (mem3_available && `NUM_MEM > 2 && dramC_v && iqentry_v[ dramC_id[`QBITS] ] && iqentry_load[ dramC_id[`QBITS] ]) begin
6653
        iqentry_res     [ dramC_id[`QBITS] ] <= dramC_bus;
6654
        iqentry_exc     [ dramC_id[`QBITS] ] <= dramC_exc;
6655
        iqentry_done[ dramC_id[`QBITS] ] <= `VAL;
6656
        iqentry_out [ dramC_id[`QBITS] ] <= `INV;
6657
        iqentry_cmt [ dramC_id[`QBITS] ] <= `VAL;
6658
        iqentry_aq  [ dramC_id[`QBITS] ] <= `INV;
6659 48 robfinch
//          if (iqentry_lptr[dram2_id[`QBITS]])
6660
//              wbrcd[pcr[5:0]] <= 1'b1;
6661 51 robfinch
end
6662 48 robfinch
 
6663
//
6664
// set the IQ entry == DONE as soon as the SW is let loose to the memory system
6665
//
6666 50 robfinch
if (mem1_available && dram0 == `DRAMSLOT_BUSY && dram0_store) begin
6667 48 robfinch
        if ((alu0_v && (dram0_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram0_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6668
        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
6669
        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
6670
end
6671 50 robfinch
if (mem2_available && `NUM_MEM > 1 && dram1 == `DRAMSLOT_BUSY && dram1_store) begin
6672 48 robfinch
        if ((alu0_v && (dram1_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram1_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6673
        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
6674
        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
6675
end
6676 50 robfinch
if (mem3_available && `NUM_MEM > 2 && dram2 == `DRAMSLOT_BUSY && dram2_store) begin
6677 48 robfinch
        if ((alu0_v && (dram2_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram2_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6678
        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
6679
        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
6680
end
6681
 
6682
//
6683
// see if anybody else wants the results ... look at lots of buses:
6684
//  - fpu_bus
6685
//  - alu0_bus
6686
//  - alu1_bus
6687
//  - fcu_bus
6688
//  - dram_bus
6689
//  - commit0_bus
6690
//  - commit1_bus
6691
//
6692
 
6693
for (n = 0; n < QENTRIES; n = n + 1)
6694
begin
6695 49 robfinch
        if (`NUM_FPU > 0)
6696
                setargs(n,{1'b0,fpu1_id},fpu1_v,fpu1_bus);
6697
        if (`NUM_FPU > 1)
6698
                setargs(n,{1'b0,fpu2_id},fpu2_v,fpu2_bus);
6699
 
6700 48 robfinch
        setargs(n,{1'b0,alu0_id},alu0_v,alu0_bus);
6701 49 robfinch
        if (`NUM_ALU > 1)
6702
                setargs(n,{1'b0,alu1_id},alu1_v,alu1_bus);
6703
 
6704 48 robfinch
        setargs(n,{1'b0,fcu_id},fcu_wr,fcu_bus);
6705 49 robfinch
 
6706 48 robfinch
        setargs(n,{1'b0,dramA_id},dramA_v,dramA_bus);
6707 49 robfinch
        if (`NUM_MEM > 1)
6708
                setargs(n,{1'b0,dramB_id},dramB_v,dramB_bus);
6709
        if (`NUM_MEM > 2)
6710
                setargs(n,{1'b0,dramC_id},dramC_v,dramC_bus);
6711
 
6712 48 robfinch
        setargs(n,commit0_id,commit0_v,commit0_bus);
6713 49 robfinch
        if (`NUM_CMT > 1)
6714
                setargs(n,commit1_id,commit1_v,commit1_bus);
6715 58 robfinch
        if (`NUM_CMT > 2)
6716
                setargs(n,commit2_id,commit2_v,commit2_bus);
6717 48 robfinch
 
6718
        setinsn(n[`QBITS],id1_ido,id1_available&id1_vo,id1_bus);
6719 49 robfinch
        if (`NUM_IDU > 1)
6720
                setinsn(n[`QBITS],id2_ido,id2_available&id2_vo,id2_bus);
6721
        if (`NUM_IDU > 2)
6722
                setinsn(n[`QBITS],id3_ido,id3_available&id3_vo,id3_bus);
6723 48 robfinch
end
6724
 
6725
//
6726
// ISSUE 
6727
//
6728
// determines what instructions are ready to go, then places them
6729
// in the various ALU queues.  
6730
// also invalidates instructions following a branch-miss BEQ or any JALR (STOMP logic)
6731
//
6732
 
6733
for (n = 0; n < QENTRIES; n = n + 1)
6734
if (id1_available) begin
6735
if (iqentry_id1issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6736
                id1_vi <= `VAL;
6737
                id1_id                  <= n[4:0];
6738
                id1_instr       <= iqentry_rtop[n] ? (
6739
                                                                                iqentry_a3_v[n] ? iqentry_a3[n]
6740 49 robfinch
`ifdef FU_BYPASS
6741 48 robfinch
                                : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
6742
                                : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
6743 49 robfinch
`endif
6744 48 robfinch
                                : `NOP_INSN)
6745
                                                                 : iqentry_instr[n];
6746
                id1_ven    <= iqentry_ven[n];
6747
                id1_vl     <= iqentry_vl[n];
6748
                id1_thrd   <= iqentry_thrd[n];
6749
                id1_Rt     <= iqentry_tgt[n][4:0];
6750
                id1_pt                  <= iqentry_pt[n];
6751
  end
6752
end
6753 49 robfinch
if (`NUM_IDU > 1) begin
6754 48 robfinch
for (n = 0; n < QENTRIES; n = n + 1)
6755 49 robfinch
        if (id2_available) begin
6756
                if (iqentry_id2issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6757
                        id2_vi <= `VAL;
6758
                        id2_id                  <= n[4:0];
6759
                        id2_instr       <= iqentry_rtop[n] ? (
6760
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6761
`ifdef FU_BYPASS
6762
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
6763
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
6764
`endif
6765
                                        : `NOP_INSN)
6766
                                                                         : iqentry_instr[n];
6767
                        id2_ven    <= iqentry_ven[n];
6768
                        id2_vl     <= iqentry_vl[n];
6769
                        id2_thrd   <= iqentry_thrd[n];
6770
                        id2_Rt     <= iqentry_tgt[n][4:0];
6771
                        id2_pt                  <= iqentry_pt[n];
6772
                end
6773 48 robfinch
        end
6774
end
6775 49 robfinch
if (`NUM_IDU > 2) begin
6776
for (n = 0; n < QENTRIES; n = n + 1)
6777
        if (id3_available) begin
6778
                if (iqentry_id3issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6779
                        id3_vi <= `VAL;
6780
                        id3_id                  <= n[4:0];
6781
                        id3_instr       <= iqentry_rtop[n] ? (
6782
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6783
`ifdef FU_BYPASS
6784
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
6785
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
6786
`endif
6787
                                        : `NOP_INSN)
6788
                                                                         : iqentry_instr[n];
6789
                        id3_ven    <= iqentry_ven[n];
6790
                        id3_vl     <= iqentry_vl[n];
6791
                        id3_thrd   <= iqentry_thrd[n];
6792
                        id3_Rt     <= iqentry_tgt[n][4:0];
6793
                        id3_pt                  <= iqentry_pt[n];
6794
                end
6795
        end
6796
end
6797 48 robfinch
 
6798 53 robfinch
// X's on unused busses cause problems in SIM.
6799 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
6800
        if (iqentry_alu0_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6801
            if (alu0_available & alu0_done) begin
6802
                 alu0_sourceid  <= n[3:0];
6803
                 alu0_instr     <= iqentry_rtop[n] ? (
6804 49 robfinch
`ifdef FU_BYPASS
6805 48 robfinch
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6806 49 robfinch
                                                    : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
6807 53 robfinch
                                                    : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
6808 49 robfinch
                                                    : (iqentry_a3_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6809 53 robfinch
                                                    : `NOP_INSN)
6810 49 robfinch
`else
6811
                                                                                                                                        iqentry_a3[n])
6812
`endif
6813 48 robfinch
                                                                         : iqentry_instr[n];
6814
                 alu0_bt                <= iqentry_bt[n];
6815
                 alu0_mem   <= iqentry_mem[n];
6816
                 alu0_shft48 <= iqentry_shft48[n];
6817
                 alu0_pc                <= iqentry_pc[n];
6818 49 robfinch
                 alu0_argA      <=
6819
`ifdef FU_BYPASS
6820
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
6821
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
6822 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
6823 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6824 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
6825 49 robfinch
`else
6826
                                                                                                                iqentry_a1[n];
6827
`endif
6828 48 robfinch
                 alu0_argB      <= iqentry_imm[n]
6829
                            ? iqentry_a0[n]
6830 49 robfinch
`ifdef FU_BYPASS
6831 48 robfinch
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
6832 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
6833 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
6834 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6835 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
6836 49 robfinch
`else
6837
                                                                                                                : iqentry_a2[n];
6838
`endif
6839
                 alu0_argC      <=
6840
`ifdef FU_BYPASS
6841
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6842 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6843 49 robfinch
`else
6844
                                                                                                                        iqentry_a3[n];
6845
`endif
6846 48 robfinch
                 alu0_argI      <= iqentry_a0[n];
6847
                 alu0_tgt    <= IsVeins(iqentry_instr[n]) ?
6848 49 robfinch
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((
6849
                                                                                        iqentry_a2_v[n] ? iqentry_a2[n][5:0]
6850 48 robfinch
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
6851
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
6852
                                            : {4{16'h0000}})) << 6 :
6853
                                iqentry_tgt[n];
6854
                 alu0_ven    <= iqentry_ven[n];
6855
                 alu0_thrd   <= iqentry_thrd[n];
6856
                 alu0_dataready <= IsSingleCycle(iqentry_instr[n]);
6857
                 alu0_ld <= TRUE;
6858
                 iqentry_out[n] <= `VAL;
6859
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
6860
                if (iqentry_mem[n]) begin
6861
                 iqentry_a1_v[n] <= `INV;
6862
                 iqentry_a1_s[n] <= n[3:0];
6863
                end
6864
            end
6865
        end
6866 49 robfinch
        if (`NUM_ALU > 1) begin
6867 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
6868
        if (iqentry_alu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6869
            if (alu1_available && alu1_done) begin
6870
                        if (iqentry_alu0[n])
6871
                                panic <= `PANIC_ALU0ONLY;
6872
                 alu1_sourceid  <= n[3:0];
6873
                 alu1_instr     <= iqentry_instr[n];
6874
                 alu1_bt                <= iqentry_bt[n];
6875
                 alu1_mem   <= iqentry_mem[n];
6876
                 alu1_shft48 <= iqentry_shft48[n];
6877
                 alu1_pc                <= iqentry_pc[n];
6878 49 robfinch
                 alu1_argA      <=
6879
`ifdef FU_BYPASS
6880
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
6881
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
6882 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
6883 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6884 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
6885 49 robfinch
`else
6886
                                                                                                                        iqentry_a1[n];
6887
`endif
6888 48 robfinch
                 alu1_argB      <= iqentry_imm[n]
6889
                            ? iqentry_a0[n]
6890 49 robfinch
`ifdef FU_BYPASS
6891 48 robfinch
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
6892 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
6893 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
6894 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6895 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
6896 49 robfinch
`else
6897
                                                                                                                : iqentry_a2[n];
6898
`endif
6899
                 alu1_argC      <=
6900
`ifdef FU_BYPASS
6901
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6902 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6903 49 robfinch
`else
6904
                                                                                                                        iqentry_a3[n];
6905
`endif
6906 48 robfinch
                 alu1_argI      <= iqentry_a0[n];
6907
                 alu1_tgt    <= IsVeins(iqentry_instr[n]) ?
6908
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((iqentry_a2_v[n] ? iqentry_a2[n][5:0]
6909
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
6910
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
6911
                                            : {4{16'h0000}})) << 6 :
6912
                                iqentry_tgt[n];
6913
                 alu1_ven    <= iqentry_ven[n];
6914
                 alu1_dataready <= IsSingleCycle(iqentry_instr[n]);
6915
                 alu1_ld <= TRUE;
6916
                 iqentry_out[n] <= `VAL;
6917
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
6918
                if (iqentry_mem[n]) begin
6919
                 iqentry_a1_v[n] <= `INV;
6920
                 iqentry_a1_s[n] <= n[3:0];
6921
                end
6922
            end
6923
        end
6924 49 robfinch
  end
6925 48 robfinch
 
6926
    for (n = 0; n < QENTRIES; n = n + 1)
6927 49 robfinch
        if (iqentry_fpu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6928
            if (fpu1_available & fpu1_done) begin
6929
                 fpu1_sourceid  <= n[3:0];
6930
                 fpu1_instr     <= iqentry_instr[n];
6931
                 fpu1_pc                <= iqentry_pc[n];
6932
                 fpu1_argA      <=
6933
`ifdef FU_BYPASS
6934
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
6935
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
6936 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
6937 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6938 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
6939 49 robfinch
`else
6940
                                                                                                                        iqentry_a1[n];
6941
`endif
6942
                 fpu1_argB      <=
6943
`ifdef FU_BYPASS
6944
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
6945
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
6946 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
6947 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6948 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
6949 49 robfinch
`else
6950
                                                                                                                        iqentry_a2[n];
6951
`endif
6952
                 fpu1_argC      <=
6953
`ifdef FU_BYPASS
6954
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
6955 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6956 49 robfinch
`else
6957
                                                                                                                        iqentry_a3[n];
6958
`endif
6959
                 fpu1_argI      <= iqentry_a0[n];
6960
                 fpu1_dataready <= `VAL;
6961
                 fpu1_ld <= TRUE;
6962 48 robfinch
                 iqentry_out[n] <= `VAL;
6963
            end
6964
        end
6965
 
6966
    for (n = 0; n < QENTRIES; n = n + 1)
6967 49 robfinch
        if (`NUM_FPU > 1 && iqentry_fpu2_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6968
            if (fpu2_available & fpu2_done) begin
6969
                 fpu2_sourceid  <= n[3:0];
6970
                 fpu2_instr     <= iqentry_instr[n];
6971
                 fpu2_pc                <= iqentry_pc[n];
6972
                 fpu2_argA      <=
6973
`ifdef FU_BYPASS
6974
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
6975
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
6976 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
6977 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6978 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
6979 49 robfinch
`else
6980
                                                                                                                        iqentry_a1[n];
6981
`endif
6982
                 fpu2_argB      <=
6983
`ifdef FU_BYPASS
6984
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
6985
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
6986 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
6987 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6988 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
6989 49 robfinch
`else
6990
                                                                                                                        iqentry_a2[n];
6991
`endif
6992
                 fpu2_argC      <=
6993
`ifdef FU_BYPASS
6994
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
6995
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6996
`else
6997
                                                                                                                        iqentry_a3[n];
6998
`endif
6999
                 fpu2_argI      <= iqentry_a0[n];
7000
                 fpu2_dataready <= `VAL;
7001
                 fpu2_ld <= TRUE;
7002
                 iqentry_out[n] <= `VAL;
7003
            end
7004
        end
7005
 
7006
    for (n = 0; n < QENTRIES; n = n + 1)
7007 48 robfinch
        if (iqentry_fcu_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7008
            if (fcu_done) begin
7009
                 fcu_sourceid   <= n[3:0];
7010
                 fcu_instr      <= iqentry_instr[n];
7011
                 fcu_insln  <= iqentry_insln[n];
7012
                 fcu_pc         <= iqentry_pc[n];
7013
                 fcu_nextpc <= iqentry_pc[n] + iqentry_insln[n];
7014
                 fcu_brdisp <= {{52{iqentry_instr[n][31]}},iqentry_instr[n][31:21],1'b0};
7015 51 robfinch
                 fcu_branch <= iqentry_br[n];
7016
                 fcu_call    <= IsCall(iqentry_instr[n])|iqentry_jal[n];
7017
                 fcu_jal     <= iqentry_jal[n];
7018
                 fcu_ret    <= iqentry_ret[n];
7019
                 fcu_brk  <= iqentry_brk[n];
7020
                 fcu_rti  <= iqentry_rti[n];
7021 48 robfinch
                 fcu_bt         <= iqentry_bt[n];
7022
                 fcu_pc         <= iqentry_pc[n];
7023
                 fcu_argA       <= iqentry_a1_v[n] ? iqentry_a1[n]
7024 49 robfinch
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7025
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7026
                            : alu1_bus;
7027 48 robfinch
`ifdef SUPPORT_SMT
7028 51 robfinch
                 fcu_argB       <= iqentry_rti[n] ? epc0[iqentry_thrd[n]]
7029 48 robfinch
`else
7030 51 robfinch
                 fcu_argB       <= iqentry_rti[n] ? epc0
7031 48 robfinch
`endif
7032
                                        : (iqentry_a2_v[n] ? iqentry_a2[n]
7033 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7034
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7035
                            : alu1_bus);
7036 48 robfinch
                 waitctr            <= iqentry_imm[n]
7037
                            ? iqentry_a0[n]
7038
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7039
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus : alu1_bus);
7040
                 fcu_argC       <= iqentry_a3_v[n] ? iqentry_a3[n]
7041
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7042
                 fcu_argI       <= iqentry_a0[n];
7043
                 fcu_thrd   <= iqentry_thrd[n];
7044
                 fcu_dataready <= `VAL;
7045
                 fcu_clearbm <= `FALSE;
7046
                 fcu_ld <= TRUE;
7047
                 fcu_timeout <= 8'h00;
7048
                 iqentry_out[n] <= `VAL;
7049
                 fcu_done <= `FALSE;
7050
            end
7051
        end
7052
//
7053
// MEMORY
7054
//
7055
// update the memory queues and put data out on bus if appropriate
7056
//
7057
 
7058
//
7059
// dram0, dram1, dram2 are the "state machines" that keep track
7060
// of three pipelined DRAM requests.  if any has the value "00", 
7061
// then it can accept a request (which bumps it up to the value "01"
7062
// at the end of the cycle).  once it hits the value "11" the request
7063
// is finished and the dram_bus takes the value.  if it is a store, the 
7064
// dram_bus value is not used, but the dram_v value along with the
7065
// dram_id value signals the waiting memq entry that the store is
7066
// completed and the instruction can commit.
7067
//
7068
 
7069
//      if (dram0 != `DRAMSLOT_AVAIL)   dram0 <= dram0 + 2'd1;
7070
//      if (dram1 != `DRAMSLOT_AVAIL)   dram1 <= dram1 + 2'd1;
7071
//      if (dram2 != `DRAMSLOT_AVAIL)   dram2 <= dram2 + 2'd1;
7072
 
7073
//
7074
// grab requests that have finished and put them on the dram_bus
7075 49 robfinch
if (mem1_available && dram0 == `DRAMREQ_READY) begin
7076 48 robfinch
        dram0 <= `DRAMSLOT_AVAIL;
7077
        dramA_v <= dram0_load;
7078
        dramA_id <= dram0_id;
7079
        dramA_exc <= dram0_exc;
7080
        dramA_bus <= fnDati(dram0_instr,dram0_addr,rdat0);
7081 50 robfinch
        if (dram0_store)        $display("m[%h] <- %h", dram0_addr, dram0_data);
7082 48 robfinch
end
7083
//    else
7084
//      dramA_v <= `INV;
7085 49 robfinch
if (mem2_available && dram1 == `DRAMREQ_READY && `NUM_MEM > 1) begin
7086 48 robfinch
        dram1 <= `DRAMSLOT_AVAIL;
7087
        dramB_v <= dram1_load;
7088
        dramB_id <= dram1_id;
7089
        dramB_exc <= dram1_exc;
7090
        dramB_bus <= fnDati(dram1_instr,dram1_addr,rdat1);
7091 50 robfinch
        if (dram1_store)     $display("m[%h] <- %h", dram1_addr, dram1_data);
7092 48 robfinch
end
7093
//    else
7094
//      dramB_v <= `INV;
7095 49 robfinch
if (mem3_available && dram2 == `DRAMREQ_READY && `NUM_MEM > 2) begin
7096 48 robfinch
        dram2 <= `DRAMSLOT_AVAIL;
7097
        dramC_v <= dram2_load;
7098
        dramC_id <= dram2_id;
7099
        dramC_exc <= dram2_exc;
7100
        dramC_bus <= fnDati(dram2_instr,dram2_addr,rdat2);
7101 50 robfinch
        if (dram2_store)     $display("m[%h] <- %h", dram2_addr, dram2_data);
7102 48 robfinch
end
7103
//    else
7104
//      dramC_v <= `INV;
7105
 
7106
        //
7107
        // determine if the instructions ready to issue can, in fact, issue.
7108
        // "ready" means that the instruction has valid operands but has not gone yet
7109
        iqentry_memissue <= memissue;
7110
        missue_count <= issue_count;
7111
 
7112
 
7113
        //
7114
        // take requests that are ready and put them into DRAM slots
7115
 
7116
        if (dram0 == `DRAMSLOT_AVAIL)    dram0_exc <= `FLT_NONE;
7117
        if (dram1 == `DRAMSLOT_AVAIL)    dram1_exc <= `FLT_NONE;
7118
        if (dram2 == `DRAMSLOT_AVAIL)    dram2_exc <= `FLT_NONE;
7119
 
7120
        for (n = 0; n < QENTRIES; n = n + 1)
7121
                if (iqentry_v[n] && iqentry_stomp[n]) begin
7122
                        iqentry_v[n] <= `INV;
7123
                        iqentry_iv[n] <= `INV;
7124
                        if (dram0_id[`QBITS] == n[`QBITS])  dram0 <= `DRAMSLOT_AVAIL;
7125
                        if (dram1_id[`QBITS] == n[`QBITS])  dram1 <= `DRAMSLOT_AVAIL;
7126
                        if (dram2_id[`QBITS] == n[`QBITS])  dram2 <= `DRAMSLOT_AVAIL;
7127
                end
7128
 
7129 53 robfinch
        last_issue = QENTRIES;
7130 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
7131 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7132
            if (mem1_available && dram0 == `DRAMSLOT_AVAIL) begin
7133 48 robfinch
                dramA_v <= `INV;
7134
             dram0              <= `DRAMSLOT_BUSY;
7135
             dram0_id   <= { 1'b1, n[`QBITS] };
7136
             dram0_instr <= iqentry_instr[n];
7137
             dram0_rmw  <= iqentry_rmw[n];
7138
             dram0_preload <= iqentry_preload[n];
7139
             dram0_tgt  <= iqentry_tgt[n];
7140
             dram0_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7141
             dram0_addr <= iqentry_a1[n];
7142
//             if (ol[iqentry_thrd[n]]==`OL_USER)
7143
//              dram0_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7144
//             else
7145 50 robfinch
             dram0_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7146
             dram0_memsize <= iqentry_memsz[n];
7147 48 robfinch
             dram0_load <= iqentry_load[n];
7148 50 robfinch
             dram0_store <= iqentry_store[n];
7149 48 robfinch
             dram0_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
7150
             // Once the memory op is issued reset the a1_v flag.
7151
             // This will cause the a1 bus to look for new data from memory (a1_s is pointed to a memory bus)
7152
             // This is used for the load and compare instructions.
7153
             iqentry_a1_v[n] <= `INV;
7154
             last_issue = n;
7155
            end
7156
        end
7157 53 robfinch
    if (last_issue < QENTRIES)
7158 48 robfinch
        iqentry_out[last_issue] <= `VAL;
7159
    for (n = 0; n < QENTRIES; n = n + 1)
7160 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7161
                if (mem2_available && n < last_issue && `NUM_MEM > 1) begin
7162 48 robfinch
                    if (dram1 == `DRAMSLOT_AVAIL) begin
7163
                        dramB_v <= `INV;
7164
                     dram1              <= `DRAMSLOT_BUSY;
7165
                     dram1_id   <= { 1'b1, n[`QBITS] };
7166
                     dram1_instr <= iqentry_instr[n];
7167
                     dram1_rmw  <= iqentry_rmw[n];
7168
                     dram1_preload <= iqentry_preload[n];
7169
                     dram1_tgt  <= iqentry_tgt[n];
7170
                     dram1_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7171
                     dram1_addr <= iqentry_a1[n];
7172
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
7173
//                      dram1_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7174
//                   else
7175 50 robfinch
                     dram1_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7176
                     dram1_memsize <= iqentry_memsz[n];
7177 48 robfinch
                     dram1_load <= iqentry_load[n];
7178 50 robfinch
                     dram1_store <= iqentry_store[n];
7179 48 robfinch
                     dram1_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
7180
                     iqentry_a1_v[n] <= `INV;
7181
                     last_issue = n;
7182
                    end
7183
                end
7184
        end
7185 53 robfinch
    if (last_issue < QENTRIES)
7186 48 robfinch
        iqentry_out[last_issue] <= `VAL;
7187
    for (n = 0; n < QENTRIES; n = n + 1)
7188 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7189
                if (mem3_available && n < last_issue && `NUM_MEM > 2) begin
7190 48 robfinch
                    if (dram2 == `DRAMSLOT_AVAIL) begin
7191
                        dramC_v <= `INV;
7192
                     dram2              <= `DRAMSLOT_BUSY;
7193
                     dram2_id   <= { 1'b1, n[`QBITS] };
7194
                     dram2_instr        <= iqentry_instr[n];
7195
                     dram2_rmw  <= iqentry_rmw[n];
7196
                     dram2_preload <= iqentry_preload[n];
7197
                     dram2_tgt  <= iqentry_tgt[n];
7198
                     dram2_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7199
                     dram2_addr <= iqentry_a1[n];
7200
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
7201
//                      dram2_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7202
//                   else
7203 50 robfinch
                     dram2_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7204
                     dram2_memsize <= iqentry_memsz[n];
7205 48 robfinch
                     dram2_load <= iqentry_load[n];
7206 50 robfinch
                     dram2_store <= iqentry_store[n];
7207 48 robfinch
                     dram2_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
7208
                     iqentry_a1_v[n] <= `INV;
7209
                    end
7210
                end
7211
        end
7212 53 robfinch
    if (last_issue < QENTRIES)
7213 48 robfinch
        iqentry_out[last_issue] <= `VAL;
7214
 
7215 51 robfinch
for (n = 0; n < QENTRIES; n = n + 1)
7216
begin
7217
        if (!iqentry_v[n])
7218
                iqentry_done[n] <= FALSE;
7219
end
7220 48 robfinch
 
7221
 
7222
 
7223 49 robfinch
//
7224
// COMMIT PHASE (dequeue only ... not register-file update)
7225
//
7226
// look at head0 and head1 and let 'em write to the register file if they are ready
7227
//
7228 48 robfinch
//    always @(posedge clk) begin: commit_phase
7229
 
7230 49 robfinch
oddball_commit(commit0_v, head0);
7231
if (`NUM_CMT > 1)
7232
        oddball_commit(commit1_v, head1);
7233 58 robfinch
if (`NUM_CMT > 2)
7234
        oddball_commit(commit2_v, head2);
7235 50 robfinch
//if (`NUM_CMT > 2)
7236
//      oddball_commit(commit2_v, head2);
7237 48 robfinch
 
7238
// Fetch and queue are limited to two instructions per cycle, so we might as
7239
// well limit retiring to two instructions max to conserve logic.
7240
//
7241
if (~|panic)
7242 49 robfinch
  casez ({ iqentry_v[head0],
7243
                iqentry_cmt[head0],
7244
                iqentry_v[head1],
7245
                iqentry_cmt[head1],
7246
                iqentry_v[head2],
7247
                iqentry_cmt[head2]})
7248 48 robfinch
 
7249
        // retire 3
7250 49 robfinch
        6'b0?_0?_0?:
7251
                if (head0 != tail0 && head1 != tail0 && head2 != tail0) begin
7252
                                head_inc(3);
7253
                end
7254
                else if (head0 != tail0 && head1 != tail0) begin
7255 48 robfinch
                    head_inc(2);
7256
                end
7257
                else if (head0 != tail0) begin
7258
                    head_inc(1);
7259
                end
7260 49 robfinch
        6'b0?_0?_10:    ;
7261
        6'b0?_0?_11:
7262
                if (`NUM_CMT > 2 || iqentry_tgt[head2][4:0]==5'd0) begin
7263
      iqentry_v[head2] <= `INV;
7264
      head_inc(3);
7265
                end
7266
                else begin
7267
      head_inc(2);
7268
                end
7269 48 robfinch
 
7270
        // retire 1 (wait for regfile for head1)
7271 49 robfinch
        6'b0?_10_??:
7272
                head_inc(1);
7273 48 robfinch
 
7274
        // retire 2
7275 49 robfinch
        6'b0?_11_0?,
7276
        6'b0?_11_10:
7277
        if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7278
          iqentry_v[head1] <= `INV;
7279
          head_inc(2);
7280 48 robfinch
        end
7281 49 robfinch
        else begin
7282
                head_inc(1);
7283
        end
7284
  6'b0?_11_11:
7285 50 robfinch
        if (`NUM_CMT > 2 || (`NUM_CMT > 1 && iqentry_tgt[head2] == 12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7286 49 robfinch
                iqentry_v[head1] <= `INV;
7287
          iqentry_v[head2] <= `INV;
7288
                head_inc(3);
7289
        end
7290
        else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7291
                iqentry_v[head1] <= `INV;
7292
                head_inc(2);
7293
        end
7294
        else
7295
                head_inc(1);
7296
  6'b10_??_??:  ;
7297
  6'b11_0?_0?:
7298
        if (head1 != tail0 && head2 != tail0) begin
7299 48 robfinch
                        iqentry_v[head0] <= `INV;
7300 49 robfinch
                        head_inc(3);
7301
        end
7302
        else if (head1 != tail0) begin
7303
                        iqentry_v[head0] <= `INV;
7304 48 robfinch
                        head_inc(2);
7305 49 robfinch
        end
7306
        else begin
7307 48 robfinch
                        iqentry_v[head0] <= `INV;
7308
                        head_inc(1);
7309 49 robfinch
        end
7310
  6'b11_0?_10:
7311
        if (head1 != tail0) begin
7312
                        iqentry_v[head0] <= `INV;
7313
                        head_inc(2);
7314
        end
7315
        else begin
7316
                        iqentry_v[head0] <= `INV;
7317
                        head_inc(1);
7318
        end
7319
  6'b11_0?_11:
7320
        if (head1 != tail0) begin
7321 50 robfinch
                if (`NUM_CMT > 2 || (iqentry_tgt[head2]==12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7322 49 robfinch
                                iqentry_v[head0] <= `INV;
7323
                                iqentry_v[head2] <= `INV;
7324
                                head_inc(3);
7325
                end
7326
                else begin
7327
                                iqentry_v[head0] <= `INV;
7328
                                head_inc(2);
7329
                        end
7330
        end
7331
        else begin
7332
                        iqentry_v[head0] <= `INV;
7333
                        head_inc(1);
7334
        end
7335
  6'b11_10_??:
7336
        begin
7337
                        iqentry_v[head0] <= `INV;
7338
                        head_inc(1);
7339
        end
7340
  6'b11_11_0?:
7341
        if (`NUM_CMT > 1 && head2 != tail0) begin
7342
                        iqentry_v[head0] <= `INV;
7343
                        iqentry_v[head1] <= `INV;
7344
                        head_inc(3);
7345
        end
7346
        else if (iqentry_tgt[head1]== 12'd0 && head2 != tail0) begin
7347
                        iqentry_v[head0] <= `INV;
7348
                        iqentry_v[head1] <= `INV;
7349
                        head_inc(3);
7350
        end
7351
        else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7352
                        iqentry_v[head0] <= `INV;
7353
                        iqentry_v[head1] <= `INV;
7354
                        head_inc(2);
7355
        end
7356
        else begin
7357
                        iqentry_v[head0] <= `INV;
7358
                        head_inc(1);
7359
        end
7360
  6'b11_11_10:
7361
        if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7362
                        iqentry_v[head0] <= `INV;
7363
                        iqentry_v[head1] <= `INV;
7364
                        head_inc(2);
7365
        end
7366
        else begin
7367
                        iqentry_v[head0] <= `INV;
7368
                        head_inc(1);
7369
        end
7370
        6'b11_11_11:
7371 50 robfinch
                if (`NUM_CMT > 2 || (`NUM_CMT > 1 && iqentry_tgt[head2]==12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7372 49 robfinch
                        iqentry_v[head0] <= `INV;
7373
                        iqentry_v[head1] <= `INV;
7374
                        iqentry_v[head2] <= `INV;
7375
                        head_inc(3);
7376 48 robfinch
                end
7377 49 robfinch
                else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7378 48 robfinch
                        iqentry_v[head0] <= `INV;
7379 49 robfinch
                        iqentry_v[head1] <= `INV;
7380
                        head_inc(2);
7381
                end
7382
                else begin
7383
                        iqentry_v[head0] <= `INV;
7384 48 robfinch
                        head_inc(1);
7385
                end
7386 49 robfinch
  endcase
7387 48 robfinch
 
7388
 
7389 55 robfinch
rf_source[0] <= 0;
7390
L1_wr0 <= FALSE;
7391
L1_wr1 <= FALSE;
7392
L1_wr2 <= FALSE;
7393
L1_invline <= FALSE;
7394
icnxt <= FALSE;
7395
L2_nxt <= FALSE;
7396 48 robfinch
// Instruction cache state machine.
7397
// On a miss first see if the instruction is in the L2 cache. No need to go to
7398
// the BIU on an L1 miss.
7399
// If not the machine will wait until the BIU loads the L2 cache.
7400
 
7401
// Capture the previous ic state, used to determine how long to wait in
7402
// icstate #4.
7403 55 robfinch
picstate <= icstate;
7404 48 robfinch
case(icstate)
7405
IDLE:
7406
        // If the bus unit is busy doing an update involving L1_adr or L2_adr
7407
        // we have to wait.
7408
        if (bstate != B7 && bstate != B9) begin
7409
                if (!ihit0) begin
7410 55 robfinch
                        L1_adr <= {pcr[5:0],pc0[31:5],5'h0};
7411
                        L2_adr <= {pcr[5:0],pc0[31:5],5'h0};
7412 48 robfinch
                        L1_invline <= TRUE;
7413 49 robfinch
                        icwhich <= 2'b00;
7414 48 robfinch
                        iccnt <= 3'b00;
7415
                        icstate <= IC2;
7416
                end
7417 49 robfinch
                else if (!ihit1 && `WAYS > 1) begin
7418 55 robfinch
                        if (thread_en) begin
7419
                                L1_adr <= {pcr[5:0],pc1[31:5],5'h0};
7420
                                L2_adr <= {pcr[5:0],pc1[31:5],5'h0};
7421
                        end
7422
                        else begin
7423
                                L1_adr <= {pcr[5:0],pc0plus6[31:5],5'h0};
7424
                                L2_adr <= {pcr[5:0],pc0plus6[31:5],5'h0};
7425
                        end
7426 48 robfinch
                        L1_invline <= TRUE;
7427 49 robfinch
                        icwhich <= 2'b01;
7428 48 robfinch
                        iccnt <= 3'b00;
7429
                        icstate <= IC2;
7430
                end
7431 49 robfinch
                else if (!ihit2 && `WAYS > 2) begin
7432 55 robfinch
                        if (thread_en) begin
7433
                                L1_adr <= {pcr[5:0],pc2[31:5],5'h0};
7434
                                L2_adr <= {pcr[5:0],pc2[31:5],5'h0};
7435
                        end
7436
                        else begin
7437
                                L1_adr <= {pcr[5:0],pc0plus12[31:5],5'h0};
7438
                                L2_adr <= {pcr[5:0],pc0plus12[31:5],5'h0};
7439
                        end
7440 49 robfinch
                        L1_invline <= TRUE;
7441
                        icwhich <= 2'b10;
7442
                        iccnt <= 3'b00;
7443
                        icstate <= IC2;
7444
                end
7445 48 robfinch
        end
7446
IC2:     icstate <= IC3;
7447
IC3:     icstate <= IC3a;
7448
IC3a:     icstate <= IC4;
7449
        // If data was in the L2 cache already there's no need to wait on the
7450
        // BIU to retrieve data. It can be determined if the hit signal was
7451
        // already active when this state was entered in which case waiting
7452
        // will do no good.
7453
        // The IC machine will stall in this state until the BIU has loaded the
7454
        // L2 cache. 
7455
IC4:
7456 49 robfinch
        if (ihitL2 && picstate==IC3a) begin
7457
                L1_en <= 9'h1FF;
7458 48 robfinch
                L1_wr0 <= TRUE;
7459 49 robfinch
                L1_wr1 <= TRUE && `WAYS > 1;
7460
                L1_wr2 <= TRUE && `WAYS > 2;
7461 48 robfinch
                L1_adr <= L2_adr;
7462
                L2_rdat <= L2_dato;
7463
                icstate <= IC5;
7464
        end
7465
        else if (bstate!=B9)
7466
                ;
7467
        else begin
7468 49 robfinch
                L1_en <= 9'h1FF;
7469 48 robfinch
                L1_wr0 <= TRUE;
7470 49 robfinch
                L1_wr1 <= TRUE && `WAYS > 1;
7471
                L1_wr2 <= TRUE && `WAYS > 2;
7472 48 robfinch
                L1_adr <= L2_adr;
7473
                L2_rdat <= L2_dato;
7474
                icstate <= IC5;
7475
        end
7476
IC5:
7477
        begin
7478 49 robfinch
                L1_en <= 9'h000;
7479 48 robfinch
                L1_wr0 <= FALSE;
7480
                L1_wr1 <= FALSE;
7481 49 robfinch
                L1_wr2 <= FALSE;
7482 48 robfinch
                icstate <= IC6;
7483
        end
7484
IC6:  icstate <= IC7;
7485
IC7:    icstate <= IC8;
7486
IC8:    begin
7487
             icstate <= IDLE;
7488
             icnxt <= TRUE;
7489
        end
7490
default:     icstate <= IDLE;
7491
endcase
7492
 
7493 49 robfinch
if (mem1_available && dram0_load)
7494 48 robfinch
case(dram0)
7495
`DRAMSLOT_AVAIL:        ;
7496
`DRAMSLOT_BUSY:         dram0 <= dram0 + !dram0_unc;
7497
3'd2:                           dram0 <= dram0 + 3'd1;
7498
3'd3:                           dram0 <= dram0 + 3'd1;
7499
3'd4:                           if (dhit0) dram0 <= `DRAMREQ_READY; else dram0 <= `DRAMSLOT_REQBUS;
7500
`DRAMSLOT_REQBUS:       ;
7501
`DRAMSLOT_HASBUS:       ;
7502
`DRAMREQ_READY:         ;
7503
endcase
7504
 
7505 49 robfinch
if (mem2_available && dram1_load && `NUM_MEM > 1)
7506 48 robfinch
case(dram1)
7507
`DRAMSLOT_AVAIL:        ;
7508
`DRAMSLOT_BUSY:         dram1 <= dram1 + !dram1_unc;
7509
3'd2:                           dram1 <= dram1 + 3'd1;
7510
3'd3:                           dram1 <= dram1 + 3'd1;
7511
3'd4:                           if (dhit1) dram1 <= `DRAMREQ_READY; else dram1 <= `DRAMSLOT_REQBUS;
7512
`DRAMSLOT_REQBUS:       ;
7513
`DRAMSLOT_HASBUS:       ;
7514
`DRAMREQ_READY:         ;
7515
endcase
7516
 
7517 49 robfinch
if (mem3_available && dram2_load && `NUM_MEM > 2)
7518 48 robfinch
case(dram2)
7519
`DRAMSLOT_AVAIL:        ;
7520
`DRAMSLOT_BUSY:         dram2 <= dram2 + !dram2_unc;
7521
3'd2:                           dram2 <= dram2 + 3'd1;
7522
3'd3:                           dram2 <= dram2 + 3'd1;
7523
3'd4:                           if (dhit2) dram2 <= `DRAMREQ_READY; else dram2 <= `DRAMSLOT_REQBUS;
7524
`DRAMSLOT_REQBUS:       ;
7525
`DRAMSLOT_HASBUS:       ;
7526
`DRAMREQ_READY:         ;
7527
endcase
7528
 
7529
// Bus Interface Unit (BIU)
7530
// Interfaces to the external bus which is WISHBONE compatible.
7531
// Stores take precedence over other operations.
7532
// Next data cache read misses are serviced.
7533
// Uncached data reads are serviced.
7534
// Finally L2 instruction cache misses are serviced.
7535
 
7536
case(bstate)
7537
BIDLE:
7538 49 robfinch
        begin
7539
                isCAS <= FALSE;
7540
                isAMO <= FALSE;
7541
                isInc <= FALSE;
7542
                isSpt <= FALSE;
7543
                isRMW <= FALSE;
7544
                rdvq <= 1'b0;
7545
                errq <= 1'b0;
7546
                exvq <= 1'b0;
7547
                bwhich <= 2'b00;
7548
                preload <= FALSE;
7549
`ifdef HAS_WB
7550
                if (wb_v[0] & wb_en) begin
7551
                        cyc_o <= `HIGH;
7552
                        stb_o <= `HIGH;
7553
                        we_o <= `HIGH;
7554
                        sel_o <= wb_sel[0];
7555
                        adr_o <= wb_addr[0];
7556
                        dat_o <= wb_data[0];
7557
                        ol_o  <= wb_ol[0];
7558
                        wbo_id <= wb_id[0];
7559 57 robfinch
        isStore <= TRUE;
7560 58 robfinch
                        bstate <= wb_rmw[0] ? B12 : B_DCacheStoreAck;
7561 49 robfinch
                end
7562
                begin
7563
                        for (j = 1; j < `WB_DEPTH; j = j + 1) begin
7564
                wb_v[j-1] <= wb_v[j];
7565
                wb_id[j-1] <= wb_id[j];
7566
                wb_rmw[j-1] <= wb_rmw[j];
7567
                wb_sel[j-1] <= wb_sel[j];
7568
                wb_addr[j-1] <= wb_addr[j];
7569
                wb_data[j-1] <= wb_data[j];
7570
                wb_ol[j-1] <= wb_ol[j];
7571
        end
7572
        wb_v[`WB_DEPTH-1] <= `INV;
7573
        wb_rmw[`WB_DEPTH-1] <= `FALSE;
7574
    end
7575
 
7576
`endif
7577
      if (~|wb_v && mem1_available && dram0==`DRAMSLOT_BUSY && dram0_rmw) begin
7578 48 robfinch
`ifdef SUPPORT_DBG
7579
            if (dbg_smatch0|dbg_lmatch0) begin
7580
                 dramA_v <= `TRUE;
7581
                 dramA_id <= dram0_id;
7582
                 dramA_exc <= `FLT_DBG;
7583
                 dramA_bus <= 64'h0;
7584
                 dram0 <= `DRAMSLOT_AVAIL;
7585
            end
7586
            else
7587
`endif
7588
            begin
7589
                 isRMW <= dram0_rmw;
7590
                 isCAS <= IsCAS(dram0_instr);
7591
                 isAMO <= IsAMO(dram0_instr);
7592
                 isInc <= IsInc(dram0_instr);
7593
                 casid <= dram0_id;
7594
                 bwhich <= 2'b00;
7595 49 robfinch
                 dram0 <= `DRAMSLOT_HASBUS;
7596 48 robfinch
                 cyc_o <= `HIGH;
7597
                 stb_o <= `HIGH;
7598
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7599
                 adr_o <= dram0_addr;
7600
                 dat_o <= fnDato(dram0_instr,dram0_data);
7601
                 ol_o  <= dram0_ol;
7602
                 bstate <= B12;
7603
            end
7604
        end
7605 49 robfinch
        else if (~|wb_v && mem2_available && dram1==`DRAMSLOT_BUSY && dram1_rmw && `NUM_MEM > 1) begin
7606 48 robfinch
`ifdef SUPPORT_DBG
7607
            if (dbg_smatch1|dbg_lmatch1) begin
7608
                 dramB_v <= `TRUE;
7609
                 dramB_id <= dram1_id;
7610
                 dramB_exc <= `FLT_DBG;
7611
                 dramB_bus <= 64'h0;
7612
                 dram1 <= `DRAMSLOT_AVAIL;
7613
            end
7614
            else
7615
`endif
7616
            begin
7617
                 isRMW <= dram1_rmw;
7618
                 isCAS <= IsCAS(dram1_instr);
7619
                 isAMO <= IsAMO(dram1_instr);
7620
                 isInc <= IsInc(dram1_instr);
7621
                 casid <= dram1_id;
7622
                 bwhich <= 2'b01;
7623 49 robfinch
                 dram1 <= `DRAMSLOT_HASBUS;
7624 48 robfinch
                 cyc_o <= `HIGH;
7625
                 stb_o <= `HIGH;
7626
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7627
                 adr_o <= dram1_addr;
7628
                 dat_o <= fnDato(dram1_instr,dram1_data);
7629
                 ol_o  <= dram1_ol;
7630
                 bstate <= B12;
7631
            end
7632
        end
7633 49 robfinch
        else if (~|wb_v && mem3_available && dram2==`DRAMSLOT_BUSY && dram2_rmw && `NUM_MEM > 2) begin
7634 48 robfinch
`ifdef SUPPORT_DBG
7635
            if (dbg_smatch2|dbg_lmatch2) begin
7636
                 dramC_v <= `TRUE;
7637
                 dramC_id <= dram2_id;
7638
                 dramC_exc <= `FLT_DBG;
7639
                 dramC_bus <= 64'h0;
7640
                 dram2 <= `DRAMSLOT_AVAIL;
7641
            end
7642
            else
7643
`endif
7644
            begin
7645
                 isRMW <= dram2_rmw;
7646
                 isCAS <= IsCAS(dram2_instr);
7647
                 isAMO <= IsAMO(dram2_instr);
7648
                 isInc <= IsInc(dram2_instr);
7649
                 casid <= dram2_id;
7650
                 bwhich <= 2'b10;
7651 49 robfinch
                 dram2 <= `DRAMSLOT_HASBUS;
7652 48 robfinch
                 cyc_o <= `HIGH;
7653
                 stb_o <= `HIGH;
7654
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
7655
                 adr_o <= dram2_addr;
7656
                 dat_o <= fnDato(dram2_instr,dram2_data);
7657
                 ol_o  <= dram2_ol;
7658
                 bstate <= B12;
7659
            end
7660
        end
7661 50 robfinch
        else if (mem1_available && dram0==`DRAMSLOT_BUSY && dram0_store) begin
7662 48 robfinch
`ifdef SUPPORT_DBG
7663
            if (dbg_smatch0) begin
7664
                 dramA_v <= `TRUE;
7665
                 dramA_id <= dram0_id;
7666
                 dramA_exc <= `FLT_DBG;
7667
                 dramA_bus <= 64'h0;
7668
                 dram0 <= `DRAMSLOT_AVAIL;
7669
            end
7670
            else
7671
`endif
7672
            begin
7673 49 robfinch
                                                        bwhich <= 2'b00;
7674
`ifndef HAS_WB
7675
                                                        dram0 <= `DRAMSLOT_HASBUS;
7676
                                                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
7677
                 cyc_o <= `HIGH;
7678
                 stb_o <= `HIGH;
7679 48 robfinch
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7680
                 adr_o <= dram0_addr;
7681
                 dat_o <= fnDato(dram0_instr,dram0_data);
7682
                 ol_o  <= dram0_ol;
7683 57 robfinch
                                        isStore <= TRUE;
7684 58 robfinch
                 bstate <= B_DCacheStoreAck;
7685 49 robfinch
`else
7686
                                                                if (wbptr<`WB_DEPTH-1) begin
7687
                                                                        dram0 <= `DRAMREQ_READY;
7688
                                                                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
7689
                                                                        wb_update(
7690
                                                                                dram0_id,
7691
                                                                                `FALSE,
7692
                                                                                fnSelect(dram0_instr,dram0_addr),
7693
                                                                                dram0_ol,
7694
                                                                                dram0_addr,
7695
                                                                                fnDato(dram0_instr,dram0_data)
7696
                                                                        );
7697
                                                                        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
7698
                                                                        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
7699
                                                                end
7700
`endif
7701
//                 cr_o <= IsSWC(dram0_instr);
7702 48 robfinch
            end
7703
        end
7704 50 robfinch
        else if (mem2_available && dram1==`DRAMSLOT_BUSY && dram1_store && `NUM_MEM > 1) begin
7705 48 robfinch
`ifdef SUPPORT_DBG
7706
            if (dbg_smatch1) begin
7707
                 dramB_v <= `TRUE;
7708
                 dramB_id <= dram1_id;
7709
                 dramB_exc <= `FLT_DBG;
7710
                 dramB_bus <= 64'h0;
7711
                 dram1 <= `DRAMSLOT_AVAIL;
7712
            end
7713
            else
7714
`endif
7715
            begin
7716 49 robfinch
                 bwhich <= 2'b01;
7717
`ifndef HAS_WB
7718 48 robfinch
                 dram1 <= `DRAMSLOT_HASBUS;
7719
                 dram1_instr[`INSTRUCTION_OP] <= `NOP;
7720 49 robfinch
                 cyc_o <= `HIGH;
7721
                 stb_o <= `HIGH;
7722 48 robfinch
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7723
                 adr_o <= dram1_addr;
7724
                 dat_o <= fnDato(dram1_instr,dram1_data);
7725
                 ol_o  <= dram1_ol;
7726 57 robfinch
                                        isStore <= TRUE;
7727 58 robfinch
                 bstate <= B_DCacheStoreAck;
7728 49 robfinch
`else
7729
                                                                if (wbptr<`WB_DEPTH-1) begin
7730
                                                                        dram1 <= `DRAMREQ_READY;
7731
                        dram1_instr[`INSTRUCTION_OP] <= `NOP;
7732
                                                                        wb_update(
7733
                                                                                dram1_id,
7734
                                                                                `FALSE,
7735
                                                                                fnSelect(dram1_instr,dram1_addr),
7736
                                                                                dram1_ol,
7737
                                                                                dram1_addr,
7738
                                                                                fnDato(dram1_instr,dram1_data)
7739
                                                                        );
7740
                                                                        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
7741
                                                                        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
7742
                                                                end
7743
`endif
7744
//                 cr_o <= IsSWC(dram0_instr);
7745 48 robfinch
            end
7746
        end
7747 50 robfinch
        else if (mem3_available && dram2==`DRAMSLOT_BUSY && dram2_store && `NUM_MEM > 2) begin
7748 48 robfinch
`ifdef SUPPORT_DBG
7749
            if (dbg_smatch2) begin
7750
                 dramC_v <= `TRUE;
7751
                 dramC_id <= dram2_id;
7752
                 dramC_exc <= `FLT_DBG;
7753
                 dramC_bus <= 64'h0;
7754
                 dram2 <= `DRAMSLOT_AVAIL;
7755
            end
7756
            else
7757
`endif
7758
            begin
7759 49 robfinch
                 bwhich <= 2'b10;
7760
`ifndef HAS_WB
7761 48 robfinch
                 dram2 <= `DRAMSLOT_HASBUS;
7762
                 dram2_instr[`INSTRUCTION_OP] <= `NOP;
7763 49 robfinch
                 cyc_o <= `HIGH;
7764
                 stb_o <= `HIGH;
7765 48 robfinch
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
7766
                 adr_o <= dram2_addr;
7767
                 dat_o <= fnDato(dram2_instr,dram2_data);
7768
                 ol_o  <= dram2_ol;
7769 57 robfinch
                                        isStore <= TRUE;
7770 58 robfinch
                 bstate <= B_DCacheStoreAck;
7771 49 robfinch
`else
7772
                                                                if (wbptr<`WB_DEPTH-1) begin
7773
                                                                        dram2 <= `DRAMREQ_READY;
7774
                        dram2_instr[`INSTRUCTION_OP] <= `NOP;
7775
                                                                        wb_update(
7776
                                                                                dram2_id,
7777
                                                                                `FALSE,
7778
                                                                                fnSelect(dram2_instr,dram2_addr),
7779
                                                                                dram2_ol,
7780
                                                                                dram2_addr,
7781
                                                                                fnDato(dram2_instr,dram2_data)
7782
                                                                        );
7783
                                                                        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
7784
                                                                        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
7785
                                                                end
7786
`endif
7787
//                 cr_o <= IsSWC(dram0_instr);
7788 48 robfinch
            end
7789
        end
7790
        // Check for read misses on the data cache
7791 51 robfinch
        else if (~|wb_v && mem1_available && !dram0_unc && dram0==`DRAMSLOT_REQBUS && dram0_load) begin
7792 48 robfinch
`ifdef SUPPORT_DBG
7793
            if (dbg_lmatch0) begin
7794
                 dramA_v <= `TRUE;
7795
                 dramA_id <= dram0_id;
7796
                 dramA_exc <= `FLT_DBG;
7797
                 dramA_bus <= 64'h0;
7798
                 dram0 <= `DRAMSLOT_AVAIL;
7799
            end
7800
            else
7801
`endif
7802
            begin
7803
                 dram0 <= `DRAMSLOT_HASBUS;
7804
                 bwhich <= 2'b00;
7805
                 preload <= dram0_preload;
7806 58 robfinch
                 bstate <= B_DCacheLoadStart;
7807 48 robfinch
            end
7808
        end
7809 49 robfinch
        else if (~|wb_v && mem2_available && !dram1_unc && dram1==`DRAMSLOT_REQBUS && dram1_load && `NUM_MEM > 1) begin
7810 48 robfinch
`ifdef SUPPORT_DBG
7811
            if (dbg_lmatch1) begin
7812
                 dramB_v <= `TRUE;
7813
                 dramB_id <= dram1_id;
7814
                 dramB_exc <= `FLT_DBG;
7815
                 dramB_bus <= 64'h0;
7816
                 dram1 <= `DRAMSLOT_AVAIL;
7817
            end
7818
            else
7819
`endif
7820
            begin
7821
                 dram1 <= `DRAMSLOT_HASBUS;
7822
                 bwhich <= 2'b01;
7823
                 preload <= dram1_preload;
7824 58 robfinch
                 bstate <= B_DCacheLoadStart;
7825 48 robfinch
            end
7826
        end
7827 49 robfinch
        else if (~|wb_v && mem3_available && !dram2_unc && dram2==`DRAMSLOT_REQBUS && dram2_load && `NUM_MEM > 2) begin
7828 48 robfinch
`ifdef SUPPORT_DBG
7829
            if (dbg_lmatch2) begin
7830
                 dramC_v <= `TRUE;
7831
                 dramC_id <= dram2_id;
7832
                 dramC_exc <= `FLT_DBG;
7833
                 dramC_bus <= 64'h0;
7834
                 dram2 <= `DRAMSLOT_AVAIL;
7835
            end
7836
            else
7837
`endif
7838
            begin
7839
                 dram2 <= `DRAMSLOT_HASBUS;
7840
                 preload <= dram2_preload;
7841
                 bwhich <= 2'b10;
7842 58 robfinch
                 bstate <= B_DCacheLoadStart;
7843 48 robfinch
            end
7844
        end
7845 49 robfinch
        else if (~|wb_v && mem1_available && dram0_unc && dram0==`DRAMSLOT_BUSY && dram0_load) begin
7846 48 robfinch
`ifdef SUPPORT_DBG
7847
            if (dbg_lmatch0) begin
7848
                 dramA_v <= `TRUE;
7849
                 dramA_id <= dram0_id;
7850
                 dramA_exc <= `FLT_DBG;
7851
                 dramA_bus <= 64'h0;
7852
                 dram0 <= `DRAMSLOT_AVAIL;
7853
            end
7854
            else
7855
`endif
7856
            begin
7857
                 bwhich <= 2'b00;
7858
                 cyc_o <= `HIGH;
7859
                 stb_o <= `HIGH;
7860
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7861
                 adr_o <= {dram0_addr[31:3],3'b0};
7862
                 sr_o <=  IsLWR(dram0_instr);
7863
                 ol_o  <= dram0_ol;
7864
                 bstate <= B12;
7865
            end
7866
        end
7867 49 robfinch
        else if (~|wb_v && mem2_available && dram1_unc && dram1==`DRAMSLOT_BUSY && dram1_load && `NUM_MEM > 1) begin
7868 48 robfinch
`ifdef SUPPORT_DBG
7869
            if (dbg_lmatch1) begin
7870
                 dramB_v <= `TRUE;
7871
                 dramB_id <= dram1_id;
7872
                 dramB_exc <= `FLT_DBG;
7873
                 dramB_bus <= 64'h0;
7874
                 dram1 <= `DRAMSLOT_AVAIL;
7875
            end
7876
            else
7877
`endif
7878
            begin
7879
                 bwhich <= 2'b01;
7880
                 cyc_o <= `HIGH;
7881
                 stb_o <= `HIGH;
7882
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7883
                 adr_o <= {dram1_addr[31:3],3'b0};
7884
                 sr_o <=  IsLWR(dram1_instr);
7885
                 ol_o  <= dram1_ol;
7886
                 bstate <= B12;
7887
            end
7888
        end
7889 49 robfinch
        else if (~|wb_v && mem3_available && dram2_unc && dram2==`DRAMSLOT_BUSY && dram2_load && `NUM_MEM > 2) begin
7890 48 robfinch
`ifdef SUPPORT_DBG
7891
            if (dbg_lmatch2) begin
7892
                 dramC_v <= `TRUE;
7893
                 dramC_id <= dram2_id;
7894
                 dramC_exc <= `FLT_DBG;
7895
                 dramC_bus <= 64'h0;
7896
                 dram2 <= 2'd0;
7897
            end
7898
            else
7899
`endif
7900
            begin
7901
                 bwhich <= 2'b10;
7902
                 cyc_o <= `HIGH;
7903
                 stb_o <= `HIGH;
7904
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
7905
                 adr_o <= {dram2_addr[31:3],3'b0};
7906
                 sr_o <=  IsLWR(dram2_instr);
7907
                 ol_o  <= dram2_ol;
7908
                 bstate <= B12;
7909
            end
7910
        end
7911
        // Check for L2 cache miss
7912 49 robfinch
        else if (~|wb_v && !ihitL2) begin
7913 48 robfinch
             cti_o <= 3'b001;
7914 49 robfinch
             bte_o <= 2'b00;//2'b01;    // 4 beat burst wrap
7915 48 robfinch
             cyc_o <= `HIGH;
7916
             stb_o <= `HIGH;
7917
             sel_o <= 8'hFF;
7918
             icl_o <= `HIGH;
7919 49 robfinch
             iccnt <= 3'd0;
7920 48 robfinch
//            adr_o <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
7921
//            L2_adr <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
7922
             adr_o <= {pcr[5:0],L1_adr[31:5],5'h0};
7923
             ol_o  <= ol[0];
7924
             L2_adr <= {pcr[5:0],L1_adr[31:5],5'h0};
7925
             L2_xsel <= 1'b0;
7926
             bstate <= B7;
7927
        end
7928
    end
7929
// Terminal state for a store operation.
7930 49 robfinch
// Note that if only a single memory channel is selected, bwhich will be a
7931
// constant 0. This should cause the extra code to be removed.
7932 58 robfinch
B_DCacheStoreAck:
7933 48 robfinch
    if (acki|err_i) begin
7934
         isStore <= `TRUE;
7935
         cyc_o <= `LOW;
7936
         stb_o <= `LOW;
7937
         we_o <= `LOW;
7938
         cr_o <= 1'b0;
7939
        // This isn't a good way of doing things; the state should be propagated
7940
        // to the commit stage, however since this is a store we know there will
7941
        // be no change of program flow. So the reservation status bit is set
7942
        // here. The author wanted to avoid the complexity of propagating the
7943
        // input signal to the commit stage. It does mean that the SWC
7944
        // instruction should be surrounded by SYNC's.
7945
        if (cr_o)
7946
             sema[0] <= rbi_i;
7947 49 robfinch
`ifdef HAS_WB
7948
                                for (n = 0; n < QENTRIES; n = n + 1) begin
7949
                                        if (wbo_id[n]) begin
7950
                        iqentry_exc[n] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7951
                        if (err_i|wrv_i) begin
7952
                                iqentry_a1[n] <= adr_o;
7953
                                wb_v <= 8'h00;          // Invalidate write buffer if there is a problem with the store
7954
                                wb_en <= `FALSE;        // and disable write buffer
7955
                        end
7956
                                                iqentry_cmt[n] <= `VAL;
7957
                                                iqentry_aq[n] <= `INV;
7958
                                        end
7959
                                end
7960
`else
7961 48 robfinch
        case(bwhich)
7962 58 robfinch
        2'd0:   begin
7963 48 robfinch
                 dram0 <= `DRAMREQ_READY;
7964
                 iqentry_exc[dram0_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7965
                if (err_i|wrv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
7966 49 robfinch
                                                                        iqentry_cmt[ dram0_id[`QBITS] ] <= `VAL;
7967
                                                                        iqentry_aq[ dram0_id[`QBITS] ] <= `INV;
7968 48 robfinch
                        //iqentry_out[ dram0_id[`QBITS] ] <= `INV;
7969
                end
7970 49 robfinch
        2'd1:   if (`NUM_MEM > 1) begin
7971 48 robfinch
                 dram1 <= `DRAMREQ_READY;
7972
                 iqentry_exc[dram1_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7973
                if (err_i|wrv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
7974 49 robfinch
                                                                        iqentry_cmt[ dram1_id[`QBITS] ] <= `VAL;
7975
                                                                        iqentry_aq[ dram1_id[`QBITS] ] <= `INV;
7976 48 robfinch
                        //iqentry_out[ dram1_id[`QBITS] ] <= `INV;
7977
                end
7978 49 robfinch
        2'd2:   if (`NUM_MEM > 2) begin
7979 48 robfinch
                 dram2 <= `DRAMREQ_READY;
7980
                 iqentry_exc[dram2_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7981
                if (err_i|wrv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
7982 49 robfinch
                                                                        iqentry_cmt[ dram2_id[`QBITS] ] <= `VAL;
7983
                                                                        iqentry_aq[ dram2_id[`QBITS] ] <= `INV;
7984 48 robfinch
                        //iqentry_out[ dram2_id[`QBITS] ] <= `INV;
7985
                end
7986
        default:    ;
7987
        endcase
7988 49 robfinch
`endif
7989 48 robfinch
         bstate <= B19;
7990
    end
7991 58 robfinch
B_DCacheLoadStart:
7992 48 robfinch
    begin
7993
    dccnt <= 2'd0;
7994
    case(bwhich)
7995
    2'd0:   begin
7996
             cti_o <= 3'b001;
7997
             bte_o <= 2'b01;
7998
             cyc_o <= `HIGH;
7999
             stb_o <= `HIGH;
8000
             sel_o <= fnSelect(dram0_instr,dram0_addr);
8001
             adr_o <= {dram0_addr[31:5],5'b0};
8002
             ol_o  <= dram0_ol;
8003 58 robfinch
             bstate <= B_DCacheLoadAck;
8004 48 robfinch
            end
8005 49 robfinch
    2'd1:   if (`NUM_MEM > 1) begin
8006 48 robfinch
             cti_o <= 3'b001;
8007
             bte_o <= 2'b01;
8008
             cyc_o <= `HIGH;
8009
             stb_o <= `HIGH;
8010
             sel_o <= fnSelect(dram1_instr,dram1_addr);
8011
             adr_o <= {dram1_addr[31:5],5'b0};
8012
             ol_o  <= dram1_ol;
8013 58 robfinch
             bstate <= B_DCacheLoadAck;
8014 48 robfinch
            end
8015 49 robfinch
    2'd2:   if (`NUM_MEM > 2) begin
8016 48 robfinch
             cti_o <= 3'b001;
8017
             bte_o <= 2'b01;
8018
             cyc_o <= `HIGH;
8019
             stb_o <= `HIGH;
8020
             sel_o <= fnSelect(dram2_instr,dram2_addr);
8021
             adr_o <= {dram2_addr[31:5],5'b0};
8022
             ol_o  <= dram2_ol;
8023 58 robfinch
             bstate <= B_DCacheLoadAck;
8024 48 robfinch
            end
8025
    default:    if (~acki)  bstate <= BIDLE;
8026
    endcase
8027
    end
8028
// Data cache load terminal state
8029 58 robfinch
B_DCacheLoadAck:
8030 48 robfinch
    if (ack_i|err_i) begin
8031
        errq <= errq | err_i;
8032
        rdvq <= rdvq | rdv_i;
8033
        if (!preload)   // A preload instruction ignores any error
8034
        case(bwhich)
8035
        2'd0:   if (err_i|rdv_i) begin
8036
                     iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8037
                     iqentry_exc[dram0_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8038
                end
8039 49 robfinch
        2'd1:   if ((err_i|rdv_i) && `NUM_MEM > 1) begin
8040 48 robfinch
                     iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8041
                     iqentry_exc[dram1_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8042
                end
8043 49 robfinch
        2'd2:   if ((err_i|rdv_i) && `NUM_MEM > 2) begin
8044 48 robfinch
                     iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8045
                     iqentry_exc[dram2_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8046
                end
8047
        default:    ;
8048
        endcase
8049
        dccnt <= dccnt + 2'd1;
8050
        adr_o[4:3] <= adr_o[4:3] + 2'd1;
8051 58 robfinch
        bstate <= B_DCacheLoadAck;
8052 48 robfinch
        if (dccnt==2'd2)
8053
             cti_o <= 3'b111;
8054
        if (dccnt==2'd3) begin
8055
             cti_o <= 3'b000;
8056
             bte_o <= 2'b00;
8057
             cyc_o <= `LOW;
8058
             stb_o <= `LOW;
8059
             sel_o <= 8'h00;
8060 58 robfinch
             bstate <= B_DCacheLoadWait1;
8061 48 robfinch
        end
8062
    end
8063 58 robfinch
B_DCacheLoadStb:
8064
        begin
8065
                stb_o <= `HIGH;
8066
                bstate <= B_DCacheLoadAck;
8067
  end
8068
B_DCacheLoadWait1: bstate <= B_DCacheLoadWait2;
8069
B_DCacheLoadWait2: bstate <= B_DCacheLoadResetBusy;
8070
//B_DCacheLoadWait3: bstate <= B_DCacheLoadResetBusy;
8071
B_DCacheLoadResetBusy: begin
8072
    // There could be more than one memory cycle active. We reset the state
8073
    // of all the machines to retest for a hit because otherwise sequential
8074
    // loading of memory will cause successive machines to miss resulting in 
8075
    // multiple dcache loads that aren't needed.
8076
    if (dram0 != `DRAMSLOT_AVAIL && dram0_addr[31:5]==adr_o[31:5]) dram0 <= `DRAMSLOT_BUSY;  // causes retest of dhit
8077
    if (dram1 != `DRAMSLOT_AVAIL && dram1_addr[31:5]==adr_o[31:5]) dram1 <= `DRAMSLOT_BUSY;
8078
    if (dram2 != `DRAMSLOT_AVAIL && dram2_addr[31:5]==adr_o[31:5]) dram2 <= `DRAMSLOT_BUSY;
8079 48 robfinch
    if (~ack_i)  bstate <= BIDLE;
8080
    end
8081
 
8082
// Ack state for instruction cache load
8083
B7:
8084
    if (ack_i|err_i) begin
8085
        errq <= errq | err_i;
8086
        exvq <= exvq | exv_i;
8087 49 robfinch
//        L1_en <= 9'h3 << {L2_xsel,L2_adr[4:3],1'b0};
8088 48 robfinch
//        L1_wr0 <= `TRUE;
8089
//        L1_wr1 <= `TRUE;
8090
//        L1_adr <= L2_adr;
8091
        if (err_i)
8092 49 robfinch
                L2_rdat <= {9{11'b0,4'd7,1'b0,`FLT_IBE,2'b00,`BRK}};
8093 48 robfinch
        else
8094 49 robfinch
                L2_rdat <= {dat_i[31:0],{4{dat_i}}};
8095 48 robfinch
        iccnt <= iccnt + 3'd1;
8096
        //stb_o <= `LOW;
8097
        if (iccnt==3'd3)
8098
            cti_o <= 3'b111;
8099
        if (iccnt==3'd4) begin
8100
            cti_o <= 3'b000;
8101
            bte_o <= 2'b00;             // linear burst
8102
            cyc_o <= `LOW;
8103
            stb_o <= `LOW;
8104
            sel_o <= 8'h00;
8105
            icl_o <= `LOW;
8106
            bstate <= B9;
8107
        end
8108
        else begin
8109
            L2_adr[4:3] <= L2_adr[4:3] + 2'd1;
8110
            if (L2_adr[4:3]==2'b11)
8111
                L2_xsel <= 1'b1;
8112
        end
8113
    end
8114
B9:
8115
        begin
8116
                L1_wr0 <= `FALSE;
8117
                L1_wr1 <= `FALSE;
8118 49 robfinch
                L1_wr2 <= `FALSE;
8119
                L1_en <= 9'h1FF;
8120 48 robfinch
                L2_xsel <= 1'b0;
8121
                if (~ack_i) begin
8122
                        bstate <= BIDLE;
8123
                        L2_nxt <= TRUE;
8124
                end
8125
        end
8126
B12:
8127
    if (ack_i|err_i) begin
8128
        if (isCAS) begin
8129
             iqentry_res        [ casid[`QBITS] ] <= (dat_i == cas);
8130
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8131
             iqentry_done[ casid[`QBITS] ] <= `VAL;
8132
             iqentry_instr[ casid[`QBITS]] <= `NOP_INSN;
8133
             iqentry_out [ casid[`QBITS] ] <= `INV;
8134
            if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
8135
            if (dat_i == cas) begin
8136
                 stb_o <= `LOW;
8137
                 we_o <= `TRUE;
8138
                 bstate <= B15;
8139
            end
8140
            else begin
8141
                 cas <= dat_i;
8142
                 cyc_o <= `LOW;
8143
                 stb_o <= `LOW;
8144
                case(bwhich)
8145
                2'b00:   dram0 <= `DRAMREQ_READY;
8146
                2'b01:   dram1 <= `DRAMREQ_READY;
8147
                2'b10:   dram2 <= `DRAMREQ_READY;
8148
                default:    ;
8149
                endcase
8150
                 bstate <= B19;
8151
            end
8152
        end
8153
        else if (isRMW) begin
8154
             rmw_instr <= iqentry_instr[casid[`QBITS]];
8155
             rmw_argA <= dat_i;
8156
                 if (isSpt) begin
8157
                        rmw_argB <= 64'd1 << iqentry_a1[casid[`QBITS]][63:58];
8158
                        rmw_argC <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ?
8159
                                                iqentry_a3[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58] :
8160
                                                iqentry_a2[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58];
8161
                 end
8162
                 else if (isInc) begin
8163
                        rmw_argB <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ? {{59{iqentry_instr[casid[`QBITS]][22]}},iqentry_instr[casid[`QBITS]][22:18]} :
8164
                                                                                                                                 {{59{iqentry_instr[casid[`QBITS]][17]}},iqentry_instr[casid[`QBITS]][17:13]};
8165
                 end
8166
                 else begin // isAMO
8167
                     iqentry_res [ casid[`QBITS] ] <= dat_i;
8168
                     rmw_argB <= iqentry_instr[casid[`QBITS]][31] ? {{59{iqentry_instr[casid[`QBITS]][20:16]}},iqentry_instr[casid[`QBITS]][20:16]} : iqentry_a2[casid[`QBITS]];
8169
                 end
8170
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8171
             if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
8172
             stb_o <= `LOW;
8173
             bstate <= B20;
8174
                end
8175
        else begin
8176
             cyc_o <= `LOW;
8177
             stb_o <= `LOW;
8178
             sr_o <= `LOW;
8179
             xdati <= dat_i;
8180
            case(bwhich)
8181
            2'b00:  begin
8182
                     dram0 <= `DRAMREQ_READY;
8183
                     iqentry_exc [ dram0_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8184
                    if (err_i|rdv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8185
                    end
8186 49 robfinch
            2'b01:  if (`NUM_MEM > 1) begin
8187 48 robfinch
                     dram1 <= `DRAMREQ_READY;
8188
                     iqentry_exc [ dram1_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8189
                    if (err_i|rdv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8190
                    end
8191 49 robfinch
            2'b10:  if (`NUM_MEM > 2) begin
8192 48 robfinch
                     dram2 <= `DRAMREQ_READY;
8193
                     iqentry_exc [ dram2_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8194
                    if (err_i|rdv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8195
                    end
8196
            default:    ;
8197
            endcase
8198
             bstate <= B19;
8199
        end
8200
    end
8201
// Three cycles to detemrine if there's a cache hit during a store.
8202
B16:    begin
8203
            case(bwhich)
8204
            2'd0:      if (dhit0) begin  dram0 <= `DRAMREQ_READY; bstate <= B17; end
8205
            2'd1:      if (dhit1) begin  dram1 <= `DRAMREQ_READY; bstate <= B17; end
8206
            2'd2:      if (dhit2) begin  dram2 <= `DRAMREQ_READY; bstate <= B17; end
8207
            default:    bstate <= BIDLE;
8208
            endcase
8209
            end
8210
B17:     bstate <= B18;
8211
B18:     bstate <= B19;
8212 57 robfinch
B19:    if (~acki)  begin
8213
                                        sel_o <= 8'h00;
8214
                                        bstate <= BIDLE;
8215
                                        isStore <= `FALSE;
8216
                                end
8217 48 robfinch
B20:
8218
        if (~ack_i) begin
8219
                stb_o <= `HIGH;
8220
                we_o  <= `HIGH;
8221
                dat_o <= fnDato(rmw_instr,rmw_res);
8222 58 robfinch
                bstate <= B_DCacheStoreAck;
8223 48 robfinch
        end
8224
B21:
8225
        if (~ack_i) begin
8226
                stb_o <= `HIGH;
8227
                bstate <= B12;
8228
        end
8229
default:     bstate <= BIDLE;
8230
endcase
8231
 
8232
if (!branchmiss) begin
8233
    case({fetchbuf0_v, fetchbuf1_v})
8234
    2'b00:  ;
8235
    2'b01:
8236
        if (canq1) begin
8237
                tail0 <= idp1(tail0);
8238
                tail1 <= idp1(tail1);
8239
        end
8240
    2'b10:
8241
        if (canq1) begin
8242
            tail0 <= idp1(tail0);
8243
            tail1 <= idp1(tail1);
8244
        end
8245
    2'b11:
8246
        if (canq1) begin
8247
            if (IsBranch(fetchbuf0_instr) && predict_taken0 && fetchbuf0_thrd==fetchbuf1_thrd) begin
8248
                 tail0 <= idp1(tail0);
8249
                 tail1 <= idp1(tail1);
8250
            end
8251
            else begin
8252
                                if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
8253
                        if (canq2) begin
8254
                             tail0 <= idp2(tail0);
8255
                             tail1 <= idp2(tail1);
8256
                        end
8257
                        else begin    // queued1 will be true
8258
                             tail0 <= idp1(tail0);
8259
                             tail1 <= idp1(tail1);
8260
                        end
8261
                end
8262
            end
8263
        end
8264
    endcase
8265
end
8266 52 robfinch
else if (!thread_en) begin      // if branchmiss
8267 48 robfinch
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
8268 52 robfinch
         tail0 <= 4'd0;
8269
         tail1 <= 4'd1;
8270 48 robfinch
    end
8271
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
8272 52 robfinch
         tail0 <= 4'd1;
8273
         tail1 <= 4'd2;
8274 48 robfinch
    end
8275
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
8276 52 robfinch
         tail0 <= 4'd2;
8277
         tail1 <= 4'd3;
8278 48 robfinch
    end
8279
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
8280 52 robfinch
         tail0 <= 4'd3;
8281
         tail1 <= 4'd4;
8282 48 robfinch
    end
8283
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
8284 52 robfinch
         tail0 <= 4'd4;
8285
         tail1 <= 4'd5;
8286 48 robfinch
    end
8287
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
8288 52 robfinch
         tail0 <= 4'd5;
8289
         tail1 <= 4'd6;
8290 48 robfinch
    end
8291
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
8292 52 robfinch
         tail0 <= 4'd6;
8293
         tail1 <= 4'd7;
8294 48 robfinch
    end
8295
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
8296 52 robfinch
         tail0 <= 4'd7;
8297
         tail1 <= 4'd8;
8298 48 robfinch
    end
8299 52 robfinch
    else if (iqentry_stomp[8] & ~iqentry_stomp[7]) begin
8300
         tail0 <= 4'd8;
8301
         tail1 <= 4'd9;
8302
    end
8303
    else if (iqentry_stomp[9] & ~iqentry_stomp[8]) begin
8304
         tail0 <= 4'd9;
8305
         tail1 <= 4'd0;
8306
    end
8307 48 robfinch
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
8308
end
8309 51 robfinch
 
8310 48 robfinch
/*
8311
    if (pebm)
8312
         seq_num <= seq_num + 5'd3;
8313
    else if (queued2)
8314
         seq_num <= seq_num + 5'd2;
8315
    else if (queued1)
8316
         seq_num <= seq_num + 5'd1;
8317
*/
8318
//      #5 rf[0] = 0; rf_v[0] = 1; rf_source[0] = 0;
8319 51 robfinch
`ifdef SIM
8320 48 robfinch
        $display("\n\n\n\n\n\n\n\n");
8321
        $display("TIME %0d", $time);
8322
        $display("%h #", pc0);
8323
`ifdef SUPPORT_SMT
8324
    $display ("Regfile: %d", rgs[0]);
8325
        for (n=0; n < 32; n=n+4) begin
8326
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8327
               n[4:0]+0, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8328
               n[4:0]+1, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8329
               n[4:0]+2, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8330
               n[4:0]+3, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8331
               );
8332
        end
8333
    $display ("Regfile: %d", rgs[1]);
8334
        for (n=128; n < 160; n=n+4) begin
8335
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8336
               n[4:0]+0, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8337
               n[4:0]+1, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8338
               n[4:0]+2, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8339
               n[4:0]+3, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8340
               );
8341
        end
8342
`else
8343
    $display ("Regfile: %d", rgs);
8344
        for (n=0; n < 32; n=n+4) begin
8345
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8346 57 robfinch
               n[4:0]+0, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8347
               n[4:0]+1, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8348
               n[4:0]+2, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8349
               n[4:0]+3, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8350 48 robfinch
               );
8351
        end
8352
`endif
8353 49 robfinch
`ifdef FCU_ENH
8354 48 robfinch
        $display("Call Stack:");
8355 49 robfinch
        for (n = 0; n < 16; n = n + 4)
8356 48 robfinch
                $display("%c%d: %h   %c%d: %h   %c%d: %h   %c%d: %h",
8357 57 robfinch
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+0 ?">" : " ", n[4:0]+0, gFetchbufInst.gb1.ufb1.ursb1.ras[n+0],
8358
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+1 ?">" : " ", n[4:0]+1, gFetchbufInst.gb1.ufb1.ursb1.ras[n+1],
8359
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+2 ?">" : " ", n[4:0]+2, gFetchbufInst.gb1.ufb1.ursb1.ras[n+2],
8360
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+3 ?">" : " ", n[4:0]+3, gFetchbufInst.gb1.ufb1.ursb1.ras[n+3]
8361 48 robfinch
                );
8362
        $display("\n");
8363 49 robfinch
`endif
8364 48 robfinch
//    $display("Return address stack:");
8365
//    for (n = 0; n < 16; n = n + 1)
8366
//        $display("%d %h", rasp+n[3:0], ras[rasp+n[3:0]]);
8367
        $display("TakeBr:%d #", take_branch);//, backpc);
8368 51 robfinch
        $display("Insn%d: %h", 0, insn0);
8369 57 robfinch
        if (`WAYS==1) begin
8370
        $display("%c%c A: %d %h %h #",
8371
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
8372
        $display("%c%c B: %d %h %h #",
8373
            45, fetchbuf?62:45, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
8374
        end
8375
        else if (`WAYS > 1) begin
8376 51 robfinch
                $display("Insn%d: %h", 1, insn1);
8377 48 robfinch
        $display("%c%c A: %d %h %h #",
8378
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
8379
        $display("%c%c B: %d %h %h #",
8380
            45, fetchbuf?45:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
8381 57 robfinch
        end
8382
        else if (`WAYS > 2) begin
8383
                $display("%c%c C: %d %h %h #",
8384
                    45, fetchbuf?62:45, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
8385
                $display("%c%c D: %d %h %h #",
8386
                    45, fetchbuf?62:45, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
8387
        end
8388 48 robfinch
        for (i=0; i<QENTRIES; i=i+1)
8389
            $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#",
8390
                 (i[`QBITS]==head0)?"C":".",
8391
                 (i[`QBITS]==tail0)?"Q":".",
8392
                  i[`QBITS],
8393
                 iqentry_v[i] ? "v" : "-",
8394
                 iqentry_iv[i] ? "I" : "-",
8395
                 iqentry_done[i]?"d":"-",
8396
                 iqentry_out[i]?"o":"-",
8397
                 iqentry_bt[i],
8398
                 iqentry_memissue[i],
8399
                 iqentry_agen[i] ? "a": "-",
8400
                 iqentry_alu0_issue[i]?"0":iqentry_alu1_issue[i]?"1":"-",
8401
                 iqentry_stomp[i]?"s":"-",
8402
                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",
8403
                iqentry_instr[i], iqentry_tgt[i][4:0],
8404
                iqentry_exc[i], iqentry_res[i], iqentry_a0[i], iqentry_a1[i], iqentry_a1_v[i],
8405
                iqentry_a1_s[i],
8406
                iqentry_a2[i], iqentry_a2_v[i], iqentry_a2_s[i],
8407
                iqentry_a3[i], iqentry_a3_v[i], iqentry_a3_s[i],
8408
                iqentry_thrd[i],
8409
                iqentry_pc[i],
8410
                iqentry_sn[i], iqentry_ven[i]
8411
                );
8412
    $display("DRAM");
8413
        $display("%d %h %h %c%h %o #",
8414
            dram0, dram0_addr, dram0_data, (IsFlowCtrl(dram0_instr) ? 98 : (IsMem(dram0_instr)) ? 109 : 97),
8415
            dram0_instr, dram0_id);
8416 49 robfinch
          if (`NUM_MEM > 1)
8417 48 robfinch
        $display("%d %h %h %c%h %o #",
8418
            dram1, dram1_addr, dram1_data, (IsFlowCtrl(dram1_instr) ? 98 : (IsMem(dram1_instr)) ? 109 : 97),
8419
            dram1_instr, dram1_id);
8420 49 robfinch
          if (`NUM_MEM > 2)
8421 48 robfinch
        $display("%d %h %h %c%h %o #",
8422
            dram2, dram2_addr, dram2_data, (IsFlowCtrl(dram2_instr) ? 98 : (IsMem(dram2_instr)) ? 109 : 97),
8423
            dram2_instr, dram2_id);
8424
        $display("%d %h %o %h #", dramA_v, dramA_bus, dramA_id, dramA_exc);
8425 49 robfinch
        if (`NUM_MEM > 1)
8426 48 robfinch
        $display("%d %h %o %h #", dramB_v, dramB_bus, dramB_id, dramB_exc);
8427 49 robfinch
        if (`NUM_MEM > 2)
8428 48 robfinch
        $display("%d %h %o %h #", dramC_v, dramC_bus, dramC_id, dramC_exc);
8429
    $display("ALU");
8430
        $display("%d %h %h %h %c%h %d %o %h #",
8431
                alu0_dataready, alu0_argI, alu0_argA, alu0_argB,
8432
                 (IsFlowCtrl(alu0_instr) ? 98 : IsMem(alu0_instr) ? 109 : 97),
8433
                alu0_instr, alu0_bt, alu0_sourceid, alu0_pc);
8434
        $display("%d %h %o 0 #", alu0_v, alu0_bus, alu0_id);
8435 49 robfinch
        if (`NUM_ALU > 1) begin
8436
                $display("%d %h %h %h %c%h %d %o %h #",
8437
                        alu1_dataready, alu1_argI, alu1_argA, alu1_argB,
8438
                        (IsFlowCtrl(alu1_instr) ? 98 : IsMem(alu1_instr) ? 109 : 97),
8439
                        alu1_instr, alu1_bt, alu1_sourceid, alu1_pc);
8440
                $display("%d %h %o 0 #", alu1_v, alu1_bus, alu1_id);
8441
        end
8442 48 robfinch
        $display("FCU");
8443
        $display("%d %h %h %h %h #", fcu_v, fcu_bus, fcu_argI, fcu_argA, fcu_argB);
8444 56 robfinch
        $display("%c %h %h %h %h #", fcu_branchmiss?"m":" ", fcu_sourceid, fcu_misspc, fcu_nextpc, fcu_brdisp);
8445 48 robfinch
    $display("Commit");
8446
        $display("0: %c %h %o %d #", commit0_v?"v":" ", commit0_bus, commit0_id, commit0_tgt[4:0]);
8447
        $display("1: %c %h %o %d #", commit1_v?"v":" ", commit1_bus, commit1_id, commit1_tgt[4:0]);
8448 58 robfinch
    $display("instructions committed: %d valid committed: %d ticks: %d ", CC, I, tick);
8449 49 robfinch
    $display("Write merges: %d", wb_merges);
8450 51 robfinch
`endif  // SIM
8451 48 robfinch
 
8452
//
8453
//      $display("\n\n\n\n\n\n\n\n");
8454
//      $display("TIME %0d", $time);
8455
//      $display("  pc0=%h", pc0);
8456
//      $display("  pc1=%h", pc1);
8457
//      $display("  reg0=%h, v=%d, src=%o", rf[0], rf_v[0], rf_source[0]);
8458
//      $display("  reg1=%h, v=%d, src=%o", rf[1], rf_v[1], rf_source[1]);
8459
//      $display("  reg2=%h, v=%d, src=%o", rf[2], rf_v[2], rf_source[2]);
8460
//      $display("  reg3=%h, v=%d, src=%o", rf[3], rf_v[3], rf_source[3]);
8461
//      $display("  reg4=%h, v=%d, src=%o", rf[4], rf_v[4], rf_source[4]);
8462
//      $display("  reg5=%h, v=%d, src=%o", rf[5], rf_v[5], rf_source[5]);
8463
//      $display("  reg6=%h, v=%d, src=%o", rf[6], rf_v[6], rf_source[6]);
8464
//      $display("  reg7=%h, v=%d, src=%o", rf[7], rf_v[7], rf_source[7]);
8465
 
8466
//      $display("Fetch Buffers:");
8467
//      $display("  %c%c fbA: v=%d instr=%h pc=%h     %c%c fbC: v=%d instr=%h pc=%h", 
8468
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc,
8469
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
8470
//      $display("  %c%c fbB: v=%d instr=%h pc=%h     %c%c fbD: v=%d instr=%h pc=%h", 
8471
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc,
8472
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
8473
//      $display("  branchback=%d backpc=%h", branchback, backpc);
8474
 
8475
//      $display("Instruction Queue:");
8476
//      for (i=0; i<8; i=i+1) 
8477
//          $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",
8478
//              (i[`QBITS]==head0)?72:32, (i[`QBITS]==tail0)?84:32, i,
8479
//              iqentry_v[i], iqentry_done[i], iqentry_out[i], iqentry_agen[i], iqentry_res[i], iqentry_op[i], 
8480
//              iqentry_bt[i], iqentry_tgt[i], iqentry_a1[i], iqentry_a1_v[i], iqentry_a1_s[i], iqentry_a2[i], iqentry_a2_v[i], 
8481
//              iqentry_a2_s[i], iqentry_a0[i], iqentry_pc[i], iqentry_exc[i]);
8482
 
8483
//      $display("Scheduling Status:");
8484
//      $display("  iqentry0 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8485
//              iqentry_0_issue, iqentry_0_islot, iqentry_stomp[0], iqentry_source[0], iqentry_memready[0], iqentry_memissue[0]);
8486
//      $display("  iqentry1 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8487
//              iqentry_1_issue, iqentry_1_islot, iqentry_stomp[1], iqentry_source[1], iqentry_memready[1], iqentry_memissue[1]);
8488
//      $display("  iqentry2 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8489
//              iqentry_2_issue, iqentry_2_islot, iqentry_stomp[2], iqentry_source[2], iqentry_memready[2], iqentry_memissue[2]);
8490
//      $display("  iqentry3 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8491
//              iqentry_3_issue, iqentry_3_islot, iqentry_stomp[3], iqentry_source[3], iqentry_memready[3], iqentry_memissue[3]);
8492
//      $display("  iqentry4 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8493
//              iqentry_4_issue, iqentry_4_islot, iqentry_stomp[4], iqentry_source[4], iqentry_memready[4], iqentry_memissue[4]);
8494
//      $display("  iqentry5 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8495
//              iqentry_5_issue, iqentry_5_islot, iqentry_stomp[5], iqentry_source[5], iqentry_memready[5], iqentry_memissue[5]);
8496
//      $display("  iqentry6 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8497
//              iqentry_6_issue, iqentry_6_islot, iqentry_stomp[6], iqentry_source[6], iqentry_memready[6], iqentry_memissue[6]);
8498
//      $display("  iqentry7 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8499
//              iqentry_7_issue, iqentry_7_islot, iqentry_stomp[7], iqentry_source[7], iqentry_memready[7], iqentry_memissue[7]);
8500
 
8501
//      $display("ALU Inputs:");
8502
//      $display("  0: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
8503
//              alu0_available, alu0_dataready, alu0_sourceid, alu0_op, alu0_argA,
8504
//              alu0_argB, alu0_argI, alu0_bt);
8505
//      $display("  1: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
8506
//              alu1_available, alu1_dataready, alu1_sourceid, alu1_op, alu1_argA,
8507
//              alu1_argB, alu1_argI, alu1_bt);
8508
 
8509
//      $display("ALU Outputs:");
8510
//      $display("  0: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
8511
//              alu0_v, alu0_bus, alu0_id, alu0_branchmiss, alu0_misspc, alu0_sourceid);
8512
//      $display("  1: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
8513
//              alu1_v, alu1_bus, alu1_id, alu1_branchmiss, alu1_misspc, alu1_sourceid);
8514
 
8515
//      $display("DRAM Status:");
8516
//      $display("  OUT: v=%d data=%h tgt=%d id=%o", dram_v, dram_bus, dram_tgt, dram_id);
8517
//      $display("  dram0: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
8518
//          dram0, dram0_addr, dram0_data, dram0_op, dram0_tgt, dram0_id);
8519
//      $display("  dram1: status=%h addr=%h data=%h op=%d tgt=%d id=%o", 
8520
//          dram1, dram1_addr, dram1_data, dram1_op, dram1_tgt, dram1_id);
8521
//      $display("  dram2: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
8522
//          dram2, dram2_addr, dram2_data, dram2_op, dram2_tgt, dram2_id);
8523
 
8524
//      $display("Commit Buses:");
8525
//      $display("  0: v=%d id=%o data=%h", commit0_v, commit0_id, commit0_bus);
8526
//      $display("  1: v=%d id=%o data=%h", commit1_v, commit1_id, commit1_bus);
8527
 
8528
//
8529
//      $display("Memory Contents:");
8530
//      for (j=0; j<64; j=j+16)
8531
//          $display("  %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h", 
8532
//              m[j+0], m[j+1], m[j+2], m[j+3], m[j+4], m[j+5], m[j+6], m[j+7],
8533
//              m[j+8], m[j+9], m[j+10], m[j+11], m[j+12], m[j+13], m[j+14], m[j+15]);
8534
 
8535
        $display("");
8536
 
8537
        if (|panic) begin
8538
            $display("");
8539
            $display("-----------------------------------------------------------------");
8540
            $display("-----------------------------------------------------------------");
8541
            $display("---------------     PANIC:%s     -----------------", message[panic]);
8542
            $display("-----------------------------------------------------------------");
8543
            $display("-----------------------------------------------------------------");
8544
            $display("");
8545
            $display("instructions committed: %d", I);
8546
            $display("total execution cycles: %d", $time / 10);
8547
            $display("");
8548
        end
8549
        if (|panic && ~outstanding_stores) begin
8550
            $finish;
8551
        end
8552
    for (n = 0; n < QENTRIES; n = n + 1)
8553
        if (branchmiss) begin
8554
            if (!setpred[n]) begin
8555
                 iqentry_instr[n][`INSTRUCTION_OP] <= `NOP;
8556
                 iqentry_done[n] <= `VAL;
8557
                 iqentry_cmt[n] <= `VAL;
8558
            end
8559
        end
8560
 
8561
        if (snr) begin
8562
                seq_num <= 32'd0;
8563
                seq_num1 <= 32'd0;
8564
        end
8565
end // clock domain
8566
/*
8567
always @(posedge clk)
8568
if (rst) begin
8569
     tail0 <= 3'd0;
8570
     tail1 <= 3'd1;
8571
end
8572
else begin
8573
if (!branchmiss) begin
8574
    case({fetchbuf0_v, fetchbuf1_v})
8575
    2'b00:  ;
8576
    2'b01:
8577
        if (canq1) begin
8578
             tail0 <= idp1(tail0);
8579
             tail1 <= idp1(tail1);
8580
        end
8581
    2'b10:
8582
        if (canq1) begin
8583
             tail0 <= idp1(tail0);
8584
             tail1 <= idp1(tail1);
8585
        end
8586
    2'b11:
8587
        if (canq1) begin
8588
            if (IsBranch(fetchbuf0_instr) && predict_taken0) begin
8589
                 tail0 <= idp1(tail0);
8590
                 tail1 <= idp1(tail1);
8591
            end
8592
            else begin
8593
                                if (vqe < vl || !IsVector(fetchbuf0_instr)) begin
8594
                        if (canq2) begin
8595
                             tail0 <= idp2(tail0);
8596
                             tail1 <= idp2(tail1);
8597
                        end
8598
                        else begin    // queued1 will be true
8599
                             tail0 <= idp1(tail0);
8600
                             tail1 <= idp1(tail1);
8601
                        end
8602
                end
8603
            end
8604
        end
8605
    endcase
8606
end
8607
else begin      // if branchmiss
8608
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
8609
         tail0 <= 3'd0;
8610
         tail1 <= 3'd1;
8611
    end
8612
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
8613
         tail0 <= 3'd1;
8614
         tail1 <= 3'd2;
8615
    end
8616
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
8617
         tail0 <= 3'd2;
8618
         tail1 <= 3'd3;
8619
    end
8620
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
8621
         tail0 <= 3'd3;
8622
         tail1 <= 3'd4;
8623
    end
8624
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
8625
         tail0 <= 3'd4;
8626
         tail1 <= 3'd5;
8627
    end
8628
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
8629
         tail0 <= 3'd5;
8630
         tail1 <= 3'd6;
8631
    end
8632
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
8633
         tail0 <= 3'd6;
8634
         tail1 <= 3'd7;
8635
    end
8636
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
8637
         tail0 <= 3'd7;
8638
         tail1 <= 3'd0;
8639
    end
8640
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
8641
end
8642
end
8643
*/
8644
/*
8645
always @(posedge clk)
8646
if (rst)
8647
     seq_num <= 5'd0;
8648
else begin
8649
    if (pebm)
8650
         seq_num <= seq_num + 5'd3;
8651
    else if (queued2)
8652
         seq_num <= seq_num + 5'd2;
8653
    else if (queued1)
8654
         seq_num <= seq_num + 5'd1;
8655
end
8656
*/
8657 49 robfinch
 
8658 51 robfinch
// Update the write buffer.
8659 49 robfinch
task wb_update;
8660
input [`QBITS] id;
8661
input rmw;
8662
input [7:0] sel;
8663
input [1:0] ol;
8664
input [`ABITS] addr;
8665
input [63:0] data;
8666
begin
8667 52 robfinch
        if (wbm && wbptr > 1 && wb_addr[wbptr-1][AMSB:3]==addr[AMSB:3]
8668
         && wb_ol[wbptr-1]==ol && wb_rmw[wbptr-1]==rmw && wb_v[wbptr-1]) begin
8669
                // The write buffer is always shifted during the bus IDLE state. That means
8670
                // the data is out of place by a slot. The slot the data is moved from is
8671
                // invalidated.
8672
                wb_v[wbptr-2] <= `INV;
8673
                wb_v[wbptr-1] <= wb_en;
8674
                wb_id[wbptr-1] <= wb_id[wbptr-1] | (16'd1 << id);
8675
                wb_rmw[wbptr-1] <= rmw;
8676
                wb_ol[wbptr-1] <= ol;
8677 49 robfinch
                wb_sel[wbptr-1] <= wb_sel[wbptr-1] | sel;
8678 52 robfinch
                wb_addr[wbptr-1] <= wb_addr[wbptr-1];
8679
                wb_data[wbptr-1] <= wb_data[wbptr-1];
8680 49 robfinch
                if (sel[0]) wb_data[wbptr-1][ 7: 0] <= data[ 7: 0];
8681
                if (sel[1]) wb_data[wbptr-1][15: 8] <= data[15: 8];
8682
                if (sel[2]) wb_data[wbptr-1][23:16] <= data[23:16];
8683
                if (sel[3]) wb_data[wbptr-1][31:24] <= data[31:24];
8684
                if (sel[4]) wb_data[wbptr-1][39:32] <= data[39:32];
8685
                if (sel[5]) wb_data[wbptr-1][47:40] <= data[47:40];
8686
                if (sel[6]) wb_data[wbptr-1][55:48] <= data[55:48];
8687
                if (sel[7]) wb_data[wbptr-1][63:56] <= data[63:56];
8688
                wb_merges <= wb_merges + 32'd1;
8689
        end
8690
        else begin
8691
                wb_v[wbptr] <= wb_en;
8692
                wb_id[wbptr] <= (16'd1 << id);
8693
                wb_rmw[wbptr] <= rmw;
8694
                wb_ol[wbptr] <= ol;
8695
                wb_sel[wbptr] <= sel;
8696
                wb_addr[wbptr] <= {addr[AMSB:3],3'b0};
8697
                wb_data[wbptr] <= data;
8698
        end
8699
end
8700
endtask
8701 52 robfinch
 
8702 48 robfinch
// Increment the head pointers
8703
// Also increments the instruction counter
8704
// Used when instructions are committed.
8705
// Also clear any outstanding state bits that foul things up.
8706
//
8707
task head_inc;
8708
input [`QBITS] amt;
8709
begin
8710 52 robfinch
     head0 <= (head0 + amt) % QENTRIES;
8711
     head1 <= (head1 + amt) % QENTRIES;
8712
     head2 <= (head2 + amt) % QENTRIES;
8713
     head3 <= (head3 + amt) % QENTRIES;
8714
     head4 <= (head4 + amt) % QENTRIES;
8715
     head5 <= (head5 + amt) % QENTRIES;
8716
     head6 <= (head6 + amt) % QENTRIES;
8717
     head7 <= (head7 + amt) % QENTRIES;
8718
     head8 <= (head8 + amt) % QENTRIES;
8719
     head9 <= (head9 + amt) % QENTRIES;
8720 58 robfinch
     CC <= CC + amt;
8721 49 robfinch
    if (amt==3'd3) begin
8722 58 robfinch
        I = I + iqentry_v[head0] + iqentry_v[head1] + iqentry_v[head2];
8723 49 robfinch
        iqentry_agen[head0] <= `INV;
8724
        iqentry_agen[head1] <= `INV;
8725
        iqentry_agen[head2] <= `INV;
8726
        iqentry_mem[head0] <= `FALSE;
8727
        iqentry_mem[head1] <= `FALSE;
8728
        iqentry_mem[head2] <= `FALSE;
8729
        iqentry_iv[head0] <= `INV;
8730
        iqentry_iv[head1] <= `INV;
8731
        iqentry_iv[head2] <= `INV;
8732
        iqentry_alu[head0] <= `FALSE;
8733
        iqentry_alu[head1] <= `FALSE;
8734
        iqentry_alu[head2] <= `FALSE;
8735
        end
8736
    else if (amt==3'd2) begin
8737 58 robfinch
        I = I + iqentry_v[head0] + iqentry_v[head1];
8738 48 robfinch
     iqentry_agen[head0] <= `INV;
8739
     iqentry_agen[head1] <= `INV;
8740 49 robfinch
     iqentry_mem[head0] <= `FALSE;
8741
     iqentry_mem[head1] <= `FALSE;
8742
     iqentry_iv[head0] <= `INV;
8743
     iqentry_iv[head1] <= `INV;
8744
        iqentry_alu[head0] <= `FALSE;
8745
     iqentry_alu[head1] <= `FALSE;
8746 48 robfinch
    end else if (amt==3'd1) begin
8747 58 robfinch
        I = I + iqentry_v[head0];
8748 49 robfinch
            iqentry_agen[head0] <= `INV;
8749
            iqentry_mem[head0] <= `FALSE;
8750
        iqentry_iv[head0] <= `INV;
8751
        iqentry_alu[head0] <= `FALSE;
8752 48 robfinch
        end
8753
end
8754
endtask
8755
 
8756
task setargs;
8757
input [`QBITS] nn;
8758
input [4:0] id;
8759
input v;
8760
input [63:0] bus;
8761
begin
8762
  if (iqentry_a1_v[nn] == `INV && iqentry_a1_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8763
                iqentry_a1[nn] <= bus;
8764
                iqentry_a1_v[nn] <= `VAL;
8765
  end
8766
  if (iqentry_a2_v[nn] == `INV && iqentry_a2_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8767
                iqentry_a2[nn] <= bus;
8768
                iqentry_a2_v[nn] <= `VAL;
8769
  end
8770
  if (iqentry_a3_v[nn] == `INV && iqentry_a3_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8771
                iqentry_a3[nn] <= bus;
8772
                iqentry_a3_v[nn] <= `VAL;
8773
  end
8774
end
8775
endtask
8776
 
8777
task setinsn;
8778
input [`QBITS] nn;
8779
input [4:0] id;
8780
input v;
8781 51 robfinch
input [143:0] bus;
8782 48 robfinch
begin
8783
  if (iqentry_iv[nn] == `INV && iqentry_is[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8784
        iqentry_iv   [nn]  <= `VAL;
8785
//      iqentry_Rt   [nn]  <= bus[`IB_RT];
8786
//      iqentry_Rc   [nn]  <= bus[`IB_RC];
8787
//      iqentry_Ra   [nn]  <= bus[`IB_RA];
8788
        iqentry_a0       [nn]  <= bus[`IB_CONST];
8789
        iqentry_imm  [nn]  <= bus[`IB_IMM];
8790 55 robfinch
//              iqentry_insln[nn]  <= bus[`IB_LN];
8791 56 robfinch
                if (iqentry_insln[nn] != bus[`IB_LN]) begin
8792
                        $display("Insn length mismatch.");
8793
                        $stop;
8794
                end
8795 51 robfinch
                iqentry_jal      [nn]  <= bus[`IB_JAL];
8796
                iqentry_ret  [nn]  <= bus[`IB_RET];
8797
                iqentry_irq  [nn]  <= bus[`IB_IRQ];
8798
                iqentry_brk      [nn]  <= bus[`IB_BRK];
8799
                iqentry_rti  [nn]  <= bus[`IB_RTI];
8800 48 robfinch
                iqentry_bt   [nn]  <= bus[`IB_BT];
8801
                iqentry_alu  [nn]  <= bus[`IB_ALU];
8802
                iqentry_alu0 [nn]  <= bus[`IB_ALU0];
8803
                iqentry_fpu  [nn]  <= bus[`IB_FPU];
8804
                iqentry_fc   [nn]  <= bus[`IB_FC];
8805
                iqentry_canex[nn]  <= bus[`IB_CANEX];
8806 50 robfinch
                iqentry_loadv[nn]  <= bus[`IB_LOADV];
8807 48 robfinch
                iqentry_load [nn]  <= bus[`IB_LOAD];
8808
                iqentry_preload[nn]<= bus[`IB_PRELOAD];
8809 50 robfinch
                iqentry_store[nn]  <= bus[`IB_STORE];
8810
                iqentry_oddball[nn] <= bus[`IB_ODDBALL];
8811
                iqentry_memsz[nn]  <= bus[`IB_MEMSZ];
8812 48 robfinch
                iqentry_mem  [nn]  <= bus[`IB_MEM];
8813
                iqentry_memndx[nn] <= bus[`IB_MEMNDX];
8814
                iqentry_rmw  [nn]  <= bus[`IB_RMW];
8815
                iqentry_memdb[nn]  <= bus[`IB_MEMDB];
8816
                iqentry_memsb[nn]  <= bus[`IB_MEMSB];
8817
                iqentry_shft48[nn] <= bus[`IB_SHFT48];
8818
                iqentry_sei      [nn]    <= bus[`IB_SEI];
8819
                iqentry_aq   [nn]  <= bus[`IB_AQ];
8820
                iqentry_rl   [nn]  <= bus[`IB_RL];
8821
                iqentry_jmp  [nn]  <= bus[`IB_JMP];
8822
                iqentry_br   [nn]  <= bus[`IB_BR];
8823
                iqentry_sync [nn]  <= bus[`IB_SYNC];
8824
                iqentry_fsync[nn]  <= bus[`IB_FSYNC];
8825
        iqentry_rfw  [nn]  <= bus[`IB_RFW];
8826
        iqentry_we   [nn]  <= bus[`IB_WE];
8827 56 robfinch
/*
8828
        if (iqentry_vector[nn]) begin
8829
                        iqentry_tgt[nn][RBIT:6] <= iqentry_Ra[nn][RBIT:6];
8830
                if (iqentry_Ra[nn][RBIT:6]==6'd0)
8831
                        iqentry_tgt[nn][RBIT:6] = 6'd0;
8832
                else begin
8833
                                if (iqentry_vcmprss[nn]) begin
8834
                                        if (vm[iqentry_instr[nn][25:23]][iqentry_Ra[nn][RBIT:6]])
8835
                                                if (qcnt==2'd2 && iqentry_vector[(nn-1)%QENTRIES] && iqentry_Ra[(nn-1)%QENTRIES][RBIT:6] >= 6'd1)
8836
                                                        iqentry_tgt[nn][RBIT:6] <= iqentry_tgt[(nn-2)%QENTRIES][RBIT:6] + 6'd2;
8837
                                                else
8838
                                                        iqentry_tgt[nn][RBIT:6] <= iqentry_tgt[(nn-1)%QENTRIES][RBIT:6] + 6'd1;
8839
                                end
8840
                        end
8841
                end
8842
*/
8843 48 robfinch
  end
8844
end
8845
endtask
8846
 
8847 55 robfinch
task a1_vs;
8848
begin
8849
        // if there is not an overlapping write to the register file.
8850
        if (Ra1s != Rt0s || !fetchbuf0_rfw) begin
8851
                iqentry_a1_v [tail1] <= regIsValid[Ra1s];
8852
                iqentry_a1_s [tail1] <= rf_source [Ra1s];
8853
        end
8854
        else begin
8855
                iqentry_a1_v [tail1] <= `INV;
8856
                iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
8857
        end
8858
end
8859
endtask
8860
 
8861
task a2_vs;
8862
begin
8863
        // if there is not an overlapping write to the register file.
8864
        if (Rb1s != Rt0s || !fetchbuf0_rfw) begin
8865
                iqentry_a2_v [tail1] <= regIsValid[Rb1s];
8866
                iqentry_a2_s [tail1] <= rf_source [Rb1s];
8867
        end
8868
        else begin
8869
                iqentry_a2_v [tail1] <= `INV;
8870
                iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
8871
        end
8872
end
8873
endtask
8874
 
8875
task a3_vs;
8876
begin
8877
        // if there is not an overlapping write to the register file.
8878
        if (Rc1s != Rt0s || !fetchbuf0_rfw) begin
8879
                iqentry_a3_v [tail1] <= regIsValid[Rc1s];
8880
                iqentry_a3_s [tail1] <= rf_source [Rc1s];
8881
        end
8882
        else begin
8883
                iqentry_a3_v [tail1] <= `INV;
8884
                iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
8885
        end
8886
end
8887
endtask
8888
 
8889
task enque0x;
8890
begin
8891
        if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
8892
                vqe0 <= vqe0 + 4'd1;
8893
                if (IsVCmprss(fetchbuf0_instr)) begin
8894
                        if (vm[fetchbuf0_instr[25:23]][vqe0])
8895
                        vqet0 <= vqet0 + 4'd1;
8896
                end
8897
                else
8898
                        vqet0 <= vqet0 + 4'd1;
8899
                if (vqe0 >= vl-2)
8900
                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
8901
                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
8902
                if (fetchbuf0_thrd)
8903
                        seq_num1 <= seq_num1 + 5'd1;
8904
                else
8905
                        seq_num <= seq_num + 5'd1;
8906
                if (fetchbuf0_rfw) begin
8907
                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
8908
                        rf_v[Rt0s] <= `INV;
8909
                end
8910
                if (canq2) begin
8911
                        if (vqe0 < vl-2) begin
8912
                                vqe0 <= vqe0 + 4'd2;
8913
                                if (IsVCmprss(fetchbuf0_instr)) begin
8914
                                        if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
8915
                                                vqet0 <= vqet0 + 4'd2;
8916
                                end
8917
                                else
8918
                                        vqet0 <= vqet0 + 4'd2;
8919
                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num+5'd1, vqe0 + 6'd1);
8920
                                if (fetchbuf0_thrd)
8921
                                        seq_num1 <= seq_num1 + 5'd2;
8922
                                else
8923
                                        seq_num <= seq_num + 5'd2;
8924
                                if (fetchbuf0_rfw) begin
8925
                                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };    // top bit indicates ALU/MEM bus
8926
                                        rf_v[Rt0s] <= `INV;
8927
                                end
8928
                        end
8929
                end
8930
        end
8931
        else begin
8932
                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, 6'd0);
8933
                if (fetchbuf0_thrd)
8934
                        seq_num1 <= seq_num1 + 5'd1;
8935
                else
8936
                        seq_num <= seq_num + 5'd1;
8937
                if (fetchbuf0_rfw) begin
8938
                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
8939
                        rf_v[Rt0s] <= `INV;
8940
                end
8941
        end
8942
end
8943
endtask
8944
 
8945 48 robfinch
// Enqueue fetchbuf0 onto the tail of the instruction queue
8946
task enque0;
8947
input [`QBITS] tail;
8948
input [63:0] seqnum;
8949
input [5:0] venno;
8950
begin
8951
        iqentry_exc[tail] <= `FLT_NONE;
8952
`ifdef SUPPORT_DBG
8953
    if (dbg_imatchA)
8954
        iqentry_exc[tail] <= `FLT_DBG;
8955
    else if (dbg_ctrl[63])
8956
        iqentry_exc[tail] <= `FLT_SSM;
8957
`endif
8958
        iqentry_sn   [tail]    <=  seqnum;
8959
        iqentry_v    [tail]    <=   `VAL;
8960
        iqentry_iv       [tail]    <=   `INV;
8961
        iqentry_is   [tail]    <= tail;
8962
        iqentry_thrd [tail]    <=   fetchbuf0_thrd;
8963
        iqentry_done [tail]    <=    `INV;
8964
        iqentry_cmt  [tail]    <=       `INV;
8965
        iqentry_out  [tail]    <=    `INV;
8966
        iqentry_res  [tail]    <=    `ZERO;
8967
        iqentry_instr[tail]    <=    IsVLS(fetchbuf0_instr) ? (vm[fnM2(fetchbuf0_instr)] ? fetchbuf0_instr : `NOP_INSN) : fetchbuf0_instr;
8968 55 robfinch
        iqentry_insln[tail]              <=  fetchbuf0_insln;
8969 48 robfinch
        iqentry_pt   [tail]    <=  predict_taken0;
8970
        iqentry_agen [tail]    <=    `INV;
8971
        iqentry_state[tail]    <=   IQS_IDLE;
8972
// If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
8973
// inherit the previous pc.
8974
//if (IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15] &&
8975
//   (IsBrk(iqentry_instr[idm1(tail)]) && !iqentry_instr[idm1(tail1)][15] && iqentry_v[idm1(tail)]))
8976
//   iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
8977
//else
8978
         iqentry_pc   [tail] <= fetchbuf0_pc;
8979
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf0_instr);
8980
        iqentry_tgt  [tail]    <=       Rt0;
8981
        iqentry_Ra   [tail]    <= Ra0;
8982
        iqentry_Rb   [tail]    <= Rb0;
8983
        iqentry_Rc   [tail]    <= Rc0;
8984
        iqentry_vl   [tail]    <=  vl;
8985
        iqentry_ven  [tail]    <=   venno;
8986
        iqentry_exc  [tail]    <=    `EXC_NONE;
8987
        iqentry_a1   [tail]    <=    rfoa0;
8988
        iqentry_a1_v [tail]    <=    Source1Valid(fetchbuf0_instr) | regIsValid[Ra0s];
8989
        iqentry_a1_s [tail]    <=    rf_source[Ra0s];
8990
        iqentry_a2   [tail]    <=    rfob0;
8991
        iqentry_a2_v [tail]    <=    Source2Valid(fetchbuf0_instr) | regIsValid[Rb0s];
8992
        iqentry_a2_s [tail]    <=    rf_source[Rb0s];
8993
        iqentry_a3   [tail]    <=    rfoc0;
8994
        iqentry_a3_v [tail]    <=    Source3Valid(fetchbuf0_instr) | regIsValid[Rc0s];
8995
        iqentry_a3_s [tail]    <=    rf_source[Rc0s];
8996
end
8997
endtask
8998
 
8999
// Enque fetchbuf1. Fetchbuf1 might be the second instruction to queue so some
9000
// of this code checks to see which tail it is being queued on.
9001
task enque1;
9002
input [`QBITS] tail;
9003
input [63:0] seqnum;
9004
input [5:0] venno;
9005
begin
9006
 iqentry_exc[tail] <= `FLT_NONE;
9007
`ifdef SUPPORT_DBG
9008
    if (dbg_imatchB)
9009
        iqentry_exc[tail] <= `FLT_DBG;
9010
    else if (dbg_ctrl[63])
9011
        iqentry_exc[tail] <= `FLT_SSM;
9012
`endif
9013
        iqentry_sn   [tail]    <=   seqnum;
9014
        iqentry_v    [tail]    <=   `VAL;
9015
        iqentry_iv       [tail]    <=   `INV;
9016
        iqentry_is   [tail]    <= tail;
9017
        iqentry_thrd [tail]    <=   fetchbuf1_thrd;
9018
        iqentry_done [tail]    <=   `INV;
9019
        iqentry_cmt  [tail]    <=       `INV;
9020
        iqentry_out  [tail]    <=   `INV;
9021
        iqentry_res  [tail]    <=   `ZERO;
9022
        iqentry_instr[tail]    <=   IsVLS(fetchbuf1_instr) ? (vm[fnM2(fetchbuf1_instr)] ? fetchbuf1_instr : `NOP_INSN) : fetchbuf1_instr;
9023 55 robfinch
        iqentry_insln[tail]              <=  fetchbuf1_insln;
9024 48 robfinch
        iqentry_pt   [tail]    <=  predict_taken1;
9025
        iqentry_agen [tail]    <=   `INV;
9026
        iqentry_state[tail]    <=   IQS_IDLE;
9027
// If queing 2nd instruction must read from first
9028
if (tail==tail1) begin
9029
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9030
    // inherit the previous pc.
9031
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
9032
//        IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15])
9033
//       iqentry_pc   [tail]    <= fetchbuf0_pc;
9034
//    else
9035
                iqentry_pc   [tail] <= fetchbuf1_pc;
9036
end
9037
else begin
9038
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9039
    // inherit the previous pc.
9040
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
9041
//       (IsBrk(iqentry_instr[idp7(tail)]) && !iqentry_instr[idm1(tail)][15] && iqentry_v[idm1(tail)]))
9042
//       iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
9043
//    else
9044
                iqentry_pc   [tail] <= fetchbuf1_pc;
9045
end
9046
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf1_instr);
9047
        iqentry_tgt  [tail]    <= Rt1;
9048
        iqentry_Ra   [tail]    <= Ra1;
9049
        iqentry_Rb   [tail]    <= Rb1;
9050
        iqentry_Rc   [tail]    <= Rc1;
9051
        iqentry_vl   [tail]    <=  vl;
9052
        iqentry_ven  [tail]    <=   venno;
9053
        iqentry_exc  [tail]    <=   `EXC_NONE;
9054
        iqentry_a1   [tail]    <=       rfoa1;
9055
        iqentry_a1_v [tail]    <=       Source1Valid(fetchbuf1_instr) | regIsValid[Ra1s];
9056
        iqentry_a1_s [tail]    <=       rf_source[Ra1s];
9057
        iqentry_a2   [tail]    <=       rfob1;
9058
        iqentry_a2_v [tail]    <=       Source2Valid(fetchbuf1_instr) | regIsValid[Rb1s];
9059
        iqentry_a2_s [tail]    <=       rf_source[Rb1s];
9060
        iqentry_a3   [tail]    <=       rfoc1;
9061
        iqentry_a3_v [tail]    <=       Source3Valid(fetchbuf1_instr) | regIsValid[Rc1s];
9062
        iqentry_a3_s [tail]    <=       rf_source[Rc1s];
9063
end
9064
endtask
9065
 
9066
// This task takes care of commits for things other than the register file.
9067
task oddball_commit;
9068
input v;
9069
input [`QBITS] head;
9070
reg thread;
9071
begin
9072
    thread = iqentry_thrd[head];
9073
    if (v) begin
9074
        if (|iqentry_exc[head]) begin
9075
            excmiss <= TRUE;
9076
`ifdef SUPPORT_SMT
9077 51 robfinch
                excmisspc <= {tvec[3'd0][31:8],1'b0,ol[thread],5'h00};
9078 48 robfinch
            excthrd <= iqentry_thrd[head];
9079
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
9080
            epc0[thread] <= iqentry_pc[head]+ 32'd4;
9081
            epc1[thread] <= epc0[thread];
9082
            epc2[thread] <= epc1[thread];
9083
            epc3[thread] <= epc2[thread];
9084
            epc4[thread] <= epc3[thread];
9085
            epc5[thread] <= epc4[thread];
9086
            epc6[thread] <= epc5[thread];
9087
            epc7[thread] <= epc6[thread];
9088
            epc8[thread] <= epc7[thread];
9089
            im_stack[thread] <= {im_stack[thread][27:0],im};
9090
            ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9091
            pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9092
            rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
9093
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
9094
            mstatus[thread][5:3] <= 3'd0;
9095
            mstatus[thread][13:6] <= 8'h00;
9096
            mstatus[thread][19:14] <= 6'd0;
9097
`else
9098 51 robfinch
                excmisspc <= {tvec[3'd0][31:8],1'b0,ol,5'h00};
9099 48 robfinch
            excthrd <= iqentry_thrd[head];
9100
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
9101
            epc0 <= iqentry_pc[head]+ 32'd4;
9102
            epc1 <= epc0;
9103
            epc2 <= epc1;
9104
            epc3 <= epc2;
9105
            epc4 <= epc3;
9106
            epc5 <= epc4;
9107
            epc6 <= epc5;
9108
            epc7 <= epc6;
9109
            epc8 <= epc7;
9110
            im_stack <= {im_stack[27:0],im};
9111
            ol_stack <= {ol_stack[13:0],ol};
9112
            pl_stack <= {pl_stack[55:0],cpl};
9113
            rs_stack <= {rs_stack[55:0],rgs};
9114
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
9115
            mstatus[5:3] <= 3'd0;
9116
            mstatus[13:6] <= 8'h00;
9117
            mstatus[19:14] <= 6'd0;
9118
`endif
9119 49 robfinch
                                                wb_en <= `TRUE;
9120 48 robfinch
            sema[0] <= 1'b0;
9121
            ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9122
`ifdef SUPPORT_DBG
9123
            dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9124
            dbg_ctrl[63] <= FALSE;
9125
`endif
9126
        end
9127
        else
9128
        case(iqentry_instr[head][`INSTRUCTION_OP])
9129
        `BRK:
9130
                        // BRK is treated as a nop unless it's a software interrupt or a
9131
                        // hardware interrupt at a higher priority than the current priority.
9132
                if ((iqentry_instr[head][23:19] > 5'd0) || iqentry_instr[head][18:16] > im) begin
9133
                            excmiss <= TRUE;
9134
`ifdef SUPPORT_SMT
9135 51 robfinch
                        excmisspc <= {tvec[3'd0][31:8],1'b0,ol[thread],5'h00};
9136 48 robfinch
                        excthrd <= iqentry_thrd[head];
9137
                    epc0[thread] <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
9138
                    epc1[thread] <= epc0[thread];
9139
                    epc2[thread] <= epc1[thread];
9140
                    epc3[thread] <= epc2[thread];
9141
                    epc4[thread] <= epc3[thread];
9142
                    epc5[thread] <= epc4[thread];
9143
                    epc6[thread] <= epc5[thread];
9144
                    epc7[thread] <= epc6[thread];
9145
                    epc8[thread] <= epc7[thread];
9146
                    im_stack[thread] <= {im_stack[thread][27:0],im};
9147
                    ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9148
                    pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9149
                    rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
9150
                    mstatus[thread][19:14] <= 6'd0;
9151
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
9152
                    mstatus[thread][5:3] <= 3'd0;
9153
                        mstatus[thread][13:6] <= 8'h00;
9154
                    // For hardware interrupts only, set a new mask level
9155
                    // Select register set according to interrupt level
9156
                    if (iqentry_instr[head][23:19]==5'd0) begin
9157
                        mstatus[thread][2:0] <= 3'd7;//iqentry_instr[head][18:16];
9158
                        mstatus[thread][42:40] <= iqentry_instr[head][18:16];
9159
                        mstatus[thread][19:14] <= {3'b0,iqentry_instr[head][18:16]};
9160
                    end
9161
                    else
9162
                        mstatus[thread][19:14] <= 6'd0;
9163
`else
9164 51 robfinch
                        excmisspc <= {tvec[3'd0][31:8],1'b0,ol,5'h00};
9165 48 robfinch
                        excthrd <= iqentry_thrd[head];
9166
                    epc0 <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
9167
                    epc1 <= epc0;
9168
                    epc2 <= epc1;
9169
                    epc3 <= epc2;
9170
                    epc4 <= epc3;
9171
                    epc5 <= epc4;
9172
                    epc6 <= epc5;
9173
                    epc7 <= epc6;
9174
                    epc8 <= epc7;
9175
                    im_stack <= {im_stack[27:0],im};
9176
                    ol_stack <= {ol_stack[13:0],ol};
9177
                    pl_stack <= {pl_stack[55:0],cpl};
9178
                    rs_stack <= {rs_stack[55:0],rgs};
9179
                    mstatus[19:14] <= 6'd0;
9180
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
9181
                    mstatus[5:3] <= 3'd0;
9182
                        mstatus[13:6] <= 8'h00;
9183
                    // For hardware interrupts only, set a new mask level
9184
                    // Select register set according to interrupt level
9185
                    if (iqentry_instr[head][23:19]==5'd0) begin
9186
                        mstatus[2:0] <= 3'd7;//iqentry_instr[head][18:16];
9187
                        mstatus[42:40] <= iqentry_instr[head][18:16];
9188
                        mstatus[19:14] <= {3'b0,iqentry_instr[head][18:16]};
9189
                    end
9190
                    else
9191
                        mstatus[19:14] <= 6'd0;
9192
`endif
9193
                    sema[0] <= 1'b0;
9194
                    ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9195
`ifdef SUPPORT_DBG
9196
                    dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9197
                    dbg_ctrl[63] <= FALSE;
9198
`endif
9199
                end
9200
        `IVECTOR:
9201
            casez(iqentry_tgt[head])
9202
            8'b00100xxx:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9203
            8'b00101111:  vl <= iqentry_res[head];
9204
            default:    ;
9205
            endcase
9206
        `R2:
9207
            case(iqentry_instr[head][`INSTRUCTION_S2])
9208
            `R1:        case(iqentry_instr[head][20:16])
9209
                        `CHAIN_OFF:     cr0[18] <= 1'b0;
9210
                        `CHAIN_ON:      cr0[18] <= 1'b1;
9211
                        //`SETWB:               wbrcd[pcr[5:0]] <= 1'b1;
9212
                        default:        ;
9213
                                endcase
9214
            `VMOV:  casez(iqentry_tgt[head])
9215
                    12'b1111111_00???:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9216
                    12'b1111111_01111:  vl <= iqentry_res[head];
9217
                    default:    ;
9218
                    endcase
9219
`ifdef SUPPORT_SMT
9220
            `SEI:   mstatus[thread][2:0] <= iqentry_res[head][2:0];   // S1
9221
`else
9222
            `SEI:   mstatus[2:0] <= iqentry_res[head][2:0];   // S1
9223
`endif
9224
            `RTI:   begin
9225
                            excmiss <= TRUE;
9226
`ifdef SUPPORT_SMT
9227
                        excmisspc <= epc0[thread];
9228
                        excthrd <= thread;
9229
                        mstatus[thread][3:0] <= im_stack[thread][3:0];
9230
                        mstatus[thread][5:4] <= ol_stack[thread][1:0];
9231
                        mstatus[thread][13:6] <= pl_stack[thread][7:0];
9232
                        mstatus[thread][19:14] <= rs_stack[thread][5:0];
9233
                        im_stack[thread] <= {4'd15,im_stack[thread][27:4]};
9234
                        ol_stack[thread] <= {2'd0,ol_stack[thread][15:2]};
9235
                        pl_stack[thread] <= {8'h00,pl_stack[thread][63:8]};
9236
                        rs_stack[thread] <= {8'h00,rs_stack[thread][63:8]};
9237
                    epc0[thread] <= epc1[thread];
9238
                    epc1[thread] <= epc2[thread];
9239
                    epc2[thread] <= epc3[thread];
9240
                    epc3[thread] <= epc4[thread];
9241
                    epc4[thread] <= epc5[thread];
9242
                    epc5[thread] <= epc6[thread];
9243
                    epc6[thread] <= epc7[thread];
9244
                    epc7[thread] <= epc8[thread];
9245 51 robfinch
                    epc8[thread] <= {tvec[0][31:8], 1'b0, ol[thread], 5'h0};
9246 48 robfinch
`else
9247
                        excmisspc <= epc0;
9248
                        excthrd <= thread;
9249
                        mstatus[3:0] <= im_stack[3:0];
9250
                        mstatus[5:4] <= ol_stack[1:0];
9251
                        mstatus[13:6] <= pl_stack[7:0];
9252
                        mstatus[19:14] <= rs_stack[5:0];
9253
                        im_stack <= {4'd15,im_stack[31:4]};
9254
                        ol_stack <= {2'd0,ol_stack[15:2]};
9255
                        pl_stack <= {8'h00,pl_stack[63:8]};
9256
                        rs_stack <= {8'h00,rs_stack[63:8]};
9257
                    epc0 <= epc1;
9258
                    epc1 <= epc2;
9259
                    epc2 <= epc3;
9260
                    epc3 <= epc4;
9261
                    epc4 <= epc5;
9262
                    epc5 <= epc6;
9263
                    epc6 <= epc7;
9264
                    epc7 <= epc8;
9265 51 robfinch
                    epc8 <= {tvec[0][31:8], 1'b0, ol, 5'h0};
9266 48 robfinch
`endif
9267
                    sema[0] <= 1'b0;
9268
                    sema[iqentry_res[head][5:0]] <= 1'b0;
9269
                    vqe0  <= ve_hold[ 5: 0];
9270
                    vqet0 <= ve_hold[21:16];
9271
                    vqe1  <= ve_hold[37:32];
9272
                    vqet1 <= ve_hold[53:48];
9273
`ifdef SUPPORT_DBG
9274
                    dbg_ctrl[62:55] <= {FALSE,dbg_ctrl[62:56]};
9275
                    dbg_ctrl[63] <= dbg_ctrl[55];
9276
`endif
9277
                    end
9278 49 robfinch
            default: ;
9279
            endcase
9280
        `MEMNDX:
9281
            case(iqentry_instr[head][`INSTRUCTION_S2])
9282 48 robfinch
            `CACHEX:
9283 49 robfinch
                    case(iqentry_instr[head][22:18])
9284 48 robfinch
                    5'h03:  invic <= TRUE;
9285
                    5'h10:  cr0[30] <= FALSE;
9286
                    5'h11:  cr0[30] <= TRUE;
9287
                    default:    ;
9288
                    endcase
9289
            default: ;
9290
            endcase
9291
        `CSRRW:
9292
                        begin
9293 51 robfinch
                        write_csr(iqentry_instr[head][31:18],iqentry_a1[head],thread);
9294 48 robfinch
                        end
9295
        `REX:
9296
`ifdef SUPPORT_SMT
9297
            // Can only redirect to a lower level
9298
            if (ol[thread] < iqentry_instr[head][13:11]) begin
9299
                mstatus[thread][5:3] <= iqentry_instr[head][13:11];
9300
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol[thread]}];
9301
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol[thread]}];
9302
                mstatus[thread][13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
9303
            end
9304
`else
9305
            if (ol < iqentry_instr[head][13:11]) begin
9306
                mstatus[5:3] <= iqentry_instr[head][13:11];
9307
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol}];
9308
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol}];
9309
                mstatus[13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
9310
            end
9311
`endif
9312
        `CACHE:
9313 49 robfinch
            case(iqentry_instr[head][17:13])
9314 48 robfinch
            5'h03:  invic <= TRUE;
9315
            5'h10:  cr0[30] <= FALSE;
9316
            5'h11:  cr0[30] <= TRUE;
9317
            default:    ;
9318
            endcase
9319
        `FLOAT:
9320
            case(iqentry_instr[head][`INSTRUCTION_S2])
9321 49 robfinch
            `FRM: begin
9322 51 robfinch
                                fp_rm <= iqentry_res[head][2:0];
9323 49 robfinch
                                end
9324 48 robfinch
            `FCX:
9325
                begin
9326 51 robfinch
                    fp_sx <= fp_sx & ~iqentry_res[head][5];
9327
                    fp_inex <= fp_inex & ~iqentry_res[head][4];
9328
                    fp_dbzx <= fp_dbzx & ~(iqentry_res[head][3]|iqentry_res[head][0]);
9329
                    fp_underx <= fp_underx & ~iqentry_res[head][2];
9330
                    fp_overx <= fp_overx & ~iqentry_res[head][1];
9331
                    fp_giopx <= fp_giopx & ~iqentry_res[head][0];
9332
                    fp_infdivx <= fp_infdivx & ~iqentry_res[head][0];
9333
                    fp_zerozerox <= fp_zerozerox & ~iqentry_res[head][0];
9334
                    fp_subinfx   <= fp_subinfx   & ~iqentry_res[head][0];
9335
                    fp_infzerox  <= fp_infzerox  & ~iqentry_res[head][0];
9336
                    fp_NaNCmpx   <= fp_NaNCmpx   & ~iqentry_res[head][0];
9337
                    fp_swtx <= 1'b0;
9338 48 robfinch
                end
9339
            `FDX:
9340
                begin
9341 51 robfinch
                    fp_inexe <= fp_inexe     & ~iqentry_res[head][4];
9342
                    fp_dbzxe <= fp_dbzxe     & ~iqentry_res[head][3];
9343
                    fp_underxe <= fp_underxe & ~iqentry_res[head][2];
9344
                    fp_overxe <= fp_overxe   & ~iqentry_res[head][1];
9345
                    fp_invopxe <= fp_invopxe & ~iqentry_res[head][0];
9346 48 robfinch
                end
9347
            `FEX:
9348
                begin
9349 51 robfinch
                    fp_inexe <= fp_inexe     | iqentry_res[head][4];
9350
                    fp_dbzxe <= fp_dbzxe     | iqentry_res[head][3];
9351
                    fp_underxe <= fp_underxe | iqentry_res[head][2];
9352
                    fp_overxe <= fp_overxe   | iqentry_res[head][1];
9353
                    fp_invopxe <= fp_invopxe | iqentry_res[head][0];
9354 48 robfinch
                end
9355
            default:
9356
                begin
9357
                    // 31 to 29 is rounding mode
9358
                    // 28 to 24 are exception enables
9359
                    // 23 is nsfp
9360
                    // 22 is a fractie
9361 51 robfinch
                    fp_fractie <= iqentry_a0[head][22];
9362
                    fp_raz <= iqentry_a0[head][21];
9363 48 robfinch
                    // 20 is a 0
9364 51 robfinch
                    fp_neg <= iqentry_a0[head][19];
9365
                    fp_pos <= iqentry_a0[head][18];
9366
                    fp_zero <= iqentry_a0[head][17];
9367
                    fp_inf <= iqentry_a0[head][16];
9368 48 robfinch
                    // 15 swtx
9369
                    // 14 
9370 51 robfinch
                    fp_inex <= fp_inex | (fp_inexe & iqentry_a0[head][14]);
9371
                    fp_dbzx <= fp_dbzx | (fp_dbzxe & iqentry_a0[head][13]);
9372
                    fp_underx <= fp_underx | (fp_underxe & iqentry_a0[head][12]);
9373
                    fp_overx <= fp_overx | (fp_overxe & iqentry_a0[head][11]);
9374 48 robfinch
                    //fp_giopx <= fp_giopx | (fp_giopxe & iqentry_res2[head][10]);
9375
                    //fp_invopx <= fp_invopx | (fp_invopxe & iqentry_res2[head][24]);
9376
                    //
9377 51 robfinch
                    fp_cvtx <= fp_cvtx |  (fp_giopxe & iqentry_a0[head][7]);
9378
                    fp_sqrtx <= fp_sqrtx |  (fp_giopxe & iqentry_a0[head][6]);
9379
                    fp_NaNCmpx <= fp_NaNCmpx |  (fp_giopxe & iqentry_a0[head][5]);
9380
                    fp_infzerox <= fp_infzerox |  (fp_giopxe & iqentry_a0[head][4]);
9381
                    fp_zerozerox <= fp_zerozerox |  (fp_giopxe & iqentry_a0[head][3]);
9382
                    fp_infdivx <= fp_infdivx | (fp_giopxe & iqentry_a0[head][2]);
9383
                    fp_subinfx <= fp_subinfx | (fp_giopxe & iqentry_a0[head][1]);
9384
                    fp_snanx <= fp_snanx | (fp_giopxe & iqentry_a0[head][0]);
9385 48 robfinch
 
9386
                end
9387
            endcase
9388
        default:    ;
9389
        endcase
9390
        // Once the flow control instruction commits, NOP it out to allow
9391
        // pending stores to be issued.
9392
        iqentry_instr[head][5:0] <= `NOP;
9393
    end
9394
end
9395
endtask
9396
 
9397
// CSR access tasks
9398
task read_csr;
9399 51 robfinch
input [11:0] csrno;
9400 48 robfinch
output [63:0] dat;
9401
input thread;
9402
begin
9403
`ifdef SUPPORT_SMT
9404
    if (csrno[11:10] >= ol[thread])
9405
`else
9406
    if (csrno[11:10] >= ol)
9407
`endif
9408
    casez(csrno[9:0])
9409
    `CSR_CR0:       dat <= cr0;
9410
    `CSR_HARTID:    dat <= hartid;
9411
    `CSR_TICK:      dat <= tick;
9412
    `CSR_PCR:       dat <= pcr;
9413
    `CSR_PCR2:      dat <= pcr2;
9414 49 robfinch
    `CSR_PMR:                           dat <= pmr;
9415 48 robfinch
    `CSR_WBRCD:         dat <= wbrcd;
9416
    `CSR_SEMA:      dat <= sema;
9417
    `CSR_SBL:       dat <= sbl;
9418
    `CSR_SBU:       dat <= sbu;
9419
    `CSR_TCB:           dat <= tcb;
9420 51 robfinch
    `CSR_FSTAT:     dat <= {fp_rgs,fp_status};
9421 48 robfinch
`ifdef SUPPORT_DBG
9422
    `CSR_DBAD0:     dat <= dbg_adr0;
9423
    `CSR_DBAD1:     dat <= dbg_adr1;
9424
    `CSR_DBAD2:     dat <= dbg_adr2;
9425
    `CSR_DBAD3:     dat <= dbg_adr3;
9426
    `CSR_DBCTRL:    dat <= dbg_ctrl;
9427
    `CSR_DBSTAT:    dat <= dbg_stat;
9428
`endif
9429
    `CSR_CAS:       dat <= cas;
9430
    `CSR_TVEC:      dat <= tvec[csrno[2:0]];
9431 52 robfinch
    `CSR_BADADR:    dat <= badaddr[{thread,csrno[11:10]}];
9432
    `CSR_CAUSE:     dat <= {48'd0,cause[{thread,csrno[11:10]}]};
9433 48 robfinch
`ifdef SUPPORT_SMT
9434
    `CSR_IM_STACK:      dat <= im_stack[thread];
9435
    `CSR_OL_STACK:      dat <= ol_stack[thread];
9436
    `CSR_PL_STACK:      dat <= pl_stack[thread];
9437
    `CSR_RS_STACK:      dat <= rs_stack[thread];
9438
    `CSR_STATUS:    dat <= mstatus[thread][63:0];
9439
    `CSR_EPC0:      dat <= epc0[thread];
9440
    `CSR_EPC1:      dat <= epc1[thread];
9441
    `CSR_EPC2:      dat <= epc2[thread];
9442
    `CSR_EPC3:      dat <= epc3[thread];
9443
    `CSR_EPC4:      dat <= epc4[thread];
9444
    `CSR_EPC5:      dat <= epc5[thread];
9445
    `CSR_EPC6:      dat <= epc6[thread];
9446
    `CSR_EPC7:      dat <= epc7[thread];
9447
`else
9448
    `CSR_IM_STACK:      dat <= im_stack;
9449
    `CSR_OL_STACK:      dat <= ol_stack;
9450
    `CSR_PL_STACK:      dat <= pl_stack;
9451
    `CSR_RS_STACK:      dat <= rs_stack;
9452
    `CSR_STATUS:    dat <= mstatus[63:0];
9453
    `CSR_EPC0:      dat <= epc0;
9454
    `CSR_EPC1:      dat <= epc1;
9455
    `CSR_EPC2:      dat <= epc2;
9456
    `CSR_EPC3:      dat <= epc3;
9457
    `CSR_EPC4:      dat <= epc4;
9458
    `CSR_EPC5:      dat <= epc5;
9459
    `CSR_EPC6:      dat <= epc6;
9460
    `CSR_EPC7:      dat <= epc7;
9461
`endif
9462
    `CSR_CODEBUF:   dat <= codebuf[csrno[5:0]];
9463
    `CSR_TIME:          dat <= wc_times;
9464
    `CSR_INFO:
9465
                    case(csrno[3:0])
9466
                    4'd0:   dat <= "Finitron";  // manufacturer
9467
                    4'd1:   dat <= "        ";
9468
                    4'd2:   dat <= "64 bit  ";  // CPU class
9469
                    4'd3:   dat <= "        ";
9470
                    4'd4:   dat <= "FT64    ";  // Name
9471
                    4'd5:   dat <= "        ";
9472
                    4'd6:   dat <= 64'd1;       // model #
9473
                    4'd7:   dat <= 64'd1;       // serial number
9474
                    4'd8:   dat <= {32'd16384,32'd16384};   // cache sizes instruction,data
9475
                    4'd9:   dat <= 64'd0;
9476
                    default:    dat <= 64'd0;
9477
                    endcase
9478
    default:    begin
9479
                        $display("Unsupported CSR:%h",csrno[10:0]);
9480
                        dat <= 64'hEEEEEEEEEEEEEEEE;
9481
                        end
9482
    endcase
9483
    else
9484
        dat <= 64'h0;
9485
end
9486
endtask
9487
 
9488
task write_csr;
9489
input [13:0] csrno;
9490
input [63:0] dat;
9491
input thread;
9492
begin
9493
`ifdef SUPPORT_SMT
9494
    if (csrno[11:10] >= ol[thread])
9495
`else
9496
    if (csrno[11:10] >= ol)
9497
`endif
9498
    case(csrno[13:12])
9499
    2'd1:   // CSRRW
9500
        casez(csrno[9:0])
9501
        `CSR_CR0:       cr0 <= dat;
9502
        `CSR_PCR:       pcr <= dat[31:0];
9503
        `CSR_PCR2:      pcr2 <= dat;
9504 49 robfinch
        `CSR_PMR:       case(`NUM_IDU)
9505
                                                0,1:     pmr[0] <= 1'b1;
9506
                                                2:
9507
                                                        begin
9508
                                                                        if (dat[1:0]==2'b00)
9509
                                                                                pmr[1:0] <= 2'b01;
9510
                                                                        else
9511
                                                                                pmr[1:0] <= dat[1:0];
9512
                                                                        pmr[63:2] <= dat[63:2];
9513
                                                                end
9514
                                                3:
9515
                                                        begin
9516
                                                                        if (dat[2:0]==3'b000)
9517
                                                                                pmr[2:0] <= 3'b001;
9518
                                                                        else
9519
                                                                                pmr[2:0] <= dat[2:0];
9520
                                                                        pmr[63:3] <= dat[63:3];
9521
                                                                end
9522
                                                default:        pmr[0] <= 1'b1;
9523
                                                endcase
9524 48 robfinch
        `CSR_WBRCD:             wbrcd <= dat;
9525
        `CSR_SEMA:      sema <= dat;
9526
        `CSR_SBL:       sbl <= dat[31:0];
9527
        `CSR_SBU:       sbu <= dat[31:0];
9528
        `CSR_TCB:               tcb <= dat;
9529 51 robfinch
        `CSR_FSTAT:             fpu_csr[37:32] <= dat[37:32];
9530 52 robfinch
        `CSR_BADADR:    badaddr[{thread,csrno[11:10]}] <= dat;
9531
        `CSR_CAUSE:     cause[{thread,csrno[11:10]}] <= dat[15:0];
9532 48 robfinch
`ifdef SUPPORT_DBG
9533
        `CSR_DBAD0:     dbg_adr0 <= dat[AMSB:0];
9534
        `CSR_DBAD1:     dbg_adr1 <= dat[AMSB:0];
9535
        `CSR_DBAD2:     dbg_adr2 <= dat[AMSB:0];
9536
        `CSR_DBAD3:     dbg_adr3 <= dat[AMSB:0];
9537
        `CSR_DBCTRL:    dbg_ctrl <= dat;
9538
`endif
9539
        `CSR_CAS:       cas <= dat;
9540
        `CSR_TVEC:      tvec[csrno[2:0]] <= dat[31:0];
9541
`ifdef SUPPORT_SMT
9542
        `CSR_IM_STACK:  im_stack[thread] <= dat[31:0];
9543
        `CSR_OL_STACK:  ol_stack[thread] <= dat[15:0];
9544
        `CSR_PL_STACK:  pl_stack[thread] <= dat;
9545
        `CSR_RS_STACK:  rs_stack[thread] <= dat;
9546
        `CSR_STATUS:    mstatus[thread][63:0] <= dat;
9547
        `CSR_EPC0:      epc0[thread] <= dat;
9548
        `CSR_EPC1:      epc1[thread] <= dat;
9549
        `CSR_EPC2:      epc2[thread] <= dat;
9550
        `CSR_EPC3:      epc3[thread] <= dat;
9551
        `CSR_EPC4:      epc4[thread] <= dat;
9552
        `CSR_EPC5:      epc5[thread] <= dat;
9553
        `CSR_EPC6:      epc6[thread] <= dat;
9554
        `CSR_EPC7:      epc7[thread] <= dat;
9555
`else
9556
        `CSR_IM_STACK:  im_stack <= dat[31:0];
9557
        `CSR_OL_STACK:  ol_stack <= dat[15:0];
9558
        `CSR_PL_STACK:  pl_stack <= dat;
9559
        `CSR_RS_STACK:  rs_stack <= dat;
9560
        `CSR_STATUS:    mstatus[63:0] <= dat;
9561
        `CSR_EPC0:      epc0 <= dat;
9562
        `CSR_EPC1:      epc1 <= dat;
9563
        `CSR_EPC2:      epc2 <= dat;
9564
        `CSR_EPC3:      epc3 <= dat;
9565
        `CSR_EPC4:      epc4 <= dat;
9566
        `CSR_EPC5:      epc5 <= dat;
9567
        `CSR_EPC6:      epc6 <= dat;
9568
        `CSR_EPC7:      epc7 <= dat;
9569
`endif
9570
                `CSR_TIME:              begin
9571
                                                ld_time <= 6'h3f;
9572
                                                wc_time_dat <= dat;
9573
                                                end
9574
        `CSR_CODEBUF:   codebuf[csrno[5:0]] <= dat;
9575
        default:    ;
9576
        endcase
9577
    2'd2:   // CSRRS
9578
        case(csrno[9:0])
9579
        `CSR_CR0:       cr0 <= cr0 | dat;
9580
        `CSR_PCR:       pcr[31:0] <= pcr[31:0] | dat[31:0];
9581
        `CSR_PCR2:      pcr2 <= pcr2 | dat;
9582 49 robfinch
        `CSR_PMR:                               pmr <= pmr | dat;
9583 48 robfinch
        `CSR_WBRCD:             wbrcd <= wbrcd | dat;
9584
`ifdef SUPPORT_DBG
9585
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl | dat;
9586
`endif
9587
        `CSR_SEMA:      sema <= sema | dat;
9588
`ifdef SUPPORT_SMT
9589
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] | dat;
9590
`else
9591
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] | dat;
9592
`endif
9593
        default:    ;
9594
        endcase
9595
    2'd3:   // CSRRC
9596
        case(csrno[9:0])
9597
        `CSR_CR0:       cr0 <= cr0 & ~dat;
9598
        `CSR_PCR:       pcr <= pcr & ~dat;
9599
        `CSR_PCR2:      pcr2 <= pcr2 & ~dat;
9600 49 robfinch
        `CSR_PMR:                       begin
9601
                                                                if (dat[1:0]==2'b11)
9602
                                                                        pmr[1:0] <= 2'b01;
9603
                                                                else
9604
                                                                        pmr[1:0] <= pmr[1:0] & ~dat[1:0];
9605
                                                                pmr[63:2] <= pmr[63:2] & ~dat[63:2];
9606
                                                                end
9607 48 robfinch
        `CSR_WBRCD:             wbrcd <= wbrcd & ~dat;
9608
`ifdef SUPPORT_DBG
9609
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl & ~dat;
9610
`endif
9611
        `CSR_SEMA:      sema <= sema & ~dat;
9612
`ifdef SUPPORT_SMT
9613
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] & ~dat;
9614
`else
9615
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] & ~dat;
9616
`endif
9617
        default:    ;
9618
        endcase
9619
    default:    ;
9620
    endcase
9621
end
9622
endtask
9623
 
9624
 
9625
endmodule
9626
 
9627
 
9628
module decoder5 (num, out);
9629
input [4:0] num;
9630
output [31:1] out;
9631
reg [31:1] out;
9632
 
9633
always @(num)
9634
case (num)
9635
    5'd0 :      out <= 31'b0000000000000000000000000000000;
9636
    5'd1 :      out <= 31'b0000000000000000000000000000001;
9637
    5'd2 :      out <= 31'b0000000000000000000000000000010;
9638
    5'd3 :      out <= 31'b0000000000000000000000000000100;
9639
    5'd4 :      out <= 31'b0000000000000000000000000001000;
9640
    5'd5 :      out <= 31'b0000000000000000000000000010000;
9641
    5'd6 :      out <= 31'b0000000000000000000000000100000;
9642
    5'd7 :      out <= 31'b0000000000000000000000001000000;
9643
    5'd8 :      out <= 31'b0000000000000000000000010000000;
9644
    5'd9 :      out <= 31'b0000000000000000000000100000000;
9645
    5'd10:      out <= 31'b0000000000000000000001000000000;
9646
    5'd11:      out <= 31'b0000000000000000000010000000000;
9647
    5'd12:      out <= 31'b0000000000000000000100000000000;
9648
    5'd13:      out <= 31'b0000000000000000001000000000000;
9649
    5'd14:      out <= 31'b0000000000000000010000000000000;
9650
    5'd15:      out <= 31'b0000000000000000100000000000000;
9651
    5'd16:      out <= 31'b0000000000000001000000000000000;
9652
    5'd17:      out <= 31'b0000000000000010000000000000000;
9653
    5'd18:      out <= 31'b0000000000000100000000000000000;
9654
    5'd19:      out <= 31'b0000000000001000000000000000000;
9655
    5'd20:      out <= 31'b0000000000010000000000000000000;
9656
    5'd21:      out <= 31'b0000000000100000000000000000000;
9657
    5'd22:      out <= 31'b0000000001000000000000000000000;
9658
    5'd23:      out <= 31'b0000000010000000000000000000000;
9659
    5'd24:      out <= 31'b0000000100000000000000000000000;
9660
    5'd25:      out <= 31'b0000001000000000000000000000000;
9661
    5'd26:      out <= 31'b0000010000000000000000000000000;
9662
    5'd27:      out <= 31'b0000100000000000000000000000000;
9663
    5'd28:      out <= 31'b0001000000000000000000000000000;
9664
    5'd29:      out <= 31'b0010000000000000000000000000000;
9665
    5'd30:      out <= 31'b0100000000000000000000000000000;
9666
    5'd31:      out <= 31'b1000000000000000000000000000000;
9667
endcase
9668
 
9669
endmodule
9670
 
9671
module decoder6 (num, out);
9672
input [5:0] num;
9673
output [63:1] out;
9674
 
9675
wire [63:0] out1;
9676
 
9677
assign out1 = 64'd1 << num;
9678
assign out = out1[63:1];
9679
 
9680
endmodule
9681
 
9682
module decoder7 (num, out);
9683
input [6:0] num;
9684
output [127:1] out;
9685
 
9686
wire [127:0] out1;
9687
 
9688
assign out1 = 128'd1 << num;
9689
assign out = out1[127:1];
9690
 
9691
endmodule
9692
 
9693
module decoder8 (num, out);
9694
input [7:0] num;
9695
output [255:1] out;
9696
 
9697
wire [255:0] out1;
9698
 
9699
assign out1 = 256'd1 << num;
9700
assign out = out1[255:1];
9701
 
9702
endmodule
9703
 

powered by: WebSVN 2.1.0

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