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

Subversion Repositories thor

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

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 59 robfinch
`ifdef SUPPORT_VECTOR
95
parameter SUP_VECTOR = 1'b1;
96
`else
97
parameter SUP_VECTOR = 1'b0;
98
`endif
99 48 robfinch
parameter DBW = 64;
100
parameter ABW = 32;
101
parameter AMSB = ABW-1;
102
parameter NTHREAD = 1;
103
reg [3:0] i;
104
integer n;
105 52 robfinch
integer j, k;
106 48 robfinch
genvar g;
107
parameter TRUE = 1'b1;
108
parameter FALSE = 1'b0;
109
// Memory access sizes
110
parameter byt = 3'd0;
111
parameter wyde = 3'd1;
112
parameter tetra = 3'd2;
113
parameter octa = 3'd3;
114
// IQ states
115
parameter IQS_IDLE = 2'd0;
116
parameter IQS_AGEN = 2'd1;
117
parameter IQS_LDDONE = 2'd2;
118
parameter IQS_S3 = 2'd3;
119
 
120
wire clk;
121 50 robfinch
//BUFG uclkb1
122
//(
123
//      .I(clk_i),
124
//      .O(clk)
125
//);
126
assign clk = clk_i;
127 48 robfinch
 
128
wire dc_ack;
129
wire acki = ack_i|dc_ack;
130 57 robfinch
wire [RBIT:0] Ra0, Ra1, Ra2;
131
wire [RBIT:0] Rb0, Rb1, Rb2;
132
wire [RBIT:0] Rc0, Rc1, Rc2;
133
wire [RBIT:0] Rt0, Rt1, Rt2;
134 48 robfinch
wire [63:0] rfoa0,rfob0,rfoc0,rfoc0a;
135
wire [63:0] rfoa1,rfob1,rfoc1,rfoc1a;
136 57 robfinch
wire [63:0] rfoa2,rfob2,rfoc2,rfoc2a;
137 48 robfinch
`ifdef SUPPORT_SMT
138
wire [7:0] Ra0s = {Ra0[7:0]};
139
wire [7:0] Ra1s = {Ra1[7:0]};
140 57 robfinch
wire [7:0] Ra2s = {Ra2[7:0]};
141 48 robfinch
wire [7:0] Rb0s = {Rb0[7:0]};
142
wire [7:0] Rb1s = {Rb1[7:0]};
143 57 robfinch
wire [7:0] Rb2s = {Rb2[7:0]};
144 48 robfinch
wire [7:0] Rc0s = {Rc0[7:0]};
145
wire [7:0] Rc1s = {Rc1[7:0]};
146 57 robfinch
wire [7:0] Rc2s = {Rc2[7:0]};
147 48 robfinch
wire [7:0] Rt0s = {Rt0[7:0]};
148
wire [7:0] Rt1s = {Rt1[7:0]};
149 57 robfinch
wire [7:0] Rt2s = {Rt2[7:0]};
150 48 robfinch
`else
151
wire [6:0] Ra0s = {Ra0[7],Ra0[5:0]};
152
wire [6:0] Ra1s = {Ra1[7],Ra1[5:0]};
153 57 robfinch
wire [6:0] Ra2s = {Ra2[7],Ra2[5:0]};
154 48 robfinch
wire [6:0] Rb0s = {Rb0[7],Rb0[5:0]};
155
wire [6:0] Rb1s = {Rb1[7],Rb1[5:0]};
156 57 robfinch
wire [6:0] Rb2s = {Rb2[7],Rb2[5:0]};
157 48 robfinch
wire [6:0] Rc0s = {Rc0[7],Rc0[5:0]};
158
wire [6:0] Rc1s = {Rc1[7],Rc1[5:0]};
159 57 robfinch
wire [6:0] Rc2s = {Rc2[7],Rc2[5:0]};
160 48 robfinch
wire [6:0] Rt0s = {Rt0[7],Rt0[5:0]};
161
wire [6:0] Rt1s = {Rt1[7],Rt1[5:0]};
162 57 robfinch
wire [6:0] Rt2s = {Rt2[7],Rt2[5:0]};
163 48 robfinch
/*
164
wire [5:0] Ra0s = {Ra0[5:0]};
165
wire [5:0] Ra1s = {Ra1[5:0]};
166
wire [5:0] Rb0s = {Rb0[5:0]};
167
wire [5:0] Rb1s = {Rb1[5:0]};
168
wire [5:0] Rc0s = {Rc0[5:0]};
169
wire [5:0] Rc1s = {Rc1[5:0]};
170
wire [5:0] Rt0s = {Rt0[5:0]};
171
wire [5:0] Rt1s = {Rt1[5:0]};
172
*/
173
`endif
174
 
175
reg [63:0] ds [0:NTHREAD];
176
reg [63:0] ss [0:NTHREAD];
177
reg [63:0] ptrmask [0:NTHREAD];
178
reg [63:0] ptrkey = "  OBJECT";
179
reg [63:0] wbrcd;
180
 
181
reg  [PREGS-1:0] rf_v;
182 52 robfinch
reg  [5:0] rf_source[0:AREGS-1];
183 48 robfinch
initial begin
184
for (n = 0; n < AREGS; n = n + 1)
185 52 robfinch
        rf_source[n] = 6'd0;
186 48 robfinch
end
187 49 robfinch
wire [`ABITS] pc0;
188
wire [`ABITS] pc1;
189
wire [`ABITS] pc2;
190 48 robfinch
 
191
reg excmiss;
192 49 robfinch
reg [`ABITS] excmisspc;
193 48 robfinch
reg excthrd;
194
reg exception_set;
195
reg rdvq;               // accumulated read violation
196
reg errq;               // accumulated err_i input status
197
reg exvq;
198
 
199
// Vector
200 57 robfinch
reg [5:0] vqe0, vqe1, vqe2;   // vector element being queued
201
reg [5:0] vqet0, vqet1, vqet2;
202 48 robfinch
reg [7:0] vl;           // vector length
203
reg [63:0] vm [0:7];    // vector mask registers
204
reg [1:0] m2;
205
 
206 49 robfinch
reg [31:0] wb_merges;
207 48 robfinch
// CSR's
208
reg [63:0] cr0;
209
wire snr = cr0[17];             // sequence number reset
210
wire dce = cr0[30];     // data cache enable
211
wire bpe = cr0[32];     // branch predictor enable
212 52 robfinch
wire wbm = cr0[34];
213 48 robfinch
wire ctgtxe = cr0[33];
214 49 robfinch
reg [63:0] pmr;
215
wire id1_available = pmr[0];
216
wire id2_available = pmr[1];
217
wire id3_available = pmr[2];
218
wire alu0_available = pmr[8];
219
wire alu1_available = pmr[9];
220
wire fpu1_available = pmr[16];
221
wire fpu2_available = pmr[17];
222
wire mem1_available = pmr[24];
223
wire mem2_available = pmr[25];
224
wire mem3_available = pmr[26];
225
wire fcu_available = pmr[32];
226 48 robfinch
// Simply setting this flag to zero should strip out almost all the logic
227
// associated SMT.
228
`ifdef SUPPORT_SMT
229
wire thread_en = cr0[16];
230
`else
231
wire thread_en = 1'b0;
232
`endif
233
wire vechain = cr0[18];
234
reg [7:0] fcu_timeout;
235
reg [63:0] tick;
236
reg [63:0] wc_time;
237
reg [31:0] pcr;
238
reg [63:0] pcr2;
239
assign pcr_o = pcr;
240
assign pcr2_o = pcr2;
241
reg [63:0] aec;
242
reg [15:0] cause[0:15];
243
`ifdef SUPPORT_SMT
244 49 robfinch
reg [`ABITS] epc [0:NTHREAD];
245
reg [`ABITS] epc0 [0:NTHREAD];
246
reg [`ABITS] epc1 [0:NTHREAD];
247
reg [`ABITS] epc2 [0:NTHREAD];
248
reg [`ABITS] epc3 [0:NTHREAD];
249
reg [`ABITS] epc4 [0:NTHREAD];
250
reg [`ABITS] epc5 [0:NTHREAD];
251
reg [`ABITS] epc6 [0:NTHREAD];
252
reg [`ABITS] epc7 [0:NTHREAD];
253
reg [`ABITS] epc8 [0:NTHREAD];                   // exception pc and stack
254 48 robfinch
reg [63:0] mstatus [0:NTHREAD];           // machine status
255 49 robfinch
wire [3:0] im = mstatus[0][3:0];
256 48 robfinch
wire [1:0] ol [0:NTHREAD];
257
wire [1:0] dl [0:NTHREAD];
258
assign ol[0] = mstatus[0][5:3];   // operating level
259
assign dl[0] = mstatus[0][21:20];
260
wire [7:0] cpl [0:NTHREAD];
261
assign cpl[0] = mstatus[0][13:6]; // current privilege level
262
wire [5:0] rgs [0:NTHREAD];
263
assign rgs[0] = mstatus[0][19:14];
264
assign ol[1] = mstatus[1][5:3]; // operating level
265
assign cpl[1] = mstatus[1][13:6];       // current privilege level
266
assign rgs[1] = mstatus[1][19:14];
267
assign dl[1] = mstatus[1][21:20];
268
reg [15:0] ol_stack [0:NTHREAD];
269
reg [31:0] im_stack [0:NTHREAD];
270
reg [63:0] pl_stack [0:NTHREAD];
271
reg [63:0] rs_stack [0:NTHREAD];
272
reg [63:0] fr_stack [0:NTHREAD];
273
wire mprv = mstatus[0][55];
274
wire [5:0] fprgs = mstatus[0][25:20];
275
//assign ol_o = mprv ? ol_stack[0][2:0] : ol[0];
276
wire vca = mstatus[0][32];               // vector chaining active
277
`else
278 49 robfinch
reg [`ABITS] epc ;
279
reg [`ABITS] epc0 ;
280
reg [`ABITS] epc1 ;
281
reg [`ABITS] epc2 ;
282
reg [`ABITS] epc3 ;
283
reg [`ABITS] epc4 ;
284
reg [`ABITS] epc5 ;
285
reg [`ABITS] epc6 ;
286
reg [`ABITS] epc7 ;
287
reg [`ABITS] epc8 ;                     // exception pc and stack
288 48 robfinch
reg [63:0] mstatus ;             // machine status
289 49 robfinch
wire [3:0] im = mstatus[3:0];
290 48 robfinch
wire [1:0] ol ;
291
wire [1:0] dl;
292
assign ol = mstatus[5:3];       // operating level
293
assign dl = mstatus[21:20];
294
wire [7:0] cpl ;
295
assign cpl = mstatus[13:6];     // current privilege level
296
wire [5:0] rgs ;
297
assign rgs = mstatus[19:14];
298
reg [15:0] ol_stack ;
299
reg [31:0] im_stack ;
300
reg [63:0] pl_stack ;
301
reg [63:0] rs_stack ;
302
reg [63:0] fr_stack ;
303
wire mprv = mstatus[55];
304
wire [5:0] fprgs = mstatus[25:20];
305
//assign ol_o = mprv ? ol_stack[2:0] : ol;
306
wire vca = mstatus[32];         // vector chaining active
307
`endif
308
reg [63:0] tcb;
309 49 robfinch
reg [`ABITS] badaddr[0:15];
310
reg [`ABITS] tvec[0:7];
311 48 robfinch
reg [63:0] sema;
312
reg [63:0] vm_sema;
313
reg [63:0] cas;         // compare and swap
314
reg [63:0] ve_hold;
315
reg isCAS, isAMO, isInc, isSpt, isRMW;
316
reg [`QBITS] casid;
317 49 robfinch
reg [`ABITS] sbl, sbu;
318 48 robfinch
reg [4:0] regLR = 5'd29;
319
 
320 51 robfinch
reg [2:0] fp_rm;
321
reg fp_inexe;
322
reg fp_dbzxe;
323
reg fp_underxe;
324
reg fp_overxe;
325
reg fp_invopxe;
326
reg fp_giopxe;
327
reg fp_nsfp = 1'b0;
328
reg fp_fractie;
329
reg fp_raz;
330 48 robfinch
 
331 51 robfinch
reg fp_neg;
332
reg fp_pos;
333
reg fp_zero;
334
reg fp_inf;
335 48 robfinch
 
336 51 robfinch
reg fp_inex;            // inexact exception
337
reg fp_dbzx;            // divide by zero exception
338
reg fp_underx;          // underflow exception
339
reg fp_overx;           // overflow exception
340
reg fp_giopx;           // global invalid operation exception
341
reg fp_sx;                      // summary exception
342
reg fp_swtx;        // software triggered exception
343
reg fp_gx;
344
reg fp_invopx;
345 48 robfinch
 
346 51 robfinch
reg fp_infzerox;
347
reg fp_zerozerox;
348
reg fp_subinfx;
349
reg fp_infdivx;
350
reg fp_NaNCmpx;
351
reg fp_cvtx;
352
reg fp_sqrtx;
353
reg fp_snanx;
354 48 robfinch
 
355 51 robfinch
wire [31:0] fp_status = {
356 48 robfinch
 
357 51 robfinch
        fp_rm,
358
        fp_inexe,
359
        fp_dbzxe,
360
        fp_underxe,
361
        fp_overxe,
362
        fp_invopxe,
363
        fp_nsfp,
364 48 robfinch
 
365 51 robfinch
        fp_fractie,
366
        fp_raz,
367 48 robfinch
        1'b0,
368 51 robfinch
        fp_neg,
369
        fp_pos,
370
        fp_zero,
371
        fp_inf,
372 48 robfinch
 
373 51 robfinch
        fp_swtx,
374
        fp_inex,
375
        fp_dbzx,
376
        fp_underx,
377
        fp_overx,
378
        fp_giopx,
379
        fp_gx,
380
        fp_sx,
381 48 robfinch
 
382 51 robfinch
        fp_cvtx,
383
        fp_sqrtx,
384
        fp_NaNCmpx,
385
        fp_infzerox,
386
        fp_zerozerox,
387
        fp_infdivx,
388
        fp_subinfx,
389
        fp_snanx
390 48 robfinch
        };
391
 
392 51 robfinch
reg [63:0] fpu_csr;
393
wire [5:0] fp_rgs = fpu_csr[37:32];
394 48 robfinch
 
395
//reg [25:0] m[0:8191];
396
reg  [3:0] panic;                // indexes the message structure
397
reg [128:0] message [0:15];       // indexed by panic
398
 
399
wire int_commit;
400
reg StatusHWI;
401 49 robfinch
reg [47:0] insn0, insn1, insn2;
402 52 robfinch
wire [47:0] insn0a, insn1b, insn2b;
403
reg [47:0] insn1a, insn2a;
404 48 robfinch
// Only need enough bits in the seqnence number to cover the instructions in
405
// the queue plus an extra count for skipping on branch misses. In this case
406
// that would be four bits minimum (count 0 to 8). 
407
reg [31:0] seq_num;
408
reg [31:0] seq_num1;
409 57 robfinch
reg [31:0] seq_num2;
410 48 robfinch
wire [63:0] rdat0,rdat1,rdat2;
411
reg [63:0] xdati;
412
 
413 57 robfinch
reg canq1, canq2, canq3;
414 48 robfinch
reg queued1;
415
reg queued2;
416 57 robfinch
reg queued3;
417 48 robfinch
reg queuedNop;
418
 
419
reg [47:0] codebuf[0:63];
420 52 robfinch
reg [QENTRIES-1:0] setpred;
421 48 robfinch
 
422
// instruction queue (ROB)
423
reg [31:0]  iqentry_sn   [0:QENTRIES-1];  // instruction sequence number
424
reg [QENTRIES-1:0] iqentry_v;                    // entry valid?  -- this should be the first bit
425
reg [QENTRIES-1:0] iqentry_iv;           // instruction is valid
426
reg [4:0]  iqentry_is   [0:QENTRIES-1];   // source of instruction
427
reg [QENTRIES-1:0] iqentry_out;  // instruction has been issued to an ALU ... 
428
reg [QENTRIES-1:0] iqentry_done; // instruction result valid
429
reg [QENTRIES-1:0] iqentry_cmt;
430
reg [QENTRIES-1:0] iqentry_thrd;         // which thread the instruction is in
431
reg [QENTRIES-1:0] iqentry_pt;           // predict taken
432 51 robfinch
reg [QENTRIES-1:0] iqentry_bt;           // update branch target buffer
433 52 robfinch
reg [QENTRIES-1:0] iqentry_takb; // take branch record
434 51 robfinch
reg [QENTRIES-1:0] iqentry_jal;
435 48 robfinch
reg [QENTRIES-1:0] iqentry_agen; // address-generate ... signifies that address is ready (only for LW/SW)
436
reg  [1:0] iqentry_state [0:QENTRIES-1];
437
reg [QENTRIES-1:0] iqentry_alu = 8'h00;  // alu type instruction
438
reg [QENTRIES-1:0] iqentry_alu0;  // only valid on alu #0
439
reg [QENTRIES-1:0] iqentry_fpu;  // floating point instruction
440
reg [QENTRIES-1:0] iqentry_fc;   // flow control instruction
441
reg [QENTRIES-1:0] iqentry_canex = 8'h00;        // true if it's an instruction that can exception
442 50 robfinch
reg [QENTRIES-1:0] iqentry_oddball = 8'h00;      // writes to register file
443 49 robfinch
reg [QENTRIES-1:0] iqentry_load; // is a memory load instruction
444 50 robfinch
reg [QENTRIES-1:0] iqentry_loadv;        // is a volatile memory load instruction
445
reg [QENTRIES-1:0] iqentry_store;        // is a memory store instruction
446 49 robfinch
reg [QENTRIES-1:0] iqentry_preload;      // is a memory preload instruction
447
reg [QENTRIES-1:0] iqentry_ldcmp;
448
reg [QENTRIES-1:0] iqentry_mem;  // touches memory: 1 if LW/SW
449
reg [QENTRIES-1:0] iqentry_memndx;  // indexed memory operation 
450 50 robfinch
reg [2:0] iqentry_memsz [0:QENTRIES-1];   // size of memory op
451 49 robfinch
reg [QENTRIES-1:0] iqentry_rmw;  // memory RMW op
452
reg [QENTRIES-1:0] iqentry_memdb;
453
reg [QENTRIES-1:0] iqentry_memsb;
454
reg [QENTRIES-1:0] iqentry_rtop;
455 48 robfinch
reg [QENTRIES-1:0] iqentry_sei;
456
reg [QENTRIES-1:0] iqentry_aq;   // memory aquire
457
reg [QENTRIES-1:0] iqentry_rl;   // memory release
458 49 robfinch
reg [QENTRIES-1:0] iqentry_shft48;
459
reg [QENTRIES-1:0] iqentry_jmp;  // changes control flow: 1 if BEQ/JALR
460 48 robfinch
reg [QENTRIES-1:0] iqentry_br;  // Bcc (for predictor)
461 51 robfinch
reg [QENTRIES-1:0] iqentry_ret;
462
reg [QENTRIES-1:0] iqentry_irq;
463
reg [QENTRIES-1:0] iqentry_brk;
464
reg [QENTRIES-1:0] iqentry_rti;
465 49 robfinch
reg [QENTRIES-1:0] iqentry_sync;  // sync instruction
466
reg [QENTRIES-1:0] iqentry_fsync;
467 48 robfinch
reg [QENTRIES-1:0] iqentry_rfw = 8'h00;  // writes to register file
468
reg  [7:0] iqentry_we   [0:QENTRIES-1];   // enable strobe
469
reg [63:0] iqentry_res   [0:QENTRIES-1];  // instruction result
470
reg [47:0] iqentry_instr[0:QENTRIES-1];   // instruction opcode
471
reg  [2:0] iqentry_insln[0:QENTRIES-1]; // instruction length
472
reg  [7:0] iqentry_exc   [0:QENTRIES-1];  // only for branches ... indicates a HALT instruction
473 59 robfinch
reg [RBIT:0] iqentry_tgt[0:QENTRIES-1];   // Rt field or ZERO -- this is the instruction's target (if any)
474 48 robfinch
reg  [7:0] iqentry_vl   [0:QENTRIES-1];
475
reg  [5:0] iqentry_ven  [0:QENTRIES-1];  // vector element number
476
reg [63:0] iqentry_a0    [0:QENTRIES-1];  // argument 0 (immediate)
477
reg [63:0] iqentry_a1    [0:QENTRIES-1];  // argument 1
478
reg        iqentry_a1_v [0:QENTRIES-1];  // arg1 valid
479
reg  [4:0] iqentry_a1_s  [0:QENTRIES-1];  // arg1 source (iq entry # with top bit representing ALU/DRAM bus)
480
reg [63:0] iqentry_a2    [0:QENTRIES-1];  // argument 2
481
reg        iqentry_a2_v [0:QENTRIES-1];  // arg2 valid
482
reg  [4:0] iqentry_a2_s  [0:QENTRIES-1];  // arg2 source (iq entry # with top bit representing ALU/DRAM bus)
483
reg [63:0] iqentry_a3    [0:QENTRIES-1];  // argument 3
484
reg        iqentry_a3_v [0:QENTRIES-1];  // arg3 valid
485
reg  [4:0] iqentry_a3_s  [0:QENTRIES-1];  // arg3 source (iq entry # with top bit representing ALU/DRAM bus)
486 49 robfinch
reg [`ABITS] iqentry_pc [0:QENTRIES-1];  // program counter for this instruction
487 48 robfinch
reg [RBIT:0] iqentry_Ra [0:QENTRIES-1];
488
reg [RBIT:0] iqentry_Rb [0:QENTRIES-1];
489
reg [RBIT:0] iqentry_Rc [0:QENTRIES-1];
490
// debugging
491
//reg  [4:0] iqentry_ra   [0:7];  // Ra
492
initial begin
493
for (n = 0; n < QENTRIES; n = n + 1)
494
        iqentry_a1_s[n] = 5'd0;
495
        iqentry_a2_s[n] = 5'd0;
496
        iqentry_a3_s[n] = 5'd0;
497
end
498
 
499 53 robfinch
reg [QENTRIES-1:0] iqentry_source = {QENTRIES{1'b0}};
500 48 robfinch
reg   [QENTRIES-1:0] iqentry_imm;
501 53 robfinch
reg  [QENTRIES-1:0] iqentry_memready;
502
reg  [QENTRIES-1:0] iqentry_memopsvalid;
503 48 robfinch
 
504 53 robfinch
reg  [QENTRIES-1:0] memissue = {QENTRIES{1'b0}};
505 48 robfinch
reg [1:0] missued;
506
integer last_issue;
507
reg  [QENTRIES-1:0] iqentry_memissue;
508
wire [QENTRIES-1:0] iqentry_stomp;
509
reg [3:0] stompedOnRets;
510
reg  [QENTRIES-1:0] iqentry_alu0_issue;
511
reg  [QENTRIES-1:0] iqentry_alu1_issue;
512 49 robfinch
reg  [QENTRIES-1:0] iqentry_alu2_issue;
513 48 robfinch
reg  [QENTRIES-1:0] iqentry_id1issue;
514
reg  [QENTRIES-1:0] iqentry_id2issue;
515 49 robfinch
reg  [QENTRIES-1:0] iqentry_id3issue;
516 48 robfinch
reg [1:0] iqentry_mem_islot [0:QENTRIES-1];
517
reg [QENTRIES-1:0] iqentry_fcu_issue;
518 49 robfinch
reg [QENTRIES-1:0] iqentry_fpu1_issue;
519
reg [QENTRIES-1:0] iqentry_fpu2_issue;
520 48 robfinch
 
521
wire [PREGS-1:1] livetarget;
522
wire  [PREGS-1:1] iqentry_0_livetarget;
523
wire  [PREGS-1:1] iqentry_1_livetarget;
524
wire  [PREGS-1:1] iqentry_2_livetarget;
525
wire  [PREGS-1:1] iqentry_3_livetarget;
526
wire  [PREGS-1:1] iqentry_4_livetarget;
527
wire  [PREGS-1:1] iqentry_5_livetarget;
528
wire  [PREGS-1:1] iqentry_6_livetarget;
529
wire  [PREGS-1:1] iqentry_7_livetarget;
530 52 robfinch
wire  [PREGS-1:1] iqentry_8_livetarget;
531
wire  [PREGS-1:1] iqentry_9_livetarget;
532
wire [PREGS-1:1] iqentry_livetarget [0:QENTRIES-1];
533
assign iqentry_livetarget[0] = iqentry_0_livetarget;
534
assign iqentry_livetarget[1] = iqentry_1_livetarget;
535
assign iqentry_livetarget[2] = iqentry_2_livetarget;
536
assign iqentry_livetarget[3] = iqentry_3_livetarget;
537
assign iqentry_livetarget[4] = iqentry_4_livetarget;
538
assign iqentry_livetarget[5] = iqentry_5_livetarget;
539
assign iqentry_livetarget[6] = iqentry_6_livetarget;
540
assign iqentry_livetarget[7] = iqentry_7_livetarget;
541
assign iqentry_livetarget[8] = iqentry_8_livetarget;
542
assign iqentry_livetarget[9] = iqentry_9_livetarget;
543 53 robfinch
reg [PREGS-1:1] iqentry_latestID [0:QENTRIES-1];
544 52 robfinch
reg [PREGS-1:1] iqentry_cumulative [0:QENTRIES-1];
545 53 robfinch
wire  [PREGS-1:1] iq_out [0:QENTRIES-1];
546 48 robfinch
 
547
reg  [`QBITS] tail0;
548
reg  [`QBITS] tail1;
549
reg  [`QBITS] head0;
550
reg  [`QBITS] head1;
551
reg  [`QBITS] head2;    // used only to determine memory-access ordering
552
reg  [`QBITS] head3;    // used only to determine memory-access ordering
553
reg  [`QBITS] head4;    // used only to determine memory-access ordering
554
reg  [`QBITS] head5;    // used only to determine memory-access ordering
555
reg  [`QBITS] head6;    // used only to determine memory-access ordering
556
reg  [`QBITS] head7;    // used only to determine memory-access ordering
557 52 robfinch
reg  [`QBITS] head8;
558
reg  [`QBITS] head9;
559 48 robfinch
 
560
wire take_branch0;
561
wire take_branch1;
562
 
563
reg [3:0] nop_fetchbuf;
564
wire        fetchbuf;   // determines which pair to read from & write to
565 49 robfinch
wire [3:0] fb_panic;
566 48 robfinch
 
567
wire [47:0] fetchbuf0_instr;
568
wire  [2:0] fetchbuf0_insln;
569 49 robfinch
wire [`ABITS] fetchbuf0_pc;
570 48 robfinch
wire        fetchbuf0_v;
571
wire            fetchbuf0_thrd;
572
wire        fetchbuf0_mem;
573
wire            fetchbuf0_memld;
574
wire        fetchbuf0_rfw;
575
wire [47:0] fetchbuf1_instr;
576
wire  [2:0] fetchbuf1_insln;
577 49 robfinch
wire [`ABITS] fetchbuf1_pc;
578 48 robfinch
wire        fetchbuf1_v;
579
wire            fetchbuf1_thrd;
580
wire        fetchbuf1_mem;
581
wire            fetchbuf1_memld;
582
wire        fetchbuf1_rfw;
583 57 robfinch
wire [47:0] fetchbuf2_instr;
584
wire  [2:0] fetchbuf2_insln;
585
wire [`ABITS] fetchbuf2_pc;
586
wire        fetchbuf2_v;
587
wire            fetchbuf2_thrd;
588
wire        fetchbuf2_mem;
589
wire            fetchbuf2_memld;
590
wire        fetchbuf2_rfw;
591 48 robfinch
 
592
wire [47:0] fetchbufA_instr;
593 49 robfinch
wire [`ABITS] fetchbufA_pc;
594 48 robfinch
wire        fetchbufA_v;
595
wire [47:0] fetchbufB_instr;
596 49 robfinch
wire [`ABITS] fetchbufB_pc;
597 48 robfinch
wire        fetchbufB_v;
598
wire [47:0] fetchbufC_instr;
599 49 robfinch
wire [`ABITS] fetchbufC_pc;
600 48 robfinch
wire        fetchbufC_v;
601
wire [47:0] fetchbufD_instr;
602 49 robfinch
wire [`ABITS] fetchbufD_pc;
603 48 robfinch
wire        fetchbufD_v;
604 57 robfinch
wire [47:0] fetchbufE_instr;
605
wire [`ABITS] fetchbufE_pc;
606
wire        fetchbufE_v;
607
wire [47:0] fetchbufF_instr;
608
wire [`ABITS] fetchbufF_pc;
609
wire        fetchbufF_v;
610 48 robfinch
 
611
//reg        did_branchback0;
612
//reg        did_branchback1;
613
 
614
reg         id1_v;
615
reg   [4:0] id1_id;
616
reg  [47:0] id1_instr;
617
reg   [5:0] id1_ven;
618
reg   [7:0] id1_vl;
619
reg         id1_thrd;
620
reg         id1_pt;
621
reg   [4:0] id1_Rt;
622 51 robfinch
wire [143:0] id1_bus;
623 48 robfinch
 
624
reg         id2_v;
625
reg   [4:0] id2_id;
626
reg  [47:0] id2_instr;
627
reg   [5:0] id2_ven;
628
reg   [7:0] id2_vl;
629
reg         id2_thrd;
630
reg         id2_pt;
631
reg   [4:0] id2_Rt;
632 51 robfinch
wire [143:0] id2_bus;
633 48 robfinch
 
634 49 robfinch
reg         id3_v;
635
reg   [4:0] id3_id;
636
reg  [47:0] id3_instr;
637
reg   [5:0] id3_ven;
638
reg   [7:0] id3_vl;
639
reg         id3_thrd;
640
reg         id3_pt;
641
reg   [4:0] id3_Rt;
642 51 robfinch
wire [143:0] id3_bus;
643 49 robfinch
 
644 48 robfinch
reg        alu0_ld;
645
reg        alu0_dataready;
646
wire       alu0_done;
647
wire       alu0_idle;
648
reg  [3:0] alu0_sourceid;
649
reg [47:0] alu0_instr;
650
reg        alu0_bt;
651
reg        alu0_mem;
652
reg        alu0_shft48;
653
reg [63:0] alu0_argA;
654
reg [63:0] alu0_argB;
655
reg [63:0] alu0_argC;
656
reg [63:0] alu0_argI;    // only used by BEQ
657
reg [RBIT:0] alu0_tgt;
658
reg [5:0]  alu0_ven;
659
reg        alu0_thrd;
660 49 robfinch
reg [`ABITS] alu0_pc;
661 48 robfinch
wire [63:0] alu0_bus;
662
wire [63:0] alu0b_bus;
663
wire  [3:0] alu0_id;
664 49 robfinch
wire  [`XBITS] alu0_exc;
665 48 robfinch
wire        alu0_v;
666
wire        alu0_branchmiss;
667 49 robfinch
wire [`ABITS] alu0_misspc;
668 48 robfinch
 
669
reg        alu1_ld;
670
reg        alu1_dataready;
671
wire       alu1_done;
672
wire       alu1_idle;
673
reg  [3:0] alu1_sourceid;
674
reg [47:0] alu1_instr;
675
reg        alu1_bt;
676
reg        alu1_mem;
677
reg        alu1_shft48;
678
reg [63:0] alu1_argA;
679
reg [63:0] alu1_argB;
680
reg [63:0] alu1_argC;
681
reg [63:0] alu1_argI;    // only used by BEQ
682
reg [RBIT:0] alu1_tgt;
683
reg [5:0]  alu1_ven;
684 49 robfinch
reg [`ABITS] alu1_pc;
685 48 robfinch
reg        alu1_thrd;
686
wire [63:0] alu1_bus;
687
wire [63:0] alu1b_bus;
688
wire  [3:0] alu1_id;
689 49 robfinch
wire  [`XBITS] alu1_exc;
690 48 robfinch
wire        alu1_v;
691
wire        alu1_branchmiss;
692 49 robfinch
wire [`ABITS] alu1_misspc;
693 48 robfinch
 
694 52 robfinch
wire [`XBITS] fpu_exc;
695 49 robfinch
reg        fpu1_ld;
696
reg        fpu1_dataready = 1'b1;
697
wire       fpu1_done = 1'b1;
698
wire       fpu1_idle;
699
reg  [3:0] fpu1_sourceid;
700
reg [47:0] fpu1_instr;
701
reg [63:0] fpu1_argA;
702
reg [63:0] fpu1_argB;
703
reg [63:0] fpu1_argC;
704
reg [63:0] fpu1_argI;    // only used by BEQ
705
reg [RBIT:0] fpu1_tgt;
706
reg [`ABITS] fpu1_pc;
707 53 robfinch
wire [63:0] fpu1_bus = 64'h0;
708 49 robfinch
wire  [3:0] fpu1_id;
709
wire  [`XBITS] fpu1_exc = 9'h000;
710
wire        fpu1_v;
711
wire [31:0] fpu1_status;
712 48 robfinch
 
713 49 robfinch
reg        fpu2_ld;
714
reg        fpu2_dataready = 1'b1;
715
wire       fpu2_done = 1'b1;
716
wire       fpu2_idle;
717
reg  [3:0] fpu2_sourceid;
718
reg [47:0] fpu2_instr;
719
reg [63:0] fpu2_argA;
720
reg [63:0] fpu2_argB;
721
reg [63:0] fpu2_argC;
722
reg [63:0] fpu2_argI;    // only used by BEQ
723
reg [RBIT:0] fpu2_tgt;
724
reg [`ABITS] fpu2_pc;
725 53 robfinch
wire [63:0] fpu2_bus = 64'h0;
726 49 robfinch
wire  [3:0] fpu2_id;
727
wire  [`XBITS] fpu2_exc = 9'h000;
728
wire        fpu2_v;
729
wire [31:0] fpu2_status;
730
 
731 48 robfinch
reg [63:0] waitctr;
732
reg        fcu_ld;
733
reg        fcu_dataready;
734
reg        fcu_done;
735
reg         fcu_idle = 1'b1;
736
reg  [3:0] fcu_sourceid;
737
reg [47:0] fcu_instr;
738
reg  [2:0] fcu_insln;
739 51 robfinch
reg        fcu_branch;
740 48 robfinch
reg        fcu_call;
741 51 robfinch
reg        fcu_ret;
742
reg        fcu_jal;
743
reg        fcu_brk;
744
reg        fcu_rti;
745 48 robfinch
reg        fcu_bt;
746
reg [63:0] fcu_argA;
747
reg [63:0] fcu_argB;
748
reg [63:0] fcu_argC;
749
reg [63:0] fcu_argI;     // only used by BEQ
750
reg [63:0] fcu_argT;
751
reg [63:0] fcu_argT2;
752 49 robfinch
reg [`ABITS] fcu_pc;
753
reg [`ABITS] fcu_nextpc;
754
reg [`ABITS] fcu_brdisp;
755 48 robfinch
wire [63:0] fcu_bus;
756
wire  [3:0] fcu_id;
757 49 robfinch
reg   [`XBITS] fcu_exc;
758 48 robfinch
wire        fcu_v;
759
reg        fcu_thrd;
760
reg        fcu_branchmiss;
761
reg  fcu_clearbm;
762 49 robfinch
reg [`ABITS] fcu_misspc;
763 48 robfinch
 
764
reg [63:0] rmw_argA;
765
reg [63:0] rmw_argB;
766
reg [63:0] rmw_argC;
767
wire [63:0] rmw_res;
768
reg [31:0] rmw_instr;
769
 
770 49 robfinch
// write buffer
771
reg [63:0] wb_data [0:`WB_DEPTH-1];
772
reg [`ABITS] wb_addr [0:`WB_DEPTH-1];
773
reg [1:0] wb_ol [0:`WB_DEPTH-1];
774
reg [`WB_DEPTH-1:0] wb_v;
775
reg [`WB_DEPTH-1:0] wb_rmw;
776
reg [QENTRIES-1:0] wb_id [0:`WB_DEPTH-1];
777
reg [QENTRIES-1:0] wbo_id;
778
reg [7:0] wb_sel [0:`WB_DEPTH-1];
779
reg wb_en;
780 52 robfinch
reg wb_shift;
781 49 robfinch
 
782 48 robfinch
reg branchmiss = 1'b0;
783
reg branchmiss_thrd = 1'b0;
784 49 robfinch
reg [`ABITS] misspc;
785 48 robfinch
reg  [`QBITS] missid;
786
 
787
wire take_branch;
788
wire take_branchA;
789
wire take_branchB;
790
wire take_branchC;
791
wire take_branchD;
792
 
793
wire        dram_avail;
794
reg      [2:0] dram0;    // state of the DRAM request (latency = 4; can have three in pipeline)
795
reg      [2:0] dram1;    // state of the DRAM request (latency = 4; can have three in pipeline)
796
reg      [2:0] dram2;    // state of the DRAM request (latency = 4; can have three in pipeline)
797
reg [63:0] dram0_data;
798 49 robfinch
reg [`ABITS] dram0_addr;
799 48 robfinch
reg [47:0] dram0_instr;
800
reg        dram0_rmw;
801
reg                dram0_preload;
802
reg [RBIT:0] dram0_tgt;
803
reg  [3:0] dram0_id;
804 49 robfinch
reg  [`XBITS] dram0_exc;
805 48 robfinch
reg        dram0_unc;
806
reg [2:0]  dram0_memsize;
807
reg        dram0_load;  // is a load operation
808 50 robfinch
reg        dram0_store;
809 48 robfinch
reg  [1:0] dram0_ol;
810
reg [63:0] dram1_data;
811 49 robfinch
reg [`ABITS] dram1_addr;
812 48 robfinch
reg [47:0] dram1_instr;
813
reg        dram1_rmw;
814
reg                dram1_preload;
815
reg [RBIT:0] dram1_tgt;
816
reg  [3:0] dram1_id;
817 49 robfinch
reg  [`XBITS] dram1_exc;
818 48 robfinch
reg        dram1_unc;
819
reg [2:0]  dram1_memsize;
820
reg        dram1_load;
821 50 robfinch
reg        dram1_store;
822 48 robfinch
reg  [1:0] dram1_ol;
823
reg [63:0] dram2_data;
824 49 robfinch
reg [`ABITS] dram2_addr;
825 48 robfinch
reg [47:0] dram2_instr;
826
reg        dram2_rmw;
827
reg                dram2_preload;
828
reg [RBIT:0] dram2_tgt;
829
reg  [3:0] dram2_id;
830 49 robfinch
reg  [`XBITS] dram2_exc;
831 48 robfinch
reg        dram2_unc;
832
reg [2:0]  dram2_memsize;
833
reg        dram2_load;
834 50 robfinch
reg        dram2_store;
835 48 robfinch
reg  [1:0] dram2_ol;
836
 
837
reg        dramA_v;
838
reg  [3:0] dramA_id;
839
reg [63:0] dramA_bus;
840 49 robfinch
reg  [`XBITS] dramA_exc;
841 48 robfinch
reg        dramB_v;
842
reg  [3:0] dramB_id;
843
reg [63:0] dramB_bus;
844 49 robfinch
reg  [`XBITS] dramB_exc;
845 48 robfinch
reg        dramC_v;
846
reg  [3:0] dramC_id;
847
reg [63:0] dramC_bus;
848 49 robfinch
reg  [`XBITS] dramC_exc;
849 48 robfinch
 
850
wire        outstanding_stores;
851 58 robfinch
reg [63:0] I;            // instruction count
852
reg [63:0] CC;   // commit count
853 48 robfinch
 
854
reg        commit0_v;
855
reg  [4:0] commit0_id;
856
reg [RBIT:0] commit0_tgt;
857
reg  [7:0] commit0_we = 8'h00;
858
reg [63:0] commit0_bus;
859
reg        commit1_v;
860
reg  [4:0] commit1_id;
861
reg [RBIT:0] commit1_tgt;
862
reg  [7:0] commit1_we = 8'h00;
863
reg [63:0] commit1_bus;
864 58 robfinch
reg        commit2_v;
865
reg  [4:0] commit2_id;
866
reg [RBIT:0] commit2_tgt;
867
reg  [7:0] commit2_we = 8'h00;
868
reg [63:0] commit2_bus;
869 48 robfinch
 
870
reg [4:0] bstate;
871
parameter BIDLE = 5'd0;
872 58 robfinch
parameter B_DCacheStoreAck = 5'd1;
873
parameter B_DCacheLoadStart = 5'd2;
874
parameter B_DCacheLoadStb = 5'd3;
875
parameter B_DCacheLoadWait1 = 5'd4;
876
parameter B_DCacheLoadWait2 = 5'd5;
877
parameter B_DCacheLoadResetBusy = 5'd6;
878 59 robfinch
parameter B_ICacheAck = 5'd7;
879 48 robfinch
parameter B8 = 5'd8;
880 59 robfinch
parameter B_ICacheNack = 5'd9;
881 48 robfinch
parameter B10 = 5'd10;
882
parameter B11 = 5'd11;
883
parameter B12 = 5'd12;
884
parameter B13 = 5'd13;
885
parameter B14 = 5'd14;
886
parameter B15 = 5'd15;
887
parameter B16 = 5'd16;
888
parameter B17 = 5'd17;
889
parameter B18 = 5'd18;
890
parameter B19 = 5'd19;
891
parameter B2a = 5'd20;
892
parameter B2b = 5'd21;
893
parameter B2c = 5'd22;
894 58 robfinch
parameter B_DCacheLoadAck = 5'd23;
895 48 robfinch
parameter B20 = 5'd24;
896
parameter B21 = 5'd25;
897 58 robfinch
parameter B_DCacheLoadWait3 = 5'd26;
898 48 robfinch
reg [1:0] bwhich;
899
reg [3:0] icstate,picstate;
900
parameter IDLE = 4'd0;
901
parameter IC1 = 4'd1;
902
parameter IC2 = 4'd2;
903
parameter IC3 = 4'd3;
904 59 robfinch
parameter IC_WaitL2 = 4'd4;
905 48 robfinch
parameter IC5 = 4'd5;
906
parameter IC6 = 4'd6;
907
parameter IC7 = 4'd7;
908 59 robfinch
parameter IC_Next = 4'd8;
909 48 robfinch
parameter IC9 = 4'd9;
910
parameter IC10 = 4'd10;
911
parameter IC3a = 4'd11;
912
reg invic, invdc;
913 49 robfinch
reg [1:0] icwhich;
914
reg icnxt,L2_nxt;
915
wire ihit0,ihit1,ihit2,ihitL2;
916
wire ihit = ihit0&ihit1&ihit2;
917 48 robfinch
reg phit;
918
wire threadx;
919
always @*
920
        phit <= ihit&&icstate==IDLE;
921
reg [2:0] iccnt;
922 49 robfinch
reg L1_wr0,L1_wr1,L1_wr2;
923 48 robfinch
reg L1_invline;
924 59 robfinch
wire [1:0] ic0_fault,ic1_fault,ic2_fault;
925 49 robfinch
reg [8:0] L1_en;
926 48 robfinch
reg [37:0] L1_adr, L2_adr;
927 59 robfinch
reg [289:0] L2_rdat;
928
wire [289:0] L2_dato;
929 48 robfinch
reg L2_xsel;
930
 
931 57 robfinch
generate begin : gRegfileInst
932
if (`WAYS > 2) begin : gb1
933
FT64_regfile2w9r_oc #(.RBIT(RBIT)) urf1
934 48 robfinch
(
935
  .clk(clk),
936
  .clk4x(clk4x),
937
  .wr0(commit0_v),
938
  .wr1(commit1_v),
939
  .we0(commit0_we),
940
  .we1(commit1_we),
941
  .wa0(commit0_tgt),
942
  .wa1(commit1_tgt),
943
  .i0(commit0_bus),
944
  .i1(commit1_bus),
945
        .rclk(~clk),
946
        .ra0(Ra0),
947
        .ra1(Rb0),
948
        .ra2(Rc0),
949 57 robfinch
        .o0(rfoa0),
950
        .o1(rfob0),
951
        .o2(rfoc0a),
952 48 robfinch
        .ra3(Ra1),
953
        .ra4(Rb1),
954
        .ra5(Rc1),
955 57 robfinch
        .o3(rfoa1),
956
        .o4(rfob1),
957
        .o5(rfoc1a),
958
        .ra6(Ra2),
959
        .ra7(Rb2),
960
        .ra8(Rc2),
961
        .o6(rfoa2),
962
        .o7(rfob2),
963
        .o8(rfoc2a)
964
);
965
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
966
assign rfoc1 = Rc1[11:6]==6'h3F ? vm[Rc1[2:0]] : rfoc1a;
967
assign rfoc2 = Rc2[11:6]==6'h3F ? vm[Rc2[2:0]] : rfoc2a;
968
end
969
else if (`WAYS > 1) begin : gb1
970
FT64_regfile2w6r_oc #(.RBIT(RBIT)) urf1
971
(
972
  .clk(clk),
973
  .clk4x(clk4x),
974
  .wr0(commit0_v),
975
  .wr1(commit1_v),
976
  .we0(commit0_we),
977
  .we1(commit1_we),
978
  .wa0(commit0_tgt),
979
  .wa1(commit1_tgt),
980
  .i0(commit0_bus),
981
  .i1(commit1_bus),
982
        .rclk(~clk),
983
        .ra0(Ra0),
984
        .ra1(Rb0),
985
        .ra2(Rc0),
986 48 robfinch
        .o0(rfoa0),
987
        .o1(rfob0),
988
        .o2(rfoc0a),
989 57 robfinch
        .ra3(Ra1),
990
        .ra4(Rb1),
991
        .ra5(Rc1),
992 48 robfinch
        .o3(rfoa1),
993
        .o4(rfob1),
994
        .o5(rfoc1a)
995
);
996
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
997
assign rfoc1 = Rc1[11:6]==6'h3F ? vm[Rc1[2:0]] : rfoc1a;
998 57 robfinch
end
999
else begin : gb1
1000
FT64_regfile1w3r_oc #(.RBIT(RBIT)) urf1
1001
(
1002
  .clk(clk),
1003
  .wr0(commit0_v),
1004
  .we0(commit0_we),
1005
  .wa0(commit0_tgt),
1006
  .i0(commit0_bus),
1007
        .rclk(~clk),
1008
        .ra0(Ra0),
1009
        .ra1(Rb0),
1010
        .ra2(Rc0),
1011
        .o0(rfoa0),
1012
        .o1(rfob0),
1013
        .o2(rfoc0a)
1014
);
1015
end
1016
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
1017
end
1018
endgenerate
1019 48 robfinch
 
1020 55 robfinch
function [3:0] fnInsLength;
1021 48 robfinch
input [47:0] ins;
1022 57 robfinch
`ifdef SUPPORT_DCI
1023 55 robfinch
if (ins[`INSTRUCTION_OP]==`CMPRSSD)
1024
        fnInsLength = 4'd2;
1025
else
1026 57 robfinch
`endif
1027 55 robfinch
        case(ins[7:6])
1028
        2'd0:   fnInsLength = 4'd4;
1029
        2'd1:   fnInsLength = 4'd6;
1030
        default:        fnInsLength = 4'd2;
1031
        endcase
1032 48 robfinch
endfunction
1033
 
1034 49 robfinch
wire [`ABITS] pc0plus6 = pc0 + 32'd6;
1035
wire [`ABITS] pc0plus12 = pc0 + 32'd12;
1036 48 robfinch
 
1037 49 robfinch
generate begin : gInsnVar
1038
        if (`WAYS > 1) begin
1039 52 robfinch
                always @*
1040
                        if (thread_en)
1041
                                insn1a <= insn1b;
1042
                        else
1043
                                insn1a = {insn1b,insn0a} >> {fnInsLength(insn0a),3'b0};
1044 49 robfinch
        end
1045
        if (`WAYS > 2) begin
1046 52 robfinch
                always @*
1047
                        if (thread_en)
1048
                                insn2a <= insn2b;
1049
                        else
1050
                                insn2a = {insn2b,insn1b,insn0a} >> {fnInsLength(insn0a) + fnInsLength(insn1a),3'b0};
1051 49 robfinch
        end
1052
end
1053
endgenerate
1054 48 robfinch
 
1055 58 robfinch
FT64_L1_icache #(.pSize(`L1_ICACHE_SIZE)) uic0
1056 48 robfinch
(
1057
    .rst(rst),
1058
    .clk(clk),
1059
    .nxt(icnxt),
1060
    .wr(L1_wr0),
1061
    .en(L1_en),
1062 59 robfinch
    .adr(icstate==IDLE||icstate==IC_Next ? {pcr[5:0],pc0} : L1_adr),
1063 48 robfinch
    .wadr(L1_adr),
1064
    .i(L2_rdat),
1065
    .o(insn0a),
1066 59 robfinch
    .fault(ic0_fault),
1067 48 robfinch
    .hit(ihit0),
1068
    .invall(invic),
1069
    .invline(L1_invline)
1070
);
1071 49 robfinch
generate begin : gICacheInst
1072
if (`WAYS > 1) begin
1073 58 robfinch
FT64_L1_icache #(.pSize(`L1_ICACHE_SIZE)) uic1
1074 48 robfinch
(
1075
    .rst(rst),
1076
    .clk(clk),
1077
    .nxt(icnxt),
1078
    .wr(L1_wr1),
1079
    .en(L1_en),
1080 59 robfinch
    .adr(icstate==IDLE||icstate==IC_Next ? (thread_en ? {pcr[5:0],pc1}: {pcr[5:0],pc0plus6} ): L1_adr),
1081 48 robfinch
    .wadr(L1_adr),
1082
    .i(L2_rdat),
1083
    .o(insn1b),
1084 59 robfinch
    .fault(ic1_fault),
1085 48 robfinch
    .hit(ihit1),
1086
    .invall(invic),
1087
    .invline(L1_invline)
1088
);
1089 49 robfinch
end
1090
else begin
1091
assign ihit1 = 1'b1;
1092
end
1093
if (`WAYS > 2) begin
1094 58 robfinch
FT64_L1_icache #(.pSize(`L1_ICACHE_SIZE)) uic2
1095 49 robfinch
(
1096
    .rst(rst),
1097
    .clk(clk),
1098
    .nxt(icnxt),
1099
    .wr(L1_wr2),
1100
    .en(L1_en),
1101 59 robfinch
    .adr(icstate==IDLE||icstate==IC_Next ? (thread_en ? {pcr[5:0],pc2} : {pcr[5:0],pc0plus12}) : L1_adr),
1102 49 robfinch
    .wadr(L1_adr),
1103
    .i(L2_rdat),
1104
    .o(insn2b),
1105 59 robfinch
    .fault(ic2_fault),
1106 49 robfinch
    .hit(ihit2),
1107
    .invall(invic),
1108
    .invline(L1_invline)
1109
);
1110
end
1111
else
1112
assign ihit2 = 1'b1;
1113
end
1114
endgenerate
1115
 
1116 48 robfinch
FT64_L2_icache uic2
1117
(
1118
    .rst(rst),
1119
    .clk(clk),
1120
    .nxt(L2_nxt),
1121 59 robfinch
    .wr(bstate==B_ICacheAck && ack_i),
1122 48 robfinch
    .xsel(L2_xsel),
1123
    .adr(L2_adr),
1124
    .cnt(iccnt),
1125
    .exv_i(exvq),
1126
    .i(dat_i),
1127
    .err_i(errq),
1128
    .o(L2_dato),
1129 49 robfinch
    .hit(ihitL2),
1130 48 robfinch
    .invall(invic),
1131
    .invline()
1132
);
1133
 
1134
wire predict_taken;
1135
wire predict_taken0;
1136
wire predict_taken1;
1137 57 robfinch
wire predict_taken2;
1138 48 robfinch
wire predict_takenA;
1139
wire predict_takenB;
1140
wire predict_takenC;
1141
wire predict_takenD;
1142 57 robfinch
wire predict_takenE;
1143
wire predict_takenF;
1144 48 robfinch
wire predict_takenA1;
1145
wire predict_takenB1;
1146
wire predict_takenC1;
1147
wire predict_takenD1;
1148
 
1149 57 robfinch
wire [`ABITS] btgtA, btgtB, btgtC, btgtD, btgtE, btgtF;
1150 48 robfinch
wire btbwr0 = iqentry_v[head0] && iqentry_done[head0] &&
1151
        (
1152 51 robfinch
        iqentry_jal[head0] ||
1153
        iqentry_brk[head0] ||
1154
        iqentry_rti[head0]);
1155 57 robfinch
generate begin: gbtbvar
1156
if (`WAYS > 1) begin
1157 48 robfinch
wire btbwr1 = iqentry_v[head1] && iqentry_done[head1] &&
1158
        (
1159 51 robfinch
        iqentry_jal[head1] ||
1160
        iqentry_brk[head1] ||
1161
        iqentry_rti[head1]);
1162 57 robfinch
end
1163
end
1164
endgenerate
1165 48 robfinch
 
1166 50 robfinch
wire fcu_clk;
1167 49 robfinch
`ifdef FCU_ENH
1168 50 robfinch
//BUFGCE ufcuclk
1169
//(
1170
//      .I(clk_i),
1171
//      .CE(fcu_available),
1172
//      .O(fcu_clk)
1173
//);
1174 49 robfinch
`endif
1175 50 robfinch
assign fcu_clk = clk_i;
1176 49 robfinch
 
1177 57 robfinch
generate begin: gBTBInst
1178
if (`WAYS > 2) begin
1179 49 robfinch
`ifdef FCU_ENH
1180 48 robfinch
FT64_BTB ubtb1
1181
(
1182 49 robfinch
  .rst(rst),
1183
  .wclk(fcu_clk),
1184
  .wr(btbwr0 | btbwr1),
1185
  .wadr(btbwr0 ? iqentry_pc[head0] : iqentry_pc[head1]),
1186
  .wdat(btbwr0 ? iqentry_a0[head0] : iqentry_a0[head1]),
1187
  .valid(btbwr0 ? iqentry_bt[head0] & iqentry_v[head0] : iqentry_bt[head1] & iqentry_v[head1]),
1188
  .rclk(~clk),
1189
  .pcA(fetchbufA_pc),
1190
  .btgtA(btgtA),
1191
  .pcB(fetchbufB_pc),
1192
  .btgtB(btgtB),
1193
  .pcC(fetchbufC_pc),
1194
  .btgtC(btgtC),
1195
  .pcD(fetchbufD_pc),
1196
  .btgtD(btgtD),
1197 57 robfinch
  .pcE(fetchbufE_pc),
1198
  .btgtE(btgtE),
1199
  .pcF(fetchbufF_pc),
1200
  .btgtF(btgtF),
1201 49 robfinch
  .npcA(BRKPC),
1202
  .npcB(BRKPC),
1203
  .npcC(BRKPC),
1204 57 robfinch
  .npcD(BRKPC),
1205
  .npcE(BRKPC),
1206
  .npcF(BRKPC)
1207 48 robfinch
);
1208 49 robfinch
`else
1209
// Branch tergets are picked up by fetchbuf logic and need to be present.
1210
// Without a target predictor they are just set to the reset address.
1211
// This virtually guarentees a miss.
1212
assign btgtA = RSTPC;
1213
assign btgtB = RSTPC;
1214
assign btgtC = RSTPC;
1215
assign btgtD = RSTPC;
1216 57 robfinch
assign btgtE = RSTPC;
1217
assign btgtF = RSTPC;
1218 49 robfinch
`endif
1219 57 robfinch
end
1220
else if (`WAYS > 1) begin
1221
`ifdef FCU_ENH
1222
FT64_BTB ubtb1
1223
(
1224
  .rst(rst),
1225
  .wclk(fcu_clk),
1226
  .wr(btbwr0 | btbwr1),
1227
  .wadr(btbwr0 ? iqentry_pc[head0] : iqentry_pc[head1]),
1228
  .wdat(btbwr0 ? iqentry_a0[head0] : iqentry_a0[head1]),
1229
  .valid(btbwr0 ? iqentry_bt[head0] & iqentry_v[head0] : iqentry_bt[head1] & iqentry_v[head1]),
1230
  .rclk(~clk),
1231
  .pcA(fetchbufA_pc),
1232
  .btgtA(btgtA),
1233
  .pcB(fetchbufB_pc),
1234
  .btgtB(btgtB),
1235
  .pcC(fetchbufC_pc),
1236
  .btgtC(btgtC),
1237
  .pcD(fetchbufD_pc),
1238
  .btgtD(btgtD),
1239
  .pcE(32'd0),
1240
  .btgtE(),
1241
  .pcF(32'd0),
1242
  .btgtF(),
1243
  .npcA(BRKPC),
1244
  .npcB(BRKPC),
1245
  .npcC(BRKPC),
1246
  .npcD(BRKPC),
1247
  .npcE(BRKPC),
1248
  .npcF(BRKPC)
1249
);
1250
`else
1251
// Branch tergets are picked up by fetchbuf logic and need to be present.
1252
// Without a target predictor they are just set to the reset address.
1253
// This virtually guarentees a miss.
1254
assign btgtA = RSTPC;
1255
assign btgtB = RSTPC;
1256
assign btgtC = RSTPC;
1257
assign btgtD = RSTPC;
1258
`endif
1259
end
1260
else begin
1261
`ifdef FCU_ENH
1262
FT64_BTB ubtb1
1263
(
1264
  .rst(rst),
1265
  .wclk(fcu_clk),
1266
  .wr(btbwr0),
1267
  .wadr(iqentry_pc[head0]),
1268
  .wdat(iqentry_a0[head0]),
1269
  .valid(iqentry_bt[head0] & iqentry_v[head0]),
1270
  .rclk(~clk),
1271
  .pcA(fetchbufA_pc),
1272
  .btgtA(btgtA),
1273
  .pcB(fetchbufB_pc),
1274
  .btgtB(btgtB),
1275
  .pcC(32'd0),
1276
  .btgtC(),
1277
  .pcD(32'd0),
1278
  .btgtD(),
1279
  .pcE(32'd0),
1280
  .btgtE(),
1281
  .pcF(32'd0),
1282
  .btgtF(),
1283
  .npcA(BRKPC),
1284
  .npcB(BRKPC),
1285
  .npcC(BRKPC),
1286
  .npcD(BRKPC),
1287
  .npcE(BRKPC),
1288
  .npcF(BRKPC)
1289
);
1290
`else
1291
// Branch tergets are picked up by fetchbuf logic and need to be present.
1292
// Without a target predictor they are just set to the reset address.
1293
// This virtually guarentees a miss.
1294
assign btgtA = RSTPC;
1295
assign btgtB = RSTPC;
1296
`endif
1297
end
1298
end
1299
endgenerate
1300 48 robfinch
 
1301 57 robfinch
generate begin: gBPInst
1302
if (`WAYS > 2) begin
1303 49 robfinch
`ifdef FCU_ENH
1304 48 robfinch
FT64_BranchPredictor ubp1
1305
(
1306 49 robfinch
  .rst(rst),
1307
  .clk(fcu_clk),
1308
  .en(bpe),
1309
  .xisBranch0(iqentry_br[head0] & commit0_v),
1310
  .xisBranch1(iqentry_br[head1] & commit1_v),
1311 58 robfinch
  .xisBranch2(iqentry_br[head2] & commit2_v),
1312 49 robfinch
  .pcA(fetchbufA_pc),
1313
  .pcB(fetchbufB_pc),
1314
  .pcC(fetchbufC_pc),
1315
  .pcD(fetchbufD_pc),
1316 57 robfinch
  .pcE(fetchbufE_pc),
1317
  .pcF(fetchbufF_pc),
1318 49 robfinch
  .xpc0(iqentry_pc[head0]),
1319
  .xpc1(iqentry_pc[head1]),
1320 58 robfinch
  .xpc2(iqentry_pc[head2]),
1321 52 robfinch
  .takb0(commit0_v & iqentry_takb[head0]),
1322
  .takb1(commit1_v & iqentry_takb[head1]),
1323 58 robfinch
  .takb2(commit2_v & iqentry_takb[head2]),
1324 49 robfinch
  .predict_takenA(predict_takenA),
1325
  .predict_takenB(predict_takenB),
1326
  .predict_takenC(predict_takenC),
1327 57 robfinch
  .predict_takenD(predict_takenD),
1328
  .predict_takenE(predict_takenE),
1329
  .predict_takenF(predict_takenF)
1330 48 robfinch
);
1331 49 robfinch
`else
1332
// Predict based on sign of displacement
1333
assign predict_takenA = fetchbufA_instr[31];
1334
assign predict_takenB = fetchbufB_instr[31];
1335
assign predict_takenC = fetchbufC_instr[31];
1336
assign predict_takenD = fetchbufD_instr[31];
1337 57 robfinch
assign predict_takenE = fetchbufE_instr[31];
1338
assign predict_takenF = fetchbufF_instr[31];
1339 49 robfinch
`endif
1340 57 robfinch
end
1341
else if (`WAYS > 1) begin
1342
`ifdef FCU_ENH
1343
FT64_BranchPredictor ubp1
1344
(
1345
  .rst(rst),
1346
  .clk(fcu_clk),
1347
  .en(bpe),
1348
  .xisBranch0(iqentry_br[head0] & commit0_v),
1349
  .xisBranch1(iqentry_br[head1] & commit1_v),
1350 58 robfinch
  .xisBranch2(iqentry_br[head2] & commit2_v),
1351 57 robfinch
  .pcA(fetchbufA_pc),
1352
  .pcB(fetchbufB_pc),
1353
  .pcC(fetchbufC_pc),
1354
  .pcD(fetchbufD_pc),
1355
  .pcE(32'd0),
1356
  .pcF(32'd0),
1357
  .xpc0(iqentry_pc[head0]),
1358
  .xpc1(iqentry_pc[head1]),
1359 58 robfinch
  .xpc2(iqentry_pc[head2]),
1360 57 robfinch
  .takb0(commit0_v & iqentry_takb[head0]),
1361
  .takb1(commit1_v & iqentry_takb[head1]),
1362 58 robfinch
  .takb2(commit2_v & iqentry_takb[head2]),
1363 57 robfinch
  .predict_takenA(predict_takenA),
1364
  .predict_takenB(predict_takenB),
1365
  .predict_takenC(predict_takenC),
1366
  .predict_takenD(predict_takenD),
1367
  .predict_takenE(),
1368
  .predict_takenF()
1369
);
1370
`else
1371
// Predict based on sign of displacement
1372
assign predict_takenA = fetchbufA_instr[31];
1373
assign predict_takenB = fetchbufB_instr[31];
1374
assign predict_takenC = fetchbufC_instr[31];
1375
assign predict_takenD = fetchbufD_instr[31];
1376
`endif
1377
end
1378
else begin
1379
`ifdef FCU_ENH
1380
FT64_BranchPredictor ubp1
1381
(
1382
  .rst(rst),
1383
  .clk(fcu_clk),
1384
  .en(bpe),
1385
  .xisBranch0(iqentry_br[head0] & commit0_v),
1386 58 robfinch
  .xisBranch1(iqentry_br[head1] & commit1_v),
1387
  .xisBranch2(iqentry_br[head2] & commit2_v),
1388 57 robfinch
  .pcA(fetchbufA_pc),
1389
  .pcB(fetchbufB_pc),
1390
  .pcC(32'd0),
1391
  .pcD(32'd0),
1392
  .pcE(32'd0),
1393
  .pcF(32'd0),
1394
  .xpc0(iqentry_pc[head0]),
1395 58 robfinch
  .xpc1(iqentry_pc[head1]),
1396
  .xpc2(iqentry_pc[head2]),
1397 57 robfinch
  .takb0(commit0_v & iqentry_takb[head0]),
1398 58 robfinch
  .takb1(commit1_v & iqentry_takb[head1]),
1399
  .takb2(commit2_v & iqentry_takb[head2]),
1400 57 robfinch
  .predict_takenA(predict_takenA),
1401
  .predict_takenB(predict_takenB),
1402
  .predict_takenC(),
1403
  .predict_takenD(),
1404
  .predict_takenE(),
1405
  .predict_takenF()
1406
);
1407
`else
1408
// Predict based on sign of displacement
1409
assign predict_takenA = fetchbufA_instr[31];
1410
assign predict_takenB = fetchbufB_instr[31];
1411
`endif
1412
end
1413
end
1414
endgenerate
1415 48 robfinch
 
1416
//-----------------------------------------------------------------------------
1417
// Debug
1418
//-----------------------------------------------------------------------------
1419
`ifdef SUPPORT_DBG
1420
 
1421
wire [DBW-1:0] dbg_stat1x;
1422
reg [DBW-1:0] dbg_stat;
1423
reg [DBW-1:0] dbg_ctrl;
1424
reg [ABW-1:0] dbg_adr0;
1425
reg [ABW-1:0] dbg_adr1;
1426
reg [ABW-1:0] dbg_adr2;
1427
reg [ABW-1:0] dbg_adr3;
1428
reg dbg_imatchA0,dbg_imatchA1,dbg_imatchA2,dbg_imatchA3,dbg_imatchA;
1429
reg dbg_imatchB0,dbg_imatchB1,dbg_imatchB2,dbg_imatchB3,dbg_imatchB;
1430
 
1431
wire dbg_lmatch00 =
1432
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1433
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1434
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1435
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1436
                                 dbg_ctrl[19:18]==2'b11)
1437
                                 ;
1438
wire dbg_lmatch01 =
1439
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1440
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1441
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1442
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1443
                  dbg_ctrl[19:18]==2'b11)
1444
                  ;
1445
wire dbg_lmatch02 =
1446
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1447
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1448
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1449
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1450
                dbg_ctrl[19:18]==2'b11)
1451
                ;
1452
wire dbg_lmatch10 =
1453
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1454
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1455
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1456
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1457
                  dbg_ctrl[23:22]==2'b11)
1458
                  ;
1459
wire dbg_lmatch11 =
1460
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1461
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1462
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1463
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1464
                dbg_ctrl[23:22]==2'b11)
1465
                ;
1466
wire dbg_lmatch12 =
1467
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1468
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1469
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1470
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1471
                dbg_ctrl[23:22]==2'b11)
1472
                ;
1473
wire dbg_lmatch20 =
1474
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1475
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1476
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1477
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1478
                    dbg_ctrl[27:26]==2'b11)
1479
                    ;
1480
wire dbg_lmatch21 =
1481
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1482
                   ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1483
                    (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1484
                    (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1485
                    dbg_ctrl[27:26]==2'b11)
1486
                    ;
1487
wire dbg_lmatch22 =
1488
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1489
                   ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1490
                    (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1491
                    (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1492
                    dbg_ctrl[27:26]==2'b11)
1493
                    ;
1494
wire dbg_lmatch30 =
1495
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1496
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1497
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1498
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1499
                      dbg_ctrl[31:30]==2'b11)
1500
                      ;
1501
wire dbg_lmatch31 =
1502
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1503
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1504
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1505
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1506
                    dbg_ctrl[31:30]==2'b11)
1507
                    ;
1508
wire dbg_lmatch32 =
1509
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1510
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1511
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1512
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1513
                    dbg_ctrl[31:30]==2'b11)
1514
                    ;
1515
wire dbg_lmatch0 = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30;
1516
wire dbg_lmatch1 = dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31;
1517
wire dbg_lmatch2 = dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32;
1518
wire dbg_lmatch = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30|
1519
                  dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31|
1520
                  dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32
1521
                    ;
1522
 
1523
wire dbg_smatch00 =
1524
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1525
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1526
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1527
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1528
                                 dbg_ctrl[19:18]==2'b11)
1529
                                 ;
1530
wire dbg_smatch01 =
1531
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1532
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1533
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1534
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1535
                  dbg_ctrl[19:18]==2'b11)
1536
                  ;
1537
wire dbg_smatch02 =
1538
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1539
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1540
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1541
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1542
                dbg_ctrl[19:18]==2'b11)
1543
                ;
1544
wire dbg_smatch10 =
1545
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1546
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1547
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1548
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1549
                  dbg_ctrl[23:22]==2'b11)
1550
                  ;
1551
wire dbg_smatch11 =
1552
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1553
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1554
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1555
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1556
                dbg_ctrl[23:22]==2'b11)
1557
                ;
1558
wire dbg_smatch12 =
1559
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1560
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1561
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1562
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1563
                dbg_ctrl[23:22]==2'b11)
1564
                ;
1565
wire dbg_smatch20 =
1566
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1567
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1568
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1569
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1570
                    dbg_ctrl[27:26]==2'b11)
1571
                    ;
1572
wire dbg_smatch21 =
1573
           dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1574
                    ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1575
                     (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1576
                     (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1577
                     dbg_ctrl[27:26]==2'b11)
1578
                     ;
1579
wire dbg_smatch22 =
1580
            dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1581
                     ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1582
                      (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1583
                      (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1584
                      dbg_ctrl[27:26]==2'b11)
1585
                      ;
1586
wire dbg_smatch30 =
1587
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1588
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1589
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1590
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1591
                      dbg_ctrl[31:30]==2'b11)
1592
                      ;
1593
wire dbg_smatch31 =
1594
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1595
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1596
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1597
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1598
                    dbg_ctrl[31:30]==2'b11)
1599
                    ;
1600
wire dbg_smatch32 =
1601
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1602
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1603
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1604
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1605
                    dbg_ctrl[31:30]==2'b11)
1606
                    ;
1607
wire dbg_smatch0 = dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30;
1608
wire dbg_smatch1 = dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31;
1609
wire dbg_smatch2 = dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32;
1610
 
1611
wire dbg_smatch =   dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30|
1612
                    dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31|
1613
                    dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32
1614
                    ;
1615
 
1616
wire dbg_stat0 = dbg_imatchA0 | dbg_imatchB0 | dbg_lmatch00 | dbg_lmatch01 | dbg_lmatch02 | dbg_smatch00 | dbg_smatch01 | dbg_smatch02;
1617
wire dbg_stat1 = dbg_imatchA1 | dbg_imatchB1 | dbg_lmatch10 | dbg_lmatch11 | dbg_lmatch12 | dbg_smatch10 | dbg_smatch11 | dbg_smatch12;
1618
wire dbg_stat2 = dbg_imatchA2 | dbg_imatchB2 | dbg_lmatch20 | dbg_lmatch21 | dbg_lmatch22 | dbg_smatch20 | dbg_smatch21 | dbg_smatch22;
1619
wire dbg_stat3 = dbg_imatchA3 | dbg_imatchB3 | dbg_lmatch30 | dbg_lmatch31 | dbg_lmatch32 | dbg_smatch30 | dbg_smatch31 | dbg_smatch32;
1620
assign dbg_stat1x = {dbg_stat3,dbg_stat2,dbg_stat1,dbg_stat0};
1621
wire debug_on = |dbg_ctrl[3:0]|dbg_ctrl[7]|dbg_ctrl[63];
1622
 
1623
always @*
1624
begin
1625
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf0_pc==dbg_adr0)
1626
        dbg_imatchA0 = `TRUE;
1627
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf0_pc==dbg_adr1)
1628
        dbg_imatchA1 = `TRUE;
1629
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf0_pc==dbg_adr2)
1630
        dbg_imatchA2 = `TRUE;
1631
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf0_pc==dbg_adr3)
1632
        dbg_imatchA3 = `TRUE;
1633
    if (dbg_imatchA0|dbg_imatchA1|dbg_imatchA2|dbg_imatchA3)
1634
        dbg_imatchA = `TRUE;
1635
end
1636
 
1637
always @*
1638
begin
1639
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf1_pc==dbg_adr0)
1640
        dbg_imatchB0 = `TRUE;
1641
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf1_pc==dbg_adr1)
1642
        dbg_imatchB1 = `TRUE;
1643
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf1_pc==dbg_adr2)
1644
        dbg_imatchB2 = `TRUE;
1645
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf1_pc==dbg_adr3)
1646
        dbg_imatchB3 = `TRUE;
1647
    if (dbg_imatchB0|dbg_imatchB1|dbg_imatchB2|dbg_imatchB3)
1648
        dbg_imatchB = `TRUE;
1649
end
1650
`endif
1651
 
1652
//-----------------------------------------------------------------------------
1653
//-----------------------------------------------------------------------------
1654
 
1655 52 robfinch
// freezePC squashes the pc increment if there's an irq.
1656
wire freezePC = (irq_i > im) && ~int_commit;
1657 48 robfinch
always @*
1658 52 robfinch
if (freezePC)
1659 49 robfinch
        insn0 <= {8'd0,3'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1660 48 robfinch
else if (phit) begin
1661 49 robfinch
        if (insn0a[`INSTRUCTION_OP]==`BRK && insn0a[23:21]==3'd0 && insn0a[7:6]==2'b00)
1662
                insn0 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1663 48 robfinch
        else
1664 59 robfinch
                insn0 <= ic0_fault[1] ? `INSN_FLT_IBE : ic0_fault[0] ? `INSN_FLT_EXF : insn0a;
1665 48 robfinch
end
1666
else
1667
        insn0 <= `NOP_INSN;
1668 49 robfinch
generate begin : gInsnMux
1669
if (`WAYS > 1) begin
1670 48 robfinch
always @*
1671 52 robfinch
if (freezePC && !thread_en)
1672
        insn1 <= {8'd0,3'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1673
else if (phit) begin
1674 49 robfinch
        if (insn1a[`INSTRUCTION_OP]==`BRK && insn1a[23:21]==3'd0 && insn1a[7:6]==2'b00)
1675
                insn1 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1676 48 robfinch
        else
1677 59 robfinch
                insn1 <= ic1_fault[1] ? `INSN_FLT_IBE : ic1_fault[0] ? `INSN_FLT_EXF : insn1a;
1678 48 robfinch
end
1679
else
1680
        insn1 <= `NOP_INSN;
1681 49 robfinch
end
1682
if (`WAYS > 2) begin
1683
always @*
1684 52 robfinch
if (freezePC && !thread_en)
1685
        insn2 <= {8'd0,3'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1686
else if (phit) begin
1687 49 robfinch
        if (insn2a[`INSTRUCTION_OP]==`BRK && insn1a[23:21]==3'd0 && insn2a[7:6]==2'b00)
1688
                insn2 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1689
        else
1690 59 robfinch
                insn2 <= ic2_fault[1] ? `INSN_FLT_IBE : ic2_fault[0] ? `INSN_FLT_EXF : insn2a;
1691 49 robfinch
end
1692
else
1693
        insn2 <= `NOP_INSN;
1694
end
1695
end
1696
endgenerate
1697 48 robfinch
 
1698
wire [63:0] dc0_out, dc1_out, dc2_out;
1699
assign rdat0 = dram0_unc ? xdati : dc0_out;
1700
assign rdat1 = dram1_unc ? xdati : dc1_out;
1701
assign rdat2 = dram2_unc ? xdati : dc2_out;
1702
 
1703
reg preload;
1704
reg [1:0] dccnt;
1705
wire dhit0, dhit1, dhit2;
1706 57 robfinch
wire dhit0a, dhit1a, dhit2a;
1707 48 robfinch
wire dhit00, dhit10, dhit20;
1708
wire dhit01, dhit11, dhit21;
1709 49 robfinch
reg [`ABITS] dc_wadr;
1710 48 robfinch
reg [63:0] dc_wdat;
1711
reg isStore;
1712
 
1713 57 robfinch
// If the data is in the write buffer, give the buffer a chance to
1714
// write out the data before trying to load from the cache.
1715
reg wb_hit0, wb_hit1, wb_hit2;
1716
always @*
1717
begin
1718
        wb_hit0 <= FALSE;
1719
        wb_hit1 <= FALSE;
1720
        wb_hit2 <= FALSE;
1721
        for (n = 0; n < `WB_DEPTH; n = n + 1) begin
1722
                if (wb_v[n] && wb_addr[n][31:3]==dram0_addr[31:3])
1723
                        wb_hit0 <= TRUE;
1724
                if (`NUM_MEM > 1 && wb_addr[n][31:3]==dram1_addr[31:3])
1725
                        wb_hit1 <= TRUE;
1726
                if (`NUM_MEM > 2 && wb_addr[n][31:3]==dram2_addr[31:3])
1727
                        wb_hit2 <= TRUE;
1728
        end
1729
end
1730
 
1731
assign dhit0 = dhit0a & !wb_hit0;
1732
assign dhit1 = dhit1a & !wb_hit1;
1733
assign dhit2 = dhit2a & !wb_hit2;
1734
wire whit0, whit1, whit2;
1735
 
1736 48 robfinch
FT64_dcache udc0
1737
(
1738
    .rst(rst),
1739
    .wclk(clk),
1740 58 robfinch
    .wr((bstate==B_DCacheLoadAck && ack_i)||((bstate==B_DCacheStoreAck||(bstate==B19 && isStore)) && whit0)),
1741 48 robfinch
    .sel(sel_o),
1742
    .wadr({pcr[5:0],adr_o}),
1743 57 robfinch
    .whit(whit0),
1744 58 robfinch
    .i(bstate==B_DCacheLoadAck ? dat_i : dat_o),
1745 48 robfinch
    .rclk(clk),
1746
    .rdsize(dram0_memsize),
1747
    .radr({pcr[5:0],dram0_addr}),
1748
    .o(dc0_out),
1749
    .hit(),
1750 57 robfinch
    .hit0(dhit0a),
1751 48 robfinch
    .hit1()
1752
);
1753 49 robfinch
generate begin : gDCacheInst
1754
if (`NUM_MEM > 1) begin
1755 48 robfinch
FT64_dcache udc1
1756
(
1757
    .rst(rst),
1758
    .wclk(clk),
1759 58 robfinch
    .wr((bstate==B_DCacheLoadAck && ack_i)||((bstate==B_DCacheStoreAck||(bstate==B19 && isStore)) && whit1)),
1760 48 robfinch
    .sel(sel_o),
1761
    .wadr({pcr[5:0],adr_o}),
1762 57 robfinch
    .whit(whit1),
1763 58 robfinch
    .i(bstate==B_DCacheLoadAck ? dat_i : dat_o),
1764 48 robfinch
    .rclk(clk),
1765
    .rdsize(dram1_memsize),
1766
    .radr({pcr[5:0],dram1_addr}),
1767
    .o(dc1_out),
1768
    .hit(),
1769 57 robfinch
    .hit0(dhit1a),
1770 48 robfinch
    .hit1()
1771
);
1772 49 robfinch
end
1773
if (`NUM_MEM > 2) begin
1774 48 robfinch
FT64_dcache udc2
1775
(
1776
    .rst(rst),
1777
    .wclk(clk),
1778 58 robfinch
    .wr((bstate==B_DCacheLoadAck && ack_i)||((bstate==B_DCacheStoreAck||(bstate==B19 && isStore)) && whit2)),
1779 48 robfinch
    .sel(sel_o),
1780
    .wadr({pcr[5:0],adr_o}),
1781 57 robfinch
    .whit(whit2),
1782 58 robfinch
    .i(bstate==B_DCacheLoadAck ? dat_i : dat_o),
1783 48 robfinch
    .rclk(clk),
1784
    .rdsize(dram2_memsize),
1785
    .radr({pcr[5:0],dram2_addr}),
1786
    .o(dc2_out),
1787
    .hit(),
1788 57 robfinch
    .hit0(dhit2a),
1789 48 robfinch
    .hit1()
1790
);
1791 49 robfinch
end
1792
end
1793
endgenerate
1794 48 robfinch
 
1795
function [`QBITS] idp1;
1796
input [`QBITS] id;
1797 52 robfinch
idp1 = (id + 1) % QENTRIES;
1798 48 robfinch
endfunction
1799
 
1800
function [`QBITS] idp2;
1801
input [`QBITS] id;
1802 52 robfinch
idp2 = (id + 2) % QENTRIES;
1803 48 robfinch
endfunction
1804
 
1805
function [`QBITS] idp3;
1806
input [`QBITS] id;
1807 52 robfinch
idp3 = (id + 3) % QENTRIES;
1808 48 robfinch
endfunction
1809
 
1810
function [`QBITS] idp4;
1811
input [`QBITS] id;
1812 52 robfinch
idp4 = (id + 4) % QENTRIES;
1813 48 robfinch
endfunction
1814
 
1815
function [`QBITS] idp5;
1816
input [`QBITS] id;
1817 52 robfinch
idp5 = (id + 5) % QENTRIES;
1818 48 robfinch
endfunction
1819
 
1820
function [`QBITS] idp6;
1821
input [`QBITS] id;
1822 52 robfinch
idp6 = (id + 6) % QENTRIES;
1823 48 robfinch
endfunction
1824
 
1825
function [`QBITS] idp7;
1826
input [`QBITS] id;
1827 52 robfinch
idp7 = (id + 7) % QENTRIES;
1828 48 robfinch
endfunction
1829
 
1830 52 robfinch
function [`QBITS] idp8;
1831
input [`QBITS] id;
1832
idp8 = (id + 8) % QENTRIES;
1833
endfunction
1834
 
1835
function [`QBITS] idp9;
1836
input [`QBITS] id;
1837
idp9 = (id + 9) % QENTRIES;
1838
endfunction
1839
 
1840 48 robfinch
function [`QBITS] idm1;
1841
input [`QBITS] id;
1842 52 robfinch
idm1 = (id - 1) % QENTRIES;
1843 48 robfinch
endfunction
1844
 
1845
`ifdef SUPPORT_SMT
1846
function [RBIT:0] fnRa;
1847
input [47:0] isn;
1848
input [5:0] vqei;
1849
input [5:0] vli;
1850
input thrd;
1851
case(isn[`INSTRUCTION_OP])
1852
`IVECTOR:
1853
        case(isn[`INSTRUCTION_S2])
1854
        `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1855
        `VMxx:
1856
                case(isn[25:23])
1857
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
1858
                    fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1859
            `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1860
            default:fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1861
            endcase
1862
        `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
1863
        `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
1864
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1865
        default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1866
        endcase
1867 50 robfinch
`R2:    casez(isn[`INSTRUCTION_S2])
1868 48 robfinch
                `MOV:
1869
                        case(isn[25:23])
1870
                        3'd0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1871 50 robfinch
                        3'd1:   fnRa = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
1872 48 robfinch
                        3'd2:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1873
                        3'd3:   fnRa = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RA]};
1874
                        3'd4:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1875 51 robfinch
                        3'd5:   fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1876
                        3'd6:   fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1877 48 robfinch
                        default:fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1878
                        endcase
1879
        `VMOV:
1880
            case (isn[`INSTRUCTION_S1])
1881
            5'h0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1882
            5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
1883
            endcase
1884
        default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1885
        endcase
1886 51 robfinch
`FLOAT:         fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1887 48 robfinch
default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1888
endcase
1889
endfunction
1890
 
1891
function [RBIT:0] fnRb;
1892
input [47:0] isn;
1893
input fb;
1894
input [5:0] vqei;
1895
input [5:0] rfoa0i;
1896
input [5:0] rfoa1i;
1897
input thrd;
1898
case(isn[`INSTRUCTION_OP])
1899
`R2:        case(isn[`INSTRUCTION_S2])
1900
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
1901
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1902
            default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1903
            endcase
1904
`IVECTOR:
1905
                        case(isn[`INSTRUCTION_S2])
1906
                        `VMxx:
1907
                                case(isn[25:23])
1908
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
1909
                        fnRb = {6'h3F,1'b1,2'b0,isn[13:11]};
1910
                default:        fnRb = 12'h000;
1911
                endcase
1912
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1913
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1914
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
1915
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
1916
                fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1917
            `VSHL,`VSHR,`VASR:
1918
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
1919
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1920
            endcase
1921 51 robfinch
`FLOAT:         fnRb = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1922 48 robfinch
default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1923
endcase
1924
endfunction
1925
 
1926
function [RBIT:0] fnRc;
1927
input [47:0] isn;
1928
input [5:0] vqei;
1929
input thrd;
1930
case(isn[`INSTRUCTION_OP])
1931
`R2:        case(isn[`INSTRUCTION_S2])
1932
            `SVX:       fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1933
                `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1934
                        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1935
                `CMOVEZ,`CMOVNZ,`MAJ:
1936
                        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1937
            default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1938
            endcase
1939
`IVECTOR:
1940
                        case(isn[`INSTRUCTION_S2])
1941
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[18:16]};
1942
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1943
            endcase
1944 51 robfinch
`FLOAT:         fnRc = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1945 48 robfinch
default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1946
endcase
1947
endfunction
1948
 
1949
function [RBIT:0] fnRt;
1950
input [47:0] isn;
1951
input [5:0] vqei;
1952
input [5:0] vli;
1953
input thrd;
1954
casez(isn[`INSTRUCTION_OP])
1955
`IVECTOR:
1956
                case(isn[`INSTRUCTION_S2])
1957
                `VMxx:
1958
                        case(isn[25:23])
1959
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
1960
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1961
            `VMPOP:     fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1962
            default:
1963
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1964
            endcase
1965
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1966
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
1967
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
1968
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
1969
        `V2BITS:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1970
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1971
        endcase
1972
 
1973 50 robfinch
`R2:    casez(isn[`INSTRUCTION_S2])
1974 48 robfinch
                `MOV:
1975
                        case(isn[25:23])
1976 50 robfinch
                        3'd0:   fnRt = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RB]};
1977 48 robfinch
                        3'd1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1978
                        3'd2:   fnRt = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RB]};
1979
                        3'd3:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1980 51 robfinch
                        3'd4:   fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1981 48 robfinch
                        3'd5:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1982 51 robfinch
                        3'd6:   fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1983 48 robfinch
                        default:fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1984
                        endcase
1985
        `VMOV:
1986
            case (isn[`INSTRUCTION_S1])
1987
            5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RB]};
1988
            5'h1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1989
            default:    fnRt = 12'h000;
1990
            endcase
1991
        `R1:
1992
                case(isn[22:18])
1993
                `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT:
1994
                        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1995
                `MEMDB,`MEMSB,`SYNC:
1996
                        fnRt = 12'd0;
1997
                default:        fnRt = 12'd0;
1998
                endcase
1999
        `CMOVEZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
2000
        `CMOVNZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
2001
        `MUX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
2002
        `MIN:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
2003
        `MAX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
2004
        `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
2005
        `SHIFTR:        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2006
        `SHIFT31,`SHIFT63:
2007
                                fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2008
        `SEI:           fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2009
        `WAIT,`RTI,`CHK:
2010
                        fnRt = 12'd0;
2011
                default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2012
        endcase
2013
`MEMNDX:
2014
    case(isn[`INSTRUCTION_S2])
2015
    `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
2016
                        fnRt = 12'd0;
2017
    default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2018
        endcase
2019
`FLOAT:
2020
                case(isn[31:26])
2021
                `FTX,`FCX,`FEX,`FDX,`FRM:
2022
                                        fnRt = 12'd0;
2023
                `FSYNC:         fnRt = 12'd0;
2024 51 robfinch
                default:        fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2025 48 robfinch
                endcase
2026
`BRK:   fnRt = 12'd0;
2027
`REX:   fnRt = 12'd0;
2028
`CHK:   fnRt = 12'd0;
2029
`EXEC:  fnRt = 12'd0;
2030
`Bcc:   fnRt = 12'd0;
2031
`BBc:   case(isn[20:19])
2032
                `IBNE:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2033
                `DBNZ:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2034
                default:        fnRt = 12'd0;
2035
                endcase
2036
`BEQI:  fnRt = 12'd0;
2037
`SB,`Sx,`SWC,`CACHE:
2038
                fnRt = 12'd0;
2039
`JMP:   fnRt = 12'd0;
2040
`CALL:  fnRt = {rgs[thrd],1'b0,regLR};  // regLR
2041
`RET:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2042
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2043
`AMO:   fnRt = isn[31] ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2044 56 robfinch
`AUIPC,`LUI:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2045 48 robfinch
default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2046
endcase
2047
endfunction
2048
`else
2049
function [RBIT:0] fnRa;
2050
input [47:0] isn;
2051
input [5:0] vqei;
2052
input [5:0] vli;
2053
input thrd;
2054
case(isn[`INSTRUCTION_OP])
2055
`IVECTOR:
2056
        case(isn[`INSTRUCTION_S2])
2057 51 robfinch
  `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
2058
  `VMxx:
2059
        case(isn[25:23])
2060
        `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
2061
              fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
2062
      `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
2063
      default:fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
2064
      endcase
2065
  `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
2066
  `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
2067
  `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
2068
  default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
2069
  endcase
2070 50 robfinch
`R2:
2071
        casez(isn[`INSTRUCTION_S2])
2072
        `MOV:
2073
                case(isn[25:23])
2074
                3'd0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2075
                3'd1:   fnRa = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
2076
                3'd2:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2077
                3'd3:   fnRa = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RA]};
2078
                3'd4:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2079 51 robfinch
                3'd5:   fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2080
                3'd6:   fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2081 50 robfinch
                default:fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2082
                endcase
2083
  `VMOV:
2084
    case (isn[`INSTRUCTION_S1])
2085
    5'h0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2086
    5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
2087
    endcase
2088
  default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2089
  endcase
2090 51 robfinch
`FLOAT:         fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2091 48 robfinch
default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2092
endcase
2093
endfunction
2094
 
2095
function [RBIT:0] fnRb;
2096
input [47:0] isn;
2097
input fb;
2098
input [5:0] vqei;
2099
input [5:0] rfoa0i;
2100
input [5:0] rfoa1i;
2101
input thrd;
2102
case(isn[`INSTRUCTION_OP])
2103
`RR:        case(isn[`INSTRUCTION_S2])
2104
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
2105
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2106
            default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2107
            endcase
2108
`IVECTOR:
2109
                        case(isn[`INSTRUCTION_S2])
2110
                        `VMxx:
2111
                                case(isn[25:23])
2112
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2113
                        fnRb = {6'h3F,1'b1,2'b0,isn[13:11]};
2114
                default:        fnRb = 12'h000;
2115
                endcase
2116
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2117
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2118
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
2119
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
2120
                fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2121
            `VSHL,`VSHR,`VASR:
2122
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
2123
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2124
            endcase
2125 51 robfinch
`FLOAT:         fnRb = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
2126 48 robfinch
default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2127
endcase
2128
endfunction
2129
 
2130
function [RBIT:0] fnRc;
2131
input [47:0] isn;
2132
input [5:0] vqei;
2133
input thrd;
2134
case(isn[`INSTRUCTION_OP])
2135
`R2:        case(isn[`INSTRUCTION_S2])
2136
            `SVX:       fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2137
                `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
2138
                        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2139
                `CMOVEZ,`CMOVNZ,`MAJ:
2140
                        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2141
            default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2142
            endcase
2143
`IVECTOR:
2144
                        case(isn[`INSTRUCTION_S2])
2145
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[18:16]};
2146
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2147
            endcase
2148 51 robfinch
`FLOAT:         fnRc = {fp_rgs,1'b0,isn[`INSTRUCTION_RC]};
2149 48 robfinch
default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2150
endcase
2151
endfunction
2152
 
2153
function [RBIT:0] fnRt;
2154
input [47:0] isn;
2155
input [5:0] vqei;
2156
input [5:0] vli;
2157
input thrd;
2158
casez(isn[`INSTRUCTION_OP])
2159
`IVECTOR:
2160
                case(isn[`INSTRUCTION_S2])
2161
                `VMxx:
2162
                        case(isn[25:23])
2163
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
2164
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2165
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2166
            default:
2167
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2168
            endcase
2169
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2170
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
2171
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
2172
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
2173
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2174
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2175
        endcase
2176
 
2177
`FVECTOR:
2178
                case(isn[`INSTRUCTION_S2])
2179
                `VMxx:
2180
                        case(isn[25:23])
2181
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
2182
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2183
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2184
            default:
2185
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2186
            endcase
2187
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2188
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
2189
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
2190
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
2191
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2192
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2193
        endcase
2194
 
2195 50 robfinch
`R2:
2196
        casez(isn[`INSTRUCTION_S2])
2197
        `MOV:
2198
                case(isn[25:23])
2199
                3'd0:   fnRt = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RB]};
2200
                3'd1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2201
                3'd2:   fnRt = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RB]};
2202
                3'd3:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2203 51 robfinch
                3'd4:   fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
2204 50 robfinch
                3'd5:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2205 51 robfinch
                3'd6:   fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
2206 50 robfinch
                default:fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2207
                endcase
2208
  `VMOV:
2209
    case (isn[`INSTRUCTION_S1])
2210
    5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RB]};
2211
    5'h1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2212
    default:    fnRt = 12'h000;
2213
    endcase
2214
  `R1:
2215
        case(isn[22:18])
2216
        `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT:
2217
                fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2218
        `MEMDB,`MEMSB,`SYNC:
2219
                fnRt = 12'd0;
2220
        default:        fnRt = 12'd0;
2221
        endcase
2222
  `CMOVEZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2223
  `CMOVNZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2224
  `MUX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2225
  `MIN:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2226
  `MAX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2227
  `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
2228
  `SHIFTR:      fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2229
  `SHIFT31,`SHIFT63:
2230
                        fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2231
  `SEI:         fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2232
  `WAIT,`RTI,`CHK:
2233
                        fnRt = 12'd0;
2234
  default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2235
  endcase
2236 48 robfinch
`MEMNDX:
2237
        case(isn[`INSTRUCTION_S2])
2238
  `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
2239
                        fnRt = 12'd0;
2240
  default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2241
  endcase
2242
`FLOAT:
2243
                case(isn[31:26])
2244
                `FTX,`FCX,`FEX,`FDX,`FRM:
2245
                                        fnRt = 12'd0;
2246
                `FSYNC:         fnRt = 12'd0;
2247 51 robfinch
                default:        fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RC]};
2248 48 robfinch
                endcase
2249
`BRK:   fnRt = 12'd0;
2250
`REX:   fnRt = 12'd0;
2251
`CHK:   fnRt = 12'd0;
2252
`EXEC:  fnRt = 12'd0;
2253
`Bcc:   fnRt = 12'd0;
2254
`BBc:
2255
        case(isn[20:19])
2256
        `IBNE:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2257
        `DBNZ:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2258
        default:        fnRt = 12'd0;
2259
        endcase
2260
`BEQI:  fnRt = 12'd0;
2261
`SB,`Sx,`SWC,`CACHE:
2262
                fnRt = 12'd0;
2263
`JMP:   fnRt = 12'd0;
2264
`CALL:  fnRt = {rgs,1'b0,regLR};        // regLR
2265
`RET:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2266
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2267
`AMO:   fnRt = isn[31] ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {rgs,1'b0,isn[`INSTRUCTION_RC]};
2268 56 robfinch
`AUIPC,`LUI:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2269 48 robfinch
default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2270
endcase
2271
endfunction
2272
`endif
2273
 
2274
// Determines which lanes of the target register get updated.
2275
function [7:0] fnWe;
2276
input [47:0] isn;
2277
casez(isn[`INSTRUCTION_OP])
2278
`R2:
2279
        case(isn[`INSTRUCTION_S2])
2280
        `R1:
2281
                case(isn[22:18])
2282
                `ABS,`CNTLZ,`CNTLO,`CNTPOP:
2283
                        case(isn[25:23])
2284
                        3'b000: fnWe = 8'h01;
2285
                        3'b001: fnWe = 8'h03;
2286
                        3'b010: fnWe = 8'h0F;
2287
                        3'b011: fnWe = 8'hFF;
2288
                        default:        fnWe = 8'hFF;
2289
                        endcase
2290
                default: fnWe = 8'hFF;
2291
                endcase
2292
        `SHIFT31:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2293
        `SHIFT63:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2294
        `SLT,`SLTU,`SLE,`SLEU,
2295
        `ADD,`SUB,
2296
        `AND,`OR,`XOR,
2297
        `NAND,`NOR,`XNOR,
2298 50 robfinch
        `DIV,`DIVU,`DIVSU,
2299
        `MOD,`MODU,`MODSU,
2300
        `MUL,`MULU,`MULSU,
2301
        `MULH,`MULUH,`MULSUH:
2302 48 robfinch
                case(isn[25:23])
2303
                3'b000: fnWe = 8'h01;
2304
                3'b001: fnWe = 8'h03;
2305
                3'b010: fnWe = 8'h0F;
2306
                3'b011: fnWe = 8'hFF;
2307
                default:        fnWe = 8'hFF;
2308
                endcase
2309
        default: fnWe = 8'hFF;
2310
        endcase
2311
default:        fnWe = 8'hFF;
2312
endcase
2313
endfunction
2314
 
2315
// Detect if a source is automatically valid
2316
function Source1Valid;
2317
input [47:0] isn;
2318
casez(isn[`INSTRUCTION_OP])
2319
`BRK:   Source1Valid = TRUE;
2320
`Bcc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2321
`BBc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2322
`BEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2323
`CHK:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2324
`RR:    case(isn[`INSTRUCTION_S2])
2325
        `SHIFT31:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2326
        `SHIFT63:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2327
        `SHIFTR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2328
        default:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2329
        endcase
2330
`MEMNDX:Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2331
`ADDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2332
`SLTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2333
`SLTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2334
`SGTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2335
`SGTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2336
`ANDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2337
`ORI:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2338
`XORI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2339
`XNORI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2340
`MULUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2341
`AMO:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2342
`LB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2343
`LBU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2344
`Lx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2345
`LxU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2346
`LWR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2347
`LV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2348
`LVx:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2349
`SB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2350
`Sx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2351
`SWC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2352
`SV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2353
`INC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2354
`CAS:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2355
`JAL:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2356
`RET:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2357
`CSRRW: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2358 51 robfinch
`BITFIELD:      case(isn[47:44])
2359
        `BFINSI:        Source1Valid = TRUE;
2360
        default:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0 || isn[30]==1'b0;
2361
        endcase
2362 48 robfinch
`IVECTOR:
2363 51 robfinch
        Source1Valid = FALSE;
2364 48 robfinch
default:    Source1Valid = TRUE;
2365
endcase
2366
endfunction
2367
 
2368
function Source2Valid;
2369
input [47:0] isn;
2370
casez(isn[`INSTRUCTION_OP])
2371
`BRK:   Source2Valid = TRUE;
2372
`Bcc:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2373
`BBc:   Source2Valid = TRUE;
2374
`BEQI:  Source2Valid = TRUE;
2375
`CHK:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2376
`RR:    case(isn[`INSTRUCTION_S2])
2377
        `R1:       Source2Valid = TRUE;
2378
        `SHIFTR:   Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2379
        `SHIFT31:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2380
        `SHIFT63:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2381
        `LVX,`SVX: Source2Valid = FALSE;
2382
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2383
        endcase
2384
`MEMNDX:
2385
        case(isn[`INSTRUCTION_S2])
2386
        `LVX,`SVX: Source2Valid = FALSE;
2387
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2388
        endcase
2389
`ADDI:  Source2Valid = TRUE;
2390
`SLTI:  Source2Valid = TRUE;
2391
`SLTUI: Source2Valid = TRUE;
2392
`SGTI:  Source2Valid = TRUE;
2393
`SGTUI: Source2Valid = TRUE;
2394
`ANDI:  Source2Valid = TRUE;
2395
`ORI:   Source2Valid = TRUE;
2396
`XORI:  Source2Valid = TRUE;
2397
`XNORI: Source2Valid = TRUE;
2398
`MULUI: Source2Valid = TRUE;
2399
`LB:    Source2Valid = TRUE;
2400
`LBU:   Source2Valid = TRUE;
2401
`Lx:    Source2Valid = TRUE;
2402
`LxU:   Source2Valid = TRUE;
2403
`LWR:   Source2Valid = TRUE;
2404
`LVx:   Source2Valid = TRUE;
2405
`INC:           Source2Valid = TRUE;
2406
`SB:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2407
`Sx:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2408
`SWC:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2409
`CAS:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2410
`JAL:   Source2Valid = TRUE;
2411
`RET:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2412
`IVECTOR:
2413
                    case(isn[`INSTRUCTION_S2])
2414
            `VABS:  Source2Valid = TRUE;
2415
            `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2416
                Source2Valid = FALSE;
2417
            `VADDS,`VSUBS,`VANDS,`VORS,`VXORS:
2418
                Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2419
            `VBITS2V:   Source2Valid = TRUE;
2420
            `V2BITS:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2421
            `VSHL,`VSHR,`VASR:  Source2Valid = isn[22:21]==2'd2;
2422
            default:    Source2Valid = FALSE;
2423
            endcase
2424
`LV:        Source2Valid = TRUE;
2425
`SV:        Source2Valid = FALSE;
2426
`AMO:           Source2Valid = isn[31] || isn[`INSTRUCTION_RB]==5'd0;
2427 51 robfinch
`BITFIELD:      Source2Valid = isn[`INSTRUCTION_RB]==5'd0 || isn[31]==1'b0;
2428 48 robfinch
default:    Source2Valid = TRUE;
2429
endcase
2430
endfunction
2431
 
2432
function Source3Valid;
2433
input [47:0] isn;
2434
case(isn[`INSTRUCTION_OP])
2435
`IVECTOR:
2436
    case(isn[`INSTRUCTION_S2])
2437
    `VEX:       Source3Valid = TRUE;
2438
    default:    Source3Valid = TRUE;
2439
    endcase
2440
`CHK:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2441
`R2:
2442
        if (isn[`INSTRUCTION_L2]==2'b01)
2443
                case(isn[47:42])
2444
    `CMOVEZ,`CMOVNZ:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2445
                default:        Source3Valid = TRUE;
2446
                endcase
2447
        else
2448
    case(isn[`INSTRUCTION_S2])
2449
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2450
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2451
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2452
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2453
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2454
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2455
    `MAJ:               Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2456
    default:    Source3Valid = TRUE;
2457
    endcase
2458
`MEMNDX:
2459
        if (isn[`INSTRUCTION_L2]==2'b00)
2460
    case(isn[`INSTRUCTION_S2])
2461
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2462
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2463
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2464
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2465
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2466
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2467
    default:    Source3Valid = TRUE;
2468
    endcase
2469 51 robfinch
`BITFIELD:      Source3Valid = isn[`INSTRUCTION_RC]==5'd0 || isn[32]==1'b0;
2470 48 robfinch
default:    Source3Valid = TRUE;
2471
endcase
2472
endfunction
2473
 
2474
// Used to indicate to the queue logic that the instruction needs to be
2475
// recycled to the queue VL number of times.
2476
function IsVector;
2477
input [47:0] isn;
2478
case(isn[`INSTRUCTION_OP])
2479 51 robfinch
`MEMNDX:
2480
  case(isn[`INSTRUCTION_S2])
2481
  `LVX,`SVX:  IsVector = TRUE;
2482
  default:    IsVector = FALSE;
2483
  endcase
2484 48 robfinch
`IVECTOR:
2485 51 robfinch
        case(isn[`INSTRUCTION_S2])
2486
        `VMxx:
2487
                case(isn[25:23])
2488
        `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2489
              IsVector = FALSE;
2490
    default:    IsVector = TRUE;
2491
    endcase
2492
  `VEINS:     IsVector = FALSE;
2493
  `VEX:       IsVector = FALSE;
2494
  default:    IsVector = TRUE;
2495
  endcase
2496 48 robfinch
`LV,`SV:    IsVector = TRUE;
2497
default:    IsVector = FALSE;
2498
endcase
2499
endfunction
2500
 
2501
function IsVeins;
2502
input [47:0] isn;
2503
case(isn[`INSTRUCTION_OP])
2504
`IVECTOR:   IsVeins = isn[`INSTRUCTION_S2]==`VEINS;
2505
default:    IsVeins = FALSE;
2506
endcase
2507
endfunction
2508
 
2509
function IsVex;
2510
input [47:0] isn;
2511
case(isn[`INSTRUCTION_OP])
2512
`IVECTOR:   IsVex = isn[`INSTRUCTION_S2]==`VEX;
2513
default:    IsVex = FALSE;
2514
endcase
2515
endfunction
2516
 
2517
function IsVCmprss;
2518
input [47:0] isn;
2519
case(isn[`INSTRUCTION_OP])
2520
`IVECTOR:   IsVCmprss = isn[`INSTRUCTION_S2]==`VCMPRSS || isn[`INSTRUCTION_S2]==`VCIDX;
2521
default:    IsVCmprss = FALSE;
2522
endcase
2523
endfunction
2524
 
2525
function IsVShifti;
2526
input [47:0] isn;
2527
case(isn[`INSTRUCTION_OP])
2528
`IVECTOR:
2529
                    case(isn[`INSTRUCTION_S2])
2530
            `VSHL,`VSHR,`VASR:
2531
                IsVShifti = {isn[25],isn[22]}==2'd2;
2532
            default:    IsVShifti = FALSE;
2533
            endcase
2534
default:    IsVShifti = FALSE;
2535
endcase
2536
endfunction
2537
 
2538
function IsVLS;
2539
input [47:0] isn;
2540
case(isn[`INSTRUCTION_OP])
2541
`MEMNDX:
2542
    case(isn[`INSTRUCTION_S2])
2543
    `LVX,`SVX,`LVWS,`SVWS:  IsVLS = TRUE;
2544
    default:    IsVLS = FALSE;
2545
    endcase
2546
`LV,`SV:    IsVLS = TRUE;
2547
default:    IsVLS = FALSE;
2548
endcase
2549
endfunction
2550
 
2551
function [1:0] fnM2;
2552
input [31:0] isn;
2553
case(isn[`INSTRUCTION_OP])
2554
`RR:    fnM2 = isn[24:23];
2555
default:    fnM2 = 2'b00;
2556
endcase
2557
endfunction
2558
 
2559
function [0:0] IsMem;
2560
input [47:0] isn;
2561
case(isn[`INSTRUCTION_OP])
2562
`MEMNDX:        IsMem = TRUE;
2563
`AMO:   IsMem = TRUE;
2564
`LB:    IsMem = TRUE;
2565
`LBU:   IsMem = TRUE;
2566
`Lx:    IsMem = TRUE;
2567
`LxU:   IsMem = TRUE;
2568
`LWR:   IsMem = TRUE;
2569
`LV,`SV:    IsMem = TRUE;
2570
`INC:           IsMem = TRUE;
2571
`SB:    IsMem = TRUE;
2572
`Sx:    IsMem = TRUE;
2573
`SWC:   IsMem = TRUE;
2574
`CAS:   IsMem = TRUE;
2575
`LVx:           IsMem = TRUE;
2576
default:    IsMem = FALSE;
2577
endcase
2578
endfunction
2579
 
2580
function IsMemNdx;
2581
input [47:0] isn;
2582
case(isn[`INSTRUCTION_OP])
2583
`MEMNDX:        IsMemNdx = TRUE;
2584
default:    IsMemNdx = FALSE;
2585
endcase
2586
endfunction
2587
 
2588
function IsLoad;
2589
input [47:0] isn;
2590
case(isn[`INSTRUCTION_OP])
2591
`MEMNDX:
2592
        if (isn[`INSTRUCTION_L2]==2'b00)
2593 50 robfinch
    case(isn[`INSTRUCTION_S2])
2594
    `LBX:   IsLoad = TRUE;
2595
    `LBUX:  IsLoad = TRUE;
2596
    `LCX:   IsLoad = TRUE;
2597
    `LCUX:  IsLoad = TRUE;
2598
    `LHX:   IsLoad = TRUE;
2599
    `LHUX:  IsLoad = TRUE;
2600
    `LWX:   IsLoad = TRUE;
2601
    `LVBX:      IsLoad = TRUE;
2602
    `LVBUX: IsLoad = TRUE;
2603
    `LVCX:  IsLoad = TRUE;
2604
    `LVCUX: IsLoad = TRUE;
2605
    `LVHX:  IsLoad = TRUE;
2606
    `LVHUX: IsLoad = TRUE;
2607
    `LVWX:  IsLoad = TRUE;
2608
    `LWRX:  IsLoad = TRUE;
2609
    `LVX:   IsLoad = TRUE;
2610
    default: IsLoad = FALSE;
2611
    endcase
2612 48 robfinch
        else
2613
                IsLoad = FALSE;
2614
`LB:    IsLoad = TRUE;
2615
`LBU:   IsLoad = TRUE;
2616
`Lx:    IsLoad = TRUE;
2617
`LxU:   IsLoad = TRUE;
2618
`LWR:   IsLoad = TRUE;
2619
`LV:    IsLoad = TRUE;
2620
`LVx:   IsLoad = TRUE;
2621
default:    IsLoad = FALSE;
2622
endcase
2623
endfunction
2624
 
2625
function IsInc;
2626
input [47:0] isn;
2627
case(isn[`INSTRUCTION_OP])
2628
`MEMNDX:
2629
        if (isn[`INSTRUCTION_L2]==2'b00)
2630
                case(isn[`INSTRUCTION_S2])
2631
            `INC:   IsInc = TRUE;
2632
            default:    IsInc = FALSE;
2633
            endcase
2634
        else
2635
                IsInc = FALSE;
2636
`INC:    IsInc = TRUE;
2637
default:    IsInc = FALSE;
2638
endcase
2639
endfunction
2640
 
2641
function IsSWC;
2642
input [47:0] isn;
2643
case(isn[`INSTRUCTION_OP])
2644
`MEMNDX:
2645
        if (isn[`INSTRUCTION_L2]==2'b00)
2646
                case(isn[`INSTRUCTION_S2])
2647
            `SWCX:   IsSWC = TRUE;
2648
            default:    IsSWC = FALSE;
2649
            endcase
2650
        else
2651
                IsSWC = FALSE;
2652
`SWC:    IsSWC = TRUE;
2653
default:    IsSWC = FALSE;
2654
endcase
2655
endfunction
2656
 
2657
// Aquire / release bits are only available on indexed SWC / LWR
2658
function IsSWCX;
2659
input [47:0] isn;
2660
case(isn[`INSTRUCTION_OP])
2661
`MEMNDX:
2662
        if (isn[`INSTRUCTION_L2]==2'b00)
2663
            case(isn[`INSTRUCTION_S2])
2664
            `SWCX:   IsSWCX = TRUE;
2665
            default:    IsSWCX = FALSE;
2666
            endcase
2667
        else
2668
                IsSWCX = FALSE;
2669
default:    IsSWCX = FALSE;
2670
endcase
2671
endfunction
2672
 
2673
function IsLWR;
2674
input [47:0] isn;
2675
case(isn[`INSTRUCTION_OP])
2676
`MEMNDX:
2677
        if (isn[`INSTRUCTION_L2]==2'b00)
2678
            case(isn[`INSTRUCTION_S2])
2679
            `LWRX:   IsLWR = TRUE;
2680
            default:    IsLWR = FALSE;
2681
            endcase
2682
        else
2683
                IsLWR = FALSE;
2684
`LWR:    IsLWR = TRUE;
2685
default:    IsLWR = FALSE;
2686
endcase
2687
endfunction
2688
 
2689
function IsLWRX;
2690
input [47:0] isn;
2691
case(isn[`INSTRUCTION_OP])
2692
`MEMNDX:
2693
        if (isn[`INSTRUCTION_L2]==2'b00)
2694
            case(isn[`INSTRUCTION_S2])
2695
            `LWRX:   IsLWRX = TRUE;
2696
            default:    IsLWRX = FALSE;
2697
            endcase
2698
        else
2699
                IsLWRX = FALSE;
2700
default:    IsLWRX = FALSE;
2701
endcase
2702
endfunction
2703
 
2704
function IsCAS;
2705
input [47:0] isn;
2706
case(isn[`INSTRUCTION_OP])
2707
`MEMNDX:
2708
        if (isn[`INSTRUCTION_L2]==2'b00)
2709
            case(isn[`INSTRUCTION_S2])
2710
            `CASX:   IsCAS = TRUE;
2711
            default:    IsCAS = FALSE;
2712
            endcase
2713
        else
2714
                IsCAS = FALSE;
2715
`CAS:       IsCAS = TRUE;
2716
default:    IsCAS = FALSE;
2717
endcase
2718
endfunction
2719
 
2720
function IsAMO;
2721
input [47:0] isn;
2722
case(isn[`INSTRUCTION_OP])
2723
`AMO:       IsAMO = TRUE;
2724
default:    IsAMO = FALSE;
2725
endcase
2726
endfunction
2727
 
2728
// Really IsPredictableBranch
2729
// Does not include BccR's
2730
function IsBranch;
2731
input [47:0] isn;
2732
casez(isn[`INSTRUCTION_OP])
2733
`Bcc:   IsBranch = TRUE;
2734
`BBc:   IsBranch = TRUE;
2735
`BEQI:  IsBranch = TRUE;
2736
`CHK:   IsBranch = TRUE;
2737
default:    IsBranch = FALSE;
2738
endcase
2739
endfunction
2740
 
2741
function IsWait;
2742
input [47:0] isn;
2743
IsWait = isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`WAIT;
2744
endfunction
2745
 
2746
function IsCall;
2747
input [47:0] isn;
2748
IsCall = isn[`INSTRUCTION_OP]==`CALL && isn[7]==1'b0;
2749
endfunction
2750
 
2751
function IsJmp;
2752
input [47:0] isn;
2753
IsJmp = isn[`INSTRUCTION_OP]==`JMP && isn[7]==1'b0;
2754
endfunction
2755
 
2756
function IsFlowCtrl;
2757
input [47:0] isn;
2758
casez(isn[`INSTRUCTION_OP])
2759
`BRK:    IsFlowCtrl = TRUE;
2760 49 robfinch
`R2:    case(isn[`INSTRUCTION_S2])
2761 48 robfinch
        `RTI:   IsFlowCtrl = TRUE;
2762
        default:    IsFlowCtrl = FALSE;
2763
        endcase
2764
`Bcc:   IsFlowCtrl = TRUE;
2765
`BBc:           IsFlowCtrl = TRUE;
2766
`BEQI:  IsFlowCtrl = TRUE;
2767
`CHK:   IsFlowCtrl = TRUE;
2768
`JAL:   IsFlowCtrl = TRUE;
2769
`JMP:           IsFlowCtrl = TRUE;
2770
`CALL:  IsFlowCtrl = TRUE;
2771
`RET:   IsFlowCtrl = TRUE;
2772
default:    IsFlowCtrl = FALSE;
2773
endcase
2774
endfunction
2775
 
2776
function IsCache;
2777
input [47:0] isn;
2778
case(isn[`INSTRUCTION_OP])
2779
`MEMNDX:
2780
        if (isn[`INSTRUCTION_L2]==2'b00)
2781
            case(isn[`INSTRUCTION_S2])
2782
            `CACHEX:    IsCache = TRUE;
2783
            default:    IsCache = FALSE;
2784
            endcase
2785
        else
2786
                IsCache = FALSE;
2787
`CACHE: IsCache = TRUE;
2788
default: IsCache = FALSE;
2789
endcase
2790
endfunction
2791
 
2792
function [4:0] CacheCmd;
2793
input [47:0] isn;
2794
case(isn[`INSTRUCTION_OP])
2795
`MEMNDX:
2796
        if (isn[`INSTRUCTION_L2]==2'b00)
2797
            case(isn[`INSTRUCTION_S2])
2798
            `CACHEX:    CacheCmd = isn[22:18];
2799
            default:    CacheCmd = 5'd0;
2800
            endcase
2801
        else
2802
                CacheCmd = 5'd0;
2803
`CACHE: CacheCmd = isn[15:11];
2804
default: CacheCmd = 5'd0;
2805
endcase
2806
endfunction
2807
 
2808
function IsMemsb;
2809
input [47:0] isn;
2810
IsMemsb = (isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMSB);
2811
endfunction
2812
 
2813
function IsSEI;
2814
input [47:0] isn;
2815
IsSEI = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`SEI);
2816
endfunction
2817
 
2818
function IsLV;
2819
input [47:0] isn;
2820
case(isn[`INSTRUCTION_OP])
2821
`MEMNDX:
2822
        if (isn[`INSTRUCTION_L2]==2'b00)
2823
            case(isn[`INSTRUCTION_S2])
2824
            `LVX:   IsLV = TRUE;
2825
            default:    IsLV = FALSE;
2826
            endcase
2827
        else
2828
                IsLV = FALSE;
2829
`LV:        IsLV = TRUE;
2830
default:    IsLV = FALSE;
2831
endcase
2832
endfunction
2833
 
2834
function IsRFW;
2835
input [47:0] isn;
2836
input [5:0] vqei;
2837
input [5:0] vli;
2838
input thrd;
2839
if (fnRt(isn,vqei,vli,thrd)==12'd0)
2840
    IsRFW = FALSE;
2841
else
2842
casez(isn[`INSTRUCTION_OP])
2843
`IVECTOR:   IsRFW = TRUE;
2844
`FVECTOR:   IsRFW = TRUE;
2845
`R2:
2846
        if (isn[`INSTRUCTION_L2]==2'b00)
2847
            case(isn[`INSTRUCTION_S2])
2848
            `R1:    IsRFW = TRUE;
2849
            `ADD:   IsRFW = TRUE;
2850
            `SUB:   IsRFW = TRUE;
2851
            `SLT:   IsRFW = TRUE;
2852
            `SLTU:  IsRFW = TRUE;
2853
            `SLE:   IsRFW = TRUE;
2854
        `SLEU:  IsRFW = TRUE;
2855
            `AND:   IsRFW = TRUE;
2856
            `OR:    IsRFW = TRUE;
2857
            `XOR:   IsRFW = TRUE;
2858
            `MULU:  IsRFW = TRUE;
2859
            `MULSU: IsRFW = TRUE;
2860
            `MUL:   IsRFW = TRUE;
2861 50 robfinch
            `MULUH:  IsRFW = TRUE;
2862
            `MULSUH: IsRFW = TRUE;
2863
            `MULH:   IsRFW = TRUE;
2864
            `DIVU:  IsRFW = TRUE;
2865
            `DIVSU: IsRFW = TRUE;
2866
            `DIV:IsRFW = TRUE;
2867
            `MODU:  IsRFW = TRUE;
2868
            `MODSU: IsRFW = TRUE;
2869
            `MOD:IsRFW = TRUE;
2870 48 robfinch
            `MOV:       IsRFW = TRUE;
2871
            `VMOV:      IsRFW = TRUE;
2872
            `SHIFTR,`SHIFT31,`SHIFT63:
2873
                        IsRFW = TRUE;
2874
            `MIN,`MAX:    IsRFW = TRUE;
2875
            `SEI:       IsRFW = TRUE;
2876
            default:    IsRFW = FALSE;
2877
            endcase
2878
        else
2879
                IsRFW = FALSE;
2880
`MEMNDX:
2881
        if (isn[`INSTRUCTION_L2]==2'b00)
2882 50 robfinch
    case(isn[`INSTRUCTION_S2])
2883
    `LBX:   IsRFW = TRUE;
2884
    `LBUX:  IsRFW = TRUE;
2885
    `LCX:   IsRFW = TRUE;
2886
    `LCUX:  IsRFW = TRUE;
2887
    `LHX:   IsRFW = TRUE;
2888
    `LHUX:  IsRFW = TRUE;
2889
    `LWX:   IsRFW = TRUE;
2890
    `LVBX:  IsRFW = TRUE;
2891
    `LVBUX: IsRFW = TRUE;
2892
    `LVCX:  IsRFW = TRUE;
2893
    `LVCUX: IsRFW = TRUE;
2894
    `LVHX:  IsRFW = TRUE;
2895
    `LVHUX: IsRFW = TRUE;
2896
    `LVWX:  IsRFW = TRUE;
2897
    `LWRX:  IsRFW = TRUE;
2898
    `LVX:   IsRFW = TRUE;
2899
    `CASX:  IsRFW = TRUE;
2900
    default:    IsRFW = FALSE;
2901
    endcase
2902 48 robfinch
        else
2903
                IsRFW = FALSE;
2904
`BBc:
2905
        case(isn[20:19])
2906
        `IBNE:  IsRFW = TRUE;
2907
        `DBNZ:  IsRFW = TRUE;
2908
        default:        IsRFW = FALSE;
2909
        endcase
2910
`BITFIELD:  IsRFW = TRUE;
2911
`ADDI:      IsRFW = TRUE;
2912
`SLTI:      IsRFW = TRUE;
2913
`SLTUI:     IsRFW = TRUE;
2914
`SGTI:      IsRFW = TRUE;
2915
`SGTUI:     IsRFW = TRUE;
2916
`ANDI:      IsRFW = TRUE;
2917
`ORI:       IsRFW = TRUE;
2918
`XORI:      IsRFW = TRUE;
2919
`MULUI:     IsRFW = TRUE;
2920
`MULI:      IsRFW = TRUE;
2921
`DIVUI:     IsRFW = TRUE;
2922
`DIVI:      IsRFW = TRUE;
2923
`MODI:      IsRFW = TRUE;
2924
`JAL:       IsRFW = TRUE;
2925
`CALL:      IsRFW = TRUE;
2926
`RET:       IsRFW = TRUE;
2927
`LB:        IsRFW = TRUE;
2928
`LBU:       IsRFW = TRUE;
2929
`Lx:        IsRFW = TRUE;
2930
`LWR:       IsRFW = TRUE;
2931
`LV:        IsRFW = TRUE;
2932
`LVx:                           IsRFW = TRUE;
2933
`CAS:       IsRFW = TRUE;
2934
`AMO:                           IsRFW = TRUE;
2935
`CSRRW:                 IsRFW = TRUE;
2936 56 robfinch
`AUIPC:                 IsRFW = TRUE;
2937 55 robfinch
`LUI:                           IsRFW = TRUE;
2938 48 robfinch
default:    IsRFW = FALSE;
2939
endcase
2940
endfunction
2941
 
2942
function IsShifti;
2943
input [47:0] isn;
2944
case(isn[`INSTRUCTION_OP])
2945
`R2:
2946
        if (isn[`INSTRUCTION_L2]==2'b00)
2947
            case(isn[`INSTRUCTION_S2])
2948
            `SHIFT31,`SHIFT63:
2949
                IsShifti = TRUE;
2950
            default: IsShifti = FALSE;
2951
            endcase
2952
    else
2953
        IsShifti = FALSE;
2954
default: IsShifti = FALSE;
2955
endcase
2956
endfunction
2957
 
2958
function IsRtop;
2959
input [47:0] isn;
2960
case(isn[`INSTRUCTION_OP])
2961
`R2:
2962
        if (isn[`INSTRUCTION_L2]==2'b01)
2963
            case(isn[47:42])
2964
            `RTOP: IsRtop = TRUE;
2965
            default: IsRtop = FALSE;
2966
            endcase
2967
    else
2968
        IsRtop = FALSE;
2969
default: IsRtop = FALSE;
2970
endcase
2971
endfunction
2972
 
2973
function IsMul;
2974
input [47:0] isn;
2975
case(isn[`INSTRUCTION_OP])
2976 50 robfinch
`R2:
2977 48 robfinch
        if (isn[`INSTRUCTION_L2]==2'b00)
2978 50 robfinch
    case(isn[`INSTRUCTION_S2])
2979
    `MULU,`MULSU,`MUL: IsMul = TRUE;
2980
    `MULUH,`MULSUH,`MULH: IsMul = TRUE;
2981
    default:    IsMul = FALSE;
2982
    endcase
2983 48 robfinch
        else
2984
                IsMul = FALSE;
2985
`MULUI,`MULI:  IsMul = TRUE;
2986
default:    IsMul = FALSE;
2987
endcase
2988
endfunction
2989
 
2990
function IsDivmod;
2991
input [47:0] isn;
2992
case(isn[`INSTRUCTION_OP])
2993 50 robfinch
`R2:
2994 48 robfinch
        if (isn[`INSTRUCTION_L2]==2'b00)
2995 50 robfinch
    case(isn[`INSTRUCTION_S2])
2996
    `DIVU,`DIVSU,`DIV: IsDivmod = TRUE;
2997
    `MODU,`MODSU,`MOD: IsDivmod = TRUE;
2998
    default: IsDivmod = FALSE;
2999
    endcase
3000 48 robfinch
        else
3001
                IsDivmod = FALSE;
3002
`DIVUI,`DIVI,`MODI:  IsDivmod = TRUE;
3003
default:    IsDivmod = FALSE;
3004
endcase
3005
endfunction
3006
 
3007
function IsExec;
3008
input [47:0] isn;
3009
case(isn[`INSTRUCTION_OP])
3010
`EXEC:  IsExec = TRUE;
3011
default:        IsExec = FALSE;
3012
endcase
3013
endfunction
3014
 
3015
function [7:0] fnSelect;
3016
input [47:0] ins;
3017 49 robfinch
input [`ABITS] adr;
3018 48 robfinch
begin
3019
        case(ins[`INSTRUCTION_OP])
3020
        `MEMNDX:
3021
                if (ins[`INSTRUCTION_L2]==2'b00)
3022
                   case(ins[`INSTRUCTION_S2])
3023 53 robfinch
               `LBX,`LBUX,`SBX,`LVBX,`LVBUX:
3024 48 robfinch
                   case(adr[2:0])
3025
                   3'd0:    fnSelect = 8'h01;
3026
                   3'd1:    fnSelect = 8'h02;
3027
                   3'd2:    fnSelect = 8'h04;
3028
                   3'd3:    fnSelect = 8'h08;
3029
                   3'd4:    fnSelect = 8'h10;
3030
                   3'd5:    fnSelect = 8'h20;
3031
                   3'd6:    fnSelect = 8'h40;
3032
                   3'd7:    fnSelect = 8'h80;
3033
                   endcase
3034 53 robfinch
                `LCX,`LCUX,`SCX,`LVCX,`LVCUX:
3035 48 robfinch
                    case(adr[2:1])
3036
                    2'd0:   fnSelect = 8'h03;
3037
                    2'd1:   fnSelect = 8'h0C;
3038
                    2'd2:   fnSelect = 8'h30;
3039
                    2'd3:   fnSelect = 8'hC0;
3040
                    endcase
3041 53 robfinch
                `LHX,`LHUX,`SHX,`LVHX,`LVHUX:
3042 48 robfinch
                   case(adr[2])
3043
                   1'b0:    fnSelect = 8'h0F;
3044
                   1'b1:    fnSelect = 8'hF0;
3045
                   endcase
3046 53 robfinch
               `INC,`LVWX,
3047 48 robfinch
               `LWX,`SWX,`LWRX,`SWCX,`LVX,`SVX,`CASX:
3048
                   fnSelect = 8'hFF;
3049
               default: fnSelect = 8'h00;
3050
                   endcase
3051
           else
3052
                fnSelect = 8'h00;
3053 52 robfinch
  `LB,`LBU,`SB:
3054 48 robfinch
                case(adr[2:0])
3055
                3'd0:   fnSelect = 8'h01;
3056
                3'd1:   fnSelect = 8'h02;
3057
                3'd2:   fnSelect = 8'h04;
3058
                3'd3:   fnSelect = 8'h08;
3059
                3'd4:   fnSelect = 8'h10;
3060
                3'd5:   fnSelect = 8'h20;
3061
                3'd6:   fnSelect = 8'h40;
3062
                3'd7:   fnSelect = 8'h80;
3063
                endcase
3064 53 robfinch
    `Lx,`LxU,`Sx,`LVx:
3065 48 robfinch
        casez(ins[20:18])
3066
        3'b100: fnSelect = 8'hFF;
3067
        3'b?10: fnSelect = adr[2] ? 8'hF0 : 8'h0F;
3068
        3'b??1:
3069
        case(adr[2:1])
3070
        2'd0:   fnSelect = 8'h03;
3071
        2'd1:   fnSelect = 8'h0C;
3072
        2'd2:   fnSelect = 8'h30;
3073
        2'd3:   fnSelect = 8'hC0;
3074
        endcase
3075
      default: fnSelect = 8'h00;
3076
      endcase
3077
        `INC,
3078
        `LWR,`SWC,`CAS:   fnSelect = 8'hFF;
3079
        `LV,`SV:   fnSelect = 8'hFF;
3080
        `AMO:
3081
                case(ins[23:21])
3082
                3'd0:   fnSelect = {8'h01 << adr[2:0]};
3083
                3'd1:   fnSelect = {8'h03 << {adr[2:1],1'b0}};
3084
                3'd2:   fnSelect = {8'h0F << {adr[2],2'b00}};
3085
                3'd3:   fnSelect = 8'hFF;
3086
                default:        fnSelect = 8'hFF;
3087
                endcase
3088
        default:        fnSelect = 8'h00;
3089
        endcase
3090
end
3091
endfunction
3092
/*
3093
function [63:0] fnDatc;
3094
input [47:0] ins;
3095
input [63:0] dat;
3096
case(ins[`INSTRUCTION_OP])
3097
`R2:
3098
        if (isn[`INSTRUCTION_L2]==2'b01)
3099
                case(ins[47:42])
3100
                `FINDB:         fnDatc = dat[7:0];
3101
                `FINDC:         fnDatc = dat[15:0];
3102
                `FINDH:         fnDatc = dat[31:0];
3103
                `FINDW:         fnDatc = dat[63:0];
3104
                default:        fnDatc = dat[63:0];
3105
                endcase
3106
        else
3107
                fnDatc = dat[63:0];
3108
default:        fnDatc = dat[63:0];
3109
endcase
3110
endfunction
3111
*/
3112
/*
3113
function [63:0] fnMemInc;
3114
input [47:0] ins;
3115
case(ins[`INSTRUCTION_OP])
3116
`R2:
3117
        if (isn[`INSTRUCTION_L2]==2'b01)
3118
                case(ins[47:42])
3119
                `FINDB:         fnMemInc = 32'd1;
3120
                `FINDC:         fnMemInc = 32'd2;
3121
                `FINDH:         fnMemInc = 32'd4;
3122
                `FINDW:         fnMemInc = 32'd8;
3123
                default:        fnMemInc = 32'd8;
3124
                endcase
3125
        else
3126
                fnMemInc = 32'd8;
3127
default:        fnMemInc = 32'd8;
3128
endcase
3129
endfunction
3130
*/
3131
function [63:0] fnDati;
3132
input [47:0] ins;
3133 49 robfinch
input [`ABITS] adr;
3134 48 robfinch
input [63:0] dat;
3135
case(ins[`INSTRUCTION_OP])
3136
`MEMNDX:
3137
        if (ins[`INSTRUCTION_L2]==2'b00)
3138
            case(ins[`INSTRUCTION_S2])
3139 53 robfinch
            `LBX,`LVBX:
3140 48 robfinch
                case(adr[2:0])
3141
                3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3142
                3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3143
                3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3144
                3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3145
                3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3146
                3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3147
                3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3148
                3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3149
                endcase
3150 53 robfinch
            `LBUX,`LVBUX:
3151 48 robfinch
                case(adr[2:0])
3152
                3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3153
                3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3154
                3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3155
                3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3156
                3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3157
                3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3158
                3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3159
                3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3160
                endcase
3161 53 robfinch
            `LCX,`LVCX:
3162 48 robfinch
                case(adr[2:1])
3163
                2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3164
                2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3165
                2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3166
                2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3167
                endcase
3168 53 robfinch
            `LCUX,`LVCUX:
3169 48 robfinch
                case(adr[2:1])
3170
                2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3171
                2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3172
                2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3173
                2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3174
                endcase
3175 53 robfinch
            `LHX,`LVHX:
3176 48 robfinch
                case(adr[2])
3177
                1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3178
                1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3179
                endcase
3180 53 robfinch
            `LHUX,`LVHUX:
3181 48 robfinch
                case(adr[2])
3182
                1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3183
                1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3184
                endcase
3185 53 robfinch
            `LWX,`LWRX,`LVX,`CAS,`LVWX:  fnDati = dat;
3186 48 robfinch
            default:    fnDati = dat;
3187
            endcase
3188
        else
3189
                fnDati = dat;
3190
`LB:
3191
  case(adr[2:0])
3192
  3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3193
  3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3194
  3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3195
  3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3196
  3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3197
  3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3198
  3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3199
  3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3200
  endcase
3201
`LBU:
3202
  case(adr[2:0])
3203
  3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3204
  3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3205
  3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3206
  3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3207
  3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3208
  3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3209
  3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3210
  3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3211
  endcase
3212 53 robfinch
`Lx,`LVx:
3213 48 robfinch
        casez(ins[20:18])
3214
        3'b100: fnDati = dat;
3215
        3'b?10:
3216
          case(adr[2])
3217
          1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3218
          1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3219
          endcase
3220
        3'b??1:
3221
          case(adr[2:1])
3222
          2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3223
          2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3224
          2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3225
          2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3226
          endcase
3227
        endcase
3228
`LxU:
3229
        casez(ins[20:18])
3230
        3'b100: fnDati = dat;
3231
        3'b?10:
3232
          case(adr[2])
3233
          1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3234
          1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3235
          endcase
3236
        3'b??1:
3237
          case(adr[2:1])
3238
          2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3239
          2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3240
          2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3241
          2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3242
          endcase
3243
        endcase
3244
`LWR,`LV,`CAS,`AMO:   fnDati = dat;
3245
default:    fnDati = dat;
3246
endcase
3247
endfunction
3248
 
3249
function [63:0] fnDato;
3250
input [47:0] isn;
3251
input [63:0] dat;
3252
case(isn[`INSTRUCTION_OP])
3253
`MEMNDX:
3254
        if (isn[`INSTRUCTION_L2]==2'b00)
3255
                case(isn[`INSTRUCTION_S2])
3256
                `SBX:   fnDato = {8{dat[7:0]}};
3257
                `SCX:   fnDato = {4{dat[15:0]}};
3258
                `SHX:   fnDato = {2{dat[31:0]}};
3259
                default:    fnDato = dat;
3260
                endcase
3261
        else
3262
                fnDato = dat;
3263
`SB:   fnDato = {8{dat[7:0]}};
3264
`Sx:
3265 49 robfinch
        casez(isn[20:18])
3266 48 robfinch
        3'b100: fnDato = dat;
3267
        3'b?10: fnDato = {2{dat[31:0]}};
3268
        3'b??1: fnDato = {4{dat[15:0]}};
3269
        default:        fnDato = dat;
3270
        endcase
3271
`AMO:
3272
        case(isn[23:21])
3273
        3'd0:   fnDato = {8{dat[7:0]}};
3274
        3'd1:   fnDato = {4{dat[15:0]}};
3275
        3'd2:   fnDato = {2{dat[31:0]}};
3276
        3'd3:   fnDato = dat;
3277
        default:        fnDato = dat;
3278
        endcase
3279
default:    fnDato = dat;
3280
endcase
3281
endfunction
3282
 
3283
// Indicate if the ALU instruction is valid immediately (single cycle operation)
3284
function IsSingleCycle;
3285
input [47:0] isn;
3286
IsSingleCycle = !(IsMul(isn)|IsDivmod(isn));
3287
endfunction
3288
 
3289
 
3290 53 robfinch
generate begin : gDecocderInst
3291
for (g = 0; g < QENTRIES; g = g + 1) begin
3292 48 robfinch
`ifdef SUPPORT_SMT
3293 53 robfinch
decoder8 iq0(.num({iqentry_tgt[g][8:7],iqentry_tgt[g][5:0]}), .out(iq_out[g]));
3294 48 robfinch
`else
3295 53 robfinch
decoder7 iq0(.num({iqentry_tgt[g][7],iqentry_tgt[g][5:0]}), .out(iq_out[g]));
3296 48 robfinch
`endif
3297 53 robfinch
end
3298
end
3299
endgenerate
3300 48 robfinch
 
3301
initial begin: Init
3302
        //
3303
        //
3304
        // set up panic messages
3305
        message[ `PANIC_NONE ]                  = "NONE            ";
3306
        message[ `PANIC_FETCHBUFBEQ ]           = "FETCHBUFBEQ     ";
3307
        message[ `PANIC_INVALIDISLOT ]          = "INVALIDISLOT    ";
3308
        message[ `PANIC_IDENTICALDRAMS ]        = "IDENTICALDRAMS  ";
3309
        message[ `PANIC_OVERRUN ]               = "OVERRUN         ";
3310
        message[ `PANIC_HALTINSTRUCTION ]       = "HALTINSTRUCTION ";
3311
        message[ `PANIC_INVALIDMEMOP ]          = "INVALIDMEMOP    ";
3312
        message[ `PANIC_INVALIDFBSTATE ]        = "INVALIDFBSTATE  ";
3313
        message[ `PANIC_INVALIDIQSTATE ]        = "INVALIDIQSTATE  ";
3314
        message[ `PANIC_BRANCHBACK ]            = "BRANCHBACK      ";
3315
        message[ `PANIC_MEMORYRACE ]            = "MEMORYRACE      ";
3316
        message[ `PANIC_ALU0ONLY ] = "ALU0 Only       ";
3317
 
3318
        for (n = 0; n < 64; n = n + 1)
3319
                codebuf[n] <= 48'h0;
3320
 
3321
end
3322
 
3323
// ---------------------------------------------------------------------------
3324
// FETCH
3325
// ---------------------------------------------------------------------------
3326
//
3327
assign fetchbuf0_mem   = IsMem(fetchbuf0_instr);
3328
assign fetchbuf0_memld = IsMem(fetchbuf0_instr) & IsLoad(fetchbuf0_instr);
3329
assign fetchbuf0_rfw   = IsRFW(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd);
3330
 
3331 57 robfinch
generate begin: gFetchbufDec
3332
if (`WAYS > 1) begin
3333 48 robfinch
assign fetchbuf1_mem   = IsMem(fetchbuf1_instr);
3334
assign fetchbuf1_memld = IsMem(fetchbuf1_instr) & IsLoad(fetchbuf1_instr);
3335
assign fetchbuf1_rfw   = IsRFW(fetchbuf1_instr,vqe1,vl,fetchbuf1_thrd);
3336 57 robfinch
end
3337
if (`WAYS > 2) begin
3338
assign fetchbuf2_mem   = IsMem(fetchbuf2_instr);
3339
assign fetchbuf2_memld = IsMem(fetchbuf2_instr) & IsLoad(fetchbuf2_instr);
3340
assign fetchbuf2_rfw   = IsRFW(fetchbuf2_instr,vqe2,vl,fetchbuf2_thrd);
3341
end
3342
end
3343
endgenerate
3344 48 robfinch
 
3345 57 robfinch
generate begin : gFetchbufInst
3346
if (`WAYS > 2) begin : gb1
3347
FT64_fetchbuf_x3 #(AMSB,RSTPC) ufb1
3348
(
3349
  .rst(rst),
3350
  .clk4x(clk4x),
3351
  .clk(clk),
3352
  .fcu_clk(fcu_clk),
3353
  .cs_i(adr_o[31:16]==16'hFFFF),
3354
  .cyc_i(cyc_o),
3355
  .stb_i(stb_o),
3356
  .ack_o(dc_ack),
3357
  .we_i(we_o),
3358
  .adr_i(adr_o[15:0]),
3359
  .dat_i(dat_o[47:0]),
3360
  .cmpgrp(cr0[10:8]),
3361
  .freezePC(freezePC),
3362
  .regLR(regLR),
3363
  .thread_en(thread_en),
3364
  .insn0(insn0),
3365
  .insn1(insn1),
3366
  .insn1(insn2),
3367
  .phit(phit),
3368
  .threadx(threadx),
3369
  .branchmiss(branchmiss),
3370
  .misspc(misspc),
3371
  .branchmiss_thrd(branchmiss_thrd),
3372
  .predict_takenA(predict_takenA),
3373
  .predict_takenB(predict_takenB),
3374
  .predict_takenC(predict_takenC),
3375
  .predict_takenD(predict_takenD),
3376
  .predict_takenE(predict_takenE),
3377
  .predict_takenF(predict_takenF),
3378
  .predict_taken0(predict_taken0),
3379
  .predict_taken1(predict_taken1),
3380
  .predict_taken1(predict_taken2),
3381
  .queued1(queued1),
3382
  .queued2(queued2),
3383
  .queued2(queued3),
3384
  .queuedNop(queuedNop),
3385
  .pc0(pc0),
3386
  .pc1(pc1),
3387
  .fetchbuf(fetchbuf),
3388
  .fetchbufA_v(fetchbufA_v),
3389
  .fetchbufB_v(fetchbufB_v),
3390
  .fetchbufC_v(fetchbufC_v),
3391
  .fetchbufD_v(fetchbufD_v),
3392
  .fetchbufD_v(fetchbufE_v),
3393
  .fetchbufD_v(fetchbufF_v),
3394
  .fetchbufA_pc(fetchbufA_pc),
3395
  .fetchbufB_pc(fetchbufB_pc),
3396
  .fetchbufC_pc(fetchbufC_pc),
3397
  .fetchbufD_pc(fetchbufD_pc),
3398
  .fetchbufD_pc(fetchbufE_pc),
3399
  .fetchbufD_pc(fetchbufF_pc),
3400
  .fetchbufA_instr(fetchbufA_instr),
3401
  .fetchbufB_instr(fetchbufB_instr),
3402
  .fetchbufC_instr(fetchbufC_instr),
3403
  .fetchbufD_instr(fetchbufD_instr),
3404
  .fetchbufE_instr(fetchbufE_instr),
3405
  .fetchbufF_instr(fetchbufF_instr),
3406
  .fetchbuf0_instr(fetchbuf0_instr),
3407
  .fetchbuf1_instr(fetchbuf1_instr),
3408
  .fetchbuf0_thrd(fetchbuf0_thrd),
3409
  .fetchbuf1_thrd(fetchbuf1_thrd),
3410
  .fetchbuf2_thrd(fetchbuf2_thrd),
3411
  .fetchbuf0_pc(fetchbuf0_pc),
3412
  .fetchbuf1_pc(fetchbuf1_pc),
3413
  .fetchbuf2_pc(fetchbuf2_pc),
3414
  .fetchbuf0_v(fetchbuf0_v),
3415
  .fetchbuf1_v(fetchbuf1_v),
3416
  .fetchbuf2_v(fetchbuf2_v),
3417
  .fetchbuf0_insln(fetchbuf0_insln),
3418
  .fetchbuf1_insln(fetchbuf1_insln),
3419
  .fetchbuf2_insln(fetchbuf2_insln),
3420
  .codebuf0(codebuf[insn0[21:16]]),
3421
  .codebuf1(codebuf[insn1[21:16]]),
3422
  .codebuf2(codebuf[insn2[21:16]]),
3423
  .btgtA(btgtA),
3424
  .btgtB(btgtB),
3425
  .btgtC(btgtC),
3426
  .btgtD(btgtD),
3427
  .btgtE(btgtE),
3428
  .btgtF(btgtF),
3429
  .nop_fetchbuf(nop_fetchbuf),
3430
  .take_branch0(take_branch0),
3431
  .take_branch1(take_branch1),
3432
  .take_branch2(take_branch2),
3433
  .stompedRets(stompedOnRets),
3434
  .panic(fb_panic)
3435
);
3436
end
3437
else if (`WAYS > 1) begin : gb1
3438 48 robfinch
FT64_fetchbuf #(AMSB,RSTPC) ufb1
3439
(
3440 49 robfinch
  .rst(rst),
3441
  .clk4x(clk4x),
3442
  .clk(clk),
3443
  .fcu_clk(fcu_clk),
3444
  .cs_i(adr_o[31:16]==16'hFFFF),
3445
  .cyc_i(cyc_o),
3446
  .stb_i(stb_o),
3447
  .ack_o(dc_ack),
3448
  .we_i(we_o),
3449
  .adr_i(adr_o[15:0]),
3450 56 robfinch
  .dat_i(dat_o[47:0]),
3451 55 robfinch
  .cmpgrp(cr0[10:8]),
3452 52 robfinch
  .freezePC(freezePC),
3453 49 robfinch
  .regLR(regLR),
3454
  .thread_en(thread_en),
3455
  .insn0(insn0),
3456
  .insn1(insn1),
3457
  .phit(phit),
3458
  .threadx(threadx),
3459
  .branchmiss(branchmiss),
3460
  .misspc(misspc),
3461
  .branchmiss_thrd(branchmiss_thrd),
3462
  .predict_takenA(predict_takenA),
3463
  .predict_takenB(predict_takenB),
3464
  .predict_takenC(predict_takenC),
3465
  .predict_takenD(predict_takenD),
3466
  .predict_taken0(predict_taken0),
3467
  .predict_taken1(predict_taken1),
3468
  .queued1(queued1),
3469
  .queued2(queued2),
3470
  .queuedNop(queuedNop),
3471
  .pc0(pc0),
3472
  .pc1(pc1),
3473
  .fetchbuf(fetchbuf),
3474
  .fetchbufA_v(fetchbufA_v),
3475
  .fetchbufB_v(fetchbufB_v),
3476
  .fetchbufC_v(fetchbufC_v),
3477
  .fetchbufD_v(fetchbufD_v),
3478
  .fetchbufA_pc(fetchbufA_pc),
3479
  .fetchbufB_pc(fetchbufB_pc),
3480
  .fetchbufC_pc(fetchbufC_pc),
3481
  .fetchbufD_pc(fetchbufD_pc),
3482
  .fetchbufA_instr(fetchbufA_instr),
3483
  .fetchbufB_instr(fetchbufB_instr),
3484
  .fetchbufC_instr(fetchbufC_instr),
3485
  .fetchbufD_instr(fetchbufD_instr),
3486
  .fetchbuf0_instr(fetchbuf0_instr),
3487
  .fetchbuf1_instr(fetchbuf1_instr),
3488
  .fetchbuf0_thrd(fetchbuf0_thrd),
3489
  .fetchbuf1_thrd(fetchbuf1_thrd),
3490
  .fetchbuf0_pc(fetchbuf0_pc),
3491
  .fetchbuf1_pc(fetchbuf1_pc),
3492
  .fetchbuf0_v(fetchbuf0_v),
3493
  .fetchbuf1_v(fetchbuf1_v),
3494
  .fetchbuf0_insln(fetchbuf0_insln),
3495
  .fetchbuf1_insln(fetchbuf1_insln),
3496
  .codebuf0(codebuf[insn0[21:16]]),
3497
  .codebuf1(codebuf[insn1[21:16]]),
3498
  .btgtA(btgtA),
3499
  .btgtB(btgtB),
3500
  .btgtC(btgtC),
3501
  .btgtD(btgtD),
3502
  .nop_fetchbuf(nop_fetchbuf),
3503
  .take_branch0(take_branch0),
3504
  .take_branch1(take_branch1),
3505
  .stompedRets(stompedOnRets),
3506
  .panic(fb_panic)
3507 48 robfinch
);
3508 57 robfinch
end
3509
else begin : gb1
3510
FT64_fetchbuf_x1 #(AMSB,RSTPC) ufb1
3511
(
3512
  .rst(rst),
3513
  .clk4x(clk4x),
3514
  .clk(clk),
3515
  .fcu_clk(fcu_clk),
3516
  .cs_i(adr_o[31:16]==16'hFFFF),
3517
  .cyc_i(cyc_o),
3518
  .stb_i(stb_o),
3519
  .ack_o(dc_ack),
3520
  .we_i(we_o),
3521
  .adr_i(adr_o[15:0]),
3522
  .dat_i(dat_o[47:0]),
3523
  .cmpgrp(cr0[10:8]),
3524
  .freezePC(freezePC),
3525
  .regLR(regLR),
3526
  .thread_en(thread_en),
3527
  .insn0(insn0),
3528
  .phit(phit),
3529
  .threadx(threadx),
3530
  .branchmiss(branchmiss),
3531
  .misspc(misspc),
3532
  .branchmiss_thrd(branchmiss_thrd),
3533
  .predict_takenA(predict_takenA),
3534
  .predict_takenB(predict_takenB),
3535
  .predict_taken0(predict_taken0),
3536
  .queued1(queued1),
3537
  .queuedNop(queuedNop),
3538
  .pc0(pc0),
3539
  .fetchbuf(fetchbuf),
3540
  .fetchbufA_v(fetchbufA_v),
3541
  .fetchbufB_v(fetchbufB_v),
3542
  .fetchbufA_pc(fetchbufA_pc),
3543
  .fetchbufB_pc(fetchbufB_pc),
3544
  .fetchbufA_instr(fetchbufA_instr),
3545
  .fetchbufB_instr(fetchbufB_instr),
3546
  .fetchbuf0_instr(fetchbuf0_instr),
3547
  .fetchbuf0_thrd(fetchbuf0_thrd),
3548
  .fetchbuf0_pc(fetchbuf0_pc),
3549
  .fetchbuf0_v(fetchbuf0_v),
3550
  .fetchbuf0_insln(fetchbuf0_insln),
3551
  .codebuf0(codebuf[insn0[21:16]]),
3552
  .btgtA(btgtA),
3553
  .btgtB(btgtB),
3554
  .nop_fetchbuf(nop_fetchbuf),
3555
  .take_branch0(take_branch0),
3556
  .stompedRets(stompedOnRets),
3557
  .panic(fb_panic)
3558
);
3559
assign fetchbuf1_v = `INV;
3560
end
3561
end
3562
endgenerate
3563 48 robfinch
 
3564
 
3565
 
3566
//initial begin: stop_at
3567
//#1000000; panic <= `PANIC_OVERRUN;
3568
//end
3569
 
3570
//
3571
// BRANCH-MISS LOGIC: livetarget
3572
//
3573
// livetarget implies that there is a not-to-be-stomped instruction that targets the register in question
3574
// therefore, if it is zero it implies the rf_v value should become VALID on a branchmiss
3575
// 
3576
 
3577
generate begin : live_target
3578
    for (g = 1; g < PREGS; g = g + 1) begin : lvtgt
3579
    assign livetarget[g] = iqentry_0_livetarget[g] |
3580
                        iqentry_1_livetarget[g] |
3581
                        iqentry_2_livetarget[g] |
3582
                        iqentry_3_livetarget[g] |
3583
                        iqentry_4_livetarget[g] |
3584
                        iqentry_5_livetarget[g] |
3585
                        iqentry_6_livetarget[g] |
3586 52 robfinch
                        iqentry_7_livetarget[g] |
3587
                        iqentry_8_livetarget[g] |
3588
                        iqentry_9_livetarget[g]
3589
                        ;
3590 48 robfinch
    end
3591
end
3592
endgenerate
3593
 
3594 53 robfinch
    assign  iqentry_0_livetarget = {PREGS {iqentry_v[0]}} & {PREGS {~iqentry_stomp[0] && iqentry_thrd[0]==branchmiss_thrd}} & iq_out[0],
3595
            iqentry_1_livetarget = {PREGS {iqentry_v[1]}} & {PREGS {~iqentry_stomp[1] && iqentry_thrd[1]==branchmiss_thrd}} & iq_out[1],
3596
            iqentry_2_livetarget = {PREGS {iqentry_v[2]}} & {PREGS {~iqentry_stomp[2] && iqentry_thrd[2]==branchmiss_thrd}} & iq_out[2],
3597
            iqentry_3_livetarget = {PREGS {iqentry_v[3]}} & {PREGS {~iqentry_stomp[3] && iqentry_thrd[3]==branchmiss_thrd}} & iq_out[3],
3598
            iqentry_4_livetarget = {PREGS {iqentry_v[4]}} & {PREGS {~iqentry_stomp[4] && iqentry_thrd[4]==branchmiss_thrd}} & iq_out[4],
3599
            iqentry_5_livetarget = {PREGS {iqentry_v[5]}} & {PREGS {~iqentry_stomp[5] && iqentry_thrd[5]==branchmiss_thrd}} & iq_out[5],
3600
            iqentry_6_livetarget = {PREGS {iqentry_v[6]}} & {PREGS {~iqentry_stomp[6] && iqentry_thrd[6]==branchmiss_thrd}} & iq_out[6],
3601
            iqentry_7_livetarget = {PREGS {iqentry_v[7]}} & {PREGS {~iqentry_stomp[7] && iqentry_thrd[7]==branchmiss_thrd}} & iq_out[7],
3602
            iqentry_8_livetarget = {PREGS {iqentry_v[8]}} & {PREGS {~iqentry_stomp[8] && iqentry_thrd[8]==branchmiss_thrd}} & iq_out[8],
3603
            iqentry_9_livetarget = {PREGS {iqentry_v[9]}} & {PREGS {~iqentry_stomp[9] && iqentry_thrd[9]==branchmiss_thrd}} & iq_out[9]
3604 52 robfinch
            ;
3605 48 robfinch
 
3606 52 robfinch
//
3607
// BRANCH-MISS LOGIC: latestID
3608
//
3609
// latestID is the instruction queue ID of the newest instruction (latest) that targets
3610
// a particular register.  looks a lot like scheduling logic, but in reverse.
3611
// 
3612
always @*
3613
        for (n = 0; n < QENTRIES; n = n + 1) begin
3614
                iqentry_cumulative[n] = 0;
3615
                for (j = n; j < n + QENTRIES; j = j + 1) begin
3616
                        if (missid==(j % QENTRIES))
3617
                                for (k = n; k <= j; k = k + 1)
3618
                                        iqentry_cumulative[n] = iqentry_cumulative[n] | iqentry_livetarget[k % QENTRIES];
3619
                end
3620
        end
3621 48 robfinch
 
3622 53 robfinch
always @*
3623
        for (n = 0; n < QENTRIES; n = n + 1)
3624
    iqentry_latestID[n] = (missid == n || ((iqentry_livetarget[n] & iqentry_cumulative[(n+1)%QENTRIES]) == {PREGS{1'b0}}))
3625
                                    ? iqentry_livetarget[n]
3626 52 robfinch
                                    : {PREGS{1'b0}};
3627 48 robfinch
 
3628 53 robfinch
always @*
3629
        for (n = 0; n < QENTRIES; n = n + 1)
3630
          iqentry_source[n] = | iqentry_latestID[n];
3631 48 robfinch
 
3632
reg vqueued2;
3633
assign Ra0 = fnRa(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3634
assign Rb0 = fnRb(fetchbuf0_instr,1'b0,vqe0,rfoa0[5:0],rfoa1[5:0],fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3635
assign Rc0 = fnRc(fetchbuf0_instr,vqe0,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3636
assign Rt0 = fnRt(fetchbuf0_instr,vqet0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3637
assign Ra1 = fnRa(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3638
assign Rb1 = fnRb(fetchbuf1_instr,1'b1,vqueued2 ? vqe0 + 1 : vqe1,rfoa0[5:0],rfoa1[5:0],fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3639
assign Rc1 = fnRc(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3640
assign Rt1 = fnRt(fetchbuf1_instr,vqueued2 ? vqet0 + 1 : vqet1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3641
 
3642 49 robfinch
//
3643
// additional logic for ISSUE
3644
//
3645
// for the moment, we look at ALU-input buffers to allow back-to-back issue of 
3646
// dependent instructions ... we do not, however, look ahead for DRAM requests 
3647
// that will become valid in the next cycle.  instead, these have to propagate
3648
// their results into the IQ entry directly, at which point it becomes issue-able
3649
//
3650 48 robfinch
 
3651 49 robfinch
// note that, for all intents & purposes, iqentry_done == iqentry_agen ... no need to duplicate
3652 48 robfinch
 
3653
wire [QENTRIES-1:0] args_valid;
3654
wire [QENTRIES-1:0] could_issue;
3655
wire [QENTRIES-1:0] could_issueid;
3656
 
3657
generate begin : issue_logic
3658
for (g = 0; g < QENTRIES; g = g + 1)
3659
begin
3660
assign args_valid[g] =
3661
                  (iqentry_a1_v[g]
3662 49 robfinch
`ifdef FU_BYPASS
3663 48 robfinch
        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3664 49 robfinch
        || ((iqentry_a1_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3665
        || ((iqentry_a1_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
3666
`endif
3667
        )
3668 48 robfinch
    && (iqentry_a2_v[g]
3669
        || (iqentry_mem[g] & ~iqentry_agen[g] & ~iqentry_memndx[g])    // a2 needs to be valid for indexed instruction
3670 49 robfinch
`ifdef FU_BYPASS
3671 48 robfinch
        || (iqentry_a2_s[g] == alu0_sourceid && alu0_dataready)
3672 49 robfinch
        || ((iqentry_a2_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3673
        || ((iqentry_a2_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
3674
`endif
3675
        )
3676 48 robfinch
    && (iqentry_a3_v[g]
3677
//        || (iqentry_mem[g] & ~iqentry_agen[g])
3678 49 robfinch
`ifdef FU_BYPASS
3679 48 robfinch
        || (iqentry_a3_s[g] == alu0_sourceid && alu0_dataready)
3680 49 robfinch
        || ((iqentry_a3_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3681
`endif
3682
        )
3683 48 robfinch
    ;
3684
 
3685
assign could_issue[g] = iqentry_v[g] && !iqentry_done[g] && !iqentry_out[g]
3686
                                                                                                && args_valid[g]
3687
                                                                                                && iqentry_iv[g]
3688
                        && (iqentry_mem[g] ? !iqentry_agen[g] : 1'b1);
3689
 
3690 52 robfinch
assign could_issueid[g] = (iqentry_v[g])// || (g==tail0 && canq1))// || (g==tail1 && canq2))
3691
                                                                                                                && !iqentry_iv[g];
3692 48 robfinch
//                && (iqentry_a1_v[g] 
3693
//        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3694
//        || (iqentry_a1_s[g] == alu1_sourceid && alu1_dataready));
3695
 
3696
end
3697
end
3698
endgenerate
3699
 
3700
// The (old) simulator didn't handle the asynchronous race loop properly in the 
3701
// original code. It would issue two instructions to the same islot. So the
3702
// issue logic has been re-written to eliminate the asynchronous loop.
3703
// Can't issue to the ALU if it's busy doing a long running operation like a 
3704
// divide.
3705
// ToDo: fix the memory synchronization, see fp_issue below
3706
 
3707
wire [`QBITS] heads [QENTRIES-1:0];
3708
assign heads[0] = head0;
3709
assign heads[1] = head1;
3710
assign heads[2] = head2;
3711
assign heads[3] = head3;
3712
assign heads[4] = head4;
3713
assign heads[5] = head5;
3714
assign heads[6] = head6;
3715
assign heads[7] = head7;
3716 52 robfinch
assign heads[8] = head8;
3717
assign heads[9] = head9;
3718 48 robfinch
 
3719
always @*
3720
begin
3721 49 robfinch
        iqentry_id1issue = {QENTRIES{1'b0}};
3722 48 robfinch
        if (id1_available) begin
3723
                for (n = 0; n < QENTRIES; n = n + 1)
3724 49 robfinch
                        if (could_issueid[heads[n]] && iqentry_id1issue=={QENTRIES{1'b0}})
3725 48 robfinch
                          iqentry_id1issue[heads[n]] = `TRUE;
3726
        end
3727 49 robfinch
end
3728
generate begin : gIDUIssue
3729
        if (`NUM_IDU > 1) begin
3730
                always @*
3731
                begin
3732
                        iqentry_id2issue = {QENTRIES{1'b0}};
3733
                        if (id2_available) begin
3734
                                for (n = 0; n < QENTRIES; n = n + 1)
3735
                                        if (could_issueid[heads[n]] && !iqentry_id1issue[heads[n]] && iqentry_id2issue=={QENTRIES{1'b0}})
3736
                                          iqentry_id2issue[heads[n]] = `TRUE;
3737
                        end
3738
                end
3739 48 robfinch
        end
3740 49 robfinch
        if (`NUM_IDU > 2) begin
3741
                always @*
3742
                begin
3743
                        iqentry_id3issue = {QENTRIES{1'b0}};
3744
                        if (id3_available) begin
3745
                                for (n = 0; n < QENTRIES; n = n + 1)
3746
                                        if (could_issueid[heads[n]]
3747
                                        && !iqentry_id1issue[heads[n]]
3748
                                        && !iqentry_id2issue[heads[n]]
3749
                                        && iqentry_id3issue=={QENTRIES{1'b0}})
3750
                                          iqentry_id3issue[heads[n]] = `TRUE;
3751
                        end
3752
                end
3753
        end
3754 48 robfinch
end
3755 49 robfinch
endgenerate
3756 48 robfinch
 
3757
always @*
3758
begin
3759 49 robfinch
        iqentry_alu0_issue = {QENTRIES{1'b0}};
3760
        iqentry_alu1_issue = {QENTRIES{1'b0}};
3761 48 robfinch
 
3762
        if (alu0_available & alu0_idle) begin
3763
                if (could_issue[head0] && iqentry_alu[head0]) begin
3764
                  iqentry_alu0_issue[head0] = `TRUE;
3765
                end
3766
                else if (could_issue[head1] && iqentry_alu[head1])
3767
                begin
3768
                  iqentry_alu0_issue[head1] = `TRUE;
3769
                end
3770
                else if (could_issue[head2] && iqentry_alu[head2]
3771
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3772
                )
3773
                begin
3774
                        iqentry_alu0_issue[head2] = `TRUE;
3775
                end
3776
                else if (could_issue[head3] && iqentry_alu[head3]
3777
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3778
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3779
                                ((!iqentry_v[head0])
3780
                        &&   (!iqentry_v[head1]))
3781
                        )
3782
                ) begin
3783
                        iqentry_alu0_issue[head3] = `TRUE;
3784
                end
3785
                else if (could_issue[head4] && iqentry_alu[head4]
3786
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3787
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3788
                                ((!iqentry_v[head0])
3789
                        &&   (!iqentry_v[head1]))
3790
                        )
3791
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3792
                                ((!iqentry_v[head0])
3793
                        &&   (!iqentry_v[head1])
3794
                        &&   (!iqentry_v[head2]))
3795
                        )
3796
                ) begin
3797
                        iqentry_alu0_issue[head4] = `TRUE;
3798
                end
3799
                else if (could_issue[head5] && iqentry_alu[head5]
3800
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3801
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3802
                                ((!iqentry_v[head0])
3803
                        &&   (!iqentry_v[head1]))
3804
                        )
3805
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3806
                                ((!iqentry_v[head0])
3807
                        &&   (!iqentry_v[head1])
3808
                        &&   (!iqentry_v[head2]))
3809
                        )
3810
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3811
                                ((!iqentry_v[head0])
3812
                        &&   (!iqentry_v[head1])
3813
                        &&   (!iqentry_v[head2])
3814
                        &&   (!iqentry_v[head3]))
3815
                        )
3816
                ) begin
3817
                        iqentry_alu0_issue[head5] = `TRUE;
3818
                end
3819
`ifdef FULL_ISSUE_LOGIC
3820
                else if (could_issue[head6] && iqentry_alu[head6]
3821
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3822
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3823
                                ((!iqentry_v[head0])
3824
                        &&   (!iqentry_v[head1]))
3825
                        )
3826
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3827
                                ((!iqentry_v[head0])
3828
                        &&   (!iqentry_v[head1])
3829
                        &&   (!iqentry_v[head2]))
3830
                        )
3831
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3832
                                ((!iqentry_v[head0])
3833
                        &&   (!iqentry_v[head1])
3834
                        &&   (!iqentry_v[head2])
3835
                        &&   (!iqentry_v[head3]))
3836
                        )
3837
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3838
                                ((!iqentry_v[head0])
3839
                        &&   (!iqentry_v[head1])
3840
                        &&   (!iqentry_v[head2])
3841
                        &&   (!iqentry_v[head3])
3842
                        &&   (!iqentry_v[head4]))
3843
                        )
3844
                ) begin
3845
                        iqentry_alu0_issue[head6] = `TRUE;
3846
                end
3847
                else if (could_issue[head7] && iqentry_alu[head7]
3848
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3849
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3850
                                ((!iqentry_v[head0])
3851
                        &&   (!iqentry_v[head1]))
3852
                        )
3853
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3854
                                ((!iqentry_v[head0])
3855
                        &&   (!iqentry_v[head1])
3856
                        &&   (!iqentry_v[head2]))
3857
                        )
3858
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3859
                                ((!iqentry_v[head0])
3860
                        &&   (!iqentry_v[head1])
3861
                        &&   (!iqentry_v[head2])
3862
                        &&   (!iqentry_v[head3]))
3863
                        )
3864
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3865
                                ((!iqentry_v[head0])
3866
                        &&   (!iqentry_v[head1])
3867
                        &&   (!iqentry_v[head2])
3868
                        &&   (!iqentry_v[head3])
3869
                        &&   (!iqentry_v[head4]))
3870
                        )
3871
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
3872
                                ((!iqentry_v[head0])
3873
                        &&   (!iqentry_v[head1])
3874
                        &&   (!iqentry_v[head2])
3875
                        &&   (!iqentry_v[head3])
3876
                        &&   (!iqentry_v[head4])
3877
                        &&   (!iqentry_v[head5]))
3878
                        )
3879
                ) begin
3880
                        iqentry_alu0_issue[head7] = `TRUE;
3881
                end
3882 59 robfinch
                else if (could_issue[head8] && iqentry_alu[head8]
3883
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3884
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3885
                                ((!iqentry_v[head0])
3886
                        &&   (!iqentry_v[head1]))
3887
                        )
3888
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3889
                                ((!iqentry_v[head0])
3890
                        &&   (!iqentry_v[head1])
3891
                        &&   (!iqentry_v[head2]))
3892
                        )
3893
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3894
                                ((!iqentry_v[head0])
3895
                        &&   (!iqentry_v[head1])
3896
                        &&   (!iqentry_v[head2])
3897
                        &&   (!iqentry_v[head3]))
3898
                        )
3899
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3900
                                ((!iqentry_v[head0])
3901
                        &&   (!iqentry_v[head1])
3902
                        &&   (!iqentry_v[head2])
3903
                        &&   (!iqentry_v[head3])
3904
                        &&   (!iqentry_v[head4]))
3905
                        )
3906
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
3907
                                ((!iqentry_v[head0])
3908
                        &&   (!iqentry_v[head1])
3909
                        &&   (!iqentry_v[head2])
3910
                        &&   (!iqentry_v[head3])
3911
                        &&   (!iqentry_v[head4])
3912
                        &&   (!iqentry_v[head5]))
3913
                        )
3914
                && (!(iqentry_v[head7] && iqentry_sync[head7]) ||
3915
                                ((!iqentry_v[head0])
3916
                        &&   (!iqentry_v[head1])
3917
                        &&   (!iqentry_v[head2])
3918
                        &&   (!iqentry_v[head3])
3919
                        &&   (!iqentry_v[head4])
3920
                        &&   (!iqentry_v[head5])
3921
                        &&   (!iqentry_v[head6])
3922
                        )
3923
                        )
3924
                ) begin
3925
                        iqentry_alu0_issue[head8] = `TRUE;
3926
                end
3927
                else if (could_issue[head9] && iqentry_alu[head9]
3928
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3929
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3930
                                ((!iqentry_v[head0])
3931
                        &&   (!iqentry_v[head1]))
3932
                        )
3933
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3934
                                ((!iqentry_v[head0])
3935
                        &&   (!iqentry_v[head1])
3936
                        &&   (!iqentry_v[head2]))
3937
                        )
3938
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3939
                                ((!iqentry_v[head0])
3940
                        &&   (!iqentry_v[head1])
3941
                        &&   (!iqentry_v[head2])
3942
                        &&   (!iqentry_v[head3]))
3943
                        )
3944
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3945
                                ((!iqentry_v[head0])
3946
                        &&   (!iqentry_v[head1])
3947
                        &&   (!iqentry_v[head2])
3948
                        &&   (!iqentry_v[head3])
3949
                        &&   (!iqentry_v[head4]))
3950
                        )
3951
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
3952
                                ((!iqentry_v[head0])
3953
                        &&   (!iqentry_v[head1])
3954
                        &&   (!iqentry_v[head2])
3955
                        &&   (!iqentry_v[head3])
3956
                        &&   (!iqentry_v[head4])
3957
                        &&   (!iqentry_v[head5]))
3958
                        )
3959
                && (!(iqentry_v[head7] && iqentry_sync[head7]) ||
3960
                                ((!iqentry_v[head0])
3961
                        &&   (!iqentry_v[head1])
3962
                        &&   (!iqentry_v[head2])
3963
                        &&   (!iqentry_v[head3])
3964
                        &&   (!iqentry_v[head4])
3965
                        &&   (!iqentry_v[head5])
3966
                        &&   (!iqentry_v[head6]))
3967
                        )
3968
                && (!(iqentry_v[head8] && iqentry_sync[head8]) ||
3969
                                ((!iqentry_v[head0])
3970
                        &&   (!iqentry_v[head1])
3971
                        &&   (!iqentry_v[head2])
3972
                        &&   (!iqentry_v[head3])
3973
                        &&   (!iqentry_v[head4])
3974
                        &&   (!iqentry_v[head5])
3975
                        &&   (!iqentry_v[head6])
3976
                        &&   (!iqentry_v[head7])
3977
                        )
3978
                        )
3979
                ) begin
3980
                        iqentry_alu0_issue[head9] = `TRUE;
3981
                end
3982 48 robfinch
`endif
3983
        end
3984
 
3985 49 robfinch
        if (alu1_available && alu1_idle && `NUM_ALU > 1) begin
3986 48 robfinch
                if ((could_issue & ~iqentry_alu0_issue & ~iqentry_alu0) != 8'h00) begin
3987
                if (could_issue[head0] && iqentry_alu[head0]
3988
                && !iqentry_alu0[head0] // alu0only
3989
                && !iqentry_alu0_issue[head0]) begin
3990
                  iqentry_alu1_issue[head0] = `TRUE;
3991
                end
3992
                else if (could_issue[head1] && !iqentry_alu0_issue[head1] && iqentry_alu[head1]
3993
                && !iqentry_alu0[head1])
3994
                begin
3995
                  iqentry_alu1_issue[head1] = `TRUE;
3996
                end
3997
                else if (could_issue[head2] && !iqentry_alu0_issue[head2] && iqentry_alu[head2]
3998
                && !iqentry_alu0[head2]
3999
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4000
                )
4001
                begin
4002
                        iqentry_alu1_issue[head2] = `TRUE;
4003
                end
4004
                else if (could_issue[head3] && !iqentry_alu0_issue[head3] && iqentry_alu[head3]
4005
                && !iqentry_alu0[head3]
4006
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4007
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4008
                                ((!iqentry_v[head0])
4009
                        &&   (!iqentry_v[head1]))
4010
                        )
4011
                ) begin
4012
                        iqentry_alu1_issue[head3] = `TRUE;
4013
                end
4014
                else if (could_issue[head4] && !iqentry_alu0_issue[head4] && iqentry_alu[head4]
4015
                && !iqentry_alu0[head4]
4016
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4017
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4018
                                ((!iqentry_v[head0])
4019
                        &&   (!iqentry_v[head1]))
4020
                        )
4021
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4022
                                ((!iqentry_v[head0])
4023
                        &&   (!iqentry_v[head1])
4024
                        &&   (!iqentry_v[head2]))
4025
                        )
4026
                ) begin
4027
                        iqentry_alu1_issue[head4] = `TRUE;
4028
                end
4029
                else if (could_issue[head5] && !iqentry_alu0_issue[head5] && iqentry_alu[head5]
4030
                && !iqentry_alu0[head5]
4031
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4032
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4033
                                ((!iqentry_v[head0])
4034
                        &&   (!iqentry_v[head1]))
4035
                        )
4036
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4037
                                ((!iqentry_v[head0])
4038
                        &&   (!iqentry_v[head1])
4039
                        &&   (!iqentry_v[head2]))
4040
                        )
4041
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4042
                                ((!iqentry_v[head0])
4043
                        &&   (!iqentry_v[head1])
4044
                        &&   (!iqentry_v[head2])
4045
                        &&   (!iqentry_v[head3]))
4046
                        )
4047
                ) begin
4048
                        iqentry_alu1_issue[head5] = `TRUE;
4049
                end
4050
`ifdef FULL_ISSUE_LOGIC
4051
                else if (could_issue[head6] && !iqentry_alu0_issue[head6] && iqentry_alu[head6]
4052
                && !iqentry_alu0[head6]
4053
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4054
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4055
                                ((!iqentry_v[head0])
4056
                        &&   (!iqentry_v[head1]))
4057
                        )
4058
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4059
                                ((!iqentry_v[head0])
4060
                        &&   (!iqentry_v[head1])
4061
                        &&   (!iqentry_v[head2]))
4062
                        )
4063
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4064
                                ((!iqentry_v[head0])
4065
                        &&   (!iqentry_v[head1])
4066
                        &&   (!iqentry_v[head2])
4067
                        &&   (!iqentry_v[head3]))
4068
                        )
4069
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4070
                                ((!iqentry_v[head0])
4071
                        &&   (!iqentry_v[head1])
4072
                        &&   (!iqentry_v[head2])
4073
                        &&   (!iqentry_v[head3])
4074
                        &&   (!iqentry_v[head4]))
4075
                        )
4076
                ) begin
4077
                        iqentry_alu1_issue[head6] = `TRUE;
4078
                end
4079
                else if (could_issue[head7] && !iqentry_alu0_issue[head7] && iqentry_alu[head7]
4080
                && !iqentry_alu0[head7]
4081
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4082
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4083
                                ((!iqentry_v[head0])
4084
                        &&   (!iqentry_v[head1]))
4085
                        )
4086
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4087
                                ((!iqentry_v[head0])
4088
                        &&   (!iqentry_v[head1])
4089
                        &&   (!iqentry_v[head2]))
4090
                        )
4091
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4092
                                ((!iqentry_v[head0])
4093
                        &&   (!iqentry_v[head1])
4094
                        &&   (!iqentry_v[head2])
4095
                        &&   (!iqentry_v[head3]))
4096
                        )
4097
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4098
                                ((!iqentry_v[head0])
4099
                        &&   (!iqentry_v[head1])
4100
                        &&   (!iqentry_v[head2])
4101
                        &&   (!iqentry_v[head3])
4102
                        &&   (!iqentry_v[head4]))
4103
                        )
4104
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4105
                                ((!iqentry_v[head0])
4106
                        &&   (!iqentry_v[head1])
4107
                        &&   (!iqentry_v[head2])
4108
                        &&   (!iqentry_v[head3])
4109
                        &&   (!iqentry_v[head4])
4110
                        &&   (!iqentry_v[head5]))
4111
                        )
4112
                ) begin
4113
                        iqentry_alu1_issue[head7] = `TRUE;
4114
                end
4115
`endif
4116
        end
4117
//      aluissue(alu0_idle,8'h00,2'b00);
4118
//      aluissue(alu1_idle,iqentry_alu0,2'b01);
4119
        end
4120
end
4121
 
4122
always @*
4123
begin
4124 49 robfinch
        iqentry_fpu1_issue = {QENTRIES{1'b0}};
4125
//      fpu1issue(fpu1_idle,2'b00);
4126
        if (fpu1_idle && `NUM_FPU > 0) begin
4127 48 robfinch
    if (could_issue[head0] && iqentry_fpu[head0]) begin
4128 49 robfinch
      iqentry_fpu1_issue[head0] = `TRUE;
4129 48 robfinch
    end
4130
    else if (could_issue[head1] && iqentry_fpu[head1])
4131
    begin
4132 49 robfinch
      iqentry_fpu1_issue[head1] = `TRUE;
4133 48 robfinch
    end
4134
    else if (could_issue[head2] && iqentry_fpu[head2]
4135
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4136
    ) begin
4137 49 robfinch
      iqentry_fpu1_issue[head2] = `TRUE;
4138 48 robfinch
    end
4139
    else if (could_issue[head3] && iqentry_fpu[head3]
4140
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4141
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4142
                ((!iqentry_v[head0])
4143
        &&   (!iqentry_v[head1]))
4144
        )
4145
    ) begin
4146 49 robfinch
      iqentry_fpu1_issue[head3] = `TRUE;
4147 48 robfinch
    end
4148
    else if (could_issue[head4] && iqentry_fpu[head4]
4149
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4150
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4151
                ((!iqentry_v[head0])
4152
        &&   (!iqentry_v[head1]))
4153
        )
4154
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4155
                ((!iqentry_v[head0])
4156
        &&   (!iqentry_v[head1])
4157
        &&   (!iqentry_v[head2]))
4158
        )
4159
    ) begin
4160 49 robfinch
      iqentry_fpu1_issue[head4] = `TRUE;
4161 48 robfinch
    end
4162
    else if (could_issue[head5] && iqentry_fpu[head5]
4163
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4164
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4165
                ((!iqentry_v[head0])
4166
        &&   (!iqentry_v[head1]))
4167
        )
4168
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4169
                ((!iqentry_v[head0])
4170
        &&   (!iqentry_v[head1])
4171
        &&   (!iqentry_v[head2]))
4172
        )
4173
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4174
                ((!iqentry_v[head0])
4175
        &&   (!iqentry_v[head1])
4176
        &&   (!iqentry_v[head2])
4177
        &&   (!iqentry_v[head3]))
4178
        )
4179
        ) begin
4180 49 robfinch
              iqentry_fpu1_issue[head5] = `TRUE;
4181 48 robfinch
    end
4182
`ifdef FULL_ISSUE_LOGIC
4183
    else if (could_issue[head6] && iqentry_fpu[head6]
4184
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4185
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4186
                ((!iqentry_v[head0])
4187
        &&   (!iqentry_v[head1]))
4188
        )
4189
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4190
                ((!iqentry_v[head0])
4191
        &&   (!iqentry_v[head1])
4192
        &&   (!iqentry_v[head2]))
4193
        )
4194
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4195
                ((!iqentry_v[head0])
4196
        &&   (!iqentry_v[head1])
4197
        &&   (!iqentry_v[head2])
4198
        &&   (!iqentry_v[head3]))
4199
        )
4200
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4201
                ((!iqentry_v[head0])
4202
        &&   (!iqentry_v[head1])
4203
        &&   (!iqentry_v[head2])
4204
        &&   (!iqentry_v[head3])
4205
        &&   (!iqentry_v[head4]))
4206
        )
4207
    ) begin
4208 49 robfinch
        iqentry_fpu1_issue[head6] = `TRUE;
4209 48 robfinch
    end
4210
    else if (could_issue[head7] && iqentry_fpu[head7]
4211
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4212
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4213
                ((!iqentry_v[head0])
4214
        &&   (!iqentry_v[head1]))
4215
        )
4216
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4217
                ((!iqentry_v[head0])
4218
        &&   (!iqentry_v[head1])
4219
        &&   (!iqentry_v[head2]))
4220
        )
4221
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4222
                ((!iqentry_v[head0])
4223
        &&   (!iqentry_v[head1])
4224
        &&   (!iqentry_v[head2])
4225
        &&   (!iqentry_v[head3]))
4226
        )
4227
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4228
                ((!iqentry_v[head0])
4229
        &&   (!iqentry_v[head1])
4230
        &&   (!iqentry_v[head2])
4231
        &&   (!iqentry_v[head3])
4232
        &&   (!iqentry_v[head4]))
4233
        )
4234
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
4235
                ((!iqentry_v[head0])
4236
        &&   (!iqentry_v[head1])
4237
        &&   (!iqentry_v[head2])
4238
        &&   (!iqentry_v[head3])
4239
        &&   (!iqentry_v[head4])
4240
        &&   (!iqentry_v[head5]))
4241
        )
4242
        )
4243
    begin
4244 49 robfinch
                iqentry_fpu1_issue[head7] = `TRUE;
4245 48 robfinch
        end
4246
`endif
4247
        end
4248
end
4249
 
4250 49 robfinch
always @*
4251
begin
4252
        iqentry_fpu2_issue = {QENTRIES{1'b0}};
4253
//      fpu2issue(fpu2_idle,2'b00);
4254
        if (fpu2_idle && `NUM_FPU > 1) begin
4255
    if (could_issue[head0] && iqentry_fpu[head0] && !iqentry_fpu1_issue[head0]) begin
4256
      iqentry_fpu2_issue[head0] = `TRUE;
4257
    end
4258
    else if (could_issue[head1] && iqentry_fpu[head1] && !iqentry_fpu1_issue[head1])
4259
    begin
4260
      iqentry_fpu2_issue[head1] = `TRUE;
4261
    end
4262
    else if (could_issue[head2] && iqentry_fpu[head2] && !iqentry_fpu1_issue[head2]
4263
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4264
    ) begin
4265
      iqentry_fpu2_issue[head2] = `TRUE;
4266
    end
4267
    else if (could_issue[head3] && iqentry_fpu[head3] && !iqentry_fpu1_issue[head3]
4268
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4269
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4270
                ((!iqentry_v[head0])
4271
        &&   (!iqentry_v[head1]))
4272
        )
4273
    ) begin
4274
      iqentry_fpu2_issue[head3] = `TRUE;
4275
    end
4276
    else if (could_issue[head4] && iqentry_fpu[head4] && !iqentry_fpu1_issue[head4]
4277
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4278
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4279
                ((!iqentry_v[head0])
4280
        &&   (!iqentry_v[head1]))
4281
        )
4282
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4283
                ((!iqentry_v[head0])
4284
        &&   (!iqentry_v[head1])
4285
        &&   (!iqentry_v[head2]))
4286
        )
4287
    ) begin
4288
      iqentry_fpu2_issue[head4] = `TRUE;
4289
    end
4290
    else if (could_issue[head5] && iqentry_fpu[head5] && !iqentry_fpu1_issue[head5]
4291
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4292
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4293
                ((!iqentry_v[head0])
4294
        &&   (!iqentry_v[head1]))
4295
        )
4296
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4297
                ((!iqentry_v[head0])
4298
        &&   (!iqentry_v[head1])
4299
        &&   (!iqentry_v[head2]))
4300
        )
4301
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4302
                ((!iqentry_v[head0])
4303
        &&   (!iqentry_v[head1])
4304
        &&   (!iqentry_v[head2])
4305
        &&   (!iqentry_v[head3]))
4306
        )
4307
        ) begin
4308
              iqentry_fpu2_issue[head5] = `TRUE;
4309
    end
4310
`ifdef FULL_ISSUE_LOGIC
4311
    else if (could_issue[head6] && iqentry_fpu[head6] && !iqentry_fpu1_issue[head6]
4312
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4313
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4314
                ((!iqentry_v[head0])
4315
        &&   (!iqentry_v[head1]))
4316
        )
4317
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4318
                ((!iqentry_v[head0])
4319
        &&   (!iqentry_v[head1])
4320
        &&   (!iqentry_v[head2]))
4321
        )
4322
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4323
                ((!iqentry_v[head0])
4324
        &&   (!iqentry_v[head1])
4325
        &&   (!iqentry_v[head2])
4326
        &&   (!iqentry_v[head3]))
4327
        )
4328
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4329
                ((!iqentry_v[head0])
4330
        &&   (!iqentry_v[head1])
4331
        &&   (!iqentry_v[head2])
4332
        &&   (!iqentry_v[head3])
4333
        &&   (!iqentry_v[head4]))
4334
        )
4335
    ) begin
4336
        iqentry_fpu2_issue[head6] = `TRUE;
4337
    end
4338
    else if (could_issue[head7] && iqentry_fpu[head7] && !iqentry_fpu1_issue[head7]
4339
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4340
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4341
                ((!iqentry_v[head0])
4342
        &&   (!iqentry_v[head1]))
4343
        )
4344
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4345
                ((!iqentry_v[head0])
4346
        &&   (!iqentry_v[head1])
4347
        &&   (!iqentry_v[head2]))
4348
        )
4349
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4350
                ((!iqentry_v[head0])
4351
        &&   (!iqentry_v[head1])
4352
        &&   (!iqentry_v[head2])
4353
        &&   (!iqentry_v[head3]))
4354
        )
4355
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4356
                ((!iqentry_v[head0])
4357
        &&   (!iqentry_v[head1])
4358
        &&   (!iqentry_v[head2])
4359
        &&   (!iqentry_v[head3])
4360
        &&   (!iqentry_v[head4]))
4361
        )
4362
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
4363
                ((!iqentry_v[head0])
4364
        &&   (!iqentry_v[head1])
4365
        &&   (!iqentry_v[head2])
4366
        &&   (!iqentry_v[head3])
4367
        &&   (!iqentry_v[head4])
4368
        &&   (!iqentry_v[head5]))
4369
        )
4370
        )
4371
    begin
4372
                iqentry_fpu2_issue[head7] = `TRUE;
4373
        end
4374
`endif
4375
        end
4376
end
4377 48 robfinch
 
4378
wire [QENTRIES-1:0] nextqd;
4379
// Next queue id
4380
 
4381
reg [`QBITS] nid0;
4382
always @*
4383
if (iqentry_thrd[1]==iqentry_thrd[0])
4384 52 robfinch
        nid0 = 4'd1;
4385 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[0])
4386 52 robfinch
        nid0 = 4'd2;
4387 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[0])
4388 52 robfinch
        nid0 = 4'd3;
4389 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[0])
4390 52 robfinch
        nid0 = 4'd4;
4391 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[0])
4392 52 robfinch
        nid0 = 4'd5;
4393 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[0])
4394 52 robfinch
        nid0 = 4'd6;
4395 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[0])
4396 52 robfinch
        nid0 = 4'd7;
4397
else if (iqentry_thrd[8]==iqentry_thrd[0])
4398
        nid0 = 4'd8;
4399
else if (iqentry_thrd[9]==iqentry_thrd[0])
4400
        nid0 = 4'd9;
4401 48 robfinch
else
4402
        nid0 = 3'd0;
4403
 
4404
reg [`QBITS] nid1;
4405
always @*
4406
if (iqentry_thrd[2]==iqentry_thrd[1])
4407 52 robfinch
        nid1 = 4'd2;
4408 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[1])
4409 52 robfinch
        nid1 = 4'd3;
4410 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[1])
4411 52 robfinch
        nid1 = 4'd4;
4412 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[1])
4413 52 robfinch
        nid1 = 4'd5;
4414 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[1])
4415 52 robfinch
        nid1 = 4'd6;
4416 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[1])
4417 52 robfinch
        nid1 = 4'd7;
4418
else if (iqentry_thrd[8]==iqentry_thrd[1])
4419
        nid1 = 4'd8;
4420
else if (iqentry_thrd[9]==iqentry_thrd[1])
4421
        nid1 = 4'd9;
4422 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[1])
4423 52 robfinch
        nid1 = 4'd0;
4424 48 robfinch
else
4425 52 robfinch
        nid1 = 4'd1;
4426 48 robfinch
 
4427
reg [`QBITS] nid2;
4428
always @*
4429
if (iqentry_thrd[3]==iqentry_thrd[2])
4430 52 robfinch
        nid2 = 4'd3;
4431 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[2])
4432 52 robfinch
        nid2 = 4'd4;
4433 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[2])
4434 52 robfinch
        nid2 = 4'd5;
4435 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[2])
4436 52 robfinch
        nid2 = 4'd6;
4437 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[2])
4438 52 robfinch
        nid2 = 4'd7;
4439
else if (iqentry_thrd[8]==iqentry_thrd[2])
4440
        nid2 = 4'd8;
4441
else if (iqentry_thrd[9]==iqentry_thrd[2])
4442
        nid2 = 4'd9;
4443 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[2])
4444 52 robfinch
        nid2 = 4'd0;
4445 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[2])
4446 52 robfinch
        nid2 = 4'd1;
4447 48 robfinch
else
4448 52 robfinch
        nid2 = 4'd2;
4449 48 robfinch
 
4450
reg [`QBITS] nid3;
4451
always @*
4452
if (iqentry_thrd[4]==iqentry_thrd[3])
4453 52 robfinch
        nid3 = 4'd4;
4454 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[3])
4455 52 robfinch
        nid3 = 4'd5;
4456 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[3])
4457 52 robfinch
        nid3 = 4'd6;
4458 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[3])
4459 52 robfinch
        nid3 = 4'd7;
4460
else if (iqentry_thrd[8]==iqentry_thrd[3])
4461
        nid3 = 4'd8;
4462
else if (iqentry_thrd[9]==iqentry_thrd[3])
4463
        nid3 = 4'd9;
4464 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[3])
4465 52 robfinch
        nid3 = 4'd0;
4466 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[3])
4467 52 robfinch
        nid3 = 4'd1;
4468 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[3])
4469 52 robfinch
        nid3 = 4'd2;
4470 48 robfinch
else
4471 52 robfinch
        nid3 = 4'd3;
4472 48 robfinch
 
4473
reg [`QBITS] nid4;
4474
always @*
4475
if (iqentry_thrd[5]==iqentry_thrd[4])
4476 52 robfinch
        nid4 = 4'd5;
4477 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[4])
4478 52 robfinch
        nid4 = 4'd6;
4479 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[4])
4480 52 robfinch
        nid4 = 4'd7;
4481
else if (iqentry_thrd[8]==iqentry_thrd[4])
4482
        nid4 = 4'd8;
4483
else if (iqentry_thrd[9]==iqentry_thrd[4])
4484
        nid4 = 4'd9;
4485 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[4])
4486 52 robfinch
        nid4 = 4'd0;
4487 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[4])
4488 52 robfinch
        nid4 = 4'd1;
4489 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[4])
4490 52 robfinch
        nid4 = 4'd2;
4491 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[4])
4492 52 robfinch
        nid4 = 4'd3;
4493 48 robfinch
else
4494 52 robfinch
        nid4 = 4'd4;
4495 48 robfinch
 
4496
reg [`QBITS] nid5;
4497
always @*
4498
if (iqentry_thrd[6]==iqentry_thrd[5])
4499 52 robfinch
        nid5 = 4'd6;
4500 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[5])
4501 52 robfinch
        nid5 = 4'd7;
4502
else if (iqentry_thrd[8]==iqentry_thrd[5])
4503
        nid5 = 4'd8;
4504
else if (iqentry_thrd[9]==iqentry_thrd[5])
4505
        nid5 = 4'd9;
4506 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[5])
4507 52 robfinch
        nid5 = 4'd0;
4508 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[5])
4509 52 robfinch
        nid5 = 4'd1;
4510 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[5])
4511 52 robfinch
        nid5 = 4'd2;
4512 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[5])
4513 52 robfinch
        nid5 = 4'd3;
4514 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[5])
4515 52 robfinch
        nid5 = 4'd4;
4516 48 robfinch
else
4517 52 robfinch
        nid5 = 4'd5;
4518 48 robfinch
 
4519
reg [`QBITS] nid6;
4520
always @*
4521
if (iqentry_thrd[7]==iqentry_thrd[6])
4522 52 robfinch
        nid6 = 4'd7;
4523
else if (iqentry_thrd[8]==iqentry_thrd[6])
4524
        nid6 = 4'd8;
4525
else if (iqentry_thrd[9]==iqentry_thrd[6])
4526
        nid6 = 4'd9;
4527 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[6])
4528 52 robfinch
        nid6 = 4'd0;
4529 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[6])
4530 52 robfinch
        nid6 = 4'd1;
4531 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[6])
4532 52 robfinch
        nid6 = 4'd2;
4533 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[6])
4534 52 robfinch
        nid6 = 4'd3;
4535 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[6])
4536 52 robfinch
        nid6 = 4'd4;
4537 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[6])
4538 52 robfinch
        nid6 = 4'd5;
4539 48 robfinch
else
4540 52 robfinch
        nid6 = 4'd6;
4541 48 robfinch
 
4542
reg [`QBITS] nid7;
4543
always @*
4544 52 robfinch
if (iqentry_thrd[8]==iqentry_thrd[7])
4545
        nid7 = 4'd8;
4546
else if (iqentry_thrd[9]==iqentry_thrd[7])
4547
        nid7 = 4'd9;
4548
else if (iqentry_thrd[0]==iqentry_thrd[7])
4549
        nid7 = 4'd0;
4550 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[7])
4551 52 robfinch
        nid7 = 4'd1;
4552 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[7])
4553 52 robfinch
        nid7 = 4'd2;
4554 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[7])
4555 52 robfinch
        nid7 = 4'd3;
4556 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[7])
4557 52 robfinch
        nid7 = 4'd4;
4558 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[7])
4559 52 robfinch
        nid7 = 4'd5;
4560 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[7])
4561 52 robfinch
        nid7 = 4'd6;
4562 48 robfinch
else
4563 52 robfinch
        nid7 = 4'd7;
4564 48 robfinch
 
4565 52 robfinch
reg [`QBITS] nid8;
4566
always @*
4567
if (iqentry_thrd[9]==iqentry_thrd[8])
4568
        nid8 = 4'd9;
4569
else if (iqentry_thrd[0]==iqentry_thrd[8])
4570
        nid8 = 4'd0;
4571
else if (iqentry_thrd[1]==iqentry_thrd[8])
4572
        nid8 = 4'd1;
4573
else if (iqentry_thrd[2]==iqentry_thrd[8])
4574
        nid8 = 4'd2;
4575
else if (iqentry_thrd[3]==iqentry_thrd[8])
4576
        nid8 = 4'd3;
4577
else if (iqentry_thrd[4]==iqentry_thrd[8])
4578
        nid8 = 4'd4;
4579
else if (iqentry_thrd[5]==iqentry_thrd[8])
4580
        nid8 = 4'd5;
4581
else if (iqentry_thrd[6]==iqentry_thrd[8])
4582
        nid8 = 4'd6;
4583
else if (iqentry_thrd[7]==iqentry_thrd[8])
4584
        nid8 = 4'd7;
4585
else
4586
        nid8 = 4'd8;
4587
 
4588
reg [`QBITS] nid9;
4589
always @*
4590
if (iqentry_thrd[0]==iqentry_thrd[9])
4591
        nid9 = 4'd0;
4592
else if (iqentry_thrd[1]==iqentry_thrd[9])
4593
        nid9 = 4'd1;
4594
else if (iqentry_thrd[2]==iqentry_thrd[9])
4595
        nid9 = 4'd2;
4596
else if (iqentry_thrd[3]==iqentry_thrd[9])
4597
        nid9 = 4'd3;
4598
else if (iqentry_thrd[4]==iqentry_thrd[9])
4599
        nid9 = 4'd4;
4600
else if (iqentry_thrd[5]==iqentry_thrd[9])
4601
        nid9 = 4'd5;
4602
else if (iqentry_thrd[6]==iqentry_thrd[9])
4603
        nid9 = 4'd6;
4604
else if (iqentry_thrd[7]==iqentry_thrd[9])
4605
        nid9 = 4'd7;
4606
else if (iqentry_thrd[8]==iqentry_thrd[9])
4607
        nid9 = 4'd8;
4608
else
4609
        nid9 = 4'd9;
4610
 
4611 48 robfinch
// Search the queue for the next entry on the same thread.
4612
reg [`QBITS] nid;
4613
always @*
4614
if (iqentry_thrd[idp1(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4615
        nid = idp1(fcu_id);
4616
else if (iqentry_thrd[idp2(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4617
        nid = idp2(fcu_id);
4618
else if (iqentry_thrd[idp3(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4619
        nid = idp3(fcu_id);
4620
else if (iqentry_thrd[idp4(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4621
        nid = idp4(fcu_id);
4622
else if (iqentry_thrd[idp5(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4623
        nid = idp5(fcu_id);
4624
else if (iqentry_thrd[idp6(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4625
        nid = idp6(fcu_id);
4626
else if (iqentry_thrd[idp7(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4627
        nid = idp7(fcu_id);
4628 52 robfinch
else if (iqentry_thrd[idp8(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4629
        nid = idp8(fcu_id);
4630
else if (iqentry_thrd[idp9(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4631
        nid = idp9(fcu_id);
4632 48 robfinch
else
4633
        nid = fcu_id;
4634
 
4635
assign  nextqd[0] = iqentry_sn[nid0] > iqentry_sn[0] || iqentry_v[0];
4636
assign  nextqd[1] = iqentry_sn[nid1] > iqentry_sn[1] || iqentry_v[1];
4637
assign  nextqd[2] = iqentry_sn[nid2] > iqentry_sn[2] || iqentry_v[2];
4638
assign  nextqd[3] = iqentry_sn[nid3] > iqentry_sn[3] || iqentry_v[3];
4639
assign  nextqd[4] = iqentry_sn[nid4] > iqentry_sn[4] || iqentry_v[4];
4640
assign  nextqd[5] = iqentry_sn[nid5] > iqentry_sn[5] || iqentry_v[5];
4641
assign  nextqd[6] = iqentry_sn[nid6] > iqentry_sn[6] || iqentry_v[6];
4642
assign  nextqd[7] = iqentry_sn[nid7] > iqentry_sn[7] || iqentry_v[7];
4643 52 robfinch
assign  nextqd[8] = iqentry_sn[nid8] > iqentry_sn[8] || iqentry_v[8];
4644
assign  nextqd[9] = iqentry_sn[nid9] > iqentry_sn[9] || iqentry_v[9];
4645 48 robfinch
 
4646
//assign nextqd = 8'hFF;
4647
 
4648
// Don't issue to the fcu until the following instruction is enqueued.
4649
// However, if the queue is full then issue anyway. A branch miss will likely occur.
4650
always @*//(could_issue or head0 or head1 or head2 or head3 or head4 or head5 or head6 or head7)
4651
begin
4652 49 robfinch
        iqentry_fcu_issue = {QENTRIES{1'b0}};
4653 48 robfinch
        if (fcu_done) begin
4654
    if (could_issue[head0] && iqentry_fc[head0] && nextqd[head0]) begin
4655
      iqentry_fcu_issue[head0] = `TRUE;
4656
    end
4657
    else if (could_issue[head1] && iqentry_fc[head1] && nextqd[head1])
4658
    begin
4659
      iqentry_fcu_issue[head1] = `TRUE;
4660
    end
4661
    else if (could_issue[head2] && iqentry_fc[head2] && nextqd[head2]
4662
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4663
    ) begin
4664
                iqentry_fcu_issue[head2] = `TRUE;
4665
    end
4666
    else if (could_issue[head3] && iqentry_fc[head3] && nextqd[head3]
4667
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4668
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4669
                ((!iqentry_v[head0])
4670
        &&   (!iqentry_v[head1]))
4671
        )
4672
    ) begin
4673
                iqentry_fcu_issue[head3] = `TRUE;
4674
    end
4675
    else if (could_issue[head4] && iqentry_fc[head4] && nextqd[head4]
4676
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4677
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4678
                ((!iqentry_v[head0])
4679
        &&   (!iqentry_v[head1]))
4680
        )
4681
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4682
                ((!iqentry_v[head0])
4683
        &&   (!iqentry_v[head1])
4684
        &&   (!iqentry_v[head2]))
4685
        )
4686
    ) begin
4687
                iqentry_fcu_issue[head4] = `TRUE;
4688
    end
4689
    else if (could_issue[head5] && iqentry_fc[head5] && nextqd[head5]
4690
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4691
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4692
                ((!iqentry_v[head0])
4693
        &&   (!iqentry_v[head1]))
4694
        )
4695
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4696
                ((!iqentry_v[head0])
4697
        &&   (!iqentry_v[head1])
4698
        &&   (!iqentry_v[head2]))
4699
        )
4700
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4701
                ((!iqentry_v[head0])
4702
        &&   (!iqentry_v[head1])
4703
        &&   (!iqentry_v[head2])
4704
        &&   (!iqentry_v[head3]))
4705
        )
4706
    ) begin
4707
                iqentry_fcu_issue[head5] = `TRUE;
4708
    end
4709
 
4710
`ifdef FULL_ISSUE_LOGIC
4711
    else if (could_issue[head6] && iqentry_fc[head6] && nextqd[head6]
4712
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4713
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4714
                ((!iqentry_v[head0])
4715
        &&   (!iqentry_v[head1]))
4716
        )
4717
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4718
                ((!iqentry_v[head0])
4719
        &&   (!iqentry_v[head1])
4720
        &&   (!iqentry_v[head2]))
4721
        )
4722
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4723
                ((!iqentry_v[head0])
4724
        &&   (!iqentry_v[head1])
4725
        &&   (!iqentry_v[head2])
4726
        &&   (!iqentry_v[head3]))
4727
        )
4728
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4729
                ((!iqentry_v[head0])
4730
        &&   (!iqentry_v[head1])
4731
        &&   (!iqentry_v[head2])
4732
        &&   (!iqentry_v[head3])
4733
        &&   (!iqentry_v[head4]))
4734
        )
4735
    ) begin
4736
                iqentry_fcu_issue[head6] = `TRUE;
4737
    end
4738
 
4739
    else if (could_issue[head7] && iqentry_fc[head7]
4740
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4741
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4742
                ((!iqentry_v[head0])
4743
        &&   (!iqentry_v[head1]))
4744
        )
4745
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4746
                ((!iqentry_v[head0])
4747
        &&   (!iqentry_v[head1])
4748
        &&   (!iqentry_v[head2]))
4749
        )
4750
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4751
                ((!iqentry_v[head0])
4752
        &&   (!iqentry_v[head1])
4753
        &&   (!iqentry_v[head2])
4754
        &&   (!iqentry_v[head3]))
4755
        )
4756
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4757
                ((!iqentry_v[head0])
4758
        &&   (!iqentry_v[head1])
4759
        &&   (!iqentry_v[head2])
4760
        &&   (!iqentry_v[head3])
4761
        &&   (!iqentry_v[head4]))
4762
        )
4763
    && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4764
                ((!iqentry_v[head0])
4765
        &&   (!iqentry_v[head1])
4766
        &&   (!iqentry_v[head2])
4767
        &&   (!iqentry_v[head3])
4768
        &&   (!iqentry_v[head4])
4769
        &&   (!iqentry_v[head5]))
4770
        )
4771
    ) begin
4772
                iqentry_fcu_issue[head7] = `TRUE;
4773
        end
4774 59 robfinch
    else if (could_issue[head8] && iqentry_fc[head8]
4775
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4776
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4777
                ((!iqentry_v[head0])
4778
        &&   (!iqentry_v[head1]))
4779
        )
4780
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4781
                ((!iqentry_v[head0])
4782
        &&   (!iqentry_v[head1])
4783
        &&   (!iqentry_v[head2]))
4784
        )
4785
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4786
                ((!iqentry_v[head0])
4787
        &&   (!iqentry_v[head1])
4788
        &&   (!iqentry_v[head2])
4789
        &&   (!iqentry_v[head3]))
4790
        )
4791
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4792
                ((!iqentry_v[head0])
4793
        &&   (!iqentry_v[head1])
4794
        &&   (!iqentry_v[head2])
4795
        &&   (!iqentry_v[head3])
4796
        &&   (!iqentry_v[head4]))
4797
        )
4798
    && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4799
                ((!iqentry_v[head0])
4800
        &&   (!iqentry_v[head1])
4801
        &&   (!iqentry_v[head2])
4802
        &&   (!iqentry_v[head3])
4803
        &&   (!iqentry_v[head4])
4804
        &&   (!iqentry_v[head5]))
4805
        )
4806
    && (!(iqentry_v[head7] && iqentry_sync[head7]) ||
4807
                ((!iqentry_v[head0])
4808
        &&   (!iqentry_v[head1])
4809
        &&   (!iqentry_v[head2])
4810
        &&   (!iqentry_v[head3])
4811
        &&   (!iqentry_v[head4])
4812
        &&   (!iqentry_v[head5])
4813
        &&   (!iqentry_v[head6])
4814
        )
4815
        )
4816
    ) begin
4817
                iqentry_fcu_issue[head8] = `TRUE;
4818
        end
4819
    else if (could_issue[head9] && iqentry_fc[head9]
4820
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4821
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4822
                ((!iqentry_v[head0])
4823
        &&   (!iqentry_v[head1]))
4824
        )
4825
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4826
                ((!iqentry_v[head0])
4827
        &&   (!iqentry_v[head1])
4828
        &&   (!iqentry_v[head2]))
4829
        )
4830
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4831
                ((!iqentry_v[head0])
4832
        &&   (!iqentry_v[head1])
4833
        &&   (!iqentry_v[head2])
4834
        &&   (!iqentry_v[head3]))
4835
        )
4836
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4837
                ((!iqentry_v[head0])
4838
        &&   (!iqentry_v[head1])
4839
        &&   (!iqentry_v[head2])
4840
        &&   (!iqentry_v[head3])
4841
        &&   (!iqentry_v[head4]))
4842
        )
4843
    && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4844
                ((!iqentry_v[head0])
4845
        &&   (!iqentry_v[head1])
4846
        &&   (!iqentry_v[head2])
4847
        &&   (!iqentry_v[head3])
4848
        &&   (!iqentry_v[head4])
4849
        &&   (!iqentry_v[head5]))
4850
        )
4851
    && (!(iqentry_v[head7] && iqentry_sync[head7]) ||
4852
                ((!iqentry_v[head0])
4853
        &&   (!iqentry_v[head1])
4854
        &&   (!iqentry_v[head2])
4855
        &&   (!iqentry_v[head3])
4856
        &&   (!iqentry_v[head4])
4857
        &&   (!iqentry_v[head5])
4858
        &&   (!iqentry_v[head6]))
4859
        )
4860
    && (!(iqentry_v[head8] && iqentry_sync[head8]) ||
4861
                ((!iqentry_v[head0])
4862
        &&   (!iqentry_v[head1])
4863
        &&   (!iqentry_v[head2])
4864
        &&   (!iqentry_v[head3])
4865
        &&   (!iqentry_v[head4])
4866
        &&   (!iqentry_v[head5])
4867
        &&   (!iqentry_v[head6])
4868
        &&   (!iqentry_v[head7])
4869
        )
4870
        )
4871
    ) begin
4872
                iqentry_fcu_issue[head9] = `TRUE;
4873
        end
4874 48 robfinch
`endif
4875
        end
4876
end
4877
 
4878
//
4879
// determine if the instructions ready to issue can, in fact, issue.
4880
// "ready" means that the instruction has valid operands but has not gone yet
4881
reg [1:0] issue_count, missue_count;
4882
always @*
4883
begin
4884
        issue_count = 0;
4885
         memissue[ head0 ] =    iqentry_memready[ head0 ];              // first in line ... go as soon as ready
4886
         if (memissue[head0])
4887
                issue_count = issue_count + 1;
4888
 
4889
         memissue[ head1 ] =    ~iqentry_stomp[head1] && iqentry_memready[ head1 ]              // addr and data are valid
4890 49 robfinch
                                        && issue_count < `NUM_MEM
4891 48 robfinch
                                        // ... and no preceding instruction is ready to go
4892
                                        //&& ~iqentry_memready[head0]
4893
                                        // ... and there is no address-overlap with any preceding instruction
4894 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4895
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head1][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4896 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4897
                                        && (iqentry_rl[head1] ? iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0] : 1'b1)
4898
                                        // ... if a preivous op has the aquire bit set
4899
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4900
                                        // ... and, if it is a SW, there is no chance of it being undone
4901
                                        && (iqentry_load[head1] ||
4902
                                           !(iqentry_fc[head0]||iqentry_canex[head0]));
4903
         if (memissue[head1])
4904
                issue_count = issue_count + 1;
4905
 
4906
         memissue[ head2 ] =    ~iqentry_stomp[head2] && iqentry_memready[ head2 ]              // addr and data are valid
4907
                                        // ... and no preceding instruction is ready to go
4908 49 robfinch
                                        && issue_count < `NUM_MEM
4909 48 robfinch
                                        //&& ~iqentry_memready[head0]
4910
                                        //&& ~iqentry_memready[head1] 
4911
                                        // ... and there is no address-overlap with any preceding instruction
4912 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4913
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head2][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4914
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4915
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head2][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4916 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4917
                                        && (iqentry_rl[head2] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4918
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4919
                                                                                         : 1'b1)
4920
                                        // ... if a preivous op has the aquire bit set
4921
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4922
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4923
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4924 49 robfinch
            && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4925
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4926 48 robfinch
                                        // ... and, if it is a SW, there is no chance of it being undone
4927
                                        && (iqentry_load[head2] ||
4928
                                              !(iqentry_fc[head0]||iqentry_canex[head0])
4929
                                           && !(iqentry_fc[head1]||iqentry_canex[head1]));
4930
         if (memissue[head2])
4931
                issue_count = issue_count + 1;
4932
 
4933
         memissue[ head3 ] =    ~iqentry_stomp[head3] && iqentry_memready[ head3 ]              // addr and data are valid
4934
                                        // ... and no preceding instruction is ready to go
4935 49 robfinch
                                        && issue_count < `NUM_MEM
4936 48 robfinch
                                        //&& ~iqentry_memready[head0]
4937
                                        //&& ~iqentry_memready[head1] 
4938
                                        //&& ~iqentry_memready[head2] 
4939
                                        // ... and there is no address-overlap with any preceding instruction
4940 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4941
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4942
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4943
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4944
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])  || iqentry_done[head2]
4945
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4946 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4947
                                        && (iqentry_rl[head3] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4948
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4949
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4950
                                                                                         : 1'b1)
4951
                                        // ... if a preivous op has the aquire bit set
4952
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4953
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4954
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4955
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4956 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4957
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4958 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4959
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4960
                                )
4961 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4962
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4963 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4964
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4965
                                )
4966
                    // ... and, if it is a SW, there is no chance of it being undone
4967
                                        && (iqentry_load[head3] ||
4968
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4969
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4970
                       && !(iqentry_fc[head2]||iqentry_canex[head2]));
4971
         if (memissue[head3])
4972
                issue_count = issue_count + 1;
4973
 
4974
         memissue[ head4 ] =    ~iqentry_stomp[head4] && iqentry_memready[ head4 ]              // addr and data are valid
4975
                                        // ... and no preceding instruction is ready to go
4976 49 robfinch
                                        && issue_count < `NUM_MEM
4977 48 robfinch
                                        //&& ~iqentry_memready[head0]
4978
                                        //&& ~iqentry_memready[head1] 
4979
                                        //&& ~iqentry_memready[head2] 
4980
                                        //&& ~iqentry_memready[head3] 
4981
                                        // ... and there is no address-overlap with any preceding instruction
4982 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4983
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4984
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4985
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4986
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])  || iqentry_done[head2]
4987
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4988
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])  || iqentry_done[head3]
4989
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
4990 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4991
                                        && (iqentry_rl[head4] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4992
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4993
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4994
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4995
                                                                                         : 1'b1)
4996
                                        // ... if a preivous op has the aquire bit set
4997
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4998
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4999
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5000
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5001
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5002 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5003
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5004 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5005
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5006
                                )
5007 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5008 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5009
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5010
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5011
                                )
5012
                                && (!(iqentry_v[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5013 49 robfinch
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5014 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5015
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5016
                                )
5017 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5018 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5019
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5020
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5021
                                )
5022
                                        // ... and, if it is a SW, there is no chance of it being undone
5023
                                        && (iqentry_load[head4] ||
5024
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5025
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5026
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5027
                       && !(iqentry_fc[head3]||iqentry_canex[head3]));
5028
         if (memissue[head4])
5029
                issue_count = issue_count + 1;
5030
 
5031
         memissue[ head5 ] =    ~iqentry_stomp[head5] && iqentry_memready[ head5 ]              // addr and data are valid
5032
                                        // ... and no preceding instruction is ready to go
5033 49 robfinch
                                        && issue_count < `NUM_MEM
5034 48 robfinch
                                        //&& ~iqentry_memready[head0]
5035
                                        //&& ~iqentry_memready[head1] 
5036
                                        //&& ~iqentry_memready[head2] 
5037
                                        //&& ~iqentry_memready[head3] 
5038
                                        //&& ~iqentry_memready[head4] 
5039
                                        // ... and there is no address-overlap with any preceding instruction
5040 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
5041
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
5042
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
5043
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
5044
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
5045
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
5046
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
5047
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
5048
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
5049
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head4][AMSB:3] || iqentry_out[head4] || iqentry_done[head4])))
5050 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
5051
                                        && (iqentry_rl[head5] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
5052
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
5053
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
5054
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
5055
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
5056
                                                                                         : 1'b1)
5057
                                        // ... if a preivous op has the aquire bit set
5058
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
5059
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
5060
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5061
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5062
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
5063
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5064 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5065
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5066 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5067
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5068
                                )
5069 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5070 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5071
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5072
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5073
                                )
5074 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
5075 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5076
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5077
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5078
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
5079
                                )
5080 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5081
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5082 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5083
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5084
                                )
5085 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5086 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5087
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5088
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5089
                                )
5090 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
5091 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5092
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5093
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5094
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
5095
                                )
5096
                                        // ... and, if it is a SW, there is no chance of it being undone
5097
                                        && (iqentry_load[head5] ||
5098
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5099
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5100
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5101
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5102
                       && !(iqentry_fc[head4]||iqentry_canex[head4]));
5103
         if (memissue[head5])
5104
                issue_count = issue_count + 1;
5105
 
5106
`ifdef FULL_ISSUE_LOGIC
5107
         memissue[ head6 ] =    ~iqentry_stomp[head6] && iqentry_memready[ head6 ]              // addr and data are valid
5108
                                        // ... and no preceding instruction is ready to go
5109 49 robfinch
                                        && issue_count < `NUM_MEM
5110 48 robfinch
                                        //&& ~iqentry_memready[head0]
5111
                                        //&& ~iqentry_memready[head1] 
5112
                                        //&& ~iqentry_memready[head2] 
5113
                                        //&& ~iqentry_memready[head3] 
5114
                                        //&& ~iqentry_memready[head4] 
5115
                                        //&& ~iqentry_memready[head5] 
5116
                                        // ... and there is no address-overlap with any preceding instruction
5117 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
5118 53 robfinch
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head0][AMSB:3])))
5119 52 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
5120 53 robfinch
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head1][AMSB:3])))
5121 52 robfinch
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
5122 53 robfinch
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head2][AMSB:3])))
5123 52 robfinch
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
5124 53 robfinch
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head3][AMSB:3])))
5125 52 robfinch
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
5126 53 robfinch
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head4][AMSB:3])))
5127 52 robfinch
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5]) || iqentry_done[head5]
5128 53 robfinch
                                                || (iqentry_a1_v[head5] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head5][AMSB:3])))
5129 48 robfinch
                                        && (iqentry_rl[head6] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
5130
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
5131
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
5132
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
5133
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
5134
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
5135
                                                                                         : 1'b1)
5136
                                        // ... if a preivous op has the aquire bit set
5137
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
5138
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
5139
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5140
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5141
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
5142
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
5143
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5144 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5145
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5146 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5147
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5148
                                )
5149 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5150 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5151
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5152
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5153
                                )
5154 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
5155 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5156
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5157
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5158
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
5159
                                )
5160 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
5161 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5162
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5163
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5164
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5165
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
5166
                                )
5167 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5168
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5169 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5170
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5171
                                )
5172 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5173 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5174
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5175
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5176
                                )
5177 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
5178 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5179
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5180
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5181
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
5182
                                )
5183 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
5184 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5185
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5186
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5187
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5188
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
5189
                                )
5190
                                        // ... and, if it is a SW, there is no chance of it being undone
5191
                                        && (iqentry_load[head6] ||
5192
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5193
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5194
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5195
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5196
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
5197
                       && !(iqentry_fc[head5]||iqentry_canex[head5]));
5198
         if (memissue[head6])
5199
                issue_count = issue_count + 1;
5200
 
5201
         memissue[ head7 ] =    ~iqentry_stomp[head7] && iqentry_memready[ head7 ]              // addr and data are valid
5202
                                        // ... and no preceding instruction is ready to go
5203 49 robfinch
                                        && issue_count < `NUM_MEM
5204 48 robfinch
                                        //&& ~iqentry_memready[head0]
5205
                                        //&& ~iqentry_memready[head1] 
5206
                                        //&& ~iqentry_memready[head2] 
5207
                                        //&& ~iqentry_memready[head3] 
5208
                                        //&& ~iqentry_memready[head4] 
5209
                                        //&& ~iqentry_memready[head5] 
5210
                                        //&& ~iqentry_memready[head6] 
5211
                                        // ... and there is no address-overlap with any preceding instruction
5212 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
5213
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
5214
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
5215
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
5216
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
5217
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
5218
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
5219
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
5220
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
5221
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head4][AMSB:3] || iqentry_out[head4] || iqentry_done[head4])))
5222
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5]) || iqentry_done[head5]
5223
                                                || (iqentry_a1_v[head5] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head5][AMSB:3] || iqentry_out[head5] || iqentry_done[head5])))
5224
                                        && (!iqentry_mem[head6] || (iqentry_agen[head6] & iqentry_out[head6]) || iqentry_done[head6]
5225
                                                || (iqentry_a1_v[head6] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head6][AMSB:3] || iqentry_out[head6] || iqentry_done[head6])))
5226 48 robfinch
                                        && (iqentry_rl[head7] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
5227
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
5228
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
5229
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
5230
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
5231
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
5232
                                                                                 && (iqentry_done[head6] || !iqentry_v[head6] || !iqentry_mem[head6])
5233
                                                                                         : 1'b1)
5234
                                        // ... if a preivous op has the aquire bit set
5235
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
5236
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
5237
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5238
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5239
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
5240
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
5241
                                        && !(iqentry_aq[head6] && iqentry_v[head6])
5242
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5243 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5244
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5245 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5246
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5247
                                )
5248 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5249 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5250
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5251
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5252
                                )
5253 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
5254 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5255
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5256
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5257
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
5258
                                )
5259 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
5260 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5261
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5262
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5263
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5264
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
5265
                                )
5266 49 robfinch
                    && (!(iqentry_iv[head6] && iqentry_memsb[head6]) ||
5267 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5268
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5269
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5270
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5271
                                &&   (iqentry_done[head4] || !iqentry_v[head4])
5272
                                &&   (iqentry_done[head5] || !iqentry_v[head5]))
5273
                                )
5274 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5275
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5276 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5277
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5278
                                )
5279 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5280 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5281
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5282
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5283
                                )
5284 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
5285 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5286
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5287
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5288
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
5289
                                )
5290 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
5291 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5292
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5293
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5294
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5295
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
5296
                                )
5297 49 robfinch
                    && (!(iqentry_iv[head6] && iqentry_memdb[head6]) ||
5298 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5299
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5300
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5301
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5302
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4])
5303
                                && (!iqentry_mem[head5] || iqentry_done[head5] || !iqentry_v[head5]))
5304
                                )
5305
                                        // ... and, if it is a SW, there is no chance of it being undone
5306
                                        && (iqentry_load[head7] ||
5307
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5308
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5309
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5310
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5311
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
5312
                       && !(iqentry_fc[head5]||iqentry_canex[head5])
5313
                       && !(iqentry_fc[head6]||iqentry_canex[head6]));
5314 59 robfinch
 
5315
         memissue[ head8 ] =    ~iqentry_stomp[head8] && iqentry_memready[ head8 ]              // addr and data are valid
5316
                                        // ... and no preceding instruction is ready to go
5317
                                        && issue_count < `NUM_MEM
5318
                                        //&& ~iqentry_memready[head0]
5319
                                        //&& ~iqentry_memready[head1] 
5320
                                        //&& ~iqentry_memready[head2] 
5321
                                        //&& ~iqentry_memready[head3] 
5322
                                        //&& ~iqentry_memready[head4] 
5323
                                        //&& ~iqentry_memready[head5] 
5324
                                        //&& ~iqentry_memready[head6] 
5325
                                        // ... and there is no address-overlap with any preceding instruction
5326
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
5327
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head8][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
5328
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
5329
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head8][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
5330
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
5331
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head8][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
5332
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
5333
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head8][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
5334
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
5335
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head8][AMSB:3] != iqentry_a1[head4][AMSB:3] || iqentry_out[head4] || iqentry_done[head4])))
5336
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5]) || iqentry_done[head5]
5337
                                                || (iqentry_a1_v[head5] && (iqentry_a1[head8][AMSB:3] != iqentry_a1[head5][AMSB:3] || iqentry_out[head5] || iqentry_done[head5])))
5338
                                        && (!iqentry_mem[head6] || (iqentry_agen[head6] & iqentry_out[head6]) || iqentry_done[head6]
5339
                                                || (iqentry_a1_v[head6] && (iqentry_a1[head8][AMSB:3] != iqentry_a1[head6][AMSB:3] || iqentry_out[head6] || iqentry_done[head6])))
5340
                                        && (!iqentry_mem[head7] || (iqentry_agen[head7] & iqentry_out[head7]) || iqentry_done[head7]
5341
                                                || (iqentry_a1_v[head7] && (iqentry_a1[head8][AMSB:3] != iqentry_a1[head7][AMSB:3] || iqentry_out[head7] || iqentry_done[head7])))
5342
                                        && (iqentry_rl[head8] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
5343
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
5344
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
5345
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
5346
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
5347
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
5348
                                                                                 && (iqentry_done[head6] || !iqentry_v[head6] || !iqentry_mem[head6])
5349
                                                                                 && (iqentry_done[head7] || !iqentry_v[head7] || !iqentry_mem[head7])
5350
                                                                                         : 1'b1)
5351
                                        // ... if a preivous op has the aquire bit set
5352
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
5353
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
5354
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5355
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5356
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
5357
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
5358
                                        && !(iqentry_aq[head6] && iqentry_v[head6])
5359
                                        && !(iqentry_aq[head7] && iqentry_v[head7])
5360
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5361
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5362
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5363
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5364
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5365
                                )
5366
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5367
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5368
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5369
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5370
                                )
5371
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
5372
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5373
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5374
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5375
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
5376
                                )
5377
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
5378
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5379
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5380
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5381
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5382
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
5383
                                )
5384
                    && (!(iqentry_iv[head6] && iqentry_memsb[head6]) ||
5385
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5386
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5387
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5388
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5389
                                &&   (iqentry_done[head4] || !iqentry_v[head4])
5390
                                &&   (iqentry_done[head5] || !iqentry_v[head5]))
5391
                                )
5392
                    && (!(iqentry_iv[head7] && iqentry_memsb[head7]) ||
5393
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5394
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5395
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5396
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5397
                                &&   (iqentry_done[head4] || !iqentry_v[head4])
5398
                                &&   (iqentry_done[head5] || !iqentry_v[head5])
5399
                                &&   (iqentry_done[head6] || !iqentry_v[head6])
5400
                                )
5401
                                )
5402
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5403
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5404
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5405
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5406
                                )
5407
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5408
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5409
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5410
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5411
                                )
5412
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
5413
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5414
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5415
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5416
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
5417
                                )
5418
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
5419
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5420
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5421
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5422
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5423
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
5424
                                )
5425
                    && (!(iqentry_iv[head6] && iqentry_memdb[head6]) ||
5426
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5427
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5428
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5429
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5430
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4])
5431
                                && (!iqentry_mem[head5] || iqentry_done[head5] || !iqentry_v[head5]))
5432
                                )
5433
                    && (!(iqentry_iv[head7] && iqentry_memdb[head7]) ||
5434
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5435
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5436
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5437
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5438
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4])
5439
                                && (!iqentry_mem[head5] || iqentry_done[head5] || !iqentry_v[head5])
5440
                                && (!iqentry_mem[head6] || iqentry_done[head6] || !iqentry_v[head6])
5441
                                )
5442
                                )
5443
                                        // ... and, if it is a SW, there is no chance of it being undone
5444
                                        && (iqentry_load[head8] ||
5445
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5446
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5447
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5448
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5449
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
5450
                       && !(iqentry_fc[head5]||iqentry_canex[head5])
5451
                       && !(iqentry_fc[head6]||iqentry_canex[head6])
5452
                       && !(iqentry_fc[head7]||iqentry_canex[head7])
5453
                       );
5454
         memissue[ head9 ] =    ~iqentry_stomp[head9] && iqentry_memready[ head9 ]              // addr and data are valid
5455
                                        // ... and no preceding instruction is ready to go
5456
                                        && issue_count < `NUM_MEM
5457
                                        //&& ~iqentry_memready[head0]
5458
                                        //&& ~iqentry_memready[head1] 
5459
                                        //&& ~iqentry_memready[head2] 
5460
                                        //&& ~iqentry_memready[head3] 
5461
                                        //&& ~iqentry_memready[head4] 
5462
                                        //&& ~iqentry_memready[head5] 
5463
                                        //&& ~iqentry_memready[head6] 
5464
                                        // ... and there is no address-overlap with any preceding instruction
5465
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
5466
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head9][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
5467
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
5468
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head9][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
5469
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
5470
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head9][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
5471
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
5472
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head9][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
5473
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
5474
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head9][AMSB:3] != iqentry_a1[head4][AMSB:3] || iqentry_out[head4] || iqentry_done[head4])))
5475
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5]) || iqentry_done[head5]
5476
                                                || (iqentry_a1_v[head5] && (iqentry_a1[head9][AMSB:3] != iqentry_a1[head5][AMSB:3] || iqentry_out[head5] || iqentry_done[head5])))
5477
                                        && (!iqentry_mem[head6] || (iqentry_agen[head6] & iqentry_out[head6]) || iqentry_done[head6]
5478
                                                || (iqentry_a1_v[head6] && (iqentry_a1[head9][AMSB:3] != iqentry_a1[head6][AMSB:3] || iqentry_out[head6] || iqentry_done[head6])))
5479
                                        && (!iqentry_mem[head7] || (iqentry_agen[head7] & iqentry_out[head7]) || iqentry_done[head7]
5480
                                                || (iqentry_a1_v[head7] && (iqentry_a1[head9][AMSB:3] != iqentry_a1[head7][AMSB:3] || iqentry_out[head7] || iqentry_done[head7])))
5481
                                        && (!iqentry_mem[head8] || (iqentry_agen[head8] & iqentry_out[head8]) || iqentry_done[head8]
5482
                                                || (iqentry_a1_v[head8] && (iqentry_a1[head9][AMSB:3] != iqentry_a1[head8][AMSB:3] || iqentry_out[head8] || iqentry_done[head8])))
5483
                                        && (iqentry_rl[head9] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
5484
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
5485
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
5486
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
5487
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
5488
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
5489
                                                                                 && (iqentry_done[head6] || !iqentry_v[head6] || !iqentry_mem[head6])
5490
                                                                                 && (iqentry_done[head7] || !iqentry_v[head7] || !iqentry_mem[head7])
5491
                                                                                 && (iqentry_done[head8] || !iqentry_v[head8] || !iqentry_mem[head8])
5492
                                                                                         : 1'b1)
5493
                                        // ... if a preivous op has the aquire bit set
5494
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
5495
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
5496
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5497
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5498
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
5499
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
5500
                                        && !(iqentry_aq[head6] && iqentry_v[head6])
5501
                                        && !(iqentry_aq[head7] && iqentry_v[head7])
5502
                                        && !(iqentry_aq[head8] && iqentry_v[head8])
5503
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5504
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5505
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5506
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5507
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5508
                                )
5509
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5510
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5511
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5512
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5513
                                )
5514
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
5515
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5516
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5517
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5518
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
5519
                                )
5520
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
5521
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5522
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5523
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5524
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5525
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
5526
                                )
5527
                    && (!(iqentry_iv[head6] && iqentry_memsb[head6]) ||
5528
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5529
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5530
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5531
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5532
                                &&   (iqentry_done[head4] || !iqentry_v[head4])
5533
                                &&   (iqentry_done[head5] || !iqentry_v[head5]))
5534
                                )
5535
                    && (!(iqentry_iv[head7] && iqentry_memsb[head7]) ||
5536
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5537
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5538
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5539
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5540
                                &&   (iqentry_done[head4] || !iqentry_v[head4])
5541
                                &&   (iqentry_done[head5] || !iqentry_v[head5])
5542
                                &&   (iqentry_done[head6] || !iqentry_v[head6]))
5543
                                )
5544
                    && (!(iqentry_iv[head8] && iqentry_memsb[head8]) ||
5545
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5546
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5547
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5548
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5549
                                &&   (iqentry_done[head4] || !iqentry_v[head4])
5550
                                &&   (iqentry_done[head5] || !iqentry_v[head5])
5551
                                &&   (iqentry_done[head6] || !iqentry_v[head6])
5552
                                &&   (iqentry_done[head7] || !iqentry_v[head7])
5553
                                )
5554
                                )
5555
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5556
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5557
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5558
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5559
                                )
5560
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5561
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5562
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5563
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5564
                                )
5565
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
5566
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5567
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5568
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5569
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
5570
                                )
5571
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
5572
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5573
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5574
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5575
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5576
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
5577
                                )
5578
                    && (!(iqentry_iv[head6] && iqentry_memdb[head6]) ||
5579
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5580
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5581
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5582
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5583
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4])
5584
                                && (!iqentry_mem[head5] || iqentry_done[head5] || !iqentry_v[head5]))
5585
                                )
5586
                    && (!(iqentry_iv[head7] && iqentry_memdb[head7]) ||
5587
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5588
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5589
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5590
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5591
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4])
5592
                                && (!iqentry_mem[head5] || iqentry_done[head5] || !iqentry_v[head5])
5593
                                && (!iqentry_mem[head6] || iqentry_done[head6] || !iqentry_v[head6]))
5594
                                )
5595
                    && (!(iqentry_iv[head8] && iqentry_memdb[head8]) ||
5596
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5597
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5598
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5599
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5600
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4])
5601
                                && (!iqentry_mem[head5] || iqentry_done[head5] || !iqentry_v[head5])
5602
                                && (!iqentry_mem[head6] || iqentry_done[head6] || !iqentry_v[head6])
5603
                                && (!iqentry_mem[head7] || iqentry_done[head7] || !iqentry_v[head7])
5604
                                )
5605
                                )
5606
                                        // ... and, if it is a SW, there is no chance of it being undone
5607
                                        && (iqentry_load[head9] ||
5608
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5609
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5610
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5611
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5612
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
5613
                       && !(iqentry_fc[head5]||iqentry_canex[head5])
5614
                       && !(iqentry_fc[head6]||iqentry_canex[head6])
5615
                       && !(iqentry_fc[head7]||iqentry_canex[head7])
5616
                       && !(iqentry_fc[head8]||iqentry_canex[head8])
5617
                       );
5618 48 robfinch
`endif
5619
end
5620
 
5621 49 robfinch
reg [2:0] wbptr;
5622
always @*
5623
begin
5624
        // Crashes sim
5625
//      wbptr <= `WB_DEPTH-1;
5626
//      if (wb_v==8'h0)
5627
//              wbptr <= 3'd0;
5628
//      else
5629
//      begin
5630
//              for (n = `WB_DEPTH-2; n >= 0; n = n - 1)
5631
//                      if (wb_v[n] && wbptr==`WB_DEPTH-1)
5632
//                              wbptr <= n + 1;
5633
//      end
5634
        if (wb_v[6])
5635
                wbptr <= 3'd7;
5636
        else if (wb_v[5])
5637
                wbptr <= 3'd6;
5638
        else if (wb_v[4])
5639
                wbptr <= 3'd5;
5640
        else if (wb_v[3])
5641
                wbptr <= 3'd4;
5642
        else if (wb_v[2])
5643
                wbptr <= 3'd3;
5644
        else if (wb_v[1])
5645
                wbptr <= 3'd2;
5646
        else if (wb_v[0])
5647
                wbptr <= 3'd1;
5648
        else
5649
                wbptr <= 3'd0;
5650
end
5651
 
5652 48 robfinch
// Stomp logic for branch miss.
5653
 
5654
FT64_stomp #(QENTRIES) ustmp1
5655
(
5656
        .branchmiss(branchmiss),
5657
        .branchmiss_thrd(branchmiss_thrd),
5658
        .missid(missid),
5659
        .head0(head0),
5660
        .thrd(iqentry_thrd),
5661
        .iqentry_v(iqentry_v),
5662
        .stomp(iqentry_stomp)
5663
);
5664
 
5665
always @*
5666
begin
5667 51 robfinch
        if (iqentry_stomp[0] && iqentry_ret[0])
5668 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5669 51 robfinch
        if (iqentry_stomp[1] && iqentry_ret[1])
5670 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5671 51 robfinch
        if (iqentry_stomp[2] && iqentry_ret[2])
5672 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5673 51 robfinch
        if (iqentry_stomp[3] && iqentry_ret[3])
5674 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5675 51 robfinch
        if (iqentry_stomp[4] && iqentry_ret[4])
5676 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5677 51 robfinch
        if (iqentry_stomp[5] && iqentry_ret[5])
5678 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5679 51 robfinch
        if (iqentry_stomp[6] && iqentry_ret[6])
5680 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5681 51 robfinch
        if (iqentry_stomp[7] && iqentry_ret[7])
5682 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5683 52 robfinch
        if (iqentry_stomp[8] && iqentry_ret[8])
5684
                stompedOnRets = stompedOnRets + 4'd1;
5685
        if (iqentry_stomp[9] && iqentry_ret[9])
5686
                stompedOnRets = stompedOnRets + 4'd1;
5687 48 robfinch
end
5688
 
5689 49 robfinch
reg id1_vi, id2_vi, id3_vi;
5690
wire [4:0] id1_ido, id2_ido, id3_ido;
5691
wire id1_vo, id2_vo, id3_vo;
5692
wire id1_clk, id2_clk, id3_clk;
5693 48 robfinch
 
5694 49 robfinch
// Always at least one decoder
5695 50 robfinch
assign id1_clk = clk_i;
5696
//BUFGCE uclkb2
5697
//(
5698
//      .I(clk_i),
5699
//      .CE(id1_available),
5700
//      .O(id1_clk)
5701
//);
5702 48 robfinch
 
5703
FT64_idecoder uid1
5704
(
5705
        .clk(id1_clk),
5706
        .idv_i(id1_vi),
5707
        .id_i(id1_id),
5708
        .instr(id1_instr),
5709
        .ven(id1_ven),
5710
        .vl(id1_vl),
5711
        .thrd(id1_thrd),
5712
        .predict_taken(id1_pt),
5713
        .Rt(id1_Rt),
5714
        .bus(id1_bus),
5715
        .id_o(id1_ido),
5716
        .idv_o(id1_vo)
5717
);
5718
 
5719 49 robfinch
generate begin : gIDUInst
5720
if (`NUM_IDU > 1) begin
5721 50 robfinch
//BUFGCE uclkb3
5722
//(
5723
//      .I(clk_i),
5724
//      .CE(id2_available),
5725
//      .O(id2_clk)
5726
//);
5727
assign id2_clk = clk_i;
5728 48 robfinch
 
5729
FT64_idecoder uid2
5730
(
5731
        .clk(id2_clk),
5732
        .idv_i(id2_vi),
5733
        .id_i(id2_id),
5734
        .instr(id2_instr),
5735
        .ven(id2_ven),
5736
        .vl(id2_vl),
5737
        .thrd(id2_thrd),
5738
        .predict_taken(id2_pt),
5739
        .Rt(id2_Rt),
5740
        .bus(id2_bus),
5741
        .id_o(id2_ido),
5742
        .idv_o(id2_vo)
5743
);
5744 49 robfinch
end
5745
if (`NUM_IDU > 2) begin
5746 50 robfinch
//BUFGCE uclkb4
5747
//(
5748
//      .I(clk_i),
5749
//      .CE(id3_available),
5750
//      .O(id3_clk)
5751
//);
5752
assign id3_clk = clk_i;
5753 48 robfinch
 
5754 49 robfinch
FT64_idecoder uid2
5755
(
5756
        .clk(id3_clk),
5757
        .idv_i(id3_vi),
5758
        .id_i(id3_id),
5759
        .instr(id3_instr),
5760
        .ven(id3_ven),
5761
        .vl(id3_vl),
5762
        .thrd(id3_thrd),
5763
        .predict_taken(id3_pt),
5764
        .Rt(id3_Rt),
5765
        .bus(id3_bus),
5766
        .id_o(id3_ido),
5767
        .idv_o(id3_vo)
5768
);
5769
end
5770
end
5771
endgenerate
5772
 
5773 48 robfinch
//
5774
// EXECUTE
5775
//
5776
reg [63:0] csr_r;
5777
always @*
5778
    read_csr(alu0_instr[29:18],csr_r,alu0_thrd);
5779
FT64_alu #(.BIG(1'b1),.SUP_VECTOR(SUP_VECTOR)) ualu0 (
5780
  .rst(rst),
5781
  .clk(clk),
5782
  .ld(alu0_ld),
5783
  .abort(1'b0),
5784
  .instr(alu0_instr),
5785
  .a(alu0_argA),
5786
  .b(alu0_argB),
5787
  .c(alu0_argC),
5788
  .pc(alu0_pc),
5789
//    .imm(alu0_argI),
5790
  .tgt(alu0_tgt),
5791
  .ven(alu0_ven),
5792
  .vm(vm[alu0_instr[25:23]]),
5793
  .sbl(sbl),
5794
  .sbu(sbu),
5795
  .csr(csr_r),
5796
  .o(alu0_bus),
5797
  .ob(alu0b_bus),
5798
  .done(alu0_done),
5799
  .idle(alu0_idle),
5800
  .excen(aec[4:0]),
5801
  .exc(alu0_exc),
5802
  .thrd(alu0_thrd),
5803
  .mem(alu0_mem),
5804
  .shift48(alu0_shft48)
5805
);
5806 49 robfinch
generate begin : gAluInst
5807
if (`NUM_ALU > 1) begin
5808 48 robfinch
FT64_alu #(.BIG(1'b0),.SUP_VECTOR(SUP_VECTOR)) ualu1 (
5809
  .rst(rst),
5810
  .clk(clk),
5811
  .ld(alu1_ld),
5812
  .abort(1'b0),
5813
  .instr(alu1_instr),
5814
  .a(alu1_argA),
5815
  .b(alu1_argB),
5816
  .c(alu1_argC),
5817
  .pc(alu1_pc),
5818
  //.imm(alu1_argI),
5819
  .tgt(alu1_tgt),
5820
  .ven(alu1_ven),
5821
  .vm(vm[alu1_instr[25:23]]),
5822
  .sbl(sbl),
5823
  .sbu(sbu),
5824
  .csr(64'd0),
5825
  .o(alu1_bus),
5826
  .ob(alu1b_bus),
5827
  .done(alu1_done),
5828
  .idle(alu1_idle),
5829
  .excen(aec[4:0]),
5830
  .exc(alu1_exc),
5831
  .thrd(1'b0),
5832
  .mem(alu1_mem),
5833
  .shift48(alu1_shft48)
5834
);
5835 49 robfinch
end
5836
end
5837
endgenerate
5838
 
5839
generate begin : gFPUInst
5840
if (`NUM_FPU > 0) begin
5841
wire fpu1_clk;
5842 50 robfinch
//BUFGCE ufpc1
5843
//(
5844
//      .I(clk_i),
5845
//      .CE(fpu1_available),
5846
//      .O(fpu1_clk)
5847
//);
5848
assign fpu1_clk = clk_i;
5849
 
5850 48 robfinch
fpUnit ufp1
5851
(
5852
  .rst(rst),
5853 49 robfinch
  .clk(fpu1_clk),
5854 48 robfinch
  .clk4x(clk4x),
5855
  .ce(1'b1),
5856 49 robfinch
  .ir(fpu1_instr),
5857
  .ld(fpu1_ld),
5858
  .a(fpu1_argA),
5859
  .b(fpu1_argB),
5860
  .imm(fpu1_argI),
5861
  .o(fpu1_bus),
5862 48 robfinch
  .csr_i(),
5863 52 robfinch
  .status(fpu1_status),
5864 48 robfinch
  .exception(),
5865 49 robfinch
  .done(fpu1_done)
5866 48 robfinch
);
5867 49 robfinch
end
5868
if (`NUM_FPU > 1) begin
5869
wire fpu2_clk;
5870 50 robfinch
//BUFGCE ufpc2
5871
//(
5872
//      .I(clk_i),
5873
//      .CE(fpu2_available),
5874
//      .O(fpu2_clk)
5875
//);
5876
assign fpu2_clk = clk_i;
5877 49 robfinch
fpUnit ufp1
5878
(
5879
  .rst(rst),
5880
  .clk(fpu2_clk),
5881
  .clk4x(clk4x),
5882
  .ce(1'b1),
5883
  .ir(fpu2_instr),
5884
  .ld(fpu2_ld),
5885
  .a(fpu2_argA),
5886
  .b(fpu2_argB),
5887
  .imm(fpu2_argI),
5888
  .o(fpu2_bus),
5889
  .csr_i(),
5890 52 robfinch
  .status(fpu2_status),
5891 49 robfinch
  .exception(),
5892
  .done(fpu2_done)
5893
);
5894
end
5895
end
5896
endgenerate
5897 48 robfinch
 
5898 52 robfinch
assign fpu1_exc = (fpu1_available) ?
5899
                                                                        ((|fpu1_status[15:0]) ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
5900
assign fpu2_exc = (fpu2_available) ?
5901
                                                                        ((|fpu2_status[15:0]) ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
5902 49 robfinch
 
5903 48 robfinch
assign  alu0_v = alu0_dataready,
5904
        alu1_v = alu1_dataready;
5905
assign  alu0_id = alu0_sourceid,
5906
            alu1_id = alu1_sourceid;
5907 49 robfinch
assign  fpu1_v = fpu1_dataready;
5908
assign  fpu1_id = fpu1_sourceid;
5909
assign  fpu2_v = fpu2_dataready;
5910
assign  fpu2_id = fpu2_sourceid;
5911 48 robfinch
 
5912
`ifdef SUPPORT_SMT
5913
wire [1:0] olm = ol[fcu_thrd];
5914
`else
5915
wire [1:0] olm = ol;
5916
`endif
5917
 
5918
assign  fcu_v = fcu_dataready;
5919
assign  fcu_id = fcu_sourceid;
5920
 
5921
wire [4:0] fcmpo;
5922
wire fnanx;
5923
fp_cmp_unit ufcmp1 (fcu_argA, fcu_argB, fcmpo, fnanx);
5924
 
5925
wire fcu_takb;
5926
 
5927
always @*
5928
begin
5929
    fcu_exc <= `FLT_NONE;
5930
    casez(fcu_instr[`INSTRUCTION_OP])
5931
    `CHK:   begin
5932
                if (fcu_instr[21])
5933
                    fcu_exc <= fcu_argA >= fcu_argB && fcu_argA < fcu_argC ? `FLT_NONE : `FLT_CHK;
5934
            end
5935
    `REX:
5936
        case(olm)
5937
        `OL_USER:   fcu_exc <= `FLT_PRIV;
5938
        default:    ;
5939
        endcase
5940
        endcase
5941
end
5942
 
5943
FT64_EvalBranch ube1
5944
(
5945
        .instr(fcu_instr),
5946
        .a(fcu_argA),
5947
        .b(fcu_argB),
5948
        .c(fcu_argC),
5949
        .takb(fcu_takb)
5950
);
5951
 
5952
FT64_FCU_Calc ufcuc1
5953
(
5954
        .ol(olm),
5955
        .instr(fcu_instr),
5956
        .tvec(tvec[fcu_instr[14:13]]),
5957
        .a(fcu_argA),
5958
        .i(fcu_argI),
5959
        .pc(fcu_pc),
5960
        .im(im),
5961
        .waitctr(waitctr),
5962
        .bus(fcu_bus)
5963
);
5964
 
5965
always @*
5966
begin
5967
case(fcu_instr[`INSTRUCTION_OP])
5968
`R2:    fcu_misspc = fcu_argB;  // RTI (we don't bother fully decoding this as it's the only R2)
5969
`RET:   fcu_misspc = fcu_argB;
5970
`REX:   fcu_misspc = fcu_bus;
5971
`BRK:   fcu_misspc = {tvec[0][31:8], 1'b0, olm, 5'h0};
5972
`JAL:   fcu_misspc = fcu_argA + fcu_argI;
5973
//`CHK: fcu_misspc = fcu_nextpc + fcu_argI;     // Handled as an instruction exception
5974
// Default: branch
5975
default:        fcu_misspc = fcu_takb ? fcu_nextpc + fcu_brdisp : fcu_nextpc;
5976
endcase
5977
fcu_misspc[0] = 1'b0;
5978
end
5979
 
5980
// To avoid false branch mispredicts the branch isn't evaluated until the
5981
// following instruction queues. The address of the next instruction is
5982
// looked at to see if the BTB predicted correctly.
5983
 
5984 51 robfinch
wire fcu_brk_miss = (fcu_brk || fcu_rti) && fcu_v;
5985
wire fcu_ret_miss = fcu_ret && fcu_v && (fcu_argB != iqentry_pc[nid]);
5986
wire fcu_jal_miss = fcu_jal && fcu_v && fcu_argA + fcu_argI != iqentry_pc[nid];
5987 48 robfinch
wire fcu_followed = iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]];
5988
always @*
5989
if (fcu_dataready) begin
5990
//      if (fcu_timeout[7])
5991
//              fcu_branchmiss = TRUE;
5992
        // Break and RTI switch register sets, and so are always treated as a branch miss in order to
5993
        // flush the pipeline. Hardware interrupts also stream break instructions so they need to 
5994
        // flushed from the queue so the interrupt is recognized only once.
5995
        // BRK and RTI are handled as excmiss types which are processed during the commit stage.
5996
//      else
5997
        if (fcu_brk_miss)
5998
                fcu_branchmiss = TRUE & ~fcu_clearbm;
5999
    // the following instruction is queued
6000
        else
6001
        if (fcu_followed) begin
6002
`ifdef SUPPORT_SMT
6003
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol[fcu_thrd]) && fcu_v)
6004
`else
6005
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol) && fcu_v)
6006
`endif
6007
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
6008
                else if (fcu_ret_miss)
6009
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
6010 52 robfinch
                else if (fcu_branch && fcu_v && (((fcu_takb && (fcu_misspc != iqentry_pc[nid])) ||
6011
                                            (~fcu_takb && (fcu_pc + fcu_insln != iqentry_pc[nid])))))// || iqentry_v[nid]))
6012 48 robfinch
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
6013
                else if (fcu_jal_miss)
6014
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
6015
                else if (fcu_instr[`INSTRUCTION_OP] == `CHK && ~fcu_takb && fcu_v)
6016
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
6017
                else
6018
                    fcu_branchmiss = FALSE;
6019
        end
6020
        else begin
6021
                // Stuck at the head and can't finish because there's still an uncommitted instruction in the queue.
6022
                // -> cause a branch miss to clear the queue.
6023
                if (iqentry_v[nid] && !IsCall(fcu_instr) && !IsJmp(fcu_instr) && fcu_v)
6024
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
6025
                else
6026
                /*
6027
                if (fcu_id==head0 && iqentry_v[idp1(head0)]) begin
6028
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
6029
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
6030
                        fcu_branchmiss = FALSE;
6031
                    else
6032
                                fcu_branchmiss = TRUE;
6033
                end
6034
                else if (fcu_id==head1 && iqentry_v[idp2(head1)]) begin
6035
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
6036
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
6037
                        fcu_branchmiss = FALSE;
6038
                    else
6039
                                fcu_branchmiss = TRUE;
6040
                end
6041
                else*/
6042
                        fcu_branchmiss = FALSE;
6043
        end
6044
end
6045
else
6046
        fcu_branchmiss = FALSE;
6047
 
6048
// Flow control ops don't issue until the next instruction queues.
6049
// The fcu_timeout tracks how long the flow control op has been in the "out" state.
6050
// It should never be that way more than a couple of cycles. Sometimes the fcu_wr pulse got missed
6051
// because the following instruction got stomped on during a branchmiss, hence iqentry_v isn't true.
6052
wire fcu_wr = (fcu_v && iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]]);//      // && iqentry_v[nid]
6053
//                                      && fcu_instr==iqentry_instr[fcu_id[`QBITS]]);// || fcu_timeout==8'h05;
6054
 
6055
FT64_RMW_alu urmwalu0 (rmw_instr, rmw_argA, rmw_argB, rmw_argC, rmw_res);
6056
 
6057
//assign fcu_done = IsWait(fcu_instr) ? ((waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]]) :
6058
//                                      fcu_v && iqentry_v[idp1(fcu_id)] && iqentry_sn[idp1(fcu_id)]==iqentry_sn[fcu_id[`QBITS]]+5'd1;
6059
 
6060
// An exception in a committing instruction takes precedence
6061
/*
6062
Too slow. Needs to be registered
6063
assign  branchmiss = excmiss|fcu_branchmiss,
6064
    misspc = excmiss ? excmisspc : fcu_misspc,
6065
    missid = excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
6066
assign branchmiss_thrd =  excmiss ? excthrd : fcu_thrd;
6067
*/
6068
 
6069
//
6070
// additional DRAM-enqueue logic
6071
 
6072
assign dram_avail = (dram0 == `DRAMSLOT_AVAIL || dram1 == `DRAMSLOT_AVAIL || dram2 == `DRAMSLOT_AVAIL);
6073
 
6074 53 robfinch
always @*
6075
for (n = 0; n < QENTRIES; n = n + 1)
6076
        iqentry_memopsvalid[n] <= (iqentry_mem[n] & iqentry_a2_v[n] & iqentry_agen[n]);
6077 48 robfinch
 
6078 53 robfinch
always @*
6079
for (n = 0; n < QENTRIES; n = n + 1)
6080 59 robfinch
        iqentry_memready[n] <= (iqentry_v[n] & iqentry_iv[n] & iqentry_memopsvalid[n] & ~iqentry_memissue[n] & ~iqentry_done[n] & ~iqentry_out[n] & ~iqentry_stomp[n]);
6081 48 robfinch
 
6082 50 robfinch
assign outstanding_stores = (dram0 && dram0_store) ||
6083
                            (dram1 && dram1_store) ||
6084
                            (dram2 && dram2_store);
6085 48 robfinch
 
6086
//
6087
// additional COMMIT logic
6088
//
6089
always @*
6090
begin
6091
    commit0_v <= ({iqentry_v[head0], iqentry_cmt[head0]} == 2'b11 && ~|panic);
6092
    commit0_id <= {iqentry_mem[head0], head0};  // if a memory op, it has a DRAM-bus id
6093
    commit0_tgt <= iqentry_tgt[head0];
6094
    commit0_we  <= iqentry_we[head0];
6095
    commit0_bus <= iqentry_res[head0];
6096 49 robfinch
    if (`NUM_CMT > 1) begin
6097
            commit1_v <= ({iqentry_v[head0], iqentry_cmt[head0]} != 2'b10
6098
                       && {iqentry_v[head1], iqentry_cmt[head1]} == 2'b11
6099
                       && ~|panic);
6100
            commit1_id <= {iqentry_mem[head1], head1};
6101
            commit1_tgt <= iqentry_tgt[head1];
6102
            commit1_we  <= iqentry_we[head1];
6103
            commit1_bus <= iqentry_res[head1];
6104 58 robfinch
            // Need to set commit1, and commit2 valid bits for the branch predictor.
6105
            if (`NUM_CMT > 2) begin
6106
                end
6107
                else begin
6108
                        commit2_v <= ({iqentry_v[head0], iqentry_cmt[head0]} != 2'b10
6109
                                                                 && {iqentry_v[head1], iqentry_cmt[head1]} != 2'b10
6110
                                                                 && {iqentry_v[head2], iqentry_br[head2], iqentry_cmt[head2]}==3'b111
6111
                               && iqentry_tgt[head2][4:0]==5'd0 && ~|panic);     // watch out for dbnz and ibne
6112
                        commit2_tgt <= 12'h000;
6113
                        commit2_we <= 8'h00;
6114
                end
6115 49 robfinch
        end
6116
        else begin
6117 58 robfinch
                commit1_v <= ({iqentry_v[head0], iqentry_cmt[head0]} != 2'b10
6118
                                                         && {iqentry_v[head1], iqentry_br[head1], iqentry_cmt[head1]}==3'b111
6119
                       && iqentry_tgt[head1][4:0]==5'd0 && ~|panic);     // watch out for dbnz and ibne
6120 49 robfinch
                commit1_tgt <= 12'h000;
6121
                commit1_we <= 8'h00;
6122 58 robfinch
                commit2_v <= ({iqentry_v[head0], iqentry_cmt[head0]} != 2'b10
6123
                                                         && {iqentry_v[head1], iqentry_cmt[head1]} != 2'b10
6124
                                                         && {iqentry_v[head2], iqentry_br[head2], iqentry_cmt[head2]}==3'b111
6125
                       && iqentry_tgt[head2][4:0]==5'd0 && ~|panic);     // watch out for dbnz and ibne
6126
                commit2_tgt <= 12'h000;
6127
                commit2_we <= 8'h00;
6128 49 robfinch
        end
6129 48 robfinch
end
6130
 
6131 58 robfinch
assign int_commit = (commit0_v && iqentry_irq[head0])
6132
                                                                         || (commit0_v && commit1_v && iqentry_irq[head1] && `NUM_CMT > 1)
6133
                                                                         || (commit0_v && commit1_v && commit2_v && iqentry_irq[head2] && `NUM_CMT > 2);
6134 48 robfinch
 
6135
// Detect if a given register will become valid during the current cycle.
6136
// We want a signal that is active during the current clock cycle for the read
6137
// through register file, which trims a cycle off register access for every
6138
// instruction. But two different kinds of assignment statements can't be
6139
// placed under the same always block, it's a bad practice and may not work.
6140
// So a signal is created here with it's own always block.
6141
reg [AREGS-1:0] regIsValid;
6142
always @*
6143
begin
6144
        for (n = 1; n < AREGS; n = n + 1)
6145
        begin
6146
                regIsValid[n] = rf_v[n];
6147
                if (branchmiss)
6148
               if (~livetarget[n]) begin
6149
                        if (branchmiss_thrd) begin
6150
                                if (n >= 128)
6151
                                        regIsValid[n] = `VAL;
6152
                        end
6153
                        else begin
6154
                                if (n < 128)
6155
                                        regIsValid[n] = `VAL;
6156
                        end
6157
               end
6158
                if (commit0_v && n=={commit0_tgt[7:0]})
6159
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit0_tgt[7:0]} ] == commit0_id
6160
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit0_id[`QBITS] ]));
6161 49 robfinch
                if (commit1_v && n=={commit1_tgt[7:0]} && `NUM_CMT > 1)
6162 48 robfinch
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit1_tgt[7:0]} ] == commit1_id
6163 58 robfinch
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit1_id[`QBITS]] && iqentry_source[ commit1_id[`QBITS] ]));
6164
                if (commit2_v && n=={commit2_tgt[7:0]} && `NUM_CMT > 2)
6165
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit2_tgt[7:0]} ] == commit2_id
6166
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit2_id[`QBITS]] && iqentry_source[ commit2_id[`QBITS] ]));
6167 48 robfinch
        end
6168
        regIsValid[0] = `VAL;
6169 55 robfinch
        regIsValid[32] = `VAL;
6170
        regIsValid[64] = `VAL;
6171
        regIsValid[128] = `VAL;
6172
`ifdef SMT
6173
        regIsValid[144] = `VAL;
6174
        regIsValid[160] = `VAL;
6175
        regIsValid[192] = `VAL;
6176
        regIsValid[224] = `VAL;
6177
`endif
6178 48 robfinch
end
6179
 
6180
// Wait until the cycle after Ra becomes valid to give time to read
6181
// the vector element from the register file.
6182
reg rf_vra0, rf_vra1;
6183
/*always @(posedge clk)
6184
    rf_vra0 <= regIsValid[Ra0s];
6185
always @(posedge clk)
6186
    rf_vra1 <= regIsValid[Ra1s];
6187
*/
6188
// Check how many instructions can be queued. This might be fewer than the
6189
// number ready to queue from the fetch stage if queue slots aren't
6190
// available or if there are no more physical registers left for remapping.
6191
// The fetch stage needs to know how many instructions will queue so this
6192
// logic is placed here.
6193
// NOPs are filtered out and do not enter the instruction queue. The core
6194
// will stream NOPs on a cache miss and they would mess up the queue order
6195
// if there are immediate prefixes in the queue.
6196
// For the VEX instruction, the instruction can't queue until register Ra
6197
// is valid, because register Ra is used to specify the vector element to
6198
// read.
6199
wire q2open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV;
6200
wire q3open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV && iqentry_v[idp1(tail1)]==`INV;
6201
always @*
6202
begin
6203
        canq1 <= FALSE;
6204
        canq2 <= FALSE;
6205
        queued1 <= FALSE;
6206
        queued2 <= FALSE;
6207
        queuedNop <= FALSE;
6208
        vqueued2 <= FALSE;
6209
        if (!branchmiss) begin
6210
      // Two available
6211
      if (fetchbuf1_v & fetchbuf0_v) begin
6212
          // Is there a pair of NOPs ? (cache miss)
6213
          if ((fetchbuf0_instr[`INSTRUCTION_OP]==`NOP) && (fetchbuf1_instr[`INSTRUCTION_OP]==`NOP))
6214
              queuedNop <= TRUE;
6215
          else begin
6216
              // If it's a predicted branch queue only the first instruction, the second
6217
              // instruction will be stomped on.
6218
              if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
6219
                  if (iqentry_v[tail0]==`INV) begin
6220
                      canq1 <= TRUE;
6221
                      queued1 <= TRUE;
6222
                  end
6223
              end
6224
              // This is where a single NOP is allowed through to simplify the code. A
6225
              // single NOP can't be a cache miss. Otherwise it would be necessary to queue
6226
              // fetchbuf1 on tail0 it would add a nightmare to the enqueue code.
6227
              // Not a branch and there are two instructions fetched, see whether or not
6228
              // both instructions can be queued.
6229
              else begin
6230
                  if (iqentry_v[tail0]==`INV) begin
6231
                      canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
6232
                      queued1 <= (
6233
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
6234
                      if (iqentry_v[tail1]==`INV) begin
6235
                          canq2 <= ((!IsVex(fetchbuf1_instr) || rf_vra1)) || !SUP_VECTOR;
6236
                          queued2 <= (
6237
                                (!IsVector(fetchbuf1_instr) && (!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
6238
                          vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
6239
                      end
6240
                  end
6241
                  // If an irq is active during a vector instruction fetch, claim the vector instruction
6242
                  // is finished queueing even though it may not be. It'll pick up where it left off after
6243
                  // the exception is processed.
6244 52 robfinch
                  if (freezePC) begin
6245 48 robfinch
                        if (IsVector(fetchbuf0_instr) && IsVector(fetchbuf1_instr) && vechain) begin
6246
                                queued1 <= TRUE;
6247
                                queued2 <= TRUE;
6248
                        end
6249
                        else if (IsVector(fetchbuf0_instr)) begin
6250
                                queued1 <= TRUE;
6251
                                if (vqe0 < vl-2)
6252
                                        queued2 <= TRUE;
6253
                                else
6254
                                        queued2 <= iqentry_v[tail1]==`INV;
6255
                        end
6256
                  end
6257
              end
6258
          end
6259
      end
6260
      // One available
6261
      else if (fetchbuf0_v) begin
6262
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
6263
              if (iqentry_v[tail0]==`INV) begin
6264
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
6265
                  queued1 <=
6266
                        (((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
6267
              end
6268
              if (iqentry_v[tail1]==`INV) begin
6269
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
6270
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
6271
                end
6272 52 robfinch
                if (freezePC) begin
6273 48 robfinch
                if (IsVector(fetchbuf0_instr)) begin
6274
                        queued1 <= TRUE;
6275
                        if (vqe0 < vl-2)
6276
                                queued2 <= iqentry_v[tail1]==`INV;
6277
                end
6278
                end
6279
          end
6280
          else
6281
              queuedNop <= TRUE;
6282
      end
6283
      else if (fetchbuf1_v) begin
6284
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
6285
              if (iqentry_v[tail0]==`INV) begin
6286
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
6287
                  queued1 <= (
6288
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
6289
              end
6290
              if (iqentry_v[tail1]==`INV) begin
6291
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
6292
                  vqueued2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2;
6293
                end
6294 52 robfinch
                if (freezePC) begin
6295 48 robfinch
                if (IsVector(fetchbuf1_instr)) begin
6296
                        queued1 <= TRUE;
6297
                        if (vqe1 < vl-2)
6298
                                queued2 <= iqentry_v[tail1]==`INV;
6299
                end
6300
                end
6301
          end
6302
          else
6303
              queuedNop <= TRUE;
6304
      end
6305
      //else no instructions available to queue
6306
    end
6307
    else begin
6308
      // One available
6309
      if (fetchbuf0_v && fetchbuf0_thrd != branchmiss_thrd) begin
6310
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
6311
              if (iqentry_v[tail0]==`INV) begin
6312
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
6313
                  queued1 <= (
6314
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
6315
              end
6316
              if (iqentry_v[tail1]==`INV) begin
6317
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
6318
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
6319
                end
6320
          end
6321
          else
6322
              queuedNop <= TRUE;
6323
      end
6324
      else if (fetchbuf1_v && fetchbuf1_thrd != branchmiss_thrd) begin
6325
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
6326
              if (iqentry_v[tail0]==`INV) begin
6327
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
6328
                  queued1 <= (
6329
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
6330
              end
6331
              if (iqentry_v[tail1]==`INV) begin
6332
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
6333
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
6334
                end
6335
          end
6336
          else
6337
              queuedNop <= TRUE;
6338
      end
6339
        else
6340
                queuedNop <= TRUE;
6341
    end
6342
end
6343
 
6344
//
6345
// Branchmiss seems to be sticky sometimes during simulation. For instance branch miss
6346
// and cache miss at same time. The branchmiss should clear before the core continues
6347
// so the positive edge is detected to avoid incrementing the sequnce number too many
6348
// times.
6349
wire pebm;
6350
edge_det uedbm (.rst(rst), .clk(clk), .ce(1'b1), .i(branchmiss), .pe(pebm), .ne(), .ee() );
6351
 
6352
reg [5:0] ld_time;
6353
reg [63:0] wc_time_dat;
6354
reg [63:0] wc_times;
6355
always @(posedge tm_clk_i)
6356
begin
6357
        if (|ld_time)
6358
                wc_time <= wc_time_dat;
6359
        else begin
6360
                wc_time[31:0] <= wc_time[31:0] + 32'd1;
6361
                if (wc_time[31:0] >= TM_CLKFREQ-1) begin
6362
                        wc_time[31:0] <= 32'd0;
6363
                        wc_time[63:32] <= wc_time[63:32] + 32'd1;
6364
                end
6365
        end
6366
end
6367
 
6368
 
6369
// Monster clock domain.
6370
// Like to move some of this to clocking under different always blocks in order
6371
// to help out the toolset's synthesis, but it ain't gonna be easy.
6372
// Simulation doesn't like it if things are under separate always blocks.
6373
// Synthesis doesn't like it if things are under the same always block.
6374
 
6375 49 robfinch
//always @(posedge clk)
6376
//begin
6377
//      branchmiss <= excmiss|fcu_branchmiss;
6378
//    misspc <= excmiss ? excmisspc : fcu_misspc;
6379
//    missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
6380
//      branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
6381
//end
6382 48 robfinch
 
6383
always @(posedge clk)
6384
if (rst) begin
6385
`ifdef SUPPORT_SMT
6386 55 robfinch
     mstatus[0] <= 64'h000F;     // select register set #0 for thread 0
6387
     mstatus[1] <= 64'h800F;    // select register set #2 for thread 1
6388 48 robfinch
`else
6389 55 robfinch
     mstatus <= 64'h000F;       // select register set #0 for thread 0
6390 48 robfinch
`endif
6391
    for (n = 0; n < QENTRIES; n = n + 1) begin
6392 51 robfinch
       iqentry_v[n] <= `INV;
6393
       iqentry_iv[n] <= `INV;
6394
       iqentry_is[n] <= 3'b00;
6395
       iqentry_done[n] <= FALSE;
6396
       iqentry_cmt[n] <= FALSE;
6397
       iqentry_out[n] <= FALSE;
6398
       iqentry_agen[n] <= FALSE;
6399
       iqentry_sn[n] <= 32'd0;
6400
       iqentry_pt[n] <= FALSE;
6401
       iqentry_bt[n] <= FALSE;
6402
       iqentry_br[n] <= FALSE;
6403
       iqentry_aq[n] <= FALSE;
6404
       iqentry_rl[n] <= FALSE;
6405
       iqentry_alu0[n] <= FALSE;
6406
       iqentry_alu[n] <= FALSE;
6407
       iqentry_alu0_issue[n] <= FALSE;
6408
       iqentry_alu1_issue[n] <= FALSE;
6409
       iqentry_fpu[n] <= FALSE;
6410
       iqentry_fpu1_issue[n] <= FALSE;
6411
       iqentry_fpu2_issue[n] <= FALSE;
6412
       iqentry_fsync[n] <= FALSE;
6413
       iqentry_fc[n] <= FALSE;
6414
       iqentry_fcu_issue[n] <= FALSE;
6415 52 robfinch
       iqentry_takb[n] <= FALSE;
6416 51 robfinch
       iqentry_jmp[n] <= FALSE;
6417
       iqentry_jal[n] <= FALSE;
6418
       iqentry_ret[n] <= FALSE;
6419
       iqentry_brk[n] <= FALSE;
6420
       iqentry_irq[n] <= FALSE;
6421
       iqentry_rti[n] <= FALSE;
6422
       iqentry_ldcmp[n] <= FALSE;
6423
       iqentry_load[n] <= FALSE;
6424
       iqentry_rtop[n] <= FALSE;
6425
       iqentry_sei[n] <= FALSE;
6426
       iqentry_shft48[n] <= FALSE;
6427
       iqentry_sync[n] <= FALSE;
6428
       iqentry_ven[n] <= 6'd0;
6429
       iqentry_vl[n] <= 8'd0;
6430
       iqentry_we[n] <= 8'h00;
6431
       iqentry_rfw[n] <= FALSE;
6432
       iqentry_rmw[n] <= FALSE;
6433
       iqentry_pc[n] <= RSTPC;
6434 48 robfinch
         iqentry_instr[n] <= `NOP_INSN;
6435 56 robfinch
         iqentry_insln[n] <= 3'd4;
6436 48 robfinch
         iqentry_preload[n] <= FALSE;
6437
         iqentry_mem[n] <= FALSE;
6438
         iqentry_memndx[n] <= FALSE;
6439 51 robfinch
       iqentry_memissue[n] <= FALSE;
6440
       iqentry_mem_islot[n] <= 3'd0;
6441
       iqentry_memdb[n] <= FALSE;
6442
       iqentry_memsb[n] <= FALSE;
6443
       iqentry_tgt[n] <= 6'd0;
6444
       iqentry_imm[n] <= 1'b0;
6445
       iqentry_a0[n] <= 64'd0;
6446
       iqentry_a1[n] <= 64'd0;
6447
       iqentry_a2[n] <= 64'd0;
6448
       iqentry_a3[n] <= 64'd0;
6449
       iqentry_a1_v[n] <= `INV;
6450
       iqentry_a2_v[n] <= `INV;
6451
       iqentry_a3_v[n] <= `INV;
6452
       iqentry_a1_s[n] <= 5'd0;
6453
       iqentry_a2_s[n] <= 5'd0;
6454
       iqentry_a3_s[n] <= 5'd0;
6455
       iqentry_canex[n] <= FALSE;
6456 48 robfinch
    end
6457 49 robfinch
     bwhich <= 2'b00;
6458 48 robfinch
     dram0 <= `DRAMSLOT_AVAIL;
6459
     dram1 <= `DRAMSLOT_AVAIL;
6460
     dram2 <= `DRAMSLOT_AVAIL;
6461
     dram0_instr <= `NOP_INSN;
6462
     dram1_instr <= `NOP_INSN;
6463
     dram2_instr <= `NOP_INSN;
6464
     dram0_addr <= 32'h0;
6465
     dram1_addr <= 32'h0;
6466
     dram2_addr <= 32'h0;
6467
     L1_adr <= RSTPC;
6468
     invic <= FALSE;
6469
     tail0 <= 3'd0;
6470
     tail1 <= 3'd1;
6471
     head0 <= 0;
6472
     head1 <= 1;
6473
     head2 <= 2;
6474
     head3 <= 3;
6475
     head4 <= 4;
6476
     head5 <= 5;
6477
     head6 <= 6;
6478
     head7 <= 7;
6479 52 robfinch
     head8 <= 8;
6480
     head9 <= 9;
6481 48 robfinch
     panic = `PANIC_NONE;
6482
     alu0_dataready <= 0;
6483
     alu1_dataready <= 0;
6484
     alu0_sourceid <= 5'd0;
6485
     alu1_sourceid <= 5'd0;
6486
`ifdef SIM
6487
                alu0_pc <= RSTPC;
6488
                alu0_instr <= `NOP_INSN;
6489
                alu0_argA <= 64'h0;
6490
                alu0_argB <= 64'h0;
6491
                alu0_argC <= 64'h0;
6492
                alu0_argI <= 64'h0;
6493
                alu0_bt <= 1'b0;
6494
                alu0_mem <= 1'b0;
6495
                alu0_shft48 <= 1'b0;
6496
                alu0_thrd <= 1'b0;
6497
                alu0_tgt <= 6'h00;
6498
                alu0_ven <= 6'd0;
6499
                alu1_pc <= RSTPC;
6500
                alu1_instr <= `NOP_INSN;
6501
                alu1_argA <= 64'h0;
6502
                alu1_argB <= 64'h0;
6503
                alu1_argC <= 64'h0;
6504
                alu1_argI <= 64'h0;
6505
                alu1_bt <= 1'b0;
6506
                alu1_mem <= 1'b0;
6507
                alu1_shft48 <= 1'b0;
6508
                alu1_thrd <= 1'b0;
6509
                alu1_tgt <= 6'h00;
6510
                alu1_ven <= 6'd0;
6511
`endif
6512
     fcu_dataready <= 0;
6513
     fcu_instr <= `NOP_INSN;
6514
     dramA_v <= 0;
6515
     dramB_v <= 0;
6516
     dramC_v <= 0;
6517
     I <= 0;
6518 58 robfinch
     CC <= 0;
6519 48 robfinch
     icstate <= IDLE;
6520
     bstate <= BIDLE;
6521
     tick <= 64'd0;
6522
     bte_o <= 2'b00;
6523
     cti_o <= 3'b000;
6524
     cyc_o <= `LOW;
6525
     stb_o <= `LOW;
6526
     we_o <= `LOW;
6527
     sel_o <= 8'h00;
6528
     sr_o <= `LOW;
6529
     cr_o <= `LOW;
6530
     adr_o <= RSTPC;
6531
     icl_o <= `LOW;             // instruction cache load
6532
     cr0 <= 64'd0;
6533 55 robfinch
     cr0[13:8] <= 6'd0;         // select compressed instruction group #0
6534 48 robfinch
     cr0[30] <= TRUE;           // enable data caching
6535
     cr0[32] <= TRUE;           // enable branch predictor
6536
     cr0[16] <= 1'b0;           // disable SMT
6537
     cr0[17] <= 1'b0;           // sequence number reset = 1
6538 52 robfinch
     cr0[34] <= FALSE;  // write buffer merging enable
6539 48 robfinch
     pcr <= 32'd0;
6540
     pcr2 <= 64'd0;
6541
    for (n = 0; n < PREGS; n = n + 1)
6542
         rf_v[n] <= `VAL;
6543 51 robfinch
     fp_rm <= 3'd0;                     // round nearest even - default rounding mode
6544
     fpu_csr[37:32] <= 5'd31;   // register set #31
6545 48 robfinch
     waitctr <= 64'd0;
6546
    for (n = 0; n < 16; n = n + 1)
6547
         badaddr[n] <= 64'd0;
6548
     sbl <= 32'h0;
6549
     sbu <= 32'hFFFFFFFF;
6550
    // Vector
6551
     vqe0 <= 6'd0;
6552
     vqet0 <= 6'd0;
6553
     vqe1 <= 6'd0;
6554
     vqet1 <= 6'd0;
6555
     vl <= 7'd62;
6556
    for (n = 0; n < 8; n = n + 1)
6557
         vm[n] <= 64'h7FFFFFFFFFFFFFFF;
6558
     nop_fetchbuf <= 4'h0;
6559
     seq_num <= 5'd0;
6560
     seq_num1 <= 5'd0;
6561
     fcu_done <= `TRUE;
6562
     sema <= 64'h0;
6563
     tvec[0] <= RSTPC;
6564 49 robfinch
     pmr <= 64'hFFFFFFFFFFFFFFFF;
6565
     pmr[0] <= `ID1_AVAIL;
6566
     pmr[1] <= `ID2_AVAIL;
6567
     pmr[2] <= `ID3_AVAIL;
6568
     pmr[8] <= `ALU0_AVAIL;
6569
     pmr[9] <= `ALU1_AVAIL;
6570
     pmr[16] <= `FPU1_AVAIL;
6571
     pmr[17] <= `FPU2_AVAIL;
6572
     pmr[24] <= `MEM1_AVAIL;
6573
     pmr[25] <= `MEM2_AVAIL;
6574
                 pmr[26] <= `MEM3_AVAIL;
6575
     pmr[32] <= `FCU_AVAIL;
6576
     for (n = 0; n < `WB_DEPTH; n = n + 1) begin
6577
        wb_v[n] <= 1'b0;
6578
        wb_rmw[n] <= 1'b0;
6579
        wb_id[n] <= {QENTRIES{1'b0}};
6580
     end
6581
     wb_en <= `TRUE;
6582
     wbo_id <= {QENTRIES{1'b0}};
6583
`ifdef SIM
6584
                wb_merges <= 32'd0;
6585
`endif
6586 48 robfinch
end
6587
else begin
6588 49 robfinch
        if (|fb_panic)
6589
                panic <= fb_panic;
6590
        begin
6591
                branchmiss <= excmiss|fcu_branchmiss;
6592 51 robfinch
                misspc <= excmiss ? excmisspc : fcu_misspc;
6593
                missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
6594 49 robfinch
                branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
6595
        end
6596 48 robfinch
        // The following signals only pulse
6597
 
6598
        // Instruction decode output should only pulse once for a queue entry. We
6599
        // want the decode to be invalidated after a clock cycle so that it isn't
6600
        // inadvertently used to update the queue at a later point.
6601 57 robfinch
        dramA_v <= `INV;
6602
        dramB_v <= `INV;
6603
        dramC_v <= `INV;
6604 48 robfinch
        id1_vi <= `INV;
6605 49 robfinch
        if (`NUM_IDU > 1)
6606
                id2_vi <= `INV;
6607
        if (`NUM_IDU > 2)
6608
                id3_vi <= `INV;
6609
        if (iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]])
6610
                fcu_dataready <= `INV;
6611 52 robfinch
        wb_shift <= FALSE;
6612 48 robfinch
        ld_time <= {ld_time[4:0],1'b0};
6613
        wc_times <= wc_time;
6614
     rf_vra0 <= regIsValid[Ra0s];
6615
     rf_vra1 <= regIsValid[Ra1s];
6616
    if (vqe0 >= vl) begin
6617
         vqe0 <= 6'd0;
6618
         vqet0 <= 6'h0;
6619
    end
6620
    if (vqe1 >= vl) begin
6621
         vqe1 <= 6'd0;
6622
         vqet1 <= 6'h0;
6623
    end
6624
    // Turn off vector chaining indicator when chained instructions are done.
6625
    if ((vqe0 >= vl || vqe0==6'd0) && (vqe1 >= vl || vqe1==6'd0))
6626
`ifdef SUPPORT_SMT
6627
        mstatus[0][32] <= 1'b0;
6628
`else
6629
        mstatus[32] <= 1'b0;
6630
`endif
6631
 
6632
     nop_fetchbuf <= 4'h0;
6633
     excmiss <= FALSE;
6634
     invic <= FALSE;
6635
     tick <= tick + 64'd1;
6636
     alu0_ld <= FALSE;
6637
     alu1_ld <= FALSE;
6638 49 robfinch
     fpu1_ld <= FALSE;
6639
     fpu2_ld <= FALSE;
6640 48 robfinch
     fcu_ld <= FALSE;
6641
     dramA_v <= FALSE;
6642
     dramB_v <= FALSE;
6643
     dramC_v <= FALSE;
6644
     cr0[17] <= 1'b0;
6645
    if (waitctr != 64'd0)
6646
         waitctr <= waitctr - 64'd1;
6647
 
6648
 
6649 50 robfinch
    if (iqentry_fc[fcu_id[`QBITS]] && iqentry_v[fcu_id[`QBITS]] && !iqentry_done[fcu_id[`QBITS]] && iqentry_out[fcu_id[`QBITS]])
6650 48 robfinch
        fcu_timeout <= fcu_timeout + 8'd1;
6651
 
6652
        if (branchmiss) begin
6653
        for (n = 1; n < PREGS; n = n + 1)
6654
           if (~livetarget[n]) begin
6655
                        if (branchmiss_thrd) begin
6656
                                if (n >= 128)
6657
                                rf_v[n] <= `VAL;
6658
                        end
6659
                        else begin
6660
                                if (n < 128)
6661
                                rf_v[n] <= `VAL;
6662
                end
6663
           end
6664
 
6665 53 robfinch
                        for (n = 0; n < QENTRIES; n = n + 1)
6666
                if (|iqentry_latestID[n])
6667
                        if (iqentry_thrd[n]==branchmiss_thrd) rf_source[ {iqentry_tgt[n][7:0]} ] <= { 1'b0, iqentry_mem[n], n[3:0] };
6668 48 robfinch
 
6669
    end
6670
 
6671
    // The source for the register file data might have changed since it was
6672
    // placed on the commit bus. So it's needed to check that the source is
6673
    // still as expected to validate the register.
6674
        if (commit0_v) begin
6675
        if (!rf_v[ {commit0_tgt[7:0]} ])
6676
//             rf_v[ {commit0_tgt[7:0]} ] <= rf_source[ commit0_tgt[7:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]);
6677
             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] ]);
6678
        if (commit0_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit0_tgt, commit0_bus, regIsValid[commit0_tgt[5:0]],
6679
        rf_source[ {commit0_tgt[7:0]} ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]));
6680
        if (commit0_tgt[5:0]==6'd30 && commit0_bus==64'd0)
6681
                $display("FP <= 0");
6682
    end
6683 49 robfinch
    if (commit1_v && `NUM_CMT > 1) begin
6684 48 robfinch
        if (!rf_v[ {commit1_tgt[7:0]} ]) begin
6685
                if ({commit1_tgt[7:0]}=={commit0_tgt[7:0]})
6686
                         rf_v[ {commit1_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}];
6687
                        /*
6688
                                (rf_source[ commit0_tgt[4:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ])) ||
6689
                                (rf_source[ commit1_tgt[4:0] ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6690
                        */
6691
                else
6692
                 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] ]);
6693
        end
6694
        if (commit1_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit1_tgt, commit1_bus, regIsValid[commit1_tgt[5:0]],
6695
        rf_source[ {commit1_tgt[7:0]} ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6696
        if (commit1_tgt[5:0]==6'd30 && commit1_bus==64'd0)
6697
                $display("FP <= 0");
6698
    end
6699 58 robfinch
    if (commit2_v && `NUM_CMT > 2) begin
6700
      if (!rf_v[ {commit2_tgt[7:0]} ]) begin
6701
        if ({commit2_tgt[7:0]}=={commit1_tgt[7:0]} && {commit2_tgt[7:0]}=={commit0_tgt[7:0]})
6702
                 rf_v[ {commit2_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}];
6703
        else if ({commit2_tgt[7:0]}=={commit0_tgt[7:0]})
6704
                 rf_v[ {commit2_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}];
6705
        else if ({commit2_tgt[7:0]}=={commit1_tgt[7:0]})
6706
                 rf_v[ {commit2_tgt[7:0]} ] <= regIsValid[{commit1_tgt[7:0]}] | regIsValid[{commit2_tgt[7:0]}];
6707
        else
6708
                 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] ]);
6709
      end
6710
      if (commit2_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit2_tgt, commit2_bus, regIsValid[commit2_tgt[5:0]],
6711
      rf_source[ {commit2_tgt[7:0]} ] == commit2_id || (branchmiss && iqentry_source[ commit2_id[`QBITS] ]));
6712
      if (commit2_tgt[5:0]==6'd30 && commit2_bus==64'd0)
6713
        $display("FP <= 0");
6714
    end
6715 48 robfinch
     rf_v[0] <= 1;
6716
 
6717 49 robfinch
  //
6718
  // ENQUEUE
6719
  //
6720
  // place up to two instructions from the fetch buffer into slots in the IQ.
6721
  //   note: they are placed in-order, and they are expected to be executed
6722
  // 0, 1, or 2 of the fetch buffers may have valid data
6723
  // 0, 1, or 2 slots in the instruction queue may be available.
6724
  // if we notice that one of the instructions in the fetch buffer is a predicted branch,
6725
  // (set branchback/backpc and delete any instructions after it in fetchbuf)
6726
  //
6727 48 robfinch
 
6728
        // enqueue fetchbuf0 and fetchbuf1, but only if there is room, 
6729
        // and ignore fetchbuf1 if fetchbuf0 has a backwards branch in it.
6730
        //
6731
        // also, do some instruction-decode ... set the operand_valid bits in the IQ
6732
        // appropriately so that the DATAINCOMING stage does not have to look at the opcode
6733
        //
6734
        if (!branchmiss)        // don't bother doing anything if there's been a branch miss
6735
 
6736
                case ({fetchbuf0_v, fetchbuf1_v})
6737
 
6738
            2'b00: ; // do nothing
6739
 
6740
            2'b01:
6741
                    if (canq1) begin
6742 56 robfinch
          if (fetchbuf1_thrd)
6743
                seq_num1 <= seq_num1 + 5'd1;
6744
          else
6745
                seq_num <= seq_num + 5'd1;
6746
                                        if (fetchbuf1_rfw) begin
6747
                                                rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail0 };  // top bit indicates ALU/MEM bus
6748
                                                rf_v [Rt1s] <= `INV;
6749
                                        end
6750
                                        if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6751
                                                vqe1 <= vqe1 + 4'd1;
6752
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6753
                                                        if (vm[fetchbuf1_instr[25:23]][vqe1])
6754
                                                                vqet1 <= vqet1 + 4'd1;
6755
                                                end
6756
                                                else
6757
                                                        vqet1 <= vqet1 + 4'd1;
6758
                                                if (vqe1 >= vl-2)
6759
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6760
                                                enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, vqe1);
6761
                                                if (canq2 && vqe1 < vl-2) begin
6762
                                                        vqe1 <= vqe1 + 4'd2;
6763
                                                        if (IsVCmprss(fetchbuf1_instr)) begin
6764
                                                                if (vm[fetchbuf1_instr[25:23]][vqe1+6'd1])
6765
                                                                        vqet1 <= vqet1 + 4'd2;
6766
                                                        end
6767
                                                        else
6768
                                                                vqet1 <= vqet1 + 4'd2;
6769
                                                        enque1(tail1, fetchbuf1_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe1 + 6'd1);
6770
                                                        // Override the earlier udpate
6771
                                                        if (fetchbuf1_thrd)
6772
                                                                seq_num1 <= seq_num1 + 5'd2;
6773
                                                        else
6774
                                                                seq_num <= seq_num + 5'd2;
6775
                                                end
6776
                                        end
6777
                                        else begin
6778
                                                enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, 6'd0);
6779
                                        end
6780 48 robfinch
                    end
6781
 
6782
            2'b10:
6783
                if (canq1) begin
6784 55 robfinch
                        enque0x();
6785 48 robfinch
                    end
6786
 
6787
            2'b11:
6788
                    if (canq1) begin
6789
                                //
6790
                                // if the first instruction is a predicted branch, enqueue it & stomp on all following instructions
6791
                                // but only if the following instruction is in the same thread. Otherwise we want to queue two.
6792
                                //
6793
                                if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
6794 55 robfinch
                                        enque0x();
6795 48 robfinch
                                end
6796
 
6797
                                else begin      // fetchbuf0 doesn't contain a predicted branch
6798
                                    //
6799
                                    // so -- we can enqueue 1 or 2 instructions, depending on space in the IQ
6800
                                    // update the rf_v and rf_source bits separately (at end)
6801
                                    //   the problem is that if we do have two instructions, 
6802
                                    //   they may interact with each other, so we have to be
6803
                                    //   careful about where things point.
6804
                                    //
6805
                                    // enqueue the first instruction ...
6806
                                    //
6807
                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
6808
                                 vqe0 <= vqe0 + 4'd1;
6809
                                if (IsVCmprss(fetchbuf0_instr)) begin
6810
                                    if (vm[fetchbuf0_instr[25:23]][vqe0])
6811
                                         vqet0 <= vqet0 + 4'd1;
6812
                                end
6813
                                else
6814
                                     vqet0 <= vqet0 + 4'd1;
6815
                                if (vqe0 >= vl-2)
6816
                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6817
                            end
6818
                            if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
6819
                                    enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
6820
                                        if (fetchbuf0_thrd)
6821
                                                seq_num1 <= seq_num1 + 5'd1;
6822
                                        else
6823
                                                seq_num <= seq_num + 5'd1;
6824
                                            //
6825
                                            // if there is room for a second instruction, enqueue it
6826
                                            //
6827
                                            if (canq2) begin
6828
                                                if (vechain && IsVector(fetchbuf1_instr)
6829
                                                && Ra1s != Rt0s // And there is no dependency
6830
                                                && Rb1s != Rt0s
6831
                                                && Rc1s != Rt0s
6832
                                                ) begin
6833
`ifdef SUPPORT_SMT
6834
                                                        mstatus[0][32] <= 1'b1;
6835
`else
6836
                                                        mstatus[32] <= 1'b1;
6837
`endif
6838
                                                vqe1 <= vqe1 + 4'd1;
6839
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6840
                                                    if (vm[fetchbuf1_instr[25:23]][vqe1])
6841
                                                         vqet1 <= vqet1 + 4'd1;
6842
                                                end
6843
                                                else
6844
                                                     vqet1 <= vqet1 + 4'd1;
6845
                                                if (vqe1 >= vl-2)
6846
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6847
                                                        enque1(tail1,
6848
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6849
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6850
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
6851
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6852
                                                                if (fetchbuf1_thrd)
6853
                                                                        seq_num1 <= seq_num1 + 5'd2;
6854
                                                                else
6855
                                                                        seq_num <= seq_num + 5'd2;
6856
                                                        end
6857
                                                        else begin
6858
                                                                if (fetchbuf1_thrd)
6859
                                                                        seq_num1 <= seq_num1 + 5'd1;
6860
                                                                else
6861
                                                                        seq_num <= seq_num + 5'd1;
6862
                                                        end
6863
 
6864
                                                                // SOURCE 1 ...
6865 55 robfinch
                                                                a1_vs();
6866 48 robfinch
 
6867
                                                                // SOURCE 2 ...
6868 55 robfinch
                                                                a2_vs();
6869 48 robfinch
 
6870
                                                                // SOURCE 3 ...
6871 55 robfinch
                                                                a3_vs();
6872 48 robfinch
 
6873
                                                                // if the two instructions enqueued target the same register, 
6874
                                                                // make sure only the second writes to rf_v and rf_source.
6875
                                                                // first is allowed to update rf_v and rf_source only if the
6876
                                                                // second has no target
6877
                                                                //
6878
                                                            if (fetchbuf0_rfw) begin
6879
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6880
                                                                     rf_v [ Rt0s] <= `INV;
6881
                                                            end
6882
                                                            if (fetchbuf1_rfw) begin
6883
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6884
                                                                     rf_v [ Rt1s ] <= `INV;
6885
                                                            end
6886
                                                end
6887
                                                // If there was a vector instruction in fetchbuf0, we really
6888
                                                // want to queue the next vector element, not the next
6889
                                                // instruction waiting in fetchbuf1.
6890
                                            else if (IsVector(fetchbuf0_instr) && SUP_VECTOR && vqe0 < vl-1) begin
6891
                                                 vqe0 <= vqe0 + 4'd2;
6892
                                                if (IsVCmprss(fetchbuf0_instr)) begin
6893
                                                    if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
6894
                                                         vqet0 <= vqet0 + 4'd2;
6895
                                                end
6896
                                                else
6897
                                                     vqet0 <= vqet0 + 4'd2;
6898
                                                if (vqe0 >= vl-3)
6899
                                                 nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6900
                                            if (vqe0 < vl-1) begin
6901
                                                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe0 + 6'd1);
6902
                                                                if (fetchbuf0_thrd)
6903
                                                                        seq_num1 <= seq_num1 + 5'd2;
6904
                                                                else
6905
                                                                        seq_num <= seq_num + 5'd2;
6906
 
6907
                                                                        // SOURCE 1 ...
6908
                                                     iqentry_a1_v [tail1] <= regIsValid[Ra0s];
6909
                                                     iqentry_a1_s [tail1] <= rf_source [Ra0s];
6910
 
6911
                                                                        // SOURCE 2 ...
6912
                                                     iqentry_a2_v [tail1] <= regIsValid[Rb0s];
6913
                                                     iqentry_a2_s [tail1] <= rf_source[ Rb0s ];
6914
 
6915
                                                                        // SOURCE 3 ...
6916
                                                     iqentry_a3_v [tail1] <= regIsValid[Rc0s];
6917
                                                     iqentry_a3_s [tail1] <= rf_source[ Rc0s ];
6918
 
6919
                                                                        // if the two instructions enqueued target the same register, 
6920
                                                                        // make sure only the second writes to rf_v and rf_source.
6921
                                                                        // first is allowed to update rf_v and rf_source only if the
6922
                                                                        // second has no target (BEQ or SW)
6923
                                                                        //
6924
                                                                    if (fetchbuf0_rfw) begin
6925
                                                                             rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };
6926
                                                                             rf_v [ Rt0s ] <= `INV;
6927
                                                                    end
6928
                                                                end
6929
                                                end
6930
                                            else if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6931
                                                 vqe1 <= 6'd1;
6932
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6933
                                                    if (vm[fetchbuf1_instr[25:23]][IsVector(fetchbuf0_instr)? 6'd0:vqe1+6'd1])
6934
                                                         vqet1 <= 6'd1;
6935
                                                else
6936
                                                         vqet1 <= 6'd0;
6937
                                                end
6938
                                                else
6939
                                                         vqet1 <= 6'd1;
6940
                                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR)
6941
                                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6942
                                                        enque1(tail1,
6943
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6944
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6945
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
6946
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6947
                                                                if (fetchbuf1_thrd)
6948
                                                                        seq_num1 <= seq_num1 + 5'd2;
6949
                                                                else
6950
                                                                        seq_num <= seq_num + 5'd2;
6951
                                                        end
6952
                                                        else begin
6953
                                                                if (fetchbuf1_thrd)
6954
                                                                        seq_num1 <= seq_num1 + 5'd1;
6955
                                                                else
6956
                                                                        seq_num <= seq_num + 5'd1;
6957
                                                        end
6958
 
6959
                                                                // SOURCE 1 ...
6960 55 robfinch
                                                                a1_vs();
6961 48 robfinch
 
6962 55 robfinch
                                                                // SOURCE 2 ..
6963
                                                                a2_vs();
6964 48 robfinch
 
6965
                                                                // SOURCE 3 ...
6966 55 robfinch
                                                                a3_vs();
6967 48 robfinch
 
6968
                                                                // if the two instructions enqueued target the same register, 
6969
                                                                // make sure only the second writes to rf_v and rf_source.
6970
                                                                // first is allowed to update rf_v and rf_source only if the
6971
                                                                // second has no target
6972
                                                                //
6973
                                                            if (fetchbuf0_rfw) begin
6974
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6975
                                                                     rf_v [ Rt0s] <= `INV;
6976
                                                            end
6977
                                                            if (fetchbuf1_rfw) begin
6978
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6979
                                                                     rf_v [ Rt1s ] <= `INV;
6980
                                                            end
6981
                                            end
6982
                                            else begin
6983
//                                                      enque1(tail1, seq_num + 5'd1, 6'd0);
6984
                                                        enque1(tail1,
6985
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6986
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6987
                                                                fetchbuf1_thrd ? seq_num1: seq_num, 6'd0);
6988
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6989
                                                                if (fetchbuf1_thrd)
6990
                                                                        seq_num1 <= seq_num1 + 5'd2;
6991
                                                                else
6992
                                                                        seq_num <= seq_num + 5'd2;
6993
                                                        end
6994
                                                        else begin
6995
                                                                        seq_num1 <= seq_num1 + 5'd1;
6996
                                                                        seq_num <= seq_num + 5'd1;
6997
                                                        end
6998
 
6999
                                                                // SOURCE 1 ...
7000 55 robfinch
                                                                a1_vs();
7001 48 robfinch
 
7002
                                                                // SOURCE 2 ...
7003 55 robfinch
                                                                a2_vs();
7004 48 robfinch
 
7005
                                                                // SOURCE 3 ...
7006 55 robfinch
                                                                a3_vs();
7007 48 robfinch
 
7008
                                                                // if the two instructions enqueued target the same register, 
7009
                                                                // make sure only the second writes to regIsValid and rf_source.
7010
                                                                // first is allowed to update regIsValid and rf_source only if the
7011
                                                                // second has no target (BEQ or SW)
7012
                                                                //
7013
                                                            if (fetchbuf0_rfw) begin
7014
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
7015
                                                                     rf_v [ Rt0s] <= `INV;
7016
                                                                     $display("r%dx (%d) Invalidated", Rt0s, Rt0s[4:0]);
7017
                                                            end
7018
                                                            else
7019
                                                                $display("No rfw");
7020
                                                            if (fetchbuf1_rfw) begin
7021
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
7022
                                                                     $display("r%dx (%d) Invalidated", Rt1s, Rt1s[4:0]);
7023
                                                                     rf_v [ Rt1s ] <= `INV;
7024
                                                            end
7025
                                                            else
7026
                                                                $display("No rfw");
7027
                                                        end
7028
 
7029
                                            end // ends the "if IQ[tail1] is available" clause
7030
                                            else begin  // only first instruction was enqueued
7031
                                                        if (fetchbuf0_rfw) begin
7032
                                                             $display("r%dx (%d) Invalidated 1", Rt0s, Rt0s[4:0]);
7033
                                                             rf_source[ Rt0s ] <= {1'b0,fetchbuf0_memld, tail0};
7034
                                                             rf_v [ Rt0s ] <= `INV;
7035
                                                        end
7036
                                                end
7037
                                    end
7038
 
7039
                                end     // ends the "else fetchbuf0 doesn't have a backwards branch" clause
7040
                    end
7041
                endcase
7042
        if (pebm) begin
7043
                if (branchmiss_thrd==1'b0)
7044
                        seq_num <= seq_num + 5'd3;
7045
                else
7046
                        seq_num1 <= seq_num1 + 5'd3;
7047
        end
7048
 
7049
//
7050
// DATAINCOMING
7051
//
7052
// wait for operand/s to appear on alu busses and puts them into 
7053
// the iqentry_a1 and iqentry_a2 slots (if appropriate)
7054
// as well as the appropriate iqentry_res slots (and setting valid bits)
7055
//
7056
// put results into the appropriate instruction entries
7057
//
7058
// This chunk of code has to be before the enqueue stage so that the agen bit
7059
// can be reset to zero by enqueue.
7060
// put results into the appropriate instruction entries
7061
//
7062
if (IsMul(alu0_instr)|IsDivmod(alu0_instr)|alu0_shft48) begin
7063
        if (alu0_done) begin
7064
                alu0_dataready <= `TRUE;
7065
        end
7066
end
7067
 
7068
if (alu0_v) begin
7069
        iqentry_tgt [ alu0_id[`QBITS] ] <= alu0_tgt;
7070
        iqentry_res     [ alu0_id[`QBITS] ] <= alu0_bus;
7071
        iqentry_exc     [ alu0_id[`QBITS] ] <= alu0_exc;
7072
        iqentry_done[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
7073 59 robfinch
        iqentry_cmt [ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
7074 48 robfinch
        iqentry_out     [ alu0_id[`QBITS] ] <= `INV;
7075
        iqentry_agen[ alu0_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
7076
        alu0_dataready <= FALSE;
7077
end
7078
 
7079 49 robfinch
if (alu1_v && `NUM_ALU > 1) begin
7080 48 robfinch
        iqentry_tgt [ alu1_id[`QBITS] ] <= alu1_tgt;
7081
        iqentry_res     [ alu1_id[`QBITS] ] <= alu1_bus;
7082
        iqentry_exc     [ alu1_id[`QBITS] ] <= alu1_exc;
7083
        iqentry_done[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
7084 59 robfinch
        iqentry_cmt [ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
7085 48 robfinch
        iqentry_out     [ alu1_id[`QBITS] ] <= `INV;
7086
        iqentry_agen[ alu1_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
7087
        alu1_dataready <= FALSE;
7088
end
7089
 
7090 49 robfinch
if (fpu1_v) begin
7091 51 robfinch
        iqentry_res [ fpu1_id[`QBITS] ] <= fpu1_bus;
7092
        iqentry_a0  [ fpu1_id[`QBITS] ] <= fpu1_status;
7093
        iqentry_exc [ fpu1_id[`QBITS] ] <= fpu1_exc;
7094 49 robfinch
        iqentry_done[ fpu1_id[`QBITS] ] <= fpu1_done;
7095 51 robfinch
        iqentry_cmt     [ fpu1_id[`QBITS] ] <= fpu1_done;
7096
        iqentry_out [ fpu1_id[`QBITS] ] <= `INV;
7097 49 robfinch
        fpu1_dataready <= FALSE;
7098 48 robfinch
end
7099
 
7100 49 robfinch
if (fpu2_v && `NUM_FPU > 1) begin
7101 51 robfinch
        iqentry_res [ fpu2_id[`QBITS] ] <= fpu2_bus;
7102
        iqentry_a0  [ fpu2_id[`QBITS] ] <= fpu2_status;
7103
        iqentry_exc [ fpu2_id[`QBITS] ] <= fpu2_exc;
7104 49 robfinch
        iqentry_done[ fpu2_id[`QBITS] ] <= fpu2_done;
7105 51 robfinch
        iqentry_cmt [ fpu2_id[`QBITS] ] <= fpu2_done;
7106
        iqentry_out [ fpu2_id[`QBITS] ] <= `INV;
7107 49 robfinch
        //iqentry_agen[ fpu_id[`QBITS] ] <= `VAL;  // RET
7108
        fpu2_dataready <= FALSE;
7109
end
7110
 
7111 51 robfinch
if (fcu_wr & ~fcu_done) begin
7112
        fcu_done <= `TRUE;
7113
  if (fcu_ld)
7114
    waitctr <= fcu_argA;
7115
  iqentry_res [ fcu_id[`QBITS] ] <= fcu_bus;
7116
  iqentry_exc [ fcu_id[`QBITS] ] <= fcu_exc;
7117
  if (IsWait(fcu_instr)) begin
7118
                iqentry_done [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
7119
                iqentry_cmt [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
7120
  end
7121
  else begin
7122
                iqentry_done[ fcu_id[`QBITS] ] <= `TRUE;
7123
                iqentry_cmt[ fcu_id[`QBITS] ] <= `TRUE;
7124
  end
7125
        // Only safe place to propagate the miss pc is a0.
7126
        iqentry_a0[ fcu_id[`QBITS] ] <= fcu_misspc;
7127 55 robfinch
        // Update branch target update indicator.
7128 51 robfinch
        if (fcu_jal || fcu_ret || fcu_brk || fcu_rti) begin
7129
                iqentry_bt[ fcu_id[`QBITS] ] <= `VAL;
7130
        end
7131
// Branch target is only updated for branch-to-register
7132 52 robfinch
        else if (fcu_branch) begin
7133
                iqentry_takb[ fcu_id[`QBITS] ] <= fcu_takb;
7134
        end
7135 51 robfinch
        iqentry_out [ fcu_id[`QBITS] ] <= `INV;
7136
        //iqentry_agen[ fcu_id[`QBITS] ] <= `VAL;//!IsRet(fcu_instr);
7137
        fcu_dataready <= `VAL;
7138 48 robfinch
         //fcu_dataready <= fcu_branchmiss || !iqentry_agen[ fcu_id[`QBITS] ] || !(iqentry_mem[ fcu_id[`QBITS] ] && IsLoad(iqentry_instr[fcu_id[`QBITS]]));
7139
         //fcu_instr[`INSTRUCTION_OP] <= fcu_branchmiss|| (!IsMem(fcu_instr) && !IsWait(fcu_instr))? `NOP : fcu_instr[`INSTRUCTION_OP]; // to clear branchmiss
7140 51 robfinch
end
7141
// Clear a branch miss when target instruction is fetched.
7142
if (fcu_branchmiss) begin
7143
        if ((fetchbuf0_v && fetchbuf0_pc==misspc) ||
7144
                (fetchbuf1_v && fetchbuf1_pc==misspc))
7145
        fcu_clearbm <= `TRUE;
7146
end
7147
 
7148 59 robfinch
if (mem1_available && dramA_v && iqentry_v[ dramA_id[`QBITS] ] && iqentry_load[ dramA_id[`QBITS] ] && !iqentry_stomp[dramA_id[`QBITS]]) begin
7149 51 robfinch
        iqentry_res     [ dramA_id[`QBITS] ] <= dramA_bus;
7150
        iqentry_exc     [ dramA_id[`QBITS] ] <= dramA_exc;
7151
        iqentry_done[ dramA_id[`QBITS] ] <= `VAL;
7152
        iqentry_out [ dramA_id[`QBITS] ] <= `INV;
7153
        iqentry_cmt [ dramA_id[`QBITS] ] <= `VAL;
7154
        iqentry_aq  [ dramA_id[`QBITS] ] <= `INV;
7155
end
7156 59 robfinch
if (mem2_available && `NUM_MEM > 1 && dramB_v && iqentry_v[ dramB_id[`QBITS] ] && iqentry_load[ dramB_id[`QBITS] ] && !iqentry_stomp[dramB_id[`QBITS]]) begin
7157 51 robfinch
        iqentry_res     [ dramB_id[`QBITS] ] <= dramB_bus;
7158
        iqentry_exc     [ dramB_id[`QBITS] ] <= dramB_exc;
7159
        iqentry_done[ dramB_id[`QBITS] ] <= `VAL;
7160
        iqentry_out [ dramB_id[`QBITS] ] <= `INV;
7161
        iqentry_cmt [ dramB_id[`QBITS] ] <= `VAL;
7162
        iqentry_aq  [ dramB_id[`QBITS] ] <= `INV;
7163
end
7164 59 robfinch
if (mem3_available && `NUM_MEM > 2 && dramC_v && iqentry_v[ dramC_id[`QBITS] ] && iqentry_load[ dramC_id[`QBITS] ] && !iqentry_stomp[dramC_id[`QBITS]]) begin
7165 51 robfinch
        iqentry_res     [ dramC_id[`QBITS] ] <= dramC_bus;
7166
        iqentry_exc     [ dramC_id[`QBITS] ] <= dramC_exc;
7167
        iqentry_done[ dramC_id[`QBITS] ] <= `VAL;
7168
        iqentry_out [ dramC_id[`QBITS] ] <= `INV;
7169
        iqentry_cmt [ dramC_id[`QBITS] ] <= `VAL;
7170
        iqentry_aq  [ dramC_id[`QBITS] ] <= `INV;
7171 48 robfinch
//          if (iqentry_lptr[dram2_id[`QBITS]])
7172
//              wbrcd[pcr[5:0]] <= 1'b1;
7173 51 robfinch
end
7174 48 robfinch
 
7175
//
7176
// set the IQ entry == DONE as soon as the SW is let loose to the memory system
7177
//
7178 50 robfinch
if (mem1_available && dram0 == `DRAMSLOT_BUSY && dram0_store) begin
7179 48 robfinch
        if ((alu0_v && (dram0_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram0_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
7180
        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
7181
        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
7182
end
7183 50 robfinch
if (mem2_available && `NUM_MEM > 1 && dram1 == `DRAMSLOT_BUSY && dram1_store) begin
7184 48 robfinch
        if ((alu0_v && (dram1_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram1_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
7185
        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
7186
        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
7187
end
7188 50 robfinch
if (mem3_available && `NUM_MEM > 2 && dram2 == `DRAMSLOT_BUSY && dram2_store) begin
7189 48 robfinch
        if ((alu0_v && (dram2_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram2_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
7190
        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
7191
        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
7192
end
7193
 
7194
//
7195
// see if anybody else wants the results ... look at lots of buses:
7196
//  - fpu_bus
7197
//  - alu0_bus
7198
//  - alu1_bus
7199
//  - fcu_bus
7200
//  - dram_bus
7201
//  - commit0_bus
7202
//  - commit1_bus
7203
//
7204
 
7205
for (n = 0; n < QENTRIES; n = n + 1)
7206
begin
7207 49 robfinch
        if (`NUM_FPU > 0)
7208
                setargs(n,{1'b0,fpu1_id},fpu1_v,fpu1_bus);
7209
        if (`NUM_FPU > 1)
7210
                setargs(n,{1'b0,fpu2_id},fpu2_v,fpu2_bus);
7211
 
7212 48 robfinch
        setargs(n,{1'b0,alu0_id},alu0_v,alu0_bus);
7213 49 robfinch
        if (`NUM_ALU > 1)
7214
                setargs(n,{1'b0,alu1_id},alu1_v,alu1_bus);
7215
 
7216 48 robfinch
        setargs(n,{1'b0,fcu_id},fcu_wr,fcu_bus);
7217 49 robfinch
 
7218 48 robfinch
        setargs(n,{1'b0,dramA_id},dramA_v,dramA_bus);
7219 49 robfinch
        if (`NUM_MEM > 1)
7220
                setargs(n,{1'b0,dramB_id},dramB_v,dramB_bus);
7221
        if (`NUM_MEM > 2)
7222
                setargs(n,{1'b0,dramC_id},dramC_v,dramC_bus);
7223
 
7224 48 robfinch
        setargs(n,commit0_id,commit0_v,commit0_bus);
7225 49 robfinch
        if (`NUM_CMT > 1)
7226
                setargs(n,commit1_id,commit1_v,commit1_bus);
7227 58 robfinch
        if (`NUM_CMT > 2)
7228
                setargs(n,commit2_id,commit2_v,commit2_bus);
7229 48 robfinch
 
7230
        setinsn(n[`QBITS],id1_ido,id1_available&id1_vo,id1_bus);
7231 49 robfinch
        if (`NUM_IDU > 1)
7232
                setinsn(n[`QBITS],id2_ido,id2_available&id2_vo,id2_bus);
7233
        if (`NUM_IDU > 2)
7234
                setinsn(n[`QBITS],id3_ido,id3_available&id3_vo,id3_bus);
7235 48 robfinch
end
7236
 
7237
//
7238
// ISSUE 
7239
//
7240
// determines what instructions are ready to go, then places them
7241
// in the various ALU queues.  
7242
// also invalidates instructions following a branch-miss BEQ or any JALR (STOMP logic)
7243
//
7244
 
7245
for (n = 0; n < QENTRIES; n = n + 1)
7246
if (id1_available) begin
7247
if (iqentry_id1issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7248
                id1_vi <= `VAL;
7249
                id1_id                  <= n[4:0];
7250
                id1_instr       <= iqentry_rtop[n] ? (
7251
                                                                                iqentry_a3_v[n] ? iqentry_a3[n]
7252 49 robfinch
`ifdef FU_BYPASS
7253 48 robfinch
                                : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7254
                                : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7255 49 robfinch
`endif
7256 48 robfinch
                                : `NOP_INSN)
7257
                                                                 : iqentry_instr[n];
7258
                id1_ven    <= iqentry_ven[n];
7259
                id1_vl     <= iqentry_vl[n];
7260
                id1_thrd   <= iqentry_thrd[n];
7261
                id1_Rt     <= iqentry_tgt[n][4:0];
7262
                id1_pt                  <= iqentry_pt[n];
7263
  end
7264
end
7265 49 robfinch
if (`NUM_IDU > 1) begin
7266 48 robfinch
for (n = 0; n < QENTRIES; n = n + 1)
7267 49 robfinch
        if (id2_available) begin
7268
                if (iqentry_id2issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7269
                        id2_vi <= `VAL;
7270
                        id2_id                  <= n[4:0];
7271
                        id2_instr       <= iqentry_rtop[n] ? (
7272
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7273
`ifdef FU_BYPASS
7274
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7275
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7276
`endif
7277
                                        : `NOP_INSN)
7278
                                                                         : iqentry_instr[n];
7279
                        id2_ven    <= iqentry_ven[n];
7280
                        id2_vl     <= iqentry_vl[n];
7281
                        id2_thrd   <= iqentry_thrd[n];
7282
                        id2_Rt     <= iqentry_tgt[n][4:0];
7283
                        id2_pt                  <= iqentry_pt[n];
7284
                end
7285 48 robfinch
        end
7286
end
7287 49 robfinch
if (`NUM_IDU > 2) begin
7288
for (n = 0; n < QENTRIES; n = n + 1)
7289
        if (id3_available) begin
7290
                if (iqentry_id3issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7291
                        id3_vi <= `VAL;
7292
                        id3_id                  <= n[4:0];
7293
                        id3_instr       <= iqentry_rtop[n] ? (
7294
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7295
`ifdef FU_BYPASS
7296
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7297
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7298
`endif
7299
                                        : `NOP_INSN)
7300
                                                                         : iqentry_instr[n];
7301
                        id3_ven    <= iqentry_ven[n];
7302
                        id3_vl     <= iqentry_vl[n];
7303
                        id3_thrd   <= iqentry_thrd[n];
7304
                        id3_Rt     <= iqentry_tgt[n][4:0];
7305
                        id3_pt                  <= iqentry_pt[n];
7306
                end
7307
        end
7308
end
7309 48 robfinch
 
7310 53 robfinch
// X's on unused busses cause problems in SIM.
7311 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
7312
        if (iqentry_alu0_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7313
            if (alu0_available & alu0_done) begin
7314
                 alu0_sourceid  <= n[3:0];
7315
                 alu0_instr     <= iqentry_rtop[n] ? (
7316 49 robfinch
`ifdef FU_BYPASS
7317 48 robfinch
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7318 49 robfinch
                                                    : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7319 53 robfinch
                                                    : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7320 49 robfinch
                                                    : (iqentry_a3_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7321 53 robfinch
                                                    : `NOP_INSN)
7322 49 robfinch
`else
7323
                                                                                                                                        iqentry_a3[n])
7324
`endif
7325 48 robfinch
                                                                         : iqentry_instr[n];
7326
                 alu0_bt                <= iqentry_bt[n];
7327
                 alu0_mem   <= iqentry_mem[n];
7328
                 alu0_shft48 <= iqentry_shft48[n];
7329
                 alu0_pc                <= iqentry_pc[n];
7330 49 robfinch
                 alu0_argA      <=
7331
`ifdef FU_BYPASS
7332
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7333
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7334 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
7335 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7336 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
7337 49 robfinch
`else
7338
                                                                                                                iqentry_a1[n];
7339
`endif
7340 48 robfinch
                 alu0_argB      <= iqentry_imm[n]
7341
                            ? iqentry_a0[n]
7342 49 robfinch
`ifdef FU_BYPASS
7343 48 robfinch
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7344 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7345 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
7346 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7347 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
7348 49 robfinch
`else
7349
                                                                                                                : iqentry_a2[n];
7350
`endif
7351
                 alu0_argC      <=
7352
`ifdef FU_BYPASS
7353
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7354 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7355 49 robfinch
`else
7356
                                                                                                                        iqentry_a3[n];
7357
`endif
7358 48 robfinch
                 alu0_argI      <= iqentry_a0[n];
7359
                 alu0_tgt    <= IsVeins(iqentry_instr[n]) ?
7360 49 robfinch
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((
7361
                                                                                        iqentry_a2_v[n] ? iqentry_a2[n][5:0]
7362 48 robfinch
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
7363
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
7364
                                            : {4{16'h0000}})) << 6 :
7365
                                iqentry_tgt[n];
7366
                 alu0_ven    <= iqentry_ven[n];
7367
                 alu0_thrd   <= iqentry_thrd[n];
7368
                 alu0_dataready <= IsSingleCycle(iqentry_instr[n]);
7369
                 alu0_ld <= TRUE;
7370
                 iqentry_out[n] <= `VAL;
7371
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
7372
                if (iqentry_mem[n]) begin
7373
                 iqentry_a1_v[n] <= `INV;
7374
                 iqentry_a1_s[n] <= n[3:0];
7375
                end
7376
            end
7377
        end
7378 49 robfinch
        if (`NUM_ALU > 1) begin
7379 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
7380
        if (iqentry_alu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7381
            if (alu1_available && alu1_done) begin
7382
                        if (iqentry_alu0[n])
7383
                                panic <= `PANIC_ALU0ONLY;
7384
                 alu1_sourceid  <= n[3:0];
7385
                 alu1_instr     <= iqentry_instr[n];
7386
                 alu1_bt                <= iqentry_bt[n];
7387
                 alu1_mem   <= iqentry_mem[n];
7388
                 alu1_shft48 <= iqentry_shft48[n];
7389
                 alu1_pc                <= iqentry_pc[n];
7390 49 robfinch
                 alu1_argA      <=
7391
`ifdef FU_BYPASS
7392
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7393
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7394 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
7395 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7396 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
7397 49 robfinch
`else
7398
                                                                                                                        iqentry_a1[n];
7399
`endif
7400 48 robfinch
                 alu1_argB      <= iqentry_imm[n]
7401
                            ? iqentry_a0[n]
7402 49 robfinch
`ifdef FU_BYPASS
7403 48 robfinch
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7404 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7405 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
7406 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7407 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
7408 49 robfinch
`else
7409
                                                                                                                : iqentry_a2[n];
7410
`endif
7411
                 alu1_argC      <=
7412
`ifdef FU_BYPASS
7413
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7414 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7415 49 robfinch
`else
7416
                                                                                                                        iqentry_a3[n];
7417
`endif
7418 48 robfinch
                 alu1_argI      <= iqentry_a0[n];
7419
                 alu1_tgt    <= IsVeins(iqentry_instr[n]) ?
7420
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((iqentry_a2_v[n] ? iqentry_a2[n][5:0]
7421
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
7422
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
7423
                                            : {4{16'h0000}})) << 6 :
7424
                                iqentry_tgt[n];
7425
                 alu1_ven    <= iqentry_ven[n];
7426
                 alu1_dataready <= IsSingleCycle(iqentry_instr[n]);
7427
                 alu1_ld <= TRUE;
7428
                 iqentry_out[n] <= `VAL;
7429
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
7430
                if (iqentry_mem[n]) begin
7431
                 iqentry_a1_v[n] <= `INV;
7432
                 iqentry_a1_s[n] <= n[3:0];
7433
                end
7434
            end
7435
        end
7436 49 robfinch
  end
7437 48 robfinch
 
7438
    for (n = 0; n < QENTRIES; n = n + 1)
7439 49 robfinch
        if (iqentry_fpu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7440
            if (fpu1_available & fpu1_done) begin
7441
                 fpu1_sourceid  <= n[3:0];
7442
                 fpu1_instr     <= iqentry_instr[n];
7443
                 fpu1_pc                <= iqentry_pc[n];
7444
                 fpu1_argA      <=
7445
`ifdef FU_BYPASS
7446
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7447
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7448 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
7449 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7450 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
7451 49 robfinch
`else
7452
                                                                                                                        iqentry_a1[n];
7453
`endif
7454
                 fpu1_argB      <=
7455
`ifdef FU_BYPASS
7456
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
7457
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7458 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
7459 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7460 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
7461 49 robfinch
`else
7462
                                                                                                                        iqentry_a2[n];
7463
`endif
7464
                 fpu1_argC      <=
7465
`ifdef FU_BYPASS
7466
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
7467 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7468 49 robfinch
`else
7469
                                                                                                                        iqentry_a3[n];
7470
`endif
7471
                 fpu1_argI      <= iqentry_a0[n];
7472
                 fpu1_dataready <= `VAL;
7473
                 fpu1_ld <= TRUE;
7474 48 robfinch
                 iqentry_out[n] <= `VAL;
7475
            end
7476
        end
7477
 
7478
    for (n = 0; n < QENTRIES; n = n + 1)
7479 49 robfinch
        if (`NUM_FPU > 1 && iqentry_fpu2_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7480
            if (fpu2_available & fpu2_done) begin
7481
                 fpu2_sourceid  <= n[3:0];
7482
                 fpu2_instr     <= iqentry_instr[n];
7483
                 fpu2_pc                <= iqentry_pc[n];
7484
                 fpu2_argA      <=
7485
`ifdef FU_BYPASS
7486
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7487
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7488 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
7489 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7490 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
7491 49 robfinch
`else
7492
                                                                                                                        iqentry_a1[n];
7493
`endif
7494
                 fpu2_argB      <=
7495
`ifdef FU_BYPASS
7496
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
7497
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7498 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
7499 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7500 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
7501 49 robfinch
`else
7502
                                                                                                                        iqentry_a2[n];
7503
`endif
7504
                 fpu2_argC      <=
7505
`ifdef FU_BYPASS
7506
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
7507
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7508
`else
7509
                                                                                                                        iqentry_a3[n];
7510
`endif
7511
                 fpu2_argI      <= iqentry_a0[n];
7512
                 fpu2_dataready <= `VAL;
7513
                 fpu2_ld <= TRUE;
7514
                 iqentry_out[n] <= `VAL;
7515
            end
7516
        end
7517
 
7518
    for (n = 0; n < QENTRIES; n = n + 1)
7519 48 robfinch
        if (iqentry_fcu_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7520
            if (fcu_done) begin
7521
                 fcu_sourceid   <= n[3:0];
7522
                 fcu_instr      <= iqentry_instr[n];
7523
                 fcu_insln  <= iqentry_insln[n];
7524
                 fcu_pc         <= iqentry_pc[n];
7525
                 fcu_nextpc <= iqentry_pc[n] + iqentry_insln[n];
7526
                 fcu_brdisp <= {{52{iqentry_instr[n][31]}},iqentry_instr[n][31:21],1'b0};
7527 51 robfinch
                 fcu_branch <= iqentry_br[n];
7528
                 fcu_call    <= IsCall(iqentry_instr[n])|iqentry_jal[n];
7529
                 fcu_jal     <= iqentry_jal[n];
7530
                 fcu_ret    <= iqentry_ret[n];
7531
                 fcu_brk  <= iqentry_brk[n];
7532
                 fcu_rti  <= iqentry_rti[n];
7533 48 robfinch
                 fcu_bt         <= iqentry_bt[n];
7534
                 fcu_pc         <= iqentry_pc[n];
7535
                 fcu_argA       <= iqentry_a1_v[n] ? iqentry_a1[n]
7536 49 robfinch
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7537
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7538
                            : alu1_bus;
7539 48 robfinch
`ifdef SUPPORT_SMT
7540 51 robfinch
                 fcu_argB       <= iqentry_rti[n] ? epc0[iqentry_thrd[n]]
7541 48 robfinch
`else
7542 51 robfinch
                 fcu_argB       <= iqentry_rti[n] ? epc0
7543 48 robfinch
`endif
7544
                                        : (iqentry_a2_v[n] ? iqentry_a2[n]
7545 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7546
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7547
                            : alu1_bus);
7548 48 robfinch
                 waitctr            <= iqentry_imm[n]
7549
                            ? iqentry_a0[n]
7550
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7551
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus : alu1_bus);
7552
                 fcu_argC       <= iqentry_a3_v[n] ? iqentry_a3[n]
7553
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7554
                 fcu_argI       <= iqentry_a0[n];
7555
                 fcu_thrd   <= iqentry_thrd[n];
7556
                 fcu_dataready <= `VAL;
7557
                 fcu_clearbm <= `FALSE;
7558
                 fcu_ld <= TRUE;
7559
                 fcu_timeout <= 8'h00;
7560
                 iqentry_out[n] <= `VAL;
7561
                 fcu_done <= `FALSE;
7562
            end
7563
        end
7564
//
7565
// MEMORY
7566
//
7567
// update the memory queues and put data out on bus if appropriate
7568
//
7569
 
7570
//
7571
// dram0, dram1, dram2 are the "state machines" that keep track
7572
// of three pipelined DRAM requests.  if any has the value "00", 
7573
// then it can accept a request (which bumps it up to the value "01"
7574
// at the end of the cycle).  once it hits the value "11" the request
7575
// is finished and the dram_bus takes the value.  if it is a store, the 
7576
// dram_bus value is not used, but the dram_v value along with the
7577
// dram_id value signals the waiting memq entry that the store is
7578
// completed and the instruction can commit.
7579
//
7580
 
7581
//      if (dram0 != `DRAMSLOT_AVAIL)   dram0 <= dram0 + 2'd1;
7582
//      if (dram1 != `DRAMSLOT_AVAIL)   dram1 <= dram1 + 2'd1;
7583
//      if (dram2 != `DRAMSLOT_AVAIL)   dram2 <= dram2 + 2'd1;
7584
 
7585
//
7586
// grab requests that have finished and put them on the dram_bus
7587 49 robfinch
if (mem1_available && dram0 == `DRAMREQ_READY) begin
7588 48 robfinch
        dram0 <= `DRAMSLOT_AVAIL;
7589 59 robfinch
        dramA_v <= dram0_load && !iqentry_stomp[dram0_id[`QBITS]];
7590 48 robfinch
        dramA_id <= dram0_id;
7591
        dramA_exc <= dram0_exc;
7592
        dramA_bus <= fnDati(dram0_instr,dram0_addr,rdat0);
7593 50 robfinch
        if (dram0_store)        $display("m[%h] <- %h", dram0_addr, dram0_data);
7594 48 robfinch
end
7595
//    else
7596
//      dramA_v <= `INV;
7597 49 robfinch
if (mem2_available && dram1 == `DRAMREQ_READY && `NUM_MEM > 1) begin
7598 48 robfinch
        dram1 <= `DRAMSLOT_AVAIL;
7599 59 robfinch
        dramB_v <= dram1_load && !iqentry_stomp[dram1_id[`QBITS]];
7600 48 robfinch
        dramB_id <= dram1_id;
7601
        dramB_exc <= dram1_exc;
7602
        dramB_bus <= fnDati(dram1_instr,dram1_addr,rdat1);
7603 50 robfinch
        if (dram1_store)     $display("m[%h] <- %h", dram1_addr, dram1_data);
7604 48 robfinch
end
7605
//    else
7606
//      dramB_v <= `INV;
7607 49 robfinch
if (mem3_available && dram2 == `DRAMREQ_READY && `NUM_MEM > 2) begin
7608 48 robfinch
        dram2 <= `DRAMSLOT_AVAIL;
7609 59 robfinch
        dramC_v <= dram2_load && !iqentry_stomp[dram2_id[`QBITS]];
7610 48 robfinch
        dramC_id <= dram2_id;
7611
        dramC_exc <= dram2_exc;
7612
        dramC_bus <= fnDati(dram2_instr,dram2_addr,rdat2);
7613 50 robfinch
        if (dram2_store)     $display("m[%h] <- %h", dram2_addr, dram2_data);
7614 48 robfinch
end
7615 59 robfinch
/*
7616
// Squash load results for stomped on instructions
7617
begin
7618
        if (iqentry_stomp[dram0_id[`QBITS]])
7619
                dram0_load <= `FALSE;
7620
        if (`NUM_MEM > 1)
7621
                if (iqentry_stomp[dram1_id[`QBITS]])
7622
                        dram1_load <= `FALSE;
7623
        if (`NUM_MEM > 2)
7624
                if (iqentry_stomp[dram2_id[`QBITS]])
7625
                        dram2_load <= `FALSE;
7626
end
7627
*/
7628
 
7629 48 robfinch
//    else
7630
//      dramC_v <= `INV;
7631
 
7632
        //
7633
        // determine if the instructions ready to issue can, in fact, issue.
7634
        // "ready" means that the instruction has valid operands but has not gone yet
7635
        iqentry_memissue <= memissue;
7636
        missue_count <= issue_count;
7637
 
7638
 
7639
        //
7640
        // take requests that are ready and put them into DRAM slots
7641
 
7642
        if (dram0 == `DRAMSLOT_AVAIL)    dram0_exc <= `FLT_NONE;
7643
        if (dram1 == `DRAMSLOT_AVAIL)    dram1_exc <= `FLT_NONE;
7644
        if (dram2 == `DRAMSLOT_AVAIL)    dram2_exc <= `FLT_NONE;
7645
 
7646
        for (n = 0; n < QENTRIES; n = n + 1)
7647
                if (iqentry_v[n] && iqentry_stomp[n]) begin
7648
                        iqentry_v[n] <= `INV;
7649
                        iqentry_iv[n] <= `INV;
7650
                        if (dram0_id[`QBITS] == n[`QBITS])  dram0 <= `DRAMSLOT_AVAIL;
7651
                        if (dram1_id[`QBITS] == n[`QBITS])  dram1 <= `DRAMSLOT_AVAIL;
7652
                        if (dram2_id[`QBITS] == n[`QBITS])  dram2 <= `DRAMSLOT_AVAIL;
7653
                end
7654
 
7655 53 robfinch
        last_issue = QENTRIES;
7656 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
7657 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7658
            if (mem1_available && dram0 == `DRAMSLOT_AVAIL) begin
7659 48 robfinch
                dramA_v <= `INV;
7660
             dram0              <= `DRAMSLOT_BUSY;
7661
             dram0_id   <= { 1'b1, n[`QBITS] };
7662
             dram0_instr <= iqentry_instr[n];
7663
             dram0_rmw  <= iqentry_rmw[n];
7664
             dram0_preload <= iqentry_preload[n];
7665
             dram0_tgt  <= iqentry_tgt[n];
7666
             dram0_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7667
             dram0_addr <= iqentry_a1[n];
7668
//             if (ol[iqentry_thrd[n]]==`OL_USER)
7669
//              dram0_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7670
//             else
7671 50 robfinch
             dram0_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7672
             dram0_memsize <= iqentry_memsz[n];
7673 48 robfinch
             dram0_load <= iqentry_load[n];
7674 50 robfinch
             dram0_store <= iqentry_store[n];
7675 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]];
7676
             // Once the memory op is issued reset the a1_v flag.
7677
             // This will cause the a1 bus to look for new data from memory (a1_s is pointed to a memory bus)
7678
             // This is used for the load and compare instructions.
7679
             iqentry_a1_v[n] <= `INV;
7680
             last_issue = n;
7681
            end
7682
        end
7683 53 robfinch
    if (last_issue < QENTRIES)
7684 48 robfinch
        iqentry_out[last_issue] <= `VAL;
7685
    for (n = 0; n < QENTRIES; n = n + 1)
7686 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7687
                if (mem2_available && n < last_issue && `NUM_MEM > 1) begin
7688 48 robfinch
                    if (dram1 == `DRAMSLOT_AVAIL) begin
7689
                        dramB_v <= `INV;
7690
                     dram1              <= `DRAMSLOT_BUSY;
7691
                     dram1_id   <= { 1'b1, n[`QBITS] };
7692
                     dram1_instr <= iqentry_instr[n];
7693
                     dram1_rmw  <= iqentry_rmw[n];
7694
                     dram1_preload <= iqentry_preload[n];
7695
                     dram1_tgt  <= iqentry_tgt[n];
7696
                     dram1_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7697
                     dram1_addr <= iqentry_a1[n];
7698
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
7699
//                      dram1_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7700
//                   else
7701 50 robfinch
                     dram1_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7702
                     dram1_memsize <= iqentry_memsz[n];
7703 48 robfinch
                     dram1_load <= iqentry_load[n];
7704 50 robfinch
                     dram1_store <= iqentry_store[n];
7705 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]];
7706
                     iqentry_a1_v[n] <= `INV;
7707
                     last_issue = n;
7708
                    end
7709
                end
7710
        end
7711 53 robfinch
    if (last_issue < QENTRIES)
7712 48 robfinch
        iqentry_out[last_issue] <= `VAL;
7713
    for (n = 0; n < QENTRIES; n = n + 1)
7714 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7715
                if (mem3_available && n < last_issue && `NUM_MEM > 2) begin
7716 48 robfinch
                    if (dram2 == `DRAMSLOT_AVAIL) begin
7717
                        dramC_v <= `INV;
7718
                     dram2              <= `DRAMSLOT_BUSY;
7719
                     dram2_id   <= { 1'b1, n[`QBITS] };
7720
                     dram2_instr        <= iqentry_instr[n];
7721
                     dram2_rmw  <= iqentry_rmw[n];
7722
                     dram2_preload <= iqentry_preload[n];
7723
                     dram2_tgt  <= iqentry_tgt[n];
7724
                     dram2_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7725
                     dram2_addr <= iqentry_a1[n];
7726
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
7727
//                      dram2_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7728
//                   else
7729 50 robfinch
                     dram2_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7730
                     dram2_memsize <= iqentry_memsz[n];
7731 48 robfinch
                     dram2_load <= iqentry_load[n];
7732 50 robfinch
                     dram2_store <= iqentry_store[n];
7733 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]];
7734
                     iqentry_a1_v[n] <= `INV;
7735
                    end
7736
                end
7737
        end
7738 53 robfinch
    if (last_issue < QENTRIES)
7739 48 robfinch
        iqentry_out[last_issue] <= `VAL;
7740
 
7741 51 robfinch
for (n = 0; n < QENTRIES; n = n + 1)
7742
begin
7743
        if (!iqentry_v[n])
7744
                iqentry_done[n] <= FALSE;
7745
end
7746 48 robfinch
 
7747
 
7748
 
7749 49 robfinch
//
7750
// COMMIT PHASE (dequeue only ... not register-file update)
7751
//
7752
// look at head0 and head1 and let 'em write to the register file if they are ready
7753
//
7754 48 robfinch
//    always @(posedge clk) begin: commit_phase
7755
 
7756 49 robfinch
oddball_commit(commit0_v, head0);
7757
if (`NUM_CMT > 1)
7758
        oddball_commit(commit1_v, head1);
7759 58 robfinch
if (`NUM_CMT > 2)
7760
        oddball_commit(commit2_v, head2);
7761 50 robfinch
//if (`NUM_CMT > 2)
7762
//      oddball_commit(commit2_v, head2);
7763 48 robfinch
 
7764
// Fetch and queue are limited to two instructions per cycle, so we might as
7765
// well limit retiring to two instructions max to conserve logic.
7766
//
7767
if (~|panic)
7768 49 robfinch
  casez ({ iqentry_v[head0],
7769
                iqentry_cmt[head0],
7770
                iqentry_v[head1],
7771
                iqentry_cmt[head1],
7772
                iqentry_v[head2],
7773
                iqentry_cmt[head2]})
7774 48 robfinch
 
7775
        // retire 3
7776 49 robfinch
        6'b0?_0?_0?:
7777
                if (head0 != tail0 && head1 != tail0 && head2 != tail0) begin
7778
                                head_inc(3);
7779
                end
7780
                else if (head0 != tail0 && head1 != tail0) begin
7781 48 robfinch
                    head_inc(2);
7782
                end
7783
                else if (head0 != tail0) begin
7784
                    head_inc(1);
7785
                end
7786 49 robfinch
        6'b0?_0?_10:    ;
7787
        6'b0?_0?_11:
7788
                if (`NUM_CMT > 2 || iqentry_tgt[head2][4:0]==5'd0) begin
7789
      iqentry_v[head2] <= `INV;
7790
      head_inc(3);
7791
                end
7792
                else begin
7793
      head_inc(2);
7794
                end
7795 48 robfinch
 
7796
        // retire 1 (wait for regfile for head1)
7797 49 robfinch
        6'b0?_10_??:
7798
                head_inc(1);
7799 48 robfinch
 
7800
        // retire 2
7801 49 robfinch
        6'b0?_11_0?,
7802
        6'b0?_11_10:
7803
        if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7804
          iqentry_v[head1] <= `INV;
7805
          head_inc(2);
7806 48 robfinch
        end
7807 49 robfinch
        else begin
7808
                head_inc(1);
7809
        end
7810
  6'b0?_11_11:
7811 50 robfinch
        if (`NUM_CMT > 2 || (`NUM_CMT > 1 && iqentry_tgt[head2] == 12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7812 49 robfinch
                iqentry_v[head1] <= `INV;
7813
          iqentry_v[head2] <= `INV;
7814
                head_inc(3);
7815
        end
7816
        else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7817
                iqentry_v[head1] <= `INV;
7818
                head_inc(2);
7819
        end
7820
        else
7821
                head_inc(1);
7822
  6'b10_??_??:  ;
7823
  6'b11_0?_0?:
7824
        if (head1 != tail0 && head2 != tail0) begin
7825 48 robfinch
                        iqentry_v[head0] <= `INV;
7826 49 robfinch
                        head_inc(3);
7827
        end
7828
        else if (head1 != tail0) begin
7829
                        iqentry_v[head0] <= `INV;
7830 48 robfinch
                        head_inc(2);
7831 49 robfinch
        end
7832
        else begin
7833 48 robfinch
                        iqentry_v[head0] <= `INV;
7834
                        head_inc(1);
7835 49 robfinch
        end
7836
  6'b11_0?_10:
7837
        if (head1 != tail0) begin
7838
                        iqentry_v[head0] <= `INV;
7839
                        head_inc(2);
7840
        end
7841
        else begin
7842
                        iqentry_v[head0] <= `INV;
7843
                        head_inc(1);
7844
        end
7845
  6'b11_0?_11:
7846
        if (head1 != tail0) begin
7847 50 robfinch
                if (`NUM_CMT > 2 || (iqentry_tgt[head2]==12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7848 49 robfinch
                                iqentry_v[head0] <= `INV;
7849
                                iqentry_v[head2] <= `INV;
7850
                                head_inc(3);
7851
                end
7852
                else begin
7853
                                iqentry_v[head0] <= `INV;
7854
                                head_inc(2);
7855
                        end
7856
        end
7857
        else begin
7858
                        iqentry_v[head0] <= `INV;
7859
                        head_inc(1);
7860
        end
7861
  6'b11_10_??:
7862
        begin
7863
                        iqentry_v[head0] <= `INV;
7864
                        head_inc(1);
7865
        end
7866
  6'b11_11_0?:
7867
        if (`NUM_CMT > 1 && head2 != tail0) begin
7868
                        iqentry_v[head0] <= `INV;
7869
                        iqentry_v[head1] <= `INV;
7870
                        head_inc(3);
7871
        end
7872
        else if (iqentry_tgt[head1]== 12'd0 && head2 != tail0) begin
7873
                        iqentry_v[head0] <= `INV;
7874
                        iqentry_v[head1] <= `INV;
7875
                        head_inc(3);
7876
        end
7877
        else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7878
                        iqentry_v[head0] <= `INV;
7879
                        iqentry_v[head1] <= `INV;
7880
                        head_inc(2);
7881
        end
7882
        else begin
7883
                        iqentry_v[head0] <= `INV;
7884
                        head_inc(1);
7885
        end
7886
  6'b11_11_10:
7887
        if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7888
                        iqentry_v[head0] <= `INV;
7889
                        iqentry_v[head1] <= `INV;
7890
                        head_inc(2);
7891
        end
7892
        else begin
7893
                        iqentry_v[head0] <= `INV;
7894
                        head_inc(1);
7895
        end
7896
        6'b11_11_11:
7897 50 robfinch
                if (`NUM_CMT > 2 || (`NUM_CMT > 1 && iqentry_tgt[head2]==12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7898 49 robfinch
                        iqentry_v[head0] <= `INV;
7899
                        iqentry_v[head1] <= `INV;
7900
                        iqentry_v[head2] <= `INV;
7901
                        head_inc(3);
7902 48 robfinch
                end
7903 49 robfinch
                else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7904 48 robfinch
                        iqentry_v[head0] <= `INV;
7905 49 robfinch
                        iqentry_v[head1] <= `INV;
7906
                        head_inc(2);
7907
                end
7908
                else begin
7909
                        iqentry_v[head0] <= `INV;
7910 48 robfinch
                        head_inc(1);
7911
                end
7912 49 robfinch
  endcase
7913 48 robfinch
 
7914
 
7915 55 robfinch
rf_source[0] <= 0;
7916
L1_wr0 <= FALSE;
7917
L1_wr1 <= FALSE;
7918
L1_wr2 <= FALSE;
7919
L1_invline <= FALSE;
7920
icnxt <= FALSE;
7921
L2_nxt <= FALSE;
7922 48 robfinch
// Instruction cache state machine.
7923
// On a miss first see if the instruction is in the L2 cache. No need to go to
7924
// the BIU on an L1 miss.
7925
// If not the machine will wait until the BIU loads the L2 cache.
7926
 
7927
// Capture the previous ic state, used to determine how long to wait in
7928
// icstate #4.
7929 55 robfinch
picstate <= icstate;
7930 48 robfinch
case(icstate)
7931
IDLE:
7932
        // If the bus unit is busy doing an update involving L1_adr or L2_adr
7933
        // we have to wait.
7934 59 robfinch
        if (bstate != B_ICacheAck && bstate != B_ICacheNack) begin
7935 48 robfinch
                if (!ihit0) begin
7936 55 robfinch
                        L1_adr <= {pcr[5:0],pc0[31:5],5'h0};
7937
                        L2_adr <= {pcr[5:0],pc0[31:5],5'h0};
7938 48 robfinch
                        L1_invline <= TRUE;
7939 49 robfinch
                        icwhich <= 2'b00;
7940 48 robfinch
                        iccnt <= 3'b00;
7941
                        icstate <= IC2;
7942
                end
7943 49 robfinch
                else if (!ihit1 && `WAYS > 1) begin
7944 55 robfinch
                        if (thread_en) begin
7945
                                L1_adr <= {pcr[5:0],pc1[31:5],5'h0};
7946
                                L2_adr <= {pcr[5:0],pc1[31:5],5'h0};
7947
                        end
7948
                        else begin
7949
                                L1_adr <= {pcr[5:0],pc0plus6[31:5],5'h0};
7950
                                L2_adr <= {pcr[5:0],pc0plus6[31:5],5'h0};
7951
                        end
7952 48 robfinch
                        L1_invline <= TRUE;
7953 49 robfinch
                        icwhich <= 2'b01;
7954 48 robfinch
                        iccnt <= 3'b00;
7955
                        icstate <= IC2;
7956
                end
7957 49 robfinch
                else if (!ihit2 && `WAYS > 2) begin
7958 55 robfinch
                        if (thread_en) begin
7959
                                L1_adr <= {pcr[5:0],pc2[31:5],5'h0};
7960
                                L2_adr <= {pcr[5:0],pc2[31:5],5'h0};
7961
                        end
7962
                        else begin
7963
                                L1_adr <= {pcr[5:0],pc0plus12[31:5],5'h0};
7964
                                L2_adr <= {pcr[5:0],pc0plus12[31:5],5'h0};
7965
                        end
7966 49 robfinch
                        L1_invline <= TRUE;
7967
                        icwhich <= 2'b10;
7968
                        iccnt <= 3'b00;
7969
                        icstate <= IC2;
7970
                end
7971 48 robfinch
        end
7972
IC2:     icstate <= IC3;
7973
IC3:     icstate <= IC3a;
7974 59 robfinch
IC3a:     icstate <= IC_WaitL2;
7975
// If data was in the L2 cache already there's no need to wait on the
7976
// BIU to retrieve data. It can be determined if the hit signal was
7977
// already active when this state was entered in which case waiting
7978
// will do no good.
7979
// The IC machine will stall in this state until the BIU has loaded the
7980
// L2 cache. 
7981
IC_WaitL2:
7982 49 robfinch
        if (ihitL2 && picstate==IC3a) begin
7983
                L1_en <= 9'h1FF;
7984 48 robfinch
                L1_wr0 <= TRUE;
7985 49 robfinch
                L1_wr1 <= TRUE && `WAYS > 1;
7986
                L1_wr2 <= TRUE && `WAYS > 2;
7987 48 robfinch
                L1_adr <= L2_adr;
7988
                L2_rdat <= L2_dato;
7989
                icstate <= IC5;
7990
        end
7991 59 robfinch
        else if (bstate!=B_ICacheNack)
7992 48 robfinch
                ;
7993
        else begin
7994 49 robfinch
                L1_en <= 9'h1FF;
7995 48 robfinch
                L1_wr0 <= TRUE;
7996 49 robfinch
                L1_wr1 <= TRUE && `WAYS > 1;
7997
                L1_wr2 <= TRUE && `WAYS > 2;
7998 48 robfinch
                L1_adr <= L2_adr;
7999 59 robfinch
                // L2_rdat set below while loading cache line
8000
                //L2_rdat <= L2_dato;
8001 48 robfinch
                icstate <= IC5;
8002
        end
8003
IC5:
8004
        begin
8005 49 robfinch
                L1_en <= 9'h000;
8006 48 robfinch
                L1_wr0 <= FALSE;
8007
                L1_wr1 <= FALSE;
8008 49 robfinch
                L1_wr2 <= FALSE;
8009 48 robfinch
                icstate <= IC6;
8010
        end
8011
IC6:  icstate <= IC7;
8012 59 robfinch
IC7:    icstate <= IC_Next;
8013
IC_Next:
8014
  begin
8015
   icstate <= IDLE;
8016
   icnxt <= TRUE;
8017
        end
8018 48 robfinch
default:     icstate <= IDLE;
8019
endcase
8020
 
8021 49 robfinch
if (mem1_available && dram0_load)
8022 48 robfinch
case(dram0)
8023
`DRAMSLOT_AVAIL:        ;
8024 59 robfinch
`DRAMSLOT_BUSY:
8025
        dram0 <= dram0 + !dram0_unc;
8026
3'd2:
8027
        dram0 <= dram0 + 3'd1;
8028
3'd3:
8029
        dram0 <= dram0 + 3'd1;
8030
3'd4:
8031
        if (iqentry_v[dram0_id[`QBITS]] && !iqentry_stomp[dram0_id[`QBITS]]) begin
8032
                if (dhit0)
8033
                        dram0 <= `DRAMREQ_READY;
8034
                else
8035
                        dram0 <= `DRAMSLOT_REQBUS;
8036
        end
8037
        else begin
8038
                dram0 <= `DRAMSLOT_AVAIL;
8039
                dram0_load <= `FALSE;
8040
        end
8041 48 robfinch
`DRAMSLOT_REQBUS:       ;
8042
`DRAMSLOT_HASBUS:       ;
8043
`DRAMREQ_READY:         ;
8044
endcase
8045
 
8046 49 robfinch
if (mem2_available && dram1_load && `NUM_MEM > 1)
8047 48 robfinch
case(dram1)
8048
`DRAMSLOT_AVAIL:        ;
8049 59 robfinch
`DRAMSLOT_BUSY:
8050
        dram1 <= dram1 + !dram1_unc;
8051
3'd2:
8052
        dram1 <= dram1 + 3'd1;
8053
3'd3:
8054
        dram1 <= dram1 + 3'd1;
8055
3'd4:
8056
        if (iqentry_v[dram1_id[`QBITS]] && !iqentry_stomp[dram1_id[`QBITS]]) begin
8057
                if (dhit1)
8058
                        dram1 <= `DRAMREQ_READY;
8059
                else
8060
                        dram1 <= `DRAMSLOT_REQBUS;
8061
        end
8062
        else begin
8063
                dram1 <= `DRAMSLOT_AVAIL;
8064
                dram1_load <= `FALSE;
8065
        end
8066 48 robfinch
`DRAMSLOT_REQBUS:       ;
8067
`DRAMSLOT_HASBUS:       ;
8068
`DRAMREQ_READY:         ;
8069
endcase
8070
 
8071 49 robfinch
if (mem3_available && dram2_load && `NUM_MEM > 2)
8072 48 robfinch
case(dram2)
8073
`DRAMSLOT_AVAIL:        ;
8074 59 robfinch
`DRAMSLOT_BUSY:
8075
        dram2 <= dram2 + !dram2_unc;
8076
3'd2:
8077
        dram2 <= dram2 + 3'd1;
8078
3'd3:
8079
        dram2 <= dram2 + 3'd1;
8080
3'd4:
8081
        if (iqentry_v[dram2_id[`QBITS]] && !iqentry_stomp[dram2_id[`QBITS]]) begin
8082
                if (dhit2)
8083
                        dram2 <= `DRAMREQ_READY;
8084
                else
8085
                        dram2 <= `DRAMSLOT_REQBUS;
8086
        end
8087
        else begin
8088
                dram2 <= `DRAMSLOT_AVAIL;
8089
                dram2_load <= `FALSE;
8090
        end
8091 48 robfinch
`DRAMSLOT_REQBUS:       ;
8092
`DRAMSLOT_HASBUS:       ;
8093
`DRAMREQ_READY:         ;
8094
endcase
8095
 
8096
// Bus Interface Unit (BIU)
8097
// Interfaces to the external bus which is WISHBONE compatible.
8098
// Stores take precedence over other operations.
8099
// Next data cache read misses are serviced.
8100
// Uncached data reads are serviced.
8101
// Finally L2 instruction cache misses are serviced.
8102
 
8103
case(bstate)
8104
BIDLE:
8105 49 robfinch
        begin
8106
                isCAS <= FALSE;
8107
                isAMO <= FALSE;
8108
                isInc <= FALSE;
8109
                isSpt <= FALSE;
8110
                isRMW <= FALSE;
8111
                rdvq <= 1'b0;
8112
                errq <= 1'b0;
8113
                exvq <= 1'b0;
8114
                bwhich <= 2'b00;
8115
                preload <= FALSE;
8116
`ifdef HAS_WB
8117
                if (wb_v[0] & wb_en) begin
8118
                        cyc_o <= `HIGH;
8119
                        stb_o <= `HIGH;
8120
                        we_o <= `HIGH;
8121
                        sel_o <= wb_sel[0];
8122
                        adr_o <= wb_addr[0];
8123
                        dat_o <= wb_data[0];
8124
                        ol_o  <= wb_ol[0];
8125
                        wbo_id <= wb_id[0];
8126 57 robfinch
        isStore <= TRUE;
8127 58 robfinch
                        bstate <= wb_rmw[0] ? B12 : B_DCacheStoreAck;
8128 49 robfinch
                end
8129
                begin
8130
                        for (j = 1; j < `WB_DEPTH; j = j + 1) begin
8131
                wb_v[j-1] <= wb_v[j];
8132
                wb_id[j-1] <= wb_id[j];
8133
                wb_rmw[j-1] <= wb_rmw[j];
8134
                wb_sel[j-1] <= wb_sel[j];
8135
                wb_addr[j-1] <= wb_addr[j];
8136
                wb_data[j-1] <= wb_data[j];
8137
                wb_ol[j-1] <= wb_ol[j];
8138
        end
8139
        wb_v[`WB_DEPTH-1] <= `INV;
8140
        wb_rmw[`WB_DEPTH-1] <= `FALSE;
8141
    end
8142
 
8143
`endif
8144
      if (~|wb_v && mem1_available && dram0==`DRAMSLOT_BUSY && dram0_rmw) begin
8145 48 robfinch
`ifdef SUPPORT_DBG
8146
            if (dbg_smatch0|dbg_lmatch0) begin
8147
                 dramA_v <= `TRUE;
8148
                 dramA_id <= dram0_id;
8149
                 dramA_exc <= `FLT_DBG;
8150
                 dramA_bus <= 64'h0;
8151
                 dram0 <= `DRAMSLOT_AVAIL;
8152
            end
8153
            else
8154
`endif
8155
            begin
8156
                 isRMW <= dram0_rmw;
8157
                 isCAS <= IsCAS(dram0_instr);
8158
                 isAMO <= IsAMO(dram0_instr);
8159
                 isInc <= IsInc(dram0_instr);
8160
                 casid <= dram0_id;
8161
                 bwhich <= 2'b00;
8162 49 robfinch
                 dram0 <= `DRAMSLOT_HASBUS;
8163 48 robfinch
                 cyc_o <= `HIGH;
8164
                 stb_o <= `HIGH;
8165
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
8166
                 adr_o <= dram0_addr;
8167
                 dat_o <= fnDato(dram0_instr,dram0_data);
8168
                 ol_o  <= dram0_ol;
8169
                 bstate <= B12;
8170
            end
8171
        end
8172 49 robfinch
        else if (~|wb_v && mem2_available && dram1==`DRAMSLOT_BUSY && dram1_rmw && `NUM_MEM > 1) begin
8173 48 robfinch
`ifdef SUPPORT_DBG
8174
            if (dbg_smatch1|dbg_lmatch1) begin
8175
                 dramB_v <= `TRUE;
8176
                 dramB_id <= dram1_id;
8177
                 dramB_exc <= `FLT_DBG;
8178
                 dramB_bus <= 64'h0;
8179
                 dram1 <= `DRAMSLOT_AVAIL;
8180
            end
8181
            else
8182
`endif
8183
            begin
8184
                 isRMW <= dram1_rmw;
8185
                 isCAS <= IsCAS(dram1_instr);
8186
                 isAMO <= IsAMO(dram1_instr);
8187
                 isInc <= IsInc(dram1_instr);
8188
                 casid <= dram1_id;
8189
                 bwhich <= 2'b01;
8190 49 robfinch
                 dram1 <= `DRAMSLOT_HASBUS;
8191 48 robfinch
                 cyc_o <= `HIGH;
8192
                 stb_o <= `HIGH;
8193
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
8194
                 adr_o <= dram1_addr;
8195
                 dat_o <= fnDato(dram1_instr,dram1_data);
8196
                 ol_o  <= dram1_ol;
8197
                 bstate <= B12;
8198
            end
8199
        end
8200 49 robfinch
        else if (~|wb_v && mem3_available && dram2==`DRAMSLOT_BUSY && dram2_rmw && `NUM_MEM > 2) begin
8201 48 robfinch
`ifdef SUPPORT_DBG
8202
            if (dbg_smatch2|dbg_lmatch2) begin
8203
                 dramC_v <= `TRUE;
8204
                 dramC_id <= dram2_id;
8205
                 dramC_exc <= `FLT_DBG;
8206
                 dramC_bus <= 64'h0;
8207
                 dram2 <= `DRAMSLOT_AVAIL;
8208
            end
8209
            else
8210
`endif
8211
            begin
8212
                 isRMW <= dram2_rmw;
8213
                 isCAS <= IsCAS(dram2_instr);
8214
                 isAMO <= IsAMO(dram2_instr);
8215
                 isInc <= IsInc(dram2_instr);
8216
                 casid <= dram2_id;
8217
                 bwhich <= 2'b10;
8218 49 robfinch
                 dram2 <= `DRAMSLOT_HASBUS;
8219 48 robfinch
                 cyc_o <= `HIGH;
8220
                 stb_o <= `HIGH;
8221
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
8222
                 adr_o <= dram2_addr;
8223
                 dat_o <= fnDato(dram2_instr,dram2_data);
8224
                 ol_o  <= dram2_ol;
8225
                 bstate <= B12;
8226
            end
8227
        end
8228 50 robfinch
        else if (mem1_available && dram0==`DRAMSLOT_BUSY && dram0_store) begin
8229 48 robfinch
`ifdef SUPPORT_DBG
8230
            if (dbg_smatch0) begin
8231
                 dramA_v <= `TRUE;
8232
                 dramA_id <= dram0_id;
8233
                 dramA_exc <= `FLT_DBG;
8234
                 dramA_bus <= 64'h0;
8235
                 dram0 <= `DRAMSLOT_AVAIL;
8236
            end
8237
            else
8238
`endif
8239
            begin
8240 49 robfinch
                                                        bwhich <= 2'b00;
8241
`ifndef HAS_WB
8242
                                                        dram0 <= `DRAMSLOT_HASBUS;
8243
                                                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
8244
                 cyc_o <= `HIGH;
8245
                 stb_o <= `HIGH;
8246 48 robfinch
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
8247
                 adr_o <= dram0_addr;
8248
                 dat_o <= fnDato(dram0_instr,dram0_data);
8249
                 ol_o  <= dram0_ol;
8250 57 robfinch
                                        isStore <= TRUE;
8251 58 robfinch
                 bstate <= B_DCacheStoreAck;
8252 49 robfinch
`else
8253
                                                                if (wbptr<`WB_DEPTH-1) begin
8254
                                                                        dram0 <= `DRAMREQ_READY;
8255
                                                                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
8256
                                                                        wb_update(
8257
                                                                                dram0_id,
8258
                                                                                `FALSE,
8259
                                                                                fnSelect(dram0_instr,dram0_addr),
8260
                                                                                dram0_ol,
8261
                                                                                dram0_addr,
8262
                                                                                fnDato(dram0_instr,dram0_data)
8263
                                                                        );
8264
                                                                        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
8265
                                                                        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
8266
                                                                end
8267
`endif
8268
//                 cr_o <= IsSWC(dram0_instr);
8269 48 robfinch
            end
8270
        end
8271 50 robfinch
        else if (mem2_available && dram1==`DRAMSLOT_BUSY && dram1_store && `NUM_MEM > 1) begin
8272 48 robfinch
`ifdef SUPPORT_DBG
8273
            if (dbg_smatch1) begin
8274
                 dramB_v <= `TRUE;
8275
                 dramB_id <= dram1_id;
8276
                 dramB_exc <= `FLT_DBG;
8277
                 dramB_bus <= 64'h0;
8278
                 dram1 <= `DRAMSLOT_AVAIL;
8279
            end
8280
            else
8281
`endif
8282
            begin
8283 49 robfinch
                 bwhich <= 2'b01;
8284
`ifndef HAS_WB
8285 48 robfinch
                 dram1 <= `DRAMSLOT_HASBUS;
8286
                 dram1_instr[`INSTRUCTION_OP] <= `NOP;
8287 49 robfinch
                 cyc_o <= `HIGH;
8288
                 stb_o <= `HIGH;
8289 48 robfinch
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
8290
                 adr_o <= dram1_addr;
8291
                 dat_o <= fnDato(dram1_instr,dram1_data);
8292
                 ol_o  <= dram1_ol;
8293 57 robfinch
                                        isStore <= TRUE;
8294 58 robfinch
                 bstate <= B_DCacheStoreAck;
8295 49 robfinch
`else
8296
                                                                if (wbptr<`WB_DEPTH-1) begin
8297
                                                                        dram1 <= `DRAMREQ_READY;
8298
                        dram1_instr[`INSTRUCTION_OP] <= `NOP;
8299
                                                                        wb_update(
8300
                                                                                dram1_id,
8301
                                                                                `FALSE,
8302
                                                                                fnSelect(dram1_instr,dram1_addr),
8303
                                                                                dram1_ol,
8304
                                                                                dram1_addr,
8305
                                                                                fnDato(dram1_instr,dram1_data)
8306
                                                                        );
8307
                                                                        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
8308
                                                                        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
8309
                                                                end
8310
`endif
8311
//                 cr_o <= IsSWC(dram0_instr);
8312 48 robfinch
            end
8313
        end
8314 50 robfinch
        else if (mem3_available && dram2==`DRAMSLOT_BUSY && dram2_store && `NUM_MEM > 2) begin
8315 48 robfinch
`ifdef SUPPORT_DBG
8316
            if (dbg_smatch2) begin
8317
                 dramC_v <= `TRUE;
8318
                 dramC_id <= dram2_id;
8319
                 dramC_exc <= `FLT_DBG;
8320
                 dramC_bus <= 64'h0;
8321
                 dram2 <= `DRAMSLOT_AVAIL;
8322
            end
8323
            else
8324
`endif
8325
            begin
8326 49 robfinch
                 bwhich <= 2'b10;
8327
`ifndef HAS_WB
8328 48 robfinch
                 dram2 <= `DRAMSLOT_HASBUS;
8329
                 dram2_instr[`INSTRUCTION_OP] <= `NOP;
8330 49 robfinch
                 cyc_o <= `HIGH;
8331
                 stb_o <= `HIGH;
8332 48 robfinch
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
8333
                 adr_o <= dram2_addr;
8334
                 dat_o <= fnDato(dram2_instr,dram2_data);
8335
                 ol_o  <= dram2_ol;
8336 57 robfinch
                                        isStore <= TRUE;
8337 58 robfinch
                 bstate <= B_DCacheStoreAck;
8338 49 robfinch
`else
8339
                                                                if (wbptr<`WB_DEPTH-1) begin
8340
                                                                        dram2 <= `DRAMREQ_READY;
8341
                        dram2_instr[`INSTRUCTION_OP] <= `NOP;
8342
                                                                        wb_update(
8343
                                                                                dram2_id,
8344
                                                                                `FALSE,
8345
                                                                                fnSelect(dram2_instr,dram2_addr),
8346
                                                                                dram2_ol,
8347
                                                                                dram2_addr,
8348
                                                                                fnDato(dram2_instr,dram2_data)
8349
                                                                        );
8350
                                                                        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
8351
                                                                        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
8352
                                                                end
8353
`endif
8354
//                 cr_o <= IsSWC(dram0_instr);
8355 48 robfinch
            end
8356
        end
8357
        // Check for read misses on the data cache
8358 51 robfinch
        else if (~|wb_v && mem1_available && !dram0_unc && dram0==`DRAMSLOT_REQBUS && dram0_load) begin
8359 48 robfinch
`ifdef SUPPORT_DBG
8360
            if (dbg_lmatch0) begin
8361
                 dramA_v <= `TRUE;
8362
                 dramA_id <= dram0_id;
8363
                 dramA_exc <= `FLT_DBG;
8364
                 dramA_bus <= 64'h0;
8365
                 dram0 <= `DRAMSLOT_AVAIL;
8366
            end
8367
            else
8368
`endif
8369
            begin
8370
                 dram0 <= `DRAMSLOT_HASBUS;
8371
                 bwhich <= 2'b00;
8372
                 preload <= dram0_preload;
8373 58 robfinch
                 bstate <= B_DCacheLoadStart;
8374 48 robfinch
            end
8375
        end
8376 49 robfinch
        else if (~|wb_v && mem2_available && !dram1_unc && dram1==`DRAMSLOT_REQBUS && dram1_load && `NUM_MEM > 1) begin
8377 48 robfinch
`ifdef SUPPORT_DBG
8378
            if (dbg_lmatch1) begin
8379
                 dramB_v <= `TRUE;
8380
                 dramB_id <= dram1_id;
8381
                 dramB_exc <= `FLT_DBG;
8382
                 dramB_bus <= 64'h0;
8383
                 dram1 <= `DRAMSLOT_AVAIL;
8384
            end
8385
            else
8386
`endif
8387
            begin
8388
                 dram1 <= `DRAMSLOT_HASBUS;
8389
                 bwhich <= 2'b01;
8390
                 preload <= dram1_preload;
8391 58 robfinch
                 bstate <= B_DCacheLoadStart;
8392 48 robfinch
            end
8393
        end
8394 49 robfinch
        else if (~|wb_v && mem3_available && !dram2_unc && dram2==`DRAMSLOT_REQBUS && dram2_load && `NUM_MEM > 2) begin
8395 48 robfinch
`ifdef SUPPORT_DBG
8396
            if (dbg_lmatch2) begin
8397
                 dramC_v <= `TRUE;
8398
                 dramC_id <= dram2_id;
8399
                 dramC_exc <= `FLT_DBG;
8400
                 dramC_bus <= 64'h0;
8401
                 dram2 <= `DRAMSLOT_AVAIL;
8402
            end
8403
            else
8404
`endif
8405
            begin
8406
                 dram2 <= `DRAMSLOT_HASBUS;
8407
                 preload <= dram2_preload;
8408
                 bwhich <= 2'b10;
8409 58 robfinch
                 bstate <= B_DCacheLoadStart;
8410 48 robfinch
            end
8411
        end
8412 49 robfinch
        else if (~|wb_v && mem1_available && dram0_unc && dram0==`DRAMSLOT_BUSY && dram0_load) begin
8413 48 robfinch
`ifdef SUPPORT_DBG
8414
            if (dbg_lmatch0) begin
8415
                 dramA_v <= `TRUE;
8416
                 dramA_id <= dram0_id;
8417
                 dramA_exc <= `FLT_DBG;
8418
                 dramA_bus <= 64'h0;
8419
                 dram0 <= `DRAMSLOT_AVAIL;
8420
            end
8421
            else
8422
`endif
8423
            begin
8424
                 bwhich <= 2'b00;
8425
                 cyc_o <= `HIGH;
8426
                 stb_o <= `HIGH;
8427
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
8428
                 adr_o <= {dram0_addr[31:3],3'b0};
8429
                 sr_o <=  IsLWR(dram0_instr);
8430
                 ol_o  <= dram0_ol;
8431
                 bstate <= B12;
8432
            end
8433
        end
8434 49 robfinch
        else if (~|wb_v && mem2_available && dram1_unc && dram1==`DRAMSLOT_BUSY && dram1_load && `NUM_MEM > 1) begin
8435 48 robfinch
`ifdef SUPPORT_DBG
8436
            if (dbg_lmatch1) begin
8437
                 dramB_v <= `TRUE;
8438
                 dramB_id <= dram1_id;
8439
                 dramB_exc <= `FLT_DBG;
8440
                 dramB_bus <= 64'h0;
8441
                 dram1 <= `DRAMSLOT_AVAIL;
8442
            end
8443
            else
8444
`endif
8445
            begin
8446
                 bwhich <= 2'b01;
8447
                 cyc_o <= `HIGH;
8448
                 stb_o <= `HIGH;
8449
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
8450
                 adr_o <= {dram1_addr[31:3],3'b0};
8451
                 sr_o <=  IsLWR(dram1_instr);
8452
                 ol_o  <= dram1_ol;
8453
                 bstate <= B12;
8454
            end
8455
        end
8456 49 robfinch
        else if (~|wb_v && mem3_available && dram2_unc && dram2==`DRAMSLOT_BUSY && dram2_load && `NUM_MEM > 2) begin
8457 48 robfinch
`ifdef SUPPORT_DBG
8458
            if (dbg_lmatch2) begin
8459
                 dramC_v <= `TRUE;
8460
                 dramC_id <= dram2_id;
8461
                 dramC_exc <= `FLT_DBG;
8462
                 dramC_bus <= 64'h0;
8463
                 dram2 <= 2'd0;
8464
            end
8465
            else
8466
`endif
8467
            begin
8468
                 bwhich <= 2'b10;
8469
                 cyc_o <= `HIGH;
8470
                 stb_o <= `HIGH;
8471
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
8472
                 adr_o <= {dram2_addr[31:3],3'b0};
8473
                 sr_o <=  IsLWR(dram2_instr);
8474
                 ol_o  <= dram2_ol;
8475
                 bstate <= B12;
8476
            end
8477
        end
8478
        // Check for L2 cache miss
8479 49 robfinch
        else if (~|wb_v && !ihitL2) begin
8480 48 robfinch
             cti_o <= 3'b001;
8481 49 robfinch
             bte_o <= 2'b00;//2'b01;    // 4 beat burst wrap
8482 48 robfinch
             cyc_o <= `HIGH;
8483
             stb_o <= `HIGH;
8484
             sel_o <= 8'hFF;
8485
             icl_o <= `HIGH;
8486 49 robfinch
             iccnt <= 3'd0;
8487 48 robfinch
//            adr_o <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
8488
//            L2_adr <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
8489
             adr_o <= {pcr[5:0],L1_adr[31:5],5'h0};
8490
             ol_o  <= ol[0];
8491
             L2_adr <= {pcr[5:0],L1_adr[31:5],5'h0};
8492
             L2_xsel <= 1'b0;
8493 59 robfinch
             bstate <= B_ICacheAck;
8494 48 robfinch
        end
8495
    end
8496
// Terminal state for a store operation.
8497 49 robfinch
// Note that if only a single memory channel is selected, bwhich will be a
8498
// constant 0. This should cause the extra code to be removed.
8499 58 robfinch
B_DCacheStoreAck:
8500 48 robfinch
    if (acki|err_i) begin
8501
         isStore <= `TRUE;
8502
         cyc_o <= `LOW;
8503
         stb_o <= `LOW;
8504
         we_o <= `LOW;
8505
         cr_o <= 1'b0;
8506
        // This isn't a good way of doing things; the state should be propagated
8507
        // to the commit stage, however since this is a store we know there will
8508
        // be no change of program flow. So the reservation status bit is set
8509
        // here. The author wanted to avoid the complexity of propagating the
8510
        // input signal to the commit stage. It does mean that the SWC
8511
        // instruction should be surrounded by SYNC's.
8512
        if (cr_o)
8513
             sema[0] <= rbi_i;
8514 49 robfinch
`ifdef HAS_WB
8515
                                for (n = 0; n < QENTRIES; n = n + 1) begin
8516
                                        if (wbo_id[n]) begin
8517
                        iqentry_exc[n] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8518
                        if (err_i|wrv_i) begin
8519
                                iqentry_a1[n] <= adr_o;
8520
                                wb_v <= 8'h00;          // Invalidate write buffer if there is a problem with the store
8521
                                wb_en <= `FALSE;        // and disable write buffer
8522
                        end
8523
                                                iqentry_cmt[n] <= `VAL;
8524
                                                iqentry_aq[n] <= `INV;
8525
                                        end
8526
                                end
8527
`else
8528 48 robfinch
        case(bwhich)
8529 58 robfinch
        2'd0:   begin
8530 48 robfinch
                 dram0 <= `DRAMREQ_READY;
8531
                 iqentry_exc[dram0_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8532
                if (err_i|wrv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8533 49 robfinch
                                                                        iqentry_cmt[ dram0_id[`QBITS] ] <= `VAL;
8534
                                                                        iqentry_aq[ dram0_id[`QBITS] ] <= `INV;
8535 48 robfinch
                        //iqentry_out[ dram0_id[`QBITS] ] <= `INV;
8536
                end
8537 49 robfinch
        2'd1:   if (`NUM_MEM > 1) begin
8538 48 robfinch
                 dram1 <= `DRAMREQ_READY;
8539
                 iqentry_exc[dram1_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8540
                if (err_i|wrv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8541 49 robfinch
                                                                        iqentry_cmt[ dram1_id[`QBITS] ] <= `VAL;
8542
                                                                        iqentry_aq[ dram1_id[`QBITS] ] <= `INV;
8543 48 robfinch
                        //iqentry_out[ dram1_id[`QBITS] ] <= `INV;
8544
                end
8545 49 robfinch
        2'd2:   if (`NUM_MEM > 2) begin
8546 48 robfinch
                 dram2 <= `DRAMREQ_READY;
8547
                 iqentry_exc[dram2_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8548
                if (err_i|wrv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8549 49 robfinch
                                                                        iqentry_cmt[ dram2_id[`QBITS] ] <= `VAL;
8550
                                                                        iqentry_aq[ dram2_id[`QBITS] ] <= `INV;
8551 48 robfinch
                        //iqentry_out[ dram2_id[`QBITS] ] <= `INV;
8552
                end
8553
        default:    ;
8554
        endcase
8555 49 robfinch
`endif
8556 48 robfinch
         bstate <= B19;
8557
    end
8558 58 robfinch
B_DCacheLoadStart:
8559 48 robfinch
    begin
8560
    dccnt <= 2'd0;
8561
    case(bwhich)
8562
    2'd0:   begin
8563
             cti_o <= 3'b001;
8564
             bte_o <= 2'b01;
8565
             cyc_o <= `HIGH;
8566
             stb_o <= `HIGH;
8567
             sel_o <= fnSelect(dram0_instr,dram0_addr);
8568
             adr_o <= {dram0_addr[31:5],5'b0};
8569
             ol_o  <= dram0_ol;
8570 58 robfinch
             bstate <= B_DCacheLoadAck;
8571 48 robfinch
            end
8572 49 robfinch
    2'd1:   if (`NUM_MEM > 1) begin
8573 48 robfinch
             cti_o <= 3'b001;
8574
             bte_o <= 2'b01;
8575
             cyc_o <= `HIGH;
8576
             stb_o <= `HIGH;
8577
             sel_o <= fnSelect(dram1_instr,dram1_addr);
8578
             adr_o <= {dram1_addr[31:5],5'b0};
8579
             ol_o  <= dram1_ol;
8580 58 robfinch
             bstate <= B_DCacheLoadAck;
8581 48 robfinch
            end
8582 49 robfinch
    2'd2:   if (`NUM_MEM > 2) begin
8583 48 robfinch
             cti_o <= 3'b001;
8584
             bte_o <= 2'b01;
8585
             cyc_o <= `HIGH;
8586
             stb_o <= `HIGH;
8587
             sel_o <= fnSelect(dram2_instr,dram2_addr);
8588
             adr_o <= {dram2_addr[31:5],5'b0};
8589
             ol_o  <= dram2_ol;
8590 58 robfinch
             bstate <= B_DCacheLoadAck;
8591 48 robfinch
            end
8592
    default:    if (~acki)  bstate <= BIDLE;
8593
    endcase
8594
    end
8595
// Data cache load terminal state
8596 58 robfinch
B_DCacheLoadAck:
8597 48 robfinch
    if (ack_i|err_i) begin
8598
        errq <= errq | err_i;
8599
        rdvq <= rdvq | rdv_i;
8600
        if (!preload)   // A preload instruction ignores any error
8601
        case(bwhich)
8602
        2'd0:   if (err_i|rdv_i) begin
8603
                     iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8604
                     iqentry_exc[dram0_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8605
                end
8606 49 robfinch
        2'd1:   if ((err_i|rdv_i) && `NUM_MEM > 1) begin
8607 48 robfinch
                     iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8608
                     iqentry_exc[dram1_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8609
                end
8610 49 robfinch
        2'd2:   if ((err_i|rdv_i) && `NUM_MEM > 2) begin
8611 48 robfinch
                     iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8612
                     iqentry_exc[dram2_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8613
                end
8614
        default:    ;
8615
        endcase
8616
        dccnt <= dccnt + 2'd1;
8617
        adr_o[4:3] <= adr_o[4:3] + 2'd1;
8618 58 robfinch
        bstate <= B_DCacheLoadAck;
8619 48 robfinch
        if (dccnt==2'd2)
8620
             cti_o <= 3'b111;
8621
        if (dccnt==2'd3) begin
8622
             cti_o <= 3'b000;
8623
             bte_o <= 2'b00;
8624
             cyc_o <= `LOW;
8625
             stb_o <= `LOW;
8626
             sel_o <= 8'h00;
8627 58 robfinch
             bstate <= B_DCacheLoadWait1;
8628 48 robfinch
        end
8629
    end
8630 58 robfinch
B_DCacheLoadStb:
8631
        begin
8632
                stb_o <= `HIGH;
8633
                bstate <= B_DCacheLoadAck;
8634
  end
8635
B_DCacheLoadWait1: bstate <= B_DCacheLoadWait2;
8636
B_DCacheLoadWait2: bstate <= B_DCacheLoadResetBusy;
8637
//B_DCacheLoadWait3: bstate <= B_DCacheLoadResetBusy;
8638
B_DCacheLoadResetBusy: begin
8639
    // There could be more than one memory cycle active. We reset the state
8640
    // of all the machines to retest for a hit because otherwise sequential
8641
    // loading of memory will cause successive machines to miss resulting in 
8642
    // multiple dcache loads that aren't needed.
8643
    if (dram0 != `DRAMSLOT_AVAIL && dram0_addr[31:5]==adr_o[31:5]) dram0 <= `DRAMSLOT_BUSY;  // causes retest of dhit
8644
    if (dram1 != `DRAMSLOT_AVAIL && dram1_addr[31:5]==adr_o[31:5]) dram1 <= `DRAMSLOT_BUSY;
8645
    if (dram2 != `DRAMSLOT_AVAIL && dram2_addr[31:5]==adr_o[31:5]) dram2 <= `DRAMSLOT_BUSY;
8646 48 robfinch
    if (~ack_i)  bstate <= BIDLE;
8647
    end
8648
 
8649
// Ack state for instruction cache load
8650 59 robfinch
B_ICacheAck:
8651 48 robfinch
    if (ack_i|err_i) begin
8652
        errq <= errq | err_i;
8653
        exvq <= exvq | exv_i;
8654 49 robfinch
//        L1_en <= 9'h3 << {L2_xsel,L2_adr[4:3],1'b0};
8655 48 robfinch
//        L1_wr0 <= `TRUE;
8656
//        L1_wr1 <= `TRUE;
8657
//        L1_adr <= L2_adr;
8658
        if (err_i)
8659 59 robfinch
                L2_rdat <= {18{`INSN_FLT_IBE}};
8660 48 robfinch
        else
8661 59 robfinch
                case(iccnt)
8662
                3'd0:   L2_rdat[63:0] <= dat_i;
8663
                3'd1:   L2_rdat[127:64] <= dat_i;
8664
                3'd2:   L2_rdat[191:128] <= dat_i;
8665
                3'd3:   L2_rdat[255:192] <= dat_i;
8666
                3'd4:   L2_rdat[287:256] <= dat_i[31:0];
8667
                default:        ;
8668
                endcase
8669
                //L2_rdat <= {dat_i[31:0],{4{dat_i}}};
8670 48 robfinch
        iccnt <= iccnt + 3'd1;
8671
        //stb_o <= `LOW;
8672
        if (iccnt==3'd3)
8673
            cti_o <= 3'b111;
8674
        if (iccnt==3'd4) begin
8675
            cti_o <= 3'b000;
8676
            bte_o <= 2'b00;             // linear burst
8677
            cyc_o <= `LOW;
8678
            stb_o <= `LOW;
8679
            sel_o <= 8'h00;
8680
            icl_o <= `LOW;
8681 59 robfinch
            bstate <= B_ICacheNack;
8682 48 robfinch
        end
8683
        else begin
8684
            L2_adr[4:3] <= L2_adr[4:3] + 2'd1;
8685
            if (L2_adr[4:3]==2'b11)
8686
                L2_xsel <= 1'b1;
8687
        end
8688
    end
8689 59 robfinch
B_ICacheNack:
8690 48 robfinch
        begin
8691
                L1_wr0 <= `FALSE;
8692
                L1_wr1 <= `FALSE;
8693 49 robfinch
                L1_wr2 <= `FALSE;
8694
                L1_en <= 9'h1FF;
8695 48 robfinch
                L2_xsel <= 1'b0;
8696
                if (~ack_i) begin
8697
                        bstate <= BIDLE;
8698
                        L2_nxt <= TRUE;
8699
                end
8700
        end
8701
B12:
8702
    if (ack_i|err_i) begin
8703
        if (isCAS) begin
8704
             iqentry_res        [ casid[`QBITS] ] <= (dat_i == cas);
8705
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8706
             iqentry_done[ casid[`QBITS] ] <= `VAL;
8707
             iqentry_instr[ casid[`QBITS]] <= `NOP_INSN;
8708
             iqentry_out [ casid[`QBITS] ] <= `INV;
8709
            if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
8710
            if (dat_i == cas) begin
8711
                 stb_o <= `LOW;
8712
                 we_o <= `TRUE;
8713
                 bstate <= B15;
8714
            end
8715
            else begin
8716
                 cas <= dat_i;
8717
                 cyc_o <= `LOW;
8718
                 stb_o <= `LOW;
8719
                case(bwhich)
8720
                2'b00:   dram0 <= `DRAMREQ_READY;
8721
                2'b01:   dram1 <= `DRAMREQ_READY;
8722
                2'b10:   dram2 <= `DRAMREQ_READY;
8723
                default:    ;
8724
                endcase
8725
                 bstate <= B19;
8726
            end
8727
        end
8728
        else if (isRMW) begin
8729
             rmw_instr <= iqentry_instr[casid[`QBITS]];
8730
             rmw_argA <= dat_i;
8731
                 if (isSpt) begin
8732
                        rmw_argB <= 64'd1 << iqentry_a1[casid[`QBITS]][63:58];
8733
                        rmw_argC <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ?
8734
                                                iqentry_a3[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58] :
8735
                                                iqentry_a2[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58];
8736
                 end
8737
                 else if (isInc) begin
8738
                        rmw_argB <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ? {{59{iqentry_instr[casid[`QBITS]][22]}},iqentry_instr[casid[`QBITS]][22:18]} :
8739
                                                                                                                                 {{59{iqentry_instr[casid[`QBITS]][17]}},iqentry_instr[casid[`QBITS]][17:13]};
8740
                 end
8741
                 else begin // isAMO
8742
                     iqentry_res [ casid[`QBITS] ] <= dat_i;
8743
                     rmw_argB <= iqentry_instr[casid[`QBITS]][31] ? {{59{iqentry_instr[casid[`QBITS]][20:16]}},iqentry_instr[casid[`QBITS]][20:16]} : iqentry_a2[casid[`QBITS]];
8744
                 end
8745
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8746
             if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
8747
             stb_o <= `LOW;
8748
             bstate <= B20;
8749
                end
8750
        else begin
8751
             cyc_o <= `LOW;
8752
             stb_o <= `LOW;
8753
             sr_o <= `LOW;
8754
             xdati <= dat_i;
8755
            case(bwhich)
8756
            2'b00:  begin
8757
                     dram0 <= `DRAMREQ_READY;
8758
                     iqentry_exc [ dram0_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8759
                    if (err_i|rdv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8760
                    end
8761 49 robfinch
            2'b01:  if (`NUM_MEM > 1) begin
8762 48 robfinch
                     dram1 <= `DRAMREQ_READY;
8763
                     iqentry_exc [ dram1_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8764
                    if (err_i|rdv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8765
                    end
8766 49 robfinch
            2'b10:  if (`NUM_MEM > 2) begin
8767 48 robfinch
                     dram2 <= `DRAMREQ_READY;
8768
                     iqentry_exc [ dram2_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8769
                    if (err_i|rdv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8770
                    end
8771
            default:    ;
8772
            endcase
8773
             bstate <= B19;
8774
        end
8775
    end
8776
// Three cycles to detemrine if there's a cache hit during a store.
8777
B16:    begin
8778
            case(bwhich)
8779
            2'd0:      if (dhit0) begin  dram0 <= `DRAMREQ_READY; bstate <= B17; end
8780
            2'd1:      if (dhit1) begin  dram1 <= `DRAMREQ_READY; bstate <= B17; end
8781
            2'd2:      if (dhit2) begin  dram2 <= `DRAMREQ_READY; bstate <= B17; end
8782
            default:    bstate <= BIDLE;
8783
            endcase
8784
            end
8785
B17:     bstate <= B18;
8786
B18:     bstate <= B19;
8787 57 robfinch
B19:    if (~acki)  begin
8788
                                        sel_o <= 8'h00;
8789
                                        bstate <= BIDLE;
8790
                                        isStore <= `FALSE;
8791
                                end
8792 48 robfinch
B20:
8793
        if (~ack_i) begin
8794
                stb_o <= `HIGH;
8795
                we_o  <= `HIGH;
8796
                dat_o <= fnDato(rmw_instr,rmw_res);
8797 58 robfinch
                bstate <= B_DCacheStoreAck;
8798 48 robfinch
        end
8799
B21:
8800
        if (~ack_i) begin
8801
                stb_o <= `HIGH;
8802
                bstate <= B12;
8803
        end
8804
default:     bstate <= BIDLE;
8805
endcase
8806
 
8807
if (!branchmiss) begin
8808
    case({fetchbuf0_v, fetchbuf1_v})
8809
    2'b00:  ;
8810
    2'b01:
8811
        if (canq1) begin
8812
                tail0 <= idp1(tail0);
8813
                tail1 <= idp1(tail1);
8814
        end
8815
    2'b10:
8816
        if (canq1) begin
8817
            tail0 <= idp1(tail0);
8818
            tail1 <= idp1(tail1);
8819
        end
8820
    2'b11:
8821
        if (canq1) begin
8822
            if (IsBranch(fetchbuf0_instr) && predict_taken0 && fetchbuf0_thrd==fetchbuf1_thrd) begin
8823
                 tail0 <= idp1(tail0);
8824
                 tail1 <= idp1(tail1);
8825
            end
8826
            else begin
8827
                                if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
8828
                        if (canq2) begin
8829
                             tail0 <= idp2(tail0);
8830
                             tail1 <= idp2(tail1);
8831
                        end
8832
                        else begin    // queued1 will be true
8833
                             tail0 <= idp1(tail0);
8834
                             tail1 <= idp1(tail1);
8835
                        end
8836
                end
8837
            end
8838
        end
8839
    endcase
8840
end
8841 52 robfinch
else if (!thread_en) begin      // if branchmiss
8842 48 robfinch
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
8843 52 robfinch
         tail0 <= 4'd0;
8844
         tail1 <= 4'd1;
8845 48 robfinch
    end
8846
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
8847 52 robfinch
         tail0 <= 4'd1;
8848
         tail1 <= 4'd2;
8849 48 robfinch
    end
8850
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
8851 52 robfinch
         tail0 <= 4'd2;
8852
         tail1 <= 4'd3;
8853 48 robfinch
    end
8854
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
8855 52 robfinch
         tail0 <= 4'd3;
8856
         tail1 <= 4'd4;
8857 48 robfinch
    end
8858
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
8859 52 robfinch
         tail0 <= 4'd4;
8860
         tail1 <= 4'd5;
8861 48 robfinch
    end
8862
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
8863 52 robfinch
         tail0 <= 4'd5;
8864
         tail1 <= 4'd6;
8865 48 robfinch
    end
8866
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
8867 52 robfinch
         tail0 <= 4'd6;
8868
         tail1 <= 4'd7;
8869 48 robfinch
    end
8870
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
8871 52 robfinch
         tail0 <= 4'd7;
8872
         tail1 <= 4'd8;
8873 48 robfinch
    end
8874 52 robfinch
    else if (iqentry_stomp[8] & ~iqentry_stomp[7]) begin
8875
         tail0 <= 4'd8;
8876
         tail1 <= 4'd9;
8877
    end
8878
    else if (iqentry_stomp[9] & ~iqentry_stomp[8]) begin
8879
         tail0 <= 4'd9;
8880
         tail1 <= 4'd0;
8881
    end
8882 48 robfinch
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
8883
end
8884 51 robfinch
 
8885 48 robfinch
/*
8886
    if (pebm)
8887
         seq_num <= seq_num + 5'd3;
8888
    else if (queued2)
8889
         seq_num <= seq_num + 5'd2;
8890
    else if (queued1)
8891
         seq_num <= seq_num + 5'd1;
8892
*/
8893
//      #5 rf[0] = 0; rf_v[0] = 1; rf_source[0] = 0;
8894 51 robfinch
`ifdef SIM
8895 48 robfinch
        $display("\n\n\n\n\n\n\n\n");
8896
        $display("TIME %0d", $time);
8897
        $display("%h #", pc0);
8898
`ifdef SUPPORT_SMT
8899
    $display ("Regfile: %d", rgs[0]);
8900
        for (n=0; n < 32; n=n+4) begin
8901
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8902
               n[4:0]+0, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8903
               n[4:0]+1, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8904
               n[4:0]+2, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8905
               n[4:0]+3, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8906
               );
8907
        end
8908
    $display ("Regfile: %d", rgs[1]);
8909
        for (n=128; n < 160; n=n+4) begin
8910
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8911
               n[4:0]+0, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8912
               n[4:0]+1, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8913
               n[4:0]+2, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8914
               n[4:0]+3, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8915
               );
8916
        end
8917
`else
8918
    $display ("Regfile: %d", rgs);
8919
        for (n=0; n < 32; n=n+4) begin
8920
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8921 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],
8922
               n[4:0]+1, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8923
               n[4:0]+2, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8924
               n[4:0]+3, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8925 48 robfinch
               );
8926
        end
8927
`endif
8928 49 robfinch
`ifdef FCU_ENH
8929 48 robfinch
        $display("Call Stack:");
8930 49 robfinch
        for (n = 0; n < 16; n = n + 4)
8931 48 robfinch
                $display("%c%d: %h   %c%d: %h   %c%d: %h   %c%d: %h",
8932 57 robfinch
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+0 ?">" : " ", n[4:0]+0, gFetchbufInst.gb1.ufb1.ursb1.ras[n+0],
8933
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+1 ?">" : " ", n[4:0]+1, gFetchbufInst.gb1.ufb1.ursb1.ras[n+1],
8934
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+2 ?">" : " ", n[4:0]+2, gFetchbufInst.gb1.ufb1.ursb1.ras[n+2],
8935
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+3 ?">" : " ", n[4:0]+3, gFetchbufInst.gb1.ufb1.ursb1.ras[n+3]
8936 48 robfinch
                );
8937
        $display("\n");
8938 49 robfinch
`endif
8939 48 robfinch
//    $display("Return address stack:");
8940
//    for (n = 0; n < 16; n = n + 1)
8941
//        $display("%d %h", rasp+n[3:0], ras[rasp+n[3:0]]);
8942
        $display("TakeBr:%d #", take_branch);//, backpc);
8943 51 robfinch
        $display("Insn%d: %h", 0, insn0);
8944 57 robfinch
        if (`WAYS==1) begin
8945
        $display("%c%c A: %d %h %h #",
8946
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
8947
        $display("%c%c B: %d %h %h #",
8948
            45, fetchbuf?62:45, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
8949
        end
8950
        else if (`WAYS > 1) begin
8951 51 robfinch
                $display("Insn%d: %h", 1, insn1);
8952 48 robfinch
        $display("%c%c A: %d %h %h #",
8953
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
8954
        $display("%c%c B: %d %h %h #",
8955
            45, fetchbuf?45:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
8956 57 robfinch
        end
8957
        else if (`WAYS > 2) begin
8958
                $display("%c%c C: %d %h %h #",
8959
                    45, fetchbuf?62:45, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
8960
                $display("%c%c D: %d %h %h #",
8961
                    45, fetchbuf?62:45, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
8962
        end
8963 48 robfinch
        for (i=0; i<QENTRIES; i=i+1)
8964
            $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#",
8965
                 (i[`QBITS]==head0)?"C":".",
8966
                 (i[`QBITS]==tail0)?"Q":".",
8967
                  i[`QBITS],
8968
                 iqentry_v[i] ? "v" : "-",
8969
                 iqentry_iv[i] ? "I" : "-",
8970
                 iqentry_done[i]?"d":"-",
8971
                 iqentry_out[i]?"o":"-",
8972
                 iqentry_bt[i],
8973
                 iqentry_memissue[i],
8974
                 iqentry_agen[i] ? "a": "-",
8975
                 iqentry_alu0_issue[i]?"0":iqentry_alu1_issue[i]?"1":"-",
8976
                 iqentry_stomp[i]?"s":"-",
8977
                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",
8978
                iqentry_instr[i], iqentry_tgt[i][4:0],
8979
                iqentry_exc[i], iqentry_res[i], iqentry_a0[i], iqentry_a1[i], iqentry_a1_v[i],
8980
                iqentry_a1_s[i],
8981
                iqentry_a2[i], iqentry_a2_v[i], iqentry_a2_s[i],
8982
                iqentry_a3[i], iqentry_a3_v[i], iqentry_a3_s[i],
8983
                iqentry_thrd[i],
8984
                iqentry_pc[i],
8985
                iqentry_sn[i], iqentry_ven[i]
8986
                );
8987
    $display("DRAM");
8988
        $display("%d %h %h %c%h %o #",
8989
            dram0, dram0_addr, dram0_data, (IsFlowCtrl(dram0_instr) ? 98 : (IsMem(dram0_instr)) ? 109 : 97),
8990
            dram0_instr, dram0_id);
8991 49 robfinch
          if (`NUM_MEM > 1)
8992 48 robfinch
        $display("%d %h %h %c%h %o #",
8993
            dram1, dram1_addr, dram1_data, (IsFlowCtrl(dram1_instr) ? 98 : (IsMem(dram1_instr)) ? 109 : 97),
8994
            dram1_instr, dram1_id);
8995 49 robfinch
          if (`NUM_MEM > 2)
8996 48 robfinch
        $display("%d %h %h %c%h %o #",
8997
            dram2, dram2_addr, dram2_data, (IsFlowCtrl(dram2_instr) ? 98 : (IsMem(dram2_instr)) ? 109 : 97),
8998
            dram2_instr, dram2_id);
8999
        $display("%d %h %o %h #", dramA_v, dramA_bus, dramA_id, dramA_exc);
9000 49 robfinch
        if (`NUM_MEM > 1)
9001 48 robfinch
        $display("%d %h %o %h #", dramB_v, dramB_bus, dramB_id, dramB_exc);
9002 49 robfinch
        if (`NUM_MEM > 2)
9003 48 robfinch
        $display("%d %h %o %h #", dramC_v, dramC_bus, dramC_id, dramC_exc);
9004
    $display("ALU");
9005
        $display("%d %h %h %h %c%h %d %o %h #",
9006
                alu0_dataready, alu0_argI, alu0_argA, alu0_argB,
9007
                 (IsFlowCtrl(alu0_instr) ? 98 : IsMem(alu0_instr) ? 109 : 97),
9008
                alu0_instr, alu0_bt, alu0_sourceid, alu0_pc);
9009
        $display("%d %h %o 0 #", alu0_v, alu0_bus, alu0_id);
9010 49 robfinch
        if (`NUM_ALU > 1) begin
9011
                $display("%d %h %h %h %c%h %d %o %h #",
9012
                        alu1_dataready, alu1_argI, alu1_argA, alu1_argB,
9013
                        (IsFlowCtrl(alu1_instr) ? 98 : IsMem(alu1_instr) ? 109 : 97),
9014
                        alu1_instr, alu1_bt, alu1_sourceid, alu1_pc);
9015
                $display("%d %h %o 0 #", alu1_v, alu1_bus, alu1_id);
9016
        end
9017 48 robfinch
        $display("FCU");
9018
        $display("%d %h %h %h %h #", fcu_v, fcu_bus, fcu_argI, fcu_argA, fcu_argB);
9019 56 robfinch
        $display("%c %h %h %h %h #", fcu_branchmiss?"m":" ", fcu_sourceid, fcu_misspc, fcu_nextpc, fcu_brdisp);
9020 48 robfinch
    $display("Commit");
9021
        $display("0: %c %h %o %d #", commit0_v?"v":" ", commit0_bus, commit0_id, commit0_tgt[4:0]);
9022
        $display("1: %c %h %o %d #", commit1_v?"v":" ", commit1_bus, commit1_id, commit1_tgt[4:0]);
9023 58 robfinch
    $display("instructions committed: %d valid committed: %d ticks: %d ", CC, I, tick);
9024 49 robfinch
    $display("Write merges: %d", wb_merges);
9025 51 robfinch
`endif  // SIM
9026 48 robfinch
 
9027
//
9028
//      $display("\n\n\n\n\n\n\n\n");
9029
//      $display("TIME %0d", $time);
9030
//      $display("  pc0=%h", pc0);
9031
//      $display("  pc1=%h", pc1);
9032
//      $display("  reg0=%h, v=%d, src=%o", rf[0], rf_v[0], rf_source[0]);
9033
//      $display("  reg1=%h, v=%d, src=%o", rf[1], rf_v[1], rf_source[1]);
9034
//      $display("  reg2=%h, v=%d, src=%o", rf[2], rf_v[2], rf_source[2]);
9035
//      $display("  reg3=%h, v=%d, src=%o", rf[3], rf_v[3], rf_source[3]);
9036
//      $display("  reg4=%h, v=%d, src=%o", rf[4], rf_v[4], rf_source[4]);
9037
//      $display("  reg5=%h, v=%d, src=%o", rf[5], rf_v[5], rf_source[5]);
9038
//      $display("  reg6=%h, v=%d, src=%o", rf[6], rf_v[6], rf_source[6]);
9039
//      $display("  reg7=%h, v=%d, src=%o", rf[7], rf_v[7], rf_source[7]);
9040
 
9041
//      $display("Fetch Buffers:");
9042
//      $display("  %c%c fbA: v=%d instr=%h pc=%h     %c%c fbC: v=%d instr=%h pc=%h", 
9043
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc,
9044
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
9045
//      $display("  %c%c fbB: v=%d instr=%h pc=%h     %c%c fbD: v=%d instr=%h pc=%h", 
9046
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc,
9047
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
9048
//      $display("  branchback=%d backpc=%h", branchback, backpc);
9049
 
9050
//      $display("Instruction Queue:");
9051
//      for (i=0; i<8; i=i+1) 
9052
//          $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",
9053
//              (i[`QBITS]==head0)?72:32, (i[`QBITS]==tail0)?84:32, i,
9054
//              iqentry_v[i], iqentry_done[i], iqentry_out[i], iqentry_agen[i], iqentry_res[i], iqentry_op[i], 
9055
//              iqentry_bt[i], iqentry_tgt[i], iqentry_a1[i], iqentry_a1_v[i], iqentry_a1_s[i], iqentry_a2[i], iqentry_a2_v[i], 
9056
//              iqentry_a2_s[i], iqentry_a0[i], iqentry_pc[i], iqentry_exc[i]);
9057
 
9058
//      $display("Scheduling Status:");
9059
//      $display("  iqentry0 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
9060
//              iqentry_0_issue, iqentry_0_islot, iqentry_stomp[0], iqentry_source[0], iqentry_memready[0], iqentry_memissue[0]);
9061
//      $display("  iqentry1 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
9062
//              iqentry_1_issue, iqentry_1_islot, iqentry_stomp[1], iqentry_source[1], iqentry_memready[1], iqentry_memissue[1]);
9063
//      $display("  iqentry2 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
9064
//              iqentry_2_issue, iqentry_2_islot, iqentry_stomp[2], iqentry_source[2], iqentry_memready[2], iqentry_memissue[2]);
9065
//      $display("  iqentry3 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
9066
//              iqentry_3_issue, iqentry_3_islot, iqentry_stomp[3], iqentry_source[3], iqentry_memready[3], iqentry_memissue[3]);
9067
//      $display("  iqentry4 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
9068
//              iqentry_4_issue, iqentry_4_islot, iqentry_stomp[4], iqentry_source[4], iqentry_memready[4], iqentry_memissue[4]);
9069
//      $display("  iqentry5 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
9070
//              iqentry_5_issue, iqentry_5_islot, iqentry_stomp[5], iqentry_source[5], iqentry_memready[5], iqentry_memissue[5]);
9071
//      $display("  iqentry6 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
9072
//              iqentry_6_issue, iqentry_6_islot, iqentry_stomp[6], iqentry_source[6], iqentry_memready[6], iqentry_memissue[6]);
9073
//      $display("  iqentry7 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
9074
//              iqentry_7_issue, iqentry_7_islot, iqentry_stomp[7], iqentry_source[7], iqentry_memready[7], iqentry_memissue[7]);
9075
 
9076
//      $display("ALU Inputs:");
9077
//      $display("  0: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
9078
//              alu0_available, alu0_dataready, alu0_sourceid, alu0_op, alu0_argA,
9079
//              alu0_argB, alu0_argI, alu0_bt);
9080
//      $display("  1: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
9081
//              alu1_available, alu1_dataready, alu1_sourceid, alu1_op, alu1_argA,
9082
//              alu1_argB, alu1_argI, alu1_bt);
9083
 
9084
//      $display("ALU Outputs:");
9085
//      $display("  0: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
9086
//              alu0_v, alu0_bus, alu0_id, alu0_branchmiss, alu0_misspc, alu0_sourceid);
9087
//      $display("  1: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
9088
//              alu1_v, alu1_bus, alu1_id, alu1_branchmiss, alu1_misspc, alu1_sourceid);
9089
 
9090
//      $display("DRAM Status:");
9091
//      $display("  OUT: v=%d data=%h tgt=%d id=%o", dram_v, dram_bus, dram_tgt, dram_id);
9092
//      $display("  dram0: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
9093
//          dram0, dram0_addr, dram0_data, dram0_op, dram0_tgt, dram0_id);
9094
//      $display("  dram1: status=%h addr=%h data=%h op=%d tgt=%d id=%o", 
9095
//          dram1, dram1_addr, dram1_data, dram1_op, dram1_tgt, dram1_id);
9096
//      $display("  dram2: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
9097
//          dram2, dram2_addr, dram2_data, dram2_op, dram2_tgt, dram2_id);
9098
 
9099
//      $display("Commit Buses:");
9100
//      $display("  0: v=%d id=%o data=%h", commit0_v, commit0_id, commit0_bus);
9101
//      $display("  1: v=%d id=%o data=%h", commit1_v, commit1_id, commit1_bus);
9102
 
9103
//
9104
//      $display("Memory Contents:");
9105
//      for (j=0; j<64; j=j+16)
9106
//          $display("  %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h", 
9107
//              m[j+0], m[j+1], m[j+2], m[j+3], m[j+4], m[j+5], m[j+6], m[j+7],
9108
//              m[j+8], m[j+9], m[j+10], m[j+11], m[j+12], m[j+13], m[j+14], m[j+15]);
9109
 
9110
        $display("");
9111
 
9112
        if (|panic) begin
9113
            $display("");
9114
            $display("-----------------------------------------------------------------");
9115
            $display("-----------------------------------------------------------------");
9116
            $display("---------------     PANIC:%s     -----------------", message[panic]);
9117
            $display("-----------------------------------------------------------------");
9118
            $display("-----------------------------------------------------------------");
9119
            $display("");
9120
            $display("instructions committed: %d", I);
9121
            $display("total execution cycles: %d", $time / 10);
9122
            $display("");
9123
        end
9124
        if (|panic && ~outstanding_stores) begin
9125
            $finish;
9126
        end
9127 59 robfinch
/*
9128 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
9129
        if (branchmiss) begin
9130
            if (!setpred[n]) begin
9131
                 iqentry_instr[n][`INSTRUCTION_OP] <= `NOP;
9132 59 robfinch
                 iqentry_done[n] <= iqentry_v[n];
9133
                 iqentry_cmt[n] <= iqentry_v[n];
9134 48 robfinch
            end
9135
        end
9136 59 robfinch
*/
9137 48 robfinch
        if (snr) begin
9138
                seq_num <= 32'd0;
9139
                seq_num1 <= 32'd0;
9140
        end
9141
end // clock domain
9142
/*
9143
always @(posedge clk)
9144
if (rst) begin
9145
     tail0 <= 3'd0;
9146
     tail1 <= 3'd1;
9147
end
9148
else begin
9149
if (!branchmiss) begin
9150
    case({fetchbuf0_v, fetchbuf1_v})
9151
    2'b00:  ;
9152
    2'b01:
9153
        if (canq1) begin
9154
             tail0 <= idp1(tail0);
9155
             tail1 <= idp1(tail1);
9156
        end
9157
    2'b10:
9158
        if (canq1) begin
9159
             tail0 <= idp1(tail0);
9160
             tail1 <= idp1(tail1);
9161
        end
9162
    2'b11:
9163
        if (canq1) begin
9164
            if (IsBranch(fetchbuf0_instr) && predict_taken0) begin
9165
                 tail0 <= idp1(tail0);
9166
                 tail1 <= idp1(tail1);
9167
            end
9168
            else begin
9169
                                if (vqe < vl || !IsVector(fetchbuf0_instr)) begin
9170
                        if (canq2) begin
9171
                             tail0 <= idp2(tail0);
9172
                             tail1 <= idp2(tail1);
9173
                        end
9174
                        else begin    // queued1 will be true
9175
                             tail0 <= idp1(tail0);
9176
                             tail1 <= idp1(tail1);
9177
                        end
9178
                end
9179
            end
9180
        end
9181
    endcase
9182
end
9183
else begin      // if branchmiss
9184
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
9185
         tail0 <= 3'd0;
9186
         tail1 <= 3'd1;
9187
    end
9188
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
9189
         tail0 <= 3'd1;
9190
         tail1 <= 3'd2;
9191
    end
9192
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
9193
         tail0 <= 3'd2;
9194
         tail1 <= 3'd3;
9195
    end
9196
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
9197
         tail0 <= 3'd3;
9198
         tail1 <= 3'd4;
9199
    end
9200
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
9201
         tail0 <= 3'd4;
9202
         tail1 <= 3'd5;
9203
    end
9204
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
9205
         tail0 <= 3'd5;
9206
         tail1 <= 3'd6;
9207
    end
9208
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
9209
         tail0 <= 3'd6;
9210
         tail1 <= 3'd7;
9211
    end
9212
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
9213
         tail0 <= 3'd7;
9214
         tail1 <= 3'd0;
9215
    end
9216
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
9217
end
9218
end
9219
*/
9220
/*
9221
always @(posedge clk)
9222
if (rst)
9223
     seq_num <= 5'd0;
9224
else begin
9225
    if (pebm)
9226
         seq_num <= seq_num + 5'd3;
9227
    else if (queued2)
9228
         seq_num <= seq_num + 5'd2;
9229
    else if (queued1)
9230
         seq_num <= seq_num + 5'd1;
9231
end
9232
*/
9233 49 robfinch
 
9234 51 robfinch
// Update the write buffer.
9235 49 robfinch
task wb_update;
9236
input [`QBITS] id;
9237
input rmw;
9238
input [7:0] sel;
9239
input [1:0] ol;
9240
input [`ABITS] addr;
9241
input [63:0] data;
9242
begin
9243 52 robfinch
        if (wbm && wbptr > 1 && wb_addr[wbptr-1][AMSB:3]==addr[AMSB:3]
9244
         && wb_ol[wbptr-1]==ol && wb_rmw[wbptr-1]==rmw && wb_v[wbptr-1]) begin
9245
                // The write buffer is always shifted during the bus IDLE state. That means
9246
                // the data is out of place by a slot. The slot the data is moved from is
9247
                // invalidated.
9248
                wb_v[wbptr-2] <= `INV;
9249
                wb_v[wbptr-1] <= wb_en;
9250
                wb_id[wbptr-1] <= wb_id[wbptr-1] | (16'd1 << id);
9251
                wb_rmw[wbptr-1] <= rmw;
9252
                wb_ol[wbptr-1] <= ol;
9253 49 robfinch
                wb_sel[wbptr-1] <= wb_sel[wbptr-1] | sel;
9254 52 robfinch
                wb_addr[wbptr-1] <= wb_addr[wbptr-1];
9255
                wb_data[wbptr-1] <= wb_data[wbptr-1];
9256 49 robfinch
                if (sel[0]) wb_data[wbptr-1][ 7: 0] <= data[ 7: 0];
9257
                if (sel[1]) wb_data[wbptr-1][15: 8] <= data[15: 8];
9258
                if (sel[2]) wb_data[wbptr-1][23:16] <= data[23:16];
9259
                if (sel[3]) wb_data[wbptr-1][31:24] <= data[31:24];
9260
                if (sel[4]) wb_data[wbptr-1][39:32] <= data[39:32];
9261
                if (sel[5]) wb_data[wbptr-1][47:40] <= data[47:40];
9262
                if (sel[6]) wb_data[wbptr-1][55:48] <= data[55:48];
9263
                if (sel[7]) wb_data[wbptr-1][63:56] <= data[63:56];
9264
                wb_merges <= wb_merges + 32'd1;
9265
        end
9266
        else begin
9267
                wb_v[wbptr] <= wb_en;
9268
                wb_id[wbptr] <= (16'd1 << id);
9269
                wb_rmw[wbptr] <= rmw;
9270
                wb_ol[wbptr] <= ol;
9271
                wb_sel[wbptr] <= sel;
9272
                wb_addr[wbptr] <= {addr[AMSB:3],3'b0};
9273
                wb_data[wbptr] <= data;
9274
        end
9275
end
9276
endtask
9277 52 robfinch
 
9278 48 robfinch
// Increment the head pointers
9279
// Also increments the instruction counter
9280
// Used when instructions are committed.
9281
// Also clear any outstanding state bits that foul things up.
9282
//
9283
task head_inc;
9284
input [`QBITS] amt;
9285
begin
9286 52 robfinch
     head0 <= (head0 + amt) % QENTRIES;
9287
     head1 <= (head1 + amt) % QENTRIES;
9288
     head2 <= (head2 + amt) % QENTRIES;
9289
     head3 <= (head3 + amt) % QENTRIES;
9290
     head4 <= (head4 + amt) % QENTRIES;
9291
     head5 <= (head5 + amt) % QENTRIES;
9292
     head6 <= (head6 + amt) % QENTRIES;
9293
     head7 <= (head7 + amt) % QENTRIES;
9294
     head8 <= (head8 + amt) % QENTRIES;
9295
     head9 <= (head9 + amt) % QENTRIES;
9296 58 robfinch
     CC <= CC + amt;
9297 49 robfinch
    if (amt==3'd3) begin
9298 58 robfinch
        I = I + iqentry_v[head0] + iqentry_v[head1] + iqentry_v[head2];
9299 49 robfinch
        iqentry_agen[head0] <= `INV;
9300
        iqentry_agen[head1] <= `INV;
9301
        iqentry_agen[head2] <= `INV;
9302
        iqentry_mem[head0] <= `FALSE;
9303
        iqentry_mem[head1] <= `FALSE;
9304
        iqentry_mem[head2] <= `FALSE;
9305
        iqentry_iv[head0] <= `INV;
9306
        iqentry_iv[head1] <= `INV;
9307
        iqentry_iv[head2] <= `INV;
9308
        iqentry_alu[head0] <= `FALSE;
9309
        iqentry_alu[head1] <= `FALSE;
9310
        iqentry_alu[head2] <= `FALSE;
9311
        end
9312
    else if (amt==3'd2) begin
9313 58 robfinch
        I = I + iqentry_v[head0] + iqentry_v[head1];
9314 48 robfinch
     iqentry_agen[head0] <= `INV;
9315
     iqentry_agen[head1] <= `INV;
9316 49 robfinch
     iqentry_mem[head0] <= `FALSE;
9317
     iqentry_mem[head1] <= `FALSE;
9318
     iqentry_iv[head0] <= `INV;
9319
     iqentry_iv[head1] <= `INV;
9320
        iqentry_alu[head0] <= `FALSE;
9321
     iqentry_alu[head1] <= `FALSE;
9322 48 robfinch
    end else if (amt==3'd1) begin
9323 58 robfinch
        I = I + iqentry_v[head0];
9324 49 robfinch
            iqentry_agen[head0] <= `INV;
9325
            iqentry_mem[head0] <= `FALSE;
9326
        iqentry_iv[head0] <= `INV;
9327
        iqentry_alu[head0] <= `FALSE;
9328 48 robfinch
        end
9329
end
9330
endtask
9331
 
9332
task setargs;
9333
input [`QBITS] nn;
9334
input [4:0] id;
9335
input v;
9336
input [63:0] bus;
9337
begin
9338
  if (iqentry_a1_v[nn] == `INV && iqentry_a1_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9339
                iqentry_a1[nn] <= bus;
9340
                iqentry_a1_v[nn] <= `VAL;
9341
  end
9342
  if (iqentry_a2_v[nn] == `INV && iqentry_a2_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9343
                iqentry_a2[nn] <= bus;
9344
                iqentry_a2_v[nn] <= `VAL;
9345
  end
9346
  if (iqentry_a3_v[nn] == `INV && iqentry_a3_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9347
                iqentry_a3[nn] <= bus;
9348
                iqentry_a3_v[nn] <= `VAL;
9349
  end
9350
end
9351
endtask
9352
 
9353
task setinsn;
9354
input [`QBITS] nn;
9355
input [4:0] id;
9356
input v;
9357 51 robfinch
input [143:0] bus;
9358 48 robfinch
begin
9359
  if (iqentry_iv[nn] == `INV && iqentry_is[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9360
        iqentry_iv   [nn]  <= `VAL;
9361
//      iqentry_Rt   [nn]  <= bus[`IB_RT];
9362
//      iqentry_Rc   [nn]  <= bus[`IB_RC];
9363
//      iqentry_Ra   [nn]  <= bus[`IB_RA];
9364
        iqentry_a0       [nn]  <= bus[`IB_CONST];
9365
        iqentry_imm  [nn]  <= bus[`IB_IMM];
9366 55 robfinch
//              iqentry_insln[nn]  <= bus[`IB_LN];
9367 56 robfinch
                if (iqentry_insln[nn] != bus[`IB_LN]) begin
9368
                        $display("Insn length mismatch.");
9369
                        $stop;
9370
                end
9371 51 robfinch
                iqentry_jal      [nn]  <= bus[`IB_JAL];
9372
                iqentry_ret  [nn]  <= bus[`IB_RET];
9373
                iqentry_irq  [nn]  <= bus[`IB_IRQ];
9374
                iqentry_brk      [nn]  <= bus[`IB_BRK];
9375
                iqentry_rti  [nn]  <= bus[`IB_RTI];
9376 48 robfinch
                iqentry_bt   [nn]  <= bus[`IB_BT];
9377
                iqentry_alu  [nn]  <= bus[`IB_ALU];
9378
                iqentry_alu0 [nn]  <= bus[`IB_ALU0];
9379
                iqentry_fpu  [nn]  <= bus[`IB_FPU];
9380
                iqentry_fc   [nn]  <= bus[`IB_FC];
9381
                iqentry_canex[nn]  <= bus[`IB_CANEX];
9382 50 robfinch
                iqentry_loadv[nn]  <= bus[`IB_LOADV];
9383 48 robfinch
                iqentry_load [nn]  <= bus[`IB_LOAD];
9384
                iqentry_preload[nn]<= bus[`IB_PRELOAD];
9385 50 robfinch
                iqentry_store[nn]  <= bus[`IB_STORE];
9386
                iqentry_oddball[nn] <= bus[`IB_ODDBALL];
9387
                iqentry_memsz[nn]  <= bus[`IB_MEMSZ];
9388 48 robfinch
                iqentry_mem  [nn]  <= bus[`IB_MEM];
9389
                iqentry_memndx[nn] <= bus[`IB_MEMNDX];
9390
                iqentry_rmw  [nn]  <= bus[`IB_RMW];
9391
                iqentry_memdb[nn]  <= bus[`IB_MEMDB];
9392
                iqentry_memsb[nn]  <= bus[`IB_MEMSB];
9393
                iqentry_shft48[nn] <= bus[`IB_SHFT48];
9394
                iqentry_sei      [nn]    <= bus[`IB_SEI];
9395
                iqentry_aq   [nn]  <= bus[`IB_AQ];
9396
                iqentry_rl   [nn]  <= bus[`IB_RL];
9397
                iqentry_jmp  [nn]  <= bus[`IB_JMP];
9398
                iqentry_br   [nn]  <= bus[`IB_BR];
9399
                iqentry_sync [nn]  <= bus[`IB_SYNC];
9400
                iqentry_fsync[nn]  <= bus[`IB_FSYNC];
9401
        iqentry_rfw  [nn]  <= bus[`IB_RFW];
9402
        iqentry_we   [nn]  <= bus[`IB_WE];
9403 56 robfinch
/*
9404
        if (iqentry_vector[nn]) begin
9405
                        iqentry_tgt[nn][RBIT:6] <= iqentry_Ra[nn][RBIT:6];
9406
                if (iqentry_Ra[nn][RBIT:6]==6'd0)
9407
                        iqentry_tgt[nn][RBIT:6] = 6'd0;
9408
                else begin
9409
                                if (iqentry_vcmprss[nn]) begin
9410
                                        if (vm[iqentry_instr[nn][25:23]][iqentry_Ra[nn][RBIT:6]])
9411
                                                if (qcnt==2'd2 && iqentry_vector[(nn-1)%QENTRIES] && iqentry_Ra[(nn-1)%QENTRIES][RBIT:6] >= 6'd1)
9412
                                                        iqentry_tgt[nn][RBIT:6] <= iqentry_tgt[(nn-2)%QENTRIES][RBIT:6] + 6'd2;
9413
                                                else
9414
                                                        iqentry_tgt[nn][RBIT:6] <= iqentry_tgt[(nn-1)%QENTRIES][RBIT:6] + 6'd1;
9415
                                end
9416
                        end
9417
                end
9418
*/
9419 48 robfinch
  end
9420
end
9421
endtask
9422
 
9423 55 robfinch
task a1_vs;
9424
begin
9425
        // if there is not an overlapping write to the register file.
9426
        if (Ra1s != Rt0s || !fetchbuf0_rfw) begin
9427
                iqentry_a1_v [tail1] <= regIsValid[Ra1s];
9428
                iqentry_a1_s [tail1] <= rf_source [Ra1s];
9429
        end
9430
        else begin
9431
                iqentry_a1_v [tail1] <= `INV;
9432
                iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
9433
        end
9434
end
9435
endtask
9436
 
9437
task a2_vs;
9438
begin
9439
        // if there is not an overlapping write to the register file.
9440
        if (Rb1s != Rt0s || !fetchbuf0_rfw) begin
9441
                iqentry_a2_v [tail1] <= regIsValid[Rb1s];
9442
                iqentry_a2_s [tail1] <= rf_source [Rb1s];
9443
        end
9444
        else begin
9445
                iqentry_a2_v [tail1] <= `INV;
9446
                iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
9447
        end
9448
end
9449
endtask
9450
 
9451
task a3_vs;
9452
begin
9453
        // if there is not an overlapping write to the register file.
9454
        if (Rc1s != Rt0s || !fetchbuf0_rfw) begin
9455
                iqentry_a3_v [tail1] <= regIsValid[Rc1s];
9456
                iqentry_a3_s [tail1] <= rf_source [Rc1s];
9457
        end
9458
        else begin
9459
                iqentry_a3_v [tail1] <= `INV;
9460
                iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
9461
        end
9462
end
9463
endtask
9464
 
9465
task enque0x;
9466
begin
9467
        if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
9468
                vqe0 <= vqe0 + 4'd1;
9469
                if (IsVCmprss(fetchbuf0_instr)) begin
9470
                        if (vm[fetchbuf0_instr[25:23]][vqe0])
9471
                        vqet0 <= vqet0 + 4'd1;
9472
                end
9473
                else
9474
                        vqet0 <= vqet0 + 4'd1;
9475
                if (vqe0 >= vl-2)
9476
                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
9477
                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
9478
                if (fetchbuf0_thrd)
9479
                        seq_num1 <= seq_num1 + 5'd1;
9480
                else
9481
                        seq_num <= seq_num + 5'd1;
9482
                if (fetchbuf0_rfw) begin
9483
                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
9484
                        rf_v[Rt0s] <= `INV;
9485
                end
9486
                if (canq2) begin
9487
                        if (vqe0 < vl-2) begin
9488
                                vqe0 <= vqe0 + 4'd2;
9489
                                if (IsVCmprss(fetchbuf0_instr)) begin
9490
                                        if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
9491
                                                vqet0 <= vqet0 + 4'd2;
9492
                                end
9493
                                else
9494
                                        vqet0 <= vqet0 + 4'd2;
9495
                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num+5'd1, vqe0 + 6'd1);
9496
                                if (fetchbuf0_thrd)
9497
                                        seq_num1 <= seq_num1 + 5'd2;
9498
                                else
9499
                                        seq_num <= seq_num + 5'd2;
9500
                                if (fetchbuf0_rfw) begin
9501
                                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };    // top bit indicates ALU/MEM bus
9502
                                        rf_v[Rt0s] <= `INV;
9503
                                end
9504
                        end
9505
                end
9506
        end
9507
        else begin
9508
                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, 6'd0);
9509
                if (fetchbuf0_thrd)
9510
                        seq_num1 <= seq_num1 + 5'd1;
9511
                else
9512
                        seq_num <= seq_num + 5'd1;
9513
                if (fetchbuf0_rfw) begin
9514
                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
9515
                        rf_v[Rt0s] <= `INV;
9516
                end
9517
        end
9518
end
9519
endtask
9520
 
9521 48 robfinch
// Enqueue fetchbuf0 onto the tail of the instruction queue
9522
task enque0;
9523
input [`QBITS] tail;
9524
input [63:0] seqnum;
9525
input [5:0] venno;
9526
begin
9527
        iqentry_exc[tail] <= `FLT_NONE;
9528
`ifdef SUPPORT_DBG
9529
    if (dbg_imatchA)
9530
        iqentry_exc[tail] <= `FLT_DBG;
9531
    else if (dbg_ctrl[63])
9532
        iqentry_exc[tail] <= `FLT_SSM;
9533
`endif
9534
        iqentry_sn   [tail]    <=  seqnum;
9535
        iqentry_v    [tail]    <=   `VAL;
9536
        iqentry_iv       [tail]    <=   `INV;
9537
        iqentry_is   [tail]    <= tail;
9538
        iqentry_thrd [tail]    <=   fetchbuf0_thrd;
9539
        iqentry_done [tail]    <=    `INV;
9540
        iqentry_cmt  [tail]    <=       `INV;
9541
        iqentry_out  [tail]    <=    `INV;
9542
        iqentry_res  [tail]    <=    `ZERO;
9543
        iqentry_instr[tail]    <=    IsVLS(fetchbuf0_instr) ? (vm[fnM2(fetchbuf0_instr)] ? fetchbuf0_instr : `NOP_INSN) : fetchbuf0_instr;
9544 55 robfinch
        iqentry_insln[tail]              <=  fetchbuf0_insln;
9545 48 robfinch
        iqentry_pt   [tail]    <=  predict_taken0;
9546
        iqentry_agen [tail]    <=    `INV;
9547
        iqentry_state[tail]    <=   IQS_IDLE;
9548
// If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9549
// inherit the previous pc.
9550
//if (IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15] &&
9551
//   (IsBrk(iqentry_instr[idm1(tail)]) && !iqentry_instr[idm1(tail1)][15] && iqentry_v[idm1(tail)]))
9552
//   iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
9553
//else
9554
         iqentry_pc   [tail] <= fetchbuf0_pc;
9555
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf0_instr);
9556
        iqentry_tgt  [tail]    <=       Rt0;
9557
        iqentry_Ra   [tail]    <= Ra0;
9558
        iqentry_Rb   [tail]    <= Rb0;
9559
        iqentry_Rc   [tail]    <= Rc0;
9560
        iqentry_vl   [tail]    <=  vl;
9561
        iqentry_ven  [tail]    <=   venno;
9562
        iqentry_exc  [tail]    <=    `EXC_NONE;
9563
        iqentry_a1   [tail]    <=    rfoa0;
9564
        iqentry_a1_v [tail]    <=    Source1Valid(fetchbuf0_instr) | regIsValid[Ra0s];
9565
        iqentry_a1_s [tail]    <=    rf_source[Ra0s];
9566
        iqentry_a2   [tail]    <=    rfob0;
9567
        iqentry_a2_v [tail]    <=    Source2Valid(fetchbuf0_instr) | regIsValid[Rb0s];
9568
        iqentry_a2_s [tail]    <=    rf_source[Rb0s];
9569
        iqentry_a3   [tail]    <=    rfoc0;
9570
        iqentry_a3_v [tail]    <=    Source3Valid(fetchbuf0_instr) | regIsValid[Rc0s];
9571
        iqentry_a3_s [tail]    <=    rf_source[Rc0s];
9572
end
9573
endtask
9574
 
9575
// Enque fetchbuf1. Fetchbuf1 might be the second instruction to queue so some
9576
// of this code checks to see which tail it is being queued on.
9577
task enque1;
9578
input [`QBITS] tail;
9579
input [63:0] seqnum;
9580
input [5:0] venno;
9581
begin
9582
 iqentry_exc[tail] <= `FLT_NONE;
9583
`ifdef SUPPORT_DBG
9584
    if (dbg_imatchB)
9585
        iqentry_exc[tail] <= `FLT_DBG;
9586
    else if (dbg_ctrl[63])
9587
        iqentry_exc[tail] <= `FLT_SSM;
9588
`endif
9589
        iqentry_sn   [tail]    <=   seqnum;
9590
        iqentry_v    [tail]    <=   `VAL;
9591
        iqentry_iv       [tail]    <=   `INV;
9592
        iqentry_is   [tail]    <= tail;
9593
        iqentry_thrd [tail]    <=   fetchbuf1_thrd;
9594
        iqentry_done [tail]    <=   `INV;
9595
        iqentry_cmt  [tail]    <=       `INV;
9596
        iqentry_out  [tail]    <=   `INV;
9597
        iqentry_res  [tail]    <=   `ZERO;
9598
        iqentry_instr[tail]    <=   IsVLS(fetchbuf1_instr) ? (vm[fnM2(fetchbuf1_instr)] ? fetchbuf1_instr : `NOP_INSN) : fetchbuf1_instr;
9599 55 robfinch
        iqentry_insln[tail]              <=  fetchbuf1_insln;
9600 48 robfinch
        iqentry_pt   [tail]    <=  predict_taken1;
9601
        iqentry_agen [tail]    <=   `INV;
9602
        iqentry_state[tail]    <=   IQS_IDLE;
9603
// If queing 2nd instruction must read from first
9604
if (tail==tail1) begin
9605
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9606
    // inherit the previous pc.
9607
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
9608
//        IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15])
9609
//       iqentry_pc   [tail]    <= fetchbuf0_pc;
9610
//    else
9611
                iqentry_pc   [tail] <= fetchbuf1_pc;
9612
end
9613
else begin
9614
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9615
    // inherit the previous pc.
9616
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
9617
//       (IsBrk(iqentry_instr[idp7(tail)]) && !iqentry_instr[idm1(tail)][15] && iqentry_v[idm1(tail)]))
9618
//       iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
9619
//    else
9620
                iqentry_pc   [tail] <= fetchbuf1_pc;
9621
end
9622
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf1_instr);
9623
        iqentry_tgt  [tail]    <= Rt1;
9624
        iqentry_Ra   [tail]    <= Ra1;
9625
        iqentry_Rb   [tail]    <= Rb1;
9626
        iqentry_Rc   [tail]    <= Rc1;
9627
        iqentry_vl   [tail]    <=  vl;
9628
        iqentry_ven  [tail]    <=   venno;
9629
        iqentry_exc  [tail]    <=   `EXC_NONE;
9630
        iqentry_a1   [tail]    <=       rfoa1;
9631
        iqentry_a1_v [tail]    <=       Source1Valid(fetchbuf1_instr) | regIsValid[Ra1s];
9632
        iqentry_a1_s [tail]    <=       rf_source[Ra1s];
9633
        iqentry_a2   [tail]    <=       rfob1;
9634
        iqentry_a2_v [tail]    <=       Source2Valid(fetchbuf1_instr) | regIsValid[Rb1s];
9635
        iqentry_a2_s [tail]    <=       rf_source[Rb1s];
9636
        iqentry_a3   [tail]    <=       rfoc1;
9637
        iqentry_a3_v [tail]    <=       Source3Valid(fetchbuf1_instr) | regIsValid[Rc1s];
9638
        iqentry_a3_s [tail]    <=       rf_source[Rc1s];
9639
end
9640
endtask
9641
 
9642
// This task takes care of commits for things other than the register file.
9643
task oddball_commit;
9644
input v;
9645
input [`QBITS] head;
9646
reg thread;
9647
begin
9648
    thread = iqentry_thrd[head];
9649
    if (v) begin
9650
        if (|iqentry_exc[head]) begin
9651
            excmiss <= TRUE;
9652
`ifdef SUPPORT_SMT
9653 51 robfinch
                excmisspc <= {tvec[3'd0][31:8],1'b0,ol[thread],5'h00};
9654 48 robfinch
            excthrd <= iqentry_thrd[head];
9655
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
9656
            epc0[thread] <= iqentry_pc[head]+ 32'd4;
9657
            epc1[thread] <= epc0[thread];
9658
            epc2[thread] <= epc1[thread];
9659
            epc3[thread] <= epc2[thread];
9660
            epc4[thread] <= epc3[thread];
9661
            epc5[thread] <= epc4[thread];
9662
            epc6[thread] <= epc5[thread];
9663
            epc7[thread] <= epc6[thread];
9664
            epc8[thread] <= epc7[thread];
9665
            im_stack[thread] <= {im_stack[thread][27:0],im};
9666
            ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9667
            pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9668
            rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
9669
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
9670
            mstatus[thread][5:3] <= 3'd0;
9671
            mstatus[thread][13:6] <= 8'h00;
9672
            mstatus[thread][19:14] <= 6'd0;
9673
`else
9674 51 robfinch
                excmisspc <= {tvec[3'd0][31:8],1'b0,ol,5'h00};
9675 48 robfinch
            excthrd <= iqentry_thrd[head];
9676
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
9677
            epc0 <= iqentry_pc[head]+ 32'd4;
9678
            epc1 <= epc0;
9679
            epc2 <= epc1;
9680
            epc3 <= epc2;
9681
            epc4 <= epc3;
9682
            epc5 <= epc4;
9683
            epc6 <= epc5;
9684
            epc7 <= epc6;
9685
            epc8 <= epc7;
9686
            im_stack <= {im_stack[27:0],im};
9687
            ol_stack <= {ol_stack[13:0],ol};
9688
            pl_stack <= {pl_stack[55:0],cpl};
9689
            rs_stack <= {rs_stack[55:0],rgs};
9690
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
9691
            mstatus[5:3] <= 3'd0;
9692
            mstatus[13:6] <= 8'h00;
9693
            mstatus[19:14] <= 6'd0;
9694
`endif
9695 49 robfinch
                                                wb_en <= `TRUE;
9696 48 robfinch
            sema[0] <= 1'b0;
9697
            ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9698
`ifdef SUPPORT_DBG
9699
            dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9700
            dbg_ctrl[63] <= FALSE;
9701
`endif
9702
        end
9703
        else
9704
        case(iqentry_instr[head][`INSTRUCTION_OP])
9705
        `BRK:
9706
                        // BRK is treated as a nop unless it's a software interrupt or a
9707
                        // hardware interrupt at a higher priority than the current priority.
9708
                if ((iqentry_instr[head][23:19] > 5'd0) || iqentry_instr[head][18:16] > im) begin
9709
                            excmiss <= TRUE;
9710
`ifdef SUPPORT_SMT
9711 51 robfinch
                        excmisspc <= {tvec[3'd0][31:8],1'b0,ol[thread],5'h00};
9712 48 robfinch
                        excthrd <= iqentry_thrd[head];
9713
                    epc0[thread] <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
9714
                    epc1[thread] <= epc0[thread];
9715
                    epc2[thread] <= epc1[thread];
9716
                    epc3[thread] <= epc2[thread];
9717
                    epc4[thread] <= epc3[thread];
9718
                    epc5[thread] <= epc4[thread];
9719
                    epc6[thread] <= epc5[thread];
9720
                    epc7[thread] <= epc6[thread];
9721
                    epc8[thread] <= epc7[thread];
9722
                    im_stack[thread] <= {im_stack[thread][27:0],im};
9723
                    ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9724
                    pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9725
                    rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
9726
                    mstatus[thread][19:14] <= 6'd0;
9727
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
9728
                    mstatus[thread][5:3] <= 3'd0;
9729
                        mstatus[thread][13:6] <= 8'h00;
9730
                    // For hardware interrupts only, set a new mask level
9731
                    // Select register set according to interrupt level
9732
                    if (iqentry_instr[head][23:19]==5'd0) begin
9733
                        mstatus[thread][2:0] <= 3'd7;//iqentry_instr[head][18:16];
9734
                        mstatus[thread][42:40] <= iqentry_instr[head][18:16];
9735
                        mstatus[thread][19:14] <= {3'b0,iqentry_instr[head][18:16]};
9736
                    end
9737
                    else
9738
                        mstatus[thread][19:14] <= 6'd0;
9739
`else
9740 51 robfinch
                        excmisspc <= {tvec[3'd0][31:8],1'b0,ol,5'h00};
9741 48 robfinch
                        excthrd <= iqentry_thrd[head];
9742
                    epc0 <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
9743
                    epc1 <= epc0;
9744
                    epc2 <= epc1;
9745
                    epc3 <= epc2;
9746
                    epc4 <= epc3;
9747
                    epc5 <= epc4;
9748
                    epc6 <= epc5;
9749
                    epc7 <= epc6;
9750
                    epc8 <= epc7;
9751
                    im_stack <= {im_stack[27:0],im};
9752
                    ol_stack <= {ol_stack[13:0],ol};
9753
                    pl_stack <= {pl_stack[55:0],cpl};
9754
                    rs_stack <= {rs_stack[55:0],rgs};
9755
                    mstatus[19:14] <= 6'd0;
9756
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
9757
                    mstatus[5:3] <= 3'd0;
9758
                        mstatus[13:6] <= 8'h00;
9759
                    // For hardware interrupts only, set a new mask level
9760
                    // Select register set according to interrupt level
9761
                    if (iqentry_instr[head][23:19]==5'd0) begin
9762
                        mstatus[2:0] <= 3'd7;//iqentry_instr[head][18:16];
9763
                        mstatus[42:40] <= iqentry_instr[head][18:16];
9764
                        mstatus[19:14] <= {3'b0,iqentry_instr[head][18:16]};
9765
                    end
9766
                    else
9767
                        mstatus[19:14] <= 6'd0;
9768
`endif
9769
                    sema[0] <= 1'b0;
9770
                    ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9771
`ifdef SUPPORT_DBG
9772
                    dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9773
                    dbg_ctrl[63] <= FALSE;
9774
`endif
9775
                end
9776
        `IVECTOR:
9777
            casez(iqentry_tgt[head])
9778
            8'b00100xxx:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9779
            8'b00101111:  vl <= iqentry_res[head];
9780
            default:    ;
9781
            endcase
9782
        `R2:
9783
            case(iqentry_instr[head][`INSTRUCTION_S2])
9784
            `R1:        case(iqentry_instr[head][20:16])
9785
                        `CHAIN_OFF:     cr0[18] <= 1'b0;
9786
                        `CHAIN_ON:      cr0[18] <= 1'b1;
9787
                        //`SETWB:               wbrcd[pcr[5:0]] <= 1'b1;
9788
                        default:        ;
9789
                                endcase
9790
            `VMOV:  casez(iqentry_tgt[head])
9791
                    12'b1111111_00???:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9792
                    12'b1111111_01111:  vl <= iqentry_res[head];
9793
                    default:    ;
9794
                    endcase
9795
`ifdef SUPPORT_SMT
9796
            `SEI:   mstatus[thread][2:0] <= iqentry_res[head][2:0];   // S1
9797
`else
9798
            `SEI:   mstatus[2:0] <= iqentry_res[head][2:0];   // S1
9799
`endif
9800
            `RTI:   begin
9801
                            excmiss <= TRUE;
9802
`ifdef SUPPORT_SMT
9803
                        excmisspc <= epc0[thread];
9804
                        excthrd <= thread;
9805
                        mstatus[thread][3:0] <= im_stack[thread][3:0];
9806
                        mstatus[thread][5:4] <= ol_stack[thread][1:0];
9807
                        mstatus[thread][13:6] <= pl_stack[thread][7:0];
9808
                        mstatus[thread][19:14] <= rs_stack[thread][5:0];
9809
                        im_stack[thread] <= {4'd15,im_stack[thread][27:4]};
9810
                        ol_stack[thread] <= {2'd0,ol_stack[thread][15:2]};
9811
                        pl_stack[thread] <= {8'h00,pl_stack[thread][63:8]};
9812
                        rs_stack[thread] <= {8'h00,rs_stack[thread][63:8]};
9813
                    epc0[thread] <= epc1[thread];
9814
                    epc1[thread] <= epc2[thread];
9815
                    epc2[thread] <= epc3[thread];
9816
                    epc3[thread] <= epc4[thread];
9817
                    epc4[thread] <= epc5[thread];
9818
                    epc5[thread] <= epc6[thread];
9819
                    epc6[thread] <= epc7[thread];
9820
                    epc7[thread] <= epc8[thread];
9821 51 robfinch
                    epc8[thread] <= {tvec[0][31:8], 1'b0, ol[thread], 5'h0};
9822 48 robfinch
`else
9823
                        excmisspc <= epc0;
9824
                        excthrd <= thread;
9825
                        mstatus[3:0] <= im_stack[3:0];
9826
                        mstatus[5:4] <= ol_stack[1:0];
9827
                        mstatus[13:6] <= pl_stack[7:0];
9828
                        mstatus[19:14] <= rs_stack[5:0];
9829
                        im_stack <= {4'd15,im_stack[31:4]};
9830
                        ol_stack <= {2'd0,ol_stack[15:2]};
9831
                        pl_stack <= {8'h00,pl_stack[63:8]};
9832
                        rs_stack <= {8'h00,rs_stack[63:8]};
9833
                    epc0 <= epc1;
9834
                    epc1 <= epc2;
9835
                    epc2 <= epc3;
9836
                    epc3 <= epc4;
9837
                    epc4 <= epc5;
9838
                    epc5 <= epc6;
9839
                    epc6 <= epc7;
9840
                    epc7 <= epc8;
9841 51 robfinch
                    epc8 <= {tvec[0][31:8], 1'b0, ol, 5'h0};
9842 48 robfinch
`endif
9843
                    sema[0] <= 1'b0;
9844
                    sema[iqentry_res[head][5:0]] <= 1'b0;
9845
                    vqe0  <= ve_hold[ 5: 0];
9846
                    vqet0 <= ve_hold[21:16];
9847
                    vqe1  <= ve_hold[37:32];
9848
                    vqet1 <= ve_hold[53:48];
9849
`ifdef SUPPORT_DBG
9850
                    dbg_ctrl[62:55] <= {FALSE,dbg_ctrl[62:56]};
9851
                    dbg_ctrl[63] <= dbg_ctrl[55];
9852
`endif
9853
                    end
9854 49 robfinch
            default: ;
9855
            endcase
9856
        `MEMNDX:
9857
            case(iqentry_instr[head][`INSTRUCTION_S2])
9858 48 robfinch
            `CACHEX:
9859 49 robfinch
                    case(iqentry_instr[head][22:18])
9860 48 robfinch
                    5'h03:  invic <= TRUE;
9861
                    5'h10:  cr0[30] <= FALSE;
9862
                    5'h11:  cr0[30] <= TRUE;
9863
                    default:    ;
9864
                    endcase
9865
            default: ;
9866
            endcase
9867
        `CSRRW:
9868
                        begin
9869 51 robfinch
                        write_csr(iqentry_instr[head][31:18],iqentry_a1[head],thread);
9870 48 robfinch
                        end
9871
        `REX:
9872
`ifdef SUPPORT_SMT
9873
            // Can only redirect to a lower level
9874
            if (ol[thread] < iqentry_instr[head][13:11]) begin
9875
                mstatus[thread][5:3] <= iqentry_instr[head][13:11];
9876
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol[thread]}];
9877
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol[thread]}];
9878
                mstatus[thread][13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
9879
            end
9880
`else
9881
            if (ol < iqentry_instr[head][13:11]) begin
9882
                mstatus[5:3] <= iqentry_instr[head][13:11];
9883
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol}];
9884
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol}];
9885
                mstatus[13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
9886
            end
9887
`endif
9888
        `CACHE:
9889 49 robfinch
            case(iqentry_instr[head][17:13])
9890 48 robfinch
            5'h03:  invic <= TRUE;
9891
            5'h10:  cr0[30] <= FALSE;
9892
            5'h11:  cr0[30] <= TRUE;
9893
            default:    ;
9894
            endcase
9895
        `FLOAT:
9896
            case(iqentry_instr[head][`INSTRUCTION_S2])
9897 49 robfinch
            `FRM: begin
9898 51 robfinch
                                fp_rm <= iqentry_res[head][2:0];
9899 49 robfinch
                                end
9900 48 robfinch
            `FCX:
9901
                begin
9902 51 robfinch
                    fp_sx <= fp_sx & ~iqentry_res[head][5];
9903
                    fp_inex <= fp_inex & ~iqentry_res[head][4];
9904
                    fp_dbzx <= fp_dbzx & ~(iqentry_res[head][3]|iqentry_res[head][0]);
9905
                    fp_underx <= fp_underx & ~iqentry_res[head][2];
9906
                    fp_overx <= fp_overx & ~iqentry_res[head][1];
9907
                    fp_giopx <= fp_giopx & ~iqentry_res[head][0];
9908
                    fp_infdivx <= fp_infdivx & ~iqentry_res[head][0];
9909
                    fp_zerozerox <= fp_zerozerox & ~iqentry_res[head][0];
9910
                    fp_subinfx   <= fp_subinfx   & ~iqentry_res[head][0];
9911
                    fp_infzerox  <= fp_infzerox  & ~iqentry_res[head][0];
9912
                    fp_NaNCmpx   <= fp_NaNCmpx   & ~iqentry_res[head][0];
9913
                    fp_swtx <= 1'b0;
9914 48 robfinch
                end
9915
            `FDX:
9916
                begin
9917 51 robfinch
                    fp_inexe <= fp_inexe     & ~iqentry_res[head][4];
9918
                    fp_dbzxe <= fp_dbzxe     & ~iqentry_res[head][3];
9919
                    fp_underxe <= fp_underxe & ~iqentry_res[head][2];
9920
                    fp_overxe <= fp_overxe   & ~iqentry_res[head][1];
9921
                    fp_invopxe <= fp_invopxe & ~iqentry_res[head][0];
9922 48 robfinch
                end
9923
            `FEX:
9924
                begin
9925 51 robfinch
                    fp_inexe <= fp_inexe     | iqentry_res[head][4];
9926
                    fp_dbzxe <= fp_dbzxe     | iqentry_res[head][3];
9927
                    fp_underxe <= fp_underxe | iqentry_res[head][2];
9928
                    fp_overxe <= fp_overxe   | iqentry_res[head][1];
9929
                    fp_invopxe <= fp_invopxe | iqentry_res[head][0];
9930 48 robfinch
                end
9931
            default:
9932
                begin
9933
                    // 31 to 29 is rounding mode
9934
                    // 28 to 24 are exception enables
9935
                    // 23 is nsfp
9936
                    // 22 is a fractie
9937 51 robfinch
                    fp_fractie <= iqentry_a0[head][22];
9938
                    fp_raz <= iqentry_a0[head][21];
9939 48 robfinch
                    // 20 is a 0
9940 51 robfinch
                    fp_neg <= iqentry_a0[head][19];
9941
                    fp_pos <= iqentry_a0[head][18];
9942
                    fp_zero <= iqentry_a0[head][17];
9943
                    fp_inf <= iqentry_a0[head][16];
9944 48 robfinch
                    // 15 swtx
9945
                    // 14 
9946 51 robfinch
                    fp_inex <= fp_inex | (fp_inexe & iqentry_a0[head][14]);
9947
                    fp_dbzx <= fp_dbzx | (fp_dbzxe & iqentry_a0[head][13]);
9948
                    fp_underx <= fp_underx | (fp_underxe & iqentry_a0[head][12]);
9949
                    fp_overx <= fp_overx | (fp_overxe & iqentry_a0[head][11]);
9950 48 robfinch
                    //fp_giopx <= fp_giopx | (fp_giopxe & iqentry_res2[head][10]);
9951
                    //fp_invopx <= fp_invopx | (fp_invopxe & iqentry_res2[head][24]);
9952
                    //
9953 51 robfinch
                    fp_cvtx <= fp_cvtx |  (fp_giopxe & iqentry_a0[head][7]);
9954
                    fp_sqrtx <= fp_sqrtx |  (fp_giopxe & iqentry_a0[head][6]);
9955
                    fp_NaNCmpx <= fp_NaNCmpx |  (fp_giopxe & iqentry_a0[head][5]);
9956
                    fp_infzerox <= fp_infzerox |  (fp_giopxe & iqentry_a0[head][4]);
9957
                    fp_zerozerox <= fp_zerozerox |  (fp_giopxe & iqentry_a0[head][3]);
9958
                    fp_infdivx <= fp_infdivx | (fp_giopxe & iqentry_a0[head][2]);
9959
                    fp_subinfx <= fp_subinfx | (fp_giopxe & iqentry_a0[head][1]);
9960
                    fp_snanx <= fp_snanx | (fp_giopxe & iqentry_a0[head][0]);
9961 48 robfinch
 
9962
                end
9963
            endcase
9964
        default:    ;
9965
        endcase
9966
        // Once the flow control instruction commits, NOP it out to allow
9967
        // pending stores to be issued.
9968
        iqentry_instr[head][5:0] <= `NOP;
9969
    end
9970
end
9971
endtask
9972
 
9973
// CSR access tasks
9974
task read_csr;
9975 51 robfinch
input [11:0] csrno;
9976 48 robfinch
output [63:0] dat;
9977
input thread;
9978
begin
9979
`ifdef SUPPORT_SMT
9980
    if (csrno[11:10] >= ol[thread])
9981
`else
9982
    if (csrno[11:10] >= ol)
9983
`endif
9984
    casez(csrno[9:0])
9985
    `CSR_CR0:       dat <= cr0;
9986
    `CSR_HARTID:    dat <= hartid;
9987
    `CSR_TICK:      dat <= tick;
9988
    `CSR_PCR:       dat <= pcr;
9989
    `CSR_PCR2:      dat <= pcr2;
9990 49 robfinch
    `CSR_PMR:                           dat <= pmr;
9991 48 robfinch
    `CSR_WBRCD:         dat <= wbrcd;
9992
    `CSR_SEMA:      dat <= sema;
9993
    `CSR_SBL:       dat <= sbl;
9994
    `CSR_SBU:       dat <= sbu;
9995
    `CSR_TCB:           dat <= tcb;
9996 51 robfinch
    `CSR_FSTAT:     dat <= {fp_rgs,fp_status};
9997 48 robfinch
`ifdef SUPPORT_DBG
9998
    `CSR_DBAD0:     dat <= dbg_adr0;
9999
    `CSR_DBAD1:     dat <= dbg_adr1;
10000
    `CSR_DBAD2:     dat <= dbg_adr2;
10001
    `CSR_DBAD3:     dat <= dbg_adr3;
10002
    `CSR_DBCTRL:    dat <= dbg_ctrl;
10003
    `CSR_DBSTAT:    dat <= dbg_stat;
10004
`endif
10005
    `CSR_CAS:       dat <= cas;
10006
    `CSR_TVEC:      dat <= tvec[csrno[2:0]];
10007 52 robfinch
    `CSR_BADADR:    dat <= badaddr[{thread,csrno[11:10]}];
10008
    `CSR_CAUSE:     dat <= {48'd0,cause[{thread,csrno[11:10]}]};
10009 48 robfinch
`ifdef SUPPORT_SMT
10010
    `CSR_IM_STACK:      dat <= im_stack[thread];
10011
    `CSR_OL_STACK:      dat <= ol_stack[thread];
10012
    `CSR_PL_STACK:      dat <= pl_stack[thread];
10013
    `CSR_RS_STACK:      dat <= rs_stack[thread];
10014
    `CSR_STATUS:    dat <= mstatus[thread][63:0];
10015
    `CSR_EPC0:      dat <= epc0[thread];
10016
    `CSR_EPC1:      dat <= epc1[thread];
10017
    `CSR_EPC2:      dat <= epc2[thread];
10018
    `CSR_EPC3:      dat <= epc3[thread];
10019
    `CSR_EPC4:      dat <= epc4[thread];
10020
    `CSR_EPC5:      dat <= epc5[thread];
10021
    `CSR_EPC6:      dat <= epc6[thread];
10022
    `CSR_EPC7:      dat <= epc7[thread];
10023
`else
10024
    `CSR_IM_STACK:      dat <= im_stack;
10025
    `CSR_OL_STACK:      dat <= ol_stack;
10026
    `CSR_PL_STACK:      dat <= pl_stack;
10027
    `CSR_RS_STACK:      dat <= rs_stack;
10028
    `CSR_STATUS:    dat <= mstatus[63:0];
10029
    `CSR_EPC0:      dat <= epc0;
10030
    `CSR_EPC1:      dat <= epc1;
10031
    `CSR_EPC2:      dat <= epc2;
10032
    `CSR_EPC3:      dat <= epc3;
10033
    `CSR_EPC4:      dat <= epc4;
10034
    `CSR_EPC5:      dat <= epc5;
10035
    `CSR_EPC6:      dat <= epc6;
10036
    `CSR_EPC7:      dat <= epc7;
10037
`endif
10038
    `CSR_CODEBUF:   dat <= codebuf[csrno[5:0]];
10039
    `CSR_TIME:          dat <= wc_times;
10040
    `CSR_INFO:
10041
                    case(csrno[3:0])
10042
                    4'd0:   dat <= "Finitron";  // manufacturer
10043
                    4'd1:   dat <= "        ";
10044
                    4'd2:   dat <= "64 bit  ";  // CPU class
10045
                    4'd3:   dat <= "        ";
10046
                    4'd4:   dat <= "FT64    ";  // Name
10047
                    4'd5:   dat <= "        ";
10048
                    4'd6:   dat <= 64'd1;       // model #
10049
                    4'd7:   dat <= 64'd1;       // serial number
10050
                    4'd8:   dat <= {32'd16384,32'd16384};   // cache sizes instruction,data
10051
                    4'd9:   dat <= 64'd0;
10052
                    default:    dat <= 64'd0;
10053
                    endcase
10054
    default:    begin
10055
                        $display("Unsupported CSR:%h",csrno[10:0]);
10056
                        dat <= 64'hEEEEEEEEEEEEEEEE;
10057
                        end
10058
    endcase
10059
    else
10060
        dat <= 64'h0;
10061
end
10062
endtask
10063
 
10064
task write_csr;
10065
input [13:0] csrno;
10066
input [63:0] dat;
10067
input thread;
10068
begin
10069
`ifdef SUPPORT_SMT
10070
    if (csrno[11:10] >= ol[thread])
10071
`else
10072
    if (csrno[11:10] >= ol)
10073
`endif
10074
    case(csrno[13:12])
10075
    2'd1:   // CSRRW
10076
        casez(csrno[9:0])
10077
        `CSR_CR0:       cr0 <= dat;
10078
        `CSR_PCR:       pcr <= dat[31:0];
10079
        `CSR_PCR2:      pcr2 <= dat;
10080 49 robfinch
        `CSR_PMR:       case(`NUM_IDU)
10081
                                                0,1:     pmr[0] <= 1'b1;
10082
                                                2:
10083
                                                        begin
10084
                                                                        if (dat[1:0]==2'b00)
10085
                                                                                pmr[1:0] <= 2'b01;
10086
                                                                        else
10087
                                                                                pmr[1:0] <= dat[1:0];
10088
                                                                        pmr[63:2] <= dat[63:2];
10089
                                                                end
10090
                                                3:
10091
                                                        begin
10092
                                                                        if (dat[2:0]==3'b000)
10093
                                                                                pmr[2:0] <= 3'b001;
10094
                                                                        else
10095
                                                                                pmr[2:0] <= dat[2:0];
10096
                                                                        pmr[63:3] <= dat[63:3];
10097
                                                                end
10098
                                                default:        pmr[0] <= 1'b1;
10099
                                                endcase
10100 48 robfinch
        `CSR_WBRCD:             wbrcd <= dat;
10101
        `CSR_SEMA:      sema <= dat;
10102
        `CSR_SBL:       sbl <= dat[31:0];
10103
        `CSR_SBU:       sbu <= dat[31:0];
10104
        `CSR_TCB:               tcb <= dat;
10105 51 robfinch
        `CSR_FSTAT:             fpu_csr[37:32] <= dat[37:32];
10106 52 robfinch
        `CSR_BADADR:    badaddr[{thread,csrno[11:10]}] <= dat;
10107
        `CSR_CAUSE:     cause[{thread,csrno[11:10]}] <= dat[15:0];
10108 48 robfinch
`ifdef SUPPORT_DBG
10109
        `CSR_DBAD0:     dbg_adr0 <= dat[AMSB:0];
10110
        `CSR_DBAD1:     dbg_adr1 <= dat[AMSB:0];
10111
        `CSR_DBAD2:     dbg_adr2 <= dat[AMSB:0];
10112
        `CSR_DBAD3:     dbg_adr3 <= dat[AMSB:0];
10113
        `CSR_DBCTRL:    dbg_ctrl <= dat;
10114
`endif
10115
        `CSR_CAS:       cas <= dat;
10116
        `CSR_TVEC:      tvec[csrno[2:0]] <= dat[31:0];
10117
`ifdef SUPPORT_SMT
10118
        `CSR_IM_STACK:  im_stack[thread] <= dat[31:0];
10119
        `CSR_OL_STACK:  ol_stack[thread] <= dat[15:0];
10120
        `CSR_PL_STACK:  pl_stack[thread] <= dat;
10121
        `CSR_RS_STACK:  rs_stack[thread] <= dat;
10122
        `CSR_STATUS:    mstatus[thread][63:0] <= dat;
10123
        `CSR_EPC0:      epc0[thread] <= dat;
10124
        `CSR_EPC1:      epc1[thread] <= dat;
10125
        `CSR_EPC2:      epc2[thread] <= dat;
10126
        `CSR_EPC3:      epc3[thread] <= dat;
10127
        `CSR_EPC4:      epc4[thread] <= dat;
10128
        `CSR_EPC5:      epc5[thread] <= dat;
10129
        `CSR_EPC6:      epc6[thread] <= dat;
10130
        `CSR_EPC7:      epc7[thread] <= dat;
10131
`else
10132
        `CSR_IM_STACK:  im_stack <= dat[31:0];
10133
        `CSR_OL_STACK:  ol_stack <= dat[15:0];
10134
        `CSR_PL_STACK:  pl_stack <= dat;
10135
        `CSR_RS_STACK:  rs_stack <= dat;
10136
        `CSR_STATUS:    mstatus[63:0] <= dat;
10137
        `CSR_EPC0:      epc0 <= dat;
10138
        `CSR_EPC1:      epc1 <= dat;
10139
        `CSR_EPC2:      epc2 <= dat;
10140
        `CSR_EPC3:      epc3 <= dat;
10141
        `CSR_EPC4:      epc4 <= dat;
10142
        `CSR_EPC5:      epc5 <= dat;
10143
        `CSR_EPC6:      epc6 <= dat;
10144
        `CSR_EPC7:      epc7 <= dat;
10145
`endif
10146
                `CSR_TIME:              begin
10147
                                                ld_time <= 6'h3f;
10148
                                                wc_time_dat <= dat;
10149
                                                end
10150
        `CSR_CODEBUF:   codebuf[csrno[5:0]] <= dat;
10151
        default:    ;
10152
        endcase
10153
    2'd2:   // CSRRS
10154
        case(csrno[9:0])
10155
        `CSR_CR0:       cr0 <= cr0 | dat;
10156
        `CSR_PCR:       pcr[31:0] <= pcr[31:0] | dat[31:0];
10157
        `CSR_PCR2:      pcr2 <= pcr2 | dat;
10158 49 robfinch
        `CSR_PMR:                               pmr <= pmr | dat;
10159 48 robfinch
        `CSR_WBRCD:             wbrcd <= wbrcd | dat;
10160
`ifdef SUPPORT_DBG
10161
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl | dat;
10162
`endif
10163
        `CSR_SEMA:      sema <= sema | dat;
10164
`ifdef SUPPORT_SMT
10165
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] | dat;
10166
`else
10167
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] | dat;
10168
`endif
10169
        default:    ;
10170
        endcase
10171
    2'd3:   // CSRRC
10172
        case(csrno[9:0])
10173
        `CSR_CR0:       cr0 <= cr0 & ~dat;
10174
        `CSR_PCR:       pcr <= pcr & ~dat;
10175
        `CSR_PCR2:      pcr2 <= pcr2 & ~dat;
10176 49 robfinch
        `CSR_PMR:                       begin
10177
                                                                if (dat[1:0]==2'b11)
10178
                                                                        pmr[1:0] <= 2'b01;
10179
                                                                else
10180
                                                                        pmr[1:0] <= pmr[1:0] & ~dat[1:0];
10181
                                                                pmr[63:2] <= pmr[63:2] & ~dat[63:2];
10182
                                                                end
10183 48 robfinch
        `CSR_WBRCD:             wbrcd <= wbrcd & ~dat;
10184
`ifdef SUPPORT_DBG
10185
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl & ~dat;
10186
`endif
10187
        `CSR_SEMA:      sema <= sema & ~dat;
10188
`ifdef SUPPORT_SMT
10189
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] & ~dat;
10190
`else
10191
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] & ~dat;
10192
`endif
10193
        default:    ;
10194
        endcase
10195
    default:    ;
10196
    endcase
10197
end
10198
endtask
10199
 
10200
 
10201
endmodule
10202
 
10203
 
10204
module decoder5 (num, out);
10205
input [4:0] num;
10206
output [31:1] out;
10207
reg [31:1] out;
10208
 
10209
always @(num)
10210
case (num)
10211
    5'd0 :      out <= 31'b0000000000000000000000000000000;
10212
    5'd1 :      out <= 31'b0000000000000000000000000000001;
10213
    5'd2 :      out <= 31'b0000000000000000000000000000010;
10214
    5'd3 :      out <= 31'b0000000000000000000000000000100;
10215
    5'd4 :      out <= 31'b0000000000000000000000000001000;
10216
    5'd5 :      out <= 31'b0000000000000000000000000010000;
10217
    5'd6 :      out <= 31'b0000000000000000000000000100000;
10218
    5'd7 :      out <= 31'b0000000000000000000000001000000;
10219
    5'd8 :      out <= 31'b0000000000000000000000010000000;
10220
    5'd9 :      out <= 31'b0000000000000000000000100000000;
10221
    5'd10:      out <= 31'b0000000000000000000001000000000;
10222
    5'd11:      out <= 31'b0000000000000000000010000000000;
10223
    5'd12:      out <= 31'b0000000000000000000100000000000;
10224
    5'd13:      out <= 31'b0000000000000000001000000000000;
10225
    5'd14:      out <= 31'b0000000000000000010000000000000;
10226
    5'd15:      out <= 31'b0000000000000000100000000000000;
10227
    5'd16:      out <= 31'b0000000000000001000000000000000;
10228
    5'd17:      out <= 31'b0000000000000010000000000000000;
10229
    5'd18:      out <= 31'b0000000000000100000000000000000;
10230
    5'd19:      out <= 31'b0000000000001000000000000000000;
10231
    5'd20:      out <= 31'b0000000000010000000000000000000;
10232
    5'd21:      out <= 31'b0000000000100000000000000000000;
10233
    5'd22:      out <= 31'b0000000001000000000000000000000;
10234
    5'd23:      out <= 31'b0000000010000000000000000000000;
10235
    5'd24:      out <= 31'b0000000100000000000000000000000;
10236
    5'd25:      out <= 31'b0000001000000000000000000000000;
10237
    5'd26:      out <= 31'b0000010000000000000000000000000;
10238
    5'd27:      out <= 31'b0000100000000000000000000000000;
10239
    5'd28:      out <= 31'b0001000000000000000000000000000;
10240
    5'd29:      out <= 31'b0010000000000000000000000000000;
10241
    5'd30:      out <= 31'b0100000000000000000000000000000;
10242
    5'd31:      out <= 31'b1000000000000000000000000000000;
10243
endcase
10244
 
10245
endmodule
10246
 
10247
module decoder6 (num, out);
10248
input [5:0] num;
10249
output [63:1] out;
10250
 
10251
wire [63:0] out1;
10252
 
10253
assign out1 = 64'd1 << num;
10254
assign out = out1[63:1];
10255
 
10256
endmodule
10257
 
10258
module decoder7 (num, out);
10259
input [6:0] num;
10260
output [127:1] out;
10261
 
10262
wire [127:0] out1;
10263
 
10264
assign out1 = 128'd1 << num;
10265
assign out = out1[127:1];
10266
 
10267
endmodule
10268
 
10269
module decoder8 (num, out);
10270
input [7:0] num;
10271
output [255:1] out;
10272
 
10273
wire [255:0] out1;
10274
 
10275
assign out1 = 256'd1 << num;
10276
assign out = out1[255:1];
10277
 
10278
endmodule
10279
 

powered by: WebSVN 2.1.0

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