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

Subversion Repositories thor

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

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

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

powered by: WebSVN 2.1.0

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