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

Subversion Repositories thor

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

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 56 robfinch
`AUIPC,`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 56 robfinch
`AUIPC,`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 56 robfinch
`AUIPC:                 IsRFW = TRUE;
2623 55 robfinch
`LUI:                           IsRFW = TRUE;
2624 48 robfinch
default:    IsRFW = FALSE;
2625
endcase
2626
endfunction
2627
 
2628
function IsShifti;
2629
input [47:0] isn;
2630
case(isn[`INSTRUCTION_OP])
2631
`R2:
2632
        if (isn[`INSTRUCTION_L2]==2'b00)
2633
            case(isn[`INSTRUCTION_S2])
2634
            `SHIFT31,`SHIFT63:
2635
                IsShifti = TRUE;
2636
            default: IsShifti = FALSE;
2637
            endcase
2638
    else
2639
        IsShifti = FALSE;
2640
default: IsShifti = FALSE;
2641
endcase
2642
endfunction
2643
 
2644
function IsRtop;
2645
input [47:0] isn;
2646
case(isn[`INSTRUCTION_OP])
2647
`R2:
2648
        if (isn[`INSTRUCTION_L2]==2'b01)
2649
            case(isn[47:42])
2650
            `RTOP: IsRtop = TRUE;
2651
            default: IsRtop = FALSE;
2652
            endcase
2653
    else
2654
        IsRtop = FALSE;
2655
default: IsRtop = FALSE;
2656
endcase
2657
endfunction
2658
 
2659
function IsMul;
2660
input [47:0] isn;
2661
case(isn[`INSTRUCTION_OP])
2662 50 robfinch
`R2:
2663 48 robfinch
        if (isn[`INSTRUCTION_L2]==2'b00)
2664 50 robfinch
    case(isn[`INSTRUCTION_S2])
2665
    `MULU,`MULSU,`MUL: IsMul = TRUE;
2666
    `MULUH,`MULSUH,`MULH: IsMul = TRUE;
2667
    default:    IsMul = FALSE;
2668
    endcase
2669 48 robfinch
        else
2670
                IsMul = FALSE;
2671
`MULUI,`MULI:  IsMul = TRUE;
2672
default:    IsMul = FALSE;
2673
endcase
2674
endfunction
2675
 
2676
function IsDivmod;
2677
input [47:0] isn;
2678
case(isn[`INSTRUCTION_OP])
2679 50 robfinch
`R2:
2680 48 robfinch
        if (isn[`INSTRUCTION_L2]==2'b00)
2681 50 robfinch
    case(isn[`INSTRUCTION_S2])
2682
    `DIVU,`DIVSU,`DIV: IsDivmod = TRUE;
2683
    `MODU,`MODSU,`MOD: IsDivmod = TRUE;
2684
    default: IsDivmod = FALSE;
2685
    endcase
2686 48 robfinch
        else
2687
                IsDivmod = FALSE;
2688
`DIVUI,`DIVI,`MODI:  IsDivmod = TRUE;
2689
default:    IsDivmod = FALSE;
2690
endcase
2691
endfunction
2692
 
2693
function IsExec;
2694
input [47:0] isn;
2695
case(isn[`INSTRUCTION_OP])
2696
`EXEC:  IsExec = TRUE;
2697
default:        IsExec = FALSE;
2698
endcase
2699
endfunction
2700
 
2701
function [7:0] fnSelect;
2702
input [47:0] ins;
2703 49 robfinch
input [`ABITS] adr;
2704 48 robfinch
begin
2705
        case(ins[`INSTRUCTION_OP])
2706
        `MEMNDX:
2707
                if (ins[`INSTRUCTION_L2]==2'b00)
2708
                   case(ins[`INSTRUCTION_S2])
2709 53 robfinch
               `LBX,`LBUX,`SBX,`LVBX,`LVBUX:
2710 48 robfinch
                   case(adr[2:0])
2711
                   3'd0:    fnSelect = 8'h01;
2712
                   3'd1:    fnSelect = 8'h02;
2713
                   3'd2:    fnSelect = 8'h04;
2714
                   3'd3:    fnSelect = 8'h08;
2715
                   3'd4:    fnSelect = 8'h10;
2716
                   3'd5:    fnSelect = 8'h20;
2717
                   3'd6:    fnSelect = 8'h40;
2718
                   3'd7:    fnSelect = 8'h80;
2719
                   endcase
2720 53 robfinch
                `LCX,`LCUX,`SCX,`LVCX,`LVCUX:
2721 48 robfinch
                    case(adr[2:1])
2722
                    2'd0:   fnSelect = 8'h03;
2723
                    2'd1:   fnSelect = 8'h0C;
2724
                    2'd2:   fnSelect = 8'h30;
2725
                    2'd3:   fnSelect = 8'hC0;
2726
                    endcase
2727 53 robfinch
                `LHX,`LHUX,`SHX,`LVHX,`LVHUX:
2728 48 robfinch
                   case(adr[2])
2729
                   1'b0:    fnSelect = 8'h0F;
2730
                   1'b1:    fnSelect = 8'hF0;
2731
                   endcase
2732 53 robfinch
               `INC,`LVWX,
2733 48 robfinch
               `LWX,`SWX,`LWRX,`SWCX,`LVX,`SVX,`CASX:
2734
                   fnSelect = 8'hFF;
2735
               default: fnSelect = 8'h00;
2736
                   endcase
2737
           else
2738
                fnSelect = 8'h00;
2739 52 robfinch
  `LB,`LBU,`SB:
2740 48 robfinch
                case(adr[2:0])
2741
                3'd0:   fnSelect = 8'h01;
2742
                3'd1:   fnSelect = 8'h02;
2743
                3'd2:   fnSelect = 8'h04;
2744
                3'd3:   fnSelect = 8'h08;
2745
                3'd4:   fnSelect = 8'h10;
2746
                3'd5:   fnSelect = 8'h20;
2747
                3'd6:   fnSelect = 8'h40;
2748
                3'd7:   fnSelect = 8'h80;
2749
                endcase
2750 53 robfinch
    `Lx,`LxU,`Sx,`LVx:
2751 48 robfinch
        casez(ins[20:18])
2752
        3'b100: fnSelect = 8'hFF;
2753
        3'b?10: fnSelect = adr[2] ? 8'hF0 : 8'h0F;
2754
        3'b??1:
2755
        case(adr[2:1])
2756
        2'd0:   fnSelect = 8'h03;
2757
        2'd1:   fnSelect = 8'h0C;
2758
        2'd2:   fnSelect = 8'h30;
2759
        2'd3:   fnSelect = 8'hC0;
2760
        endcase
2761
      default: fnSelect = 8'h00;
2762
      endcase
2763
        `INC,
2764
        `LWR,`SWC,`CAS:   fnSelect = 8'hFF;
2765
        `LV,`SV:   fnSelect = 8'hFF;
2766
        `AMO:
2767
                case(ins[23:21])
2768
                3'd0:   fnSelect = {8'h01 << adr[2:0]};
2769
                3'd1:   fnSelect = {8'h03 << {adr[2:1],1'b0}};
2770
                3'd2:   fnSelect = {8'h0F << {adr[2],2'b00}};
2771
                3'd3:   fnSelect = 8'hFF;
2772
                default:        fnSelect = 8'hFF;
2773
                endcase
2774
        default:        fnSelect = 8'h00;
2775
        endcase
2776
end
2777
endfunction
2778
/*
2779
function [63:0] fnDatc;
2780
input [47:0] ins;
2781
input [63:0] dat;
2782
case(ins[`INSTRUCTION_OP])
2783
`R2:
2784
        if (isn[`INSTRUCTION_L2]==2'b01)
2785
                case(ins[47:42])
2786
                `FINDB:         fnDatc = dat[7:0];
2787
                `FINDC:         fnDatc = dat[15:0];
2788
                `FINDH:         fnDatc = dat[31:0];
2789
                `FINDW:         fnDatc = dat[63:0];
2790
                default:        fnDatc = dat[63:0];
2791
                endcase
2792
        else
2793
                fnDatc = dat[63:0];
2794
default:        fnDatc = dat[63:0];
2795
endcase
2796
endfunction
2797
*/
2798
/*
2799
function [63:0] fnMemInc;
2800
input [47:0] ins;
2801
case(ins[`INSTRUCTION_OP])
2802
`R2:
2803
        if (isn[`INSTRUCTION_L2]==2'b01)
2804
                case(ins[47:42])
2805
                `FINDB:         fnMemInc = 32'd1;
2806
                `FINDC:         fnMemInc = 32'd2;
2807
                `FINDH:         fnMemInc = 32'd4;
2808
                `FINDW:         fnMemInc = 32'd8;
2809
                default:        fnMemInc = 32'd8;
2810
                endcase
2811
        else
2812
                fnMemInc = 32'd8;
2813
default:        fnMemInc = 32'd8;
2814
endcase
2815
endfunction
2816
*/
2817
function [63:0] fnDati;
2818
input [47:0] ins;
2819 49 robfinch
input [`ABITS] adr;
2820 48 robfinch
input [63:0] dat;
2821
case(ins[`INSTRUCTION_OP])
2822
`MEMNDX:
2823
        if (ins[`INSTRUCTION_L2]==2'b00)
2824
            case(ins[`INSTRUCTION_S2])
2825 53 robfinch
            `LBX,`LVBX:
2826 48 robfinch
                case(adr[2:0])
2827
                3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
2828
                3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
2829
                3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
2830
                3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
2831
                3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
2832
                3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
2833
                3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
2834
                3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
2835
                endcase
2836 53 robfinch
            `LBUX,`LVBUX:
2837 48 robfinch
                case(adr[2:0])
2838
                3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
2839
                3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
2840
                3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
2841
                3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
2842
                3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
2843
                3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
2844
                3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
2845
                3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
2846
                endcase
2847 53 robfinch
            `LCX,`LVCX:
2848 48 robfinch
                case(adr[2:1])
2849
                2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
2850
                2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
2851
                2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
2852
                2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
2853
                endcase
2854 53 robfinch
            `LCUX,`LVCUX:
2855 48 robfinch
                case(adr[2:1])
2856
                2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
2857
                2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
2858
                2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
2859
                2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
2860
                endcase
2861 53 robfinch
            `LHX,`LVHX:
2862 48 robfinch
                case(adr[2])
2863
                1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
2864
                1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
2865
                endcase
2866 53 robfinch
            `LHUX,`LVHUX:
2867 48 robfinch
                case(adr[2])
2868
                1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
2869
                1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
2870
                endcase
2871 53 robfinch
            `LWX,`LWRX,`LVX,`CAS,`LVWX:  fnDati = dat;
2872 48 robfinch
            default:    fnDati = dat;
2873
            endcase
2874
        else
2875
                fnDati = dat;
2876
`LB:
2877
  case(adr[2:0])
2878
  3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
2879
  3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
2880
  3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
2881
  3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
2882
  3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
2883
  3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
2884
  3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
2885
  3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
2886
  endcase
2887
`LBU:
2888
  case(adr[2:0])
2889
  3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
2890
  3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
2891
  3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
2892
  3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
2893
  3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
2894
  3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
2895
  3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
2896
  3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
2897
  endcase
2898 53 robfinch
`Lx,`LVx:
2899 48 robfinch
        casez(ins[20:18])
2900
        3'b100: fnDati = dat;
2901
        3'b?10:
2902
          case(adr[2])
2903
          1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
2904
          1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
2905
          endcase
2906
        3'b??1:
2907
          case(adr[2:1])
2908
          2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
2909
          2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
2910
          2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
2911
          2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
2912
          endcase
2913
        endcase
2914
`LxU:
2915
        casez(ins[20:18])
2916
        3'b100: fnDati = dat;
2917
        3'b?10:
2918
          case(adr[2])
2919
          1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
2920
          1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
2921
          endcase
2922
        3'b??1:
2923
          case(adr[2:1])
2924
          2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
2925
          2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
2926
          2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
2927
          2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
2928
          endcase
2929
        endcase
2930
`LWR,`LV,`CAS,`AMO:   fnDati = dat;
2931
default:    fnDati = dat;
2932
endcase
2933
endfunction
2934
 
2935
function [63:0] fnDato;
2936
input [47:0] isn;
2937
input [63:0] dat;
2938
case(isn[`INSTRUCTION_OP])
2939
`MEMNDX:
2940
        if (isn[`INSTRUCTION_L2]==2'b00)
2941
                case(isn[`INSTRUCTION_S2])
2942
                `SBX:   fnDato = {8{dat[7:0]}};
2943
                `SCX:   fnDato = {4{dat[15:0]}};
2944
                `SHX:   fnDato = {2{dat[31:0]}};
2945
                default:    fnDato = dat;
2946
                endcase
2947
        else
2948
                fnDato = dat;
2949
`SB:   fnDato = {8{dat[7:0]}};
2950
`Sx:
2951 49 robfinch
        casez(isn[20:18])
2952 48 robfinch
        3'b100: fnDato = dat;
2953
        3'b?10: fnDato = {2{dat[31:0]}};
2954
        3'b??1: fnDato = {4{dat[15:0]}};
2955
        default:        fnDato = dat;
2956
        endcase
2957
`AMO:
2958
        case(isn[23:21])
2959
        3'd0:   fnDato = {8{dat[7:0]}};
2960
        3'd1:   fnDato = {4{dat[15:0]}};
2961
        3'd2:   fnDato = {2{dat[31:0]}};
2962
        3'd3:   fnDato = dat;
2963
        default:        fnDato = dat;
2964
        endcase
2965
default:    fnDato = dat;
2966
endcase
2967
endfunction
2968
 
2969
// Indicate if the ALU instruction is valid immediately (single cycle operation)
2970
function IsSingleCycle;
2971
input [47:0] isn;
2972
IsSingleCycle = !(IsMul(isn)|IsDivmod(isn));
2973
endfunction
2974
 
2975
 
2976 53 robfinch
generate begin : gDecocderInst
2977
for (g = 0; g < QENTRIES; g = g + 1) begin
2978 48 robfinch
`ifdef SUPPORT_SMT
2979 53 robfinch
decoder8 iq0(.num({iqentry_tgt[g][8:7],iqentry_tgt[g][5:0]}), .out(iq_out[g]));
2980 48 robfinch
`else
2981 53 robfinch
decoder7 iq0(.num({iqentry_tgt[g][7],iqentry_tgt[g][5:0]}), .out(iq_out[g]));
2982 48 robfinch
`endif
2983 53 robfinch
end
2984
end
2985
endgenerate
2986 48 robfinch
 
2987
initial begin: Init
2988
        //
2989
        //
2990
        // set up panic messages
2991
        message[ `PANIC_NONE ]                  = "NONE            ";
2992
        message[ `PANIC_FETCHBUFBEQ ]           = "FETCHBUFBEQ     ";
2993
        message[ `PANIC_INVALIDISLOT ]          = "INVALIDISLOT    ";
2994
        message[ `PANIC_IDENTICALDRAMS ]        = "IDENTICALDRAMS  ";
2995
        message[ `PANIC_OVERRUN ]               = "OVERRUN         ";
2996
        message[ `PANIC_HALTINSTRUCTION ]       = "HALTINSTRUCTION ";
2997
        message[ `PANIC_INVALIDMEMOP ]          = "INVALIDMEMOP    ";
2998
        message[ `PANIC_INVALIDFBSTATE ]        = "INVALIDFBSTATE  ";
2999
        message[ `PANIC_INVALIDIQSTATE ]        = "INVALIDIQSTATE  ";
3000
        message[ `PANIC_BRANCHBACK ]            = "BRANCHBACK      ";
3001
        message[ `PANIC_MEMORYRACE ]            = "MEMORYRACE      ";
3002
        message[ `PANIC_ALU0ONLY ] = "ALU0 Only       ";
3003
 
3004
        for (n = 0; n < 64; n = n + 1)
3005
                codebuf[n] <= 48'h0;
3006
 
3007
end
3008
 
3009
// ---------------------------------------------------------------------------
3010
// FETCH
3011
// ---------------------------------------------------------------------------
3012
//
3013
assign fetchbuf0_mem   = IsMem(fetchbuf0_instr);
3014
assign fetchbuf0_memld = IsMem(fetchbuf0_instr) & IsLoad(fetchbuf0_instr);
3015
assign fetchbuf0_rfw   = IsRFW(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd);
3016
 
3017
assign fetchbuf1_mem   = IsMem(fetchbuf1_instr);
3018
assign fetchbuf1_memld = IsMem(fetchbuf1_instr) & IsLoad(fetchbuf1_instr);
3019
assign fetchbuf1_rfw   = IsRFW(fetchbuf1_instr,vqe1,vl,fetchbuf1_thrd);
3020
 
3021
FT64_fetchbuf #(AMSB,RSTPC) ufb1
3022
(
3023 49 robfinch
  .rst(rst),
3024
  .clk4x(clk4x),
3025
  .clk(clk),
3026
  .fcu_clk(fcu_clk),
3027
  .cs_i(adr_o[31:16]==16'hFFFF),
3028
  .cyc_i(cyc_o),
3029
  .stb_i(stb_o),
3030
  .ack_o(dc_ack),
3031
  .we_i(we_o),
3032
  .adr_i(adr_o[15:0]),
3033 56 robfinch
  .dat_i(dat_o[47:0]),
3034 55 robfinch
  .cmpgrp(cr0[10:8]),
3035 52 robfinch
  .freezePC(freezePC),
3036 49 robfinch
  .regLR(regLR),
3037
  .thread_en(thread_en),
3038
  .insn0(insn0),
3039
  .insn1(insn1),
3040
  .phit(phit),
3041
  .threadx(threadx),
3042
  .branchmiss(branchmiss),
3043
  .misspc(misspc),
3044
  .branchmiss_thrd(branchmiss_thrd),
3045
  .predict_takenA(predict_takenA),
3046
  .predict_takenB(predict_takenB),
3047
  .predict_takenC(predict_takenC),
3048
  .predict_takenD(predict_takenD),
3049
  .predict_taken0(predict_taken0),
3050
  .predict_taken1(predict_taken1),
3051
  .queued1(queued1),
3052
  .queued2(queued2),
3053
  .queuedNop(queuedNop),
3054
  .pc0(pc0),
3055
  .pc1(pc1),
3056
  .fetchbuf(fetchbuf),
3057
  .fetchbufA_v(fetchbufA_v),
3058
  .fetchbufB_v(fetchbufB_v),
3059
  .fetchbufC_v(fetchbufC_v),
3060
  .fetchbufD_v(fetchbufD_v),
3061
  .fetchbufA_pc(fetchbufA_pc),
3062
  .fetchbufB_pc(fetchbufB_pc),
3063
  .fetchbufC_pc(fetchbufC_pc),
3064
  .fetchbufD_pc(fetchbufD_pc),
3065
  .fetchbufA_instr(fetchbufA_instr),
3066
  .fetchbufB_instr(fetchbufB_instr),
3067
  .fetchbufC_instr(fetchbufC_instr),
3068
  .fetchbufD_instr(fetchbufD_instr),
3069
  .fetchbuf0_instr(fetchbuf0_instr),
3070
  .fetchbuf1_instr(fetchbuf1_instr),
3071
  .fetchbuf0_thrd(fetchbuf0_thrd),
3072
  .fetchbuf1_thrd(fetchbuf1_thrd),
3073
  .fetchbuf0_pc(fetchbuf0_pc),
3074
  .fetchbuf1_pc(fetchbuf1_pc),
3075
  .fetchbuf0_v(fetchbuf0_v),
3076
  .fetchbuf1_v(fetchbuf1_v),
3077
  .fetchbuf0_insln(fetchbuf0_insln),
3078
  .fetchbuf1_insln(fetchbuf1_insln),
3079
  .codebuf0(codebuf[insn0[21:16]]),
3080
  .codebuf1(codebuf[insn1[21:16]]),
3081
  .btgtA(btgtA),
3082
  .btgtB(btgtB),
3083
  .btgtC(btgtC),
3084
  .btgtD(btgtD),
3085
  .nop_fetchbuf(nop_fetchbuf),
3086
  .take_branch0(take_branch0),
3087
  .take_branch1(take_branch1),
3088
  .stompedRets(stompedOnRets),
3089
  .panic(fb_panic)
3090 48 robfinch
);
3091
 
3092
 
3093
 
3094
//initial begin: stop_at
3095
//#1000000; panic <= `PANIC_OVERRUN;
3096
//end
3097
 
3098
//
3099
// BRANCH-MISS LOGIC: livetarget
3100
//
3101
// livetarget implies that there is a not-to-be-stomped instruction that targets the register in question
3102
// therefore, if it is zero it implies the rf_v value should become VALID on a branchmiss
3103
// 
3104
 
3105
generate begin : live_target
3106
    for (g = 1; g < PREGS; g = g + 1) begin : lvtgt
3107
    assign livetarget[g] = iqentry_0_livetarget[g] |
3108
                        iqentry_1_livetarget[g] |
3109
                        iqentry_2_livetarget[g] |
3110
                        iqentry_3_livetarget[g] |
3111
                        iqentry_4_livetarget[g] |
3112
                        iqentry_5_livetarget[g] |
3113
                        iqentry_6_livetarget[g] |
3114 52 robfinch
                        iqentry_7_livetarget[g] |
3115
                        iqentry_8_livetarget[g] |
3116
                        iqentry_9_livetarget[g]
3117
                        ;
3118 48 robfinch
    end
3119
end
3120
endgenerate
3121
 
3122 53 robfinch
    assign  iqentry_0_livetarget = {PREGS {iqentry_v[0]}} & {PREGS {~iqentry_stomp[0] && iqentry_thrd[0]==branchmiss_thrd}} & iq_out[0],
3123
            iqentry_1_livetarget = {PREGS {iqentry_v[1]}} & {PREGS {~iqentry_stomp[1] && iqentry_thrd[1]==branchmiss_thrd}} & iq_out[1],
3124
            iqentry_2_livetarget = {PREGS {iqentry_v[2]}} & {PREGS {~iqentry_stomp[2] && iqentry_thrd[2]==branchmiss_thrd}} & iq_out[2],
3125
            iqentry_3_livetarget = {PREGS {iqentry_v[3]}} & {PREGS {~iqentry_stomp[3] && iqentry_thrd[3]==branchmiss_thrd}} & iq_out[3],
3126
            iqentry_4_livetarget = {PREGS {iqentry_v[4]}} & {PREGS {~iqentry_stomp[4] && iqentry_thrd[4]==branchmiss_thrd}} & iq_out[4],
3127
            iqentry_5_livetarget = {PREGS {iqentry_v[5]}} & {PREGS {~iqentry_stomp[5] && iqentry_thrd[5]==branchmiss_thrd}} & iq_out[5],
3128
            iqentry_6_livetarget = {PREGS {iqentry_v[6]}} & {PREGS {~iqentry_stomp[6] && iqentry_thrd[6]==branchmiss_thrd}} & iq_out[6],
3129
            iqentry_7_livetarget = {PREGS {iqentry_v[7]}} & {PREGS {~iqentry_stomp[7] && iqentry_thrd[7]==branchmiss_thrd}} & iq_out[7],
3130
            iqentry_8_livetarget = {PREGS {iqentry_v[8]}} & {PREGS {~iqentry_stomp[8] && iqentry_thrd[8]==branchmiss_thrd}} & iq_out[8],
3131
            iqentry_9_livetarget = {PREGS {iqentry_v[9]}} & {PREGS {~iqentry_stomp[9] && iqentry_thrd[9]==branchmiss_thrd}} & iq_out[9]
3132 52 robfinch
            ;
3133 48 robfinch
 
3134 52 robfinch
//
3135
// BRANCH-MISS LOGIC: latestID
3136
//
3137
// latestID is the instruction queue ID of the newest instruction (latest) that targets
3138
// a particular register.  looks a lot like scheduling logic, but in reverse.
3139
// 
3140
always @*
3141
        for (n = 0; n < QENTRIES; n = n + 1) begin
3142
                iqentry_cumulative[n] = 0;
3143
                for (j = n; j < n + QENTRIES; j = j + 1) begin
3144
                        if (missid==(j % QENTRIES))
3145
                                for (k = n; k <= j; k = k + 1)
3146
                                        iqentry_cumulative[n] = iqentry_cumulative[n] | iqentry_livetarget[k % QENTRIES];
3147
                end
3148
        end
3149 48 robfinch
 
3150 53 robfinch
always @*
3151
        for (n = 0; n < QENTRIES; n = n + 1)
3152
    iqentry_latestID[n] = (missid == n || ((iqentry_livetarget[n] & iqentry_cumulative[(n+1)%QENTRIES]) == {PREGS{1'b0}}))
3153
                                    ? iqentry_livetarget[n]
3154 52 robfinch
                                    : {PREGS{1'b0}};
3155 48 robfinch
 
3156 53 robfinch
always @*
3157
        for (n = 0; n < QENTRIES; n = n + 1)
3158
          iqentry_source[n] = | iqentry_latestID[n];
3159 48 robfinch
 
3160
reg vqueued2;
3161
assign Ra0 = fnRa(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3162
assign Rb0 = fnRb(fetchbuf0_instr,1'b0,vqe0,rfoa0[5:0],rfoa1[5:0],fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3163
assign Rc0 = fnRc(fetchbuf0_instr,vqe0,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3164
assign Rt0 = fnRt(fetchbuf0_instr,vqet0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3165
assign Ra1 = fnRa(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3166
assign Rb1 = fnRb(fetchbuf1_instr,1'b1,vqueued2 ? vqe0 + 1 : vqe1,rfoa0[5:0],rfoa1[5:0],fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3167
assign Rc1 = fnRc(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3168
assign Rt1 = fnRt(fetchbuf1_instr,vqueued2 ? vqet0 + 1 : vqet1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3169
 
3170 49 robfinch
//
3171
// additional logic for ISSUE
3172
//
3173
// for the moment, we look at ALU-input buffers to allow back-to-back issue of 
3174
// dependent instructions ... we do not, however, look ahead for DRAM requests 
3175
// that will become valid in the next cycle.  instead, these have to propagate
3176
// their results into the IQ entry directly, at which point it becomes issue-able
3177
//
3178 48 robfinch
 
3179 49 robfinch
// note that, for all intents & purposes, iqentry_done == iqentry_agen ... no need to duplicate
3180 48 robfinch
 
3181
wire [QENTRIES-1:0] args_valid;
3182
wire [QENTRIES-1:0] could_issue;
3183
wire [QENTRIES-1:0] could_issueid;
3184
 
3185
generate begin : issue_logic
3186
for (g = 0; g < QENTRIES; g = g + 1)
3187
begin
3188
assign args_valid[g] =
3189
                  (iqentry_a1_v[g]
3190 49 robfinch
`ifdef FU_BYPASS
3191 48 robfinch
        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3192 49 robfinch
        || ((iqentry_a1_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3193
        || ((iqentry_a1_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
3194
`endif
3195
        )
3196 48 robfinch
    && (iqentry_a2_v[g]
3197
        || (iqentry_mem[g] & ~iqentry_agen[g] & ~iqentry_memndx[g])    // a2 needs to be valid for indexed instruction
3198 49 robfinch
`ifdef FU_BYPASS
3199 48 robfinch
        || (iqentry_a2_s[g] == alu0_sourceid && alu0_dataready)
3200 49 robfinch
        || ((iqentry_a2_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3201
        || ((iqentry_a2_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
3202
`endif
3203
        )
3204 48 robfinch
    && (iqentry_a3_v[g]
3205
//        || (iqentry_mem[g] & ~iqentry_agen[g])
3206 49 robfinch
`ifdef FU_BYPASS
3207 48 robfinch
        || (iqentry_a3_s[g] == alu0_sourceid && alu0_dataready)
3208 49 robfinch
        || ((iqentry_a3_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3209
`endif
3210
        )
3211 48 robfinch
    ;
3212
 
3213
assign could_issue[g] = iqentry_v[g] && !iqentry_done[g] && !iqentry_out[g]
3214
                                                                                                && args_valid[g]
3215
                                                                                                && iqentry_iv[g]
3216
                        && (iqentry_mem[g] ? !iqentry_agen[g] : 1'b1);
3217
 
3218 52 robfinch
assign could_issueid[g] = (iqentry_v[g])// || (g==tail0 && canq1))// || (g==tail1 && canq2))
3219
                                                                                                                && !iqentry_iv[g];
3220 48 robfinch
//                && (iqentry_a1_v[g] 
3221
//        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3222
//        || (iqentry_a1_s[g] == alu1_sourceid && alu1_dataready));
3223
 
3224
end
3225
end
3226
endgenerate
3227
 
3228
// The (old) simulator didn't handle the asynchronous race loop properly in the 
3229
// original code. It would issue two instructions to the same islot. So the
3230
// issue logic has been re-written to eliminate the asynchronous loop.
3231
// Can't issue to the ALU if it's busy doing a long running operation like a 
3232
// divide.
3233
// ToDo: fix the memory synchronization, see fp_issue below
3234
 
3235
wire [`QBITS] heads [QENTRIES-1:0];
3236
assign heads[0] = head0;
3237
assign heads[1] = head1;
3238
assign heads[2] = head2;
3239
assign heads[3] = head3;
3240
assign heads[4] = head4;
3241
assign heads[5] = head5;
3242
assign heads[6] = head6;
3243
assign heads[7] = head7;
3244 52 robfinch
assign heads[8] = head8;
3245
assign heads[9] = head9;
3246 48 robfinch
 
3247
always @*
3248
begin
3249 49 robfinch
        iqentry_id1issue = {QENTRIES{1'b0}};
3250 48 robfinch
        if (id1_available) begin
3251
                for (n = 0; n < QENTRIES; n = n + 1)
3252 49 robfinch
                        if (could_issueid[heads[n]] && iqentry_id1issue=={QENTRIES{1'b0}})
3253 48 robfinch
                          iqentry_id1issue[heads[n]] = `TRUE;
3254
        end
3255 49 robfinch
end
3256
generate begin : gIDUIssue
3257
        if (`NUM_IDU > 1) begin
3258
                always @*
3259
                begin
3260
                        iqentry_id2issue = {QENTRIES{1'b0}};
3261
                        if (id2_available) begin
3262
                                for (n = 0; n < QENTRIES; n = n + 1)
3263
                                        if (could_issueid[heads[n]] && !iqentry_id1issue[heads[n]] && iqentry_id2issue=={QENTRIES{1'b0}})
3264
                                          iqentry_id2issue[heads[n]] = `TRUE;
3265
                        end
3266
                end
3267 48 robfinch
        end
3268 49 robfinch
        if (`NUM_IDU > 2) begin
3269
                always @*
3270
                begin
3271
                        iqentry_id3issue = {QENTRIES{1'b0}};
3272
                        if (id3_available) begin
3273
                                for (n = 0; n < QENTRIES; n = n + 1)
3274
                                        if (could_issueid[heads[n]]
3275
                                        && !iqentry_id1issue[heads[n]]
3276
                                        && !iqentry_id2issue[heads[n]]
3277
                                        && iqentry_id3issue=={QENTRIES{1'b0}})
3278
                                          iqentry_id3issue[heads[n]] = `TRUE;
3279
                        end
3280
                end
3281
        end
3282 48 robfinch
end
3283 49 robfinch
endgenerate
3284 48 robfinch
 
3285
always @*
3286
begin
3287 49 robfinch
        iqentry_alu0_issue = {QENTRIES{1'b0}};
3288
        iqentry_alu1_issue = {QENTRIES{1'b0}};
3289 48 robfinch
 
3290
        if (alu0_available & alu0_idle) begin
3291
                if (could_issue[head0] && iqentry_alu[head0]) begin
3292
                  iqentry_alu0_issue[head0] = `TRUE;
3293
                end
3294
                else if (could_issue[head1] && iqentry_alu[head1])
3295
                begin
3296
                  iqentry_alu0_issue[head1] = `TRUE;
3297
                end
3298
                else if (could_issue[head2] && iqentry_alu[head2]
3299
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3300
                )
3301
                begin
3302
                        iqentry_alu0_issue[head2] = `TRUE;
3303
                end
3304
                else if (could_issue[head3] && iqentry_alu[head3]
3305
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3306
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3307
                                ((!iqentry_v[head0])
3308
                        &&   (!iqentry_v[head1]))
3309
                        )
3310
                ) begin
3311
                        iqentry_alu0_issue[head3] = `TRUE;
3312
                end
3313
                else if (could_issue[head4] && iqentry_alu[head4]
3314
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3315
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3316
                                ((!iqentry_v[head0])
3317
                        &&   (!iqentry_v[head1]))
3318
                        )
3319
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3320
                                ((!iqentry_v[head0])
3321
                        &&   (!iqentry_v[head1])
3322
                        &&   (!iqentry_v[head2]))
3323
                        )
3324
                ) begin
3325
                        iqentry_alu0_issue[head4] = `TRUE;
3326
                end
3327
                else if (could_issue[head5] && iqentry_alu[head5]
3328
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3329
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3330
                                ((!iqentry_v[head0])
3331
                        &&   (!iqentry_v[head1]))
3332
                        )
3333
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3334
                                ((!iqentry_v[head0])
3335
                        &&   (!iqentry_v[head1])
3336
                        &&   (!iqentry_v[head2]))
3337
                        )
3338
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3339
                                ((!iqentry_v[head0])
3340
                        &&   (!iqentry_v[head1])
3341
                        &&   (!iqentry_v[head2])
3342
                        &&   (!iqentry_v[head3]))
3343
                        )
3344
                ) begin
3345
                        iqentry_alu0_issue[head5] = `TRUE;
3346
                end
3347
`ifdef FULL_ISSUE_LOGIC
3348
                else if (could_issue[head6] && iqentry_alu[head6]
3349
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3350
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3351
                                ((!iqentry_v[head0])
3352
                        &&   (!iqentry_v[head1]))
3353
                        )
3354
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3355
                                ((!iqentry_v[head0])
3356
                        &&   (!iqentry_v[head1])
3357
                        &&   (!iqentry_v[head2]))
3358
                        )
3359
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3360
                                ((!iqentry_v[head0])
3361
                        &&   (!iqentry_v[head1])
3362
                        &&   (!iqentry_v[head2])
3363
                        &&   (!iqentry_v[head3]))
3364
                        )
3365
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3366
                                ((!iqentry_v[head0])
3367
                        &&   (!iqentry_v[head1])
3368
                        &&   (!iqentry_v[head2])
3369
                        &&   (!iqentry_v[head3])
3370
                        &&   (!iqentry_v[head4]))
3371
                        )
3372
                ) begin
3373
                        iqentry_alu0_issue[head6] = `TRUE;
3374
                end
3375
                else if (could_issue[head7] && iqentry_alu[head7]
3376
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3377
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3378
                                ((!iqentry_v[head0])
3379
                        &&   (!iqentry_v[head1]))
3380
                        )
3381
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3382
                                ((!iqentry_v[head0])
3383
                        &&   (!iqentry_v[head1])
3384
                        &&   (!iqentry_v[head2]))
3385
                        )
3386
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3387
                                ((!iqentry_v[head0])
3388
                        &&   (!iqentry_v[head1])
3389
                        &&   (!iqentry_v[head2])
3390
                        &&   (!iqentry_v[head3]))
3391
                        )
3392
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3393
                                ((!iqentry_v[head0])
3394
                        &&   (!iqentry_v[head1])
3395
                        &&   (!iqentry_v[head2])
3396
                        &&   (!iqentry_v[head3])
3397
                        &&   (!iqentry_v[head4]))
3398
                        )
3399
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
3400
                                ((!iqentry_v[head0])
3401
                        &&   (!iqentry_v[head1])
3402
                        &&   (!iqentry_v[head2])
3403
                        &&   (!iqentry_v[head3])
3404
                        &&   (!iqentry_v[head4])
3405
                        &&   (!iqentry_v[head5]))
3406
                        )
3407
                ) begin
3408
                        iqentry_alu0_issue[head7] = `TRUE;
3409
                end
3410
`endif
3411
        end
3412
 
3413 49 robfinch
        if (alu1_available && alu1_idle && `NUM_ALU > 1) begin
3414 48 robfinch
                if ((could_issue & ~iqentry_alu0_issue & ~iqentry_alu0) != 8'h00) begin
3415
                if (could_issue[head0] && iqentry_alu[head0]
3416
                && !iqentry_alu0[head0] // alu0only
3417
                && !iqentry_alu0_issue[head0]) begin
3418
                  iqentry_alu1_issue[head0] = `TRUE;
3419
                end
3420
                else if (could_issue[head1] && !iqentry_alu0_issue[head1] && iqentry_alu[head1]
3421
                && !iqentry_alu0[head1])
3422
                begin
3423
                  iqentry_alu1_issue[head1] = `TRUE;
3424
                end
3425
                else if (could_issue[head2] && !iqentry_alu0_issue[head2] && iqentry_alu[head2]
3426
                && !iqentry_alu0[head2]
3427
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3428
                )
3429
                begin
3430
                        iqentry_alu1_issue[head2] = `TRUE;
3431
                end
3432
                else if (could_issue[head3] && !iqentry_alu0_issue[head3] && iqentry_alu[head3]
3433
                && !iqentry_alu0[head3]
3434
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3435
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3436
                                ((!iqentry_v[head0])
3437
                        &&   (!iqentry_v[head1]))
3438
                        )
3439
                ) begin
3440
                        iqentry_alu1_issue[head3] = `TRUE;
3441
                end
3442
                else if (could_issue[head4] && !iqentry_alu0_issue[head4] && iqentry_alu[head4]
3443
                && !iqentry_alu0[head4]
3444
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3445
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3446
                                ((!iqentry_v[head0])
3447
                        &&   (!iqentry_v[head1]))
3448
                        )
3449
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3450
                                ((!iqentry_v[head0])
3451
                        &&   (!iqentry_v[head1])
3452
                        &&   (!iqentry_v[head2]))
3453
                        )
3454
                ) begin
3455
                        iqentry_alu1_issue[head4] = `TRUE;
3456
                end
3457
                else if (could_issue[head5] && !iqentry_alu0_issue[head5] && iqentry_alu[head5]
3458
                && !iqentry_alu0[head5]
3459
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3460
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3461
                                ((!iqentry_v[head0])
3462
                        &&   (!iqentry_v[head1]))
3463
                        )
3464
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3465
                                ((!iqentry_v[head0])
3466
                        &&   (!iqentry_v[head1])
3467
                        &&   (!iqentry_v[head2]))
3468
                        )
3469
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3470
                                ((!iqentry_v[head0])
3471
                        &&   (!iqentry_v[head1])
3472
                        &&   (!iqentry_v[head2])
3473
                        &&   (!iqentry_v[head3]))
3474
                        )
3475
                ) begin
3476
                        iqentry_alu1_issue[head5] = `TRUE;
3477
                end
3478
`ifdef FULL_ISSUE_LOGIC
3479
                else if (could_issue[head6] && !iqentry_alu0_issue[head6] && iqentry_alu[head6]
3480
                && !iqentry_alu0[head6]
3481
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3482
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3483
                                ((!iqentry_v[head0])
3484
                        &&   (!iqentry_v[head1]))
3485
                        )
3486
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3487
                                ((!iqentry_v[head0])
3488
                        &&   (!iqentry_v[head1])
3489
                        &&   (!iqentry_v[head2]))
3490
                        )
3491
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3492
                                ((!iqentry_v[head0])
3493
                        &&   (!iqentry_v[head1])
3494
                        &&   (!iqentry_v[head2])
3495
                        &&   (!iqentry_v[head3]))
3496
                        )
3497
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3498
                                ((!iqentry_v[head0])
3499
                        &&   (!iqentry_v[head1])
3500
                        &&   (!iqentry_v[head2])
3501
                        &&   (!iqentry_v[head3])
3502
                        &&   (!iqentry_v[head4]))
3503
                        )
3504
                ) begin
3505
                        iqentry_alu1_issue[head6] = `TRUE;
3506
                end
3507
                else if (could_issue[head7] && !iqentry_alu0_issue[head7] && iqentry_alu[head7]
3508
                && !iqentry_alu0[head7]
3509
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3510
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3511
                                ((!iqentry_v[head0])
3512
                        &&   (!iqentry_v[head1]))
3513
                        )
3514
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3515
                                ((!iqentry_v[head0])
3516
                        &&   (!iqentry_v[head1])
3517
                        &&   (!iqentry_v[head2]))
3518
                        )
3519
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3520
                                ((!iqentry_v[head0])
3521
                        &&   (!iqentry_v[head1])
3522
                        &&   (!iqentry_v[head2])
3523
                        &&   (!iqentry_v[head3]))
3524
                        )
3525
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3526
                                ((!iqentry_v[head0])
3527
                        &&   (!iqentry_v[head1])
3528
                        &&   (!iqentry_v[head2])
3529
                        &&   (!iqentry_v[head3])
3530
                        &&   (!iqentry_v[head4]))
3531
                        )
3532
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
3533
                                ((!iqentry_v[head0])
3534
                        &&   (!iqentry_v[head1])
3535
                        &&   (!iqentry_v[head2])
3536
                        &&   (!iqentry_v[head3])
3537
                        &&   (!iqentry_v[head4])
3538
                        &&   (!iqentry_v[head5]))
3539
                        )
3540
                ) begin
3541
                        iqentry_alu1_issue[head7] = `TRUE;
3542
                end
3543
`endif
3544
        end
3545
//      aluissue(alu0_idle,8'h00,2'b00);
3546
//      aluissue(alu1_idle,iqentry_alu0,2'b01);
3547
        end
3548
end
3549
 
3550
always @*
3551
begin
3552 49 robfinch
        iqentry_fpu1_issue = {QENTRIES{1'b0}};
3553
//      fpu1issue(fpu1_idle,2'b00);
3554
        if (fpu1_idle && `NUM_FPU > 0) begin
3555 48 robfinch
    if (could_issue[head0] && iqentry_fpu[head0]) begin
3556 49 robfinch
      iqentry_fpu1_issue[head0] = `TRUE;
3557 48 robfinch
    end
3558
    else if (could_issue[head1] && iqentry_fpu[head1])
3559
    begin
3560 49 robfinch
      iqentry_fpu1_issue[head1] = `TRUE;
3561 48 robfinch
    end
3562
    else if (could_issue[head2] && iqentry_fpu[head2]
3563
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
3564
    ) begin
3565 49 robfinch
      iqentry_fpu1_issue[head2] = `TRUE;
3566 48 robfinch
    end
3567
    else if (could_issue[head3] && iqentry_fpu[head3]
3568
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
3569
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
3570
                ((!iqentry_v[head0])
3571
        &&   (!iqentry_v[head1]))
3572
        )
3573
    ) begin
3574 49 robfinch
      iqentry_fpu1_issue[head3] = `TRUE;
3575 48 robfinch
    end
3576
    else if (could_issue[head4] && iqentry_fpu[head4]
3577
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
3578
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
3579
                ((!iqentry_v[head0])
3580
        &&   (!iqentry_v[head1]))
3581
        )
3582
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
3583
                ((!iqentry_v[head0])
3584
        &&   (!iqentry_v[head1])
3585
        &&   (!iqentry_v[head2]))
3586
        )
3587
    ) begin
3588 49 robfinch
      iqentry_fpu1_issue[head4] = `TRUE;
3589 48 robfinch
    end
3590
    else if (could_issue[head5] && iqentry_fpu[head5]
3591
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
3592
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
3593
                ((!iqentry_v[head0])
3594
        &&   (!iqentry_v[head1]))
3595
        )
3596
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
3597
                ((!iqentry_v[head0])
3598
        &&   (!iqentry_v[head1])
3599
        &&   (!iqentry_v[head2]))
3600
        )
3601
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
3602
                ((!iqentry_v[head0])
3603
        &&   (!iqentry_v[head1])
3604
        &&   (!iqentry_v[head2])
3605
        &&   (!iqentry_v[head3]))
3606
        )
3607
        ) begin
3608 49 robfinch
              iqentry_fpu1_issue[head5] = `TRUE;
3609 48 robfinch
    end
3610
`ifdef FULL_ISSUE_LOGIC
3611
    else if (could_issue[head6] && iqentry_fpu[head6]
3612
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
3613
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
3614
                ((!iqentry_v[head0])
3615
        &&   (!iqentry_v[head1]))
3616
        )
3617
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
3618
                ((!iqentry_v[head0])
3619
        &&   (!iqentry_v[head1])
3620
        &&   (!iqentry_v[head2]))
3621
        )
3622
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
3623
                ((!iqentry_v[head0])
3624
        &&   (!iqentry_v[head1])
3625
        &&   (!iqentry_v[head2])
3626
        &&   (!iqentry_v[head3]))
3627
        )
3628
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
3629
                ((!iqentry_v[head0])
3630
        &&   (!iqentry_v[head1])
3631
        &&   (!iqentry_v[head2])
3632
        &&   (!iqentry_v[head3])
3633
        &&   (!iqentry_v[head4]))
3634
        )
3635
    ) begin
3636 49 robfinch
        iqentry_fpu1_issue[head6] = `TRUE;
3637 48 robfinch
    end
3638
    else if (could_issue[head7] && iqentry_fpu[head7]
3639
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
3640
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
3641
                ((!iqentry_v[head0])
3642
        &&   (!iqentry_v[head1]))
3643
        )
3644
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
3645
                ((!iqentry_v[head0])
3646
        &&   (!iqentry_v[head1])
3647
        &&   (!iqentry_v[head2]))
3648
        )
3649
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
3650
                ((!iqentry_v[head0])
3651
        &&   (!iqentry_v[head1])
3652
        &&   (!iqentry_v[head2])
3653
        &&   (!iqentry_v[head3]))
3654
        )
3655
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
3656
                ((!iqentry_v[head0])
3657
        &&   (!iqentry_v[head1])
3658
        &&   (!iqentry_v[head2])
3659
        &&   (!iqentry_v[head3])
3660
        &&   (!iqentry_v[head4]))
3661
        )
3662
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
3663
                ((!iqentry_v[head0])
3664
        &&   (!iqentry_v[head1])
3665
        &&   (!iqentry_v[head2])
3666
        &&   (!iqentry_v[head3])
3667
        &&   (!iqentry_v[head4])
3668
        &&   (!iqentry_v[head5]))
3669
        )
3670
        )
3671
    begin
3672 49 robfinch
                iqentry_fpu1_issue[head7] = `TRUE;
3673 48 robfinch
        end
3674
`endif
3675
        end
3676
end
3677
 
3678 49 robfinch
always @*
3679
begin
3680
        iqentry_fpu2_issue = {QENTRIES{1'b0}};
3681
//      fpu2issue(fpu2_idle,2'b00);
3682
        if (fpu2_idle && `NUM_FPU > 1) begin
3683
    if (could_issue[head0] && iqentry_fpu[head0] && !iqentry_fpu1_issue[head0]) begin
3684
      iqentry_fpu2_issue[head0] = `TRUE;
3685
    end
3686
    else if (could_issue[head1] && iqentry_fpu[head1] && !iqentry_fpu1_issue[head1])
3687
    begin
3688
      iqentry_fpu2_issue[head1] = `TRUE;
3689
    end
3690
    else if (could_issue[head2] && iqentry_fpu[head2] && !iqentry_fpu1_issue[head2]
3691
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
3692
    ) begin
3693
      iqentry_fpu2_issue[head2] = `TRUE;
3694
    end
3695
    else if (could_issue[head3] && iqentry_fpu[head3] && !iqentry_fpu1_issue[head3]
3696
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
3697
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
3698
                ((!iqentry_v[head0])
3699
        &&   (!iqentry_v[head1]))
3700
        )
3701
    ) begin
3702
      iqentry_fpu2_issue[head3] = `TRUE;
3703
    end
3704
    else if (could_issue[head4] && iqentry_fpu[head4] && !iqentry_fpu1_issue[head4]
3705
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
3706
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
3707
                ((!iqentry_v[head0])
3708
        &&   (!iqentry_v[head1]))
3709
        )
3710
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
3711
                ((!iqentry_v[head0])
3712
        &&   (!iqentry_v[head1])
3713
        &&   (!iqentry_v[head2]))
3714
        )
3715
    ) begin
3716
      iqentry_fpu2_issue[head4] = `TRUE;
3717
    end
3718
    else if (could_issue[head5] && iqentry_fpu[head5] && !iqentry_fpu1_issue[head5]
3719
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
3720
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
3721
                ((!iqentry_v[head0])
3722
        &&   (!iqentry_v[head1]))
3723
        )
3724
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
3725
                ((!iqentry_v[head0])
3726
        &&   (!iqentry_v[head1])
3727
        &&   (!iqentry_v[head2]))
3728
        )
3729
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
3730
                ((!iqentry_v[head0])
3731
        &&   (!iqentry_v[head1])
3732
        &&   (!iqentry_v[head2])
3733
        &&   (!iqentry_v[head3]))
3734
        )
3735
        ) begin
3736
              iqentry_fpu2_issue[head5] = `TRUE;
3737
    end
3738
`ifdef FULL_ISSUE_LOGIC
3739
    else if (could_issue[head6] && iqentry_fpu[head6] && !iqentry_fpu1_issue[head6]
3740
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
3741
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
3742
                ((!iqentry_v[head0])
3743
        &&   (!iqentry_v[head1]))
3744
        )
3745
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
3746
                ((!iqentry_v[head0])
3747
        &&   (!iqentry_v[head1])
3748
        &&   (!iqentry_v[head2]))
3749
        )
3750
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
3751
                ((!iqentry_v[head0])
3752
        &&   (!iqentry_v[head1])
3753
        &&   (!iqentry_v[head2])
3754
        &&   (!iqentry_v[head3]))
3755
        )
3756
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
3757
                ((!iqentry_v[head0])
3758
        &&   (!iqentry_v[head1])
3759
        &&   (!iqentry_v[head2])
3760
        &&   (!iqentry_v[head3])
3761
        &&   (!iqentry_v[head4]))
3762
        )
3763
    ) begin
3764
        iqentry_fpu2_issue[head6] = `TRUE;
3765
    end
3766
    else if (could_issue[head7] && iqentry_fpu[head7] && !iqentry_fpu1_issue[head7]
3767
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
3768
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
3769
                ((!iqentry_v[head0])
3770
        &&   (!iqentry_v[head1]))
3771
        )
3772
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
3773
                ((!iqentry_v[head0])
3774
        &&   (!iqentry_v[head1])
3775
        &&   (!iqentry_v[head2]))
3776
        )
3777
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
3778
                ((!iqentry_v[head0])
3779
        &&   (!iqentry_v[head1])
3780
        &&   (!iqentry_v[head2])
3781
        &&   (!iqentry_v[head3]))
3782
        )
3783
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
3784
                ((!iqentry_v[head0])
3785
        &&   (!iqentry_v[head1])
3786
        &&   (!iqentry_v[head2])
3787
        &&   (!iqentry_v[head3])
3788
        &&   (!iqentry_v[head4]))
3789
        )
3790
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
3791
                ((!iqentry_v[head0])
3792
        &&   (!iqentry_v[head1])
3793
        &&   (!iqentry_v[head2])
3794
        &&   (!iqentry_v[head3])
3795
        &&   (!iqentry_v[head4])
3796
        &&   (!iqentry_v[head5]))
3797
        )
3798
        )
3799
    begin
3800
                iqentry_fpu2_issue[head7] = `TRUE;
3801
        end
3802
`endif
3803
        end
3804
end
3805 48 robfinch
 
3806
wire [QENTRIES-1:0] nextqd;
3807
// Next queue id
3808
 
3809
reg [`QBITS] nid0;
3810
always @*
3811
if (iqentry_thrd[1]==iqentry_thrd[0])
3812 52 robfinch
        nid0 = 4'd1;
3813 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[0])
3814 52 robfinch
        nid0 = 4'd2;
3815 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[0])
3816 52 robfinch
        nid0 = 4'd3;
3817 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[0])
3818 52 robfinch
        nid0 = 4'd4;
3819 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[0])
3820 52 robfinch
        nid0 = 4'd5;
3821 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[0])
3822 52 robfinch
        nid0 = 4'd6;
3823 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[0])
3824 52 robfinch
        nid0 = 4'd7;
3825
else if (iqentry_thrd[8]==iqentry_thrd[0])
3826
        nid0 = 4'd8;
3827
else if (iqentry_thrd[9]==iqentry_thrd[0])
3828
        nid0 = 4'd9;
3829 48 robfinch
else
3830
        nid0 = 3'd0;
3831
 
3832
reg [`QBITS] nid1;
3833
always @*
3834
if (iqentry_thrd[2]==iqentry_thrd[1])
3835 52 robfinch
        nid1 = 4'd2;
3836 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[1])
3837 52 robfinch
        nid1 = 4'd3;
3838 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[1])
3839 52 robfinch
        nid1 = 4'd4;
3840 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[1])
3841 52 robfinch
        nid1 = 4'd5;
3842 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[1])
3843 52 robfinch
        nid1 = 4'd6;
3844 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[1])
3845 52 robfinch
        nid1 = 4'd7;
3846
else if (iqentry_thrd[8]==iqentry_thrd[1])
3847
        nid1 = 4'd8;
3848
else if (iqentry_thrd[9]==iqentry_thrd[1])
3849
        nid1 = 4'd9;
3850 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[1])
3851 52 robfinch
        nid1 = 4'd0;
3852 48 robfinch
else
3853 52 robfinch
        nid1 = 4'd1;
3854 48 robfinch
 
3855
reg [`QBITS] nid2;
3856
always @*
3857
if (iqentry_thrd[3]==iqentry_thrd[2])
3858 52 robfinch
        nid2 = 4'd3;
3859 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[2])
3860 52 robfinch
        nid2 = 4'd4;
3861 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[2])
3862 52 robfinch
        nid2 = 4'd5;
3863 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[2])
3864 52 robfinch
        nid2 = 4'd6;
3865 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[2])
3866 52 robfinch
        nid2 = 4'd7;
3867
else if (iqentry_thrd[8]==iqentry_thrd[2])
3868
        nid2 = 4'd8;
3869
else if (iqentry_thrd[9]==iqentry_thrd[2])
3870
        nid2 = 4'd9;
3871 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[2])
3872 52 robfinch
        nid2 = 4'd0;
3873 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[2])
3874 52 robfinch
        nid2 = 4'd1;
3875 48 robfinch
else
3876 52 robfinch
        nid2 = 4'd2;
3877 48 robfinch
 
3878
reg [`QBITS] nid3;
3879
always @*
3880
if (iqentry_thrd[4]==iqentry_thrd[3])
3881 52 robfinch
        nid3 = 4'd4;
3882 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[3])
3883 52 robfinch
        nid3 = 4'd5;
3884 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[3])
3885 52 robfinch
        nid3 = 4'd6;
3886 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[3])
3887 52 robfinch
        nid3 = 4'd7;
3888
else if (iqentry_thrd[8]==iqentry_thrd[3])
3889
        nid3 = 4'd8;
3890
else if (iqentry_thrd[9]==iqentry_thrd[3])
3891
        nid3 = 4'd9;
3892 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[3])
3893 52 robfinch
        nid3 = 4'd0;
3894 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[3])
3895 52 robfinch
        nid3 = 4'd1;
3896 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[3])
3897 52 robfinch
        nid3 = 4'd2;
3898 48 robfinch
else
3899 52 robfinch
        nid3 = 4'd3;
3900 48 robfinch
 
3901
reg [`QBITS] nid4;
3902
always @*
3903
if (iqentry_thrd[5]==iqentry_thrd[4])
3904 52 robfinch
        nid4 = 4'd5;
3905 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[4])
3906 52 robfinch
        nid4 = 4'd6;
3907 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[4])
3908 52 robfinch
        nid4 = 4'd7;
3909
else if (iqentry_thrd[8]==iqentry_thrd[4])
3910
        nid4 = 4'd8;
3911
else if (iqentry_thrd[9]==iqentry_thrd[4])
3912
        nid4 = 4'd9;
3913 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[4])
3914 52 robfinch
        nid4 = 4'd0;
3915 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[4])
3916 52 robfinch
        nid4 = 4'd1;
3917 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[4])
3918 52 robfinch
        nid4 = 4'd2;
3919 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[4])
3920 52 robfinch
        nid4 = 4'd3;
3921 48 robfinch
else
3922 52 robfinch
        nid4 = 4'd4;
3923 48 robfinch
 
3924
reg [`QBITS] nid5;
3925
always @*
3926
if (iqentry_thrd[6]==iqentry_thrd[5])
3927 52 robfinch
        nid5 = 4'd6;
3928 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[5])
3929 52 robfinch
        nid5 = 4'd7;
3930
else if (iqentry_thrd[8]==iqentry_thrd[5])
3931
        nid5 = 4'd8;
3932
else if (iqentry_thrd[9]==iqentry_thrd[5])
3933
        nid5 = 4'd9;
3934 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[5])
3935 52 robfinch
        nid5 = 4'd0;
3936 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[5])
3937 52 robfinch
        nid5 = 4'd1;
3938 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[5])
3939 52 robfinch
        nid5 = 4'd2;
3940 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[5])
3941 52 robfinch
        nid5 = 4'd3;
3942 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[5])
3943 52 robfinch
        nid5 = 4'd4;
3944 48 robfinch
else
3945 52 robfinch
        nid5 = 4'd5;
3946 48 robfinch
 
3947
reg [`QBITS] nid6;
3948
always @*
3949
if (iqentry_thrd[7]==iqentry_thrd[6])
3950 52 robfinch
        nid6 = 4'd7;
3951
else if (iqentry_thrd[8]==iqentry_thrd[6])
3952
        nid6 = 4'd8;
3953
else if (iqentry_thrd[9]==iqentry_thrd[6])
3954
        nid6 = 4'd9;
3955 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[6])
3956 52 robfinch
        nid6 = 4'd0;
3957 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[6])
3958 52 robfinch
        nid6 = 4'd1;
3959 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[6])
3960 52 robfinch
        nid6 = 4'd2;
3961 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[6])
3962 52 robfinch
        nid6 = 4'd3;
3963 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[6])
3964 52 robfinch
        nid6 = 4'd4;
3965 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[6])
3966 52 robfinch
        nid6 = 4'd5;
3967 48 robfinch
else
3968 52 robfinch
        nid6 = 4'd6;
3969 48 robfinch
 
3970
reg [`QBITS] nid7;
3971
always @*
3972 52 robfinch
if (iqentry_thrd[8]==iqentry_thrd[7])
3973
        nid7 = 4'd8;
3974
else if (iqentry_thrd[9]==iqentry_thrd[7])
3975
        nid7 = 4'd9;
3976
else if (iqentry_thrd[0]==iqentry_thrd[7])
3977
        nid7 = 4'd0;
3978 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[7])
3979 52 robfinch
        nid7 = 4'd1;
3980 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[7])
3981 52 robfinch
        nid7 = 4'd2;
3982 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[7])
3983 52 robfinch
        nid7 = 4'd3;
3984 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[7])
3985 52 robfinch
        nid7 = 4'd4;
3986 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[7])
3987 52 robfinch
        nid7 = 4'd5;
3988 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[7])
3989 52 robfinch
        nid7 = 4'd6;
3990 48 robfinch
else
3991 52 robfinch
        nid7 = 4'd7;
3992 48 robfinch
 
3993 52 robfinch
reg [`QBITS] nid8;
3994
always @*
3995
if (iqentry_thrd[9]==iqentry_thrd[8])
3996
        nid8 = 4'd9;
3997
else if (iqentry_thrd[0]==iqentry_thrd[8])
3998
        nid8 = 4'd0;
3999
else if (iqentry_thrd[1]==iqentry_thrd[8])
4000
        nid8 = 4'd1;
4001
else if (iqentry_thrd[2]==iqentry_thrd[8])
4002
        nid8 = 4'd2;
4003
else if (iqentry_thrd[3]==iqentry_thrd[8])
4004
        nid8 = 4'd3;
4005
else if (iqentry_thrd[4]==iqentry_thrd[8])
4006
        nid8 = 4'd4;
4007
else if (iqentry_thrd[5]==iqentry_thrd[8])
4008
        nid8 = 4'd5;
4009
else if (iqentry_thrd[6]==iqentry_thrd[8])
4010
        nid8 = 4'd6;
4011
else if (iqentry_thrd[7]==iqentry_thrd[8])
4012
        nid8 = 4'd7;
4013
else
4014
        nid8 = 4'd8;
4015
 
4016
reg [`QBITS] nid9;
4017
always @*
4018
if (iqentry_thrd[0]==iqentry_thrd[9])
4019
        nid9 = 4'd0;
4020
else if (iqentry_thrd[1]==iqentry_thrd[9])
4021
        nid9 = 4'd1;
4022
else if (iqentry_thrd[2]==iqentry_thrd[9])
4023
        nid9 = 4'd2;
4024
else if (iqentry_thrd[3]==iqentry_thrd[9])
4025
        nid9 = 4'd3;
4026
else if (iqentry_thrd[4]==iqentry_thrd[9])
4027
        nid9 = 4'd4;
4028
else if (iqentry_thrd[5]==iqentry_thrd[9])
4029
        nid9 = 4'd5;
4030
else if (iqentry_thrd[6]==iqentry_thrd[9])
4031
        nid9 = 4'd6;
4032
else if (iqentry_thrd[7]==iqentry_thrd[9])
4033
        nid9 = 4'd7;
4034
else if (iqentry_thrd[8]==iqentry_thrd[9])
4035
        nid9 = 4'd8;
4036
else
4037
        nid9 = 4'd9;
4038
 
4039 48 robfinch
// Search the queue for the next entry on the same thread.
4040
reg [`QBITS] nid;
4041
always @*
4042
if (iqentry_thrd[idp1(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4043
        nid = idp1(fcu_id);
4044
else if (iqentry_thrd[idp2(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4045
        nid = idp2(fcu_id);
4046
else if (iqentry_thrd[idp3(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4047
        nid = idp3(fcu_id);
4048
else if (iqentry_thrd[idp4(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4049
        nid = idp4(fcu_id);
4050
else if (iqentry_thrd[idp5(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4051
        nid = idp5(fcu_id);
4052
else if (iqentry_thrd[idp6(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4053
        nid = idp6(fcu_id);
4054
else if (iqentry_thrd[idp7(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4055
        nid = idp7(fcu_id);
4056 52 robfinch
else if (iqentry_thrd[idp8(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4057
        nid = idp8(fcu_id);
4058
else if (iqentry_thrd[idp9(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4059
        nid = idp9(fcu_id);
4060 48 robfinch
else
4061
        nid = fcu_id;
4062
 
4063
assign  nextqd[0] = iqentry_sn[nid0] > iqentry_sn[0] || iqentry_v[0];
4064
assign  nextqd[1] = iqentry_sn[nid1] > iqentry_sn[1] || iqentry_v[1];
4065
assign  nextqd[2] = iqentry_sn[nid2] > iqentry_sn[2] || iqentry_v[2];
4066
assign  nextqd[3] = iqentry_sn[nid3] > iqentry_sn[3] || iqentry_v[3];
4067
assign  nextqd[4] = iqentry_sn[nid4] > iqentry_sn[4] || iqentry_v[4];
4068
assign  nextqd[5] = iqentry_sn[nid5] > iqentry_sn[5] || iqentry_v[5];
4069
assign  nextqd[6] = iqentry_sn[nid6] > iqentry_sn[6] || iqentry_v[6];
4070
assign  nextqd[7] = iqentry_sn[nid7] > iqentry_sn[7] || iqentry_v[7];
4071 52 robfinch
assign  nextqd[8] = iqentry_sn[nid8] > iqentry_sn[8] || iqentry_v[8];
4072
assign  nextqd[9] = iqentry_sn[nid9] > iqentry_sn[9] || iqentry_v[9];
4073 48 robfinch
 
4074
//assign nextqd = 8'hFF;
4075
 
4076
// Don't issue to the fcu until the following instruction is enqueued.
4077
// However, if the queue is full then issue anyway. A branch miss will likely occur.
4078
always @*//(could_issue or head0 or head1 or head2 or head3 or head4 or head5 or head6 or head7)
4079
begin
4080 49 robfinch
        iqentry_fcu_issue = {QENTRIES{1'b0}};
4081 48 robfinch
        if (fcu_done) begin
4082
    if (could_issue[head0] && iqentry_fc[head0] && nextqd[head0]) begin
4083
      iqentry_fcu_issue[head0] = `TRUE;
4084
    end
4085
    else if (could_issue[head1] && iqentry_fc[head1] && nextqd[head1])
4086
    begin
4087
      iqentry_fcu_issue[head1] = `TRUE;
4088
    end
4089
    else if (could_issue[head2] && iqentry_fc[head2] && nextqd[head2]
4090
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4091
    ) begin
4092
                iqentry_fcu_issue[head2] = `TRUE;
4093
    end
4094
    else if (could_issue[head3] && iqentry_fc[head3] && nextqd[head3]
4095
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4096
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4097
                ((!iqentry_v[head0])
4098
        &&   (!iqentry_v[head1]))
4099
        )
4100
    ) begin
4101
                iqentry_fcu_issue[head3] = `TRUE;
4102
    end
4103
    else if (could_issue[head4] && iqentry_fc[head4] && nextqd[head4]
4104
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4105
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4106
                ((!iqentry_v[head0])
4107
        &&   (!iqentry_v[head1]))
4108
        )
4109
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4110
                ((!iqentry_v[head0])
4111
        &&   (!iqentry_v[head1])
4112
        &&   (!iqentry_v[head2]))
4113
        )
4114
    ) begin
4115
                iqentry_fcu_issue[head4] = `TRUE;
4116
    end
4117
    else if (could_issue[head5] && iqentry_fc[head5] && nextqd[head5]
4118
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4119
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4120
                ((!iqentry_v[head0])
4121
        &&   (!iqentry_v[head1]))
4122
        )
4123
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4124
                ((!iqentry_v[head0])
4125
        &&   (!iqentry_v[head1])
4126
        &&   (!iqentry_v[head2]))
4127
        )
4128
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4129
                ((!iqentry_v[head0])
4130
        &&   (!iqentry_v[head1])
4131
        &&   (!iqentry_v[head2])
4132
        &&   (!iqentry_v[head3]))
4133
        )
4134
    ) begin
4135
                iqentry_fcu_issue[head5] = `TRUE;
4136
    end
4137
 
4138
`ifdef FULL_ISSUE_LOGIC
4139
    else if (could_issue[head6] && iqentry_fc[head6] && nextqd[head6]
4140
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4141
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4142
                ((!iqentry_v[head0])
4143
        &&   (!iqentry_v[head1]))
4144
        )
4145
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4146
                ((!iqentry_v[head0])
4147
        &&   (!iqentry_v[head1])
4148
        &&   (!iqentry_v[head2]))
4149
        )
4150
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4151
                ((!iqentry_v[head0])
4152
        &&   (!iqentry_v[head1])
4153
        &&   (!iqentry_v[head2])
4154
        &&   (!iqentry_v[head3]))
4155
        )
4156
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4157
                ((!iqentry_v[head0])
4158
        &&   (!iqentry_v[head1])
4159
        &&   (!iqentry_v[head2])
4160
        &&   (!iqentry_v[head3])
4161
        &&   (!iqentry_v[head4]))
4162
        )
4163
    ) begin
4164
                iqentry_fcu_issue[head6] = `TRUE;
4165
    end
4166
 
4167
    else if (could_issue[head7] && iqentry_fc[head7]
4168
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4169
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4170
                ((!iqentry_v[head0])
4171
        &&   (!iqentry_v[head1]))
4172
        )
4173
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4174
                ((!iqentry_v[head0])
4175
        &&   (!iqentry_v[head1])
4176
        &&   (!iqentry_v[head2]))
4177
        )
4178
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4179
                ((!iqentry_v[head0])
4180
        &&   (!iqentry_v[head1])
4181
        &&   (!iqentry_v[head2])
4182
        &&   (!iqentry_v[head3]))
4183
        )
4184
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4185
                ((!iqentry_v[head0])
4186
        &&   (!iqentry_v[head1])
4187
        &&   (!iqentry_v[head2])
4188
        &&   (!iqentry_v[head3])
4189
        &&   (!iqentry_v[head4]))
4190
        )
4191
    && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4192
                ((!iqentry_v[head0])
4193
        &&   (!iqentry_v[head1])
4194
        &&   (!iqentry_v[head2])
4195
        &&   (!iqentry_v[head3])
4196
        &&   (!iqentry_v[head4])
4197
        &&   (!iqentry_v[head5]))
4198
        )
4199
    ) begin
4200
                iqentry_fcu_issue[head7] = `TRUE;
4201
        end
4202
`endif
4203
        end
4204
end
4205
 
4206
//
4207
// determine if the instructions ready to issue can, in fact, issue.
4208
// "ready" means that the instruction has valid operands but has not gone yet
4209
reg [1:0] issue_count, missue_count;
4210
always @*
4211
begin
4212
        issue_count = 0;
4213
         memissue[ head0 ] =    iqentry_memready[ head0 ];              // first in line ... go as soon as ready
4214
         if (memissue[head0])
4215
                issue_count = issue_count + 1;
4216
 
4217
         memissue[ head1 ] =    ~iqentry_stomp[head1] && iqentry_memready[ head1 ]              // addr and data are valid
4218 49 robfinch
                                        && issue_count < `NUM_MEM
4219 48 robfinch
                                        // ... and no preceding instruction is ready to go
4220
                                        //&& ~iqentry_memready[head0]
4221
                                        // ... and there is no address-overlap with any preceding instruction
4222 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4223
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head1][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4224 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4225
                                        && (iqentry_rl[head1] ? iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0] : 1'b1)
4226
                                        // ... if a preivous op has the aquire bit set
4227
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4228
                                        // ... and, if it is a SW, there is no chance of it being undone
4229
                                        && (iqentry_load[head1] ||
4230
                                           !(iqentry_fc[head0]||iqentry_canex[head0]));
4231
         if (memissue[head1])
4232
                issue_count = issue_count + 1;
4233
 
4234
         memissue[ head2 ] =    ~iqentry_stomp[head2] && iqentry_memready[ head2 ]              // addr and data are valid
4235
                                        // ... and no preceding instruction is ready to go
4236 49 robfinch
                                        && issue_count < `NUM_MEM
4237 48 robfinch
                                        //&& ~iqentry_memready[head0]
4238
                                        //&& ~iqentry_memready[head1] 
4239
                                        // ... and there is no address-overlap with any preceding instruction
4240 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4241
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head2][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4242
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4243
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head2][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4244 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4245
                                        && (iqentry_rl[head2] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4246
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4247
                                                                                         : 1'b1)
4248
                                        // ... if a preivous op has the aquire bit set
4249
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4250
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4251
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4252 49 robfinch
            && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4253
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4254 48 robfinch
                                        // ... and, if it is a SW, there is no chance of it being undone
4255
                                        && (iqentry_load[head2] ||
4256
                                              !(iqentry_fc[head0]||iqentry_canex[head0])
4257
                                           && !(iqentry_fc[head1]||iqentry_canex[head1]));
4258
         if (memissue[head2])
4259
                issue_count = issue_count + 1;
4260
 
4261
         memissue[ head3 ] =    ~iqentry_stomp[head3] && iqentry_memready[ head3 ]              // addr and data are valid
4262
                                        // ... and no preceding instruction is ready to go
4263 49 robfinch
                                        && issue_count < `NUM_MEM
4264 48 robfinch
                                        //&& ~iqentry_memready[head0]
4265
                                        //&& ~iqentry_memready[head1] 
4266
                                        //&& ~iqentry_memready[head2] 
4267
                                        // ... and there is no address-overlap with any preceding instruction
4268 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4269
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4270
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4271
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4272
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])  || iqentry_done[head2]
4273
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4274 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4275
                                        && (iqentry_rl[head3] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4276
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4277
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4278
                                                                                         : 1'b1)
4279
                                        // ... if a preivous op has the aquire bit set
4280
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4281
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4282
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4283
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4284 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4285
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4286 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4287
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4288
                                )
4289 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4290
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4291 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4292
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4293
                                )
4294
                    // ... and, if it is a SW, there is no chance of it being undone
4295
                                        && (iqentry_load[head3] ||
4296
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4297
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4298
                       && !(iqentry_fc[head2]||iqentry_canex[head2]));
4299
         if (memissue[head3])
4300
                issue_count = issue_count + 1;
4301
 
4302
         memissue[ head4 ] =    ~iqentry_stomp[head4] && iqentry_memready[ head4 ]              // addr and data are valid
4303
                                        // ... and no preceding instruction is ready to go
4304 49 robfinch
                                        && issue_count < `NUM_MEM
4305 48 robfinch
                                        //&& ~iqentry_memready[head0]
4306
                                        //&& ~iqentry_memready[head1] 
4307
                                        //&& ~iqentry_memready[head2] 
4308
                                        //&& ~iqentry_memready[head3] 
4309
                                        // ... and there is no address-overlap with any preceding instruction
4310 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4311
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4312
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4313
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4314
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])  || iqentry_done[head2]
4315
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4316
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])  || iqentry_done[head3]
4317
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
4318 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4319
                                        && (iqentry_rl[head4] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4320
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4321
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4322
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4323
                                                                                         : 1'b1)
4324
                                        // ... if a preivous op has the aquire bit set
4325
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4326
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4327
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4328
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4329
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4330 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4331
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4332 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4333
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4334
                                )
4335 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4336 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4337
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4338
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4339
                                )
4340
                                && (!(iqentry_v[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4341 49 robfinch
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4342 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4343
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4344
                                )
4345 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
4346 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4347
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4348
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4349
                                )
4350
                                        // ... and, if it is a SW, there is no chance of it being undone
4351
                                        && (iqentry_load[head4] ||
4352
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4353
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4354
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4355
                       && !(iqentry_fc[head3]||iqentry_canex[head3]));
4356
         if (memissue[head4])
4357
                issue_count = issue_count + 1;
4358
 
4359
         memissue[ head5 ] =    ~iqentry_stomp[head5] && iqentry_memready[ head5 ]              // addr and data are valid
4360
                                        // ... and no preceding instruction is ready to go
4361 49 robfinch
                                        && issue_count < `NUM_MEM
4362 48 robfinch
                                        //&& ~iqentry_memready[head0]
4363
                                        //&& ~iqentry_memready[head1] 
4364
                                        //&& ~iqentry_memready[head2] 
4365
                                        //&& ~iqentry_memready[head3] 
4366
                                        //&& ~iqentry_memready[head4] 
4367
                                        // ... and there is no address-overlap with any preceding instruction
4368 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4369
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4370
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
4371
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4372
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
4373
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4374
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
4375
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
4376
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
4377
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head4][AMSB:3] || iqentry_out[head4] || iqentry_done[head4])))
4378 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4379
                                        && (iqentry_rl[head5] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4380
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4381
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4382
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4383
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
4384
                                                                                         : 1'b1)
4385
                                        // ... if a preivous op has the aquire bit set
4386
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4387
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4388
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4389
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4390
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
4391
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4392 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4393
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4394 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4395
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4396
                                )
4397 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4398 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4399
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4400
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4401
                                )
4402 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
4403 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4404
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4405
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4406
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
4407
                                )
4408 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4409
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4410 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4411
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4412
                                )
4413 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
4414 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4415
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4416
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4417
                                )
4418 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
4419 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4420
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4421
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4422
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
4423
                                )
4424
                                        // ... and, if it is a SW, there is no chance of it being undone
4425
                                        && (iqentry_load[head5] ||
4426
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4427
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4428
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4429
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
4430
                       && !(iqentry_fc[head4]||iqentry_canex[head4]));
4431
         if (memissue[head5])
4432
                issue_count = issue_count + 1;
4433
 
4434
`ifdef FULL_ISSUE_LOGIC
4435
         memissue[ head6 ] =    ~iqentry_stomp[head6] && iqentry_memready[ head6 ]              // addr and data are valid
4436
                                        // ... and no preceding instruction is ready to go
4437 49 robfinch
                                        && issue_count < `NUM_MEM
4438 48 robfinch
                                        //&& ~iqentry_memready[head0]
4439
                                        //&& ~iqentry_memready[head1] 
4440
                                        //&& ~iqentry_memready[head2] 
4441
                                        //&& ~iqentry_memready[head3] 
4442
                                        //&& ~iqentry_memready[head4] 
4443
                                        //&& ~iqentry_memready[head5] 
4444
                                        // ... and there is no address-overlap with any preceding instruction
4445 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4446 53 robfinch
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head0][AMSB:3])))
4447 52 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
4448 53 robfinch
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head1][AMSB:3])))
4449 52 robfinch
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
4450 53 robfinch
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head2][AMSB:3])))
4451 52 robfinch
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
4452 53 robfinch
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head3][AMSB:3])))
4453 52 robfinch
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
4454 53 robfinch
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head4][AMSB:3])))
4455 52 robfinch
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5]) || iqentry_done[head5]
4456 53 robfinch
                                                || (iqentry_a1_v[head5] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head5][AMSB:3])))
4457 48 robfinch
                                        && (iqentry_rl[head6] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4458
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4459
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4460
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4461
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
4462
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
4463
                                                                                         : 1'b1)
4464
                                        // ... if a preivous op has the aquire bit set
4465
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4466
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4467
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4468
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4469
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
4470
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
4471
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4472 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4473
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4474 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4475
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4476
                                )
4477 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4478 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4479
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4480
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4481
                                )
4482 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
4483 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4484
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4485
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4486
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
4487
                                )
4488 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
4489 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4490
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4491
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4492
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
4493
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
4494
                                )
4495 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4496
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4497 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4498
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4499
                                )
4500 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
4501 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4502
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4503
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4504
                                )
4505 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
4506 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4507
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4508
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4509
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
4510
                                )
4511 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
4512 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4513
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4514
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4515
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
4516
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
4517
                                )
4518
                                        // ... and, if it is a SW, there is no chance of it being undone
4519
                                        && (iqentry_load[head6] ||
4520
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4521
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4522
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4523
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
4524
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
4525
                       && !(iqentry_fc[head5]||iqentry_canex[head5]));
4526
         if (memissue[head6])
4527
                issue_count = issue_count + 1;
4528
 
4529
         memissue[ head7 ] =    ~iqentry_stomp[head7] && iqentry_memready[ head7 ]              // addr and data are valid
4530
                                        // ... and no preceding instruction is ready to go
4531 49 robfinch
                                        && issue_count < `NUM_MEM
4532 48 robfinch
                                        //&& ~iqentry_memready[head0]
4533
                                        //&& ~iqentry_memready[head1] 
4534
                                        //&& ~iqentry_memready[head2] 
4535
                                        //&& ~iqentry_memready[head3] 
4536
                                        //&& ~iqentry_memready[head4] 
4537
                                        //&& ~iqentry_memready[head5] 
4538
                                        //&& ~iqentry_memready[head6] 
4539
                                        // ... and there is no address-overlap with any preceding instruction
4540 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4541
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4542
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
4543
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4544
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
4545
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4546
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
4547
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
4548
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
4549
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head4][AMSB:3] || iqentry_out[head4] || iqentry_done[head4])))
4550
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5]) || iqentry_done[head5]
4551
                                                || (iqentry_a1_v[head5] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head5][AMSB:3] || iqentry_out[head5] || iqentry_done[head5])))
4552
                                        && (!iqentry_mem[head6] || (iqentry_agen[head6] & iqentry_out[head6]) || iqentry_done[head6]
4553
                                                || (iqentry_a1_v[head6] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head6][AMSB:3] || iqentry_out[head6] || iqentry_done[head6])))
4554 48 robfinch
                                        && (iqentry_rl[head7] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4555
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4556
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4557
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4558
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
4559
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
4560
                                                                                 && (iqentry_done[head6] || !iqentry_v[head6] || !iqentry_mem[head6])
4561
                                                                                         : 1'b1)
4562
                                        // ... if a preivous op has the aquire bit set
4563
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4564
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4565
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4566
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4567
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
4568
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
4569
                                        && !(iqentry_aq[head6] && iqentry_v[head6])
4570
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4571 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4572
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4573 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4574
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4575
                                )
4576 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4577 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4578
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4579
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4580
                                )
4581 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
4582 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4583
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4584
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4585
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
4586
                                )
4587 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
4588 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4589
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4590
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4591
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
4592
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
4593
                                )
4594 49 robfinch
                    && (!(iqentry_iv[head6] && iqentry_memsb[head6]) ||
4595 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4596
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4597
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4598
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
4599
                                &&   (iqentry_done[head4] || !iqentry_v[head4])
4600
                                &&   (iqentry_done[head5] || !iqentry_v[head5]))
4601
                                )
4602 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4603
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4604 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4605
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4606
                                )
4607 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
4608 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4609
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4610
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4611
                                )
4612 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
4613 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4614
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4615
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4616
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
4617
                                )
4618 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
4619 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4620
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4621
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4622
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
4623
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
4624
                                )
4625 49 robfinch
                    && (!(iqentry_iv[head6] && iqentry_memdb[head6]) ||
4626 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4627
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4628
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4629
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
4630
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4])
4631
                                && (!iqentry_mem[head5] || iqentry_done[head5] || !iqentry_v[head5]))
4632
                                )
4633
                                        // ... and, if it is a SW, there is no chance of it being undone
4634
                                        && (iqentry_load[head7] ||
4635
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4636
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4637
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4638
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
4639
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
4640
                       && !(iqentry_fc[head5]||iqentry_canex[head5])
4641
                       && !(iqentry_fc[head6]||iqentry_canex[head6]));
4642
`endif
4643
end
4644
 
4645 49 robfinch
reg [2:0] wbptr;
4646
always @*
4647
begin
4648
        // Crashes sim
4649
//      wbptr <= `WB_DEPTH-1;
4650
//      if (wb_v==8'h0)
4651
//              wbptr <= 3'd0;
4652
//      else
4653
//      begin
4654
//              for (n = `WB_DEPTH-2; n >= 0; n = n - 1)
4655
//                      if (wb_v[n] && wbptr==`WB_DEPTH-1)
4656
//                              wbptr <= n + 1;
4657
//      end
4658
        if (wb_v[6])
4659
                wbptr <= 3'd7;
4660
        else if (wb_v[5])
4661
                wbptr <= 3'd6;
4662
        else if (wb_v[4])
4663
                wbptr <= 3'd5;
4664
        else if (wb_v[3])
4665
                wbptr <= 3'd4;
4666
        else if (wb_v[2])
4667
                wbptr <= 3'd3;
4668
        else if (wb_v[1])
4669
                wbptr <= 3'd2;
4670
        else if (wb_v[0])
4671
                wbptr <= 3'd1;
4672
        else
4673
                wbptr <= 3'd0;
4674
end
4675
 
4676 48 robfinch
// Stomp logic for branch miss.
4677
 
4678
FT64_stomp #(QENTRIES) ustmp1
4679
(
4680
        .branchmiss(branchmiss),
4681
        .branchmiss_thrd(branchmiss_thrd),
4682
        .missid(missid),
4683
        .head0(head0),
4684
        .thrd(iqentry_thrd),
4685
        .iqentry_v(iqentry_v),
4686
        .stomp(iqentry_stomp)
4687
);
4688
 
4689
always @*
4690
begin
4691 51 robfinch
        if (iqentry_stomp[0] && iqentry_ret[0])
4692 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
4693 51 robfinch
        if (iqentry_stomp[1] && iqentry_ret[1])
4694 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
4695 51 robfinch
        if (iqentry_stomp[2] && iqentry_ret[2])
4696 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
4697 51 robfinch
        if (iqentry_stomp[3] && iqentry_ret[3])
4698 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
4699 51 robfinch
        if (iqentry_stomp[4] && iqentry_ret[4])
4700 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
4701 51 robfinch
        if (iqentry_stomp[5] && iqentry_ret[5])
4702 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
4703 51 robfinch
        if (iqentry_stomp[6] && iqentry_ret[6])
4704 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
4705 51 robfinch
        if (iqentry_stomp[7] && iqentry_ret[7])
4706 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
4707 52 robfinch
        if (iqentry_stomp[8] && iqentry_ret[8])
4708
                stompedOnRets = stompedOnRets + 4'd1;
4709
        if (iqentry_stomp[9] && iqentry_ret[9])
4710
                stompedOnRets = stompedOnRets + 4'd1;
4711 48 robfinch
end
4712
 
4713 49 robfinch
reg id1_vi, id2_vi, id3_vi;
4714
wire [4:0] id1_ido, id2_ido, id3_ido;
4715
wire id1_vo, id2_vo, id3_vo;
4716
wire id1_clk, id2_clk, id3_clk;
4717 48 robfinch
 
4718 49 robfinch
// Always at least one decoder
4719 50 robfinch
assign id1_clk = clk_i;
4720
//BUFGCE uclkb2
4721
//(
4722
//      .I(clk_i),
4723
//      .CE(id1_available),
4724
//      .O(id1_clk)
4725
//);
4726 48 robfinch
 
4727
FT64_idecoder uid1
4728
(
4729
        .clk(id1_clk),
4730
        .idv_i(id1_vi),
4731
        .id_i(id1_id),
4732
        .instr(id1_instr),
4733
        .ven(id1_ven),
4734
        .vl(id1_vl),
4735
        .thrd(id1_thrd),
4736
        .predict_taken(id1_pt),
4737
        .Rt(id1_Rt),
4738
        .bus(id1_bus),
4739
        .id_o(id1_ido),
4740
        .idv_o(id1_vo)
4741
);
4742
 
4743 49 robfinch
generate begin : gIDUInst
4744
if (`NUM_IDU > 1) begin
4745 50 robfinch
//BUFGCE uclkb3
4746
//(
4747
//      .I(clk_i),
4748
//      .CE(id2_available),
4749
//      .O(id2_clk)
4750
//);
4751
assign id2_clk = clk_i;
4752 48 robfinch
 
4753
FT64_idecoder uid2
4754
(
4755
        .clk(id2_clk),
4756
        .idv_i(id2_vi),
4757
        .id_i(id2_id),
4758
        .instr(id2_instr),
4759
        .ven(id2_ven),
4760
        .vl(id2_vl),
4761
        .thrd(id2_thrd),
4762
        .predict_taken(id2_pt),
4763
        .Rt(id2_Rt),
4764
        .bus(id2_bus),
4765
        .id_o(id2_ido),
4766
        .idv_o(id2_vo)
4767
);
4768 49 robfinch
end
4769
if (`NUM_IDU > 2) begin
4770 50 robfinch
//BUFGCE uclkb4
4771
//(
4772
//      .I(clk_i),
4773
//      .CE(id3_available),
4774
//      .O(id3_clk)
4775
//);
4776
assign id3_clk = clk_i;
4777 48 robfinch
 
4778 49 robfinch
FT64_idecoder uid2
4779
(
4780
        .clk(id3_clk),
4781
        .idv_i(id3_vi),
4782
        .id_i(id3_id),
4783
        .instr(id3_instr),
4784
        .ven(id3_ven),
4785
        .vl(id3_vl),
4786
        .thrd(id3_thrd),
4787
        .predict_taken(id3_pt),
4788
        .Rt(id3_Rt),
4789
        .bus(id3_bus),
4790
        .id_o(id3_ido),
4791
        .idv_o(id3_vo)
4792
);
4793
end
4794
end
4795
endgenerate
4796
 
4797 48 robfinch
//
4798
// EXECUTE
4799
//
4800
reg [63:0] csr_r;
4801
always @*
4802
    read_csr(alu0_instr[29:18],csr_r,alu0_thrd);
4803
FT64_alu #(.BIG(1'b1),.SUP_VECTOR(SUP_VECTOR)) ualu0 (
4804
  .rst(rst),
4805
  .clk(clk),
4806
  .ld(alu0_ld),
4807
  .abort(1'b0),
4808
  .instr(alu0_instr),
4809
  .a(alu0_argA),
4810
  .b(alu0_argB),
4811
  .c(alu0_argC),
4812
  .pc(alu0_pc),
4813
//    .imm(alu0_argI),
4814
  .tgt(alu0_tgt),
4815
  .ven(alu0_ven),
4816
  .vm(vm[alu0_instr[25:23]]),
4817
  .sbl(sbl),
4818
  .sbu(sbu),
4819
  .csr(csr_r),
4820
  .o(alu0_bus),
4821
  .ob(alu0b_bus),
4822
  .done(alu0_done),
4823
  .idle(alu0_idle),
4824
  .excen(aec[4:0]),
4825
  .exc(alu0_exc),
4826
  .thrd(alu0_thrd),
4827
  .mem(alu0_mem),
4828
  .shift48(alu0_shft48)
4829
);
4830 49 robfinch
generate begin : gAluInst
4831
if (`NUM_ALU > 1) begin
4832 48 robfinch
FT64_alu #(.BIG(1'b0),.SUP_VECTOR(SUP_VECTOR)) ualu1 (
4833
  .rst(rst),
4834
  .clk(clk),
4835
  .ld(alu1_ld),
4836
  .abort(1'b0),
4837
  .instr(alu1_instr),
4838
  .a(alu1_argA),
4839
  .b(alu1_argB),
4840
  .c(alu1_argC),
4841
  .pc(alu1_pc),
4842
  //.imm(alu1_argI),
4843
  .tgt(alu1_tgt),
4844
  .ven(alu1_ven),
4845
  .vm(vm[alu1_instr[25:23]]),
4846
  .sbl(sbl),
4847
  .sbu(sbu),
4848
  .csr(64'd0),
4849
  .o(alu1_bus),
4850
  .ob(alu1b_bus),
4851
  .done(alu1_done),
4852
  .idle(alu1_idle),
4853
  .excen(aec[4:0]),
4854
  .exc(alu1_exc),
4855
  .thrd(1'b0),
4856
  .mem(alu1_mem),
4857
  .shift48(alu1_shft48)
4858
);
4859 49 robfinch
end
4860
end
4861
endgenerate
4862
 
4863
generate begin : gFPUInst
4864
if (`NUM_FPU > 0) begin
4865
wire fpu1_clk;
4866 50 robfinch
//BUFGCE ufpc1
4867
//(
4868
//      .I(clk_i),
4869
//      .CE(fpu1_available),
4870
//      .O(fpu1_clk)
4871
//);
4872
assign fpu1_clk = clk_i;
4873
 
4874 48 robfinch
fpUnit ufp1
4875
(
4876
  .rst(rst),
4877 49 robfinch
  .clk(fpu1_clk),
4878 48 robfinch
  .clk4x(clk4x),
4879
  .ce(1'b1),
4880 49 robfinch
  .ir(fpu1_instr),
4881
  .ld(fpu1_ld),
4882
  .a(fpu1_argA),
4883
  .b(fpu1_argB),
4884
  .imm(fpu1_argI),
4885
  .o(fpu1_bus),
4886 48 robfinch
  .csr_i(),
4887 52 robfinch
  .status(fpu1_status),
4888 48 robfinch
  .exception(),
4889 49 robfinch
  .done(fpu1_done)
4890 48 robfinch
);
4891 49 robfinch
end
4892
if (`NUM_FPU > 1) begin
4893
wire fpu2_clk;
4894 50 robfinch
//BUFGCE ufpc2
4895
//(
4896
//      .I(clk_i),
4897
//      .CE(fpu2_available),
4898
//      .O(fpu2_clk)
4899
//);
4900
assign fpu2_clk = clk_i;
4901 49 robfinch
fpUnit ufp1
4902
(
4903
  .rst(rst),
4904
  .clk(fpu2_clk),
4905
  .clk4x(clk4x),
4906
  .ce(1'b1),
4907
  .ir(fpu2_instr),
4908
  .ld(fpu2_ld),
4909
  .a(fpu2_argA),
4910
  .b(fpu2_argB),
4911
  .imm(fpu2_argI),
4912
  .o(fpu2_bus),
4913
  .csr_i(),
4914 52 robfinch
  .status(fpu2_status),
4915 49 robfinch
  .exception(),
4916
  .done(fpu2_done)
4917
);
4918
end
4919
end
4920
endgenerate
4921 48 robfinch
 
4922 52 robfinch
assign fpu1_exc = (fpu1_available) ?
4923
                                                                        ((|fpu1_status[15:0]) ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
4924
assign fpu2_exc = (fpu2_available) ?
4925
                                                                        ((|fpu2_status[15:0]) ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
4926 49 robfinch
 
4927 48 robfinch
assign  alu0_v = alu0_dataready,
4928
        alu1_v = alu1_dataready;
4929
assign  alu0_id = alu0_sourceid,
4930
            alu1_id = alu1_sourceid;
4931 49 robfinch
assign  fpu1_v = fpu1_dataready;
4932
assign  fpu1_id = fpu1_sourceid;
4933
assign  fpu2_v = fpu2_dataready;
4934
assign  fpu2_id = fpu2_sourceid;
4935 48 robfinch
 
4936
`ifdef SUPPORT_SMT
4937
wire [1:0] olm = ol[fcu_thrd];
4938
`else
4939
wire [1:0] olm = ol;
4940
`endif
4941
 
4942
assign  fcu_v = fcu_dataready;
4943
assign  fcu_id = fcu_sourceid;
4944
 
4945
wire [4:0] fcmpo;
4946
wire fnanx;
4947
fp_cmp_unit ufcmp1 (fcu_argA, fcu_argB, fcmpo, fnanx);
4948
 
4949
wire fcu_takb;
4950
 
4951
always @*
4952
begin
4953
    fcu_exc <= `FLT_NONE;
4954
    casez(fcu_instr[`INSTRUCTION_OP])
4955
    `CHK:   begin
4956
                if (fcu_instr[21])
4957
                    fcu_exc <= fcu_argA >= fcu_argB && fcu_argA < fcu_argC ? `FLT_NONE : `FLT_CHK;
4958
            end
4959
    `REX:
4960
        case(olm)
4961
        `OL_USER:   fcu_exc <= `FLT_PRIV;
4962
        default:    ;
4963
        endcase
4964
        endcase
4965
end
4966
 
4967
FT64_EvalBranch ube1
4968
(
4969
        .instr(fcu_instr),
4970
        .a(fcu_argA),
4971
        .b(fcu_argB),
4972
        .c(fcu_argC),
4973
        .takb(fcu_takb)
4974
);
4975
 
4976
FT64_FCU_Calc ufcuc1
4977
(
4978
        .ol(olm),
4979
        .instr(fcu_instr),
4980
        .tvec(tvec[fcu_instr[14:13]]),
4981
        .a(fcu_argA),
4982
        .i(fcu_argI),
4983
        .pc(fcu_pc),
4984
        .im(im),
4985
        .waitctr(waitctr),
4986
        .bus(fcu_bus)
4987
);
4988
 
4989
always @*
4990
begin
4991
case(fcu_instr[`INSTRUCTION_OP])
4992
`R2:    fcu_misspc = fcu_argB;  // RTI (we don't bother fully decoding this as it's the only R2)
4993
`RET:   fcu_misspc = fcu_argB;
4994
`REX:   fcu_misspc = fcu_bus;
4995
`BRK:   fcu_misspc = {tvec[0][31:8], 1'b0, olm, 5'h0};
4996
`JAL:   fcu_misspc = fcu_argA + fcu_argI;
4997
//`CHK: fcu_misspc = fcu_nextpc + fcu_argI;     // Handled as an instruction exception
4998
// Default: branch
4999
default:        fcu_misspc = fcu_takb ? fcu_nextpc + fcu_brdisp : fcu_nextpc;
5000
endcase
5001
fcu_misspc[0] = 1'b0;
5002
end
5003
 
5004
// To avoid false branch mispredicts the branch isn't evaluated until the
5005
// following instruction queues. The address of the next instruction is
5006
// looked at to see if the BTB predicted correctly.
5007
 
5008 51 robfinch
wire fcu_brk_miss = (fcu_brk || fcu_rti) && fcu_v;
5009
wire fcu_ret_miss = fcu_ret && fcu_v && (fcu_argB != iqentry_pc[nid]);
5010
wire fcu_jal_miss = fcu_jal && fcu_v && fcu_argA + fcu_argI != iqentry_pc[nid];
5011 48 robfinch
wire fcu_followed = iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]];
5012
always @*
5013
if (fcu_dataready) begin
5014
//      if (fcu_timeout[7])
5015
//              fcu_branchmiss = TRUE;
5016
        // Break and RTI switch register sets, and so are always treated as a branch miss in order to
5017
        // flush the pipeline. Hardware interrupts also stream break instructions so they need to 
5018
        // flushed from the queue so the interrupt is recognized only once.
5019
        // BRK and RTI are handled as excmiss types which are processed during the commit stage.
5020
//      else
5021
        if (fcu_brk_miss)
5022
                fcu_branchmiss = TRUE & ~fcu_clearbm;
5023
    // the following instruction is queued
5024
        else
5025
        if (fcu_followed) begin
5026
`ifdef SUPPORT_SMT
5027
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol[fcu_thrd]) && fcu_v)
5028
`else
5029
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol) && fcu_v)
5030
`endif
5031
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5032
                else if (fcu_ret_miss)
5033
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5034 52 robfinch
                else if (fcu_branch && fcu_v && (((fcu_takb && (fcu_misspc != iqentry_pc[nid])) ||
5035
                                            (~fcu_takb && (fcu_pc + fcu_insln != iqentry_pc[nid])))))// || iqentry_v[nid]))
5036 48 robfinch
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5037
                else if (fcu_jal_miss)
5038
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5039
                else if (fcu_instr[`INSTRUCTION_OP] == `CHK && ~fcu_takb && fcu_v)
5040
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5041
                else
5042
                    fcu_branchmiss = FALSE;
5043
        end
5044
        else begin
5045
                // Stuck at the head and can't finish because there's still an uncommitted instruction in the queue.
5046
                // -> cause a branch miss to clear the queue.
5047
                if (iqentry_v[nid] && !IsCall(fcu_instr) && !IsJmp(fcu_instr) && fcu_v)
5048
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5049
                else
5050
                /*
5051
                if (fcu_id==head0 && iqentry_v[idp1(head0)]) begin
5052
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
5053
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
5054
                        fcu_branchmiss = FALSE;
5055
                    else
5056
                                fcu_branchmiss = TRUE;
5057
                end
5058
                else if (fcu_id==head1 && iqentry_v[idp2(head1)]) begin
5059
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
5060
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
5061
                        fcu_branchmiss = FALSE;
5062
                    else
5063
                                fcu_branchmiss = TRUE;
5064
                end
5065
                else*/
5066
                        fcu_branchmiss = FALSE;
5067
        end
5068
end
5069
else
5070
        fcu_branchmiss = FALSE;
5071
 
5072
// Flow control ops don't issue until the next instruction queues.
5073
// The fcu_timeout tracks how long the flow control op has been in the "out" state.
5074
// It should never be that way more than a couple of cycles. Sometimes the fcu_wr pulse got missed
5075
// because the following instruction got stomped on during a branchmiss, hence iqentry_v isn't true.
5076
wire fcu_wr = (fcu_v && iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]]);//      // && iqentry_v[nid]
5077
//                                      && fcu_instr==iqentry_instr[fcu_id[`QBITS]]);// || fcu_timeout==8'h05;
5078
 
5079
FT64_RMW_alu urmwalu0 (rmw_instr, rmw_argA, rmw_argB, rmw_argC, rmw_res);
5080
 
5081
//assign fcu_done = IsWait(fcu_instr) ? ((waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]]) :
5082
//                                      fcu_v && iqentry_v[idp1(fcu_id)] && iqentry_sn[idp1(fcu_id)]==iqentry_sn[fcu_id[`QBITS]]+5'd1;
5083
 
5084
// An exception in a committing instruction takes precedence
5085
/*
5086
Too slow. Needs to be registered
5087
assign  branchmiss = excmiss|fcu_branchmiss,
5088
    misspc = excmiss ? excmisspc : fcu_misspc,
5089
    missid = excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
5090
assign branchmiss_thrd =  excmiss ? excthrd : fcu_thrd;
5091
*/
5092
 
5093
//
5094
// additional DRAM-enqueue logic
5095
 
5096
assign dram_avail = (dram0 == `DRAMSLOT_AVAIL || dram1 == `DRAMSLOT_AVAIL || dram2 == `DRAMSLOT_AVAIL);
5097
 
5098 53 robfinch
always @*
5099
for (n = 0; n < QENTRIES; n = n + 1)
5100
        iqentry_memopsvalid[n] <= (iqentry_mem[n] & iqentry_a2_v[n] & iqentry_agen[n]);
5101 48 robfinch
 
5102 53 robfinch
always @*
5103
for (n = 0; n < QENTRIES; n = n + 1)
5104
        iqentry_memready[n] <= (iqentry_v[n] & iqentry_memopsvalid[n] & ~iqentry_memissue[n] & ~iqentry_done[n] & ~iqentry_out[n] & ~iqentry_stomp[n]);
5105 48 robfinch
 
5106 50 robfinch
assign outstanding_stores = (dram0 && dram0_store) ||
5107
                            (dram1 && dram1_store) ||
5108
                            (dram2 && dram2_store);
5109 48 robfinch
 
5110
//
5111
// additional COMMIT logic
5112
//
5113
always @*
5114
begin
5115
    commit0_v <= ({iqentry_v[head0], iqentry_cmt[head0]} == 2'b11 && ~|panic);
5116
    commit0_id <= {iqentry_mem[head0], head0};  // if a memory op, it has a DRAM-bus id
5117
    commit0_tgt <= iqentry_tgt[head0];
5118
    commit0_we  <= iqentry_we[head0];
5119
    commit0_bus <= iqentry_res[head0];
5120 49 robfinch
    if (`NUM_CMT > 1) begin
5121
            commit1_v <= ({iqentry_v[head0], iqentry_cmt[head0]} != 2'b10
5122
                       && {iqentry_v[head1], iqentry_cmt[head1]} == 2'b11
5123
                       && ~|panic);
5124
            commit1_id <= {iqentry_mem[head1], head1};
5125
            commit1_tgt <= iqentry_tgt[head1];
5126
            commit1_we  <= iqentry_we[head1];
5127
            commit1_bus <= iqentry_res[head1];
5128
        end
5129
        else begin
5130
                commit1_tgt <= 12'h000;
5131
                commit1_we <= 8'h00;
5132
        end
5133 48 robfinch
end
5134
 
5135 51 robfinch
assign int_commit = (commit0_v && iqentry_irq[head0]) ||
5136
                    (commit0_v && commit1_v && iqentry_irq[head1] && `NUM_CMT > 1);
5137 48 robfinch
 
5138
// Detect if a given register will become valid during the current cycle.
5139
// We want a signal that is active during the current clock cycle for the read
5140
// through register file, which trims a cycle off register access for every
5141
// instruction. But two different kinds of assignment statements can't be
5142
// placed under the same always block, it's a bad practice and may not work.
5143
// So a signal is created here with it's own always block.
5144
reg [AREGS-1:0] regIsValid;
5145
always @*
5146
begin
5147
        for (n = 1; n < AREGS; n = n + 1)
5148
        begin
5149
                regIsValid[n] = rf_v[n];
5150
                if (branchmiss)
5151
               if (~livetarget[n]) begin
5152
                        if (branchmiss_thrd) begin
5153
                                if (n >= 128)
5154
                                        regIsValid[n] = `VAL;
5155
                        end
5156
                        else begin
5157
                                if (n < 128)
5158
                                        regIsValid[n] = `VAL;
5159
                        end
5160
               end
5161
                if (commit0_v && n=={commit0_tgt[7:0]})
5162
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit0_tgt[7:0]} ] == commit0_id
5163
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit0_id[`QBITS] ]));
5164 49 robfinch
                if (commit1_v && n=={commit1_tgt[7:0]} && `NUM_CMT > 1)
5165 48 robfinch
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit1_tgt[7:0]} ] == commit1_id
5166
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit1_id[`QBITS] ]));
5167
        end
5168
        regIsValid[0] = `VAL;
5169 55 robfinch
        regIsValid[32] = `VAL;
5170
        regIsValid[64] = `VAL;
5171
        regIsValid[128] = `VAL;
5172
`ifdef SMT
5173
        regIsValid[144] = `VAL;
5174
        regIsValid[160] = `VAL;
5175
        regIsValid[192] = `VAL;
5176
        regIsValid[224] = `VAL;
5177
`endif
5178 48 robfinch
end
5179
 
5180
// Wait until the cycle after Ra becomes valid to give time to read
5181
// the vector element from the register file.
5182
reg rf_vra0, rf_vra1;
5183
/*always @(posedge clk)
5184
    rf_vra0 <= regIsValid[Ra0s];
5185
always @(posedge clk)
5186
    rf_vra1 <= regIsValid[Ra1s];
5187
*/
5188
// Check how many instructions can be queued. This might be fewer than the
5189
// number ready to queue from the fetch stage if queue slots aren't
5190
// available or if there are no more physical registers left for remapping.
5191
// The fetch stage needs to know how many instructions will queue so this
5192
// logic is placed here.
5193
// NOPs are filtered out and do not enter the instruction queue. The core
5194
// will stream NOPs on a cache miss and they would mess up the queue order
5195
// if there are immediate prefixes in the queue.
5196
// For the VEX instruction, the instruction can't queue until register Ra
5197
// is valid, because register Ra is used to specify the vector element to
5198
// read.
5199
wire q2open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV;
5200
wire q3open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV && iqentry_v[idp1(tail1)]==`INV;
5201
always @*
5202
begin
5203
        canq1 <= FALSE;
5204
        canq2 <= FALSE;
5205
        queued1 <= FALSE;
5206
        queued2 <= FALSE;
5207
        queuedNop <= FALSE;
5208
        vqueued2 <= FALSE;
5209
        if (!branchmiss) begin
5210
      // Two available
5211
      if (fetchbuf1_v & fetchbuf0_v) begin
5212
          // Is there a pair of NOPs ? (cache miss)
5213
          if ((fetchbuf0_instr[`INSTRUCTION_OP]==`NOP) && (fetchbuf1_instr[`INSTRUCTION_OP]==`NOP))
5214
              queuedNop <= TRUE;
5215
          else begin
5216
              // If it's a predicted branch queue only the first instruction, the second
5217
              // instruction will be stomped on.
5218
              if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
5219
                  if (iqentry_v[tail0]==`INV) begin
5220
                      canq1 <= TRUE;
5221
                      queued1 <= TRUE;
5222
                  end
5223
              end
5224
              // This is where a single NOP is allowed through to simplify the code. A
5225
              // single NOP can't be a cache miss. Otherwise it would be necessary to queue
5226
              // fetchbuf1 on tail0 it would add a nightmare to the enqueue code.
5227
              // Not a branch and there are two instructions fetched, see whether or not
5228
              // both instructions can be queued.
5229
              else begin
5230
                  if (iqentry_v[tail0]==`INV) begin
5231
                      canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5232
                      queued1 <= (
5233
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5234
                      if (iqentry_v[tail1]==`INV) begin
5235
                          canq2 <= ((!IsVex(fetchbuf1_instr) || rf_vra1)) || !SUP_VECTOR;
5236
                          queued2 <= (
5237
                                (!IsVector(fetchbuf1_instr) && (!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5238
                          vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5239
                      end
5240
                  end
5241
                  // If an irq is active during a vector instruction fetch, claim the vector instruction
5242
                  // is finished queueing even though it may not be. It'll pick up where it left off after
5243
                  // the exception is processed.
5244 52 robfinch
                  if (freezePC) begin
5245 48 robfinch
                        if (IsVector(fetchbuf0_instr) && IsVector(fetchbuf1_instr) && vechain) begin
5246
                                queued1 <= TRUE;
5247
                                queued2 <= TRUE;
5248
                        end
5249
                        else if (IsVector(fetchbuf0_instr)) begin
5250
                                queued1 <= TRUE;
5251
                                if (vqe0 < vl-2)
5252
                                        queued2 <= TRUE;
5253
                                else
5254
                                        queued2 <= iqentry_v[tail1]==`INV;
5255
                        end
5256
                  end
5257
              end
5258
          end
5259
      end
5260
      // One available
5261
      else if (fetchbuf0_v) begin
5262
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
5263
              if (iqentry_v[tail0]==`INV) begin
5264
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5265
                  queued1 <=
5266
                        (((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5267
              end
5268
              if (iqentry_v[tail1]==`INV) begin
5269
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
5270
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5271
                end
5272 52 robfinch
                if (freezePC) begin
5273 48 robfinch
                if (IsVector(fetchbuf0_instr)) begin
5274
                        queued1 <= TRUE;
5275
                        if (vqe0 < vl-2)
5276
                                queued2 <= iqentry_v[tail1]==`INV;
5277
                end
5278
                end
5279
          end
5280
          else
5281
              queuedNop <= TRUE;
5282
      end
5283
      else if (fetchbuf1_v) begin
5284
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
5285
              if (iqentry_v[tail0]==`INV) begin
5286
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
5287
                  queued1 <= (
5288
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
5289
              end
5290
              if (iqentry_v[tail1]==`INV) begin
5291
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
5292
                  vqueued2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2;
5293
                end
5294 52 robfinch
                if (freezePC) begin
5295 48 robfinch
                if (IsVector(fetchbuf1_instr)) begin
5296
                        queued1 <= TRUE;
5297
                        if (vqe1 < vl-2)
5298
                                queued2 <= iqentry_v[tail1]==`INV;
5299
                end
5300
                end
5301
          end
5302
          else
5303
              queuedNop <= TRUE;
5304
      end
5305
      //else no instructions available to queue
5306
    end
5307
    else begin
5308
      // One available
5309
      if (fetchbuf0_v && fetchbuf0_thrd != branchmiss_thrd) begin
5310
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
5311
              if (iqentry_v[tail0]==`INV) begin
5312
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5313
                  queued1 <= (
5314
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5315
              end
5316
              if (iqentry_v[tail1]==`INV) begin
5317
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
5318
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5319
                end
5320
          end
5321
          else
5322
              queuedNop <= TRUE;
5323
      end
5324
      else if (fetchbuf1_v && fetchbuf1_thrd != branchmiss_thrd) begin
5325
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
5326
              if (iqentry_v[tail0]==`INV) begin
5327
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
5328
                  queued1 <= (
5329
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
5330
              end
5331
              if (iqentry_v[tail1]==`INV) begin
5332
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
5333
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5334
                end
5335
          end
5336
          else
5337
              queuedNop <= TRUE;
5338
      end
5339
        else
5340
                queuedNop <= TRUE;
5341
    end
5342
end
5343
 
5344
//
5345
// Branchmiss seems to be sticky sometimes during simulation. For instance branch miss
5346
// and cache miss at same time. The branchmiss should clear before the core continues
5347
// so the positive edge is detected to avoid incrementing the sequnce number too many
5348
// times.
5349
wire pebm;
5350
edge_det uedbm (.rst(rst), .clk(clk), .ce(1'b1), .i(branchmiss), .pe(pebm), .ne(), .ee() );
5351
 
5352
reg [5:0] ld_time;
5353
reg [63:0] wc_time_dat;
5354
reg [63:0] wc_times;
5355
always @(posedge tm_clk_i)
5356
begin
5357
        if (|ld_time)
5358
                wc_time <= wc_time_dat;
5359
        else begin
5360
                wc_time[31:0] <= wc_time[31:0] + 32'd1;
5361
                if (wc_time[31:0] >= TM_CLKFREQ-1) begin
5362
                        wc_time[31:0] <= 32'd0;
5363
                        wc_time[63:32] <= wc_time[63:32] + 32'd1;
5364
                end
5365
        end
5366
end
5367
 
5368
 
5369
// Monster clock domain.
5370
// Like to move some of this to clocking under different always blocks in order
5371
// to help out the toolset's synthesis, but it ain't gonna be easy.
5372
// Simulation doesn't like it if things are under separate always blocks.
5373
// Synthesis doesn't like it if things are under the same always block.
5374
 
5375 49 robfinch
//always @(posedge clk)
5376
//begin
5377
//      branchmiss <= excmiss|fcu_branchmiss;
5378
//    misspc <= excmiss ? excmisspc : fcu_misspc;
5379
//    missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
5380
//      branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
5381
//end
5382 48 robfinch
 
5383
always @(posedge clk)
5384
if (rst) begin
5385
`ifdef SUPPORT_SMT
5386 55 robfinch
     mstatus[0] <= 64'h000F;     // select register set #0 for thread 0
5387
     mstatus[1] <= 64'h800F;    // select register set #2 for thread 1
5388 48 robfinch
`else
5389 55 robfinch
     mstatus <= 64'h000F;       // select register set #0 for thread 0
5390 48 robfinch
`endif
5391
    for (n = 0; n < QENTRIES; n = n + 1) begin
5392 51 robfinch
       iqentry_v[n] <= `INV;
5393
       iqentry_iv[n] <= `INV;
5394
       iqentry_is[n] <= 3'b00;
5395
       iqentry_done[n] <= FALSE;
5396
       iqentry_cmt[n] <= FALSE;
5397
       iqentry_out[n] <= FALSE;
5398
       iqentry_agen[n] <= FALSE;
5399
       iqentry_sn[n] <= 32'd0;
5400
       iqentry_pt[n] <= FALSE;
5401
       iqentry_bt[n] <= FALSE;
5402
       iqentry_br[n] <= FALSE;
5403
       iqentry_aq[n] <= FALSE;
5404
       iqentry_rl[n] <= FALSE;
5405
       iqentry_alu0[n] <= FALSE;
5406
       iqentry_alu[n] <= FALSE;
5407
       iqentry_alu0_issue[n] <= FALSE;
5408
       iqentry_alu1_issue[n] <= FALSE;
5409
       iqentry_fpu[n] <= FALSE;
5410
       iqentry_fpu1_issue[n] <= FALSE;
5411
       iqentry_fpu2_issue[n] <= FALSE;
5412
       iqentry_fsync[n] <= FALSE;
5413
       iqentry_fc[n] <= FALSE;
5414
       iqentry_fcu_issue[n] <= FALSE;
5415 52 robfinch
       iqentry_takb[n] <= FALSE;
5416 51 robfinch
       iqentry_jmp[n] <= FALSE;
5417
       iqentry_jal[n] <= FALSE;
5418
       iqentry_ret[n] <= FALSE;
5419
       iqentry_brk[n] <= FALSE;
5420
       iqentry_irq[n] <= FALSE;
5421
       iqentry_rti[n] <= FALSE;
5422
       iqentry_ldcmp[n] <= FALSE;
5423
       iqentry_load[n] <= FALSE;
5424
       iqentry_rtop[n] <= FALSE;
5425
       iqentry_sei[n] <= FALSE;
5426
       iqentry_shft48[n] <= FALSE;
5427
       iqentry_sync[n] <= FALSE;
5428
       iqentry_ven[n] <= 6'd0;
5429
       iqentry_vl[n] <= 8'd0;
5430
       iqentry_we[n] <= 8'h00;
5431
       iqentry_rfw[n] <= FALSE;
5432
       iqentry_rmw[n] <= FALSE;
5433
       iqentry_pc[n] <= RSTPC;
5434 48 robfinch
         iqentry_instr[n] <= `NOP_INSN;
5435 56 robfinch
         iqentry_insln[n] <= 3'd4;
5436 48 robfinch
         iqentry_preload[n] <= FALSE;
5437
         iqentry_mem[n] <= FALSE;
5438
         iqentry_memndx[n] <= FALSE;
5439 51 robfinch
       iqentry_memissue[n] <= FALSE;
5440
       iqentry_mem_islot[n] <= 3'd0;
5441
       iqentry_memdb[n] <= FALSE;
5442
       iqentry_memsb[n] <= FALSE;
5443
       iqentry_tgt[n] <= 6'd0;
5444
       iqentry_imm[n] <= 1'b0;
5445
       iqentry_a0[n] <= 64'd0;
5446
       iqentry_a1[n] <= 64'd0;
5447
       iqentry_a2[n] <= 64'd0;
5448
       iqentry_a3[n] <= 64'd0;
5449
       iqentry_a1_v[n] <= `INV;
5450
       iqentry_a2_v[n] <= `INV;
5451
       iqentry_a3_v[n] <= `INV;
5452
       iqentry_a1_s[n] <= 5'd0;
5453
       iqentry_a2_s[n] <= 5'd0;
5454
       iqentry_a3_s[n] <= 5'd0;
5455
       iqentry_canex[n] <= FALSE;
5456 48 robfinch
    end
5457 49 robfinch
     bwhich <= 2'b00;
5458 48 robfinch
     dram0 <= `DRAMSLOT_AVAIL;
5459
     dram1 <= `DRAMSLOT_AVAIL;
5460
     dram2 <= `DRAMSLOT_AVAIL;
5461
     dram0_instr <= `NOP_INSN;
5462
     dram1_instr <= `NOP_INSN;
5463
     dram2_instr <= `NOP_INSN;
5464
     dram0_addr <= 32'h0;
5465
     dram1_addr <= 32'h0;
5466
     dram2_addr <= 32'h0;
5467
     L1_adr <= RSTPC;
5468
     invic <= FALSE;
5469
     tail0 <= 3'd0;
5470
     tail1 <= 3'd1;
5471
     head0 <= 0;
5472
     head1 <= 1;
5473
     head2 <= 2;
5474
     head3 <= 3;
5475
     head4 <= 4;
5476
     head5 <= 5;
5477
     head6 <= 6;
5478
     head7 <= 7;
5479 52 robfinch
     head8 <= 8;
5480
     head9 <= 9;
5481 48 robfinch
     panic = `PANIC_NONE;
5482
     alu0_dataready <= 0;
5483
     alu1_dataready <= 0;
5484
     alu0_sourceid <= 5'd0;
5485
     alu1_sourceid <= 5'd0;
5486
`ifdef SIM
5487
                alu0_pc <= RSTPC;
5488
                alu0_instr <= `NOP_INSN;
5489
                alu0_argA <= 64'h0;
5490
                alu0_argB <= 64'h0;
5491
                alu0_argC <= 64'h0;
5492
                alu0_argI <= 64'h0;
5493
                alu0_bt <= 1'b0;
5494
                alu0_mem <= 1'b0;
5495
                alu0_shft48 <= 1'b0;
5496
                alu0_thrd <= 1'b0;
5497
                alu0_tgt <= 6'h00;
5498
                alu0_ven <= 6'd0;
5499
                alu1_pc <= RSTPC;
5500
                alu1_instr <= `NOP_INSN;
5501
                alu1_argA <= 64'h0;
5502
                alu1_argB <= 64'h0;
5503
                alu1_argC <= 64'h0;
5504
                alu1_argI <= 64'h0;
5505
                alu1_bt <= 1'b0;
5506
                alu1_mem <= 1'b0;
5507
                alu1_shft48 <= 1'b0;
5508
                alu1_thrd <= 1'b0;
5509
                alu1_tgt <= 6'h00;
5510
                alu1_ven <= 6'd0;
5511
`endif
5512
     fcu_dataready <= 0;
5513
     fcu_instr <= `NOP_INSN;
5514
     dramA_v <= 0;
5515
     dramB_v <= 0;
5516
     dramC_v <= 0;
5517
     I <= 0;
5518
     icstate <= IDLE;
5519
     bstate <= BIDLE;
5520
     tick <= 64'd0;
5521
     bte_o <= 2'b00;
5522
     cti_o <= 3'b000;
5523
     cyc_o <= `LOW;
5524
     stb_o <= `LOW;
5525
     we_o <= `LOW;
5526
     sel_o <= 8'h00;
5527
     sr_o <= `LOW;
5528
     cr_o <= `LOW;
5529
     adr_o <= RSTPC;
5530
     icl_o <= `LOW;             // instruction cache load
5531
     cr0 <= 64'd0;
5532 55 robfinch
     cr0[13:8] <= 6'd0;         // select compressed instruction group #0
5533 48 robfinch
     cr0[30] <= TRUE;           // enable data caching
5534
     cr0[32] <= TRUE;           // enable branch predictor
5535
     cr0[16] <= 1'b0;           // disable SMT
5536
     cr0[17] <= 1'b0;           // sequence number reset = 1
5537 52 robfinch
     cr0[34] <= FALSE;  // write buffer merging enable
5538 48 robfinch
     pcr <= 32'd0;
5539
     pcr2 <= 64'd0;
5540
    for (n = 0; n < PREGS; n = n + 1)
5541
         rf_v[n] <= `VAL;
5542 51 robfinch
     fp_rm <= 3'd0;                     // round nearest even - default rounding mode
5543
     fpu_csr[37:32] <= 5'd31;   // register set #31
5544 48 robfinch
     waitctr <= 64'd0;
5545
    for (n = 0; n < 16; n = n + 1)
5546
         badaddr[n] <= 64'd0;
5547
     sbl <= 32'h0;
5548
     sbu <= 32'hFFFFFFFF;
5549
    // Vector
5550
     vqe0 <= 6'd0;
5551
     vqet0 <= 6'd0;
5552
     vqe1 <= 6'd0;
5553
     vqet1 <= 6'd0;
5554
     vl <= 7'd62;
5555
    for (n = 0; n < 8; n = n + 1)
5556
         vm[n] <= 64'h7FFFFFFFFFFFFFFF;
5557
     nop_fetchbuf <= 4'h0;
5558
     seq_num <= 5'd0;
5559
     seq_num1 <= 5'd0;
5560
     fcu_done <= `TRUE;
5561
     sema <= 64'h0;
5562
     tvec[0] <= RSTPC;
5563 49 robfinch
     pmr <= 64'hFFFFFFFFFFFFFFFF;
5564
     pmr[0] <= `ID1_AVAIL;
5565
     pmr[1] <= `ID2_AVAIL;
5566
     pmr[2] <= `ID3_AVAIL;
5567
     pmr[8] <= `ALU0_AVAIL;
5568
     pmr[9] <= `ALU1_AVAIL;
5569
     pmr[16] <= `FPU1_AVAIL;
5570
     pmr[17] <= `FPU2_AVAIL;
5571
     pmr[24] <= `MEM1_AVAIL;
5572
     pmr[25] <= `MEM2_AVAIL;
5573
                 pmr[26] <= `MEM3_AVAIL;
5574
     pmr[32] <= `FCU_AVAIL;
5575
     for (n = 0; n < `WB_DEPTH; n = n + 1) begin
5576
        wb_v[n] <= 1'b0;
5577
        wb_rmw[n] <= 1'b0;
5578
        wb_id[n] <= {QENTRIES{1'b0}};
5579
     end
5580
     wb_en <= `TRUE;
5581
     wbo_id <= {QENTRIES{1'b0}};
5582
`ifdef SIM
5583
                wb_merges <= 32'd0;
5584
`endif
5585 48 robfinch
end
5586
else begin
5587 49 robfinch
        if (|fb_panic)
5588
                panic <= fb_panic;
5589
        begin
5590
                branchmiss <= excmiss|fcu_branchmiss;
5591 51 robfinch
                misspc <= excmiss ? excmisspc : fcu_misspc;
5592
                missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
5593 49 robfinch
                branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
5594
        end
5595 48 robfinch
        // The following signals only pulse
5596
 
5597
        // Instruction decode output should only pulse once for a queue entry. We
5598
        // want the decode to be invalidated after a clock cycle so that it isn't
5599
        // inadvertently used to update the queue at a later point.
5600
        id1_vi <= `INV;
5601 49 robfinch
        if (`NUM_IDU > 1)
5602
                id2_vi <= `INV;
5603
        if (`NUM_IDU > 2)
5604
                id3_vi <= `INV;
5605
        if (iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]])
5606
                fcu_dataready <= `INV;
5607 52 robfinch
        wb_shift <= FALSE;
5608 48 robfinch
        ld_time <= {ld_time[4:0],1'b0};
5609
        wc_times <= wc_time;
5610
     rf_vra0 <= regIsValid[Ra0s];
5611
     rf_vra1 <= regIsValid[Ra1s];
5612
    if (vqe0 >= vl) begin
5613
         vqe0 <= 6'd0;
5614
         vqet0 <= 6'h0;
5615
    end
5616
    if (vqe1 >= vl) begin
5617
         vqe1 <= 6'd0;
5618
         vqet1 <= 6'h0;
5619
    end
5620
    // Turn off vector chaining indicator when chained instructions are done.
5621
    if ((vqe0 >= vl || vqe0==6'd0) && (vqe1 >= vl || vqe1==6'd0))
5622
`ifdef SUPPORT_SMT
5623
        mstatus[0][32] <= 1'b0;
5624
`else
5625
        mstatus[32] <= 1'b0;
5626
`endif
5627
 
5628
     nop_fetchbuf <= 4'h0;
5629
     excmiss <= FALSE;
5630
     invic <= FALSE;
5631
     tick <= tick + 64'd1;
5632
     alu0_ld <= FALSE;
5633
     alu1_ld <= FALSE;
5634 49 robfinch
     fpu1_ld <= FALSE;
5635
     fpu2_ld <= FALSE;
5636 48 robfinch
     fcu_ld <= FALSE;
5637
     dramA_v <= FALSE;
5638
     dramB_v <= FALSE;
5639
     dramC_v <= FALSE;
5640
     cr0[17] <= 1'b0;
5641
    if (waitctr != 64'd0)
5642
         waitctr <= waitctr - 64'd1;
5643
 
5644
 
5645 50 robfinch
    if (iqentry_fc[fcu_id[`QBITS]] && iqentry_v[fcu_id[`QBITS]] && !iqentry_done[fcu_id[`QBITS]] && iqentry_out[fcu_id[`QBITS]])
5646 48 robfinch
        fcu_timeout <= fcu_timeout + 8'd1;
5647
 
5648
        if (branchmiss) begin
5649
        for (n = 1; n < PREGS; n = n + 1)
5650
           if (~livetarget[n]) begin
5651
                        if (branchmiss_thrd) begin
5652
                                if (n >= 128)
5653
                                rf_v[n] <= `VAL;
5654
                        end
5655
                        else begin
5656
                                if (n < 128)
5657
                                rf_v[n] <= `VAL;
5658
                end
5659
           end
5660
 
5661 53 robfinch
                        for (n = 0; n < QENTRIES; n = n + 1)
5662
                if (|iqentry_latestID[n])
5663
                        if (iqentry_thrd[n]==branchmiss_thrd) rf_source[ {iqentry_tgt[n][7:0]} ] <= { 1'b0, iqentry_mem[n], n[3:0] };
5664 48 robfinch
 
5665
    end
5666
 
5667
    // The source for the register file data might have changed since it was
5668
    // placed on the commit bus. So it's needed to check that the source is
5669
    // still as expected to validate the register.
5670
        if (commit0_v) begin
5671
        if (!rf_v[ {commit0_tgt[7:0]} ])
5672
//             rf_v[ {commit0_tgt[7:0]} ] <= rf_source[ commit0_tgt[7:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]);
5673
             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] ]);
5674
        if (commit0_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit0_tgt, commit0_bus, regIsValid[commit0_tgt[5:0]],
5675
        rf_source[ {commit0_tgt[7:0]} ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]));
5676
        if (commit0_tgt[5:0]==6'd30 && commit0_bus==64'd0)
5677
                $display("FP <= 0");
5678
    end
5679 49 robfinch
    if (commit1_v && `NUM_CMT > 1) begin
5680 48 robfinch
        if (!rf_v[ {commit1_tgt[7:0]} ]) begin
5681
                if ({commit1_tgt[7:0]}=={commit0_tgt[7:0]})
5682
                         rf_v[ {commit1_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}];
5683
                        /*
5684
                                (rf_source[ commit0_tgt[4:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ])) ||
5685
                                (rf_source[ commit1_tgt[4:0] ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
5686
                        */
5687
                else
5688
                 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] ]);
5689
        end
5690
        if (commit1_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit1_tgt, commit1_bus, regIsValid[commit1_tgt[5:0]],
5691
        rf_source[ {commit1_tgt[7:0]} ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
5692
        if (commit1_tgt[5:0]==6'd30 && commit1_bus==64'd0)
5693
                $display("FP <= 0");
5694
    end
5695
     rf_v[0] <= 1;
5696
 
5697 49 robfinch
  //
5698
  // ENQUEUE
5699
  //
5700
  // place up to two instructions from the fetch buffer into slots in the IQ.
5701
  //   note: they are placed in-order, and they are expected to be executed
5702
  // 0, 1, or 2 of the fetch buffers may have valid data
5703
  // 0, 1, or 2 slots in the instruction queue may be available.
5704
  // if we notice that one of the instructions in the fetch buffer is a predicted branch,
5705
  // (set branchback/backpc and delete any instructions after it in fetchbuf)
5706
  //
5707 48 robfinch
 
5708
        // enqueue fetchbuf0 and fetchbuf1, but only if there is room, 
5709
        // and ignore fetchbuf1 if fetchbuf0 has a backwards branch in it.
5710
        //
5711
        // also, do some instruction-decode ... set the operand_valid bits in the IQ
5712
        // appropriately so that the DATAINCOMING stage does not have to look at the opcode
5713
        //
5714
        if (!branchmiss)        // don't bother doing anything if there's been a branch miss
5715
 
5716
                case ({fetchbuf0_v, fetchbuf1_v})
5717
 
5718
            2'b00: ; // do nothing
5719
 
5720
            2'b01:
5721
                    if (canq1) begin
5722 56 robfinch
          if (fetchbuf1_thrd)
5723
                seq_num1 <= seq_num1 + 5'd1;
5724
          else
5725
                seq_num <= seq_num + 5'd1;
5726
                                        if (fetchbuf1_rfw) begin
5727
                                                rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail0 };  // top bit indicates ALU/MEM bus
5728
                                                rf_v [Rt1s] <= `INV;
5729
                                        end
5730
                                        if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
5731
                                                vqe1 <= vqe1 + 4'd1;
5732
                                                if (IsVCmprss(fetchbuf1_instr)) begin
5733
                                                        if (vm[fetchbuf1_instr[25:23]][vqe1])
5734
                                                                vqet1 <= vqet1 + 4'd1;
5735
                                                end
5736
                                                else
5737
                                                        vqet1 <= vqet1 + 4'd1;
5738
                                                if (vqe1 >= vl-2)
5739
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
5740
                                                enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, vqe1);
5741
                                                if (canq2 && vqe1 < vl-2) begin
5742
                                                        vqe1 <= vqe1 + 4'd2;
5743
                                                        if (IsVCmprss(fetchbuf1_instr)) begin
5744
                                                                if (vm[fetchbuf1_instr[25:23]][vqe1+6'd1])
5745
                                                                        vqet1 <= vqet1 + 4'd2;
5746
                                                        end
5747
                                                        else
5748
                                                                vqet1 <= vqet1 + 4'd2;
5749
                                                        enque1(tail1, fetchbuf1_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe1 + 6'd1);
5750
                                                        // Override the earlier udpate
5751
                                                        if (fetchbuf1_thrd)
5752
                                                                seq_num1 <= seq_num1 + 5'd2;
5753
                                                        else
5754
                                                                seq_num <= seq_num + 5'd2;
5755
                                                end
5756
                                        end
5757
                                        else begin
5758
                                                enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, 6'd0);
5759
                                        end
5760 48 robfinch
                    end
5761
 
5762
            2'b10:
5763
                if (canq1) begin
5764 55 robfinch
                        enque0x();
5765 48 robfinch
                    end
5766
 
5767
            2'b11:
5768
                    if (canq1) begin
5769
                                //
5770
                                // if the first instruction is a predicted branch, enqueue it & stomp on all following instructions
5771
                                // but only if the following instruction is in the same thread. Otherwise we want to queue two.
5772
                                //
5773
                                if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
5774 55 robfinch
                                        enque0x();
5775 48 robfinch
                                end
5776
 
5777
                                else begin      // fetchbuf0 doesn't contain a predicted branch
5778
                                    //
5779
                                    // so -- we can enqueue 1 or 2 instructions, depending on space in the IQ
5780
                                    // update the rf_v and rf_source bits separately (at end)
5781
                                    //   the problem is that if we do have two instructions, 
5782
                                    //   they may interact with each other, so we have to be
5783
                                    //   careful about where things point.
5784
                                    //
5785
                                    // enqueue the first instruction ...
5786
                                    //
5787
                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
5788
                                 vqe0 <= vqe0 + 4'd1;
5789
                                if (IsVCmprss(fetchbuf0_instr)) begin
5790
                                    if (vm[fetchbuf0_instr[25:23]][vqe0])
5791
                                         vqet0 <= vqet0 + 4'd1;
5792
                                end
5793
                                else
5794
                                     vqet0 <= vqet0 + 4'd1;
5795
                                if (vqe0 >= vl-2)
5796
                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
5797
                            end
5798
                            if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
5799
                                    enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
5800
                                        if (fetchbuf0_thrd)
5801
                                                seq_num1 <= seq_num1 + 5'd1;
5802
                                        else
5803
                                                seq_num <= seq_num + 5'd1;
5804
                                            //
5805
                                            // if there is room for a second instruction, enqueue it
5806
                                            //
5807
                                            if (canq2) begin
5808
                                                if (vechain && IsVector(fetchbuf1_instr)
5809
                                                && Ra1s != Rt0s // And there is no dependency
5810
                                                && Rb1s != Rt0s
5811
                                                && Rc1s != Rt0s
5812
                                                ) begin
5813
`ifdef SUPPORT_SMT
5814
                                                        mstatus[0][32] <= 1'b1;
5815
`else
5816
                                                        mstatus[32] <= 1'b1;
5817
`endif
5818
                                                vqe1 <= vqe1 + 4'd1;
5819
                                                if (IsVCmprss(fetchbuf1_instr)) begin
5820
                                                    if (vm[fetchbuf1_instr[25:23]][vqe1])
5821
                                                         vqet1 <= vqet1 + 4'd1;
5822
                                                end
5823
                                                else
5824
                                                     vqet1 <= vqet1 + 4'd1;
5825
                                                if (vqe1 >= vl-2)
5826
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
5827
                                                        enque1(tail1,
5828
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
5829
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
5830
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
5831
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
5832
                                                                if (fetchbuf1_thrd)
5833
                                                                        seq_num1 <= seq_num1 + 5'd2;
5834
                                                                else
5835
                                                                        seq_num <= seq_num + 5'd2;
5836
                                                        end
5837
                                                        else begin
5838
                                                                if (fetchbuf1_thrd)
5839
                                                                        seq_num1 <= seq_num1 + 5'd1;
5840
                                                                else
5841
                                                                        seq_num <= seq_num + 5'd1;
5842
                                                        end
5843
 
5844
                                                                // SOURCE 1 ...
5845 55 robfinch
                                                                a1_vs();
5846 48 robfinch
 
5847
                                                                // SOURCE 2 ...
5848 55 robfinch
                                                                a2_vs();
5849 48 robfinch
 
5850
                                                                // SOURCE 3 ...
5851 55 robfinch
                                                                a3_vs();
5852 48 robfinch
 
5853
                                                                // if the two instructions enqueued target the same register, 
5854
                                                                // make sure only the second writes to rf_v and rf_source.
5855
                                                                // first is allowed to update rf_v and rf_source only if the
5856
                                                                // second has no target
5857
                                                                //
5858
                                                            if (fetchbuf0_rfw) begin
5859
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
5860
                                                                     rf_v [ Rt0s] <= `INV;
5861
                                                            end
5862
                                                            if (fetchbuf1_rfw) begin
5863
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
5864
                                                                     rf_v [ Rt1s ] <= `INV;
5865
                                                            end
5866
                                                end
5867
                                                // If there was a vector instruction in fetchbuf0, we really
5868
                                                // want to queue the next vector element, not the next
5869
                                                // instruction waiting in fetchbuf1.
5870
                                            else if (IsVector(fetchbuf0_instr) && SUP_VECTOR && vqe0 < vl-1) begin
5871
                                                 vqe0 <= vqe0 + 4'd2;
5872
                                                if (IsVCmprss(fetchbuf0_instr)) begin
5873
                                                    if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
5874
                                                         vqet0 <= vqet0 + 4'd2;
5875
                                                end
5876
                                                else
5877
                                                     vqet0 <= vqet0 + 4'd2;
5878
                                                if (vqe0 >= vl-3)
5879
                                                 nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
5880
                                            if (vqe0 < vl-1) begin
5881
                                                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe0 + 6'd1);
5882
                                                                if (fetchbuf0_thrd)
5883
                                                                        seq_num1 <= seq_num1 + 5'd2;
5884
                                                                else
5885
                                                                        seq_num <= seq_num + 5'd2;
5886
 
5887
                                                                        // SOURCE 1 ...
5888
                                                     iqentry_a1_v [tail1] <= regIsValid[Ra0s];
5889
                                                     iqentry_a1_s [tail1] <= rf_source [Ra0s];
5890
 
5891
                                                                        // SOURCE 2 ...
5892
                                                     iqentry_a2_v [tail1] <= regIsValid[Rb0s];
5893
                                                     iqentry_a2_s [tail1] <= rf_source[ Rb0s ];
5894
 
5895
                                                                        // SOURCE 3 ...
5896
                                                     iqentry_a3_v [tail1] <= regIsValid[Rc0s];
5897
                                                     iqentry_a3_s [tail1] <= rf_source[ Rc0s ];
5898
 
5899
                                                                        // if the two instructions enqueued target the same register, 
5900
                                                                        // make sure only the second writes to rf_v and rf_source.
5901
                                                                        // first is allowed to update rf_v and rf_source only if the
5902
                                                                        // second has no target (BEQ or SW)
5903
                                                                        //
5904
                                                                    if (fetchbuf0_rfw) begin
5905
                                                                             rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };
5906
                                                                             rf_v [ Rt0s ] <= `INV;
5907
                                                                    end
5908
                                                                end
5909
                                                end
5910
                                            else if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
5911
                                                 vqe1 <= 6'd1;
5912
                                                if (IsVCmprss(fetchbuf1_instr)) begin
5913
                                                    if (vm[fetchbuf1_instr[25:23]][IsVector(fetchbuf0_instr)? 6'd0:vqe1+6'd1])
5914
                                                         vqet1 <= 6'd1;
5915
                                                else
5916
                                                         vqet1 <= 6'd0;
5917
                                                end
5918
                                                else
5919
                                                         vqet1 <= 6'd1;
5920
                                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR)
5921
                                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
5922
                                                        enque1(tail1,
5923
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
5924
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
5925
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
5926
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
5927
                                                                if (fetchbuf1_thrd)
5928
                                                                        seq_num1 <= seq_num1 + 5'd2;
5929
                                                                else
5930
                                                                        seq_num <= seq_num + 5'd2;
5931
                                                        end
5932
                                                        else begin
5933
                                                                if (fetchbuf1_thrd)
5934
                                                                        seq_num1 <= seq_num1 + 5'd1;
5935
                                                                else
5936
                                                                        seq_num <= seq_num + 5'd1;
5937
                                                        end
5938
 
5939
                                                                // SOURCE 1 ...
5940 55 robfinch
                                                                a1_vs();
5941 48 robfinch
 
5942 55 robfinch
                                                                // SOURCE 2 ..
5943
                                                                a2_vs();
5944 48 robfinch
 
5945
                                                                // SOURCE 3 ...
5946 55 robfinch
                                                                a3_vs();
5947 48 robfinch
 
5948
                                                                // if the two instructions enqueued target the same register, 
5949
                                                                // make sure only the second writes to rf_v and rf_source.
5950
                                                                // first is allowed to update rf_v and rf_source only if the
5951
                                                                // second has no target
5952
                                                                //
5953
                                                            if (fetchbuf0_rfw) begin
5954
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
5955
                                                                     rf_v [ Rt0s] <= `INV;
5956
                                                            end
5957
                                                            if (fetchbuf1_rfw) begin
5958
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
5959
                                                                     rf_v [ Rt1s ] <= `INV;
5960
                                                            end
5961
                                            end
5962
                                            else begin
5963
//                                                      enque1(tail1, seq_num + 5'd1, 6'd0);
5964
                                                        enque1(tail1,
5965
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
5966
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
5967
                                                                fetchbuf1_thrd ? seq_num1: seq_num, 6'd0);
5968
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
5969
                                                                if (fetchbuf1_thrd)
5970
                                                                        seq_num1 <= seq_num1 + 5'd2;
5971
                                                                else
5972
                                                                        seq_num <= seq_num + 5'd2;
5973
                                                        end
5974
                                                        else begin
5975
                                                                        seq_num1 <= seq_num1 + 5'd1;
5976
                                                                        seq_num <= seq_num + 5'd1;
5977
                                                        end
5978
 
5979
                                                                // SOURCE 1 ...
5980 55 robfinch
                                                                a1_vs();
5981 48 robfinch
 
5982
                                                                // SOURCE 2 ...
5983 55 robfinch
                                                                a2_vs();
5984 48 robfinch
 
5985
                                                                // SOURCE 3 ...
5986 55 robfinch
                                                                a3_vs();
5987 48 robfinch
 
5988
                                                                // if the two instructions enqueued target the same register, 
5989
                                                                // make sure only the second writes to regIsValid and rf_source.
5990
                                                                // first is allowed to update regIsValid and rf_source only if the
5991
                                                                // second has no target (BEQ or SW)
5992
                                                                //
5993
                                                            if (fetchbuf0_rfw) begin
5994
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
5995
                                                                     rf_v [ Rt0s] <= `INV;
5996
                                                                     $display("r%dx (%d) Invalidated", Rt0s, Rt0s[4:0]);
5997
                                                            end
5998
                                                            else
5999
                                                                $display("No rfw");
6000
                                                            if (fetchbuf1_rfw) begin
6001
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6002
                                                                     $display("r%dx (%d) Invalidated", Rt1s, Rt1s[4:0]);
6003
                                                                     rf_v [ Rt1s ] <= `INV;
6004
                                                            end
6005
                                                            else
6006
                                                                $display("No rfw");
6007
                                                        end
6008
 
6009
                                            end // ends the "if IQ[tail1] is available" clause
6010
                                            else begin  // only first instruction was enqueued
6011
                                                        if (fetchbuf0_rfw) begin
6012
                                                             $display("r%dx (%d) Invalidated 1", Rt0s, Rt0s[4:0]);
6013
                                                             rf_source[ Rt0s ] <= {1'b0,fetchbuf0_memld, tail0};
6014
                                                             rf_v [ Rt0s ] <= `INV;
6015
                                                        end
6016
                                                end
6017
                                    end
6018
 
6019
                                end     // ends the "else fetchbuf0 doesn't have a backwards branch" clause
6020
                    end
6021
                endcase
6022
        if (pebm) begin
6023
                if (branchmiss_thrd==1'b0)
6024
                        seq_num <= seq_num + 5'd3;
6025
                else
6026
                        seq_num1 <= seq_num1 + 5'd3;
6027
        end
6028
 
6029
//
6030
// DATAINCOMING
6031
//
6032
// wait for operand/s to appear on alu busses and puts them into 
6033
// the iqentry_a1 and iqentry_a2 slots (if appropriate)
6034
// as well as the appropriate iqentry_res slots (and setting valid bits)
6035
//
6036
// put results into the appropriate instruction entries
6037
//
6038
// This chunk of code has to be before the enqueue stage so that the agen bit
6039
// can be reset to zero by enqueue.
6040
// put results into the appropriate instruction entries
6041
//
6042
if (IsMul(alu0_instr)|IsDivmod(alu0_instr)|alu0_shft48) begin
6043
        if (alu0_done) begin
6044
                alu0_dataready <= `TRUE;
6045
        end
6046
end
6047
 
6048
if (alu0_v) begin
6049
        iqentry_tgt [ alu0_id[`QBITS] ] <= alu0_tgt;
6050
        iqentry_res     [ alu0_id[`QBITS] ] <= alu0_bus;
6051
        iqentry_exc     [ alu0_id[`QBITS] ] <= alu0_exc;
6052
        iqentry_done[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
6053
        iqentry_cmt[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
6054
        iqentry_out     [ alu0_id[`QBITS] ] <= `INV;
6055
        iqentry_agen[ alu0_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
6056
        alu0_dataready <= FALSE;
6057
end
6058
 
6059 49 robfinch
if (alu1_v && `NUM_ALU > 1) begin
6060 48 robfinch
        iqentry_tgt [ alu1_id[`QBITS] ] <= alu1_tgt;
6061
        iqentry_res     [ alu1_id[`QBITS] ] <= alu1_bus;
6062
        iqentry_exc     [ alu1_id[`QBITS] ] <= alu1_exc;
6063
        iqentry_done[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
6064
        iqentry_cmt[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
6065
        iqentry_out     [ alu1_id[`QBITS] ] <= `INV;
6066
        iqentry_agen[ alu1_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
6067
        alu1_dataready <= FALSE;
6068
end
6069
 
6070 49 robfinch
if (fpu1_v) begin
6071 51 robfinch
        iqentry_res [ fpu1_id[`QBITS] ] <= fpu1_bus;
6072
        iqentry_a0  [ fpu1_id[`QBITS] ] <= fpu1_status;
6073
        iqentry_exc [ fpu1_id[`QBITS] ] <= fpu1_exc;
6074 49 robfinch
        iqentry_done[ fpu1_id[`QBITS] ] <= fpu1_done;
6075 51 robfinch
        iqentry_cmt     [ fpu1_id[`QBITS] ] <= fpu1_done;
6076
        iqentry_out [ fpu1_id[`QBITS] ] <= `INV;
6077 49 robfinch
        fpu1_dataready <= FALSE;
6078 48 robfinch
end
6079
 
6080 49 robfinch
if (fpu2_v && `NUM_FPU > 1) begin
6081 51 robfinch
        iqentry_res [ fpu2_id[`QBITS] ] <= fpu2_bus;
6082
        iqentry_a0  [ fpu2_id[`QBITS] ] <= fpu2_status;
6083
        iqentry_exc [ fpu2_id[`QBITS] ] <= fpu2_exc;
6084 49 robfinch
        iqentry_done[ fpu2_id[`QBITS] ] <= fpu2_done;
6085 51 robfinch
        iqentry_cmt [ fpu2_id[`QBITS] ] <= fpu2_done;
6086
        iqentry_out [ fpu2_id[`QBITS] ] <= `INV;
6087 49 robfinch
        //iqentry_agen[ fpu_id[`QBITS] ] <= `VAL;  // RET
6088
        fpu2_dataready <= FALSE;
6089
end
6090
 
6091 51 robfinch
if (fcu_wr & ~fcu_done) begin
6092
        fcu_done <= `TRUE;
6093
  if (fcu_ld)
6094
    waitctr <= fcu_argA;
6095
  iqentry_res [ fcu_id[`QBITS] ] <= fcu_bus;
6096
  iqentry_exc [ fcu_id[`QBITS] ] <= fcu_exc;
6097
  if (IsWait(fcu_instr)) begin
6098
                iqentry_done [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
6099
                iqentry_cmt [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
6100
  end
6101
  else begin
6102
                iqentry_done[ fcu_id[`QBITS] ] <= `TRUE;
6103
                iqentry_cmt[ fcu_id[`QBITS] ] <= `TRUE;
6104
  end
6105
        // Only safe place to propagate the miss pc is a0.
6106
        iqentry_a0[ fcu_id[`QBITS] ] <= fcu_misspc;
6107 55 robfinch
        // Update branch target update indicator.
6108 51 robfinch
        if (fcu_jal || fcu_ret || fcu_brk || fcu_rti) begin
6109
                iqentry_bt[ fcu_id[`QBITS] ] <= `VAL;
6110
        end
6111
// Branch target is only updated for branch-to-register
6112 52 robfinch
        else if (fcu_branch) begin
6113
                iqentry_takb[ fcu_id[`QBITS] ] <= fcu_takb;
6114
        end
6115 51 robfinch
        iqentry_out [ fcu_id[`QBITS] ] <= `INV;
6116
        //iqentry_agen[ fcu_id[`QBITS] ] <= `VAL;//!IsRet(fcu_instr);
6117
        fcu_dataready <= `VAL;
6118 48 robfinch
         //fcu_dataready <= fcu_branchmiss || !iqentry_agen[ fcu_id[`QBITS] ] || !(iqentry_mem[ fcu_id[`QBITS] ] && IsLoad(iqentry_instr[fcu_id[`QBITS]]));
6119
         //fcu_instr[`INSTRUCTION_OP] <= fcu_branchmiss|| (!IsMem(fcu_instr) && !IsWait(fcu_instr))? `NOP : fcu_instr[`INSTRUCTION_OP]; // to clear branchmiss
6120 51 robfinch
end
6121
// Clear a branch miss when target instruction is fetched.
6122
if (fcu_branchmiss) begin
6123
        if ((fetchbuf0_v && fetchbuf0_pc==misspc) ||
6124
                (fetchbuf1_v && fetchbuf1_pc==misspc))
6125
        fcu_clearbm <= `TRUE;
6126
end
6127
 
6128
if (mem1_available && dramA_v && iqentry_v[ dramA_id[`QBITS] ] && iqentry_load[ dramA_id[`QBITS] ]) begin
6129
        iqentry_res     [ dramA_id[`QBITS] ] <= dramA_bus;
6130
        iqentry_exc     [ dramA_id[`QBITS] ] <= dramA_exc;
6131
        iqentry_done[ dramA_id[`QBITS] ] <= `VAL;
6132
        iqentry_out [ dramA_id[`QBITS] ] <= `INV;
6133
        iqentry_cmt [ dramA_id[`QBITS] ] <= `VAL;
6134
        iqentry_aq  [ dramA_id[`QBITS] ] <= `INV;
6135
end
6136
if (mem2_available && `NUM_MEM > 1 && dramB_v && iqentry_v[ dramB_id[`QBITS] ] && iqentry_load[ dramB_id[`QBITS] ]) begin
6137
        iqentry_res     [ dramB_id[`QBITS] ] <= dramB_bus;
6138
        iqentry_exc     [ dramB_id[`QBITS] ] <= dramB_exc;
6139
        iqentry_done[ dramB_id[`QBITS] ] <= `VAL;
6140
        iqentry_out [ dramB_id[`QBITS] ] <= `INV;
6141
        iqentry_cmt [ dramB_id[`QBITS] ] <= `VAL;
6142
        iqentry_aq  [ dramB_id[`QBITS] ] <= `INV;
6143
end
6144
if (mem3_available && `NUM_MEM > 2 && dramC_v && iqentry_v[ dramC_id[`QBITS] ] && iqentry_load[ dramC_id[`QBITS] ]) begin
6145
        iqentry_res     [ dramC_id[`QBITS] ] <= dramC_bus;
6146
        iqentry_exc     [ dramC_id[`QBITS] ] <= dramC_exc;
6147
        iqentry_done[ dramC_id[`QBITS] ] <= `VAL;
6148
        iqentry_out [ dramC_id[`QBITS] ] <= `INV;
6149
        iqentry_cmt [ dramC_id[`QBITS] ] <= `VAL;
6150
        iqentry_aq  [ dramC_id[`QBITS] ] <= `INV;
6151 48 robfinch
//          if (iqentry_lptr[dram2_id[`QBITS]])
6152
//              wbrcd[pcr[5:0]] <= 1'b1;
6153 51 robfinch
end
6154 48 robfinch
 
6155
//
6156
// set the IQ entry == DONE as soon as the SW is let loose to the memory system
6157
//
6158 50 robfinch
if (mem1_available && dram0 == `DRAMSLOT_BUSY && dram0_store) begin
6159 48 robfinch
        if ((alu0_v && (dram0_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram0_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6160
        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
6161
        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
6162
end
6163 50 robfinch
if (mem2_available && `NUM_MEM > 1 && dram1 == `DRAMSLOT_BUSY && dram1_store) begin
6164 48 robfinch
        if ((alu0_v && (dram1_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram1_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6165
        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
6166
        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
6167
end
6168 50 robfinch
if (mem3_available && `NUM_MEM > 2 && dram2 == `DRAMSLOT_BUSY && dram2_store) begin
6169 48 robfinch
        if ((alu0_v && (dram2_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram2_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6170
        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
6171
        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
6172
end
6173
 
6174
//
6175
// see if anybody else wants the results ... look at lots of buses:
6176
//  - fpu_bus
6177
//  - alu0_bus
6178
//  - alu1_bus
6179
//  - fcu_bus
6180
//  - dram_bus
6181
//  - commit0_bus
6182
//  - commit1_bus
6183
//
6184
 
6185
for (n = 0; n < QENTRIES; n = n + 1)
6186
begin
6187 49 robfinch
        if (`NUM_FPU > 0)
6188
                setargs(n,{1'b0,fpu1_id},fpu1_v,fpu1_bus);
6189
        if (`NUM_FPU > 1)
6190
                setargs(n,{1'b0,fpu2_id},fpu2_v,fpu2_bus);
6191
 
6192 48 robfinch
        setargs(n,{1'b0,alu0_id},alu0_v,alu0_bus);
6193 49 robfinch
        if (`NUM_ALU > 1)
6194
                setargs(n,{1'b0,alu1_id},alu1_v,alu1_bus);
6195
 
6196 48 robfinch
        setargs(n,{1'b0,fcu_id},fcu_wr,fcu_bus);
6197 49 robfinch
 
6198 48 robfinch
        setargs(n,{1'b0,dramA_id},dramA_v,dramA_bus);
6199 49 robfinch
        if (`NUM_MEM > 1)
6200
                setargs(n,{1'b0,dramB_id},dramB_v,dramB_bus);
6201
        if (`NUM_MEM > 2)
6202
                setargs(n,{1'b0,dramC_id},dramC_v,dramC_bus);
6203
 
6204 48 robfinch
        setargs(n,commit0_id,commit0_v,commit0_bus);
6205 49 robfinch
        if (`NUM_CMT > 1)
6206
                setargs(n,commit1_id,commit1_v,commit1_bus);
6207 48 robfinch
 
6208
        setinsn(n[`QBITS],id1_ido,id1_available&id1_vo,id1_bus);
6209 49 robfinch
        if (`NUM_IDU > 1)
6210
                setinsn(n[`QBITS],id2_ido,id2_available&id2_vo,id2_bus);
6211
        if (`NUM_IDU > 2)
6212
                setinsn(n[`QBITS],id3_ido,id3_available&id3_vo,id3_bus);
6213 48 robfinch
end
6214
 
6215
//
6216
// ISSUE 
6217
//
6218
// determines what instructions are ready to go, then places them
6219
// in the various ALU queues.  
6220
// also invalidates instructions following a branch-miss BEQ or any JALR (STOMP logic)
6221
//
6222
 
6223
for (n = 0; n < QENTRIES; n = n + 1)
6224
if (id1_available) begin
6225
if (iqentry_id1issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6226
                id1_vi <= `VAL;
6227
                id1_id                  <= n[4:0];
6228
                id1_instr       <= iqentry_rtop[n] ? (
6229
                                                                                iqentry_a3_v[n] ? iqentry_a3[n]
6230 49 robfinch
`ifdef FU_BYPASS
6231 48 robfinch
                                : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
6232
                                : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
6233 49 robfinch
`endif
6234 48 robfinch
                                : `NOP_INSN)
6235
                                                                 : iqentry_instr[n];
6236
                id1_ven    <= iqentry_ven[n];
6237
                id1_vl     <= iqentry_vl[n];
6238
                id1_thrd   <= iqentry_thrd[n];
6239
                id1_Rt     <= iqentry_tgt[n][4:0];
6240
                id1_pt                  <= iqentry_pt[n];
6241
  end
6242
end
6243 49 robfinch
if (`NUM_IDU > 1) begin
6244 48 robfinch
for (n = 0; n < QENTRIES; n = n + 1)
6245 49 robfinch
        if (id2_available) begin
6246
                if (iqentry_id2issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6247
                        id2_vi <= `VAL;
6248
                        id2_id                  <= n[4:0];
6249
                        id2_instr       <= iqentry_rtop[n] ? (
6250
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6251
`ifdef FU_BYPASS
6252
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
6253
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
6254
`endif
6255
                                        : `NOP_INSN)
6256
                                                                         : iqentry_instr[n];
6257
                        id2_ven    <= iqentry_ven[n];
6258
                        id2_vl     <= iqentry_vl[n];
6259
                        id2_thrd   <= iqentry_thrd[n];
6260
                        id2_Rt     <= iqentry_tgt[n][4:0];
6261
                        id2_pt                  <= iqentry_pt[n];
6262
                end
6263 48 robfinch
        end
6264
end
6265 49 robfinch
if (`NUM_IDU > 2) begin
6266
for (n = 0; n < QENTRIES; n = n + 1)
6267
        if (id3_available) begin
6268
                if (iqentry_id3issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6269
                        id3_vi <= `VAL;
6270
                        id3_id                  <= n[4:0];
6271
                        id3_instr       <= iqentry_rtop[n] ? (
6272
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6273
`ifdef FU_BYPASS
6274
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
6275
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
6276
`endif
6277
                                        : `NOP_INSN)
6278
                                                                         : iqentry_instr[n];
6279
                        id3_ven    <= iqentry_ven[n];
6280
                        id3_vl     <= iqentry_vl[n];
6281
                        id3_thrd   <= iqentry_thrd[n];
6282
                        id3_Rt     <= iqentry_tgt[n][4:0];
6283
                        id3_pt                  <= iqentry_pt[n];
6284
                end
6285
        end
6286
end
6287 48 robfinch
 
6288 53 robfinch
// X's on unused busses cause problems in SIM.
6289 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
6290
        if (iqentry_alu0_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6291
            if (alu0_available & alu0_done) begin
6292
                 alu0_sourceid  <= n[3:0];
6293
                 alu0_instr     <= iqentry_rtop[n] ? (
6294 49 robfinch
`ifdef FU_BYPASS
6295 48 robfinch
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6296 49 robfinch
                                                    : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
6297 53 robfinch
                                                    : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
6298 49 robfinch
                                                    : (iqentry_a3_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6299 53 robfinch
                                                    : `NOP_INSN)
6300 49 robfinch
`else
6301
                                                                                                                                        iqentry_a3[n])
6302
`endif
6303 48 robfinch
                                                                         : iqentry_instr[n];
6304
                 alu0_bt                <= iqentry_bt[n];
6305
                 alu0_mem   <= iqentry_mem[n];
6306
                 alu0_shft48 <= iqentry_shft48[n];
6307
                 alu0_pc                <= iqentry_pc[n];
6308 49 robfinch
                 alu0_argA      <=
6309
`ifdef FU_BYPASS
6310
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
6311
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
6312 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
6313 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6314 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
6315 49 robfinch
`else
6316
                                                                                                                iqentry_a1[n];
6317
`endif
6318 48 robfinch
                 alu0_argB      <= iqentry_imm[n]
6319
                            ? iqentry_a0[n]
6320 49 robfinch
`ifdef FU_BYPASS
6321 48 robfinch
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
6322 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
6323 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
6324 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6325 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
6326 49 robfinch
`else
6327
                                                                                                                : iqentry_a2[n];
6328
`endif
6329
                 alu0_argC      <=
6330
`ifdef FU_BYPASS
6331
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6332 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6333 49 robfinch
`else
6334
                                                                                                                        iqentry_a3[n];
6335
`endif
6336 48 robfinch
                 alu0_argI      <= iqentry_a0[n];
6337
                 alu0_tgt    <= IsVeins(iqentry_instr[n]) ?
6338 49 robfinch
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((
6339
                                                                                        iqentry_a2_v[n] ? iqentry_a2[n][5:0]
6340 48 robfinch
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
6341
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
6342
                                            : {4{16'h0000}})) << 6 :
6343
                                iqentry_tgt[n];
6344
                 alu0_ven    <= iqentry_ven[n];
6345
                 alu0_thrd   <= iqentry_thrd[n];
6346
                 alu0_dataready <= IsSingleCycle(iqentry_instr[n]);
6347
                 alu0_ld <= TRUE;
6348
                 iqentry_out[n] <= `VAL;
6349
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
6350
                if (iqentry_mem[n]) begin
6351
                 iqentry_a1_v[n] <= `INV;
6352
                 iqentry_a1_s[n] <= n[3:0];
6353
                end
6354
            end
6355
        end
6356 49 robfinch
        if (`NUM_ALU > 1) begin
6357 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
6358
        if (iqentry_alu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6359
            if (alu1_available && alu1_done) begin
6360
                        if (iqentry_alu0[n])
6361
                                panic <= `PANIC_ALU0ONLY;
6362
                 alu1_sourceid  <= n[3:0];
6363
                 alu1_instr     <= iqentry_instr[n];
6364
                 alu1_bt                <= iqentry_bt[n];
6365
                 alu1_mem   <= iqentry_mem[n];
6366
                 alu1_shft48 <= iqentry_shft48[n];
6367
                 alu1_pc                <= iqentry_pc[n];
6368 49 robfinch
                 alu1_argA      <=
6369
`ifdef FU_BYPASS
6370
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
6371
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
6372 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
6373 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6374 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
6375 49 robfinch
`else
6376
                                                                                                                        iqentry_a1[n];
6377
`endif
6378 48 robfinch
                 alu1_argB      <= iqentry_imm[n]
6379
                            ? iqentry_a0[n]
6380 49 robfinch
`ifdef FU_BYPASS
6381 48 robfinch
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
6382 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
6383 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
6384 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6385 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
6386 49 robfinch
`else
6387
                                                                                                                : iqentry_a2[n];
6388
`endif
6389
                 alu1_argC      <=
6390
`ifdef FU_BYPASS
6391
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6392 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6393 49 robfinch
`else
6394
                                                                                                                        iqentry_a3[n];
6395
`endif
6396 48 robfinch
                 alu1_argI      <= iqentry_a0[n];
6397
                 alu1_tgt    <= IsVeins(iqentry_instr[n]) ?
6398
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((iqentry_a2_v[n] ? iqentry_a2[n][5:0]
6399
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
6400
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
6401
                                            : {4{16'h0000}})) << 6 :
6402
                                iqentry_tgt[n];
6403
                 alu1_ven    <= iqentry_ven[n];
6404
                 alu1_dataready <= IsSingleCycle(iqentry_instr[n]);
6405
                 alu1_ld <= TRUE;
6406
                 iqentry_out[n] <= `VAL;
6407
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
6408
                if (iqentry_mem[n]) begin
6409
                 iqentry_a1_v[n] <= `INV;
6410
                 iqentry_a1_s[n] <= n[3:0];
6411
                end
6412
            end
6413
        end
6414 49 robfinch
  end
6415 48 robfinch
 
6416
    for (n = 0; n < QENTRIES; n = n + 1)
6417 49 robfinch
        if (iqentry_fpu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6418
            if (fpu1_available & fpu1_done) begin
6419
                 fpu1_sourceid  <= n[3:0];
6420
                 fpu1_instr     <= iqentry_instr[n];
6421
                 fpu1_pc                <= iqentry_pc[n];
6422
                 fpu1_argA      <=
6423
`ifdef FU_BYPASS
6424
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
6425
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
6426 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
6427 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6428 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
6429 49 robfinch
`else
6430
                                                                                                                        iqentry_a1[n];
6431
`endif
6432
                 fpu1_argB      <=
6433
`ifdef FU_BYPASS
6434
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
6435
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
6436 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
6437 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6438 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
6439 49 robfinch
`else
6440
                                                                                                                        iqentry_a2[n];
6441
`endif
6442
                 fpu1_argC      <=
6443
`ifdef FU_BYPASS
6444
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
6445 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6446 49 robfinch
`else
6447
                                                                                                                        iqentry_a3[n];
6448
`endif
6449
                 fpu1_argI      <= iqentry_a0[n];
6450
                 fpu1_dataready <= `VAL;
6451
                 fpu1_ld <= TRUE;
6452 48 robfinch
                 iqentry_out[n] <= `VAL;
6453
            end
6454
        end
6455
 
6456
    for (n = 0; n < QENTRIES; n = n + 1)
6457 49 robfinch
        if (`NUM_FPU > 1 && iqentry_fpu2_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6458
            if (fpu2_available & fpu2_done) begin
6459
                 fpu2_sourceid  <= n[3:0];
6460
                 fpu2_instr     <= iqentry_instr[n];
6461
                 fpu2_pc                <= iqentry_pc[n];
6462
                 fpu2_argA      <=
6463
`ifdef FU_BYPASS
6464
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
6465
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
6466 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
6467 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6468 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
6469 49 robfinch
`else
6470
                                                                                                                        iqentry_a1[n];
6471
`endif
6472
                 fpu2_argB      <=
6473
`ifdef FU_BYPASS
6474
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
6475
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
6476 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
6477 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6478 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
6479 49 robfinch
`else
6480
                                                                                                                        iqentry_a2[n];
6481
`endif
6482
                 fpu2_argC      <=
6483
`ifdef FU_BYPASS
6484
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
6485
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6486
`else
6487
                                                                                                                        iqentry_a3[n];
6488
`endif
6489
                 fpu2_argI      <= iqentry_a0[n];
6490
                 fpu2_dataready <= `VAL;
6491
                 fpu2_ld <= TRUE;
6492
                 iqentry_out[n] <= `VAL;
6493
            end
6494
        end
6495
 
6496
    for (n = 0; n < QENTRIES; n = n + 1)
6497 48 robfinch
        if (iqentry_fcu_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6498
            if (fcu_done) begin
6499
                 fcu_sourceid   <= n[3:0];
6500
                 fcu_instr      <= iqentry_instr[n];
6501
                 fcu_insln  <= iqentry_insln[n];
6502
                 fcu_pc         <= iqentry_pc[n];
6503
                 fcu_nextpc <= iqentry_pc[n] + iqentry_insln[n];
6504
                 fcu_brdisp <= {{52{iqentry_instr[n][31]}},iqentry_instr[n][31:21],1'b0};
6505 51 robfinch
                 fcu_branch <= iqentry_br[n];
6506
                 fcu_call    <= IsCall(iqentry_instr[n])|iqentry_jal[n];
6507
                 fcu_jal     <= iqentry_jal[n];
6508
                 fcu_ret    <= iqentry_ret[n];
6509
                 fcu_brk  <= iqentry_brk[n];
6510
                 fcu_rti  <= iqentry_rti[n];
6511 48 robfinch
                 fcu_bt         <= iqentry_bt[n];
6512
                 fcu_pc         <= iqentry_pc[n];
6513
                 fcu_argA       <= iqentry_a1_v[n] ? iqentry_a1[n]
6514 49 robfinch
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
6515
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6516
                            : alu1_bus;
6517 48 robfinch
`ifdef SUPPORT_SMT
6518 51 robfinch
                 fcu_argB       <= iqentry_rti[n] ? epc0[iqentry_thrd[n]]
6519 48 robfinch
`else
6520 51 robfinch
                 fcu_argB       <= iqentry_rti[n] ? epc0
6521 48 robfinch
`endif
6522
                                        : (iqentry_a2_v[n] ? iqentry_a2[n]
6523 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
6524
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6525
                            : alu1_bus);
6526 48 robfinch
                 waitctr            <= iqentry_imm[n]
6527
                            ? iqentry_a0[n]
6528
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
6529
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus : alu1_bus);
6530
                 fcu_argC       <= iqentry_a3_v[n] ? iqentry_a3[n]
6531
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6532
                 fcu_argI       <= iqentry_a0[n];
6533
                 fcu_thrd   <= iqentry_thrd[n];
6534
                 fcu_dataready <= `VAL;
6535
                 fcu_clearbm <= `FALSE;
6536
                 fcu_ld <= TRUE;
6537
                 fcu_timeout <= 8'h00;
6538
                 iqentry_out[n] <= `VAL;
6539
                 fcu_done <= `FALSE;
6540
            end
6541
        end
6542
//
6543
// MEMORY
6544
//
6545
// update the memory queues and put data out on bus if appropriate
6546
//
6547
 
6548
//
6549
// dram0, dram1, dram2 are the "state machines" that keep track
6550
// of three pipelined DRAM requests.  if any has the value "00", 
6551
// then it can accept a request (which bumps it up to the value "01"
6552
// at the end of the cycle).  once it hits the value "11" the request
6553
// is finished and the dram_bus takes the value.  if it is a store, the 
6554
// dram_bus value is not used, but the dram_v value along with the
6555
// dram_id value signals the waiting memq entry that the store is
6556
// completed and the instruction can commit.
6557
//
6558
 
6559
//      if (dram0 != `DRAMSLOT_AVAIL)   dram0 <= dram0 + 2'd1;
6560
//      if (dram1 != `DRAMSLOT_AVAIL)   dram1 <= dram1 + 2'd1;
6561
//      if (dram2 != `DRAMSLOT_AVAIL)   dram2 <= dram2 + 2'd1;
6562
 
6563
//
6564
// grab requests that have finished and put them on the dram_bus
6565 49 robfinch
if (mem1_available && dram0 == `DRAMREQ_READY) begin
6566 48 robfinch
        dram0 <= `DRAMSLOT_AVAIL;
6567
        dramA_v <= dram0_load;
6568
        dramA_id <= dram0_id;
6569
        dramA_exc <= dram0_exc;
6570
        dramA_bus <= fnDati(dram0_instr,dram0_addr,rdat0);
6571 50 robfinch
        if (dram0_store)        $display("m[%h] <- %h", dram0_addr, dram0_data);
6572 48 robfinch
end
6573
//    else
6574
//      dramA_v <= `INV;
6575 49 robfinch
if (mem2_available && dram1 == `DRAMREQ_READY && `NUM_MEM > 1) begin
6576 48 robfinch
        dram1 <= `DRAMSLOT_AVAIL;
6577
        dramB_v <= dram1_load;
6578
        dramB_id <= dram1_id;
6579
        dramB_exc <= dram1_exc;
6580
        dramB_bus <= fnDati(dram1_instr,dram1_addr,rdat1);
6581 50 robfinch
        if (dram1_store)     $display("m[%h] <- %h", dram1_addr, dram1_data);
6582 48 robfinch
end
6583
//    else
6584
//      dramB_v <= `INV;
6585 49 robfinch
if (mem3_available && dram2 == `DRAMREQ_READY && `NUM_MEM > 2) begin
6586 48 robfinch
        dram2 <= `DRAMSLOT_AVAIL;
6587
        dramC_v <= dram2_load;
6588
        dramC_id <= dram2_id;
6589
        dramC_exc <= dram2_exc;
6590
        dramC_bus <= fnDati(dram2_instr,dram2_addr,rdat2);
6591 50 robfinch
        if (dram2_store)     $display("m[%h] <- %h", dram2_addr, dram2_data);
6592 48 robfinch
end
6593
//    else
6594
//      dramC_v <= `INV;
6595
 
6596
        //
6597
        // determine if the instructions ready to issue can, in fact, issue.
6598
        // "ready" means that the instruction has valid operands but has not gone yet
6599
        iqentry_memissue <= memissue;
6600
        missue_count <= issue_count;
6601
 
6602
 
6603
        //
6604
        // take requests that are ready and put them into DRAM slots
6605
 
6606
        if (dram0 == `DRAMSLOT_AVAIL)    dram0_exc <= `FLT_NONE;
6607
        if (dram1 == `DRAMSLOT_AVAIL)    dram1_exc <= `FLT_NONE;
6608
        if (dram2 == `DRAMSLOT_AVAIL)    dram2_exc <= `FLT_NONE;
6609
 
6610
        for (n = 0; n < QENTRIES; n = n + 1)
6611
                if (iqentry_v[n] && iqentry_stomp[n]) begin
6612
                        iqentry_v[n] <= `INV;
6613
                        iqentry_iv[n] <= `INV;
6614
                        if (dram0_id[`QBITS] == n[`QBITS])  dram0 <= `DRAMSLOT_AVAIL;
6615
                        if (dram1_id[`QBITS] == n[`QBITS])  dram1 <= `DRAMSLOT_AVAIL;
6616
                        if (dram2_id[`QBITS] == n[`QBITS])  dram2 <= `DRAMSLOT_AVAIL;
6617
                end
6618
 
6619 53 robfinch
        last_issue = QENTRIES;
6620 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
6621 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
6622
            if (mem1_available && dram0 == `DRAMSLOT_AVAIL) begin
6623 48 robfinch
                dramA_v <= `INV;
6624
             dram0              <= `DRAMSLOT_BUSY;
6625
             dram0_id   <= { 1'b1, n[`QBITS] };
6626
             dram0_instr <= iqentry_instr[n];
6627
             dram0_rmw  <= iqentry_rmw[n];
6628
             dram0_preload <= iqentry_preload[n];
6629
             dram0_tgt  <= iqentry_tgt[n];
6630
             dram0_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
6631
             dram0_addr <= iqentry_a1[n];
6632
//             if (ol[iqentry_thrd[n]]==`OL_USER)
6633
//              dram0_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
6634
//             else
6635 50 robfinch
             dram0_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
6636
             dram0_memsize <= iqentry_memsz[n];
6637 48 robfinch
             dram0_load <= iqentry_load[n];
6638 50 robfinch
             dram0_store <= iqentry_store[n];
6639 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]];
6640
             // Once the memory op is issued reset the a1_v flag.
6641
             // This will cause the a1 bus to look for new data from memory (a1_s is pointed to a memory bus)
6642
             // This is used for the load and compare instructions.
6643
             iqentry_a1_v[n] <= `INV;
6644
             last_issue = n;
6645
            end
6646
        end
6647 53 robfinch
    if (last_issue < QENTRIES)
6648 48 robfinch
        iqentry_out[last_issue] <= `VAL;
6649
    for (n = 0; n < QENTRIES; n = n + 1)
6650 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
6651
                if (mem2_available && n < last_issue && `NUM_MEM > 1) begin
6652 48 robfinch
                    if (dram1 == `DRAMSLOT_AVAIL) begin
6653
                        dramB_v <= `INV;
6654
                     dram1              <= `DRAMSLOT_BUSY;
6655
                     dram1_id   <= { 1'b1, n[`QBITS] };
6656
                     dram1_instr <= iqentry_instr[n];
6657
                     dram1_rmw  <= iqentry_rmw[n];
6658
                     dram1_preload <= iqentry_preload[n];
6659
                     dram1_tgt  <= iqentry_tgt[n];
6660
                     dram1_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
6661
                     dram1_addr <= iqentry_a1[n];
6662
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
6663
//                      dram1_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
6664
//                   else
6665 50 robfinch
                     dram1_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
6666
                     dram1_memsize <= iqentry_memsz[n];
6667 48 robfinch
                     dram1_load <= iqentry_load[n];
6668 50 robfinch
                     dram1_store <= iqentry_store[n];
6669 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]];
6670
                     iqentry_a1_v[n] <= `INV;
6671
                     last_issue = n;
6672
                    end
6673
                end
6674
        end
6675 53 robfinch
    if (last_issue < QENTRIES)
6676 48 robfinch
        iqentry_out[last_issue] <= `VAL;
6677
    for (n = 0; n < QENTRIES; n = n + 1)
6678 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
6679
                if (mem3_available && n < last_issue && `NUM_MEM > 2) begin
6680 48 robfinch
                    if (dram2 == `DRAMSLOT_AVAIL) begin
6681
                        dramC_v <= `INV;
6682
                     dram2              <= `DRAMSLOT_BUSY;
6683
                     dram2_id   <= { 1'b1, n[`QBITS] };
6684
                     dram2_instr        <= iqentry_instr[n];
6685
                     dram2_rmw  <= iqentry_rmw[n];
6686
                     dram2_preload <= iqentry_preload[n];
6687
                     dram2_tgt  <= iqentry_tgt[n];
6688
                     dram2_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
6689
                     dram2_addr <= iqentry_a1[n];
6690
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
6691
//                      dram2_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
6692
//                   else
6693 50 robfinch
                     dram2_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
6694
                     dram2_memsize <= iqentry_memsz[n];
6695 48 robfinch
                     dram2_load <= iqentry_load[n];
6696 50 robfinch
                     dram2_store <= iqentry_store[n];
6697 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]];
6698
                     iqentry_a1_v[n] <= `INV;
6699
                    end
6700
                end
6701
        end
6702 53 robfinch
    if (last_issue < QENTRIES)
6703 48 robfinch
        iqentry_out[last_issue] <= `VAL;
6704
 
6705 51 robfinch
for (n = 0; n < QENTRIES; n = n + 1)
6706
begin
6707
        if (!iqentry_v[n])
6708
                iqentry_done[n] <= FALSE;
6709
end
6710 48 robfinch
 
6711
 
6712
 
6713 49 robfinch
//
6714
// COMMIT PHASE (dequeue only ... not register-file update)
6715
//
6716
// look at head0 and head1 and let 'em write to the register file if they are ready
6717
//
6718 48 robfinch
//    always @(posedge clk) begin: commit_phase
6719
 
6720 49 robfinch
oddball_commit(commit0_v, head0);
6721
if (`NUM_CMT > 1)
6722
        oddball_commit(commit1_v, head1);
6723 50 robfinch
//if (`NUM_CMT > 2)
6724
//      oddball_commit(commit2_v, head2);
6725 48 robfinch
 
6726
// Fetch and queue are limited to two instructions per cycle, so we might as
6727
// well limit retiring to two instructions max to conserve logic.
6728
//
6729
if (~|panic)
6730 49 robfinch
  casez ({ iqentry_v[head0],
6731
                iqentry_cmt[head0],
6732
                iqentry_v[head1],
6733
                iqentry_cmt[head1],
6734
                iqentry_v[head2],
6735
                iqentry_cmt[head2]})
6736 48 robfinch
 
6737
        // retire 3
6738 49 robfinch
        6'b0?_0?_0?:
6739
                if (head0 != tail0 && head1 != tail0 && head2 != tail0) begin
6740
                                head_inc(3);
6741
                end
6742
                else if (head0 != tail0 && head1 != tail0) begin
6743 48 robfinch
                    head_inc(2);
6744
                end
6745
                else if (head0 != tail0) begin
6746
                    head_inc(1);
6747
                end
6748 49 robfinch
        6'b0?_0?_10:    ;
6749
        6'b0?_0?_11:
6750
                if (`NUM_CMT > 2 || iqentry_tgt[head2][4:0]==5'd0) begin
6751
      iqentry_v[head2] <= `INV;
6752
      head_inc(3);
6753
                end
6754
                else begin
6755
      head_inc(2);
6756
                end
6757 48 robfinch
 
6758
        // retire 1 (wait for regfile for head1)
6759 49 robfinch
        6'b0?_10_??:
6760
                head_inc(1);
6761 48 robfinch
 
6762
        // retire 2
6763 49 robfinch
        6'b0?_11_0?,
6764
        6'b0?_11_10:
6765
        if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
6766
          iqentry_v[head1] <= `INV;
6767
          head_inc(2);
6768 48 robfinch
        end
6769 49 robfinch
        else begin
6770
                head_inc(1);
6771
        end
6772
  6'b0?_11_11:
6773 50 robfinch
        if (`NUM_CMT > 2 || (`NUM_CMT > 1 && iqentry_tgt[head2] == 12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
6774 49 robfinch
                iqentry_v[head1] <= `INV;
6775
          iqentry_v[head2] <= `INV;
6776
                head_inc(3);
6777
        end
6778
        else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
6779
                iqentry_v[head1] <= `INV;
6780
                head_inc(2);
6781
        end
6782
        else
6783
                head_inc(1);
6784
  6'b10_??_??:  ;
6785
  6'b11_0?_0?:
6786
        if (head1 != tail0 && head2 != tail0) begin
6787 48 robfinch
                        iqentry_v[head0] <= `INV;
6788 49 robfinch
                        head_inc(3);
6789
        end
6790
        else if (head1 != tail0) begin
6791
                        iqentry_v[head0] <= `INV;
6792 48 robfinch
                        head_inc(2);
6793 49 robfinch
        end
6794
        else begin
6795 48 robfinch
                        iqentry_v[head0] <= `INV;
6796
                        head_inc(1);
6797 49 robfinch
        end
6798
  6'b11_0?_10:
6799
        if (head1 != tail0) begin
6800
                        iqentry_v[head0] <= `INV;
6801
                        head_inc(2);
6802
        end
6803
        else begin
6804
                        iqentry_v[head0] <= `INV;
6805
                        head_inc(1);
6806
        end
6807
  6'b11_0?_11:
6808
        if (head1 != tail0) begin
6809 50 robfinch
                if (`NUM_CMT > 2 || (iqentry_tgt[head2]==12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
6810 49 robfinch
                                iqentry_v[head0] <= `INV;
6811
                                iqentry_v[head2] <= `INV;
6812
                                head_inc(3);
6813
                end
6814
                else begin
6815
                                iqentry_v[head0] <= `INV;
6816
                                head_inc(2);
6817
                        end
6818
        end
6819
        else begin
6820
                        iqentry_v[head0] <= `INV;
6821
                        head_inc(1);
6822
        end
6823
  6'b11_10_??:
6824
        begin
6825
                        iqentry_v[head0] <= `INV;
6826
                        head_inc(1);
6827
        end
6828
  6'b11_11_0?:
6829
        if (`NUM_CMT > 1 && head2 != tail0) begin
6830
                        iqentry_v[head0] <= `INV;
6831
                        iqentry_v[head1] <= `INV;
6832
                        head_inc(3);
6833
        end
6834
        else if (iqentry_tgt[head1]== 12'd0 && head2 != tail0) begin
6835
                        iqentry_v[head0] <= `INV;
6836
                        iqentry_v[head1] <= `INV;
6837
                        head_inc(3);
6838
        end
6839
        else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
6840
                        iqentry_v[head0] <= `INV;
6841
                        iqentry_v[head1] <= `INV;
6842
                        head_inc(2);
6843
        end
6844
        else begin
6845
                        iqentry_v[head0] <= `INV;
6846
                        head_inc(1);
6847
        end
6848
  6'b11_11_10:
6849
        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_11:
6859 50 robfinch
                if (`NUM_CMT > 2 || (`NUM_CMT > 1 && iqentry_tgt[head2]==12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
6860 49 robfinch
                        iqentry_v[head0] <= `INV;
6861
                        iqentry_v[head1] <= `INV;
6862
                        iqentry_v[head2] <= `INV;
6863
                        head_inc(3);
6864 48 robfinch
                end
6865 49 robfinch
                else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
6866 48 robfinch
                        iqentry_v[head0] <= `INV;
6867 49 robfinch
                        iqentry_v[head1] <= `INV;
6868
                        head_inc(2);
6869
                end
6870
                else begin
6871
                        iqentry_v[head0] <= `INV;
6872 48 robfinch
                        head_inc(1);
6873
                end
6874 49 robfinch
  endcase
6875 48 robfinch
 
6876
 
6877 55 robfinch
rf_source[0] <= 0;
6878
L1_wr0 <= FALSE;
6879
L1_wr1 <= FALSE;
6880
L1_wr2 <= FALSE;
6881
L1_invline <= FALSE;
6882
icnxt <= FALSE;
6883
L2_nxt <= FALSE;
6884 48 robfinch
// Instruction cache state machine.
6885
// On a miss first see if the instruction is in the L2 cache. No need to go to
6886
// the BIU on an L1 miss.
6887
// If not the machine will wait until the BIU loads the L2 cache.
6888
 
6889
// Capture the previous ic state, used to determine how long to wait in
6890
// icstate #4.
6891 55 robfinch
picstate <= icstate;
6892 48 robfinch
case(icstate)
6893
IDLE:
6894
        // If the bus unit is busy doing an update involving L1_adr or L2_adr
6895
        // we have to wait.
6896
        if (bstate != B7 && bstate != B9) begin
6897
                if (!ihit0) begin
6898 55 robfinch
                        L1_adr <= {pcr[5:0],pc0[31:5],5'h0};
6899
                        L2_adr <= {pcr[5:0],pc0[31:5],5'h0};
6900 48 robfinch
                        L1_invline <= TRUE;
6901 49 robfinch
                        icwhich <= 2'b00;
6902 48 robfinch
                        iccnt <= 3'b00;
6903
                        icstate <= IC2;
6904
                end
6905 49 robfinch
                else if (!ihit1 && `WAYS > 1) begin
6906 55 robfinch
                        if (thread_en) begin
6907
                                L1_adr <= {pcr[5:0],pc1[31:5],5'h0};
6908
                                L2_adr <= {pcr[5:0],pc1[31:5],5'h0};
6909
                        end
6910
                        else begin
6911
                                L1_adr <= {pcr[5:0],pc0plus6[31:5],5'h0};
6912
                                L2_adr <= {pcr[5:0],pc0plus6[31:5],5'h0};
6913
                        end
6914 48 robfinch
                        L1_invline <= TRUE;
6915 49 robfinch
                        icwhich <= 2'b01;
6916 48 robfinch
                        iccnt <= 3'b00;
6917
                        icstate <= IC2;
6918
                end
6919 49 robfinch
                else if (!ihit2 && `WAYS > 2) begin
6920 55 robfinch
                        if (thread_en) begin
6921
                                L1_adr <= {pcr[5:0],pc2[31:5],5'h0};
6922
                                L2_adr <= {pcr[5:0],pc2[31:5],5'h0};
6923
                        end
6924
                        else begin
6925
                                L1_adr <= {pcr[5:0],pc0plus12[31:5],5'h0};
6926
                                L2_adr <= {pcr[5:0],pc0plus12[31:5],5'h0};
6927
                        end
6928 49 robfinch
                        L1_invline <= TRUE;
6929
                        icwhich <= 2'b10;
6930
                        iccnt <= 3'b00;
6931
                        icstate <= IC2;
6932
                end
6933 48 robfinch
        end
6934
IC2:     icstate <= IC3;
6935
IC3:     icstate <= IC3a;
6936
IC3a:     icstate <= IC4;
6937
        // If data was in the L2 cache already there's no need to wait on the
6938
        // BIU to retrieve data. It can be determined if the hit signal was
6939
        // already active when this state was entered in which case waiting
6940
        // will do no good.
6941
        // The IC machine will stall in this state until the BIU has loaded the
6942
        // L2 cache. 
6943
IC4:
6944 49 robfinch
        if (ihitL2 && picstate==IC3a) begin
6945
                L1_en <= 9'h1FF;
6946 48 robfinch
                L1_wr0 <= TRUE;
6947 49 robfinch
                L1_wr1 <= TRUE && `WAYS > 1;
6948
                L1_wr2 <= TRUE && `WAYS > 2;
6949 48 robfinch
                L1_adr <= L2_adr;
6950
                L2_rdat <= L2_dato;
6951
                icstate <= IC5;
6952
        end
6953
        else if (bstate!=B9)
6954
                ;
6955
        else begin
6956 49 robfinch
                L1_en <= 9'h1FF;
6957 48 robfinch
                L1_wr0 <= TRUE;
6958 49 robfinch
                L1_wr1 <= TRUE && `WAYS > 1;
6959
                L1_wr2 <= TRUE && `WAYS > 2;
6960 48 robfinch
                L1_adr <= L2_adr;
6961
                L2_rdat <= L2_dato;
6962
                icstate <= IC5;
6963
        end
6964
IC5:
6965
        begin
6966 49 robfinch
                L1_en <= 9'h000;
6967 48 robfinch
                L1_wr0 <= FALSE;
6968
                L1_wr1 <= FALSE;
6969 49 robfinch
                L1_wr2 <= FALSE;
6970 48 robfinch
                icstate <= IC6;
6971
        end
6972
IC6:  icstate <= IC7;
6973
IC7:    icstate <= IC8;
6974
IC8:    begin
6975
             icstate <= IDLE;
6976
             icnxt <= TRUE;
6977
        end
6978
default:     icstate <= IDLE;
6979
endcase
6980
 
6981 49 robfinch
if (mem1_available && dram0_load)
6982 48 robfinch
case(dram0)
6983
`DRAMSLOT_AVAIL:        ;
6984
`DRAMSLOT_BUSY:         dram0 <= dram0 + !dram0_unc;
6985
3'd2:                           dram0 <= dram0 + 3'd1;
6986
3'd3:                           dram0 <= dram0 + 3'd1;
6987
3'd4:                           if (dhit0) dram0 <= `DRAMREQ_READY; else dram0 <= `DRAMSLOT_REQBUS;
6988
`DRAMSLOT_REQBUS:       ;
6989
`DRAMSLOT_HASBUS:       ;
6990
`DRAMREQ_READY:         ;
6991
endcase
6992
 
6993 49 robfinch
if (mem2_available && dram1_load && `NUM_MEM > 1)
6994 48 robfinch
case(dram1)
6995
`DRAMSLOT_AVAIL:        ;
6996
`DRAMSLOT_BUSY:         dram1 <= dram1 + !dram1_unc;
6997
3'd2:                           dram1 <= dram1 + 3'd1;
6998
3'd3:                           dram1 <= dram1 + 3'd1;
6999
3'd4:                           if (dhit1) dram1 <= `DRAMREQ_READY; else dram1 <= `DRAMSLOT_REQBUS;
7000
`DRAMSLOT_REQBUS:       ;
7001
`DRAMSLOT_HASBUS:       ;
7002
`DRAMREQ_READY:         ;
7003
endcase
7004
 
7005 49 robfinch
if (mem3_available && dram2_load && `NUM_MEM > 2)
7006 48 robfinch
case(dram2)
7007
`DRAMSLOT_AVAIL:        ;
7008
`DRAMSLOT_BUSY:         dram2 <= dram2 + !dram2_unc;
7009
3'd2:                           dram2 <= dram2 + 3'd1;
7010
3'd3:                           dram2 <= dram2 + 3'd1;
7011
3'd4:                           if (dhit2) dram2 <= `DRAMREQ_READY; else dram2 <= `DRAMSLOT_REQBUS;
7012
`DRAMSLOT_REQBUS:       ;
7013
`DRAMSLOT_HASBUS:       ;
7014
`DRAMREQ_READY:         ;
7015
endcase
7016
 
7017
// Bus Interface Unit (BIU)
7018
// Interfaces to the external bus which is WISHBONE compatible.
7019
// Stores take precedence over other operations.
7020
// Next data cache read misses are serviced.
7021
// Uncached data reads are serviced.
7022
// Finally L2 instruction cache misses are serviced.
7023
 
7024
case(bstate)
7025
BIDLE:
7026 49 robfinch
        begin
7027
                isCAS <= FALSE;
7028
                isAMO <= FALSE;
7029
                isInc <= FALSE;
7030
                isSpt <= FALSE;
7031
                isRMW <= FALSE;
7032
                rdvq <= 1'b0;
7033
                errq <= 1'b0;
7034
                exvq <= 1'b0;
7035
                bwhich <= 2'b00;
7036
                preload <= FALSE;
7037
`ifdef HAS_WB
7038
                if (wb_v[0] & wb_en) begin
7039
                        cyc_o <= `HIGH;
7040
                        stb_o <= `HIGH;
7041
                        we_o <= `HIGH;
7042
                        sel_o <= wb_sel[0];
7043
                        adr_o <= wb_addr[0];
7044
                        dat_o <= wb_data[0];
7045
                        ol_o  <= wb_ol[0];
7046
                        wbo_id <= wb_id[0];
7047
                        bstate <= wb_rmw[0] ? B12 : B1;
7048
                end
7049
                begin
7050
                        for (j = 1; j < `WB_DEPTH; j = j + 1) begin
7051
                wb_v[j-1] <= wb_v[j];
7052
                wb_id[j-1] <= wb_id[j];
7053
                wb_rmw[j-1] <= wb_rmw[j];
7054
                wb_sel[j-1] <= wb_sel[j];
7055
                wb_addr[j-1] <= wb_addr[j];
7056
                wb_data[j-1] <= wb_data[j];
7057
                wb_ol[j-1] <= wb_ol[j];
7058
        end
7059
        wb_v[`WB_DEPTH-1] <= `INV;
7060
        wb_rmw[`WB_DEPTH-1] <= `FALSE;
7061
    end
7062
 
7063
`endif
7064
      if (~|wb_v && mem1_available && dram0==`DRAMSLOT_BUSY && dram0_rmw) begin
7065 48 robfinch
`ifdef SUPPORT_DBG
7066
            if (dbg_smatch0|dbg_lmatch0) begin
7067
                 dramA_v <= `TRUE;
7068
                 dramA_id <= dram0_id;
7069
                 dramA_exc <= `FLT_DBG;
7070
                 dramA_bus <= 64'h0;
7071
                 dram0 <= `DRAMSLOT_AVAIL;
7072
            end
7073
            else
7074
`endif
7075
            begin
7076
                 isRMW <= dram0_rmw;
7077
                 isCAS <= IsCAS(dram0_instr);
7078
                 isAMO <= IsAMO(dram0_instr);
7079
                 isInc <= IsInc(dram0_instr);
7080
                 casid <= dram0_id;
7081
                 bwhich <= 2'b00;
7082 49 robfinch
                 dram0 <= `DRAMSLOT_HASBUS;
7083 48 robfinch
                 cyc_o <= `HIGH;
7084
                 stb_o <= `HIGH;
7085
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7086
                 adr_o <= dram0_addr;
7087
                 dat_o <= fnDato(dram0_instr,dram0_data);
7088
                 ol_o  <= dram0_ol;
7089
                 bstate <= B12;
7090
            end
7091
        end
7092 49 robfinch
        else if (~|wb_v && mem2_available && dram1==`DRAMSLOT_BUSY && dram1_rmw && `NUM_MEM > 1) begin
7093 48 robfinch
`ifdef SUPPORT_DBG
7094
            if (dbg_smatch1|dbg_lmatch1) begin
7095
                 dramB_v <= `TRUE;
7096
                 dramB_id <= dram1_id;
7097
                 dramB_exc <= `FLT_DBG;
7098
                 dramB_bus <= 64'h0;
7099
                 dram1 <= `DRAMSLOT_AVAIL;
7100
            end
7101
            else
7102
`endif
7103
            begin
7104
                 isRMW <= dram1_rmw;
7105
                 isCAS <= IsCAS(dram1_instr);
7106
                 isAMO <= IsAMO(dram1_instr);
7107
                 isInc <= IsInc(dram1_instr);
7108
                 casid <= dram1_id;
7109
                 bwhich <= 2'b01;
7110 49 robfinch
                 dram1 <= `DRAMSLOT_HASBUS;
7111 48 robfinch
                 cyc_o <= `HIGH;
7112
                 stb_o <= `HIGH;
7113
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7114
                 adr_o <= dram1_addr;
7115
                 dat_o <= fnDato(dram1_instr,dram1_data);
7116
                 ol_o  <= dram1_ol;
7117
                 bstate <= B12;
7118
            end
7119
        end
7120 49 robfinch
        else if (~|wb_v && mem3_available && dram2==`DRAMSLOT_BUSY && dram2_rmw && `NUM_MEM > 2) begin
7121 48 robfinch
`ifdef SUPPORT_DBG
7122
            if (dbg_smatch2|dbg_lmatch2) begin
7123
                 dramC_v <= `TRUE;
7124
                 dramC_id <= dram2_id;
7125
                 dramC_exc <= `FLT_DBG;
7126
                 dramC_bus <= 64'h0;
7127
                 dram2 <= `DRAMSLOT_AVAIL;
7128
            end
7129
            else
7130
`endif
7131
            begin
7132
                 isRMW <= dram2_rmw;
7133
                 isCAS <= IsCAS(dram2_instr);
7134
                 isAMO <= IsAMO(dram2_instr);
7135
                 isInc <= IsInc(dram2_instr);
7136
                 casid <= dram2_id;
7137
                 bwhich <= 2'b10;
7138 49 robfinch
                 dram2 <= `DRAMSLOT_HASBUS;
7139 48 robfinch
                 cyc_o <= `HIGH;
7140
                 stb_o <= `HIGH;
7141
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
7142
                 adr_o <= dram2_addr;
7143
                 dat_o <= fnDato(dram2_instr,dram2_data);
7144
                 ol_o  <= dram2_ol;
7145
                 bstate <= B12;
7146
            end
7147
        end
7148 50 robfinch
        else if (mem1_available && dram0==`DRAMSLOT_BUSY && dram0_store) begin
7149 48 robfinch
`ifdef SUPPORT_DBG
7150
            if (dbg_smatch0) begin
7151
                 dramA_v <= `TRUE;
7152
                 dramA_id <= dram0_id;
7153
                 dramA_exc <= `FLT_DBG;
7154
                 dramA_bus <= 64'h0;
7155
                 dram0 <= `DRAMSLOT_AVAIL;
7156
            end
7157
            else
7158
`endif
7159
            begin
7160 49 robfinch
                                                        bwhich <= 2'b00;
7161
`ifndef HAS_WB
7162
                                                        dram0 <= `DRAMSLOT_HASBUS;
7163
                                                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
7164
                 cyc_o <= `HIGH;
7165
                 stb_o <= `HIGH;
7166 48 robfinch
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7167
                 adr_o <= dram0_addr;
7168
                 dat_o <= fnDato(dram0_instr,dram0_data);
7169
                 ol_o  <= dram0_ol;
7170
                 bstate <= B1;
7171 49 robfinch
`else
7172
                                                                if (wbptr<`WB_DEPTH-1) begin
7173
                                                                        dram0 <= `DRAMREQ_READY;
7174
                                                                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
7175
                                                                        wb_update(
7176
                                                                                dram0_id,
7177
                                                                                `FALSE,
7178
                                                                                fnSelect(dram0_instr,dram0_addr),
7179
                                                                                dram0_ol,
7180
                                                                                dram0_addr,
7181
                                                                                fnDato(dram0_instr,dram0_data)
7182
                                                                        );
7183
                                                                        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
7184
                                                                        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
7185
                                                                end
7186
`endif
7187
//                 cr_o <= IsSWC(dram0_instr);
7188 48 robfinch
            end
7189
        end
7190 50 robfinch
        else if (mem2_available && dram1==`DRAMSLOT_BUSY && dram1_store && `NUM_MEM > 1) begin
7191 48 robfinch
`ifdef SUPPORT_DBG
7192
            if (dbg_smatch1) begin
7193
                 dramB_v <= `TRUE;
7194
                 dramB_id <= dram1_id;
7195
                 dramB_exc <= `FLT_DBG;
7196
                 dramB_bus <= 64'h0;
7197
                 dram1 <= `DRAMSLOT_AVAIL;
7198
            end
7199
            else
7200
`endif
7201
            begin
7202 49 robfinch
                 bwhich <= 2'b01;
7203
`ifndef HAS_WB
7204 48 robfinch
                 dram1 <= `DRAMSLOT_HASBUS;
7205
                 dram1_instr[`INSTRUCTION_OP] <= `NOP;
7206 49 robfinch
                 cyc_o <= `HIGH;
7207
                 stb_o <= `HIGH;
7208 48 robfinch
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7209
                 adr_o <= dram1_addr;
7210
                 dat_o <= fnDato(dram1_instr,dram1_data);
7211
                 ol_o  <= dram1_ol;
7212
                 bstate <= B1;
7213 49 robfinch
`else
7214
                                                                if (wbptr<`WB_DEPTH-1) begin
7215
                                                                        dram1 <= `DRAMREQ_READY;
7216
                        dram1_instr[`INSTRUCTION_OP] <= `NOP;
7217
                                                                        wb_update(
7218
                                                                                dram1_id,
7219
                                                                                `FALSE,
7220
                                                                                fnSelect(dram1_instr,dram1_addr),
7221
                                                                                dram1_ol,
7222
                                                                                dram1_addr,
7223
                                                                                fnDato(dram1_instr,dram1_data)
7224
                                                                        );
7225
                                                                        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
7226
                                                                        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
7227
                                                                end
7228
`endif
7229
//                 cr_o <= IsSWC(dram0_instr);
7230 48 robfinch
            end
7231
        end
7232 50 robfinch
        else if (mem3_available && dram2==`DRAMSLOT_BUSY && dram2_store && `NUM_MEM > 2) begin
7233 48 robfinch
`ifdef SUPPORT_DBG
7234
            if (dbg_smatch2) begin
7235
                 dramC_v <= `TRUE;
7236
                 dramC_id <= dram2_id;
7237
                 dramC_exc <= `FLT_DBG;
7238
                 dramC_bus <= 64'h0;
7239
                 dram2 <= `DRAMSLOT_AVAIL;
7240
            end
7241
            else
7242
`endif
7243
            begin
7244 49 robfinch
                 bwhich <= 2'b10;
7245
`ifndef HAS_WB
7246 48 robfinch
                 dram2 <= `DRAMSLOT_HASBUS;
7247
                 dram2_instr[`INSTRUCTION_OP] <= `NOP;
7248 49 robfinch
                 cyc_o <= `HIGH;
7249
                 stb_o <= `HIGH;
7250 48 robfinch
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
7251
                 adr_o <= dram2_addr;
7252
                 dat_o <= fnDato(dram2_instr,dram2_data);
7253
                 ol_o  <= dram2_ol;
7254
                 bstate <= B1;
7255 49 robfinch
`else
7256
                                                                if (wbptr<`WB_DEPTH-1) begin
7257
                                                                        dram2 <= `DRAMREQ_READY;
7258
                        dram2_instr[`INSTRUCTION_OP] <= `NOP;
7259
                                                                        wb_update(
7260
                                                                                dram2_id,
7261
                                                                                `FALSE,
7262
                                                                                fnSelect(dram2_instr,dram2_addr),
7263
                                                                                dram2_ol,
7264
                                                                                dram2_addr,
7265
                                                                                fnDato(dram2_instr,dram2_data)
7266
                                                                        );
7267
                                                                        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
7268
                                                                        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
7269
                                                                end
7270
`endif
7271
//                 cr_o <= IsSWC(dram0_instr);
7272 48 robfinch
            end
7273
        end
7274
        // Check for read misses on the data cache
7275 51 robfinch
        else if (~|wb_v && mem1_available && !dram0_unc && dram0==`DRAMSLOT_REQBUS && dram0_load) begin
7276 48 robfinch
`ifdef SUPPORT_DBG
7277
            if (dbg_lmatch0) begin
7278
                 dramA_v <= `TRUE;
7279
                 dramA_id <= dram0_id;
7280
                 dramA_exc <= `FLT_DBG;
7281
                 dramA_bus <= 64'h0;
7282
                 dram0 <= `DRAMSLOT_AVAIL;
7283
            end
7284
            else
7285
`endif
7286
            begin
7287
                 dram0 <= `DRAMSLOT_HASBUS;
7288
                 bwhich <= 2'b00;
7289
                 preload <= dram0_preload;
7290
                 bstate <= B2;
7291
            end
7292
        end
7293 49 robfinch
        else if (~|wb_v && mem2_available && !dram1_unc && dram1==`DRAMSLOT_REQBUS && dram1_load && `NUM_MEM > 1) begin
7294 48 robfinch
`ifdef SUPPORT_DBG
7295
            if (dbg_lmatch1) begin
7296
                 dramB_v <= `TRUE;
7297
                 dramB_id <= dram1_id;
7298
                 dramB_exc <= `FLT_DBG;
7299
                 dramB_bus <= 64'h0;
7300
                 dram1 <= `DRAMSLOT_AVAIL;
7301
            end
7302
            else
7303
`endif
7304
            begin
7305
                 dram1 <= `DRAMSLOT_HASBUS;
7306
                 bwhich <= 2'b01;
7307
                 preload <= dram1_preload;
7308
                 bstate <= B2;
7309
            end
7310
        end
7311 49 robfinch
        else if (~|wb_v && mem3_available && !dram2_unc && dram2==`DRAMSLOT_REQBUS && dram2_load && `NUM_MEM > 2) begin
7312 48 robfinch
`ifdef SUPPORT_DBG
7313
            if (dbg_lmatch2) begin
7314
                 dramC_v <= `TRUE;
7315
                 dramC_id <= dram2_id;
7316
                 dramC_exc <= `FLT_DBG;
7317
                 dramC_bus <= 64'h0;
7318
                 dram2 <= `DRAMSLOT_AVAIL;
7319
            end
7320
            else
7321
`endif
7322
            begin
7323
                 dram2 <= `DRAMSLOT_HASBUS;
7324
                 preload <= dram2_preload;
7325
                 bwhich <= 2'b10;
7326
                 bstate <= B2;
7327
            end
7328
        end
7329 49 robfinch
        else if (~|wb_v && mem1_available && dram0_unc && dram0==`DRAMSLOT_BUSY && dram0_load) begin
7330 48 robfinch
`ifdef SUPPORT_DBG
7331
            if (dbg_lmatch0) begin
7332
                 dramA_v <= `TRUE;
7333
                 dramA_id <= dram0_id;
7334
                 dramA_exc <= `FLT_DBG;
7335
                 dramA_bus <= 64'h0;
7336
                 dram0 <= `DRAMSLOT_AVAIL;
7337
            end
7338
            else
7339
`endif
7340
            begin
7341
                 bwhich <= 2'b00;
7342
                 cyc_o <= `HIGH;
7343
                 stb_o <= `HIGH;
7344
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7345
                 adr_o <= {dram0_addr[31:3],3'b0};
7346
                 sr_o <=  IsLWR(dram0_instr);
7347
                 ol_o  <= dram0_ol;
7348
                 bstate <= B12;
7349
            end
7350
        end
7351 49 robfinch
        else if (~|wb_v && mem2_available && dram1_unc && dram1==`DRAMSLOT_BUSY && dram1_load && `NUM_MEM > 1) begin
7352 48 robfinch
`ifdef SUPPORT_DBG
7353
            if (dbg_lmatch1) begin
7354
                 dramB_v <= `TRUE;
7355
                 dramB_id <= dram1_id;
7356
                 dramB_exc <= `FLT_DBG;
7357
                 dramB_bus <= 64'h0;
7358
                 dram1 <= `DRAMSLOT_AVAIL;
7359
            end
7360
            else
7361
`endif
7362
            begin
7363
                 bwhich <= 2'b01;
7364
                 cyc_o <= `HIGH;
7365
                 stb_o <= `HIGH;
7366
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7367
                 adr_o <= {dram1_addr[31:3],3'b0};
7368
                 sr_o <=  IsLWR(dram1_instr);
7369
                 ol_o  <= dram1_ol;
7370
                 bstate <= B12;
7371
            end
7372
        end
7373 49 robfinch
        else if (~|wb_v && mem3_available && dram2_unc && dram2==`DRAMSLOT_BUSY && dram2_load && `NUM_MEM > 2) begin
7374 48 robfinch
`ifdef SUPPORT_DBG
7375
            if (dbg_lmatch2) begin
7376
                 dramC_v <= `TRUE;
7377
                 dramC_id <= dram2_id;
7378
                 dramC_exc <= `FLT_DBG;
7379
                 dramC_bus <= 64'h0;
7380
                 dram2 <= 2'd0;
7381
            end
7382
            else
7383
`endif
7384
            begin
7385
                 bwhich <= 2'b10;
7386
                 cyc_o <= `HIGH;
7387
                 stb_o <= `HIGH;
7388
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
7389
                 adr_o <= {dram2_addr[31:3],3'b0};
7390
                 sr_o <=  IsLWR(dram2_instr);
7391
                 ol_o  <= dram2_ol;
7392
                 bstate <= B12;
7393
            end
7394
        end
7395
        // Check for L2 cache miss
7396 49 robfinch
        else if (~|wb_v && !ihitL2) begin
7397 48 robfinch
             cti_o <= 3'b001;
7398 49 robfinch
             bte_o <= 2'b00;//2'b01;    // 4 beat burst wrap
7399 48 robfinch
             cyc_o <= `HIGH;
7400
             stb_o <= `HIGH;
7401
             sel_o <= 8'hFF;
7402
             icl_o <= `HIGH;
7403 49 robfinch
             iccnt <= 3'd0;
7404 48 robfinch
//            adr_o <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
7405
//            L2_adr <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
7406
             adr_o <= {pcr[5:0],L1_adr[31:5],5'h0};
7407
             ol_o  <= ol[0];
7408
             L2_adr <= {pcr[5:0],L1_adr[31:5],5'h0};
7409
             L2_xsel <= 1'b0;
7410
             bstate <= B7;
7411
        end
7412
    end
7413
// Terminal state for a store operation.
7414 49 robfinch
// Note that if only a single memory channel is selected, bwhich will be a
7415
// constant 0. This should cause the extra code to be removed.
7416 48 robfinch
B1:
7417
    if (acki|err_i) begin
7418
         isStore <= `TRUE;
7419
         cyc_o <= `LOW;
7420
         stb_o <= `LOW;
7421
         we_o <= `LOW;
7422
         sel_o <= 8'h00;
7423
         cr_o <= 1'b0;
7424
        // This isn't a good way of doing things; the state should be propagated
7425
        // to the commit stage, however since this is a store we know there will
7426
        // be no change of program flow. So the reservation status bit is set
7427
        // here. The author wanted to avoid the complexity of propagating the
7428
        // input signal to the commit stage. It does mean that the SWC
7429
        // instruction should be surrounded by SYNC's.
7430
        if (cr_o)
7431
             sema[0] <= rbi_i;
7432 49 robfinch
`ifdef HAS_WB
7433
                                for (n = 0; n < QENTRIES; n = n + 1) begin
7434
                                        if (wbo_id[n]) begin
7435
                        iqentry_exc[n] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7436
                        if (err_i|wrv_i) begin
7437
                                iqentry_a1[n] <= adr_o;
7438
                                wb_v <= 8'h00;          // Invalidate write buffer if there is a problem with the store
7439
                                wb_en <= `FALSE;        // and disable write buffer
7440
                        end
7441
                                                iqentry_cmt[n] <= `VAL;
7442
                                                iqentry_aq[n] <= `INV;
7443
                                        end
7444
                                end
7445
`else
7446 48 robfinch
        case(bwhich)
7447 49 robfinch
        2'd0:   if (mem1_available) begin
7448 48 robfinch
                 dram0 <= `DRAMREQ_READY;
7449
                 iqentry_exc[dram0_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7450
                if (err_i|wrv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
7451 49 robfinch
                                                                        iqentry_cmt[ dram0_id[`QBITS] ] <= `VAL;
7452
                                                                        iqentry_aq[ dram0_id[`QBITS] ] <= `INV;
7453 48 robfinch
                        //iqentry_out[ dram0_id[`QBITS] ] <= `INV;
7454
                end
7455 49 robfinch
        2'd1:   if (`NUM_MEM > 1) begin
7456 48 robfinch
                 dram1 <= `DRAMREQ_READY;
7457
                 iqentry_exc[dram1_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7458
                if (err_i|wrv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
7459 49 robfinch
                                                                        iqentry_cmt[ dram1_id[`QBITS] ] <= `VAL;
7460
                                                                        iqentry_aq[ dram1_id[`QBITS] ] <= `INV;
7461 48 robfinch
                        //iqentry_out[ dram1_id[`QBITS] ] <= `INV;
7462
                end
7463 49 robfinch
        2'd2:   if (`NUM_MEM > 2) begin
7464 48 robfinch
                 dram2 <= `DRAMREQ_READY;
7465
                 iqentry_exc[dram2_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7466
                if (err_i|wrv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
7467 49 robfinch
                                                                        iqentry_cmt[ dram2_id[`QBITS] ] <= `VAL;
7468
                                                                        iqentry_aq[ dram2_id[`QBITS] ] <= `INV;
7469 48 robfinch
                        //iqentry_out[ dram2_id[`QBITS] ] <= `INV;
7470
                end
7471
        default:    ;
7472
        endcase
7473 49 robfinch
`endif
7474 48 robfinch
         bstate <= B19;
7475
    end
7476
B2:
7477
    begin
7478
    dccnt <= 2'd0;
7479
    case(bwhich)
7480
    2'd0:   begin
7481
             cti_o <= 3'b001;
7482
             bte_o <= 2'b01;
7483
             cyc_o <= `HIGH;
7484
             stb_o <= `HIGH;
7485
             sel_o <= fnSelect(dram0_instr,dram0_addr);
7486
             adr_o <= {dram0_addr[31:5],5'b0};
7487
             ol_o  <= dram0_ol;
7488
             bstate <= B2d;
7489
            end
7490 49 robfinch
    2'd1:   if (`NUM_MEM > 1) begin
7491 48 robfinch
             cti_o <= 3'b001;
7492
             bte_o <= 2'b01;
7493
             cyc_o <= `HIGH;
7494
             stb_o <= `HIGH;
7495
             sel_o <= fnSelect(dram1_instr,dram1_addr);
7496
             adr_o <= {dram1_addr[31:5],5'b0};
7497
             ol_o  <= dram1_ol;
7498
             bstate <= B2d;
7499
            end
7500 49 robfinch
    2'd2:   if (`NUM_MEM > 2) 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(dram2_instr,dram2_addr);
7506
             adr_o <= {dram2_addr[31:5],5'b0};
7507
             ol_o  <= dram2_ol;
7508
             bstate <= B2d;
7509
            end
7510
    default:    if (~acki)  bstate <= BIDLE;
7511
    endcase
7512
    end
7513
// Data cache load terminal state
7514
B2d:
7515
    if (ack_i|err_i) begin
7516
        errq <= errq | err_i;
7517
        rdvq <= rdvq | rdv_i;
7518
        if (!preload)   // A preload instruction ignores any error
7519
        case(bwhich)
7520
        2'd0:   if (err_i|rdv_i) begin
7521
                     iqentry_a1[dram0_id[`QBITS]] <= adr_o;
7522
                     iqentry_exc[dram0_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
7523
                end
7524 49 robfinch
        2'd1:   if ((err_i|rdv_i) && `NUM_MEM > 1) begin
7525 48 robfinch
                     iqentry_a1[dram1_id[`QBITS]] <= adr_o;
7526
                     iqentry_exc[dram1_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
7527
                end
7528 49 robfinch
        2'd2:   if ((err_i|rdv_i) && `NUM_MEM > 2) begin
7529 48 robfinch
                     iqentry_a1[dram2_id[`QBITS]] <= adr_o;
7530
                     iqentry_exc[dram2_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
7531
                end
7532
        default:    ;
7533
        endcase
7534
        dccnt <= dccnt + 2'd1;
7535
        adr_o[4:3] <= adr_o[4:3] + 2'd1;
7536
        bstate <= B2d;
7537
        if (dccnt==2'd2)
7538
             cti_o <= 3'b111;
7539
        if (dccnt==2'd3) begin
7540
             cti_o <= 3'b000;
7541
             bte_o <= 2'b00;
7542
             cyc_o <= `LOW;
7543
             stb_o <= `LOW;
7544
             sel_o <= 8'h00;
7545
             bstate <= B4;
7546
        end
7547
    end
7548
B3: begin
7549
         stb_o <= `HIGH;
7550
         bstate <= B2d;
7551
    end
7552
B4:  bstate <= B5;
7553
B5:  bstate <= B6;
7554
B6: begin
7555
    case(bwhich)
7556
    2'd0:    dram0 <= `DRAMSLOT_BUSY;  // causes retest of dhit
7557
    2'd1:    dram1 <= `DRAMSLOT_BUSY;
7558
    2'd2:    dram2 <= `DRAMSLOT_BUSY;
7559
    default:    ;
7560
    endcase
7561
    if (~ack_i)  bstate <= BIDLE;
7562
    end
7563
 
7564
// Ack state for instruction cache load
7565
B7:
7566
    if (ack_i|err_i) begin
7567
        errq <= errq | err_i;
7568
        exvq <= exvq | exv_i;
7569 49 robfinch
//        L1_en <= 9'h3 << {L2_xsel,L2_adr[4:3],1'b0};
7570 48 robfinch
//        L1_wr0 <= `TRUE;
7571
//        L1_wr1 <= `TRUE;
7572
//        L1_adr <= L2_adr;
7573
        if (err_i)
7574 49 robfinch
                L2_rdat <= {9{11'b0,4'd7,1'b0,`FLT_IBE,2'b00,`BRK}};
7575 48 robfinch
        else
7576 49 robfinch
                L2_rdat <= {dat_i[31:0],{4{dat_i}}};
7577 48 robfinch
        iccnt <= iccnt + 3'd1;
7578
        //stb_o <= `LOW;
7579
        if (iccnt==3'd3)
7580
            cti_o <= 3'b111;
7581
        if (iccnt==3'd4) begin
7582
            cti_o <= 3'b000;
7583
            bte_o <= 2'b00;             // linear burst
7584
            cyc_o <= `LOW;
7585
            stb_o <= `LOW;
7586
            sel_o <= 8'h00;
7587
            icl_o <= `LOW;
7588
            bstate <= B9;
7589
        end
7590
        else begin
7591
            L2_adr[4:3] <= L2_adr[4:3] + 2'd1;
7592
            if (L2_adr[4:3]==2'b11)
7593
                L2_xsel <= 1'b1;
7594
        end
7595
    end
7596
B9:
7597
        begin
7598
                L1_wr0 <= `FALSE;
7599
                L1_wr1 <= `FALSE;
7600 49 robfinch
                L1_wr2 <= `FALSE;
7601
                L1_en <= 9'h1FF;
7602 48 robfinch
                L2_xsel <= 1'b0;
7603
                if (~ack_i) begin
7604
                        bstate <= BIDLE;
7605
                        L2_nxt <= TRUE;
7606
                end
7607
        end
7608
B12:
7609
    if (ack_i|err_i) begin
7610
        if (isCAS) begin
7611
             iqentry_res        [ casid[`QBITS] ] <= (dat_i == cas);
7612
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
7613
             iqentry_done[ casid[`QBITS] ] <= `VAL;
7614
             iqentry_instr[ casid[`QBITS]] <= `NOP_INSN;
7615
             iqentry_out [ casid[`QBITS] ] <= `INV;
7616
            if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
7617
            if (dat_i == cas) begin
7618
                 stb_o <= `LOW;
7619
                 we_o <= `TRUE;
7620
                 bstate <= B15;
7621
            end
7622
            else begin
7623
                 cas <= dat_i;
7624
                 cyc_o <= `LOW;
7625
                 stb_o <= `LOW;
7626
                 sel_o <= 8'h00;
7627
                case(bwhich)
7628
                2'b00:   dram0 <= `DRAMREQ_READY;
7629
                2'b01:   dram1 <= `DRAMREQ_READY;
7630
                2'b10:   dram2 <= `DRAMREQ_READY;
7631
                default:    ;
7632
                endcase
7633
                 bstate <= B19;
7634
            end
7635
        end
7636
        else if (isRMW) begin
7637
             rmw_instr <= iqentry_instr[casid[`QBITS]];
7638
             rmw_argA <= dat_i;
7639
                 if (isSpt) begin
7640
                        rmw_argB <= 64'd1 << iqentry_a1[casid[`QBITS]][63:58];
7641
                        rmw_argC <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ?
7642
                                                iqentry_a3[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58] :
7643
                                                iqentry_a2[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58];
7644
                 end
7645
                 else if (isInc) begin
7646
                        rmw_argB <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ? {{59{iqentry_instr[casid[`QBITS]][22]}},iqentry_instr[casid[`QBITS]][22:18]} :
7647
                                                                                                                                 {{59{iqentry_instr[casid[`QBITS]][17]}},iqentry_instr[casid[`QBITS]][17:13]};
7648
                 end
7649
                 else begin // isAMO
7650
                     iqentry_res [ casid[`QBITS] ] <= dat_i;
7651
                     rmw_argB <= iqentry_instr[casid[`QBITS]][31] ? {{59{iqentry_instr[casid[`QBITS]][20:16]}},iqentry_instr[casid[`QBITS]][20:16]} : iqentry_a2[casid[`QBITS]];
7652
                 end
7653
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
7654
             if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
7655
             stb_o <= `LOW;
7656
             bstate <= B20;
7657
                end
7658
        else begin
7659
             cyc_o <= `LOW;
7660
             stb_o <= `LOW;
7661
             sel_o <= 8'h00;
7662
             sr_o <= `LOW;
7663
             xdati <= dat_i;
7664
            case(bwhich)
7665
            2'b00:  begin
7666
                     dram0 <= `DRAMREQ_READY;
7667
                     iqentry_exc [ dram0_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
7668
                    if (err_i|rdv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
7669
                    end
7670 49 robfinch
            2'b01:  if (`NUM_MEM > 1) begin
7671 48 robfinch
                     dram1 <= `DRAMREQ_READY;
7672
                     iqentry_exc [ dram1_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
7673
                    if (err_i|rdv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
7674
                    end
7675 49 robfinch
            2'b10:  if (`NUM_MEM > 2) begin
7676 48 robfinch
                     dram2 <= `DRAMREQ_READY;
7677
                     iqentry_exc [ dram2_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
7678
                    if (err_i|rdv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
7679
                    end
7680
            default:    ;
7681
            endcase
7682
             bstate <= B19;
7683
        end
7684
    end
7685
// Three cycles to detemrine if there's a cache hit during a store.
7686
B16:    begin
7687
            case(bwhich)
7688
            2'd0:      if (dhit0) begin  dram0 <= `DRAMREQ_READY; bstate <= B17; end
7689
            2'd1:      if (dhit1) begin  dram1 <= `DRAMREQ_READY; bstate <= B17; end
7690
            2'd2:      if (dhit2) begin  dram2 <= `DRAMREQ_READY; bstate <= B17; end
7691
            default:    bstate <= BIDLE;
7692
            endcase
7693
            end
7694
B17:     bstate <= B18;
7695
B18:     bstate <= B19;
7696
B19:    if (~acki)  begin bstate <= BIDLE; isStore <= `FALSE; end
7697
B20:
7698
        if (~ack_i) begin
7699
                stb_o <= `HIGH;
7700
                we_o  <= `HIGH;
7701
                dat_o <= fnDato(rmw_instr,rmw_res);
7702
                bstate <= B1;
7703
        end
7704
B21:
7705
        if (~ack_i) begin
7706
                stb_o <= `HIGH;
7707
                bstate <= B12;
7708
        end
7709
default:     bstate <= BIDLE;
7710
endcase
7711
 
7712
if (!branchmiss) begin
7713
    case({fetchbuf0_v, fetchbuf1_v})
7714
    2'b00:  ;
7715
    2'b01:
7716
        if (canq1) begin
7717
                tail0 <= idp1(tail0);
7718
                tail1 <= idp1(tail1);
7719
        end
7720
    2'b10:
7721
        if (canq1) begin
7722
            tail0 <= idp1(tail0);
7723
            tail1 <= idp1(tail1);
7724
        end
7725
    2'b11:
7726
        if (canq1) begin
7727
            if (IsBranch(fetchbuf0_instr) && predict_taken0 && fetchbuf0_thrd==fetchbuf1_thrd) begin
7728
                 tail0 <= idp1(tail0);
7729
                 tail1 <= idp1(tail1);
7730
            end
7731
            else begin
7732
                                if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
7733
                        if (canq2) begin
7734
                             tail0 <= idp2(tail0);
7735
                             tail1 <= idp2(tail1);
7736
                        end
7737
                        else begin    // queued1 will be true
7738
                             tail0 <= idp1(tail0);
7739
                             tail1 <= idp1(tail1);
7740
                        end
7741
                end
7742
            end
7743
        end
7744
    endcase
7745
end
7746 52 robfinch
else if (!thread_en) begin      // if branchmiss
7747 48 robfinch
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
7748 52 robfinch
         tail0 <= 4'd0;
7749
         tail1 <= 4'd1;
7750 48 robfinch
    end
7751
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
7752 52 robfinch
         tail0 <= 4'd1;
7753
         tail1 <= 4'd2;
7754 48 robfinch
    end
7755
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
7756 52 robfinch
         tail0 <= 4'd2;
7757
         tail1 <= 4'd3;
7758 48 robfinch
    end
7759
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
7760 52 robfinch
         tail0 <= 4'd3;
7761
         tail1 <= 4'd4;
7762 48 robfinch
    end
7763
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
7764 52 robfinch
         tail0 <= 4'd4;
7765
         tail1 <= 4'd5;
7766 48 robfinch
    end
7767
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
7768 52 robfinch
         tail0 <= 4'd5;
7769
         tail1 <= 4'd6;
7770 48 robfinch
    end
7771
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
7772 52 robfinch
         tail0 <= 4'd6;
7773
         tail1 <= 4'd7;
7774 48 robfinch
    end
7775
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
7776 52 robfinch
         tail0 <= 4'd7;
7777
         tail1 <= 4'd8;
7778 48 robfinch
    end
7779 52 robfinch
    else if (iqentry_stomp[8] & ~iqentry_stomp[7]) begin
7780
         tail0 <= 4'd8;
7781
         tail1 <= 4'd9;
7782
    end
7783
    else if (iqentry_stomp[9] & ~iqentry_stomp[8]) begin
7784
         tail0 <= 4'd9;
7785
         tail1 <= 4'd0;
7786
    end
7787 48 robfinch
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
7788
end
7789 51 robfinch
 
7790 48 robfinch
/*
7791
    if (pebm)
7792
         seq_num <= seq_num + 5'd3;
7793
    else if (queued2)
7794
         seq_num <= seq_num + 5'd2;
7795
    else if (queued1)
7796
         seq_num <= seq_num + 5'd1;
7797
*/
7798
//      #5 rf[0] = 0; rf_v[0] = 1; rf_source[0] = 0;
7799 51 robfinch
`ifdef SIM
7800 48 robfinch
        $display("\n\n\n\n\n\n\n\n");
7801
        $display("TIME %0d", $time);
7802
        $display("%h #", pc0);
7803
`ifdef SUPPORT_SMT
7804
    $display ("Regfile: %d", rgs[0]);
7805
        for (n=0; n < 32; n=n+4) begin
7806
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
7807
               n[4:0]+0, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
7808
               n[4:0]+1, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
7809
               n[4:0]+2, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
7810
               n[4:0]+3, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
7811
               );
7812
        end
7813
    $display ("Regfile: %d", rgs[1]);
7814
        for (n=128; n < 160; n=n+4) begin
7815
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
7816
               n[4:0]+0, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
7817
               n[4:0]+1, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
7818
               n[4:0]+2, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
7819
               n[4:0]+3, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
7820
               );
7821
        end
7822
`else
7823
    $display ("Regfile: %d", rgs);
7824
        for (n=0; n < 32; 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'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
7827
               n[4:0]+1, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
7828
               n[4:0]+2, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
7829
               n[4:0]+3, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
7830
               );
7831
        end
7832
`endif
7833 49 robfinch
`ifdef FCU_ENH
7834 48 robfinch
        $display("Call Stack:");
7835 49 robfinch
        for (n = 0; n < 16; n = n + 4)
7836 48 robfinch
                $display("%c%d: %h   %c%d: %h   %c%d: %h   %c%d: %h",
7837
                        ufb1.ursb1.rasp==n+0 ?">" : " ", n[4:0]+0, ufb1.ursb1.ras[n+0],
7838
                        ufb1.ursb1.rasp==n+1 ?">" : " ", n[4:0]+1, ufb1.ursb1.ras[n+1],
7839
                        ufb1.ursb1.rasp==n+2 ?">" : " ", n[4:0]+2, ufb1.ursb1.ras[n+2],
7840
                        ufb1.ursb1.rasp==n+3 ?">" : " ", n[4:0]+3, ufb1.ursb1.ras[n+3]
7841
                );
7842
        $display("\n");
7843 49 robfinch
`endif
7844 48 robfinch
//    $display("Return address stack:");
7845
//    for (n = 0; n < 16; n = n + 1)
7846
//        $display("%d %h", rasp+n[3:0], ras[rasp+n[3:0]]);
7847
        $display("TakeBr:%d #", take_branch);//, backpc);
7848 51 robfinch
        $display("Insn%d: %h", 0, insn0);
7849
        if (`WAYS > 1)
7850
                $display("Insn%d: %h", 1, insn1);
7851 48 robfinch
        $display("%c%c A: %d %h %h #",
7852
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
7853
        $display("%c%c B: %d %h %h #",
7854
            45, fetchbuf?45:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
7855
        $display("%c%c C: %d %h %h #",
7856
            45, fetchbuf?62:45, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
7857
        $display("%c%c D: %d %h %h #",
7858
            45, fetchbuf?62:45, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
7859
 
7860
        for (i=0; i<QENTRIES; i=i+1)
7861
            $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#",
7862
                 (i[`QBITS]==head0)?"C":".",
7863
                 (i[`QBITS]==tail0)?"Q":".",
7864
                  i[`QBITS],
7865
                 iqentry_v[i] ? "v" : "-",
7866
                 iqentry_iv[i] ? "I" : "-",
7867
                 iqentry_done[i]?"d":"-",
7868
                 iqentry_out[i]?"o":"-",
7869
                 iqentry_bt[i],
7870
                 iqentry_memissue[i],
7871
                 iqentry_agen[i] ? "a": "-",
7872
                 iqentry_alu0_issue[i]?"0":iqentry_alu1_issue[i]?"1":"-",
7873
                 iqentry_stomp[i]?"s":"-",
7874
                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",
7875
                iqentry_instr[i], iqentry_tgt[i][4:0],
7876
                iqentry_exc[i], iqentry_res[i], iqentry_a0[i], iqentry_a1[i], iqentry_a1_v[i],
7877
                iqentry_a1_s[i],
7878
                iqentry_a2[i], iqentry_a2_v[i], iqentry_a2_s[i],
7879
                iqentry_a3[i], iqentry_a3_v[i], iqentry_a3_s[i],
7880
                iqentry_thrd[i],
7881
                iqentry_pc[i],
7882
                iqentry_sn[i], iqentry_ven[i]
7883
                );
7884
    $display("DRAM");
7885
        $display("%d %h %h %c%h %o #",
7886
            dram0, dram0_addr, dram0_data, (IsFlowCtrl(dram0_instr) ? 98 : (IsMem(dram0_instr)) ? 109 : 97),
7887
            dram0_instr, dram0_id);
7888 49 robfinch
          if (`NUM_MEM > 1)
7889 48 robfinch
        $display("%d %h %h %c%h %o #",
7890
            dram1, dram1_addr, dram1_data, (IsFlowCtrl(dram1_instr) ? 98 : (IsMem(dram1_instr)) ? 109 : 97),
7891
            dram1_instr, dram1_id);
7892 49 robfinch
          if (`NUM_MEM > 2)
7893 48 robfinch
        $display("%d %h %h %c%h %o #",
7894
            dram2, dram2_addr, dram2_data, (IsFlowCtrl(dram2_instr) ? 98 : (IsMem(dram2_instr)) ? 109 : 97),
7895
            dram2_instr, dram2_id);
7896
        $display("%d %h %o %h #", dramA_v, dramA_bus, dramA_id, dramA_exc);
7897 49 robfinch
        if (`NUM_MEM > 1)
7898 48 robfinch
        $display("%d %h %o %h #", dramB_v, dramB_bus, dramB_id, dramB_exc);
7899 49 robfinch
        if (`NUM_MEM > 2)
7900 48 robfinch
        $display("%d %h %o %h #", dramC_v, dramC_bus, dramC_id, dramC_exc);
7901
    $display("ALU");
7902
        $display("%d %h %h %h %c%h %d %o %h #",
7903
                alu0_dataready, alu0_argI, alu0_argA, alu0_argB,
7904
                 (IsFlowCtrl(alu0_instr) ? 98 : IsMem(alu0_instr) ? 109 : 97),
7905
                alu0_instr, alu0_bt, alu0_sourceid, alu0_pc);
7906
        $display("%d %h %o 0 #", alu0_v, alu0_bus, alu0_id);
7907 49 robfinch
        if (`NUM_ALU > 1) begin
7908
                $display("%d %h %h %h %c%h %d %o %h #",
7909
                        alu1_dataready, alu1_argI, alu1_argA, alu1_argB,
7910
                        (IsFlowCtrl(alu1_instr) ? 98 : IsMem(alu1_instr) ? 109 : 97),
7911
                        alu1_instr, alu1_bt, alu1_sourceid, alu1_pc);
7912
                $display("%d %h %o 0 #", alu1_v, alu1_bus, alu1_id);
7913
        end
7914 48 robfinch
        $display("FCU");
7915
        $display("%d %h %h %h %h #", fcu_v, fcu_bus, fcu_argI, fcu_argA, fcu_argB);
7916 56 robfinch
        $display("%c %h %h %h %h #", fcu_branchmiss?"m":" ", fcu_sourceid, fcu_misspc, fcu_nextpc, fcu_brdisp);
7917 48 robfinch
    $display("Commit");
7918
        $display("0: %c %h %o %d #", commit0_v?"v":" ", commit0_bus, commit0_id, commit0_tgt[4:0]);
7919
        $display("1: %c %h %o %d #", commit1_v?"v":" ", commit1_bus, commit1_id, commit1_tgt[4:0]);
7920
    $display("instructions committed: %d ticks: %d ", I, tick);
7921 49 robfinch
    $display("Write merges: %d", wb_merges);
7922 51 robfinch
`endif  // SIM
7923 48 robfinch
 
7924
//
7925
//      $display("\n\n\n\n\n\n\n\n");
7926
//      $display("TIME %0d", $time);
7927
//      $display("  pc0=%h", pc0);
7928
//      $display("  pc1=%h", pc1);
7929
//      $display("  reg0=%h, v=%d, src=%o", rf[0], rf_v[0], rf_source[0]);
7930
//      $display("  reg1=%h, v=%d, src=%o", rf[1], rf_v[1], rf_source[1]);
7931
//      $display("  reg2=%h, v=%d, src=%o", rf[2], rf_v[2], rf_source[2]);
7932
//      $display("  reg3=%h, v=%d, src=%o", rf[3], rf_v[3], rf_source[3]);
7933
//      $display("  reg4=%h, v=%d, src=%o", rf[4], rf_v[4], rf_source[4]);
7934
//      $display("  reg5=%h, v=%d, src=%o", rf[5], rf_v[5], rf_source[5]);
7935
//      $display("  reg6=%h, v=%d, src=%o", rf[6], rf_v[6], rf_source[6]);
7936
//      $display("  reg7=%h, v=%d, src=%o", rf[7], rf_v[7], rf_source[7]);
7937
 
7938
//      $display("Fetch Buffers:");
7939
//      $display("  %c%c fbA: v=%d instr=%h pc=%h     %c%c fbC: v=%d instr=%h pc=%h", 
7940
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc,
7941
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
7942
//      $display("  %c%c fbB: v=%d instr=%h pc=%h     %c%c fbD: v=%d instr=%h pc=%h", 
7943
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc,
7944
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
7945
//      $display("  branchback=%d backpc=%h", branchback, backpc);
7946
 
7947
//      $display("Instruction Queue:");
7948
//      for (i=0; i<8; i=i+1) 
7949
//          $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",
7950
//              (i[`QBITS]==head0)?72:32, (i[`QBITS]==tail0)?84:32, i,
7951
//              iqentry_v[i], iqentry_done[i], iqentry_out[i], iqentry_agen[i], iqentry_res[i], iqentry_op[i], 
7952
//              iqentry_bt[i], iqentry_tgt[i], iqentry_a1[i], iqentry_a1_v[i], iqentry_a1_s[i], iqentry_a2[i], iqentry_a2_v[i], 
7953
//              iqentry_a2_s[i], iqentry_a0[i], iqentry_pc[i], iqentry_exc[i]);
7954
 
7955
//      $display("Scheduling Status:");
7956
//      $display("  iqentry0 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
7957
//              iqentry_0_issue, iqentry_0_islot, iqentry_stomp[0], iqentry_source[0], iqentry_memready[0], iqentry_memissue[0]);
7958
//      $display("  iqentry1 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
7959
//              iqentry_1_issue, iqentry_1_islot, iqentry_stomp[1], iqentry_source[1], iqentry_memready[1], iqentry_memissue[1]);
7960
//      $display("  iqentry2 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
7961
//              iqentry_2_issue, iqentry_2_islot, iqentry_stomp[2], iqentry_source[2], iqentry_memready[2], iqentry_memissue[2]);
7962
//      $display("  iqentry3 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
7963
//              iqentry_3_issue, iqentry_3_islot, iqentry_stomp[3], iqentry_source[3], iqentry_memready[3], iqentry_memissue[3]);
7964
//      $display("  iqentry4 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
7965
//              iqentry_4_issue, iqentry_4_islot, iqentry_stomp[4], iqentry_source[4], iqentry_memready[4], iqentry_memissue[4]);
7966
//      $display("  iqentry5 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
7967
//              iqentry_5_issue, iqentry_5_islot, iqentry_stomp[5], iqentry_source[5], iqentry_memready[5], iqentry_memissue[5]);
7968
//      $display("  iqentry6 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
7969
//              iqentry_6_issue, iqentry_6_islot, iqentry_stomp[6], iqentry_source[6], iqentry_memready[6], iqentry_memissue[6]);
7970
//      $display("  iqentry7 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
7971
//              iqentry_7_issue, iqentry_7_islot, iqentry_stomp[7], iqentry_source[7], iqentry_memready[7], iqentry_memissue[7]);
7972
 
7973
//      $display("ALU Inputs:");
7974
//      $display("  0: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
7975
//              alu0_available, alu0_dataready, alu0_sourceid, alu0_op, alu0_argA,
7976
//              alu0_argB, alu0_argI, alu0_bt);
7977
//      $display("  1: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
7978
//              alu1_available, alu1_dataready, alu1_sourceid, alu1_op, alu1_argA,
7979
//              alu1_argB, alu1_argI, alu1_bt);
7980
 
7981
//      $display("ALU Outputs:");
7982
//      $display("  0: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
7983
//              alu0_v, alu0_bus, alu0_id, alu0_branchmiss, alu0_misspc, alu0_sourceid);
7984
//      $display("  1: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
7985
//              alu1_v, alu1_bus, alu1_id, alu1_branchmiss, alu1_misspc, alu1_sourceid);
7986
 
7987
//      $display("DRAM Status:");
7988
//      $display("  OUT: v=%d data=%h tgt=%d id=%o", dram_v, dram_bus, dram_tgt, dram_id);
7989
//      $display("  dram0: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
7990
//          dram0, dram0_addr, dram0_data, dram0_op, dram0_tgt, dram0_id);
7991
//      $display("  dram1: status=%h addr=%h data=%h op=%d tgt=%d id=%o", 
7992
//          dram1, dram1_addr, dram1_data, dram1_op, dram1_tgt, dram1_id);
7993
//      $display("  dram2: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
7994
//          dram2, dram2_addr, dram2_data, dram2_op, dram2_tgt, dram2_id);
7995
 
7996
//      $display("Commit Buses:");
7997
//      $display("  0: v=%d id=%o data=%h", commit0_v, commit0_id, commit0_bus);
7998
//      $display("  1: v=%d id=%o data=%h", commit1_v, commit1_id, commit1_bus);
7999
 
8000
//
8001
//      $display("Memory Contents:");
8002
//      for (j=0; j<64; j=j+16)
8003
//          $display("  %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h", 
8004
//              m[j+0], m[j+1], m[j+2], m[j+3], m[j+4], m[j+5], m[j+6], m[j+7],
8005
//              m[j+8], m[j+9], m[j+10], m[j+11], m[j+12], m[j+13], m[j+14], m[j+15]);
8006
 
8007
        $display("");
8008
 
8009
        if (|panic) begin
8010
            $display("");
8011
            $display("-----------------------------------------------------------------");
8012
            $display("-----------------------------------------------------------------");
8013
            $display("---------------     PANIC:%s     -----------------", message[panic]);
8014
            $display("-----------------------------------------------------------------");
8015
            $display("-----------------------------------------------------------------");
8016
            $display("");
8017
            $display("instructions committed: %d", I);
8018
            $display("total execution cycles: %d", $time / 10);
8019
            $display("");
8020
        end
8021
        if (|panic && ~outstanding_stores) begin
8022
            $finish;
8023
        end
8024
    for (n = 0; n < QENTRIES; n = n + 1)
8025
        if (branchmiss) begin
8026
            if (!setpred[n]) begin
8027
                 iqentry_instr[n][`INSTRUCTION_OP] <= `NOP;
8028
                 iqentry_done[n] <= `VAL;
8029
                 iqentry_cmt[n] <= `VAL;
8030
            end
8031
        end
8032
 
8033
        if (snr) begin
8034
                seq_num <= 32'd0;
8035
                seq_num1 <= 32'd0;
8036
        end
8037
end // clock domain
8038
/*
8039
always @(posedge clk)
8040
if (rst) begin
8041
     tail0 <= 3'd0;
8042
     tail1 <= 3'd1;
8043
end
8044
else begin
8045
if (!branchmiss) begin
8046
    case({fetchbuf0_v, fetchbuf1_v})
8047
    2'b00:  ;
8048
    2'b01:
8049
        if (canq1) begin
8050
             tail0 <= idp1(tail0);
8051
             tail1 <= idp1(tail1);
8052
        end
8053
    2'b10:
8054
        if (canq1) begin
8055
             tail0 <= idp1(tail0);
8056
             tail1 <= idp1(tail1);
8057
        end
8058
    2'b11:
8059
        if (canq1) begin
8060
            if (IsBranch(fetchbuf0_instr) && predict_taken0) begin
8061
                 tail0 <= idp1(tail0);
8062
                 tail1 <= idp1(tail1);
8063
            end
8064
            else begin
8065
                                if (vqe < vl || !IsVector(fetchbuf0_instr)) begin
8066
                        if (canq2) begin
8067
                             tail0 <= idp2(tail0);
8068
                             tail1 <= idp2(tail1);
8069
                        end
8070
                        else begin    // queued1 will be true
8071
                             tail0 <= idp1(tail0);
8072
                             tail1 <= idp1(tail1);
8073
                        end
8074
                end
8075
            end
8076
        end
8077
    endcase
8078
end
8079
else begin      // if branchmiss
8080
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
8081
         tail0 <= 3'd0;
8082
         tail1 <= 3'd1;
8083
    end
8084
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
8085
         tail0 <= 3'd1;
8086
         tail1 <= 3'd2;
8087
    end
8088
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
8089
         tail0 <= 3'd2;
8090
         tail1 <= 3'd3;
8091
    end
8092
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
8093
         tail0 <= 3'd3;
8094
         tail1 <= 3'd4;
8095
    end
8096
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
8097
         tail0 <= 3'd4;
8098
         tail1 <= 3'd5;
8099
    end
8100
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
8101
         tail0 <= 3'd5;
8102
         tail1 <= 3'd6;
8103
    end
8104
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
8105
         tail0 <= 3'd6;
8106
         tail1 <= 3'd7;
8107
    end
8108
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
8109
         tail0 <= 3'd7;
8110
         tail1 <= 3'd0;
8111
    end
8112
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
8113
end
8114
end
8115
*/
8116
/*
8117
always @(posedge clk)
8118
if (rst)
8119
     seq_num <= 5'd0;
8120
else begin
8121
    if (pebm)
8122
         seq_num <= seq_num + 5'd3;
8123
    else if (queued2)
8124
         seq_num <= seq_num + 5'd2;
8125
    else if (queued1)
8126
         seq_num <= seq_num + 5'd1;
8127
end
8128
*/
8129 49 robfinch
 
8130 51 robfinch
// Update the write buffer.
8131 49 robfinch
task wb_update;
8132
input [`QBITS] id;
8133
input rmw;
8134
input [7:0] sel;
8135
input [1:0] ol;
8136
input [`ABITS] addr;
8137
input [63:0] data;
8138
begin
8139 52 robfinch
        if (wbm && wbptr > 1 && wb_addr[wbptr-1][AMSB:3]==addr[AMSB:3]
8140
         && wb_ol[wbptr-1]==ol && wb_rmw[wbptr-1]==rmw && wb_v[wbptr-1]) begin
8141
                // The write buffer is always shifted during the bus IDLE state. That means
8142
                // the data is out of place by a slot. The slot the data is moved from is
8143
                // invalidated.
8144
                wb_v[wbptr-2] <= `INV;
8145
                wb_v[wbptr-1] <= wb_en;
8146
                wb_id[wbptr-1] <= wb_id[wbptr-1] | (16'd1 << id);
8147
                wb_rmw[wbptr-1] <= rmw;
8148
                wb_ol[wbptr-1] <= ol;
8149 49 robfinch
                wb_sel[wbptr-1] <= wb_sel[wbptr-1] | sel;
8150 52 robfinch
                wb_addr[wbptr-1] <= wb_addr[wbptr-1];
8151
                wb_data[wbptr-1] <= wb_data[wbptr-1];
8152 49 robfinch
                if (sel[0]) wb_data[wbptr-1][ 7: 0] <= data[ 7: 0];
8153
                if (sel[1]) wb_data[wbptr-1][15: 8] <= data[15: 8];
8154
                if (sel[2]) wb_data[wbptr-1][23:16] <= data[23:16];
8155
                if (sel[3]) wb_data[wbptr-1][31:24] <= data[31:24];
8156
                if (sel[4]) wb_data[wbptr-1][39:32] <= data[39:32];
8157
                if (sel[5]) wb_data[wbptr-1][47:40] <= data[47:40];
8158
                if (sel[6]) wb_data[wbptr-1][55:48] <= data[55:48];
8159
                if (sel[7]) wb_data[wbptr-1][63:56] <= data[63:56];
8160
                wb_merges <= wb_merges + 32'd1;
8161
        end
8162
        else begin
8163
                wb_v[wbptr] <= wb_en;
8164
                wb_id[wbptr] <= (16'd1 << id);
8165
                wb_rmw[wbptr] <= rmw;
8166
                wb_ol[wbptr] <= ol;
8167
                wb_sel[wbptr] <= sel;
8168
                wb_addr[wbptr] <= {addr[AMSB:3],3'b0};
8169
                wb_data[wbptr] <= data;
8170
        end
8171
end
8172
endtask
8173 52 robfinch
 
8174 48 robfinch
// Increment the head pointers
8175
// Also increments the instruction counter
8176
// Used when instructions are committed.
8177
// Also clear any outstanding state bits that foul things up.
8178
//
8179
task head_inc;
8180
input [`QBITS] amt;
8181
begin
8182 52 robfinch
     head0 <= (head0 + amt) % QENTRIES;
8183
     head1 <= (head1 + amt) % QENTRIES;
8184
     head2 <= (head2 + amt) % QENTRIES;
8185
     head3 <= (head3 + amt) % QENTRIES;
8186
     head4 <= (head4 + amt) % QENTRIES;
8187
     head5 <= (head5 + amt) % QENTRIES;
8188
     head6 <= (head6 + amt) % QENTRIES;
8189
     head7 <= (head7 + amt) % QENTRIES;
8190
     head8 <= (head8 + amt) % QENTRIES;
8191
     head9 <= (head9 + amt) % QENTRIES;
8192 48 robfinch
     I <= I + amt;
8193 49 robfinch
    if (amt==3'd3) begin
8194
        iqentry_agen[head0] <= `INV;
8195
        iqentry_agen[head1] <= `INV;
8196
        iqentry_agen[head2] <= `INV;
8197
        iqentry_mem[head0] <= `FALSE;
8198
        iqentry_mem[head1] <= `FALSE;
8199
        iqentry_mem[head2] <= `FALSE;
8200
        iqentry_iv[head0] <= `INV;
8201
        iqentry_iv[head1] <= `INV;
8202
        iqentry_iv[head2] <= `INV;
8203
        iqentry_alu[head0] <= `FALSE;
8204
        iqentry_alu[head1] <= `FALSE;
8205
        iqentry_alu[head2] <= `FALSE;
8206
        end
8207
    else if (amt==3'd2) begin
8208 48 robfinch
     iqentry_agen[head0] <= `INV;
8209
     iqentry_agen[head1] <= `INV;
8210 49 robfinch
     iqentry_mem[head0] <= `FALSE;
8211
     iqentry_mem[head1] <= `FALSE;
8212
     iqentry_iv[head0] <= `INV;
8213
     iqentry_iv[head1] <= `INV;
8214
        iqentry_alu[head0] <= `FALSE;
8215
     iqentry_alu[head1] <= `FALSE;
8216 48 robfinch
    end else if (amt==3'd1) begin
8217 49 robfinch
            iqentry_agen[head0] <= `INV;
8218
            iqentry_mem[head0] <= `FALSE;
8219
        iqentry_iv[head0] <= `INV;
8220
        iqentry_alu[head0] <= `FALSE;
8221 48 robfinch
        end
8222
end
8223
endtask
8224
 
8225
task setargs;
8226
input [`QBITS] nn;
8227
input [4:0] id;
8228
input v;
8229
input [63:0] bus;
8230
begin
8231
  if (iqentry_a1_v[nn] == `INV && iqentry_a1_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8232
                iqentry_a1[nn] <= bus;
8233
                iqentry_a1_v[nn] <= `VAL;
8234
  end
8235
  if (iqentry_a2_v[nn] == `INV && iqentry_a2_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8236
                iqentry_a2[nn] <= bus;
8237
                iqentry_a2_v[nn] <= `VAL;
8238
  end
8239
  if (iqentry_a3_v[nn] == `INV && iqentry_a3_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8240
                iqentry_a3[nn] <= bus;
8241
                iqentry_a3_v[nn] <= `VAL;
8242
  end
8243
end
8244
endtask
8245
 
8246
task setinsn;
8247
input [`QBITS] nn;
8248
input [4:0] id;
8249
input v;
8250 51 robfinch
input [143:0] bus;
8251 48 robfinch
begin
8252
  if (iqentry_iv[nn] == `INV && iqentry_is[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8253
        iqentry_iv   [nn]  <= `VAL;
8254
//      iqentry_Rt   [nn]  <= bus[`IB_RT];
8255
//      iqentry_Rc   [nn]  <= bus[`IB_RC];
8256
//      iqentry_Ra   [nn]  <= bus[`IB_RA];
8257
        iqentry_a0       [nn]  <= bus[`IB_CONST];
8258
        iqentry_imm  [nn]  <= bus[`IB_IMM];
8259 55 robfinch
//              iqentry_insln[nn]  <= bus[`IB_LN];
8260 56 robfinch
                if (iqentry_insln[nn] != bus[`IB_LN]) begin
8261
                        $display("Insn length mismatch.");
8262
                        $stop;
8263
                end
8264 51 robfinch
                iqentry_jal      [nn]  <= bus[`IB_JAL];
8265
                iqentry_ret  [nn]  <= bus[`IB_RET];
8266
                iqentry_irq  [nn]  <= bus[`IB_IRQ];
8267
                iqentry_brk      [nn]  <= bus[`IB_BRK];
8268
                iqentry_rti  [nn]  <= bus[`IB_RTI];
8269 48 robfinch
                iqentry_bt   [nn]  <= bus[`IB_BT];
8270
                iqentry_alu  [nn]  <= bus[`IB_ALU];
8271
                iqentry_alu0 [nn]  <= bus[`IB_ALU0];
8272
                iqentry_fpu  [nn]  <= bus[`IB_FPU];
8273
                iqentry_fc   [nn]  <= bus[`IB_FC];
8274
                iqentry_canex[nn]  <= bus[`IB_CANEX];
8275 50 robfinch
                iqentry_loadv[nn]  <= bus[`IB_LOADV];
8276 48 robfinch
                iqentry_load [nn]  <= bus[`IB_LOAD];
8277
                iqentry_preload[nn]<= bus[`IB_PRELOAD];
8278 50 robfinch
                iqentry_store[nn]  <= bus[`IB_STORE];
8279
                iqentry_oddball[nn] <= bus[`IB_ODDBALL];
8280
                iqentry_memsz[nn]  <= bus[`IB_MEMSZ];
8281 48 robfinch
                iqentry_mem  [nn]  <= bus[`IB_MEM];
8282
                iqentry_memndx[nn] <= bus[`IB_MEMNDX];
8283
                iqentry_rmw  [nn]  <= bus[`IB_RMW];
8284
                iqentry_memdb[nn]  <= bus[`IB_MEMDB];
8285
                iqentry_memsb[nn]  <= bus[`IB_MEMSB];
8286
                iqentry_shft48[nn] <= bus[`IB_SHFT48];
8287
                iqentry_sei      [nn]    <= bus[`IB_SEI];
8288
                iqentry_aq   [nn]  <= bus[`IB_AQ];
8289
                iqentry_rl   [nn]  <= bus[`IB_RL];
8290
                iqentry_jmp  [nn]  <= bus[`IB_JMP];
8291
                iqentry_br   [nn]  <= bus[`IB_BR];
8292
                iqentry_sync [nn]  <= bus[`IB_SYNC];
8293
                iqentry_fsync[nn]  <= bus[`IB_FSYNC];
8294
        iqentry_rfw  [nn]  <= bus[`IB_RFW];
8295
        iqentry_we   [nn]  <= bus[`IB_WE];
8296 56 robfinch
/*
8297
        if (iqentry_vector[nn]) begin
8298
                        iqentry_tgt[nn][RBIT:6] <= iqentry_Ra[nn][RBIT:6];
8299
                if (iqentry_Ra[nn][RBIT:6]==6'd0)
8300
                        iqentry_tgt[nn][RBIT:6] = 6'd0;
8301
                else begin
8302
                                if (iqentry_vcmprss[nn]) begin
8303
                                        if (vm[iqentry_instr[nn][25:23]][iqentry_Ra[nn][RBIT:6]])
8304
                                                if (qcnt==2'd2 && iqentry_vector[(nn-1)%QENTRIES] && iqentry_Ra[(nn-1)%QENTRIES][RBIT:6] >= 6'd1)
8305
                                                        iqentry_tgt[nn][RBIT:6] <= iqentry_tgt[(nn-2)%QENTRIES][RBIT:6] + 6'd2;
8306
                                                else
8307
                                                        iqentry_tgt[nn][RBIT:6] <= iqentry_tgt[(nn-1)%QENTRIES][RBIT:6] + 6'd1;
8308
                                end
8309
                        end
8310
                end
8311
*/
8312 48 robfinch
  end
8313
end
8314
endtask
8315
 
8316 55 robfinch
task a1_vs;
8317
begin
8318
        // if there is not an overlapping write to the register file.
8319
        if (Ra1s != Rt0s || !fetchbuf0_rfw) begin
8320
                iqentry_a1_v [tail1] <= regIsValid[Ra1s];
8321
                iqentry_a1_s [tail1] <= rf_source [Ra1s];
8322
        end
8323
        else begin
8324
                iqentry_a1_v [tail1] <= `INV;
8325
                iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
8326
        end
8327
end
8328
endtask
8329
 
8330
task a2_vs;
8331
begin
8332
        // if there is not an overlapping write to the register file.
8333
        if (Rb1s != Rt0s || !fetchbuf0_rfw) begin
8334
                iqentry_a2_v [tail1] <= regIsValid[Rb1s];
8335
                iqentry_a2_s [tail1] <= rf_source [Rb1s];
8336
        end
8337
        else begin
8338
                iqentry_a2_v [tail1] <= `INV;
8339
                iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
8340
        end
8341
end
8342
endtask
8343
 
8344
task a3_vs;
8345
begin
8346
        // if there is not an overlapping write to the register file.
8347
        if (Rc1s != Rt0s || !fetchbuf0_rfw) begin
8348
                iqentry_a3_v [tail1] <= regIsValid[Rc1s];
8349
                iqentry_a3_s [tail1] <= rf_source [Rc1s];
8350
        end
8351
        else begin
8352
                iqentry_a3_v [tail1] <= `INV;
8353
                iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
8354
        end
8355
end
8356
endtask
8357
 
8358
task enque0x;
8359
begin
8360
        if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
8361
                vqe0 <= vqe0 + 4'd1;
8362
                if (IsVCmprss(fetchbuf0_instr)) begin
8363
                        if (vm[fetchbuf0_instr[25:23]][vqe0])
8364
                        vqet0 <= vqet0 + 4'd1;
8365
                end
8366
                else
8367
                        vqet0 <= vqet0 + 4'd1;
8368
                if (vqe0 >= vl-2)
8369
                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
8370
                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
8371
                if (fetchbuf0_thrd)
8372
                        seq_num1 <= seq_num1 + 5'd1;
8373
                else
8374
                        seq_num <= seq_num + 5'd1;
8375
                if (fetchbuf0_rfw) begin
8376
                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
8377
                        rf_v[Rt0s] <= `INV;
8378
                end
8379
                if (canq2) begin
8380
                        if (vqe0 < vl-2) begin
8381
                                vqe0 <= vqe0 + 4'd2;
8382
                                if (IsVCmprss(fetchbuf0_instr)) begin
8383
                                        if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
8384
                                                vqet0 <= vqet0 + 4'd2;
8385
                                end
8386
                                else
8387
                                        vqet0 <= vqet0 + 4'd2;
8388
                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num+5'd1, vqe0 + 6'd1);
8389
                                if (fetchbuf0_thrd)
8390
                                        seq_num1 <= seq_num1 + 5'd2;
8391
                                else
8392
                                        seq_num <= seq_num + 5'd2;
8393
                                if (fetchbuf0_rfw) begin
8394
                                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };    // top bit indicates ALU/MEM bus
8395
                                        rf_v[Rt0s] <= `INV;
8396
                                end
8397
                        end
8398
                end
8399
        end
8400
        else begin
8401
                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, 6'd0);
8402
                if (fetchbuf0_thrd)
8403
                        seq_num1 <= seq_num1 + 5'd1;
8404
                else
8405
                        seq_num <= seq_num + 5'd1;
8406
                if (fetchbuf0_rfw) begin
8407
                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
8408
                        rf_v[Rt0s] <= `INV;
8409
                end
8410
        end
8411
end
8412
endtask
8413
 
8414 48 robfinch
// Enqueue fetchbuf0 onto the tail of the instruction queue
8415
task enque0;
8416
input [`QBITS] tail;
8417
input [63:0] seqnum;
8418
input [5:0] venno;
8419
begin
8420
        iqentry_exc[tail] <= `FLT_NONE;
8421
`ifdef SUPPORT_DBG
8422
    if (dbg_imatchA)
8423
        iqentry_exc[tail] <= `FLT_DBG;
8424
    else if (dbg_ctrl[63])
8425
        iqentry_exc[tail] <= `FLT_SSM;
8426
`endif
8427
        iqentry_sn   [tail]    <=  seqnum;
8428
        iqentry_v    [tail]    <=   `VAL;
8429
        iqentry_iv       [tail]    <=   `INV;
8430
        iqentry_is   [tail]    <= tail;
8431
        iqentry_thrd [tail]    <=   fetchbuf0_thrd;
8432
        iqentry_done [tail]    <=    `INV;
8433
        iqentry_cmt  [tail]    <=       `INV;
8434
        iqentry_out  [tail]    <=    `INV;
8435
        iqentry_res  [tail]    <=    `ZERO;
8436
        iqentry_instr[tail]    <=    IsVLS(fetchbuf0_instr) ? (vm[fnM2(fetchbuf0_instr)] ? fetchbuf0_instr : `NOP_INSN) : fetchbuf0_instr;
8437 55 robfinch
        iqentry_insln[tail]              <=  fetchbuf0_insln;
8438 48 robfinch
        iqentry_pt   [tail]    <=  predict_taken0;
8439
        iqentry_agen [tail]    <=    `INV;
8440
        iqentry_state[tail]    <=   IQS_IDLE;
8441
// If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
8442
// inherit the previous pc.
8443
//if (IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15] &&
8444
//   (IsBrk(iqentry_instr[idm1(tail)]) && !iqentry_instr[idm1(tail1)][15] && iqentry_v[idm1(tail)]))
8445
//   iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
8446
//else
8447
         iqentry_pc   [tail] <= fetchbuf0_pc;
8448
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf0_instr);
8449
        iqentry_tgt  [tail]    <=       Rt0;
8450
        iqentry_Ra   [tail]    <= Ra0;
8451
        iqentry_Rb   [tail]    <= Rb0;
8452
        iqentry_Rc   [tail]    <= Rc0;
8453
        iqentry_vl   [tail]    <=  vl;
8454
        iqentry_ven  [tail]    <=   venno;
8455
        iqentry_exc  [tail]    <=    `EXC_NONE;
8456
        iqentry_a1   [tail]    <=    rfoa0;
8457
        iqentry_a1_v [tail]    <=    Source1Valid(fetchbuf0_instr) | regIsValid[Ra0s];
8458
        iqentry_a1_s [tail]    <=    rf_source[Ra0s];
8459
        iqentry_a2   [tail]    <=    rfob0;
8460
        iqentry_a2_v [tail]    <=    Source2Valid(fetchbuf0_instr) | regIsValid[Rb0s];
8461
        iqentry_a2_s [tail]    <=    rf_source[Rb0s];
8462
        iqentry_a3   [tail]    <=    rfoc0;
8463
        iqentry_a3_v [tail]    <=    Source3Valid(fetchbuf0_instr) | regIsValid[Rc0s];
8464
        iqentry_a3_s [tail]    <=    rf_source[Rc0s];
8465
end
8466
endtask
8467
 
8468
// Enque fetchbuf1. Fetchbuf1 might be the second instruction to queue so some
8469
// of this code checks to see which tail it is being queued on.
8470
task enque1;
8471
input [`QBITS] tail;
8472
input [63:0] seqnum;
8473
input [5:0] venno;
8474
begin
8475
 iqentry_exc[tail] <= `FLT_NONE;
8476
`ifdef SUPPORT_DBG
8477
    if (dbg_imatchB)
8478
        iqentry_exc[tail] <= `FLT_DBG;
8479
    else if (dbg_ctrl[63])
8480
        iqentry_exc[tail] <= `FLT_SSM;
8481
`endif
8482
        iqentry_sn   [tail]    <=   seqnum;
8483
        iqentry_v    [tail]    <=   `VAL;
8484
        iqentry_iv       [tail]    <=   `INV;
8485
        iqentry_is   [tail]    <= tail;
8486
        iqentry_thrd [tail]    <=   fetchbuf1_thrd;
8487
        iqentry_done [tail]    <=   `INV;
8488
        iqentry_cmt  [tail]    <=       `INV;
8489
        iqentry_out  [tail]    <=   `INV;
8490
        iqentry_res  [tail]    <=   `ZERO;
8491
        iqentry_instr[tail]    <=   IsVLS(fetchbuf1_instr) ? (vm[fnM2(fetchbuf1_instr)] ? fetchbuf1_instr : `NOP_INSN) : fetchbuf1_instr;
8492 55 robfinch
        iqentry_insln[tail]              <=  fetchbuf1_insln;
8493 48 robfinch
        iqentry_pt   [tail]    <=  predict_taken1;
8494
        iqentry_agen [tail]    <=   `INV;
8495
        iqentry_state[tail]    <=   IQS_IDLE;
8496
// If queing 2nd instruction must read from first
8497
if (tail==tail1) begin
8498
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
8499
    // inherit the previous pc.
8500
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
8501
//        IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15])
8502
//       iqentry_pc   [tail]    <= fetchbuf0_pc;
8503
//    else
8504
                iqentry_pc   [tail] <= fetchbuf1_pc;
8505
end
8506
else begin
8507
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
8508
    // inherit the previous pc.
8509
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
8510
//       (IsBrk(iqentry_instr[idp7(tail)]) && !iqentry_instr[idm1(tail)][15] && iqentry_v[idm1(tail)]))
8511
//       iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
8512
//    else
8513
                iqentry_pc   [tail] <= fetchbuf1_pc;
8514
end
8515
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf1_instr);
8516
        iqentry_tgt  [tail]    <= Rt1;
8517
        iqentry_Ra   [tail]    <= Ra1;
8518
        iqentry_Rb   [tail]    <= Rb1;
8519
        iqentry_Rc   [tail]    <= Rc1;
8520
        iqentry_vl   [tail]    <=  vl;
8521
        iqentry_ven  [tail]    <=   venno;
8522
        iqentry_exc  [tail]    <=   `EXC_NONE;
8523
        iqentry_a1   [tail]    <=       rfoa1;
8524
        iqentry_a1_v [tail]    <=       Source1Valid(fetchbuf1_instr) | regIsValid[Ra1s];
8525
        iqentry_a1_s [tail]    <=       rf_source[Ra1s];
8526
        iqentry_a2   [tail]    <=       rfob1;
8527
        iqentry_a2_v [tail]    <=       Source2Valid(fetchbuf1_instr) | regIsValid[Rb1s];
8528
        iqentry_a2_s [tail]    <=       rf_source[Rb1s];
8529
        iqentry_a3   [tail]    <=       rfoc1;
8530
        iqentry_a3_v [tail]    <=       Source3Valid(fetchbuf1_instr) | regIsValid[Rc1s];
8531
        iqentry_a3_s [tail]    <=       rf_source[Rc1s];
8532
end
8533
endtask
8534
 
8535
// This task takes care of commits for things other than the register file.
8536
task oddball_commit;
8537
input v;
8538
input [`QBITS] head;
8539
reg thread;
8540
begin
8541
    thread = iqentry_thrd[head];
8542
    if (v) begin
8543
        if (|iqentry_exc[head]) begin
8544
            excmiss <= TRUE;
8545
`ifdef SUPPORT_SMT
8546 51 robfinch
                excmisspc <= {tvec[3'd0][31:8],1'b0,ol[thread],5'h00};
8547 48 robfinch
            excthrd <= iqentry_thrd[head];
8548
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
8549
            epc0[thread] <= iqentry_pc[head]+ 32'd4;
8550
            epc1[thread] <= epc0[thread];
8551
            epc2[thread] <= epc1[thread];
8552
            epc3[thread] <= epc2[thread];
8553
            epc4[thread] <= epc3[thread];
8554
            epc5[thread] <= epc4[thread];
8555
            epc6[thread] <= epc5[thread];
8556
            epc7[thread] <= epc6[thread];
8557
            epc8[thread] <= epc7[thread];
8558
            im_stack[thread] <= {im_stack[thread][27:0],im};
8559
            ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
8560
            pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
8561
            rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
8562
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
8563
            mstatus[thread][5:3] <= 3'd0;
8564
            mstatus[thread][13:6] <= 8'h00;
8565
            mstatus[thread][19:14] <= 6'd0;
8566
`else
8567 51 robfinch
                excmisspc <= {tvec[3'd0][31:8],1'b0,ol,5'h00};
8568 48 robfinch
            excthrd <= iqentry_thrd[head];
8569
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
8570
            epc0 <= iqentry_pc[head]+ 32'd4;
8571
            epc1 <= epc0;
8572
            epc2 <= epc1;
8573
            epc3 <= epc2;
8574
            epc4 <= epc3;
8575
            epc5 <= epc4;
8576
            epc6 <= epc5;
8577
            epc7 <= epc6;
8578
            epc8 <= epc7;
8579
            im_stack <= {im_stack[27:0],im};
8580
            ol_stack <= {ol_stack[13:0],ol};
8581
            pl_stack <= {pl_stack[55:0],cpl};
8582
            rs_stack <= {rs_stack[55:0],rgs};
8583
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
8584
            mstatus[5:3] <= 3'd0;
8585
            mstatus[13:6] <= 8'h00;
8586
            mstatus[19:14] <= 6'd0;
8587
`endif
8588 49 robfinch
                                                wb_en <= `TRUE;
8589 48 robfinch
            sema[0] <= 1'b0;
8590
            ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
8591
`ifdef SUPPORT_DBG
8592
            dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
8593
            dbg_ctrl[63] <= FALSE;
8594
`endif
8595
        end
8596
        else
8597
        case(iqentry_instr[head][`INSTRUCTION_OP])
8598
        `BRK:
8599
                        // BRK is treated as a nop unless it's a software interrupt or a
8600
                        // hardware interrupt at a higher priority than the current priority.
8601
                if ((iqentry_instr[head][23:19] > 5'd0) || iqentry_instr[head][18:16] > im) begin
8602
                            excmiss <= TRUE;
8603
`ifdef SUPPORT_SMT
8604 51 robfinch
                        excmisspc <= {tvec[3'd0][31:8],1'b0,ol[thread],5'h00};
8605 48 robfinch
                        excthrd <= iqentry_thrd[head];
8606
                    epc0[thread] <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
8607
                    epc1[thread] <= epc0[thread];
8608
                    epc2[thread] <= epc1[thread];
8609
                    epc3[thread] <= epc2[thread];
8610
                    epc4[thread] <= epc3[thread];
8611
                    epc5[thread] <= epc4[thread];
8612
                    epc6[thread] <= epc5[thread];
8613
                    epc7[thread] <= epc6[thread];
8614
                    epc8[thread] <= epc7[thread];
8615
                    im_stack[thread] <= {im_stack[thread][27:0],im};
8616
                    ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
8617
                    pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
8618
                    rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
8619
                    mstatus[thread][19:14] <= 6'd0;
8620
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
8621
                    mstatus[thread][5:3] <= 3'd0;
8622
                        mstatus[thread][13:6] <= 8'h00;
8623
                    // For hardware interrupts only, set a new mask level
8624
                    // Select register set according to interrupt level
8625
                    if (iqentry_instr[head][23:19]==5'd0) begin
8626
                        mstatus[thread][2:0] <= 3'd7;//iqentry_instr[head][18:16];
8627
                        mstatus[thread][42:40] <= iqentry_instr[head][18:16];
8628
                        mstatus[thread][19:14] <= {3'b0,iqentry_instr[head][18:16]};
8629
                    end
8630
                    else
8631
                        mstatus[thread][19:14] <= 6'd0;
8632
`else
8633 51 robfinch
                        excmisspc <= {tvec[3'd0][31:8],1'b0,ol,5'h00};
8634 48 robfinch
                        excthrd <= iqentry_thrd[head];
8635
                    epc0 <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
8636
                    epc1 <= epc0;
8637
                    epc2 <= epc1;
8638
                    epc3 <= epc2;
8639
                    epc4 <= epc3;
8640
                    epc5 <= epc4;
8641
                    epc6 <= epc5;
8642
                    epc7 <= epc6;
8643
                    epc8 <= epc7;
8644
                    im_stack <= {im_stack[27:0],im};
8645
                    ol_stack <= {ol_stack[13:0],ol};
8646
                    pl_stack <= {pl_stack[55:0],cpl};
8647
                    rs_stack <= {rs_stack[55:0],rgs};
8648
                    mstatus[19:14] <= 6'd0;
8649
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
8650
                    mstatus[5:3] <= 3'd0;
8651
                        mstatus[13:6] <= 8'h00;
8652
                    // For hardware interrupts only, set a new mask level
8653
                    // Select register set according to interrupt level
8654
                    if (iqentry_instr[head][23:19]==5'd0) begin
8655
                        mstatus[2:0] <= 3'd7;//iqentry_instr[head][18:16];
8656
                        mstatus[42:40] <= iqentry_instr[head][18:16];
8657
                        mstatus[19:14] <= {3'b0,iqentry_instr[head][18:16]};
8658
                    end
8659
                    else
8660
                        mstatus[19:14] <= 6'd0;
8661
`endif
8662
                    sema[0] <= 1'b0;
8663
                    ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
8664
`ifdef SUPPORT_DBG
8665
                    dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
8666
                    dbg_ctrl[63] <= FALSE;
8667
`endif
8668
                end
8669
        `IVECTOR:
8670
            casez(iqentry_tgt[head])
8671
            8'b00100xxx:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
8672
            8'b00101111:  vl <= iqentry_res[head];
8673
            default:    ;
8674
            endcase
8675
        `R2:
8676
            case(iqentry_instr[head][`INSTRUCTION_S2])
8677
            `R1:        case(iqentry_instr[head][20:16])
8678
                        `CHAIN_OFF:     cr0[18] <= 1'b0;
8679
                        `CHAIN_ON:      cr0[18] <= 1'b1;
8680
                        //`SETWB:               wbrcd[pcr[5:0]] <= 1'b1;
8681
                        default:        ;
8682
                                endcase
8683
            `VMOV:  casez(iqentry_tgt[head])
8684
                    12'b1111111_00???:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
8685
                    12'b1111111_01111:  vl <= iqentry_res[head];
8686
                    default:    ;
8687
                    endcase
8688
`ifdef SUPPORT_SMT
8689
            `SEI:   mstatus[thread][2:0] <= iqentry_res[head][2:0];   // S1
8690
`else
8691
            `SEI:   mstatus[2:0] <= iqentry_res[head][2:0];   // S1
8692
`endif
8693
            `RTI:   begin
8694
                            excmiss <= TRUE;
8695
`ifdef SUPPORT_SMT
8696
                        excmisspc <= epc0[thread];
8697
                        excthrd <= thread;
8698
                        mstatus[thread][3:0] <= im_stack[thread][3:0];
8699
                        mstatus[thread][5:4] <= ol_stack[thread][1:0];
8700
                        mstatus[thread][13:6] <= pl_stack[thread][7:0];
8701
                        mstatus[thread][19:14] <= rs_stack[thread][5:0];
8702
                        im_stack[thread] <= {4'd15,im_stack[thread][27:4]};
8703
                        ol_stack[thread] <= {2'd0,ol_stack[thread][15:2]};
8704
                        pl_stack[thread] <= {8'h00,pl_stack[thread][63:8]};
8705
                        rs_stack[thread] <= {8'h00,rs_stack[thread][63:8]};
8706
                    epc0[thread] <= epc1[thread];
8707
                    epc1[thread] <= epc2[thread];
8708
                    epc2[thread] <= epc3[thread];
8709
                    epc3[thread] <= epc4[thread];
8710
                    epc4[thread] <= epc5[thread];
8711
                    epc5[thread] <= epc6[thread];
8712
                    epc6[thread] <= epc7[thread];
8713
                    epc7[thread] <= epc8[thread];
8714 51 robfinch
                    epc8[thread] <= {tvec[0][31:8], 1'b0, ol[thread], 5'h0};
8715 48 robfinch
`else
8716
                        excmisspc <= epc0;
8717
                        excthrd <= thread;
8718
                        mstatus[3:0] <= im_stack[3:0];
8719
                        mstatus[5:4] <= ol_stack[1:0];
8720
                        mstatus[13:6] <= pl_stack[7:0];
8721
                        mstatus[19:14] <= rs_stack[5:0];
8722
                        im_stack <= {4'd15,im_stack[31:4]};
8723
                        ol_stack <= {2'd0,ol_stack[15:2]};
8724
                        pl_stack <= {8'h00,pl_stack[63:8]};
8725
                        rs_stack <= {8'h00,rs_stack[63:8]};
8726
                    epc0 <= epc1;
8727
                    epc1 <= epc2;
8728
                    epc2 <= epc3;
8729
                    epc3 <= epc4;
8730
                    epc4 <= epc5;
8731
                    epc5 <= epc6;
8732
                    epc6 <= epc7;
8733
                    epc7 <= epc8;
8734 51 robfinch
                    epc8 <= {tvec[0][31:8], 1'b0, ol, 5'h0};
8735 48 robfinch
`endif
8736
                    sema[0] <= 1'b0;
8737
                    sema[iqentry_res[head][5:0]] <= 1'b0;
8738
                    vqe0  <= ve_hold[ 5: 0];
8739
                    vqet0 <= ve_hold[21:16];
8740
                    vqe1  <= ve_hold[37:32];
8741
                    vqet1 <= ve_hold[53:48];
8742
`ifdef SUPPORT_DBG
8743
                    dbg_ctrl[62:55] <= {FALSE,dbg_ctrl[62:56]};
8744
                    dbg_ctrl[63] <= dbg_ctrl[55];
8745
`endif
8746
                    end
8747 49 robfinch
            default: ;
8748
            endcase
8749
        `MEMNDX:
8750
            case(iqentry_instr[head][`INSTRUCTION_S2])
8751 48 robfinch
            `CACHEX:
8752 49 robfinch
                    case(iqentry_instr[head][22:18])
8753 48 robfinch
                    5'h03:  invic <= TRUE;
8754
                    5'h10:  cr0[30] <= FALSE;
8755
                    5'h11:  cr0[30] <= TRUE;
8756
                    default:    ;
8757
                    endcase
8758
            default: ;
8759
            endcase
8760
        `CSRRW:
8761
                        begin
8762 51 robfinch
                        write_csr(iqentry_instr[head][31:18],iqentry_a1[head],thread);
8763 48 robfinch
                        end
8764
        `REX:
8765
`ifdef SUPPORT_SMT
8766
            // Can only redirect to a lower level
8767
            if (ol[thread] < iqentry_instr[head][13:11]) begin
8768
                mstatus[thread][5:3] <= iqentry_instr[head][13:11];
8769
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol[thread]}];
8770
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol[thread]}];
8771
                mstatus[thread][13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
8772
            end
8773
`else
8774
            if (ol < iqentry_instr[head][13:11]) begin
8775
                mstatus[5:3] <= iqentry_instr[head][13:11];
8776
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol}];
8777
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol}];
8778
                mstatus[13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
8779
            end
8780
`endif
8781
        `CACHE:
8782 49 robfinch
            case(iqentry_instr[head][17:13])
8783 48 robfinch
            5'h03:  invic <= TRUE;
8784
            5'h10:  cr0[30] <= FALSE;
8785
            5'h11:  cr0[30] <= TRUE;
8786
            default:    ;
8787
            endcase
8788
        `FLOAT:
8789
            case(iqentry_instr[head][`INSTRUCTION_S2])
8790 49 robfinch
            `FRM: begin
8791 51 robfinch
                                fp_rm <= iqentry_res[head][2:0];
8792 49 robfinch
                                end
8793 48 robfinch
            `FCX:
8794
                begin
8795 51 robfinch
                    fp_sx <= fp_sx & ~iqentry_res[head][5];
8796
                    fp_inex <= fp_inex & ~iqentry_res[head][4];
8797
                    fp_dbzx <= fp_dbzx & ~(iqentry_res[head][3]|iqentry_res[head][0]);
8798
                    fp_underx <= fp_underx & ~iqentry_res[head][2];
8799
                    fp_overx <= fp_overx & ~iqentry_res[head][1];
8800
                    fp_giopx <= fp_giopx & ~iqentry_res[head][0];
8801
                    fp_infdivx <= fp_infdivx & ~iqentry_res[head][0];
8802
                    fp_zerozerox <= fp_zerozerox & ~iqentry_res[head][0];
8803
                    fp_subinfx   <= fp_subinfx   & ~iqentry_res[head][0];
8804
                    fp_infzerox  <= fp_infzerox  & ~iqentry_res[head][0];
8805
                    fp_NaNCmpx   <= fp_NaNCmpx   & ~iqentry_res[head][0];
8806
                    fp_swtx <= 1'b0;
8807 48 robfinch
                end
8808
            `FDX:
8809
                begin
8810 51 robfinch
                    fp_inexe <= fp_inexe     & ~iqentry_res[head][4];
8811
                    fp_dbzxe <= fp_dbzxe     & ~iqentry_res[head][3];
8812
                    fp_underxe <= fp_underxe & ~iqentry_res[head][2];
8813
                    fp_overxe <= fp_overxe   & ~iqentry_res[head][1];
8814
                    fp_invopxe <= fp_invopxe & ~iqentry_res[head][0];
8815 48 robfinch
                end
8816
            `FEX:
8817
                begin
8818 51 robfinch
                    fp_inexe <= fp_inexe     | iqentry_res[head][4];
8819
                    fp_dbzxe <= fp_dbzxe     | iqentry_res[head][3];
8820
                    fp_underxe <= fp_underxe | iqentry_res[head][2];
8821
                    fp_overxe <= fp_overxe   | iqentry_res[head][1];
8822
                    fp_invopxe <= fp_invopxe | iqentry_res[head][0];
8823 48 robfinch
                end
8824
            default:
8825
                begin
8826
                    // 31 to 29 is rounding mode
8827
                    // 28 to 24 are exception enables
8828
                    // 23 is nsfp
8829
                    // 22 is a fractie
8830 51 robfinch
                    fp_fractie <= iqentry_a0[head][22];
8831
                    fp_raz <= iqentry_a0[head][21];
8832 48 robfinch
                    // 20 is a 0
8833 51 robfinch
                    fp_neg <= iqentry_a0[head][19];
8834
                    fp_pos <= iqentry_a0[head][18];
8835
                    fp_zero <= iqentry_a0[head][17];
8836
                    fp_inf <= iqentry_a0[head][16];
8837 48 robfinch
                    // 15 swtx
8838
                    // 14 
8839 51 robfinch
                    fp_inex <= fp_inex | (fp_inexe & iqentry_a0[head][14]);
8840
                    fp_dbzx <= fp_dbzx | (fp_dbzxe & iqentry_a0[head][13]);
8841
                    fp_underx <= fp_underx | (fp_underxe & iqentry_a0[head][12]);
8842
                    fp_overx <= fp_overx | (fp_overxe & iqentry_a0[head][11]);
8843 48 robfinch
                    //fp_giopx <= fp_giopx | (fp_giopxe & iqentry_res2[head][10]);
8844
                    //fp_invopx <= fp_invopx | (fp_invopxe & iqentry_res2[head][24]);
8845
                    //
8846 51 robfinch
                    fp_cvtx <= fp_cvtx |  (fp_giopxe & iqentry_a0[head][7]);
8847
                    fp_sqrtx <= fp_sqrtx |  (fp_giopxe & iqentry_a0[head][6]);
8848
                    fp_NaNCmpx <= fp_NaNCmpx |  (fp_giopxe & iqentry_a0[head][5]);
8849
                    fp_infzerox <= fp_infzerox |  (fp_giopxe & iqentry_a0[head][4]);
8850
                    fp_zerozerox <= fp_zerozerox |  (fp_giopxe & iqentry_a0[head][3]);
8851
                    fp_infdivx <= fp_infdivx | (fp_giopxe & iqentry_a0[head][2]);
8852
                    fp_subinfx <= fp_subinfx | (fp_giopxe & iqentry_a0[head][1]);
8853
                    fp_snanx <= fp_snanx | (fp_giopxe & iqentry_a0[head][0]);
8854 48 robfinch
 
8855
                end
8856
            endcase
8857
        default:    ;
8858
        endcase
8859
        // Once the flow control instruction commits, NOP it out to allow
8860
        // pending stores to be issued.
8861
        iqentry_instr[head][5:0] <= `NOP;
8862
    end
8863
end
8864
endtask
8865
 
8866
// CSR access tasks
8867
task read_csr;
8868 51 robfinch
input [11:0] csrno;
8869 48 robfinch
output [63:0] dat;
8870
input thread;
8871
begin
8872
`ifdef SUPPORT_SMT
8873
    if (csrno[11:10] >= ol[thread])
8874
`else
8875
    if (csrno[11:10] >= ol)
8876
`endif
8877
    casez(csrno[9:0])
8878
    `CSR_CR0:       dat <= cr0;
8879
    `CSR_HARTID:    dat <= hartid;
8880
    `CSR_TICK:      dat <= tick;
8881
    `CSR_PCR:       dat <= pcr;
8882
    `CSR_PCR2:      dat <= pcr2;
8883 49 robfinch
    `CSR_PMR:                           dat <= pmr;
8884 48 robfinch
    `CSR_WBRCD:         dat <= wbrcd;
8885
    `CSR_SEMA:      dat <= sema;
8886
    `CSR_SBL:       dat <= sbl;
8887
    `CSR_SBU:       dat <= sbu;
8888
    `CSR_TCB:           dat <= tcb;
8889 51 robfinch
    `CSR_FSTAT:     dat <= {fp_rgs,fp_status};
8890 48 robfinch
`ifdef SUPPORT_DBG
8891
    `CSR_DBAD0:     dat <= dbg_adr0;
8892
    `CSR_DBAD1:     dat <= dbg_adr1;
8893
    `CSR_DBAD2:     dat <= dbg_adr2;
8894
    `CSR_DBAD3:     dat <= dbg_adr3;
8895
    `CSR_DBCTRL:    dat <= dbg_ctrl;
8896
    `CSR_DBSTAT:    dat <= dbg_stat;
8897
`endif
8898
    `CSR_CAS:       dat <= cas;
8899
    `CSR_TVEC:      dat <= tvec[csrno[2:0]];
8900 52 robfinch
    `CSR_BADADR:    dat <= badaddr[{thread,csrno[11:10]}];
8901
    `CSR_CAUSE:     dat <= {48'd0,cause[{thread,csrno[11:10]}]};
8902 48 robfinch
`ifdef SUPPORT_SMT
8903
    `CSR_IM_STACK:      dat <= im_stack[thread];
8904
    `CSR_OL_STACK:      dat <= ol_stack[thread];
8905
    `CSR_PL_STACK:      dat <= pl_stack[thread];
8906
    `CSR_RS_STACK:      dat <= rs_stack[thread];
8907
    `CSR_STATUS:    dat <= mstatus[thread][63:0];
8908
    `CSR_EPC0:      dat <= epc0[thread];
8909
    `CSR_EPC1:      dat <= epc1[thread];
8910
    `CSR_EPC2:      dat <= epc2[thread];
8911
    `CSR_EPC3:      dat <= epc3[thread];
8912
    `CSR_EPC4:      dat <= epc4[thread];
8913
    `CSR_EPC5:      dat <= epc5[thread];
8914
    `CSR_EPC6:      dat <= epc6[thread];
8915
    `CSR_EPC7:      dat <= epc7[thread];
8916
`else
8917
    `CSR_IM_STACK:      dat <= im_stack;
8918
    `CSR_OL_STACK:      dat <= ol_stack;
8919
    `CSR_PL_STACK:      dat <= pl_stack;
8920
    `CSR_RS_STACK:      dat <= rs_stack;
8921
    `CSR_STATUS:    dat <= mstatus[63:0];
8922
    `CSR_EPC0:      dat <= epc0;
8923
    `CSR_EPC1:      dat <= epc1;
8924
    `CSR_EPC2:      dat <= epc2;
8925
    `CSR_EPC3:      dat <= epc3;
8926
    `CSR_EPC4:      dat <= epc4;
8927
    `CSR_EPC5:      dat <= epc5;
8928
    `CSR_EPC6:      dat <= epc6;
8929
    `CSR_EPC7:      dat <= epc7;
8930
`endif
8931
    `CSR_CODEBUF:   dat <= codebuf[csrno[5:0]];
8932
    `CSR_TIME:          dat <= wc_times;
8933
    `CSR_INFO:
8934
                    case(csrno[3:0])
8935
                    4'd0:   dat <= "Finitron";  // manufacturer
8936
                    4'd1:   dat <= "        ";
8937
                    4'd2:   dat <= "64 bit  ";  // CPU class
8938
                    4'd3:   dat <= "        ";
8939
                    4'd4:   dat <= "FT64    ";  // Name
8940
                    4'd5:   dat <= "        ";
8941
                    4'd6:   dat <= 64'd1;       // model #
8942
                    4'd7:   dat <= 64'd1;       // serial number
8943
                    4'd8:   dat <= {32'd16384,32'd16384};   // cache sizes instruction,data
8944
                    4'd9:   dat <= 64'd0;
8945
                    default:    dat <= 64'd0;
8946
                    endcase
8947
    default:    begin
8948
                        $display("Unsupported CSR:%h",csrno[10:0]);
8949
                        dat <= 64'hEEEEEEEEEEEEEEEE;
8950
                        end
8951
    endcase
8952
    else
8953
        dat <= 64'h0;
8954
end
8955
endtask
8956
 
8957
task write_csr;
8958
input [13:0] csrno;
8959
input [63:0] dat;
8960
input thread;
8961
begin
8962
`ifdef SUPPORT_SMT
8963
    if (csrno[11:10] >= ol[thread])
8964
`else
8965
    if (csrno[11:10] >= ol)
8966
`endif
8967
    case(csrno[13:12])
8968
    2'd1:   // CSRRW
8969
        casez(csrno[9:0])
8970
        `CSR_CR0:       cr0 <= dat;
8971
        `CSR_PCR:       pcr <= dat[31:0];
8972
        `CSR_PCR2:      pcr2 <= dat;
8973 49 robfinch
        `CSR_PMR:       case(`NUM_IDU)
8974
                                                0,1:     pmr[0] <= 1'b1;
8975
                                                2:
8976
                                                        begin
8977
                                                                        if (dat[1:0]==2'b00)
8978
                                                                                pmr[1:0] <= 2'b01;
8979
                                                                        else
8980
                                                                                pmr[1:0] <= dat[1:0];
8981
                                                                        pmr[63:2] <= dat[63:2];
8982
                                                                end
8983
                                                3:
8984
                                                        begin
8985
                                                                        if (dat[2:0]==3'b000)
8986
                                                                                pmr[2:0] <= 3'b001;
8987
                                                                        else
8988
                                                                                pmr[2:0] <= dat[2:0];
8989
                                                                        pmr[63:3] <= dat[63:3];
8990
                                                                end
8991
                                                default:        pmr[0] <= 1'b1;
8992
                                                endcase
8993 48 robfinch
        `CSR_WBRCD:             wbrcd <= dat;
8994
        `CSR_SEMA:      sema <= dat;
8995
        `CSR_SBL:       sbl <= dat[31:0];
8996
        `CSR_SBU:       sbu <= dat[31:0];
8997
        `CSR_TCB:               tcb <= dat;
8998 51 robfinch
        `CSR_FSTAT:             fpu_csr[37:32] <= dat[37:32];
8999 52 robfinch
        `CSR_BADADR:    badaddr[{thread,csrno[11:10]}] <= dat;
9000
        `CSR_CAUSE:     cause[{thread,csrno[11:10]}] <= dat[15:0];
9001 48 robfinch
`ifdef SUPPORT_DBG
9002
        `CSR_DBAD0:     dbg_adr0 <= dat[AMSB:0];
9003
        `CSR_DBAD1:     dbg_adr1 <= dat[AMSB:0];
9004
        `CSR_DBAD2:     dbg_adr2 <= dat[AMSB:0];
9005
        `CSR_DBAD3:     dbg_adr3 <= dat[AMSB:0];
9006
        `CSR_DBCTRL:    dbg_ctrl <= dat;
9007
`endif
9008
        `CSR_CAS:       cas <= dat;
9009
        `CSR_TVEC:      tvec[csrno[2:0]] <= dat[31:0];
9010
`ifdef SUPPORT_SMT
9011
        `CSR_IM_STACK:  im_stack[thread] <= dat[31:0];
9012
        `CSR_OL_STACK:  ol_stack[thread] <= dat[15:0];
9013
        `CSR_PL_STACK:  pl_stack[thread] <= dat;
9014
        `CSR_RS_STACK:  rs_stack[thread] <= dat;
9015
        `CSR_STATUS:    mstatus[thread][63:0] <= dat;
9016
        `CSR_EPC0:      epc0[thread] <= dat;
9017
        `CSR_EPC1:      epc1[thread] <= dat;
9018
        `CSR_EPC2:      epc2[thread] <= dat;
9019
        `CSR_EPC3:      epc3[thread] <= dat;
9020
        `CSR_EPC4:      epc4[thread] <= dat;
9021
        `CSR_EPC5:      epc5[thread] <= dat;
9022
        `CSR_EPC6:      epc6[thread] <= dat;
9023
        `CSR_EPC7:      epc7[thread] <= dat;
9024
`else
9025
        `CSR_IM_STACK:  im_stack <= dat[31:0];
9026
        `CSR_OL_STACK:  ol_stack <= dat[15:0];
9027
        `CSR_PL_STACK:  pl_stack <= dat;
9028
        `CSR_RS_STACK:  rs_stack <= dat;
9029
        `CSR_STATUS:    mstatus[63:0] <= dat;
9030
        `CSR_EPC0:      epc0 <= dat;
9031
        `CSR_EPC1:      epc1 <= dat;
9032
        `CSR_EPC2:      epc2 <= dat;
9033
        `CSR_EPC3:      epc3 <= dat;
9034
        `CSR_EPC4:      epc4 <= dat;
9035
        `CSR_EPC5:      epc5 <= dat;
9036
        `CSR_EPC6:      epc6 <= dat;
9037
        `CSR_EPC7:      epc7 <= dat;
9038
`endif
9039
                `CSR_TIME:              begin
9040
                                                ld_time <= 6'h3f;
9041
                                                wc_time_dat <= dat;
9042
                                                end
9043
        `CSR_CODEBUF:   codebuf[csrno[5:0]] <= dat;
9044
        default:    ;
9045
        endcase
9046
    2'd2:   // CSRRS
9047
        case(csrno[9:0])
9048
        `CSR_CR0:       cr0 <= cr0 | dat;
9049
        `CSR_PCR:       pcr[31:0] <= pcr[31:0] | dat[31:0];
9050
        `CSR_PCR2:      pcr2 <= pcr2 | dat;
9051 49 robfinch
        `CSR_PMR:                               pmr <= pmr | dat;
9052 48 robfinch
        `CSR_WBRCD:             wbrcd <= wbrcd | dat;
9053
`ifdef SUPPORT_DBG
9054
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl | dat;
9055
`endif
9056
        `CSR_SEMA:      sema <= sema | dat;
9057
`ifdef SUPPORT_SMT
9058
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] | dat;
9059
`else
9060
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] | dat;
9061
`endif
9062
        default:    ;
9063
        endcase
9064
    2'd3:   // CSRRC
9065
        case(csrno[9:0])
9066
        `CSR_CR0:       cr0 <= cr0 & ~dat;
9067
        `CSR_PCR:       pcr <= pcr & ~dat;
9068
        `CSR_PCR2:      pcr2 <= pcr2 & ~dat;
9069 49 robfinch
        `CSR_PMR:                       begin
9070
                                                                if (dat[1:0]==2'b11)
9071
                                                                        pmr[1:0] <= 2'b01;
9072
                                                                else
9073
                                                                        pmr[1:0] <= pmr[1:0] & ~dat[1:0];
9074
                                                                pmr[63:2] <= pmr[63:2] & ~dat[63:2];
9075
                                                                end
9076 48 robfinch
        `CSR_WBRCD:             wbrcd <= wbrcd & ~dat;
9077
`ifdef SUPPORT_DBG
9078
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl & ~dat;
9079
`endif
9080
        `CSR_SEMA:      sema <= sema & ~dat;
9081
`ifdef SUPPORT_SMT
9082
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] & ~dat;
9083
`else
9084
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] & ~dat;
9085
`endif
9086
        default:    ;
9087
        endcase
9088
    default:    ;
9089
    endcase
9090
end
9091
endtask
9092
 
9093
 
9094
endmodule
9095
 
9096
 
9097
module decoder5 (num, out);
9098
input [4:0] num;
9099
output [31:1] out;
9100
reg [31:1] out;
9101
 
9102
always @(num)
9103
case (num)
9104
    5'd0 :      out <= 31'b0000000000000000000000000000000;
9105
    5'd1 :      out <= 31'b0000000000000000000000000000001;
9106
    5'd2 :      out <= 31'b0000000000000000000000000000010;
9107
    5'd3 :      out <= 31'b0000000000000000000000000000100;
9108
    5'd4 :      out <= 31'b0000000000000000000000000001000;
9109
    5'd5 :      out <= 31'b0000000000000000000000000010000;
9110
    5'd6 :      out <= 31'b0000000000000000000000000100000;
9111
    5'd7 :      out <= 31'b0000000000000000000000001000000;
9112
    5'd8 :      out <= 31'b0000000000000000000000010000000;
9113
    5'd9 :      out <= 31'b0000000000000000000000100000000;
9114
    5'd10:      out <= 31'b0000000000000000000001000000000;
9115
    5'd11:      out <= 31'b0000000000000000000010000000000;
9116
    5'd12:      out <= 31'b0000000000000000000100000000000;
9117
    5'd13:      out <= 31'b0000000000000000001000000000000;
9118
    5'd14:      out <= 31'b0000000000000000010000000000000;
9119
    5'd15:      out <= 31'b0000000000000000100000000000000;
9120
    5'd16:      out <= 31'b0000000000000001000000000000000;
9121
    5'd17:      out <= 31'b0000000000000010000000000000000;
9122
    5'd18:      out <= 31'b0000000000000100000000000000000;
9123
    5'd19:      out <= 31'b0000000000001000000000000000000;
9124
    5'd20:      out <= 31'b0000000000010000000000000000000;
9125
    5'd21:      out <= 31'b0000000000100000000000000000000;
9126
    5'd22:      out <= 31'b0000000001000000000000000000000;
9127
    5'd23:      out <= 31'b0000000010000000000000000000000;
9128
    5'd24:      out <= 31'b0000000100000000000000000000000;
9129
    5'd25:      out <= 31'b0000001000000000000000000000000;
9130
    5'd26:      out <= 31'b0000010000000000000000000000000;
9131
    5'd27:      out <= 31'b0000100000000000000000000000000;
9132
    5'd28:      out <= 31'b0001000000000000000000000000000;
9133
    5'd29:      out <= 31'b0010000000000000000000000000000;
9134
    5'd30:      out <= 31'b0100000000000000000000000000000;
9135
    5'd31:      out <= 31'b1000000000000000000000000000000;
9136
endcase
9137
 
9138
endmodule
9139
 
9140
module decoder6 (num, out);
9141
input [5:0] num;
9142
output [63:1] out;
9143
 
9144
wire [63:0] out1;
9145
 
9146
assign out1 = 64'd1 << num;
9147
assign out = out1[63:1];
9148
 
9149
endmodule
9150
 
9151
module decoder7 (num, out);
9152
input [6:0] num;
9153
output [127:1] out;
9154
 
9155
wire [127:0] out1;
9156
 
9157
assign out1 = 128'd1 << num;
9158
assign out = out1[127:1];
9159
 
9160
endmodule
9161
 
9162
module decoder8 (num, out);
9163
input [7:0] num;
9164
output [255:1] out;
9165
 
9166
wire [255:0] out1;
9167
 
9168
assign out1 = 256'd1 << num;
9169
assign out = out1[255:1];
9170
 
9171
endmodule
9172
 

powered by: WebSVN 2.1.0

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