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

Subversion Repositories thor

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

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

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2017-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      FT64.v
9
//      Features include:
10
//  - 16/32/48 bit instructions
11
//  - vector instruction set,
12
//  - SIMD instructions
13
//  - data width of 64 bits
14
//      - 32 general purpose registers
15
//  - 32 floating point registers
16
//      - 32 vector registers, length 63
17
//  - powerful branch prediction
18
//  - branch target buffer (BTB)
19
//  - return address predictor (RSB)
20
//  - bus interface unit
21
//  - instruction and data caches
22
//  - asynchronous logic loops for issue and branch miss
23
//    re-written for synchronous operation, not as elegant
24
//    but required for operation in an FPGA
25
//      - fine-grained simultaneous multi-threading (SMT)
26
//
27
// This source file is free software: you can redistribute it and/or modify 
28
// it under the terms of the GNU Lesser General Public License as published 
29
// by the Free Software Foundation, either version 3 of the License, or     
30
// (at your option) any later version.                                      
31
//                                                                          
32
// This source file is distributed in the hope that it will be useful,      
33
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
34
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
35
// GNU General Public License for more details.                             
36
//                                                                          
37
// You should have received a copy of the GNU General Public License        
38
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
39
//
40
// Approx. 100,000 LUTs. 160,000 LC's.
41 50 robfinch
// 38,000LUTs???
42 48 robfinch
// ============================================================================
43
//
44 49 robfinch
`include "FT64_config.vh"
45 48 robfinch
`include "FT64_defines.vh"
46
 
47
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,
48
    ol_o, pcr_o, pcr2_o, exv_i, rdv_i, wrv_i, icl_o, sr_o, cr_o, rbi_i, signal_i);
49
input [63:0] hartid;
50
input rst;
51
input clk_i;
52
input clk4x;
53
input tm_clk_i;
54 49 robfinch
input [3:0] irq_i;
55 48 robfinch
input [7:0] vec_i;
56
output reg [1:0] bte_o;
57
output reg [2:0] cti_o;
58
output reg cyc_o;
59
output reg stb_o;
60
input ack_i;
61
input err_i;
62
output reg we_o;
63
output reg [7:0] sel_o;
64 49 robfinch
output reg [`ABITS] adr_o;
65 48 robfinch
output reg [63:0] dat_o;
66
input [63:0] dat_i;
67
output reg [1:0] ol_o;
68
output [31:0] pcr_o;
69
output [63:0] pcr2_o;
70
input exv_i;
71
input rdv_i;
72
input wrv_i;
73
output reg icl_o;
74
output reg cr_o;
75
output reg sr_o;
76
input rbi_i;
77
input [31:0] signal_i;
78
 
79
parameter TM_CLKFREQ = 20000000;
80
parameter QENTRIES = `QENTRIES;
81
parameter RSTPC = 32'hFFFC0100;
82
parameter BRKPC = 32'hFFFC0000;
83
`ifdef SUPPORT_SMT
84
parameter PREGS = 256;   // number of physical registers - 1
85
parameter AREGS = 256;   // number of architectural registers
86
`else
87
parameter PREGS = 128;
88
parameter AREGS = 128;
89
`endif
90
parameter RBIT = 11;
91
parameter DEBUG = 1'b0;
92
parameter NMAP = QENTRIES;
93
parameter BRANCH_PRED = 1'b0;
94
parameter SUP_TXE = 1'b0;
95
parameter SUP_VECTOR = 1;
96
parameter DBW = 64;
97
parameter ABW = 32;
98
parameter AMSB = ABW-1;
99
parameter NTHREAD = 1;
100
reg [3:0] i;
101
integer n;
102 52 robfinch
integer j, k;
103 48 robfinch
genvar g;
104
parameter TRUE = 1'b1;
105
parameter FALSE = 1'b0;
106
// Memory access sizes
107
parameter byt = 3'd0;
108
parameter wyde = 3'd1;
109
parameter tetra = 3'd2;
110
parameter octa = 3'd3;
111
// IQ states
112
parameter IQS_IDLE = 2'd0;
113
parameter IQS_AGEN = 2'd1;
114
parameter IQS_LDDONE = 2'd2;
115
parameter IQS_S3 = 2'd3;
116
 
117
wire clk;
118 50 robfinch
//BUFG uclkb1
119
//(
120
//      .I(clk_i),
121
//      .O(clk)
122
//);
123
assign clk = clk_i;
124 48 robfinch
 
125
wire dc_ack;
126
wire acki = ack_i|dc_ack;
127
wire [RBIT:0] Ra0, Ra1;
128
wire [RBIT:0] Rb0, Rb1;
129
wire [RBIT:0] Rc0, Rc1;
130
wire [RBIT:0] Rt0, Rt1;
131
wire [63:0] rfoa0,rfob0,rfoc0,rfoc0a;
132
wire [63:0] rfoa1,rfob1,rfoc1,rfoc1a;
133
`ifdef SUPPORT_SMT
134
wire [7:0] Ra0s = {Ra0[7:0]};
135
wire [7:0] Ra1s = {Ra1[7:0]};
136
wire [7:0] Rb0s = {Rb0[7:0]};
137
wire [7:0] Rb1s = {Rb1[7:0]};
138
wire [7:0] Rc0s = {Rc0[7:0]};
139
wire [7:0] Rc1s = {Rc1[7:0]};
140
wire [7:0] Rt0s = {Rt0[7:0]};
141
wire [7:0] Rt1s = {Rt1[7:0]};
142
`else
143
wire [6:0] Ra0s = {Ra0[7],Ra0[5:0]};
144
wire [6:0] Ra1s = {Ra1[7],Ra1[5:0]};
145
wire [6:0] Rb0s = {Rb0[7],Rb0[5:0]};
146
wire [6:0] Rb1s = {Rb1[7],Rb1[5:0]};
147
wire [6:0] Rc0s = {Rc0[7],Rc0[5:0]};
148
wire [6:0] Rc1s = {Rc1[7],Rc1[5:0]};
149
wire [6:0] Rt0s = {Rt0[7],Rt0[5:0]};
150
wire [6:0] Rt1s = {Rt1[7],Rt1[5:0]};
151
/*
152
wire [5:0] Ra0s = {Ra0[5:0]};
153
wire [5:0] Ra1s = {Ra1[5:0]};
154
wire [5:0] Rb0s = {Rb0[5:0]};
155
wire [5:0] Rb1s = {Rb1[5:0]};
156
wire [5:0] Rc0s = {Rc0[5:0]};
157
wire [5:0] Rc1s = {Rc1[5:0]};
158
wire [5:0] Rt0s = {Rt0[5:0]};
159
wire [5:0] Rt1s = {Rt1[5:0]};
160
*/
161
`endif
162
 
163
reg [63:0] ds [0:NTHREAD];
164
reg [63:0] ss [0:NTHREAD];
165
reg [63:0] ptrmask [0:NTHREAD];
166
reg [63:0] ptrkey = "  OBJECT";
167
reg [63:0] wbrcd;
168
 
169
reg  [PREGS-1:0] rf_v;
170 52 robfinch
reg  [5:0] rf_source[0:AREGS-1];
171 48 robfinch
initial begin
172
for (n = 0; n < AREGS; n = n + 1)
173 52 robfinch
        rf_source[n] = 6'd0;
174 48 robfinch
end
175 49 robfinch
wire [`ABITS] pc0;
176
wire [`ABITS] pc1;
177
wire [`ABITS] pc2;
178 48 robfinch
 
179
reg excmiss;
180 49 robfinch
reg [`ABITS] excmisspc;
181 48 robfinch
reg excthrd;
182
reg exception_set;
183
reg rdvq;               // accumulated read violation
184
reg errq;               // accumulated err_i input status
185
reg exvq;
186
 
187
// Vector
188
reg [5:0] vqe0, vqe1;   // vector element being queued
189
reg [5:0] vqet0, vqet1;
190
reg [7:0] vl;           // vector length
191
reg [63:0] vm [0:7];    // vector mask registers
192
reg [1:0] m2;
193
 
194 49 robfinch
reg [31:0] wb_merges;
195 48 robfinch
// CSR's
196
reg [63:0] cr0;
197
wire snr = cr0[17];             // sequence number reset
198
wire dce = cr0[30];     // data cache enable
199
wire bpe = cr0[32];     // branch predictor enable
200 52 robfinch
wire wbm = cr0[34];
201 48 robfinch
wire ctgtxe = cr0[33];
202 49 robfinch
reg [63:0] pmr;
203
wire id1_available = pmr[0];
204
wire id2_available = pmr[1];
205
wire id3_available = pmr[2];
206
wire alu0_available = pmr[8];
207
wire alu1_available = pmr[9];
208
wire fpu1_available = pmr[16];
209
wire fpu2_available = pmr[17];
210
wire mem1_available = pmr[24];
211
wire mem2_available = pmr[25];
212
wire mem3_available = pmr[26];
213
wire fcu_available = pmr[32];
214 48 robfinch
// Simply setting this flag to zero should strip out almost all the logic
215
// associated SMT.
216
`ifdef SUPPORT_SMT
217
wire thread_en = cr0[16];
218
`else
219
wire thread_en = 1'b0;
220
`endif
221
wire vechain = cr0[18];
222
reg [7:0] fcu_timeout;
223
reg [63:0] tick;
224
reg [63:0] wc_time;
225
reg [31:0] pcr;
226
reg [63:0] pcr2;
227
assign pcr_o = pcr;
228
assign pcr2_o = pcr2;
229
reg [63:0] aec;
230
reg [15:0] cause[0:15];
231
`ifdef SUPPORT_SMT
232 49 robfinch
reg [`ABITS] epc [0:NTHREAD];
233
reg [`ABITS] epc0 [0:NTHREAD];
234
reg [`ABITS] epc1 [0:NTHREAD];
235
reg [`ABITS] epc2 [0:NTHREAD];
236
reg [`ABITS] epc3 [0:NTHREAD];
237
reg [`ABITS] epc4 [0:NTHREAD];
238
reg [`ABITS] epc5 [0:NTHREAD];
239
reg [`ABITS] epc6 [0:NTHREAD];
240
reg [`ABITS] epc7 [0:NTHREAD];
241
reg [`ABITS] epc8 [0:NTHREAD];                   // exception pc and stack
242 48 robfinch
reg [63:0] mstatus [0:NTHREAD];           // machine status
243 49 robfinch
wire [3:0] im = mstatus[0][3:0];
244 48 robfinch
wire [1:0] ol [0:NTHREAD];
245
wire [1:0] dl [0:NTHREAD];
246
assign ol[0] = mstatus[0][5:3];   // operating level
247
assign dl[0] = mstatus[0][21:20];
248
wire [7:0] cpl [0:NTHREAD];
249
assign cpl[0] = mstatus[0][13:6]; // current privilege level
250
wire [5:0] rgs [0:NTHREAD];
251
assign rgs[0] = mstatus[0][19:14];
252
assign ol[1] = mstatus[1][5:3]; // operating level
253
assign cpl[1] = mstatus[1][13:6];       // current privilege level
254
assign rgs[1] = mstatus[1][19:14];
255
assign dl[1] = mstatus[1][21:20];
256
reg [15:0] ol_stack [0:NTHREAD];
257
reg [31:0] im_stack [0:NTHREAD];
258
reg [63:0] pl_stack [0:NTHREAD];
259
reg [63:0] rs_stack [0:NTHREAD];
260
reg [63:0] fr_stack [0:NTHREAD];
261
wire mprv = mstatus[0][55];
262
wire [5:0] fprgs = mstatus[0][25:20];
263
//assign ol_o = mprv ? ol_stack[0][2:0] : ol[0];
264
wire vca = mstatus[0][32];               // vector chaining active
265
`else
266 49 robfinch
reg [`ABITS] epc ;
267
reg [`ABITS] epc0 ;
268
reg [`ABITS] epc1 ;
269
reg [`ABITS] epc2 ;
270
reg [`ABITS] epc3 ;
271
reg [`ABITS] epc4 ;
272
reg [`ABITS] epc5 ;
273
reg [`ABITS] epc6 ;
274
reg [`ABITS] epc7 ;
275
reg [`ABITS] epc8 ;                     // exception pc and stack
276 48 robfinch
reg [63:0] mstatus ;             // machine status
277 49 robfinch
wire [3:0] im = mstatus[3:0];
278 48 robfinch
wire [1:0] ol ;
279
wire [1:0] dl;
280
assign ol = mstatus[5:3];       // operating level
281
assign dl = mstatus[21:20];
282
wire [7:0] cpl ;
283
assign cpl = mstatus[13:6];     // current privilege level
284
wire [5:0] rgs ;
285
assign rgs = mstatus[19:14];
286
reg [15:0] ol_stack ;
287
reg [31:0] im_stack ;
288
reg [63:0] pl_stack ;
289
reg [63:0] rs_stack ;
290
reg [63:0] fr_stack ;
291
wire mprv = mstatus[55];
292
wire [5:0] fprgs = mstatus[25:20];
293
//assign ol_o = mprv ? ol_stack[2:0] : ol;
294
wire vca = mstatus[32];         // vector chaining active
295
`endif
296
reg [63:0] tcb;
297 49 robfinch
reg [`ABITS] badaddr[0:15];
298
reg [`ABITS] tvec[0:7];
299 48 robfinch
reg [63:0] sema;
300
reg [63:0] vm_sema;
301
reg [63:0] cas;         // compare and swap
302
reg [63:0] ve_hold;
303
reg isCAS, isAMO, isInc, isSpt, isRMW;
304
reg [`QBITS] casid;
305 49 robfinch
reg [`ABITS] sbl, sbu;
306 48 robfinch
reg [4:0] regLR = 5'd29;
307
 
308 51 robfinch
reg [2:0] fp_rm;
309
reg fp_inexe;
310
reg fp_dbzxe;
311
reg fp_underxe;
312
reg fp_overxe;
313
reg fp_invopxe;
314
reg fp_giopxe;
315
reg fp_nsfp = 1'b0;
316
reg fp_fractie;
317
reg fp_raz;
318 48 robfinch
 
319 51 robfinch
reg fp_neg;
320
reg fp_pos;
321
reg fp_zero;
322
reg fp_inf;
323 48 robfinch
 
324 51 robfinch
reg fp_inex;            // inexact exception
325
reg fp_dbzx;            // divide by zero exception
326
reg fp_underx;          // underflow exception
327
reg fp_overx;           // overflow exception
328
reg fp_giopx;           // global invalid operation exception
329
reg fp_sx;                      // summary exception
330
reg fp_swtx;        // software triggered exception
331
reg fp_gx;
332
reg fp_invopx;
333 48 robfinch
 
334 51 robfinch
reg fp_infzerox;
335
reg fp_zerozerox;
336
reg fp_subinfx;
337
reg fp_infdivx;
338
reg fp_NaNCmpx;
339
reg fp_cvtx;
340
reg fp_sqrtx;
341
reg fp_snanx;
342 48 robfinch
 
343 51 robfinch
wire [31:0] fp_status = {
344 48 robfinch
 
345 51 robfinch
        fp_rm,
346
        fp_inexe,
347
        fp_dbzxe,
348
        fp_underxe,
349
        fp_overxe,
350
        fp_invopxe,
351
        fp_nsfp,
352 48 robfinch
 
353 51 robfinch
        fp_fractie,
354
        fp_raz,
355 48 robfinch
        1'b0,
356 51 robfinch
        fp_neg,
357
        fp_pos,
358
        fp_zero,
359
        fp_inf,
360 48 robfinch
 
361 51 robfinch
        fp_swtx,
362
        fp_inex,
363
        fp_dbzx,
364
        fp_underx,
365
        fp_overx,
366
        fp_giopx,
367
        fp_gx,
368
        fp_sx,
369 48 robfinch
 
370 51 robfinch
        fp_cvtx,
371
        fp_sqrtx,
372
        fp_NaNCmpx,
373
        fp_infzerox,
374
        fp_zerozerox,
375
        fp_infdivx,
376
        fp_subinfx,
377
        fp_snanx
378 48 robfinch
        };
379
 
380 51 robfinch
reg [63:0] fpu_csr;
381
wire [5:0] fp_rgs = fpu_csr[37:32];
382 48 robfinch
 
383
//reg [25:0] m[0:8191];
384
reg  [3:0] panic;                // indexes the message structure
385
reg [128:0] message [0:15];       // indexed by panic
386
 
387
wire int_commit;
388
reg StatusHWI;
389 49 robfinch
reg [47:0] insn0, insn1, insn2;
390 52 robfinch
wire [47:0] insn0a, insn1b, insn2b;
391
reg [47:0] insn1a, insn2a;
392 48 robfinch
reg tgtq;
393
// Only need enough bits in the seqnence number to cover the instructions in
394
// the queue plus an extra count for skipping on branch misses. In this case
395
// that would be four bits minimum (count 0 to 8). 
396
reg [31:0] seq_num;
397
reg [31:0] seq_num1;
398
wire [63:0] rdat0,rdat1,rdat2;
399
reg [63:0] xdati;
400
 
401
reg canq1, canq2;
402
reg queued1;
403
reg queued2;
404
reg queuedNop;
405
 
406
reg [47:0] codebuf[0:63];
407 52 robfinch
reg [QENTRIES-1:0] setpred;
408 48 robfinch
 
409
// instruction queue (ROB)
410
reg [31:0]  iqentry_sn   [0:QENTRIES-1];  // instruction sequence number
411
reg [QENTRIES-1:0] iqentry_v;                    // entry valid?  -- this should be the first bit
412
reg [QENTRIES-1:0] iqentry_iv;           // instruction is valid
413
reg [4:0]  iqentry_is   [0:QENTRIES-1];   // source of instruction
414
reg [QENTRIES-1:0] iqentry_out;  // instruction has been issued to an ALU ... 
415
reg [QENTRIES-1:0] iqentry_done; // instruction result valid
416
reg [QENTRIES-1:0] iqentry_cmt;
417
reg [QENTRIES-1:0] iqentry_thrd;         // which thread the instruction is in
418
reg [QENTRIES-1:0] iqentry_pt;           // predict taken
419 51 robfinch
reg [QENTRIES-1:0] iqentry_bt;           // update branch target buffer
420 52 robfinch
reg [QENTRIES-1:0] iqentry_takb; // take branch record
421 51 robfinch
reg [QENTRIES-1:0] iqentry_jal;
422 48 robfinch
reg [QENTRIES-1:0] iqentry_agen; // address-generate ... signifies that address is ready (only for LW/SW)
423
reg  [1:0] iqentry_state [0:QENTRIES-1];
424
reg [QENTRIES-1:0] iqentry_alu = 8'h00;  // alu type instruction
425
reg [QENTRIES-1:0] iqentry_alu0;  // only valid on alu #0
426
reg [QENTRIES-1:0] iqentry_fpu;  // floating point instruction
427
reg [QENTRIES-1:0] iqentry_fc;   // flow control instruction
428
reg [QENTRIES-1:0] iqentry_canex = 8'h00;        // true if it's an instruction that can exception
429 50 robfinch
reg [QENTRIES-1:0] iqentry_oddball = 8'h00;      // writes to register file
430 49 robfinch
reg [QENTRIES-1:0] iqentry_load; // is a memory load instruction
431 50 robfinch
reg [QENTRIES-1:0] iqentry_loadv;        // is a volatile memory load instruction
432
reg [QENTRIES-1:0] iqentry_store;        // is a memory store instruction
433 49 robfinch
reg [QENTRIES-1:0] iqentry_preload;      // is a memory preload instruction
434
reg [QENTRIES-1:0] iqentry_ldcmp;
435
reg [QENTRIES-1:0] iqentry_mem;  // touches memory: 1 if LW/SW
436
reg [QENTRIES-1:0] iqentry_memndx;  // indexed memory operation 
437 50 robfinch
reg [2:0] iqentry_memsz [0:QENTRIES-1];   // size of memory op
438 49 robfinch
reg [QENTRIES-1:0] iqentry_rmw;  // memory RMW op
439
reg [QENTRIES-1:0] iqentry_memdb;
440
reg [QENTRIES-1:0] iqentry_memsb;
441
reg [QENTRIES-1:0] iqentry_rtop;
442 48 robfinch
reg [QENTRIES-1:0] iqentry_sei;
443
reg [QENTRIES-1:0] iqentry_aq;   // memory aquire
444
reg [QENTRIES-1:0] iqentry_rl;   // memory release
445 49 robfinch
reg [QENTRIES-1:0] iqentry_shft48;
446
reg [QENTRIES-1:0] iqentry_jmp;  // changes control flow: 1 if BEQ/JALR
447 48 robfinch
reg [QENTRIES-1:0] iqentry_br;  // Bcc (for predictor)
448 51 robfinch
reg [QENTRIES-1:0] iqentry_ret;
449
reg [QENTRIES-1:0] iqentry_irq;
450
reg [QENTRIES-1:0] iqentry_brk;
451
reg [QENTRIES-1:0] iqentry_rti;
452 49 robfinch
reg [QENTRIES-1:0] iqentry_sync;  // sync instruction
453
reg [QENTRIES-1:0] iqentry_fsync;
454 48 robfinch
reg [QENTRIES-1:0] iqentry_rfw = 8'h00;  // writes to register file
455
reg  [7:0] iqentry_we   [0:QENTRIES-1];   // enable strobe
456
reg [63:0] iqentry_res   [0:QENTRIES-1];  // instruction result
457
reg [47:0] iqentry_instr[0:QENTRIES-1];   // instruction opcode
458
reg  [2:0] iqentry_insln[0:QENTRIES-1]; // instruction length
459
reg  [7:0] iqentry_exc   [0:QENTRIES-1];  // only for branches ... indicates a HALT instruction
460
reg [RBIT:0] iqentry_tgt [0:QENTRIES-1];  // Rt field or ZERO -- this is the instruction's target (if any)
461
reg  [7:0] iqentry_vl   [0:QENTRIES-1];
462
reg  [5:0] iqentry_ven  [0:QENTRIES-1];  // vector element number
463
reg [63:0] iqentry_a0    [0:QENTRIES-1];  // argument 0 (immediate)
464
reg [63:0] iqentry_a1    [0:QENTRIES-1];  // argument 1
465
reg        iqentry_a1_v [0:QENTRIES-1];  // arg1 valid
466
reg  [4:0] iqentry_a1_s  [0:QENTRIES-1];  // arg1 source (iq entry # with top bit representing ALU/DRAM bus)
467
reg [63:0] iqentry_a2    [0:QENTRIES-1];  // argument 2
468
reg        iqentry_a2_v [0:QENTRIES-1];  // arg2 valid
469
reg  [4:0] iqentry_a2_s  [0:QENTRIES-1];  // arg2 source (iq entry # with top bit representing ALU/DRAM bus)
470
reg [63:0] iqentry_a3    [0:QENTRIES-1];  // argument 3
471
reg        iqentry_a3_v [0:QENTRIES-1];  // arg3 valid
472
reg  [4:0] iqentry_a3_s  [0:QENTRIES-1];  // arg3 source (iq entry # with top bit representing ALU/DRAM bus)
473 49 robfinch
reg [`ABITS] iqentry_pc [0:QENTRIES-1];  // program counter for this instruction
474 48 robfinch
reg [RBIT:0] iqentry_Ra [0:QENTRIES-1];
475
reg [RBIT:0] iqentry_Rb [0:QENTRIES-1];
476
reg [RBIT:0] iqentry_Rc [0:QENTRIES-1];
477
// debugging
478
//reg  [4:0] iqentry_ra   [0:7];  // Ra
479
initial begin
480
for (n = 0; n < QENTRIES; n = n + 1)
481
        iqentry_a1_s[n] = 5'd0;
482
        iqentry_a2_s[n] = 5'd0;
483
        iqentry_a3_s[n] = 5'd0;
484
end
485
 
486
wire  [QENTRIES-1:0] iqentry_source = 8'h00;
487
reg   [QENTRIES-1:0] iqentry_imm;
488
wire  [QENTRIES-1:0] iqentry_memready;
489
wire  [QENTRIES-1:0] iqentry_memopsvalid;
490
 
491
reg  [QENTRIES-1:0] memissue = 8'h00;
492
reg [1:0] missued;
493
integer last_issue;
494
reg  [QENTRIES-1:0] iqentry_memissue;
495
wire [QENTRIES-1:0] iqentry_stomp;
496
reg [3:0] stompedOnRets;
497
reg  [QENTRIES-1:0] iqentry_alu0_issue;
498
reg  [QENTRIES-1:0] iqentry_alu1_issue;
499 49 robfinch
reg  [QENTRIES-1:0] iqentry_alu2_issue;
500 48 robfinch
reg  [QENTRIES-1:0] iqentry_id1issue;
501
reg  [QENTRIES-1:0] iqentry_id2issue;
502 49 robfinch
reg  [QENTRIES-1:0] iqentry_id3issue;
503 48 robfinch
reg [1:0] iqentry_mem_islot [0:QENTRIES-1];
504
reg [QENTRIES-1:0] iqentry_fcu_issue;
505 49 robfinch
reg [QENTRIES-1:0] iqentry_fpu1_issue;
506
reg [QENTRIES-1:0] iqentry_fpu2_issue;
507 48 robfinch
 
508
wire [PREGS-1:1] livetarget;
509
wire  [PREGS-1:1] iqentry_0_livetarget;
510
wire  [PREGS-1:1] iqentry_1_livetarget;
511
wire  [PREGS-1:1] iqentry_2_livetarget;
512
wire  [PREGS-1:1] iqentry_3_livetarget;
513
wire  [PREGS-1:1] iqentry_4_livetarget;
514
wire  [PREGS-1:1] iqentry_5_livetarget;
515
wire  [PREGS-1:1] iqentry_6_livetarget;
516
wire  [PREGS-1:1] iqentry_7_livetarget;
517 52 robfinch
wire  [PREGS-1:1] iqentry_8_livetarget;
518
wire  [PREGS-1:1] iqentry_9_livetarget;
519
wire [PREGS-1:1] iqentry_livetarget [0:QENTRIES-1];
520
assign iqentry_livetarget[0] = iqentry_0_livetarget;
521
assign iqentry_livetarget[1] = iqentry_1_livetarget;
522
assign iqentry_livetarget[2] = iqentry_2_livetarget;
523
assign iqentry_livetarget[3] = iqentry_3_livetarget;
524
assign iqentry_livetarget[4] = iqentry_4_livetarget;
525
assign iqentry_livetarget[5] = iqentry_5_livetarget;
526
assign iqentry_livetarget[6] = iqentry_6_livetarget;
527
assign iqentry_livetarget[7] = iqentry_7_livetarget;
528
assign iqentry_livetarget[8] = iqentry_8_livetarget;
529
assign iqentry_livetarget[9] = iqentry_9_livetarget;
530 48 robfinch
wire  [PREGS-1:1] iqentry_0_latestID;
531
wire  [PREGS-1:1] iqentry_1_latestID;
532
wire  [PREGS-1:1] iqentry_2_latestID;
533
wire  [PREGS-1:1] iqentry_3_latestID;
534
wire  [PREGS-1:1] iqentry_4_latestID;
535
wire  [PREGS-1:1] iqentry_5_latestID;
536
wire  [PREGS-1:1] iqentry_6_latestID;
537
wire  [PREGS-1:1] iqentry_7_latestID;
538 52 robfinch
wire  [PREGS-1:1] iqentry_8_latestID;
539
wire  [PREGS-1:1] iqentry_9_latestID;
540 48 robfinch
wire  [PREGS-1:1] iqentry_0_cumulative;
541
wire  [PREGS-1:1] iqentry_1_cumulative;
542
wire  [PREGS-1:1] iqentry_2_cumulative;
543
wire  [PREGS-1:1] iqentry_3_cumulative;
544
wire  [PREGS-1:1] iqentry_4_cumulative;
545
wire  [PREGS-1:1] iqentry_5_cumulative;
546
wire  [PREGS-1:1] iqentry_6_cumulative;
547
wire  [PREGS-1:1] iqentry_7_cumulative;
548 52 robfinch
wire  [PREGS-1:1] iqentry_8_cumulative;
549
wire  [PREGS-1:1] iqentry_9_cumulative;
550
reg [PREGS-1:1] iqentry_cumulative [0:QENTRIES-1];
551 48 robfinch
wire  [PREGS-1:1] iq0_out;
552
wire  [PREGS-1:1] iq1_out;
553
wire  [PREGS-1:1] iq2_out;
554
wire  [PREGS-1:1] iq3_out;
555
wire  [PREGS-1:1] iq4_out;
556
wire  [PREGS-1:1] iq5_out;
557
wire  [PREGS-1:1] iq6_out;
558
wire  [PREGS-1:1] iq7_out;
559 52 robfinch
wire  [PREGS-1:1] iq8_out;
560
wire  [PREGS-1:1] iq9_out;
561 48 robfinch
 
562
reg  [`QBITS] tail0;
563
reg  [`QBITS] tail1;
564
reg  [`QBITS] head0;
565
reg  [`QBITS] head1;
566
reg  [`QBITS] head2;    // used only to determine memory-access ordering
567
reg  [`QBITS] head3;    // used only to determine memory-access ordering
568
reg  [`QBITS] head4;    // used only to determine memory-access ordering
569
reg  [`QBITS] head5;    // used only to determine memory-access ordering
570
reg  [`QBITS] head6;    // used only to determine memory-access ordering
571
reg  [`QBITS] head7;    // used only to determine memory-access ordering
572 52 robfinch
reg  [`QBITS] head8;
573
reg  [`QBITS] head9;
574 48 robfinch
 
575
wire take_branch0;
576
wire take_branch1;
577
 
578
reg [3:0] nop_fetchbuf;
579
wire        fetchbuf;   // determines which pair to read from & write to
580 49 robfinch
wire [3:0] fb_panic;
581 48 robfinch
 
582
wire [47:0] fetchbuf0_instr;
583
wire  [2:0] fetchbuf0_insln;
584 49 robfinch
wire [`ABITS] fetchbuf0_pc;
585 48 robfinch
wire        fetchbuf0_v;
586
wire            fetchbuf0_thrd;
587
wire        fetchbuf0_mem;
588
wire            fetchbuf0_memld;
589
wire        fetchbuf0_rfw;
590
wire [47:0] fetchbuf1_instr;
591
wire  [2:0] fetchbuf1_insln;
592 49 robfinch
wire [`ABITS] fetchbuf1_pc;
593 48 robfinch
wire        fetchbuf1_v;
594
wire            fetchbuf1_thrd;
595
wire        fetchbuf1_mem;
596
wire            fetchbuf1_memld;
597
wire        fetchbuf1_rfw;
598
 
599
wire [47:0] fetchbufA_instr;
600 49 robfinch
wire [`ABITS] fetchbufA_pc;
601 48 robfinch
wire        fetchbufA_v;
602
wire [47:0] fetchbufB_instr;
603 49 robfinch
wire [`ABITS] fetchbufB_pc;
604 48 robfinch
wire        fetchbufB_v;
605
wire [47:0] fetchbufC_instr;
606 49 robfinch
wire [`ABITS] fetchbufC_pc;
607 48 robfinch
wire        fetchbufC_v;
608
wire [47:0] fetchbufD_instr;
609 49 robfinch
wire [`ABITS] fetchbufD_pc;
610 48 robfinch
wire        fetchbufD_v;
611
 
612
//reg        did_branchback0;
613
//reg        did_branchback1;
614
 
615
reg         id1_v;
616
reg   [4:0] id1_id;
617
reg  [47:0] id1_instr;
618
reg   [5:0] id1_ven;
619
reg   [7:0] id1_vl;
620
reg         id1_thrd;
621
reg         id1_pt;
622
reg   [4:0] id1_Rt;
623 51 robfinch
wire [143:0] id1_bus;
624 48 robfinch
 
625
reg         id2_v;
626
reg   [4:0] id2_id;
627
reg  [47:0] id2_instr;
628
reg   [5:0] id2_ven;
629
reg   [7:0] id2_vl;
630
reg         id2_thrd;
631
reg         id2_pt;
632
reg   [4:0] id2_Rt;
633 51 robfinch
wire [143:0] id2_bus;
634 48 robfinch
 
635 49 robfinch
reg         id3_v;
636
reg   [4:0] id3_id;
637
reg  [47:0] id3_instr;
638
reg   [5:0] id3_ven;
639
reg   [7:0] id3_vl;
640
reg         id3_thrd;
641
reg         id3_pt;
642
reg   [4:0] id3_Rt;
643 51 robfinch
wire [143:0] id3_bus;
644 49 robfinch
 
645 48 robfinch
reg        alu0_ld;
646
reg        alu0_dataready;
647
wire       alu0_done;
648
wire       alu0_idle;
649
reg  [3:0] alu0_sourceid;
650
reg [47:0] alu0_instr;
651
reg        alu0_bt;
652
reg        alu0_mem;
653
reg        alu0_shft48;
654
reg [63:0] alu0_argA;
655
reg [63:0] alu0_argB;
656
reg [63:0] alu0_argC;
657
reg [63:0] alu0_argI;    // only used by BEQ
658
reg [RBIT:0] alu0_tgt;
659
reg [5:0]  alu0_ven;
660
reg        alu0_thrd;
661 49 robfinch
reg [`ABITS] alu0_pc;
662 48 robfinch
wire [63:0] alu0_bus;
663
wire [63:0] alu0b_bus;
664
wire  [3:0] alu0_id;
665 49 robfinch
wire  [`XBITS] alu0_exc;
666 48 robfinch
wire        alu0_v;
667
wire        alu0_branchmiss;
668 49 robfinch
wire [`ABITS] alu0_misspc;
669 48 robfinch
 
670
reg        alu1_ld;
671
reg        alu1_dataready;
672
wire       alu1_done;
673
wire       alu1_idle;
674
reg  [3:0] alu1_sourceid;
675
reg [47:0] alu1_instr;
676
reg        alu1_bt;
677
reg        alu1_mem;
678
reg        alu1_shft48;
679
reg [63:0] alu1_argA;
680
reg [63:0] alu1_argB;
681
reg [63:0] alu1_argC;
682
reg [63:0] alu1_argI;    // only used by BEQ
683
reg [RBIT:0] alu1_tgt;
684
reg [5:0]  alu1_ven;
685 49 robfinch
reg [`ABITS] alu1_pc;
686 48 robfinch
reg        alu1_thrd;
687
wire [63:0] alu1_bus;
688
wire [63:0] alu1b_bus;
689
wire  [3:0] alu1_id;
690 49 robfinch
wire  [`XBITS] alu1_exc;
691 48 robfinch
wire        alu1_v;
692
wire        alu1_branchmiss;
693 49 robfinch
wire [`ABITS] alu1_misspc;
694 48 robfinch
 
695 52 robfinch
wire [`XBITS] fpu_exc;
696 49 robfinch
reg        fpu1_ld;
697
reg        fpu1_dataready = 1'b1;
698
wire       fpu1_done = 1'b1;
699
wire       fpu1_idle;
700
reg  [3:0] fpu1_sourceid;
701
reg [47:0] fpu1_instr;
702
reg [63:0] fpu1_argA;
703
reg [63:0] fpu1_argB;
704
reg [63:0] fpu1_argC;
705
reg [63:0] fpu1_argI;    // only used by BEQ
706
reg [RBIT:0] fpu1_tgt;
707
reg [`ABITS] fpu1_pc;
708
wire [63:0] fpu1_bus;
709
wire  [3:0] fpu1_id;
710
wire  [`XBITS] fpu1_exc = 9'h000;
711
wire        fpu1_v;
712
wire [31:0] fpu1_status;
713 48 robfinch
 
714 49 robfinch
reg        fpu2_ld;
715
reg        fpu2_dataready = 1'b1;
716
wire       fpu2_done = 1'b1;
717
wire       fpu2_idle;
718
reg  [3:0] fpu2_sourceid;
719
reg [47:0] fpu2_instr;
720
reg [63:0] fpu2_argA;
721
reg [63:0] fpu2_argB;
722
reg [63:0] fpu2_argC;
723
reg [63:0] fpu2_argI;    // only used by BEQ
724
reg [RBIT:0] fpu2_tgt;
725
reg [`ABITS] fpu2_pc;
726
wire [63:0] fpu2_bus;
727
wire  [3:0] fpu2_id;
728
wire  [`XBITS] fpu2_exc = 9'h000;
729
wire        fpu2_v;
730
wire [31:0] fpu2_status;
731
 
732 48 robfinch
reg [63:0] waitctr;
733
reg        fcu_ld;
734
reg        fcu_dataready;
735
reg        fcu_done;
736
reg         fcu_idle = 1'b1;
737
reg  [3:0] fcu_sourceid;
738
reg [47:0] fcu_instr;
739
reg  [2:0] fcu_insln;
740 51 robfinch
reg        fcu_branch;
741 48 robfinch
reg        fcu_call;
742 51 robfinch
reg        fcu_ret;
743
reg        fcu_jal;
744
reg        fcu_brk;
745
reg        fcu_rti;
746 48 robfinch
reg        fcu_bt;
747
reg [63:0] fcu_argA;
748
reg [63:0] fcu_argB;
749
reg [63:0] fcu_argC;
750
reg [63:0] fcu_argI;     // only used by BEQ
751
reg [63:0] fcu_argT;
752
reg [63:0] fcu_argT2;
753 49 robfinch
reg [`ABITS] fcu_pc;
754
reg [`ABITS] fcu_nextpc;
755
reg [`ABITS] fcu_brdisp;
756 48 robfinch
wire [63:0] fcu_bus;
757
wire  [3:0] fcu_id;
758 49 robfinch
reg   [`XBITS] fcu_exc;
759 48 robfinch
wire        fcu_v;
760
reg        fcu_thrd;
761
reg        fcu_branchmiss;
762
reg  fcu_clearbm;
763 49 robfinch
reg [`ABITS] fcu_misspc;
764 48 robfinch
 
765
reg [63:0] rmw_argA;
766
reg [63:0] rmw_argB;
767
reg [63:0] rmw_argC;
768
wire [63:0] rmw_res;
769
reg [31:0] rmw_instr;
770
 
771 49 robfinch
// write buffer
772
reg [63:0] wb_data [0:`WB_DEPTH-1];
773
reg [`ABITS] wb_addr [0:`WB_DEPTH-1];
774
reg [1:0] wb_ol [0:`WB_DEPTH-1];
775
reg [`WB_DEPTH-1:0] wb_v;
776
reg [`WB_DEPTH-1:0] wb_rmw;
777
reg [QENTRIES-1:0] wb_id [0:`WB_DEPTH-1];
778
reg [QENTRIES-1:0] wbo_id;
779
reg [7:0] wb_sel [0:`WB_DEPTH-1];
780
reg wb_en;
781 52 robfinch
reg wb_shift;
782 49 robfinch
 
783 48 robfinch
reg branchmiss = 1'b0;
784
reg branchmiss_thrd = 1'b0;
785 49 robfinch
reg [`ABITS] misspc;
786 48 robfinch
reg  [`QBITS] missid;
787
 
788
wire take_branch;
789
wire take_branchA;
790
wire take_branchB;
791
wire take_branchC;
792
wire take_branchD;
793
 
794
wire        dram_avail;
795
reg      [2:0] dram0;    // state of the DRAM request (latency = 4; can have three in pipeline)
796
reg      [2:0] dram1;    // state of the DRAM request (latency = 4; can have three in pipeline)
797
reg      [2:0] dram2;    // state of the DRAM request (latency = 4; can have three in pipeline)
798
reg [63:0] dram0_data;
799 49 robfinch
reg [`ABITS] dram0_addr;
800 48 robfinch
reg [31:0] dram0_seg;
801
reg [47:0] dram0_instr;
802
reg        dram0_rmw;
803
reg                dram0_preload;
804
reg [RBIT:0] dram0_tgt;
805
reg  [3:0] dram0_id;
806 49 robfinch
reg  [`XBITS] dram0_exc;
807 48 robfinch
reg        dram0_unc;
808
reg [2:0]  dram0_memsize;
809
reg        dram0_load;  // is a load operation
810 50 robfinch
reg        dram0_store;
811 48 robfinch
reg  [1:0] dram0_ol;
812
reg [63:0] dram1_data;
813 49 robfinch
reg [`ABITS] dram1_addr;
814 48 robfinch
reg [31:0] dram1_seg;
815
reg [47:0] dram1_instr;
816
reg        dram1_rmw;
817
reg                dram1_preload;
818
reg [RBIT:0] dram1_tgt;
819
reg  [3:0] dram1_id;
820 49 robfinch
reg  [`XBITS] dram1_exc;
821 48 robfinch
reg        dram1_unc;
822
reg [2:0]  dram1_memsize;
823
reg        dram1_load;
824 50 robfinch
reg        dram1_store;
825 48 robfinch
reg  [1:0] dram1_ol;
826
reg [63:0] dram2_data;
827 49 robfinch
reg [`ABITS] dram2_addr;
828 48 robfinch
reg [31:0] dram2_seg;
829
reg [47:0] dram2_instr;
830
reg        dram2_rmw;
831
reg                dram2_preload;
832
reg [RBIT:0] dram2_tgt;
833
reg  [3:0] dram2_id;
834 49 robfinch
reg  [`XBITS] dram2_exc;
835 48 robfinch
reg        dram2_unc;
836
reg [2:0]  dram2_memsize;
837
reg        dram2_load;
838 50 robfinch
reg        dram2_store;
839 48 robfinch
reg  [1:0] dram2_ol;
840
 
841
reg        dramA_v;
842
reg  [3:0] dramA_id;
843
reg [63:0] dramA_bus;
844 49 robfinch
reg  [`XBITS] dramA_exc;
845 48 robfinch
reg        dramB_v;
846
reg  [3:0] dramB_id;
847
reg [63:0] dramB_bus;
848 49 robfinch
reg  [`XBITS] dramB_exc;
849 48 robfinch
reg        dramC_v;
850
reg  [3:0] dramC_id;
851
reg [63:0] dramC_bus;
852 49 robfinch
reg  [`XBITS] dramC_exc;
853 48 robfinch
 
854
wire        outstanding_stores;
855
reg [63:0] I;    // instruction count
856
 
857
reg        commit0_v;
858
reg  [4:0] commit0_id;
859
reg [RBIT:0] commit0_tgt;
860
reg  [7:0] commit0_we = 8'h00;
861
reg [63:0] commit0_bus;
862
reg        commit1_v;
863
reg  [4:0] commit1_id;
864
reg [RBIT:0] commit1_tgt;
865
reg  [7:0] commit1_we = 8'h00;
866
reg [63:0] commit1_bus;
867
 
868
reg [4:0] bstate;
869
parameter BIDLE = 5'd0;
870
parameter B1 = 5'd1;
871
parameter B2 = 5'd2;
872
parameter B3 = 5'd3;
873
parameter B4 = 5'd4;
874
parameter B5 = 5'd5;
875
parameter B6 = 5'd6;
876
parameter B7 = 5'd7;
877
parameter B8 = 5'd8;
878
parameter B9 = 5'd9;
879
parameter B10 = 5'd10;
880
parameter B11 = 5'd11;
881
parameter B12 = 5'd12;
882
parameter B13 = 5'd13;
883
parameter B14 = 5'd14;
884
parameter B15 = 5'd15;
885
parameter B16 = 5'd16;
886
parameter B17 = 5'd17;
887
parameter B18 = 5'd18;
888
parameter B19 = 5'd19;
889
parameter B2a = 5'd20;
890
parameter B2b = 5'd21;
891
parameter B2c = 5'd22;
892
parameter B2d = 5'd23;
893
parameter B20 = 5'd24;
894
parameter B21 = 5'd25;
895
reg [1:0] bwhich;
896
reg [3:0] icstate,picstate;
897
parameter IDLE = 4'd0;
898
parameter IC1 = 4'd1;
899
parameter IC2 = 4'd2;
900
parameter IC3 = 4'd3;
901
parameter IC4 = 4'd4;
902
parameter IC5 = 4'd5;
903
parameter IC6 = 4'd6;
904
parameter IC7 = 4'd7;
905
parameter IC8 = 4'd8;
906
parameter IC9 = 4'd9;
907
parameter IC10 = 4'd10;
908
parameter IC3a = 4'd11;
909
reg invic, invdc;
910 49 robfinch
reg [1:0] icwhich;
911
reg icnxt,L2_nxt;
912
wire ihit0,ihit1,ihit2,ihitL2;
913
wire ihit = ihit0&ihit1&ihit2;
914 48 robfinch
reg phit;
915
wire threadx;
916
always @*
917
        phit <= ihit&&icstate==IDLE;
918
reg [2:0] iccnt;
919 49 robfinch
reg L1_wr0,L1_wr1,L1_wr2;
920 48 robfinch
reg L1_invline;
921 49 robfinch
reg [8:0] L1_en;
922 48 robfinch
reg [37:0] L1_adr, L2_adr;
923 49 robfinch
reg [287:0] L2_rdat;
924
wire [287:0] L2_dato;
925 48 robfinch
reg L2_xsel;
926
 
927
FT64_regfile2w6r_oc #(.RBIT(RBIT)) urf1
928
(
929
  .clk(clk),
930
  .clk4x(clk4x),
931
  .wr0(commit0_v),
932
  .wr1(commit1_v),
933
  .we0(commit0_we),
934
  .we1(commit1_we),
935
  .wa0(commit0_tgt),
936
  .wa1(commit1_tgt),
937
  .i0(commit0_bus),
938
  .i1(commit1_bus),
939
        .rclk(~clk),
940
        .ra0(Ra0),
941
        .ra1(Rb0),
942
        .ra2(Rc0),
943
        .ra3(Ra1),
944
        .ra4(Rb1),
945
        .ra5(Rc1),
946
        .o0(rfoa0),
947
        .o1(rfob0),
948
        .o2(rfoc0a),
949
        .o3(rfoa1),
950
        .o4(rfob1),
951
        .o5(rfoc1a)
952
);
953
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
954
assign rfoc1 = Rc1[11:6]==6'h3F ? vm[Rc1[2:0]] : rfoc1a;
955
 
956
function [2:0] fnInsLength;
957
input [47:0] ins;
958
case(ins[7:6])
959
2'b00:  fnInsLength = 3'd4;
960
2'b01:  fnInsLength = 3'd6;
961
2'b10:  fnInsLength = 3'd2;
962
2'b11:  fnInsLength = 3'd2;
963
endcase
964
endfunction
965
 
966 49 robfinch
wire [`ABITS] pc0plus6 = pc0 + 32'd6;
967
wire [`ABITS] pc0plus12 = pc0 + 32'd12;
968 48 robfinch
 
969 49 robfinch
generate begin : gInsnVar
970
        if (`WAYS > 1) begin
971 52 robfinch
                always @*
972
                        if (thread_en)
973
                                insn1a <= insn1b;
974
                        else
975
                                insn1a = {insn1b,insn0a} >> {fnInsLength(insn0a),3'b0};
976 49 robfinch
        end
977
        if (`WAYS > 2) begin
978 52 robfinch
                always @*
979
                        if (thread_en)
980
                                insn2a <= insn2b;
981
                        else
982
                                insn2a = {insn2b,insn1b,insn0a} >> {fnInsLength(insn0a) + fnInsLength(insn1a),3'b0};
983 49 robfinch
        end
984
end
985
endgenerate
986 48 robfinch
 
987
FT64_L1_icache uic0
988
(
989
    .rst(rst),
990
    .clk(clk),
991
    .nxt(icnxt),
992
    .wr(L1_wr0),
993
    .en(L1_en),
994
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc0} : L1_adr),
995
    .wadr(L1_adr),
996
    .i(L2_rdat),
997
    .o(insn0a),
998
    .hit(ihit0),
999
    .invall(invic),
1000
    .invline(L1_invline)
1001
);
1002 49 robfinch
generate begin : gICacheInst
1003
if (`WAYS > 1) begin
1004 48 robfinch
FT64_L1_icache uic1
1005
(
1006
    .rst(rst),
1007
    .clk(clk),
1008
    .nxt(icnxt),
1009
    .wr(L1_wr1),
1010
    .en(L1_en),
1011 52 robfinch
    .adr(icstate==IDLE||icstate==IC8 ? (thread_en ? {pcr[5:0],pc1}: {pcr[5:0],pc0plus6} ): L1_adr),
1012 48 robfinch
    .wadr(L1_adr),
1013
    .i(L2_rdat),
1014
    .o(insn1b),
1015
    .hit(ihit1),
1016
    .invall(invic),
1017
    .invline(L1_invline)
1018
);
1019 49 robfinch
end
1020
else begin
1021
assign ihit1 = 1'b1;
1022
end
1023
if (`WAYS > 2) begin
1024
FT64_L1_icache uic2
1025
(
1026
    .rst(rst),
1027
    .clk(clk),
1028
    .nxt(icnxt),
1029
    .wr(L1_wr2),
1030
    .en(L1_en),
1031 52 robfinch
    .adr(icstate==IDLE||icstate==IC8 ? (thread_en ? {pcr[5:0],pc2} : {pcr[5:0],pc0plus12}) : L1_adr),
1032 49 robfinch
    .wadr(L1_adr),
1033
    .i(L2_rdat),
1034
    .o(insn2b),
1035
    .hit(ihit2),
1036
    .invall(invic),
1037
    .invline(L1_invline)
1038
);
1039
end
1040
else
1041
assign ihit2 = 1'b1;
1042
end
1043
endgenerate
1044
 
1045 48 robfinch
FT64_L2_icache uic2
1046
(
1047
    .rst(rst),
1048
    .clk(clk),
1049
    .nxt(L2_nxt),
1050
    .wr(bstate==B7 && ack_i),
1051
    .xsel(L2_xsel),
1052
    .adr(L2_adr),
1053
    .cnt(iccnt),
1054
    .exv_i(exvq),
1055
    .i(dat_i),
1056
    .err_i(errq),
1057
    .o(L2_dato),
1058 49 robfinch
    .hit(ihitL2),
1059 48 robfinch
    .invall(invic),
1060
    .invline()
1061
);
1062
 
1063
wire predict_taken;
1064
wire predict_taken0;
1065
wire predict_taken1;
1066
wire predict_takenA;
1067
wire predict_takenB;
1068
wire predict_takenC;
1069
wire predict_takenD;
1070
wire predict_takenA1;
1071
wire predict_takenB1;
1072
wire predict_takenC1;
1073
wire predict_takenD1;
1074
 
1075 49 robfinch
wire [`ABITS] btgtA, btgtB, btgtC, btgtD;
1076 48 robfinch
wire btbwr0 = iqentry_v[head0] && iqentry_done[head0] &&
1077
        (
1078 51 robfinch
        iqentry_jal[head0] ||
1079
        iqentry_brk[head0] ||
1080
        iqentry_rti[head0]);
1081 48 robfinch
wire btbwr1 = iqentry_v[head1] && iqentry_done[head1] &&
1082
        (
1083 51 robfinch
        iqentry_jal[head1] ||
1084
        iqentry_brk[head1] ||
1085
        iqentry_rti[head1]);
1086 48 robfinch
 
1087 50 robfinch
wire fcu_clk;
1088 49 robfinch
`ifdef FCU_ENH
1089 50 robfinch
//BUFGCE ufcuclk
1090
//(
1091
//      .I(clk_i),
1092
//      .CE(fcu_available),
1093
//      .O(fcu_clk)
1094
//);
1095 49 robfinch
`endif
1096 50 robfinch
assign fcu_clk = clk_i;
1097 49 robfinch
 
1098
`ifdef FCU_ENH
1099 48 robfinch
FT64_BTB ubtb1
1100
(
1101 49 robfinch
  .rst(rst),
1102
  .wclk(fcu_clk),
1103
  .wr(btbwr0 | btbwr1),
1104
  .wadr(btbwr0 ? iqentry_pc[head0] : iqentry_pc[head1]),
1105
  .wdat(btbwr0 ? iqentry_a0[head0] : iqentry_a0[head1]),
1106
  .valid(btbwr0 ? iqentry_bt[head0] & iqentry_v[head0] : iqentry_bt[head1] & iqentry_v[head1]),
1107
  .rclk(~clk),
1108
  .pcA(fetchbufA_pc),
1109
  .btgtA(btgtA),
1110
  .pcB(fetchbufB_pc),
1111
  .btgtB(btgtB),
1112
  .pcC(fetchbufC_pc),
1113
  .btgtC(btgtC),
1114
  .pcD(fetchbufD_pc),
1115
  .btgtD(btgtD),
1116
  .npcA(BRKPC),
1117
  .npcB(BRKPC),
1118
  .npcC(BRKPC),
1119
  .npcD(BRKPC)
1120 48 robfinch
);
1121 49 robfinch
`else
1122
// Branch tergets are picked up by fetchbuf logic and need to be present.
1123
// Without a target predictor they are just set to the reset address.
1124
// This virtually guarentees a miss.
1125
assign btgtA = RSTPC;
1126
assign btgtB = RSTPC;
1127
assign btgtC = RSTPC;
1128
assign btgtD = RSTPC;
1129
`endif
1130 48 robfinch
 
1131 49 robfinch
`ifdef FCU_ENH
1132 48 robfinch
FT64_BranchPredictor ubp1
1133
(
1134 49 robfinch
  .rst(rst),
1135
  .clk(fcu_clk),
1136
  .en(bpe),
1137
  .xisBranch0(iqentry_br[head0] & commit0_v),
1138
  .xisBranch1(iqentry_br[head1] & commit1_v),
1139
  .pcA(fetchbufA_pc),
1140
  .pcB(fetchbufB_pc),
1141
  .pcC(fetchbufC_pc),
1142
  .pcD(fetchbufD_pc),
1143
  .xpc0(iqentry_pc[head0]),
1144
  .xpc1(iqentry_pc[head1]),
1145 52 robfinch
  .takb0(commit0_v & iqentry_takb[head0]),
1146
  .takb1(commit1_v & iqentry_takb[head1]),
1147 49 robfinch
  .predict_takenA(predict_takenA),
1148
  .predict_takenB(predict_takenB),
1149
  .predict_takenC(predict_takenC),
1150
  .predict_takenD(predict_takenD)
1151 48 robfinch
);
1152 49 robfinch
`else
1153
// Predict based on sign of displacement
1154
assign predict_takenA = fetchbufA_instr[31];
1155
assign predict_takenB = fetchbufB_instr[31];
1156
assign predict_takenC = fetchbufC_instr[31];
1157
assign predict_takenD = fetchbufD_instr[31];
1158
`endif
1159 48 robfinch
 
1160
//-----------------------------------------------------------------------------
1161
// Debug
1162
//-----------------------------------------------------------------------------
1163
`ifdef SUPPORT_DBG
1164
 
1165
wire [DBW-1:0] dbg_stat1x;
1166
reg [DBW-1:0] dbg_stat;
1167
reg [DBW-1:0] dbg_ctrl;
1168
reg [ABW-1:0] dbg_adr0;
1169
reg [ABW-1:0] dbg_adr1;
1170
reg [ABW-1:0] dbg_adr2;
1171
reg [ABW-1:0] dbg_adr3;
1172
reg dbg_imatchA0,dbg_imatchA1,dbg_imatchA2,dbg_imatchA3,dbg_imatchA;
1173
reg dbg_imatchB0,dbg_imatchB1,dbg_imatchB2,dbg_imatchB3,dbg_imatchB;
1174
 
1175
wire dbg_lmatch00 =
1176
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1177
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1178
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1179
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1180
                                 dbg_ctrl[19:18]==2'b11)
1181
                                 ;
1182
wire dbg_lmatch01 =
1183
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1184
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1185
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1186
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1187
                  dbg_ctrl[19:18]==2'b11)
1188
                  ;
1189
wire dbg_lmatch02 =
1190
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1191
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1192
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1193
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1194
                dbg_ctrl[19:18]==2'b11)
1195
                ;
1196
wire dbg_lmatch10 =
1197
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1198
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1199
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1200
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1201
                  dbg_ctrl[23:22]==2'b11)
1202
                  ;
1203
wire dbg_lmatch11 =
1204
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1205
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1206
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1207
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1208
                dbg_ctrl[23:22]==2'b11)
1209
                ;
1210
wire dbg_lmatch12 =
1211
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1212
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1213
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1214
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1215
                dbg_ctrl[23:22]==2'b11)
1216
                ;
1217
wire dbg_lmatch20 =
1218
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1219
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1220
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1221
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1222
                    dbg_ctrl[27:26]==2'b11)
1223
                    ;
1224
wire dbg_lmatch21 =
1225
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1226
                   ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1227
                    (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1228
                    (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1229
                    dbg_ctrl[27:26]==2'b11)
1230
                    ;
1231
wire dbg_lmatch22 =
1232
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1233
                   ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1234
                    (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1235
                    (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1236
                    dbg_ctrl[27:26]==2'b11)
1237
                    ;
1238
wire dbg_lmatch30 =
1239
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1240
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1241
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1242
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1243
                      dbg_ctrl[31:30]==2'b11)
1244
                      ;
1245
wire dbg_lmatch31 =
1246
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1247
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1248
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1249
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1250
                    dbg_ctrl[31:30]==2'b11)
1251
                    ;
1252
wire dbg_lmatch32 =
1253
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1254
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1255
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1256
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1257
                    dbg_ctrl[31:30]==2'b11)
1258
                    ;
1259
wire dbg_lmatch0 = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30;
1260
wire dbg_lmatch1 = dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31;
1261
wire dbg_lmatch2 = dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32;
1262
wire dbg_lmatch = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30|
1263
                  dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31|
1264
                  dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32
1265
                    ;
1266
 
1267
wire dbg_smatch00 =
1268
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1269
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1270
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1271
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1272
                                 dbg_ctrl[19:18]==2'b11)
1273
                                 ;
1274
wire dbg_smatch01 =
1275
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1276
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1277
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1278
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1279
                  dbg_ctrl[19:18]==2'b11)
1280
                  ;
1281
wire dbg_smatch02 =
1282
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1283
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1284
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1285
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1286
                dbg_ctrl[19:18]==2'b11)
1287
                ;
1288
wire dbg_smatch10 =
1289
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1290
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1291
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1292
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1293
                  dbg_ctrl[23:22]==2'b11)
1294
                  ;
1295
wire dbg_smatch11 =
1296
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1297
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1298
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1299
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1300
                dbg_ctrl[23:22]==2'b11)
1301
                ;
1302
wire dbg_smatch12 =
1303
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1304
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1305
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1306
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1307
                dbg_ctrl[23:22]==2'b11)
1308
                ;
1309
wire dbg_smatch20 =
1310
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1311
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1312
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1313
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1314
                    dbg_ctrl[27:26]==2'b11)
1315
                    ;
1316
wire dbg_smatch21 =
1317
           dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1318
                    ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1319
                     (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1320
                     (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1321
                     dbg_ctrl[27:26]==2'b11)
1322
                     ;
1323
wire dbg_smatch22 =
1324
            dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1325
                     ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1326
                      (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1327
                      (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1328
                      dbg_ctrl[27:26]==2'b11)
1329
                      ;
1330
wire dbg_smatch30 =
1331
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1332
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1333
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1334
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1335
                      dbg_ctrl[31:30]==2'b11)
1336
                      ;
1337
wire dbg_smatch31 =
1338
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1339
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1340
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1341
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1342
                    dbg_ctrl[31:30]==2'b11)
1343
                    ;
1344
wire dbg_smatch32 =
1345
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1346
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1347
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1348
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1349
                    dbg_ctrl[31:30]==2'b11)
1350
                    ;
1351
wire dbg_smatch0 = dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30;
1352
wire dbg_smatch1 = dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31;
1353
wire dbg_smatch2 = dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32;
1354
 
1355
wire dbg_smatch =   dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30|
1356
                    dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31|
1357
                    dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32
1358
                    ;
1359
 
1360
wire dbg_stat0 = dbg_imatchA0 | dbg_imatchB0 | dbg_lmatch00 | dbg_lmatch01 | dbg_lmatch02 | dbg_smatch00 | dbg_smatch01 | dbg_smatch02;
1361
wire dbg_stat1 = dbg_imatchA1 | dbg_imatchB1 | dbg_lmatch10 | dbg_lmatch11 | dbg_lmatch12 | dbg_smatch10 | dbg_smatch11 | dbg_smatch12;
1362
wire dbg_stat2 = dbg_imatchA2 | dbg_imatchB2 | dbg_lmatch20 | dbg_lmatch21 | dbg_lmatch22 | dbg_smatch20 | dbg_smatch21 | dbg_smatch22;
1363
wire dbg_stat3 = dbg_imatchA3 | dbg_imatchB3 | dbg_lmatch30 | dbg_lmatch31 | dbg_lmatch32 | dbg_smatch30 | dbg_smatch31 | dbg_smatch32;
1364
assign dbg_stat1x = {dbg_stat3,dbg_stat2,dbg_stat1,dbg_stat0};
1365
wire debug_on = |dbg_ctrl[3:0]|dbg_ctrl[7]|dbg_ctrl[63];
1366
 
1367
always @*
1368
begin
1369
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf0_pc==dbg_adr0)
1370
        dbg_imatchA0 = `TRUE;
1371
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf0_pc==dbg_adr1)
1372
        dbg_imatchA1 = `TRUE;
1373
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf0_pc==dbg_adr2)
1374
        dbg_imatchA2 = `TRUE;
1375
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf0_pc==dbg_adr3)
1376
        dbg_imatchA3 = `TRUE;
1377
    if (dbg_imatchA0|dbg_imatchA1|dbg_imatchA2|dbg_imatchA3)
1378
        dbg_imatchA = `TRUE;
1379
end
1380
 
1381
always @*
1382
begin
1383
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf1_pc==dbg_adr0)
1384
        dbg_imatchB0 = `TRUE;
1385
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf1_pc==dbg_adr1)
1386
        dbg_imatchB1 = `TRUE;
1387
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf1_pc==dbg_adr2)
1388
        dbg_imatchB2 = `TRUE;
1389
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf1_pc==dbg_adr3)
1390
        dbg_imatchB3 = `TRUE;
1391
    if (dbg_imatchB0|dbg_imatchB1|dbg_imatchB2|dbg_imatchB3)
1392
        dbg_imatchB = `TRUE;
1393
end
1394
`endif
1395
 
1396
//-----------------------------------------------------------------------------
1397
//-----------------------------------------------------------------------------
1398
 
1399 52 robfinch
// freezePC squashes the pc increment if there's an irq.
1400
wire freezePC = (irq_i > im) && ~int_commit;
1401 48 robfinch
always @*
1402 52 robfinch
if (freezePC)
1403 49 robfinch
        insn0 <= {8'd0,3'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1404 48 robfinch
else if (phit) begin
1405 49 robfinch
        if (insn0a[`INSTRUCTION_OP]==`BRK && insn0a[23:21]==3'd0 && insn0a[7:6]==2'b00)
1406
                insn0 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1407 48 robfinch
        else
1408
                insn0 <= insn0a;
1409
end
1410
else
1411
        insn0 <= `NOP_INSN;
1412 49 robfinch
generate begin : gInsnMux
1413
if (`WAYS > 1) begin
1414 48 robfinch
always @*
1415 52 robfinch
if (freezePC && !thread_en)
1416
        insn1 <= {8'd0,3'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1417
else if (phit) begin
1418 49 robfinch
        if (insn1a[`INSTRUCTION_OP]==`BRK && insn1a[23:21]==3'd0 && insn1a[7:6]==2'b00)
1419
                insn1 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1420 48 robfinch
        else
1421
                insn1 <= insn1a;
1422
end
1423
else
1424
        insn1 <= `NOP_INSN;
1425 49 robfinch
end
1426
if (`WAYS > 2) begin
1427
always @*
1428 52 robfinch
if (freezePC && !thread_en)
1429
        insn2 <= {8'd0,3'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1430
else if (phit) begin
1431 49 robfinch
        if (insn2a[`INSTRUCTION_OP]==`BRK && insn1a[23:21]==3'd0 && insn2a[7:6]==2'b00)
1432
                insn2 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1433
        else
1434
                insn2 <= insn2a;
1435
end
1436
else
1437
        insn2 <= `NOP_INSN;
1438
end
1439
end
1440
endgenerate
1441 48 robfinch
 
1442
wire [63:0] dc0_out, dc1_out, dc2_out;
1443
assign rdat0 = dram0_unc ? xdati : dc0_out;
1444
assign rdat1 = dram1_unc ? xdati : dc1_out;
1445
assign rdat2 = dram2_unc ? xdati : dc2_out;
1446
 
1447
reg preload;
1448
reg [1:0] dccnt;
1449
wire dhit0, dhit1, dhit2;
1450
wire dhit00, dhit10, dhit20;
1451
wire dhit01, dhit11, dhit21;
1452 49 robfinch
reg [`ABITS] dc_wadr;
1453 48 robfinch
reg [63:0] dc_wdat;
1454
reg isStore;
1455
 
1456
FT64_dcache udc0
1457
(
1458
    .rst(rst),
1459
    .wclk(clk),
1460
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && dhit0)),
1461
    .sel(sel_o),
1462
    .wadr({pcr[5:0],adr_o}),
1463
    .i(bstate==B2d ? dat_i : dat_o),
1464
    .rclk(clk),
1465
    .rdsize(dram0_memsize),
1466
    .radr({pcr[5:0],dram0_addr}),
1467
    .o(dc0_out),
1468
    .hit(),
1469
    .hit0(dhit0),
1470
    .hit1()
1471
);
1472 49 robfinch
generate begin : gDCacheInst
1473
if (`NUM_MEM > 1) begin
1474 48 robfinch
FT64_dcache udc1
1475
(
1476
    .rst(rst),
1477
    .wclk(clk),
1478
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && dhit1)),
1479
    .sel(sel_o),
1480
    .wadr({pcr[5:0],adr_o}),
1481
    .i(bstate==B2d ? dat_i : dat_o),
1482
    .rclk(clk),
1483
    .rdsize(dram1_memsize),
1484
    .radr({pcr[5:0],dram1_addr}),
1485
    .o(dc1_out),
1486
    .hit(),
1487
    .hit0(dhit1),
1488
    .hit1()
1489
);
1490 49 robfinch
end
1491
if (`NUM_MEM > 2) begin
1492 48 robfinch
FT64_dcache udc2
1493
(
1494
    .rst(rst),
1495
    .wclk(clk),
1496
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && dhit2)),
1497
    .sel(sel_o),
1498
    .wadr({pcr[5:0],adr_o}),
1499
    .i(bstate==B2d ? dat_i : dat_o),
1500
    .rclk(clk),
1501
    .rdsize(dram2_memsize),
1502
    .radr({pcr[5:0],dram2_addr}),
1503
    .o(dc2_out),
1504
    .hit(),
1505
    .hit0(dhit2),
1506
    .hit1()
1507
);
1508 49 robfinch
end
1509
end
1510
endgenerate
1511 48 robfinch
 
1512
function [`QBITS] idp1;
1513
input [`QBITS] id;
1514 52 robfinch
idp1 = (id + 1) % QENTRIES;
1515 48 robfinch
endfunction
1516
 
1517
function [`QBITS] idp2;
1518
input [`QBITS] id;
1519 52 robfinch
idp2 = (id + 2) % QENTRIES;
1520 48 robfinch
endfunction
1521
 
1522
function [`QBITS] idp3;
1523
input [`QBITS] id;
1524 52 robfinch
idp3 = (id + 3) % QENTRIES;
1525 48 robfinch
endfunction
1526
 
1527
function [`QBITS] idp4;
1528
input [`QBITS] id;
1529 52 robfinch
idp4 = (id + 4) % QENTRIES;
1530 48 robfinch
endfunction
1531
 
1532
function [`QBITS] idp5;
1533
input [`QBITS] id;
1534 52 robfinch
idp5 = (id + 5) % QENTRIES;
1535 48 robfinch
endfunction
1536
 
1537
function [`QBITS] idp6;
1538
input [`QBITS] id;
1539 52 robfinch
idp6 = (id + 6) % QENTRIES;
1540 48 robfinch
endfunction
1541
 
1542
function [`QBITS] idp7;
1543
input [`QBITS] id;
1544 52 robfinch
idp7 = (id + 7) % QENTRIES;
1545 48 robfinch
endfunction
1546
 
1547 52 robfinch
function [`QBITS] idp8;
1548
input [`QBITS] id;
1549
idp8 = (id + 8) % QENTRIES;
1550
endfunction
1551
 
1552
function [`QBITS] idp9;
1553
input [`QBITS] id;
1554
idp9 = (id + 9) % QENTRIES;
1555
endfunction
1556
 
1557 48 robfinch
function [`QBITS] idm1;
1558
input [`QBITS] id;
1559 52 robfinch
idm1 = (id - 1) % QENTRIES;
1560 48 robfinch
endfunction
1561
 
1562
`ifdef SUPPORT_SMT
1563
function [RBIT:0] fnRa;
1564
input [47:0] isn;
1565
input [5:0] vqei;
1566
input [5:0] vli;
1567
input thrd;
1568
case(isn[`INSTRUCTION_OP])
1569
`IVECTOR:
1570
        case(isn[`INSTRUCTION_S2])
1571
        `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1572
        `VMxx:
1573
                case(isn[25:23])
1574
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
1575
                    fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1576
            `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1577
            default:fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1578
            endcase
1579
        `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
1580
        `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
1581
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1582
        default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1583
        endcase
1584 50 robfinch
`R2:    casez(isn[`INSTRUCTION_S2])
1585 48 robfinch
                `MOV:
1586
                        case(isn[25:23])
1587
                        3'd0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1588 50 robfinch
                        3'd1:   fnRa = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
1589 48 robfinch
                        3'd2:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1590
                        3'd3:   fnRa = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RA]};
1591
                        3'd4:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1592 51 robfinch
                        3'd5:   fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1593
                        3'd6:   fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1594 48 robfinch
                        default:fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1595
                        endcase
1596
        `VMOV:
1597
            case (isn[`INSTRUCTION_S1])
1598
            5'h0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1599
            5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
1600
            endcase
1601
        default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1602
        endcase
1603 51 robfinch
`FLOAT:         fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1604 48 robfinch
default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1605
endcase
1606
endfunction
1607
 
1608
function [RBIT:0] fnRb;
1609
input [47:0] isn;
1610
input fb;
1611
input [5:0] vqei;
1612
input [5:0] rfoa0i;
1613
input [5:0] rfoa1i;
1614
input thrd;
1615
case(isn[`INSTRUCTION_OP])
1616
`R2:        case(isn[`INSTRUCTION_S2])
1617
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
1618
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1619
            default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1620
            endcase
1621
`IVECTOR:
1622
                        case(isn[`INSTRUCTION_S2])
1623
                        `VMxx:
1624
                                case(isn[25:23])
1625
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
1626
                        fnRb = {6'h3F,1'b1,2'b0,isn[13:11]};
1627
                default:        fnRb = 12'h000;
1628
                endcase
1629
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1630
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1631
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
1632
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
1633
                fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1634
            `VSHL,`VSHR,`VASR:
1635
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
1636
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1637
            endcase
1638 51 robfinch
`FLOAT:         fnRb = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1639 48 robfinch
default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1640
endcase
1641
endfunction
1642
 
1643
function [RBIT:0] fnRc;
1644
input [47:0] isn;
1645
input [5:0] vqei;
1646
input thrd;
1647
case(isn[`INSTRUCTION_OP])
1648
`R2:        case(isn[`INSTRUCTION_S2])
1649
            `SVX:       fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1650
                `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1651
                        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1652
                `CMOVEZ,`CMOVNZ,`MAJ:
1653
                        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1654
            default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1655
            endcase
1656
`IVECTOR:
1657
                        case(isn[`INSTRUCTION_S2])
1658
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[18:16]};
1659
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1660
            endcase
1661 51 robfinch
`FLOAT:         fnRc = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1662 48 robfinch
default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1663
endcase
1664
endfunction
1665
 
1666
function [RBIT:0] fnRt;
1667
input [47:0] isn;
1668
input [5:0] vqei;
1669
input [5:0] vli;
1670
input thrd;
1671
casez(isn[`INSTRUCTION_OP])
1672
`IVECTOR:
1673
                case(isn[`INSTRUCTION_S2])
1674
                `VMxx:
1675
                        case(isn[25:23])
1676
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
1677
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1678
            `VMPOP:     fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1679
            default:
1680
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1681
            endcase
1682
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1683
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
1684
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
1685
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
1686
        `V2BITS:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1687
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1688
        endcase
1689
 
1690 50 robfinch
`R2:    casez(isn[`INSTRUCTION_S2])
1691 48 robfinch
                `MOV:
1692
                        case(isn[25:23])
1693 50 robfinch
                        3'd0:   fnRt = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RB]};
1694 48 robfinch
                        3'd1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1695
                        3'd2:   fnRt = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RB]};
1696
                        3'd3:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1697 51 robfinch
                        3'd4:   fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1698 48 robfinch
                        3'd5:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1699 51 robfinch
                        3'd6:   fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1700 48 robfinch
                        default:fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1701
                        endcase
1702
        `VMOV:
1703
            case (isn[`INSTRUCTION_S1])
1704
            5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RB]};
1705
            5'h1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1706
            default:    fnRt = 12'h000;
1707
            endcase
1708
        `R1:
1709
                case(isn[22:18])
1710
                `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT:
1711
                        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1712
                `MEMDB,`MEMSB,`SYNC:
1713
                        fnRt = 12'd0;
1714
                default:        fnRt = 12'd0;
1715
                endcase
1716
        `CMOVEZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1717
        `CMOVNZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1718
        `MUX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1719
        `MIN:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1720
        `MAX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1721
        `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
1722
        `SHIFTR:        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1723
        `SHIFT31,`SHIFT63:
1724
                                fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1725
        `SEI:           fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1726
        `WAIT,`RTI,`CHK:
1727
                        fnRt = 12'd0;
1728
                default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1729
        endcase
1730
`MEMNDX:
1731
    case(isn[`INSTRUCTION_S2])
1732
    `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1733
                        fnRt = 12'd0;
1734
    default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1735
        endcase
1736
`FLOAT:
1737
                case(isn[31:26])
1738
                `FTX,`FCX,`FEX,`FDX,`FRM:
1739
                                        fnRt = 12'd0;
1740
                `FSYNC:         fnRt = 12'd0;
1741 51 robfinch
                default:        fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1742 48 robfinch
                endcase
1743
`BRK:   fnRt = 12'd0;
1744
`REX:   fnRt = 12'd0;
1745
`CHK:   fnRt = 12'd0;
1746
`EXEC:  fnRt = 12'd0;
1747
`Bcc:   fnRt = 12'd0;
1748
`BBc:   case(isn[20:19])
1749
                `IBNE:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1750
                `DBNZ:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1751
                default:        fnRt = 12'd0;
1752
                endcase
1753
`BEQI:  fnRt = 12'd0;
1754
`SB,`Sx,`SWC,`CACHE:
1755
                fnRt = 12'd0;
1756
`JMP:   fnRt = 12'd0;
1757
`CALL:  fnRt = {rgs[thrd],1'b0,regLR};  // regLR
1758
`RET:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1759
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1760
`AMO:   fnRt = isn[31] ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1761
default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1762
endcase
1763
endfunction
1764
`else
1765
function [RBIT:0] fnRa;
1766
input [47:0] isn;
1767
input [5:0] vqei;
1768
input [5:0] vli;
1769
input thrd;
1770
case(isn[`INSTRUCTION_OP])
1771
`IVECTOR:
1772
        case(isn[`INSTRUCTION_S2])
1773 51 robfinch
  `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1774
  `VMxx:
1775
        case(isn[25:23])
1776
        `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
1777
              fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1778
      `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1779
      default:fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1780
      endcase
1781
  `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
1782
  `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
1783
  `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1784
  default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1785
  endcase
1786 50 robfinch
`R2:
1787
        casez(isn[`INSTRUCTION_S2])
1788
        `MOV:
1789
                case(isn[25:23])
1790
                3'd0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1791
                3'd1:   fnRa = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
1792
                3'd2:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1793
                3'd3:   fnRa = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RA]};
1794
                3'd4:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1795 51 robfinch
                3'd5:   fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
1796
                3'd6:   fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
1797 50 robfinch
                default:fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1798
                endcase
1799
  `VMOV:
1800
    case (isn[`INSTRUCTION_S1])
1801
    5'h0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1802
    5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
1803
    endcase
1804
  default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1805
  endcase
1806 51 robfinch
`FLOAT:         fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
1807 48 robfinch
default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1808
endcase
1809
endfunction
1810
 
1811
function [RBIT:0] fnRb;
1812
input [47:0] isn;
1813
input fb;
1814
input [5:0] vqei;
1815
input [5:0] rfoa0i;
1816
input [5:0] rfoa1i;
1817
input thrd;
1818
case(isn[`INSTRUCTION_OP])
1819
`RR:        case(isn[`INSTRUCTION_S2])
1820
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
1821
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1822
            default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1823
            endcase
1824
`IVECTOR:
1825
                        case(isn[`INSTRUCTION_S2])
1826
                        `VMxx:
1827
                                case(isn[25:23])
1828
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
1829
                        fnRb = {6'h3F,1'b1,2'b0,isn[13:11]};
1830
                default:        fnRb = 12'h000;
1831
                endcase
1832
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1833
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1834
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
1835
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
1836
                fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1837
            `VSHL,`VSHR,`VASR:
1838
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
1839
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1840
            endcase
1841 51 robfinch
`FLOAT:         fnRb = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
1842 48 robfinch
default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1843
endcase
1844
endfunction
1845
 
1846
function [RBIT:0] fnRc;
1847
input [47:0] isn;
1848
input [5:0] vqei;
1849
input thrd;
1850
case(isn[`INSTRUCTION_OP])
1851
`R2:        case(isn[`INSTRUCTION_S2])
1852
            `SVX:       fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1853
                `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1854
                        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1855
                `CMOVEZ,`CMOVNZ,`MAJ:
1856
                        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1857
            default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1858
            endcase
1859
`IVECTOR:
1860
                        case(isn[`INSTRUCTION_S2])
1861
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[18:16]};
1862
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1863
            endcase
1864 51 robfinch
`FLOAT:         fnRc = {fp_rgs,1'b0,isn[`INSTRUCTION_RC]};
1865 48 robfinch
default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1866
endcase
1867
endfunction
1868
 
1869
function [RBIT:0] fnRt;
1870
input [47:0] isn;
1871
input [5:0] vqei;
1872
input [5:0] vli;
1873
input thrd;
1874
casez(isn[`INSTRUCTION_OP])
1875
`IVECTOR:
1876
                case(isn[`INSTRUCTION_S2])
1877
                `VMxx:
1878
                        case(isn[25:23])
1879
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
1880
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1881
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1882
            default:
1883
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1884
            endcase
1885
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1886
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
1887
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
1888
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
1889
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1890
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1891
        endcase
1892
 
1893
`FVECTOR:
1894
                case(isn[`INSTRUCTION_S2])
1895
                `VMxx:
1896
                        case(isn[25:23])
1897
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
1898
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1899
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1900
            default:
1901
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1902
            endcase
1903
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1904
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
1905
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
1906
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
1907
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1908
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1909
        endcase
1910
 
1911 50 robfinch
`R2:
1912
        casez(isn[`INSTRUCTION_S2])
1913
        `MOV:
1914
                case(isn[25:23])
1915
                3'd0:   fnRt = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RB]};
1916
                3'd1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1917
                3'd2:   fnRt = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RB]};
1918
                3'd3:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1919 51 robfinch
                3'd4:   fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
1920 50 robfinch
                3'd5:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1921 51 robfinch
                3'd6:   fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
1922 50 robfinch
                default:fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1923
                endcase
1924
  `VMOV:
1925
    case (isn[`INSTRUCTION_S1])
1926
    5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RB]};
1927
    5'h1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1928
    default:    fnRt = 12'h000;
1929
    endcase
1930
  `R1:
1931
        case(isn[22:18])
1932
        `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT:
1933
                fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1934
        `MEMDB,`MEMSB,`SYNC:
1935
                fnRt = 12'd0;
1936
        default:        fnRt = 12'd0;
1937
        endcase
1938
  `CMOVEZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
1939
  `CMOVNZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
1940
  `MUX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
1941
  `MIN:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
1942
  `MAX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
1943
  `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
1944
  `SHIFTR:      fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1945
  `SHIFT31,`SHIFT63:
1946
                        fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1947
  `SEI:         fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1948
  `WAIT,`RTI,`CHK:
1949
                        fnRt = 12'd0;
1950
  default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1951
  endcase
1952 48 robfinch
`MEMNDX:
1953
        case(isn[`INSTRUCTION_S2])
1954
  `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1955
                        fnRt = 12'd0;
1956
  default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1957
  endcase
1958
`FLOAT:
1959
                case(isn[31:26])
1960
                `FTX,`FCX,`FEX,`FDX,`FRM:
1961
                                        fnRt = 12'd0;
1962
                `FSYNC:         fnRt = 12'd0;
1963 51 robfinch
                default:        fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RC]};
1964 48 robfinch
                endcase
1965
`BRK:   fnRt = 12'd0;
1966
`REX:   fnRt = 12'd0;
1967
`CHK:   fnRt = 12'd0;
1968
`EXEC:  fnRt = 12'd0;
1969
`Bcc:   fnRt = 12'd0;
1970
`BBc:
1971
        case(isn[20:19])
1972
        `IBNE:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1973
        `DBNZ:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1974
        default:        fnRt = 12'd0;
1975
        endcase
1976
`BEQI:  fnRt = 12'd0;
1977
`SB,`Sx,`SWC,`CACHE:
1978
                fnRt = 12'd0;
1979
`JMP:   fnRt = 12'd0;
1980
`CALL:  fnRt = {rgs,1'b0,regLR};        // regLR
1981
`RET:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1982
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1983
`AMO:   fnRt = isn[31] ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {rgs,1'b0,isn[`INSTRUCTION_RC]};
1984
default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1985
endcase
1986
endfunction
1987
`endif
1988
 
1989
// Determines which lanes of the target register get updated.
1990
function [7:0] fnWe;
1991
input [47:0] isn;
1992
casez(isn[`INSTRUCTION_OP])
1993
`R2:
1994
        case(isn[`INSTRUCTION_S2])
1995
        `R1:
1996
                case(isn[22:18])
1997
                `ABS,`CNTLZ,`CNTLO,`CNTPOP:
1998
                        case(isn[25:23])
1999
                        3'b000: fnWe = 8'h01;
2000
                        3'b001: fnWe = 8'h03;
2001
                        3'b010: fnWe = 8'h0F;
2002
                        3'b011: fnWe = 8'hFF;
2003
                        default:        fnWe = 8'hFF;
2004
                        endcase
2005
                default: fnWe = 8'hFF;
2006
                endcase
2007
        `SHIFT31:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2008
        `SHIFT63:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2009
        `SLT,`SLTU,`SLE,`SLEU,
2010
        `ADD,`SUB,
2011
        `AND,`OR,`XOR,
2012
        `NAND,`NOR,`XNOR,
2013 50 robfinch
        `DIV,`DIVU,`DIVSU,
2014
        `MOD,`MODU,`MODSU,
2015
        `MUL,`MULU,`MULSU,
2016
        `MULH,`MULUH,`MULSUH:
2017 48 robfinch
                case(isn[25:23])
2018
                3'b000: fnWe = 8'h01;
2019
                3'b001: fnWe = 8'h03;
2020
                3'b010: fnWe = 8'h0F;
2021
                3'b011: fnWe = 8'hFF;
2022
                default:        fnWe = 8'hFF;
2023
                endcase
2024
        default: fnWe = 8'hFF;
2025
        endcase
2026
default:        fnWe = 8'hFF;
2027
endcase
2028
endfunction
2029
 
2030
// Detect if a source is automatically valid
2031
function Source1Valid;
2032
input [47:0] isn;
2033
casez(isn[`INSTRUCTION_OP])
2034
`BRK:   Source1Valid = TRUE;
2035
`Bcc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2036
`BBc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2037
`BEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2038
`CHK:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2039
`RR:    case(isn[`INSTRUCTION_S2])
2040
        `SHIFT31:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2041
        `SHIFT63:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2042
        `SHIFTR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2043
        default:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2044
        endcase
2045
`MEMNDX:Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2046
`ADDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2047
`SLTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2048
`SLTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2049
`SGTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2050
`SGTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2051
`ANDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2052
`ORI:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2053
`XORI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2054
`XNORI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2055
`MULUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2056
`AMO:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2057
`LB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2058
`LBU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2059
`Lx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2060
`LxU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2061
`LWR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2062
`LV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2063
`LVx:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2064
`SB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2065
`Sx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2066
`SWC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2067
`SV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2068
`INC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2069
`CAS:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2070
`JAL:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2071
`RET:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2072
`CSRRW: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2073 51 robfinch
`BITFIELD:      case(isn[47:44])
2074
        `BFINSI:        Source1Valid = TRUE;
2075
        default:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0 || isn[30]==1'b0;
2076
        endcase
2077 48 robfinch
`IVECTOR:
2078 51 robfinch
        Source1Valid = FALSE;
2079 48 robfinch
default:    Source1Valid = TRUE;
2080
endcase
2081
endfunction
2082
 
2083
function Source2Valid;
2084
input [47:0] isn;
2085
casez(isn[`INSTRUCTION_OP])
2086
`BRK:   Source2Valid = TRUE;
2087
`Bcc:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2088
`BBc:   Source2Valid = TRUE;
2089
`BEQI:  Source2Valid = TRUE;
2090
`CHK:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2091
`RR:    case(isn[`INSTRUCTION_S2])
2092
        `R1:       Source2Valid = TRUE;
2093
        `SHIFTR:   Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2094
        `SHIFT31:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2095
        `SHIFT63:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2096
        `LVX,`SVX: Source2Valid = FALSE;
2097
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2098
        endcase
2099
`MEMNDX:
2100
        case(isn[`INSTRUCTION_S2])
2101
        `LVX,`SVX: Source2Valid = FALSE;
2102
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2103
        endcase
2104
`ADDI:  Source2Valid = TRUE;
2105
`SLTI:  Source2Valid = TRUE;
2106
`SLTUI: Source2Valid = TRUE;
2107
`SGTI:  Source2Valid = TRUE;
2108
`SGTUI: Source2Valid = TRUE;
2109
`ANDI:  Source2Valid = TRUE;
2110
`ORI:   Source2Valid = TRUE;
2111
`XORI:  Source2Valid = TRUE;
2112
`XNORI: Source2Valid = TRUE;
2113
`MULUI: Source2Valid = TRUE;
2114
`LB:    Source2Valid = TRUE;
2115
`LBU:   Source2Valid = TRUE;
2116
`Lx:    Source2Valid = TRUE;
2117
`LxU:   Source2Valid = TRUE;
2118
`LWR:   Source2Valid = TRUE;
2119
`LVx:   Source2Valid = TRUE;
2120
`INC:           Source2Valid = TRUE;
2121
`SB:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2122
`Sx:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2123
`SWC:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2124
`CAS:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2125
`JAL:   Source2Valid = TRUE;
2126
`RET:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2127
`IVECTOR:
2128
                    case(isn[`INSTRUCTION_S2])
2129
            `VABS:  Source2Valid = TRUE;
2130
            `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2131
                Source2Valid = FALSE;
2132
            `VADDS,`VSUBS,`VANDS,`VORS,`VXORS:
2133
                Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2134
            `VBITS2V:   Source2Valid = TRUE;
2135
            `V2BITS:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2136
            `VSHL,`VSHR,`VASR:  Source2Valid = isn[22:21]==2'd2;
2137
            default:    Source2Valid = FALSE;
2138
            endcase
2139
`LV:        Source2Valid = TRUE;
2140
`SV:        Source2Valid = FALSE;
2141
`AMO:           Source2Valid = isn[31] || isn[`INSTRUCTION_RB]==5'd0;
2142 51 robfinch
`BITFIELD:      Source2Valid = isn[`INSTRUCTION_RB]==5'd0 || isn[31]==1'b0;
2143 48 robfinch
default:    Source2Valid = TRUE;
2144
endcase
2145
endfunction
2146
 
2147
function Source3Valid;
2148
input [47:0] isn;
2149
case(isn[`INSTRUCTION_OP])
2150
`IVECTOR:
2151
    case(isn[`INSTRUCTION_S2])
2152
    `VEX:       Source3Valid = TRUE;
2153
    default:    Source3Valid = TRUE;
2154
    endcase
2155
`CHK:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2156
`R2:
2157
        if (isn[`INSTRUCTION_L2]==2'b01)
2158
                case(isn[47:42])
2159
    `CMOVEZ,`CMOVNZ:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2160
                default:        Source3Valid = TRUE;
2161
                endcase
2162
        else
2163
    case(isn[`INSTRUCTION_S2])
2164
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2165
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2166
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2167
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2168
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2169
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2170
    `MAJ:               Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2171
    default:    Source3Valid = TRUE;
2172
    endcase
2173
`MEMNDX:
2174
        if (isn[`INSTRUCTION_L2]==2'b00)
2175
    case(isn[`INSTRUCTION_S2])
2176
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2177
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2178
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2179
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2180
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2181
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2182
    default:    Source3Valid = TRUE;
2183
    endcase
2184 51 robfinch
`BITFIELD:      Source3Valid = isn[`INSTRUCTION_RC]==5'd0 || isn[32]==1'b0;
2185 48 robfinch
default:    Source3Valid = TRUE;
2186
endcase
2187
endfunction
2188
 
2189
// Used to indicate to the queue logic that the instruction needs to be
2190
// recycled to the queue VL number of times.
2191
function IsVector;
2192
input [47:0] isn;
2193
case(isn[`INSTRUCTION_OP])
2194 51 robfinch
`MEMNDX:
2195
  case(isn[`INSTRUCTION_S2])
2196
  `LVX,`SVX:  IsVector = TRUE;
2197
  default:    IsVector = FALSE;
2198
  endcase
2199 48 robfinch
`IVECTOR:
2200 51 robfinch
        case(isn[`INSTRUCTION_S2])
2201
        `VMxx:
2202
                case(isn[25:23])
2203
        `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2204
              IsVector = FALSE;
2205
    default:    IsVector = TRUE;
2206
    endcase
2207
  `VEINS:     IsVector = FALSE;
2208
  `VEX:       IsVector = FALSE;
2209
  default:    IsVector = TRUE;
2210
  endcase
2211 48 robfinch
`LV,`SV:    IsVector = TRUE;
2212
default:    IsVector = FALSE;
2213
endcase
2214
endfunction
2215
 
2216
function IsVeins;
2217
input [47:0] isn;
2218
case(isn[`INSTRUCTION_OP])
2219
`IVECTOR:   IsVeins = isn[`INSTRUCTION_S2]==`VEINS;
2220
default:    IsVeins = FALSE;
2221
endcase
2222
endfunction
2223
 
2224
function IsVex;
2225
input [47:0] isn;
2226
case(isn[`INSTRUCTION_OP])
2227
`IVECTOR:   IsVex = isn[`INSTRUCTION_S2]==`VEX;
2228
default:    IsVex = FALSE;
2229
endcase
2230
endfunction
2231
 
2232
function IsVCmprss;
2233
input [47:0] isn;
2234
case(isn[`INSTRUCTION_OP])
2235
`IVECTOR:   IsVCmprss = isn[`INSTRUCTION_S2]==`VCMPRSS || isn[`INSTRUCTION_S2]==`VCIDX;
2236
default:    IsVCmprss = FALSE;
2237
endcase
2238
endfunction
2239
 
2240
function IsVShifti;
2241
input [47:0] isn;
2242
case(isn[`INSTRUCTION_OP])
2243
`IVECTOR:
2244
                    case(isn[`INSTRUCTION_S2])
2245
            `VSHL,`VSHR,`VASR:
2246
                IsVShifti = {isn[25],isn[22]}==2'd2;
2247
            default:    IsVShifti = FALSE;
2248
            endcase
2249
default:    IsVShifti = FALSE;
2250
endcase
2251
endfunction
2252
 
2253
function IsVLS;
2254
input [47:0] isn;
2255
case(isn[`INSTRUCTION_OP])
2256
`MEMNDX:
2257
    case(isn[`INSTRUCTION_S2])
2258
    `LVX,`SVX,`LVWS,`SVWS:  IsVLS = TRUE;
2259
    default:    IsVLS = FALSE;
2260
    endcase
2261
`LV,`SV:    IsVLS = TRUE;
2262
default:    IsVLS = FALSE;
2263
endcase
2264
endfunction
2265
 
2266
function [1:0] fnM2;
2267
input [31:0] isn;
2268
case(isn[`INSTRUCTION_OP])
2269
`RR:    fnM2 = isn[24:23];
2270
default:    fnM2 = 2'b00;
2271
endcase
2272
endfunction
2273
 
2274
function [0:0] IsMem;
2275
input [47:0] isn;
2276
case(isn[`INSTRUCTION_OP])
2277
`MEMNDX:        IsMem = TRUE;
2278
`AMO:   IsMem = TRUE;
2279
`LB:    IsMem = TRUE;
2280
`LBU:   IsMem = TRUE;
2281
`Lx:    IsMem = TRUE;
2282
`LxU:   IsMem = TRUE;
2283
`LWR:   IsMem = TRUE;
2284
`LV,`SV:    IsMem = TRUE;
2285
`INC:           IsMem = TRUE;
2286
`SB:    IsMem = TRUE;
2287
`Sx:    IsMem = TRUE;
2288
`SWC:   IsMem = TRUE;
2289
`CAS:   IsMem = TRUE;
2290
`LVx:           IsMem = TRUE;
2291
default:    IsMem = FALSE;
2292
endcase
2293
endfunction
2294
 
2295
function IsMemNdx;
2296
input [47:0] isn;
2297
case(isn[`INSTRUCTION_OP])
2298
`MEMNDX:        IsMemNdx = TRUE;
2299
default:    IsMemNdx = FALSE;
2300
endcase
2301
endfunction
2302
 
2303
function IsLoad;
2304
input [47:0] isn;
2305
case(isn[`INSTRUCTION_OP])
2306
`MEMNDX:
2307
        if (isn[`INSTRUCTION_L2]==2'b00)
2308 50 robfinch
    case(isn[`INSTRUCTION_S2])
2309
    `LBX:   IsLoad = TRUE;
2310
    `LBUX:  IsLoad = TRUE;
2311
    `LCX:   IsLoad = TRUE;
2312
    `LCUX:  IsLoad = TRUE;
2313
    `LHX:   IsLoad = TRUE;
2314
    `LHUX:  IsLoad = TRUE;
2315
    `LWX:   IsLoad = TRUE;
2316
    `LVBX:      IsLoad = TRUE;
2317
    `LVBUX: IsLoad = TRUE;
2318
    `LVCX:  IsLoad = TRUE;
2319
    `LVCUX: IsLoad = TRUE;
2320
    `LVHX:  IsLoad = TRUE;
2321
    `LVHUX: IsLoad = TRUE;
2322
    `LVWX:  IsLoad = TRUE;
2323
    `LWRX:  IsLoad = TRUE;
2324
    `LVX:   IsLoad = TRUE;
2325
    default: IsLoad = FALSE;
2326
    endcase
2327 48 robfinch
        else
2328
                IsLoad = FALSE;
2329
`LB:    IsLoad = TRUE;
2330
`LBU:   IsLoad = TRUE;
2331
`Lx:    IsLoad = TRUE;
2332
`LxU:   IsLoad = TRUE;
2333
`LWR:   IsLoad = TRUE;
2334
`LV:    IsLoad = TRUE;
2335
`LVx:   IsLoad = TRUE;
2336
default:    IsLoad = FALSE;
2337
endcase
2338
endfunction
2339
 
2340
function IsInc;
2341
input [47:0] isn;
2342
case(isn[`INSTRUCTION_OP])
2343
`MEMNDX:
2344
        if (isn[`INSTRUCTION_L2]==2'b00)
2345
                case(isn[`INSTRUCTION_S2])
2346
            `INC:   IsInc = TRUE;
2347
            default:    IsInc = FALSE;
2348
            endcase
2349
        else
2350
                IsInc = FALSE;
2351
`INC:    IsInc = TRUE;
2352
default:    IsInc = FALSE;
2353
endcase
2354
endfunction
2355
 
2356
function IsSWC;
2357
input [47:0] isn;
2358
case(isn[`INSTRUCTION_OP])
2359
`MEMNDX:
2360
        if (isn[`INSTRUCTION_L2]==2'b00)
2361
                case(isn[`INSTRUCTION_S2])
2362
            `SWCX:   IsSWC = TRUE;
2363
            default:    IsSWC = FALSE;
2364
            endcase
2365
        else
2366
                IsSWC = FALSE;
2367
`SWC:    IsSWC = TRUE;
2368
default:    IsSWC = FALSE;
2369
endcase
2370
endfunction
2371
 
2372
// Aquire / release bits are only available on indexed SWC / LWR
2373
function IsSWCX;
2374
input [47:0] isn;
2375
case(isn[`INSTRUCTION_OP])
2376
`MEMNDX:
2377
        if (isn[`INSTRUCTION_L2]==2'b00)
2378
            case(isn[`INSTRUCTION_S2])
2379
            `SWCX:   IsSWCX = TRUE;
2380
            default:    IsSWCX = FALSE;
2381
            endcase
2382
        else
2383
                IsSWCX = FALSE;
2384
default:    IsSWCX = FALSE;
2385
endcase
2386
endfunction
2387
 
2388
function IsLWR;
2389
input [47:0] isn;
2390
case(isn[`INSTRUCTION_OP])
2391
`MEMNDX:
2392
        if (isn[`INSTRUCTION_L2]==2'b00)
2393
            case(isn[`INSTRUCTION_S2])
2394
            `LWRX:   IsLWR = TRUE;
2395
            default:    IsLWR = FALSE;
2396
            endcase
2397
        else
2398
                IsLWR = FALSE;
2399
`LWR:    IsLWR = TRUE;
2400
default:    IsLWR = FALSE;
2401
endcase
2402
endfunction
2403
 
2404
function IsLWRX;
2405
input [47:0] isn;
2406
case(isn[`INSTRUCTION_OP])
2407
`MEMNDX:
2408
        if (isn[`INSTRUCTION_L2]==2'b00)
2409
            case(isn[`INSTRUCTION_S2])
2410
            `LWRX:   IsLWRX = TRUE;
2411
            default:    IsLWRX = FALSE;
2412
            endcase
2413
        else
2414
                IsLWRX = FALSE;
2415
default:    IsLWRX = FALSE;
2416
endcase
2417
endfunction
2418
 
2419
function IsCAS;
2420
input [47:0] isn;
2421
case(isn[`INSTRUCTION_OP])
2422
`MEMNDX:
2423
        if (isn[`INSTRUCTION_L2]==2'b00)
2424
            case(isn[`INSTRUCTION_S2])
2425
            `CASX:   IsCAS = TRUE;
2426
            default:    IsCAS = FALSE;
2427
            endcase
2428
        else
2429
                IsCAS = FALSE;
2430
`CAS:       IsCAS = TRUE;
2431
default:    IsCAS = FALSE;
2432
endcase
2433
endfunction
2434
 
2435
function IsAMO;
2436
input [47:0] isn;
2437
case(isn[`INSTRUCTION_OP])
2438
`AMO:       IsAMO = TRUE;
2439
default:    IsAMO = FALSE;
2440
endcase
2441
endfunction
2442
 
2443
// Really IsPredictableBranch
2444
// Does not include BccR's
2445
function IsBranch;
2446
input [47:0] isn;
2447
casez(isn[`INSTRUCTION_OP])
2448
`Bcc:   IsBranch = TRUE;
2449
`BBc:   IsBranch = TRUE;
2450
`BEQI:  IsBranch = TRUE;
2451
`CHK:   IsBranch = TRUE;
2452
default:    IsBranch = FALSE;
2453
endcase
2454
endfunction
2455
 
2456
function IsWait;
2457
input [47:0] isn;
2458
IsWait = isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`WAIT;
2459
endfunction
2460
 
2461
function IsCall;
2462
input [47:0] isn;
2463
IsCall = isn[`INSTRUCTION_OP]==`CALL && isn[7]==1'b0;
2464
endfunction
2465
 
2466
function IsJmp;
2467
input [47:0] isn;
2468
IsJmp = isn[`INSTRUCTION_OP]==`JMP && isn[7]==1'b0;
2469
endfunction
2470
 
2471
function IsFlowCtrl;
2472
input [47:0] isn;
2473
casez(isn[`INSTRUCTION_OP])
2474
`BRK:    IsFlowCtrl = TRUE;
2475 49 robfinch
`R2:    case(isn[`INSTRUCTION_S2])
2476 48 robfinch
        `RTI:   IsFlowCtrl = TRUE;
2477
        default:    IsFlowCtrl = FALSE;
2478
        endcase
2479
`Bcc:   IsFlowCtrl = TRUE;
2480
`BBc:           IsFlowCtrl = TRUE;
2481
`BEQI:  IsFlowCtrl = TRUE;
2482
`CHK:   IsFlowCtrl = TRUE;
2483
`JAL:   IsFlowCtrl = TRUE;
2484
`JMP:           IsFlowCtrl = TRUE;
2485
`CALL:  IsFlowCtrl = TRUE;
2486
`RET:   IsFlowCtrl = TRUE;
2487
default:    IsFlowCtrl = FALSE;
2488
endcase
2489
endfunction
2490
 
2491
function IsCache;
2492
input [47:0] isn;
2493
case(isn[`INSTRUCTION_OP])
2494
`MEMNDX:
2495
        if (isn[`INSTRUCTION_L2]==2'b00)
2496
            case(isn[`INSTRUCTION_S2])
2497
            `CACHEX:    IsCache = TRUE;
2498
            default:    IsCache = FALSE;
2499
            endcase
2500
        else
2501
                IsCache = FALSE;
2502
`CACHE: IsCache = TRUE;
2503
default: IsCache = FALSE;
2504
endcase
2505
endfunction
2506
 
2507
function [4:0] CacheCmd;
2508
input [47:0] isn;
2509
case(isn[`INSTRUCTION_OP])
2510
`MEMNDX:
2511
        if (isn[`INSTRUCTION_L2]==2'b00)
2512
            case(isn[`INSTRUCTION_S2])
2513
            `CACHEX:    CacheCmd = isn[22:18];
2514
            default:    CacheCmd = 5'd0;
2515
            endcase
2516
        else
2517
                CacheCmd = 5'd0;
2518
`CACHE: CacheCmd = isn[15:11];
2519
default: CacheCmd = 5'd0;
2520
endcase
2521
endfunction
2522
 
2523
function IsMemsb;
2524
input [47:0] isn;
2525
IsMemsb = (isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMSB);
2526
endfunction
2527
 
2528
function IsSEI;
2529
input [47:0] isn;
2530
IsSEI = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`SEI);
2531
endfunction
2532
 
2533
function IsLV;
2534
input [47:0] isn;
2535
case(isn[`INSTRUCTION_OP])
2536
`MEMNDX:
2537
        if (isn[`INSTRUCTION_L2]==2'b00)
2538
            case(isn[`INSTRUCTION_S2])
2539
            `LVX:   IsLV = TRUE;
2540
            default:    IsLV = FALSE;
2541
            endcase
2542
        else
2543
                IsLV = FALSE;
2544
`LV:        IsLV = TRUE;
2545
default:    IsLV = FALSE;
2546
endcase
2547
endfunction
2548
 
2549
function IsRFW;
2550
input [47:0] isn;
2551
input [5:0] vqei;
2552
input [5:0] vli;
2553
input thrd;
2554
if (fnRt(isn,vqei,vli,thrd)==12'd0)
2555
    IsRFW = FALSE;
2556
else
2557
casez(isn[`INSTRUCTION_OP])
2558
`IVECTOR:   IsRFW = TRUE;
2559
`FVECTOR:   IsRFW = TRUE;
2560
`R2:
2561
        if (isn[`INSTRUCTION_L2]==2'b00)
2562
            case(isn[`INSTRUCTION_S2])
2563
            `R1:    IsRFW = TRUE;
2564
            `ADD:   IsRFW = TRUE;
2565
            `SUB:   IsRFW = TRUE;
2566
            `SLT:   IsRFW = TRUE;
2567
            `SLTU:  IsRFW = TRUE;
2568
            `SLE:   IsRFW = TRUE;
2569
        `SLEU:  IsRFW = TRUE;
2570
            `AND:   IsRFW = TRUE;
2571
            `OR:    IsRFW = TRUE;
2572
            `XOR:   IsRFW = TRUE;
2573
            `MULU:  IsRFW = TRUE;
2574
            `MULSU: IsRFW = TRUE;
2575
            `MUL:   IsRFW = TRUE;
2576 50 robfinch
            `MULUH:  IsRFW = TRUE;
2577
            `MULSUH: IsRFW = TRUE;
2578
            `MULH:   IsRFW = TRUE;
2579
            `DIVU:  IsRFW = TRUE;
2580
            `DIVSU: IsRFW = TRUE;
2581
            `DIV:IsRFW = TRUE;
2582
            `MODU:  IsRFW = TRUE;
2583
            `MODSU: IsRFW = TRUE;
2584
            `MOD:IsRFW = TRUE;
2585 48 robfinch
            `MOV:       IsRFW = TRUE;
2586
            `VMOV:      IsRFW = TRUE;
2587
            `SHIFTR,`SHIFT31,`SHIFT63:
2588
                        IsRFW = TRUE;
2589
            `MIN,`MAX:    IsRFW = TRUE;
2590
            `SEI:       IsRFW = TRUE;
2591
            default:    IsRFW = FALSE;
2592
            endcase
2593
        else
2594
                IsRFW = FALSE;
2595
`MEMNDX:
2596
        if (isn[`INSTRUCTION_L2]==2'b00)
2597 50 robfinch
    case(isn[`INSTRUCTION_S2])
2598
    `LBX:   IsRFW = TRUE;
2599
    `LBUX:  IsRFW = TRUE;
2600
    `LCX:   IsRFW = TRUE;
2601
    `LCUX:  IsRFW = TRUE;
2602
    `LHX:   IsRFW = TRUE;
2603
    `LHUX:  IsRFW = TRUE;
2604
    `LWX:   IsRFW = TRUE;
2605
    `LVBX:  IsRFW = TRUE;
2606
    `LVBUX: IsRFW = TRUE;
2607
    `LVCX:  IsRFW = TRUE;
2608
    `LVCUX: IsRFW = TRUE;
2609
    `LVHX:  IsRFW = TRUE;
2610
    `LVHUX: IsRFW = TRUE;
2611
    `LVWX:  IsRFW = TRUE;
2612
    `LWRX:  IsRFW = TRUE;
2613
    `LVX:   IsRFW = TRUE;
2614
    `CASX:  IsRFW = TRUE;
2615
    default:    IsRFW = FALSE;
2616
    endcase
2617 48 robfinch
        else
2618
                IsRFW = FALSE;
2619
`BBc:
2620
        case(isn[20:19])
2621
        `IBNE:  IsRFW = TRUE;
2622
        `DBNZ:  IsRFW = TRUE;
2623
        default:        IsRFW = FALSE;
2624
        endcase
2625
`BITFIELD:  IsRFW = TRUE;
2626
`ADDI:      IsRFW = TRUE;
2627
`SLTI:      IsRFW = TRUE;
2628
`SLTUI:     IsRFW = TRUE;
2629
`SGTI:      IsRFW = TRUE;
2630
`SGTUI:     IsRFW = TRUE;
2631
`ANDI:      IsRFW = TRUE;
2632
`ORI:       IsRFW = TRUE;
2633
`XORI:      IsRFW = TRUE;
2634
`MULUI:     IsRFW = TRUE;
2635
`MULI:      IsRFW = TRUE;
2636
`DIVUI:     IsRFW = TRUE;
2637
`DIVI:      IsRFW = TRUE;
2638
`MODI:      IsRFW = TRUE;
2639
`JAL:       IsRFW = TRUE;
2640
`CALL:      IsRFW = TRUE;
2641
`RET:       IsRFW = TRUE;
2642
`LB:        IsRFW = TRUE;
2643
`LBU:       IsRFW = TRUE;
2644
`Lx:        IsRFW = TRUE;
2645
`LWR:       IsRFW = TRUE;
2646
`LV:        IsRFW = TRUE;
2647
`LVx:                           IsRFW = TRUE;
2648
`CAS:       IsRFW = TRUE;
2649
`AMO:                           IsRFW = TRUE;
2650
`CSRRW:                 IsRFW = TRUE;
2651
default:    IsRFW = FALSE;
2652
endcase
2653
endfunction
2654
 
2655
function IsShifti;
2656
input [47:0] isn;
2657
case(isn[`INSTRUCTION_OP])
2658
`R2:
2659
        if (isn[`INSTRUCTION_L2]==2'b00)
2660
            case(isn[`INSTRUCTION_S2])
2661
            `SHIFT31,`SHIFT63:
2662
                IsShifti = TRUE;
2663
            default: IsShifti = FALSE;
2664
            endcase
2665
    else
2666
        IsShifti = FALSE;
2667
default: IsShifti = FALSE;
2668
endcase
2669
endfunction
2670
 
2671
function IsRtop;
2672
input [47:0] isn;
2673
case(isn[`INSTRUCTION_OP])
2674
`R2:
2675
        if (isn[`INSTRUCTION_L2]==2'b01)
2676
            case(isn[47:42])
2677
            `RTOP: IsRtop = TRUE;
2678
            default: IsRtop = FALSE;
2679
            endcase
2680
    else
2681
        IsRtop = FALSE;
2682
default: IsRtop = FALSE;
2683
endcase
2684
endfunction
2685
 
2686
function IsMul;
2687
input [47:0] isn;
2688
case(isn[`INSTRUCTION_OP])
2689 50 robfinch
`R2:
2690 48 robfinch
        if (isn[`INSTRUCTION_L2]==2'b00)
2691 50 robfinch
    case(isn[`INSTRUCTION_S2])
2692
    `MULU,`MULSU,`MUL: IsMul = TRUE;
2693
    `MULUH,`MULSUH,`MULH: IsMul = TRUE;
2694
    default:    IsMul = FALSE;
2695
    endcase
2696 48 robfinch
        else
2697
                IsMul = FALSE;
2698
`MULUI,`MULI:  IsMul = TRUE;
2699
default:    IsMul = FALSE;
2700
endcase
2701
endfunction
2702
 
2703
function IsDivmod;
2704
input [47:0] isn;
2705
case(isn[`INSTRUCTION_OP])
2706 50 robfinch
`R2:
2707 48 robfinch
        if (isn[`INSTRUCTION_L2]==2'b00)
2708 50 robfinch
    case(isn[`INSTRUCTION_S2])
2709
    `DIVU,`DIVSU,`DIV: IsDivmod = TRUE;
2710
    `MODU,`MODSU,`MOD: IsDivmod = TRUE;
2711
    default: IsDivmod = FALSE;
2712
    endcase
2713 48 robfinch
        else
2714
                IsDivmod = FALSE;
2715
`DIVUI,`DIVI,`MODI:  IsDivmod = TRUE;
2716
default:    IsDivmod = FALSE;
2717
endcase
2718
endfunction
2719
 
2720
function IsExec;
2721
input [47:0] isn;
2722
case(isn[`INSTRUCTION_OP])
2723
`EXEC:  IsExec = TRUE;
2724
default:        IsExec = FALSE;
2725
endcase
2726
endfunction
2727
 
2728
function [7:0] fnSelect;
2729
input [47:0] ins;
2730 49 robfinch
input [`ABITS] adr;
2731 48 robfinch
begin
2732
        case(ins[`INSTRUCTION_OP])
2733
        `MEMNDX:
2734
                if (ins[`INSTRUCTION_L2]==2'b00)
2735
                   case(ins[`INSTRUCTION_S2])
2736
               `LBX,`LBUX,`SBX:
2737
                   case(adr[2:0])
2738
                   3'd0:    fnSelect = 8'h01;
2739
                   3'd1:    fnSelect = 8'h02;
2740
                   3'd2:    fnSelect = 8'h04;
2741
                   3'd3:    fnSelect = 8'h08;
2742
                   3'd4:    fnSelect = 8'h10;
2743
                   3'd5:    fnSelect = 8'h20;
2744
                   3'd6:    fnSelect = 8'h40;
2745
                   3'd7:    fnSelect = 8'h80;
2746
                   endcase
2747
                `LCX,`LCUX,`SCX:
2748
                    case(adr[2:1])
2749
                    2'd0:   fnSelect = 8'h03;
2750
                    2'd1:   fnSelect = 8'h0C;
2751
                    2'd2:   fnSelect = 8'h30;
2752
                    2'd3:   fnSelect = 8'hC0;
2753
                    endcase
2754
                `LHX,`LHUX,`SHX:
2755
                   case(adr[2])
2756
                   1'b0:    fnSelect = 8'h0F;
2757
                   1'b1:    fnSelect = 8'hF0;
2758
                   endcase
2759
               `INC,
2760
               `LWX,`SWX,`LWRX,`SWCX,`LVX,`SVX,`CASX:
2761
                   fnSelect = 8'hFF;
2762
               `LVx:   ;
2763
//                      case(ins[25:23])
2764
//                     `LVB,`LVBU:
2765
//                         case(adr[2:0])
2766
//                         3'd0:    fnSelect = 8'h01;
2767
//                         3'd1:    fnSelect = 8'h02;
2768
//                         3'd2:    fnSelect = 8'h04;
2769
//                         3'd3:    fnSelect = 8'h08;
2770
//                         3'd4:    fnSelect = 8'h10;
2771
//                         3'd5:    fnSelect = 8'h20;
2772
//                         3'd6:    fnSelect = 8'h40;
2773
//                         3'd7:    fnSelect = 8'h80;
2774
//                         endcase
2775
//                      `LVC,`LVCU:
2776
//                          case(adr[2:1])
2777
//                          2'd0:   fnSelect = 8'h03;
2778
//                          2'd1:   fnSelect = 8'h0C;
2779
//                          2'd2:   fnSelect = 8'h30;
2780
//                          2'd3:   fnSelect = 8'hC0;
2781
//                          endcase
2782
//                      `LVH,`LVHU:
2783
//                         case(adr[2])
2784
//                         1'b0:    fnSelect = 8'h0F;
2785
//                         1'b1:    fnSelect = 8'hF0;
2786
//                         endcase
2787
//                     `LVW:
2788
//                         fnSelect = 8'hFF;
2789
//                      endcase
2790
               default: fnSelect = 8'h00;
2791
                   endcase
2792
           else
2793
                fnSelect = 8'h00;
2794 52 robfinch
  `LB,`LBU,`SB:
2795 48 robfinch
                case(adr[2:0])
2796
                3'd0:   fnSelect = 8'h01;
2797
                3'd1:   fnSelect = 8'h02;
2798
                3'd2:   fnSelect = 8'h04;
2799
                3'd3:   fnSelect = 8'h08;
2800
                3'd4:   fnSelect = 8'h10;
2801
                3'd5:   fnSelect = 8'h20;
2802
                3'd6:   fnSelect = 8'h40;
2803
                3'd7:   fnSelect = 8'h80;
2804
                endcase
2805
    `Lx,`LxU,`Sx:
2806
        casez(ins[20:18])
2807
        3'b100: fnSelect = 8'hFF;
2808
        3'b?10: fnSelect = adr[2] ? 8'hF0 : 8'h0F;
2809
        3'b??1:
2810
        case(adr[2:1])
2811
        2'd0:   fnSelect = 8'h03;
2812
        2'd1:   fnSelect = 8'h0C;
2813
        2'd2:   fnSelect = 8'h30;
2814
        2'd3:   fnSelect = 8'hC0;
2815
        endcase
2816
      default: fnSelect = 8'h00;
2817
      endcase
2818
        `INC,
2819
        `LWR,`SWC,`CAS:   fnSelect = 8'hFF;
2820
        `LV,`SV:   fnSelect = 8'hFF;
2821
        `AMO:
2822
                case(ins[23:21])
2823
                3'd0:   fnSelect = {8'h01 << adr[2:0]};
2824
                3'd1:   fnSelect = {8'h03 << {adr[2:1],1'b0}};
2825
                3'd2:   fnSelect = {8'h0F << {adr[2],2'b00}};
2826
                3'd3:   fnSelect = 8'hFF;
2827
                default:        fnSelect = 8'hFF;
2828
                endcase
2829
//      `LVx:
2830
//       `LVB,`LVBU:
2831
//           case(adr[2:0])
2832
//           3'd0:    fnSelect = 8'h01;
2833
//           3'd1:    fnSelect = 8'h02;
2834
//           3'd2:    fnSelect = 8'h04;
2835
//           3'd3:    fnSelect = 8'h08;
2836
//           3'd4:    fnSelect = 8'h10;
2837
//           3'd5:    fnSelect = 8'h20;
2838
//           3'd6:    fnSelect = 8'h40;
2839
//           3'd7:    fnSelect = 8'h80;
2840
//           endcase
2841
//        `LVC,`LVCU:
2842
//            case(adr[2:1])
2843
//            2'd0:   fnSelect = 8'h03;
2844
//            2'd1:   fnSelect = 8'h0C;
2845
//            2'd2:   fnSelect = 8'h30;
2846
//            2'd3:   fnSelect = 8'hC0;
2847
//            endcase
2848
//      `LVH,`LVHU:
2849
//           case(adr[2])
2850
//           1'b0:    fnSelect = 8'h0F;
2851
//           1'b1:    fnSelect = 8'hF0;
2852
//           endcase
2853
//       `LVW:
2854
//           fnSelect = 8'hFF;
2855
        default:        fnSelect = 8'h00;
2856
        endcase
2857
end
2858
endfunction
2859
/*
2860
function [63:0] fnDatc;
2861
input [47:0] ins;
2862
input [63:0] dat;
2863
case(ins[`INSTRUCTION_OP])
2864
`R2:
2865
        if (isn[`INSTRUCTION_L2]==2'b01)
2866
                case(ins[47:42])
2867
                `FINDB:         fnDatc = dat[7:0];
2868
                `FINDC:         fnDatc = dat[15:0];
2869
                `FINDH:         fnDatc = dat[31:0];
2870
                `FINDW:         fnDatc = dat[63:0];
2871
                default:        fnDatc = dat[63:0];
2872
                endcase
2873
        else
2874
                fnDatc = dat[63:0];
2875
default:        fnDatc = dat[63:0];
2876
endcase
2877
endfunction
2878
*/
2879
/*
2880
function [63:0] fnMemInc;
2881
input [47:0] ins;
2882
case(ins[`INSTRUCTION_OP])
2883
`R2:
2884
        if (isn[`INSTRUCTION_L2]==2'b01)
2885
                case(ins[47:42])
2886
                `FINDB:         fnMemInc = 32'd1;
2887
                `FINDC:         fnMemInc = 32'd2;
2888
                `FINDH:         fnMemInc = 32'd4;
2889
                `FINDW:         fnMemInc = 32'd8;
2890
                default:        fnMemInc = 32'd8;
2891
                endcase
2892
        else
2893
                fnMemInc = 32'd8;
2894
default:        fnMemInc = 32'd8;
2895
endcase
2896
endfunction
2897
*/
2898
function [63:0] fnDati;
2899
input [47:0] ins;
2900 49 robfinch
input [`ABITS] adr;
2901 48 robfinch
input [63:0] dat;
2902
case(ins[`INSTRUCTION_OP])
2903
`MEMNDX:
2904
        if (ins[`INSTRUCTION_L2]==2'b00)
2905
            case(ins[`INSTRUCTION_S2])
2906
            `LBX:
2907
                case(adr[2:0])
2908
                3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
2909
                3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
2910
                3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
2911
                3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
2912
                3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
2913
                3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
2914
                3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
2915
                3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
2916
                endcase
2917
            `LBUX:
2918
                case(adr[2:0])
2919
                3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
2920
                3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
2921
                3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
2922
                3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
2923
                3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
2924
                3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
2925
                3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
2926
                3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
2927
                endcase
2928
            `LCX:
2929
                case(adr[2:1])
2930
                2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
2931
                2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
2932
                2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
2933
                2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
2934
                endcase
2935
            `LCUX:
2936
                case(adr[2:1])
2937
                2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
2938
                2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
2939
                2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
2940
                2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
2941
                endcase
2942
            `LHX:
2943
                case(adr[2])
2944
                1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
2945
                1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
2946
                endcase
2947
            `LHUX:
2948
                case(adr[2])
2949
                1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
2950
                1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
2951
                endcase
2952
            `LWX,`LWRX,`LVX,`CAS:  fnDati = dat;
2953
//          `LVx:
2954
//              case(ins[25:23])
2955
//                  `LVB:
2956
//                      case(adr[2:0])
2957
//                      3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
2958
//                      3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
2959
//                      3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
2960
//                      3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
2961
//                      3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
2962
//                      3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
2963
//                      3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
2964
//                      3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
2965
//                      endcase
2966
//                  `LVBU:
2967
//                      case(adr[2:0])
2968
//                      3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
2969
//                      3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
2970
//                      3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
2971
//                      3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
2972
//                      3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
2973
//                      3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
2974
//                      3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
2975
//                      3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
2976
//                      endcase
2977
//                  `LVC:
2978
//                      case(adr[2:1])
2979
//                      2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
2980
//                      2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
2981
//                      2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
2982
//                      2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
2983
//                      endcase
2984
//                  `LVCU:
2985
//                      case(adr[2:1])
2986
//                      2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
2987
//                      2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
2988
//                      2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
2989
//                      2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
2990
//                      endcase
2991
//                  `LVH:
2992
//                      case(adr[2])
2993
//                      1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
2994
//                      1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
2995
//                      endcase
2996
//                  `LVHU:
2997
//                      case(adr[2])
2998
//                      1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
2999
//                      1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3000
//                      endcase
3001
//                  `LVW:  fnDati = dat;
3002
//                  default:    fnDati = dat;
3003
//              endcase
3004
            default:    fnDati = dat;
3005
            endcase
3006
        else
3007
                fnDati = dat;
3008
`LB:
3009
  case(adr[2:0])
3010
  3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3011
  3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3012
  3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3013
  3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3014
  3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3015
  3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3016
  3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3017
  3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3018
  endcase
3019
`LBU:
3020
  case(adr[2:0])
3021
  3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3022
  3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3023
  3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3024
  3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3025
  3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3026
  3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3027
  3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3028
  3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3029
  endcase
3030
`Lx:
3031
        casez(ins[20:18])
3032
        3'b100: fnDati = dat;
3033
        3'b?10:
3034
          case(adr[2])
3035
          1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3036
          1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3037
          endcase
3038
        3'b??1:
3039
          case(adr[2:1])
3040
          2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3041
          2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3042
          2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3043
          2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3044
          endcase
3045
        endcase
3046
`LxU:
3047
        casez(ins[20:18])
3048
        3'b100: fnDati = dat;
3049
        3'b?10:
3050
          case(adr[2])
3051
          1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3052
          1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3053
          endcase
3054
        3'b??1:
3055
          case(adr[2:1])
3056
          2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3057
          2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3058
          2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3059
          2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3060
          endcase
3061
        endcase
3062
`LWR,`LV,`CAS,`AMO:   fnDati = dat;
3063
//`LVx:
3064
//      case(ins[30:28])
3065
//    `LVB:
3066
//        case(adr[2:0])
3067
//        3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3068
//        3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3069
//        3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3070
//        3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3071
//        3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3072
//        3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3073
//        3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3074
//        3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3075
//        endcase
3076
//    `LVBU:
3077
//        case(adr[2:0])
3078
//        3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3079
//        3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3080
//        3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3081
//        3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3082
//        3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3083
//        3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3084
//        3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3085
//        3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3086
//        endcase
3087
//    `LVC:
3088
//        case(adr[2:1])
3089
//        2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3090
//        2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3091
//        2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3092
//        2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3093
//        endcase
3094
//    `LVCU:
3095
//        case(adr[2:1])
3096
//        2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3097
//        2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3098
//        2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3099
//        2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3100
//        endcase
3101
//    `LVH:
3102
//        case(adr[2])
3103
//        1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3104
//        1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3105
//        endcase
3106
//    `LVHU:
3107
//        case(adr[2])
3108
//        1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3109
//        1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3110
//        endcase
3111
////    `LVW:  fnDati = dat;
3112
//    default:  fnDati = dat;
3113
//      endcase
3114
default:    fnDati = dat;
3115
endcase
3116
endfunction
3117
 
3118
function [63:0] fnDato;
3119
input [47:0] isn;
3120
input [63:0] dat;
3121
case(isn[`INSTRUCTION_OP])
3122
`MEMNDX:
3123
        if (isn[`INSTRUCTION_L2]==2'b00)
3124
                case(isn[`INSTRUCTION_S2])
3125
                `SBX:   fnDato = {8{dat[7:0]}};
3126
                `SCX:   fnDato = {4{dat[15:0]}};
3127
                `SHX:   fnDato = {2{dat[31:0]}};
3128
                default:    fnDato = dat;
3129
                endcase
3130
        else
3131
                fnDato = dat;
3132
`SB:   fnDato = {8{dat[7:0]}};
3133
`Sx:
3134 49 robfinch
        casez(isn[20:18])
3135 48 robfinch
        3'b100: fnDato = dat;
3136
        3'b?10: fnDato = {2{dat[31:0]}};
3137
        3'b??1: fnDato = {4{dat[15:0]}};
3138
        default:        fnDato = dat;
3139
        endcase
3140
`AMO:
3141
        case(isn[23:21])
3142
        3'd0:   fnDato = {8{dat[7:0]}};
3143
        3'd1:   fnDato = {4{dat[15:0]}};
3144
        3'd2:   fnDato = {2{dat[31:0]}};
3145
        3'd3:   fnDato = dat;
3146
        default:        fnDato = dat;
3147
        endcase
3148
default:    fnDato = dat;
3149
endcase
3150
endfunction
3151
 
3152
// Indicate if the ALU instruction is valid immediately (single cycle operation)
3153
function IsSingleCycle;
3154
input [47:0] isn;
3155
IsSingleCycle = !(IsMul(isn)|IsDivmod(isn));
3156
endfunction
3157
 
3158
 
3159
`ifdef SUPPORT_SMT
3160
decoder8 iq0(.num({iqentry_tgt[0][8:7],iqentry_tgt[0][5:0]}), .out(iq0_out));
3161
decoder8 iq1(.num({iqentry_tgt[1][8:7],iqentry_tgt[1][5:0]}), .out(iq1_out));
3162
decoder8 iq2(.num({iqentry_tgt[2][8:7],iqentry_tgt[2][5:0]}), .out(iq2_out));
3163
decoder8 iq3(.num({iqentry_tgt[3][8:7],iqentry_tgt[3][5:0]}), .out(iq3_out));
3164
decoder8 iq4(.num({iqentry_tgt[4][8:7],iqentry_tgt[4][5:0]}), .out(iq4_out));
3165
decoder8 iq5(.num({iqentry_tgt[5][8:7],iqentry_tgt[5][5:0]}), .out(iq5_out));
3166
decoder8 iq6(.num({iqentry_tgt[6][8:7],iqentry_tgt[6][5:0]}), .out(iq6_out));
3167
decoder8 iq7(.num({iqentry_tgt[7][8:7],iqentry_tgt[7][5:0]}), .out(iq7_out));
3168 52 robfinch
decoder8 iq8(.num({iqentry_tgt[8][8:7],iqentry_tgt[8][5:0]}), .out(iq8_out));
3169
decoder8 iq9(.num({iqentry_tgt[9][8:7],iqentry_tgt[9][5:0]}), .out(iq9_out));
3170 48 robfinch
`else
3171
decoder7 iq0(.num({iqentry_tgt[0][7],iqentry_tgt[0][5:0]}), .out(iq0_out));
3172
decoder7 iq1(.num({iqentry_tgt[1][7],iqentry_tgt[1][5:0]}), .out(iq1_out));
3173
decoder7 iq2(.num({iqentry_tgt[2][7],iqentry_tgt[2][5:0]}), .out(iq2_out));
3174
decoder7 iq3(.num({iqentry_tgt[3][7],iqentry_tgt[3][5:0]}), .out(iq3_out));
3175
decoder7 iq4(.num({iqentry_tgt[4][7],iqentry_tgt[4][5:0]}), .out(iq4_out));
3176
decoder7 iq5(.num({iqentry_tgt[5][7],iqentry_tgt[5][5:0]}), .out(iq5_out));
3177
decoder7 iq6(.num({iqentry_tgt[6][7],iqentry_tgt[6][5:0]}), .out(iq6_out));
3178
decoder7 iq7(.num({iqentry_tgt[7][7],iqentry_tgt[7][5:0]}), .out(iq7_out));
3179 52 robfinch
decoder7 iq8(.num({iqentry_tgt[8][7],iqentry_tgt[8][5:0]}), .out(iq8_out));
3180
decoder7 iq9(.num({iqentry_tgt[9][7],iqentry_tgt[9][5:0]}), .out(iq9_out));
3181 48 robfinch
/*
3182
decoder6 iq0(.num({iqentry_tgt[0][5:0]}), .out(iq0_out));
3183
decoder6 iq1(.num({iqentry_tgt[1][5:0]}), .out(iq1_out));
3184
decoder6 iq2(.num({iqentry_tgt[2][5:0]}), .out(iq2_out));
3185
decoder6 iq3(.num({iqentry_tgt[3][5:0]}), .out(iq3_out));
3186
decoder6 iq4(.num({iqentry_tgt[4][5:0]}), .out(iq4_out));
3187
decoder6 iq5(.num({iqentry_tgt[5][5:0]}), .out(iq5_out));
3188
decoder6 iq6(.num({iqentry_tgt[6][5:0]}), .out(iq6_out));
3189
decoder6 iq7(.num({iqentry_tgt[7][5:0]}), .out(iq7_out));*/
3190
`endif
3191
 
3192
initial begin: Init
3193
        //
3194
        //
3195
        // set up panic messages
3196
        message[ `PANIC_NONE ]                  = "NONE            ";
3197
        message[ `PANIC_FETCHBUFBEQ ]           = "FETCHBUFBEQ     ";
3198
        message[ `PANIC_INVALIDISLOT ]          = "INVALIDISLOT    ";
3199
        message[ `PANIC_IDENTICALDRAMS ]        = "IDENTICALDRAMS  ";
3200
        message[ `PANIC_OVERRUN ]               = "OVERRUN         ";
3201
        message[ `PANIC_HALTINSTRUCTION ]       = "HALTINSTRUCTION ";
3202
        message[ `PANIC_INVALIDMEMOP ]          = "INVALIDMEMOP    ";
3203
        message[ `PANIC_INVALIDFBSTATE ]        = "INVALIDFBSTATE  ";
3204
        message[ `PANIC_INVALIDIQSTATE ]        = "INVALIDIQSTATE  ";
3205
        message[ `PANIC_BRANCHBACK ]            = "BRANCHBACK      ";
3206
        message[ `PANIC_MEMORYRACE ]            = "MEMORYRACE      ";
3207
        message[ `PANIC_ALU0ONLY ] = "ALU0 Only       ";
3208
 
3209
        for (n = 0; n < 64; n = n + 1)
3210
                codebuf[n] <= 48'h0;
3211
 
3212
end
3213
 
3214
// ---------------------------------------------------------------------------
3215
// FETCH
3216
// ---------------------------------------------------------------------------
3217
//
3218
assign fetchbuf0_mem   = IsMem(fetchbuf0_instr);
3219
assign fetchbuf0_memld = IsMem(fetchbuf0_instr) & IsLoad(fetchbuf0_instr);
3220
assign fetchbuf0_rfw   = IsRFW(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd);
3221
 
3222
assign fetchbuf1_mem   = IsMem(fetchbuf1_instr);
3223
assign fetchbuf1_memld = IsMem(fetchbuf1_instr) & IsLoad(fetchbuf1_instr);
3224
assign fetchbuf1_rfw   = IsRFW(fetchbuf1_instr,vqe1,vl,fetchbuf1_thrd);
3225
 
3226
FT64_fetchbuf #(AMSB,RSTPC) ufb1
3227
(
3228 49 robfinch
  .rst(rst),
3229
  .clk4x(clk4x),
3230
  .clk(clk),
3231
  .fcu_clk(fcu_clk),
3232
  .cs_i(adr_o[31:16]==16'hFFFF),
3233
  .cyc_i(cyc_o),
3234
  .stb_i(stb_o),
3235
  .ack_o(dc_ack),
3236
  .we_i(we_o),
3237
  .adr_i(adr_o[15:0]),
3238
  .dat_i(dat_o[31:0]),
3239 52 robfinch
  .freezePC(freezePC),
3240 49 robfinch
  .regLR(regLR),
3241
  .thread_en(thread_en),
3242
  .insn0(insn0),
3243
  .insn1(insn1),
3244
  .phit(phit),
3245
  .threadx(threadx),
3246
  .branchmiss(branchmiss),
3247
  .misspc(misspc),
3248
  .branchmiss_thrd(branchmiss_thrd),
3249
  .predict_takenA(predict_takenA),
3250
  .predict_takenB(predict_takenB),
3251
  .predict_takenC(predict_takenC),
3252
  .predict_takenD(predict_takenD),
3253
  .predict_taken0(predict_taken0),
3254
  .predict_taken1(predict_taken1),
3255
  .queued1(queued1),
3256
  .queued2(queued2),
3257
  .queuedNop(queuedNop),
3258
  .pc0(pc0),
3259
  .pc1(pc1),
3260
  .fetchbuf(fetchbuf),
3261
  .fetchbufA_v(fetchbufA_v),
3262
  .fetchbufB_v(fetchbufB_v),
3263
  .fetchbufC_v(fetchbufC_v),
3264
  .fetchbufD_v(fetchbufD_v),
3265
  .fetchbufA_pc(fetchbufA_pc),
3266
  .fetchbufB_pc(fetchbufB_pc),
3267
  .fetchbufC_pc(fetchbufC_pc),
3268
  .fetchbufD_pc(fetchbufD_pc),
3269
  .fetchbufA_instr(fetchbufA_instr),
3270
  .fetchbufB_instr(fetchbufB_instr),
3271
  .fetchbufC_instr(fetchbufC_instr),
3272
  .fetchbufD_instr(fetchbufD_instr),
3273
  .fetchbuf0_instr(fetchbuf0_instr),
3274
  .fetchbuf1_instr(fetchbuf1_instr),
3275
  .fetchbuf0_thrd(fetchbuf0_thrd),
3276
  .fetchbuf1_thrd(fetchbuf1_thrd),
3277
  .fetchbuf0_pc(fetchbuf0_pc),
3278
  .fetchbuf1_pc(fetchbuf1_pc),
3279
  .fetchbuf0_v(fetchbuf0_v),
3280
  .fetchbuf1_v(fetchbuf1_v),
3281
  .fetchbuf0_insln(fetchbuf0_insln),
3282
  .fetchbuf1_insln(fetchbuf1_insln),
3283
  .codebuf0(codebuf[insn0[21:16]]),
3284
  .codebuf1(codebuf[insn1[21:16]]),
3285
  .btgtA(btgtA),
3286
  .btgtB(btgtB),
3287
  .btgtC(btgtC),
3288
  .btgtD(btgtD),
3289
  .nop_fetchbuf(nop_fetchbuf),
3290
  .take_branch0(take_branch0),
3291
  .take_branch1(take_branch1),
3292
  .stompedRets(stompedOnRets),
3293
  .panic(fb_panic)
3294 48 robfinch
);
3295
 
3296
 
3297
 
3298
//initial begin: stop_at
3299
//#1000000; panic <= `PANIC_OVERRUN;
3300
//end
3301
 
3302
//
3303
// BRANCH-MISS LOGIC: livetarget
3304
//
3305
// livetarget implies that there is a not-to-be-stomped instruction that targets the register in question
3306
// therefore, if it is zero it implies the rf_v value should become VALID on a branchmiss
3307
// 
3308
 
3309
generate begin : live_target
3310
    for (g = 1; g < PREGS; g = g + 1) begin : lvtgt
3311
    assign livetarget[g] = iqentry_0_livetarget[g] |
3312
                        iqentry_1_livetarget[g] |
3313
                        iqentry_2_livetarget[g] |
3314
                        iqentry_3_livetarget[g] |
3315
                        iqentry_4_livetarget[g] |
3316
                        iqentry_5_livetarget[g] |
3317
                        iqentry_6_livetarget[g] |
3318 52 robfinch
                        iqentry_7_livetarget[g] |
3319
                        iqentry_8_livetarget[g] |
3320
                        iqentry_9_livetarget[g]
3321
                        ;
3322 48 robfinch
    end
3323
end
3324
endgenerate
3325
 
3326
    assign  iqentry_0_livetarget = {PREGS {iqentry_v[0]}} & {PREGS {~iqentry_stomp[0] && iqentry_thrd[0]==branchmiss_thrd}} & iq0_out,
3327
            iqentry_1_livetarget = {PREGS {iqentry_v[1]}} & {PREGS {~iqentry_stomp[1] && iqentry_thrd[1]==branchmiss_thrd}} & iq1_out,
3328
            iqentry_2_livetarget = {PREGS {iqentry_v[2]}} & {PREGS {~iqentry_stomp[2] && iqentry_thrd[2]==branchmiss_thrd}} & iq2_out,
3329
            iqentry_3_livetarget = {PREGS {iqentry_v[3]}} & {PREGS {~iqentry_stomp[3] && iqentry_thrd[3]==branchmiss_thrd}} & iq3_out,
3330
            iqentry_4_livetarget = {PREGS {iqentry_v[4]}} & {PREGS {~iqentry_stomp[4] && iqentry_thrd[4]==branchmiss_thrd}} & iq4_out,
3331
            iqentry_5_livetarget = {PREGS {iqentry_v[5]}} & {PREGS {~iqentry_stomp[5] && iqentry_thrd[5]==branchmiss_thrd}} & iq5_out,
3332
            iqentry_6_livetarget = {PREGS {iqentry_v[6]}} & {PREGS {~iqentry_stomp[6] && iqentry_thrd[6]==branchmiss_thrd}} & iq6_out,
3333 52 robfinch
            iqentry_7_livetarget = {PREGS {iqentry_v[7]}} & {PREGS {~iqentry_stomp[7] && iqentry_thrd[7]==branchmiss_thrd}} & iq7_out,
3334
            iqentry_8_livetarget = {PREGS {iqentry_v[8]}} & {PREGS {~iqentry_stomp[8] && iqentry_thrd[8]==branchmiss_thrd}} & iq8_out,
3335
            iqentry_9_livetarget = {PREGS {iqentry_v[9]}} & {PREGS {~iqentry_stomp[9] && iqentry_thrd[9]==branchmiss_thrd}} & iq9_out
3336
            ;
3337 48 robfinch
 
3338 52 robfinch
//
3339
// BRANCH-MISS LOGIC: latestID
3340
//
3341
// latestID is the instruction queue ID of the newest instruction (latest) that targets
3342
// a particular register.  looks a lot like scheduling logic, but in reverse.
3343
// 
3344
always @*
3345
        for (n = 0; n < QENTRIES; n = n + 1) begin
3346
                iqentry_cumulative[n] = 0;
3347
                for (j = n; j < n + QENTRIES; j = j + 1) begin
3348
                        if (missid==(j % QENTRIES))
3349
                                for (k = n; k <= j; k = k + 1)
3350
                                        iqentry_cumulative[n] = iqentry_cumulative[n] | iqentry_livetarget[k % QENTRIES];
3351
                end
3352
        end
3353
/*
3354 48 robfinch
    assign iqentry_0_cumulative = (missid==3'd0) ? iqentry_0_livetarget :
3355
                                  (missid==3'd1) ? iqentry_0_livetarget |
3356
                                                   iqentry_1_livetarget :
3357
                                  (missid==3'd2) ? iqentry_0_livetarget |
3358
                                                   iqentry_1_livetarget |
3359
                                                   iqentry_2_livetarget :
3360
                                  (missid==3'd3) ? iqentry_0_livetarget |
3361
                                                   iqentry_1_livetarget |
3362
                                                   iqentry_2_livetarget |
3363
                                                   iqentry_3_livetarget :
3364
                                  (missid==3'd4) ? iqentry_0_livetarget |
3365
                                                   iqentry_1_livetarget |
3366
                                                   iqentry_2_livetarget |
3367
                                                   iqentry_3_livetarget |
3368
                                                   iqentry_4_livetarget :
3369
                                  (missid==3'd5) ? iqentry_0_livetarget |
3370
                                                   iqentry_1_livetarget |
3371
                                                   iqentry_2_livetarget |
3372
                                                   iqentry_3_livetarget |
3373
                                                   iqentry_4_livetarget |
3374
                                                   iqentry_5_livetarget :
3375
                                  (missid==3'd6) ? iqentry_0_livetarget |
3376
                                                   iqentry_1_livetarget |
3377
                                                   iqentry_2_livetarget |
3378
                                                   iqentry_3_livetarget |
3379
                                                   iqentry_4_livetarget |
3380
                                                   iqentry_5_livetarget |
3381
                                                   iqentry_6_livetarget :
3382
                                  (missid==3'd7) ? iqentry_0_livetarget |
3383
                                                   iqentry_1_livetarget |
3384
                                                   iqentry_2_livetarget |
3385
                                                   iqentry_3_livetarget |
3386
                                                   iqentry_4_livetarget |
3387
                                                   iqentry_5_livetarget |
3388
                                                   iqentry_6_livetarget |
3389
                                                   iqentry_7_livetarget :
3390
                                                   {PREGS{1'b0}};
3391
 
3392 52 robfinch
    assign iqentry_1_cumulative = (missid==4'd1) ? iqentry_1_livetarget :
3393
                                  (missid==4'd2) ? iqentry_1_livetarget |
3394 48 robfinch
                                                   iqentry_2_livetarget :
3395 52 robfinch
                                  (missid==4'd3) ? iqentry_1_livetarget |
3396 48 robfinch
                                                   iqentry_2_livetarget |
3397
                                                   iqentry_3_livetarget :
3398 52 robfinch
                                  (missid==4'd4) ? iqentry_1_livetarget |
3399 48 robfinch
                                                   iqentry_2_livetarget |
3400
                                                   iqentry_3_livetarget |
3401
                                                   iqentry_4_livetarget :
3402 52 robfinch
                                  (missid==4'd5) ? iqentry_1_livetarget |
3403 48 robfinch
                                                   iqentry_2_livetarget |
3404
                                                   iqentry_3_livetarget |
3405
                                                   iqentry_4_livetarget |
3406
                                                   iqentry_5_livetarget :
3407 52 robfinch
                                  (missid==4'd6) ? iqentry_1_livetarget |
3408 48 robfinch
                                                   iqentry_2_livetarget |
3409
                                                   iqentry_3_livetarget |
3410
                                                   iqentry_4_livetarget |
3411
                                                   iqentry_5_livetarget |
3412
                                                   iqentry_6_livetarget :
3413 52 robfinch
                                  (missid==4'd7) ? iqentry_1_livetarget |
3414 48 robfinch
                                                   iqentry_2_livetarget |
3415
                                                   iqentry_3_livetarget |
3416
                                                   iqentry_4_livetarget |
3417
                                                   iqentry_5_livetarget |
3418
                                                   iqentry_6_livetarget |
3419
                                                   iqentry_7_livetarget :
3420 52 robfinch
                                  (missid==4'd0) ? iqentry_1_livetarget |
3421 48 robfinch
                                                   iqentry_2_livetarget |
3422
                                                   iqentry_3_livetarget |
3423
                                                   iqentry_4_livetarget |
3424
                                                   iqentry_5_livetarget |
3425
                                                   iqentry_6_livetarget |
3426
                                                   iqentry_7_livetarget |
3427
                                                   iqentry_0_livetarget :
3428
                                                   {PREGS{1'b0}};
3429
 
3430 52 robfinch
    assign iqentry_2_cumulative = (missid==4'd2) ? iqentry_2_livetarget :
3431
                                     (missid==4'd3) ? iqentry_2_livetarget |
3432 48 robfinch
                                                      iqentry_3_livetarget :
3433 52 robfinch
                                     (missid==4'd4) ? iqentry_2_livetarget |
3434 48 robfinch
                                                      iqentry_3_livetarget |
3435
                                                      iqentry_4_livetarget :
3436 52 robfinch
                                     (missid==4'd5) ? iqentry_2_livetarget |
3437 48 robfinch
                                                      iqentry_3_livetarget |
3438
                                                      iqentry_4_livetarget |
3439
                                                      iqentry_5_livetarget :
3440 52 robfinch
                                     (missid==4'd6) ? iqentry_2_livetarget |
3441 48 robfinch
                                                      iqentry_3_livetarget |
3442
                                                      iqentry_4_livetarget |
3443
                                                      iqentry_5_livetarget |
3444
                                                      iqentry_6_livetarget :
3445 52 robfinch
                                     (missid==4'd7) ? iqentry_2_livetarget |
3446 48 robfinch
                                                      iqentry_3_livetarget |
3447
                                                      iqentry_4_livetarget |
3448
                                                      iqentry_5_livetarget |
3449
                                                      iqentry_6_livetarget |
3450
                                                      iqentry_7_livetarget :
3451 52 robfinch
                                     (missid==4'd0) ? iqentry_2_livetarget |
3452 48 robfinch
                                                      iqentry_3_livetarget |
3453
                                                      iqentry_4_livetarget |
3454
                                                      iqentry_5_livetarget |
3455
                                                      iqentry_6_livetarget |
3456
                                                      iqentry_7_livetarget |
3457
                                                      iqentry_0_livetarget :
3458 52 robfinch
                                     (missid==4'd1) ? iqentry_2_livetarget |
3459 48 robfinch
                                                      iqentry_3_livetarget |
3460
                                                      iqentry_4_livetarget |
3461
                                                      iqentry_5_livetarget |
3462
                                                      iqentry_6_livetarget |
3463
                                                      iqentry_7_livetarget |
3464
                                                      iqentry_0_livetarget |
3465
                                                      iqentry_1_livetarget :
3466
                                                      {PREGS{1'b0}};
3467
 
3468 52 robfinch
    assign iqentry_3_cumulative = (missid==4'd3) ? iqentry_3_livetarget :
3469
                                     (missid==4'd4) ? iqentry_3_livetarget |
3470 48 robfinch
                                                      iqentry_4_livetarget :
3471 52 robfinch
                                     (missid==4'd5) ? iqentry_3_livetarget |
3472 48 robfinch
                                                      iqentry_4_livetarget |
3473
                                                      iqentry_5_livetarget :
3474 52 robfinch
                                     (missid==4'd6) ? iqentry_3_livetarget |
3475 48 robfinch
                                                      iqentry_4_livetarget |
3476
                                                      iqentry_5_livetarget |
3477
                                                      iqentry_6_livetarget :
3478 52 robfinch
                                     (missid==4'd7) ? iqentry_3_livetarget |
3479 48 robfinch
                                                      iqentry_4_livetarget |
3480
                                                      iqentry_5_livetarget |
3481
                                                      iqentry_6_livetarget |
3482
                                                      iqentry_7_livetarget :
3483 52 robfinch
                                     (missid==4'd0) ? iqentry_3_livetarget |
3484 48 robfinch
                                                      iqentry_4_livetarget |
3485
                                                      iqentry_5_livetarget |
3486
                                                      iqentry_6_livetarget |
3487
                                                      iqentry_7_livetarget |
3488
                                                      iqentry_0_livetarget :
3489 52 robfinch
                                     (missid==4'd1) ? iqentry_3_livetarget |
3490 48 robfinch
                                                      iqentry_4_livetarget |
3491
                                                      iqentry_5_livetarget |
3492
                                                      iqentry_6_livetarget |
3493
                                                      iqentry_7_livetarget |
3494
                                                      iqentry_0_livetarget |
3495
                                                      iqentry_1_livetarget :
3496 52 robfinch
                                     (missid==4'd2) ? iqentry_3_livetarget |
3497 48 robfinch
                                                      iqentry_4_livetarget |
3498
                                                      iqentry_5_livetarget |
3499
                                                      iqentry_6_livetarget |
3500
                                                      iqentry_7_livetarget |
3501
                                                      iqentry_0_livetarget |
3502
                                                      iqentry_1_livetarget |
3503
                                                      iqentry_2_livetarget :
3504
                                                      {PREGS{1'b0}};
3505
 
3506 52 robfinch
    assign iqentry_4_cumulative = (missid==4'd4) ? iqentry_4_livetarget :
3507
                                     (missid==4'd5) ? iqentry_4_livetarget |
3508 48 robfinch
                                                      iqentry_5_livetarget :
3509 52 robfinch
                                     (missid==4'd6) ? iqentry_4_livetarget |
3510 48 robfinch
                                                      iqentry_5_livetarget |
3511
                                                      iqentry_6_livetarget :
3512 52 robfinch
                                     (missid==4'd7) ? iqentry_4_livetarget |
3513 48 robfinch
                                                      iqentry_5_livetarget |
3514
                                                      iqentry_6_livetarget |
3515
                                                      iqentry_7_livetarget :
3516 52 robfinch
                                     (missid==4'd0) ? iqentry_4_livetarget |
3517 48 robfinch
                                                      iqentry_5_livetarget |
3518
                                                      iqentry_6_livetarget |
3519
                                                      iqentry_7_livetarget |
3520
                                                      iqentry_0_livetarget :
3521 52 robfinch
                                     (missid==4'd1) ? iqentry_4_livetarget |
3522 48 robfinch
                                                      iqentry_5_livetarget |
3523
                                                      iqentry_6_livetarget |
3524
                                                      iqentry_7_livetarget |
3525
                                                      iqentry_0_livetarget |
3526
                                                      iqentry_1_livetarget :
3527 52 robfinch
                                     (missid==4'd2) ? iqentry_4_livetarget |
3528 48 robfinch
                                                      iqentry_5_livetarget |
3529
                                                      iqentry_6_livetarget |
3530
                                                      iqentry_7_livetarget |
3531
                                                      iqentry_0_livetarget |
3532
                                                      iqentry_1_livetarget |
3533
                                                      iqentry_2_livetarget :
3534 52 robfinch
                                     (missid==4'd3) ? iqentry_4_livetarget |
3535 48 robfinch
                                                      iqentry_5_livetarget |
3536
                                                      iqentry_6_livetarget |
3537
                                                      iqentry_7_livetarget |
3538
                                                      iqentry_0_livetarget |
3539
                                                      iqentry_1_livetarget |
3540
                                                      iqentry_2_livetarget |
3541
                                                      iqentry_3_livetarget :
3542
                                                      {PREGS{1'b0}};
3543
 
3544 52 robfinch
    assign iqentry_5_cumulative = (missid==4'd5) ? iqentry_5_livetarget :
3545
                                     (missid==4'd6) ? iqentry_5_livetarget |
3546 48 robfinch
                                                      iqentry_6_livetarget :
3547 52 robfinch
                                     (missid==4'd7) ? iqentry_5_livetarget |
3548 48 robfinch
                                                      iqentry_6_livetarget |
3549
                                                      iqentry_7_livetarget :
3550 52 robfinch
                                     (missid==4'd0) ? iqentry_5_livetarget |
3551 48 robfinch
                                                      iqentry_6_livetarget |
3552
                                                      iqentry_7_livetarget |
3553
                                                      iqentry_0_livetarget :
3554 52 robfinch
                                     (missid==4'd1) ? iqentry_5_livetarget |
3555 48 robfinch
                                                      iqentry_6_livetarget |
3556
                                                      iqentry_7_livetarget |
3557
                                                      iqentry_0_livetarget |
3558
                                                      iqentry_1_livetarget :
3559 52 robfinch
                                     (missid==4'd2) ? iqentry_5_livetarget |
3560 48 robfinch
                                                      iqentry_6_livetarget |
3561
                                                      iqentry_7_livetarget |
3562
                                                      iqentry_0_livetarget |
3563
                                                      iqentry_1_livetarget |
3564
                                                      iqentry_2_livetarget :
3565 52 robfinch
                                     (missid==4'd3) ? iqentry_5_livetarget |
3566 48 robfinch
                                                      iqentry_6_livetarget |
3567
                                                      iqentry_7_livetarget |
3568
                                                      iqentry_0_livetarget |
3569
                                                      iqentry_1_livetarget |
3570
                                                      iqentry_2_livetarget |
3571
                                                      iqentry_3_livetarget :
3572 52 robfinch
                                     (missid==4'd4) ? iqentry_5_livetarget |
3573 48 robfinch
                                                      iqentry_6_livetarget |
3574
                                                      iqentry_7_livetarget |
3575
                                                      iqentry_0_livetarget |
3576
                                                      iqentry_1_livetarget |
3577
                                                      iqentry_2_livetarget |
3578
                                                      iqentry_3_livetarget |
3579
                                                      iqentry_4_livetarget :
3580
                                                      {PREGS{1'b0}};
3581 52 robfinch
    assign iqentry_6_cumulative = (missid==4'd6) ? iqentry_6_livetarget :
3582
                                       (missid==4'd7) ? iqentry_6_livetarget |
3583 48 robfinch
                                                        iqentry_7_livetarget :
3584 52 robfinch
                                       (missid==4'd0) ? iqentry_6_livetarget |
3585 48 robfinch
                                                        iqentry_7_livetarget |
3586
                                                        iqentry_0_livetarget :
3587 52 robfinch
                                       (missid==4'd1) ? iqentry_6_livetarget |
3588 48 robfinch
                                                        iqentry_7_livetarget |
3589
                                                        iqentry_0_livetarget |
3590
                                                        iqentry_1_livetarget :
3591 52 robfinch
                                       (missid==4'd2) ? iqentry_6_livetarget |
3592 48 robfinch
                                                        iqentry_7_livetarget |
3593
                                                        iqentry_0_livetarget |
3594
                                                        iqentry_1_livetarget |
3595
                                                        iqentry_2_livetarget :
3596 52 robfinch
                                       (missid==4'd3) ? iqentry_6_livetarget |
3597 48 robfinch
                                                        iqentry_7_livetarget |
3598
                                                        iqentry_0_livetarget |
3599
                                                        iqentry_1_livetarget |
3600
                                                        iqentry_2_livetarget |
3601
                                                        iqentry_3_livetarget :
3602 52 robfinch
                                       (missid==4'd4) ? iqentry_6_livetarget |
3603 48 robfinch
                                                        iqentry_7_livetarget |
3604
                                                        iqentry_0_livetarget |
3605
                                                        iqentry_1_livetarget |
3606
                                                        iqentry_2_livetarget |
3607
                                                        iqentry_3_livetarget |
3608
                                                        iqentry_4_livetarget :
3609 52 robfinch
                                       (missid==4'd5) ? iqentry_6_livetarget |
3610 48 robfinch
                                                        iqentry_7_livetarget |
3611
                                                        iqentry_0_livetarget |
3612
                                                        iqentry_1_livetarget |
3613
                                                        iqentry_2_livetarget |
3614
                                                        iqentry_3_livetarget |
3615
                                                        iqentry_4_livetarget |
3616
                                                        iqentry_5_livetarget :
3617
                                                        {PREGS{1'b0}};
3618
 
3619 52 robfinch
    assign iqentry_7_cumulative = (missid==4'd7) ? iqentry_7_livetarget :
3620
                                       (missid==4'd0) ? iqentry_7_livetarget |
3621 48 robfinch
                                                        iqentry_0_livetarget :
3622 52 robfinch
                                       (missid==4'd1) ? iqentry_7_livetarget |
3623 48 robfinch
                                                        iqentry_0_livetarget |
3624
                                                        iqentry_1_livetarget :
3625 52 robfinch
                                       (missid==4'd2) ? iqentry_7_livetarget |
3626 48 robfinch
                                                        iqentry_0_livetarget |
3627
                                                        iqentry_1_livetarget |
3628
                                                        iqentry_2_livetarget :
3629 52 robfinch
                                       (missid==4'd3) ? iqentry_7_livetarget |
3630 48 robfinch
                                                        iqentry_0_livetarget |
3631
                                                        iqentry_1_livetarget |
3632
                                                        iqentry_2_livetarget |
3633
                                                        iqentry_3_livetarget :
3634 52 robfinch
                                       (missid==4'd4) ? iqentry_7_livetarget |
3635 48 robfinch
                                                        iqentry_0_livetarget |
3636
                                                        iqentry_1_livetarget |
3637
                                                        iqentry_2_livetarget |
3638
                                                        iqentry_3_livetarget |
3639
                                                        iqentry_4_livetarget :
3640 52 robfinch
                                       (missid==4'd5) ? iqentry_7_livetarget |
3641 48 robfinch
                                                        iqentry_0_livetarget |
3642
                                                        iqentry_1_livetarget |
3643
                                                        iqentry_2_livetarget |
3644
                                                        iqentry_3_livetarget |
3645
                                                        iqentry_4_livetarget |
3646
                                                        iqentry_5_livetarget :
3647 52 robfinch
                                       (missid==4'd6) ? iqentry_7_livetarget |
3648 48 robfinch
                                                        iqentry_0_livetarget |
3649
                                                        iqentry_1_livetarget |
3650
                                                        iqentry_2_livetarget |
3651
                                                        iqentry_3_livetarget |
3652
                                                        iqentry_4_livetarget |
3653
                                                        iqentry_5_livetarget |
3654
                                                        iqentry_6_livetarget :
3655
                                                        {PREGS{1'b0}};
3656 52 robfinch
*/
3657
    assign iqentry_0_latestID = (missid == 4'd0 || ((iqentry_livetarget[0] & iqentry_cumulative[1]) == {PREGS{1'b0}}))
3658
                                    ? iqentry_livetarget[0]
3659
                                    : {PREGS{1'b0}};
3660 48 robfinch
 
3661 52 robfinch
    assign iqentry_1_latestID = (missid == 4'd1 || ((iqentry_livetarget[1] & iqentry_cumulative[2]) == {PREGS{1'b0}}))
3662
                                    ? iqentry_livetarget[1]
3663 48 robfinch
                                    : {PREGS{1'b0}};
3664
 
3665 52 robfinch
    assign iqentry_2_latestID = (missid == 4'd2 || ((iqentry_livetarget[2] & iqentry_cumulative[3]) == {PREGS{1'b0}}))
3666
                                    ? iqentry_livetarget[2]
3667 48 robfinch
                                    : {PREGS{1'b0}};
3668
 
3669 52 robfinch
    assign iqentry_3_latestID = (missid == 4'd3 || ((iqentry_livetarget[3] & iqentry_cumulative[4]) == {PREGS{1'b0}}))
3670
                                    ? iqentry_livetarget[3]
3671 48 robfinch
                                    : {PREGS{1'b0}};
3672
 
3673 52 robfinch
    assign iqentry_4_latestID = (missid == 4'd4 || ((iqentry_livetarget[4] & iqentry_cumulative[5]) == {PREGS{1'b0}}))
3674
                                    ? iqentry_livetarget[4]
3675 48 robfinch
                                    : {PREGS{1'b0}};
3676
 
3677 52 robfinch
    assign iqentry_5_latestID = (missid == 4'd5 || ((iqentry_livetarget[5] & iqentry_cumulative[6]) == {PREGS{1'b0}}))
3678
                                    ? iqentry_livetarget[5]
3679 48 robfinch
                                    : {PREGS{1'b0}};
3680
 
3681 52 robfinch
    assign iqentry_6_latestID = (missid == 4'd6 || ((iqentry_livetarget[6] & iqentry_cumulative[7]) == {PREGS{1'b0}}))
3682
                                    ? iqentry_livetarget[6]
3683 48 robfinch
                                    : {PREGS{1'b0}};
3684
 
3685 52 robfinch
    assign iqentry_7_latestID = (missid == 4'd7 || ((iqentry_livetarget[7] & iqentry_cumulative[8]) == {PREGS{1'b0}}))
3686
                                    ? iqentry_livetarget[7]
3687 48 robfinch
                                    : {PREGS{1'b0}};
3688
 
3689 52 robfinch
    assign iqentry_8_latestID = (missid == 4'd8 || ((iqentry_livetarget[8] & iqentry_cumulative[9]) == {PREGS{1'b0}}))
3690
                                    ? iqentry_livetarget[8]
3691 48 robfinch
                                    : {PREGS{1'b0}};
3692
 
3693 52 robfinch
    assign iqentry_9_latestID = (missid == 4'd9 || ((iqentry_livetarget[9] & iqentry_cumulative[0]) == {PREGS{1'b0}}))
3694
                                    ? iqentry_livetarget[9]
3695
                                    : {PREGS{1'b0}};
3696
 
3697
assign
3698
  iqentry_source[0] = | iqentry_0_latestID,
3699 49 robfinch
  iqentry_source[1] = | iqentry_1_latestID,
3700
  iqentry_source[2] = | iqentry_2_latestID,
3701
  iqentry_source[3] = | iqentry_3_latestID,
3702
  iqentry_source[4] = | iqentry_4_latestID,
3703
  iqentry_source[5] = | iqentry_5_latestID,
3704
  iqentry_source[6] = | iqentry_6_latestID,
3705 52 robfinch
  iqentry_source[7] = | iqentry_7_latestID,
3706
  iqentry_source[8] = | iqentry_8_latestID,
3707
  iqentry_source[9] = | iqentry_9_latestID
3708
  ;
3709 48 robfinch
 
3710
 
3711
reg vqueued2;
3712
assign Ra0 = fnRa(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3713
assign Rb0 = fnRb(fetchbuf0_instr,1'b0,vqe0,rfoa0[5:0],rfoa1[5:0],fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3714
assign Rc0 = fnRc(fetchbuf0_instr,vqe0,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3715
assign Rt0 = fnRt(fetchbuf0_instr,vqet0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3716
assign Ra1 = fnRa(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3717
assign Rb1 = fnRb(fetchbuf1_instr,1'b1,vqueued2 ? vqe0 + 1 : vqe1,rfoa0[5:0],rfoa1[5:0],fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3718
assign Rc1 = fnRc(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3719
assign Rt1 = fnRt(fetchbuf1_instr,vqueued2 ? vqet0 + 1 : vqet1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3720
 
3721 49 robfinch
//
3722
// additional logic for ISSUE
3723
//
3724
// for the moment, we look at ALU-input buffers to allow back-to-back issue of 
3725
// dependent instructions ... we do not, however, look ahead for DRAM requests 
3726
// that will become valid in the next cycle.  instead, these have to propagate
3727
// their results into the IQ entry directly, at which point it becomes issue-able
3728
//
3729 48 robfinch
 
3730 49 robfinch
// note that, for all intents & purposes, iqentry_done == iqentry_agen ... no need to duplicate
3731 48 robfinch
 
3732
wire [QENTRIES-1:0] args_valid;
3733
wire [QENTRIES-1:0] could_issue;
3734
wire [QENTRIES-1:0] could_issueid;
3735
 
3736
generate begin : issue_logic
3737
for (g = 0; g < QENTRIES; g = g + 1)
3738
begin
3739
assign args_valid[g] =
3740
                  (iqentry_a1_v[g]
3741 49 robfinch
`ifdef FU_BYPASS
3742 48 robfinch
        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3743 49 robfinch
        || ((iqentry_a1_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3744
        || ((iqentry_a1_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
3745
`endif
3746
        )
3747 48 robfinch
    && (iqentry_a2_v[g]
3748
        || (iqentry_mem[g] & ~iqentry_agen[g] & ~iqentry_memndx[g])    // a2 needs to be valid for indexed instruction
3749 49 robfinch
`ifdef FU_BYPASS
3750 48 robfinch
        || (iqentry_a2_s[g] == alu0_sourceid && alu0_dataready)
3751 49 robfinch
        || ((iqentry_a2_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3752
        || ((iqentry_a2_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
3753
`endif
3754
        )
3755 48 robfinch
    && (iqentry_a3_v[g]
3756
//        || (iqentry_mem[g] & ~iqentry_agen[g])
3757 49 robfinch
`ifdef FU_BYPASS
3758 48 robfinch
        || (iqentry_a3_s[g] == alu0_sourceid && alu0_dataready)
3759 49 robfinch
        || ((iqentry_a3_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3760
`endif
3761
        )
3762 48 robfinch
    ;
3763
 
3764
assign could_issue[g] = iqentry_v[g] && !iqentry_done[g] && !iqentry_out[g]
3765
                                                                                                && args_valid[g]
3766
                                                                                                && iqentry_iv[g]
3767
                        && (iqentry_mem[g] ? !iqentry_agen[g] : 1'b1);
3768
 
3769 52 robfinch
assign could_issueid[g] = (iqentry_v[g])// || (g==tail0 && canq1))// || (g==tail1 && canq2))
3770
                                                                                                                && !iqentry_iv[g];
3771 48 robfinch
//                && (iqentry_a1_v[g] 
3772
//        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3773
//        || (iqentry_a1_s[g] == alu1_sourceid && alu1_dataready));
3774
 
3775
end
3776
end
3777
endgenerate
3778
 
3779
// The (old) simulator didn't handle the asynchronous race loop properly in the 
3780
// original code. It would issue two instructions to the same islot. So the
3781
// issue logic has been re-written to eliminate the asynchronous loop.
3782
// Can't issue to the ALU if it's busy doing a long running operation like a 
3783
// divide.
3784
// ToDo: fix the memory synchronization, see fp_issue below
3785
 
3786
wire [`QBITS] heads [QENTRIES-1:0];
3787
assign heads[0] = head0;
3788
assign heads[1] = head1;
3789
assign heads[2] = head2;
3790
assign heads[3] = head3;
3791
assign heads[4] = head4;
3792
assign heads[5] = head5;
3793
assign heads[6] = head6;
3794
assign heads[7] = head7;
3795 52 robfinch
assign heads[8] = head8;
3796
assign heads[9] = head9;
3797 48 robfinch
 
3798
always @*
3799
begin
3800 49 robfinch
        iqentry_id1issue = {QENTRIES{1'b0}};
3801 48 robfinch
        if (id1_available) begin
3802
                for (n = 0; n < QENTRIES; n = n + 1)
3803 49 robfinch
                        if (could_issueid[heads[n]] && iqentry_id1issue=={QENTRIES{1'b0}})
3804 48 robfinch
                          iqentry_id1issue[heads[n]] = `TRUE;
3805
        end
3806 49 robfinch
end
3807
generate begin : gIDUIssue
3808
        if (`NUM_IDU > 1) begin
3809
                always @*
3810
                begin
3811
                        iqentry_id2issue = {QENTRIES{1'b0}};
3812
                        if (id2_available) begin
3813
                                for (n = 0; n < QENTRIES; n = n + 1)
3814
                                        if (could_issueid[heads[n]] && !iqentry_id1issue[heads[n]] && iqentry_id2issue=={QENTRIES{1'b0}})
3815
                                          iqentry_id2issue[heads[n]] = `TRUE;
3816
                        end
3817
                end
3818 48 robfinch
        end
3819 49 robfinch
        if (`NUM_IDU > 2) begin
3820
                always @*
3821
                begin
3822
                        iqentry_id3issue = {QENTRIES{1'b0}};
3823
                        if (id3_available) begin
3824
                                for (n = 0; n < QENTRIES; n = n + 1)
3825
                                        if (could_issueid[heads[n]]
3826
                                        && !iqentry_id1issue[heads[n]]
3827
                                        && !iqentry_id2issue[heads[n]]
3828
                                        && iqentry_id3issue=={QENTRIES{1'b0}})
3829
                                          iqentry_id3issue[heads[n]] = `TRUE;
3830
                        end
3831
                end
3832
        end
3833 48 robfinch
end
3834 49 robfinch
endgenerate
3835 48 robfinch
 
3836
always @*
3837
begin
3838 49 robfinch
        iqentry_alu0_issue = {QENTRIES{1'b0}};
3839
        iqentry_alu1_issue = {QENTRIES{1'b0}};
3840 48 robfinch
 
3841
        if (alu0_available & alu0_idle) begin
3842
                if (could_issue[head0] && iqentry_alu[head0]) begin
3843
                  iqentry_alu0_issue[head0] = `TRUE;
3844
                end
3845
                else if (could_issue[head1] && iqentry_alu[head1])
3846
                begin
3847
                  iqentry_alu0_issue[head1] = `TRUE;
3848
                end
3849
                else if (could_issue[head2] && iqentry_alu[head2]
3850
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3851
                )
3852
                begin
3853
                        iqentry_alu0_issue[head2] = `TRUE;
3854
                end
3855
                else if (could_issue[head3] && iqentry_alu[head3]
3856
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3857
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3858
                                ((!iqentry_v[head0])
3859
                        &&   (!iqentry_v[head1]))
3860
                        )
3861
                ) begin
3862
                        iqentry_alu0_issue[head3] = `TRUE;
3863
                end
3864
                else if (could_issue[head4] && iqentry_alu[head4]
3865
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3866
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3867
                                ((!iqentry_v[head0])
3868
                        &&   (!iqentry_v[head1]))
3869
                        )
3870
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3871
                                ((!iqentry_v[head0])
3872
                        &&   (!iqentry_v[head1])
3873
                        &&   (!iqentry_v[head2]))
3874
                        )
3875
                ) begin
3876
                        iqentry_alu0_issue[head4] = `TRUE;
3877
                end
3878
                else if (could_issue[head5] && iqentry_alu[head5]
3879
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3880
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3881
                                ((!iqentry_v[head0])
3882
                        &&   (!iqentry_v[head1]))
3883
                        )
3884
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3885
                                ((!iqentry_v[head0])
3886
                        &&   (!iqentry_v[head1])
3887
                        &&   (!iqentry_v[head2]))
3888
                        )
3889
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3890
                                ((!iqentry_v[head0])
3891
                        &&   (!iqentry_v[head1])
3892
                        &&   (!iqentry_v[head2])
3893
                        &&   (!iqentry_v[head3]))
3894
                        )
3895
                ) begin
3896
                        iqentry_alu0_issue[head5] = `TRUE;
3897
                end
3898
`ifdef FULL_ISSUE_LOGIC
3899
                else if (could_issue[head6] && iqentry_alu[head6]
3900
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3901
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3902
                                ((!iqentry_v[head0])
3903
                        &&   (!iqentry_v[head1]))
3904
                        )
3905
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3906
                                ((!iqentry_v[head0])
3907
                        &&   (!iqentry_v[head1])
3908
                        &&   (!iqentry_v[head2]))
3909
                        )
3910
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3911
                                ((!iqentry_v[head0])
3912
                        &&   (!iqentry_v[head1])
3913
                        &&   (!iqentry_v[head2])
3914
                        &&   (!iqentry_v[head3]))
3915
                        )
3916
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3917
                                ((!iqentry_v[head0])
3918
                        &&   (!iqentry_v[head1])
3919
                        &&   (!iqentry_v[head2])
3920
                        &&   (!iqentry_v[head3])
3921
                        &&   (!iqentry_v[head4]))
3922
                        )
3923
                ) begin
3924
                        iqentry_alu0_issue[head6] = `TRUE;
3925
                end
3926
                else if (could_issue[head7] && iqentry_alu[head7]
3927
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3928
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3929
                                ((!iqentry_v[head0])
3930
                        &&   (!iqentry_v[head1]))
3931
                        )
3932
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3933
                                ((!iqentry_v[head0])
3934
                        &&   (!iqentry_v[head1])
3935
                        &&   (!iqentry_v[head2]))
3936
                        )
3937
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3938
                                ((!iqentry_v[head0])
3939
                        &&   (!iqentry_v[head1])
3940
                        &&   (!iqentry_v[head2])
3941
                        &&   (!iqentry_v[head3]))
3942
                        )
3943
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3944
                                ((!iqentry_v[head0])
3945
                        &&   (!iqentry_v[head1])
3946
                        &&   (!iqentry_v[head2])
3947
                        &&   (!iqentry_v[head3])
3948
                        &&   (!iqentry_v[head4]))
3949
                        )
3950
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
3951
                                ((!iqentry_v[head0])
3952
                        &&   (!iqentry_v[head1])
3953
                        &&   (!iqentry_v[head2])
3954
                        &&   (!iqentry_v[head3])
3955
                        &&   (!iqentry_v[head4])
3956
                        &&   (!iqentry_v[head5]))
3957
                        )
3958
                ) begin
3959
                        iqentry_alu0_issue[head7] = `TRUE;
3960
                end
3961
`endif
3962
        end
3963
 
3964 49 robfinch
        if (alu1_available && alu1_idle && `NUM_ALU > 1) begin
3965 48 robfinch
                if ((could_issue & ~iqentry_alu0_issue & ~iqentry_alu0) != 8'h00) begin
3966
                if (could_issue[head0] && iqentry_alu[head0]
3967
                && !iqentry_alu0[head0] // alu0only
3968
                && !iqentry_alu0_issue[head0]) begin
3969
                  iqentry_alu1_issue[head0] = `TRUE;
3970
                end
3971
                else if (could_issue[head1] && !iqentry_alu0_issue[head1] && iqentry_alu[head1]
3972
                && !iqentry_alu0[head1])
3973
                begin
3974
                  iqentry_alu1_issue[head1] = `TRUE;
3975
                end
3976
                else if (could_issue[head2] && !iqentry_alu0_issue[head2] && iqentry_alu[head2]
3977
                && !iqentry_alu0[head2]
3978
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3979
                )
3980
                begin
3981
                        iqentry_alu1_issue[head2] = `TRUE;
3982
                end
3983
                else if (could_issue[head3] && !iqentry_alu0_issue[head3] && iqentry_alu[head3]
3984
                && !iqentry_alu0[head3]
3985
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3986
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3987
                                ((!iqentry_v[head0])
3988
                        &&   (!iqentry_v[head1]))
3989
                        )
3990
                ) begin
3991
                        iqentry_alu1_issue[head3] = `TRUE;
3992
                end
3993
                else if (could_issue[head4] && !iqentry_alu0_issue[head4] && iqentry_alu[head4]
3994
                && !iqentry_alu0[head4]
3995
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3996
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3997
                                ((!iqentry_v[head0])
3998
                        &&   (!iqentry_v[head1]))
3999
                        )
4000
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4001
                                ((!iqentry_v[head0])
4002
                        &&   (!iqentry_v[head1])
4003
                        &&   (!iqentry_v[head2]))
4004
                        )
4005
                ) begin
4006
                        iqentry_alu1_issue[head4] = `TRUE;
4007
                end
4008
                else if (could_issue[head5] && !iqentry_alu0_issue[head5] && iqentry_alu[head5]
4009
                && !iqentry_alu0[head5]
4010
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4011
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4012
                                ((!iqentry_v[head0])
4013
                        &&   (!iqentry_v[head1]))
4014
                        )
4015
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4016
                                ((!iqentry_v[head0])
4017
                        &&   (!iqentry_v[head1])
4018
                        &&   (!iqentry_v[head2]))
4019
                        )
4020
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4021
                                ((!iqentry_v[head0])
4022
                        &&   (!iqentry_v[head1])
4023
                        &&   (!iqentry_v[head2])
4024
                        &&   (!iqentry_v[head3]))
4025
                        )
4026
                ) begin
4027
                        iqentry_alu1_issue[head5] = `TRUE;
4028
                end
4029
`ifdef FULL_ISSUE_LOGIC
4030
                else if (could_issue[head6] && !iqentry_alu0_issue[head6] && iqentry_alu[head6]
4031
                && !iqentry_alu0[head6]
4032
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4033
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4034
                                ((!iqentry_v[head0])
4035
                        &&   (!iqentry_v[head1]))
4036
                        )
4037
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4038
                                ((!iqentry_v[head0])
4039
                        &&   (!iqentry_v[head1])
4040
                        &&   (!iqentry_v[head2]))
4041
                        )
4042
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4043
                                ((!iqentry_v[head0])
4044
                        &&   (!iqentry_v[head1])
4045
                        &&   (!iqentry_v[head2])
4046
                        &&   (!iqentry_v[head3]))
4047
                        )
4048
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4049
                                ((!iqentry_v[head0])
4050
                        &&   (!iqentry_v[head1])
4051
                        &&   (!iqentry_v[head2])
4052
                        &&   (!iqentry_v[head3])
4053
                        &&   (!iqentry_v[head4]))
4054
                        )
4055
                ) begin
4056
                        iqentry_alu1_issue[head6] = `TRUE;
4057
                end
4058
                else if (could_issue[head7] && !iqentry_alu0_issue[head7] && iqentry_alu[head7]
4059
                && !iqentry_alu0[head7]
4060
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4061
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4062
                                ((!iqentry_v[head0])
4063
                        &&   (!iqentry_v[head1]))
4064
                        )
4065
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4066
                                ((!iqentry_v[head0])
4067
                        &&   (!iqentry_v[head1])
4068
                        &&   (!iqentry_v[head2]))
4069
                        )
4070
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4071
                                ((!iqentry_v[head0])
4072
                        &&   (!iqentry_v[head1])
4073
                        &&   (!iqentry_v[head2])
4074
                        &&   (!iqentry_v[head3]))
4075
                        )
4076
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4077
                                ((!iqentry_v[head0])
4078
                        &&   (!iqentry_v[head1])
4079
                        &&   (!iqentry_v[head2])
4080
                        &&   (!iqentry_v[head3])
4081
                        &&   (!iqentry_v[head4]))
4082
                        )
4083
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4084
                                ((!iqentry_v[head0])
4085
                        &&   (!iqentry_v[head1])
4086
                        &&   (!iqentry_v[head2])
4087
                        &&   (!iqentry_v[head3])
4088
                        &&   (!iqentry_v[head4])
4089
                        &&   (!iqentry_v[head5]))
4090
                        )
4091
                ) begin
4092
                        iqentry_alu1_issue[head7] = `TRUE;
4093
                end
4094
`endif
4095
        end
4096
//      aluissue(alu0_idle,8'h00,2'b00);
4097
//      aluissue(alu1_idle,iqentry_alu0,2'b01);
4098
        end
4099
end
4100
 
4101
always @*
4102
begin
4103 49 robfinch
        iqentry_fpu1_issue = {QENTRIES{1'b0}};
4104
//      fpu1issue(fpu1_idle,2'b00);
4105
        if (fpu1_idle && `NUM_FPU > 0) begin
4106 48 robfinch
    if (could_issue[head0] && iqentry_fpu[head0]) begin
4107 49 robfinch
      iqentry_fpu1_issue[head0] = `TRUE;
4108 48 robfinch
    end
4109
    else if (could_issue[head1] && iqentry_fpu[head1])
4110
    begin
4111 49 robfinch
      iqentry_fpu1_issue[head1] = `TRUE;
4112 48 robfinch
    end
4113
    else if (could_issue[head2] && iqentry_fpu[head2]
4114
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4115
    ) begin
4116 49 robfinch
      iqentry_fpu1_issue[head2] = `TRUE;
4117 48 robfinch
    end
4118
    else if (could_issue[head3] && iqentry_fpu[head3]
4119
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4120
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4121
                ((!iqentry_v[head0])
4122
        &&   (!iqentry_v[head1]))
4123
        )
4124
    ) begin
4125 49 robfinch
      iqentry_fpu1_issue[head3] = `TRUE;
4126 48 robfinch
    end
4127
    else if (could_issue[head4] && iqentry_fpu[head4]
4128
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4129
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4130
                ((!iqentry_v[head0])
4131
        &&   (!iqentry_v[head1]))
4132
        )
4133
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4134
                ((!iqentry_v[head0])
4135
        &&   (!iqentry_v[head1])
4136
        &&   (!iqentry_v[head2]))
4137
        )
4138
    ) begin
4139 49 robfinch
      iqentry_fpu1_issue[head4] = `TRUE;
4140 48 robfinch
    end
4141
    else if (could_issue[head5] && iqentry_fpu[head5]
4142
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4143
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4144
                ((!iqentry_v[head0])
4145
        &&   (!iqentry_v[head1]))
4146
        )
4147
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4148
                ((!iqentry_v[head0])
4149
        &&   (!iqentry_v[head1])
4150
        &&   (!iqentry_v[head2]))
4151
        )
4152
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4153
                ((!iqentry_v[head0])
4154
        &&   (!iqentry_v[head1])
4155
        &&   (!iqentry_v[head2])
4156
        &&   (!iqentry_v[head3]))
4157
        )
4158
        ) begin
4159 49 robfinch
              iqentry_fpu1_issue[head5] = `TRUE;
4160 48 robfinch
    end
4161
`ifdef FULL_ISSUE_LOGIC
4162
    else if (could_issue[head6] && iqentry_fpu[head6]
4163
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4164
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4165
                ((!iqentry_v[head0])
4166
        &&   (!iqentry_v[head1]))
4167
        )
4168
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4169
                ((!iqentry_v[head0])
4170
        &&   (!iqentry_v[head1])
4171
        &&   (!iqentry_v[head2]))
4172
        )
4173
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4174
                ((!iqentry_v[head0])
4175
        &&   (!iqentry_v[head1])
4176
        &&   (!iqentry_v[head2])
4177
        &&   (!iqentry_v[head3]))
4178
        )
4179
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4180
                ((!iqentry_v[head0])
4181
        &&   (!iqentry_v[head1])
4182
        &&   (!iqentry_v[head2])
4183
        &&   (!iqentry_v[head3])
4184
        &&   (!iqentry_v[head4]))
4185
        )
4186
    ) begin
4187 49 robfinch
        iqentry_fpu1_issue[head6] = `TRUE;
4188 48 robfinch
    end
4189
    else if (could_issue[head7] && iqentry_fpu[head7]
4190
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4191
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4192
                ((!iqentry_v[head0])
4193
        &&   (!iqentry_v[head1]))
4194
        )
4195
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4196
                ((!iqentry_v[head0])
4197
        &&   (!iqentry_v[head1])
4198
        &&   (!iqentry_v[head2]))
4199
        )
4200
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4201
                ((!iqentry_v[head0])
4202
        &&   (!iqentry_v[head1])
4203
        &&   (!iqentry_v[head2])
4204
        &&   (!iqentry_v[head3]))
4205
        )
4206
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4207
                ((!iqentry_v[head0])
4208
        &&   (!iqentry_v[head1])
4209
        &&   (!iqentry_v[head2])
4210
        &&   (!iqentry_v[head3])
4211
        &&   (!iqentry_v[head4]))
4212
        )
4213
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
4214
                ((!iqentry_v[head0])
4215
        &&   (!iqentry_v[head1])
4216
        &&   (!iqentry_v[head2])
4217
        &&   (!iqentry_v[head3])
4218
        &&   (!iqentry_v[head4])
4219
        &&   (!iqentry_v[head5]))
4220
        )
4221
        )
4222
    begin
4223 49 robfinch
                iqentry_fpu1_issue[head7] = `TRUE;
4224 48 robfinch
        end
4225
`endif
4226
        end
4227
end
4228
 
4229 49 robfinch
always @*
4230
begin
4231
        iqentry_fpu2_issue = {QENTRIES{1'b0}};
4232
//      fpu2issue(fpu2_idle,2'b00);
4233
        if (fpu2_idle && `NUM_FPU > 1) begin
4234
    if (could_issue[head0] && iqentry_fpu[head0] && !iqentry_fpu1_issue[head0]) begin
4235
      iqentry_fpu2_issue[head0] = `TRUE;
4236
    end
4237
    else if (could_issue[head1] && iqentry_fpu[head1] && !iqentry_fpu1_issue[head1])
4238
    begin
4239
      iqentry_fpu2_issue[head1] = `TRUE;
4240
    end
4241
    else if (could_issue[head2] && iqentry_fpu[head2] && !iqentry_fpu1_issue[head2]
4242
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4243
    ) begin
4244
      iqentry_fpu2_issue[head2] = `TRUE;
4245
    end
4246
    else if (could_issue[head3] && iqentry_fpu[head3] && !iqentry_fpu1_issue[head3]
4247
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4248
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4249
                ((!iqentry_v[head0])
4250
        &&   (!iqentry_v[head1]))
4251
        )
4252
    ) begin
4253
      iqentry_fpu2_issue[head3] = `TRUE;
4254
    end
4255
    else if (could_issue[head4] && iqentry_fpu[head4] && !iqentry_fpu1_issue[head4]
4256
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4257
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4258
                ((!iqentry_v[head0])
4259
        &&   (!iqentry_v[head1]))
4260
        )
4261
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4262
                ((!iqentry_v[head0])
4263
        &&   (!iqentry_v[head1])
4264
        &&   (!iqentry_v[head2]))
4265
        )
4266
    ) begin
4267
      iqentry_fpu2_issue[head4] = `TRUE;
4268
    end
4269
    else if (could_issue[head5] && iqentry_fpu[head5] && !iqentry_fpu1_issue[head5]
4270
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4271
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4272
                ((!iqentry_v[head0])
4273
        &&   (!iqentry_v[head1]))
4274
        )
4275
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4276
                ((!iqentry_v[head0])
4277
        &&   (!iqentry_v[head1])
4278
        &&   (!iqentry_v[head2]))
4279
        )
4280
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4281
                ((!iqentry_v[head0])
4282
        &&   (!iqentry_v[head1])
4283
        &&   (!iqentry_v[head2])
4284
        &&   (!iqentry_v[head3]))
4285
        )
4286
        ) begin
4287
              iqentry_fpu2_issue[head5] = `TRUE;
4288
    end
4289
`ifdef FULL_ISSUE_LOGIC
4290
    else if (could_issue[head6] && iqentry_fpu[head6] && !iqentry_fpu1_issue[head6]
4291
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4292
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4293
                ((!iqentry_v[head0])
4294
        &&   (!iqentry_v[head1]))
4295
        )
4296
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4297
                ((!iqentry_v[head0])
4298
        &&   (!iqentry_v[head1])
4299
        &&   (!iqentry_v[head2]))
4300
        )
4301
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4302
                ((!iqentry_v[head0])
4303
        &&   (!iqentry_v[head1])
4304
        &&   (!iqentry_v[head2])
4305
        &&   (!iqentry_v[head3]))
4306
        )
4307
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4308
                ((!iqentry_v[head0])
4309
        &&   (!iqentry_v[head1])
4310
        &&   (!iqentry_v[head2])
4311
        &&   (!iqentry_v[head3])
4312
        &&   (!iqentry_v[head4]))
4313
        )
4314
    ) begin
4315
        iqentry_fpu2_issue[head6] = `TRUE;
4316
    end
4317
    else if (could_issue[head7] && iqentry_fpu[head7] && !iqentry_fpu1_issue[head7]
4318
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4319
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4320
                ((!iqentry_v[head0])
4321
        &&   (!iqentry_v[head1]))
4322
        )
4323
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4324
                ((!iqentry_v[head0])
4325
        &&   (!iqentry_v[head1])
4326
        &&   (!iqentry_v[head2]))
4327
        )
4328
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4329
                ((!iqentry_v[head0])
4330
        &&   (!iqentry_v[head1])
4331
        &&   (!iqentry_v[head2])
4332
        &&   (!iqentry_v[head3]))
4333
        )
4334
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4335
                ((!iqentry_v[head0])
4336
        &&   (!iqentry_v[head1])
4337
        &&   (!iqentry_v[head2])
4338
        &&   (!iqentry_v[head3])
4339
        &&   (!iqentry_v[head4]))
4340
        )
4341
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
4342
                ((!iqentry_v[head0])
4343
        &&   (!iqentry_v[head1])
4344
        &&   (!iqentry_v[head2])
4345
        &&   (!iqentry_v[head3])
4346
        &&   (!iqentry_v[head4])
4347
        &&   (!iqentry_v[head5]))
4348
        )
4349
        )
4350
    begin
4351
                iqentry_fpu2_issue[head7] = `TRUE;
4352
        end
4353
`endif
4354
        end
4355
end
4356 48 robfinch
 
4357
wire [QENTRIES-1:0] nextqd;
4358
// Next queue id
4359
 
4360
reg [`QBITS] nid0;
4361
always @*
4362
if (iqentry_thrd[1]==iqentry_thrd[0])
4363 52 robfinch
        nid0 = 4'd1;
4364 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[0])
4365 52 robfinch
        nid0 = 4'd2;
4366 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[0])
4367 52 robfinch
        nid0 = 4'd3;
4368 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[0])
4369 52 robfinch
        nid0 = 4'd4;
4370 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[0])
4371 52 robfinch
        nid0 = 4'd5;
4372 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[0])
4373 52 robfinch
        nid0 = 4'd6;
4374 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[0])
4375 52 robfinch
        nid0 = 4'd7;
4376
else if (iqentry_thrd[8]==iqentry_thrd[0])
4377
        nid0 = 4'd8;
4378
else if (iqentry_thrd[9]==iqentry_thrd[0])
4379
        nid0 = 4'd9;
4380 48 robfinch
else
4381
        nid0 = 3'd0;
4382
 
4383
reg [`QBITS] nid1;
4384
always @*
4385
if (iqentry_thrd[2]==iqentry_thrd[1])
4386 52 robfinch
        nid1 = 4'd2;
4387 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[1])
4388 52 robfinch
        nid1 = 4'd3;
4389 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[1])
4390 52 robfinch
        nid1 = 4'd4;
4391 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[1])
4392 52 robfinch
        nid1 = 4'd5;
4393 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[1])
4394 52 robfinch
        nid1 = 4'd6;
4395 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[1])
4396 52 robfinch
        nid1 = 4'd7;
4397
else if (iqentry_thrd[8]==iqentry_thrd[1])
4398
        nid1 = 4'd8;
4399
else if (iqentry_thrd[9]==iqentry_thrd[1])
4400
        nid1 = 4'd9;
4401 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[1])
4402 52 robfinch
        nid1 = 4'd0;
4403 48 robfinch
else
4404 52 robfinch
        nid1 = 4'd1;
4405 48 robfinch
 
4406
reg [`QBITS] nid2;
4407
always @*
4408
if (iqentry_thrd[3]==iqentry_thrd[2])
4409 52 robfinch
        nid2 = 4'd3;
4410 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[2])
4411 52 robfinch
        nid2 = 4'd4;
4412 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[2])
4413 52 robfinch
        nid2 = 4'd5;
4414 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[2])
4415 52 robfinch
        nid2 = 4'd6;
4416 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[2])
4417 52 robfinch
        nid2 = 4'd7;
4418
else if (iqentry_thrd[8]==iqentry_thrd[2])
4419
        nid2 = 4'd8;
4420
else if (iqentry_thrd[9]==iqentry_thrd[2])
4421
        nid2 = 4'd9;
4422 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[2])
4423 52 robfinch
        nid2 = 4'd0;
4424 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[2])
4425 52 robfinch
        nid2 = 4'd1;
4426 48 robfinch
else
4427 52 robfinch
        nid2 = 4'd2;
4428 48 robfinch
 
4429
reg [`QBITS] nid3;
4430
always @*
4431
if (iqentry_thrd[4]==iqentry_thrd[3])
4432 52 robfinch
        nid3 = 4'd4;
4433 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[3])
4434 52 robfinch
        nid3 = 4'd5;
4435 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[3])
4436 52 robfinch
        nid3 = 4'd6;
4437 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[3])
4438 52 robfinch
        nid3 = 4'd7;
4439
else if (iqentry_thrd[8]==iqentry_thrd[3])
4440
        nid3 = 4'd8;
4441
else if (iqentry_thrd[9]==iqentry_thrd[3])
4442
        nid3 = 4'd9;
4443 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[3])
4444 52 robfinch
        nid3 = 4'd0;
4445 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[3])
4446 52 robfinch
        nid3 = 4'd1;
4447 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[3])
4448 52 robfinch
        nid3 = 4'd2;
4449 48 robfinch
else
4450 52 robfinch
        nid3 = 4'd3;
4451 48 robfinch
 
4452
reg [`QBITS] nid4;
4453
always @*
4454
if (iqentry_thrd[5]==iqentry_thrd[4])
4455 52 robfinch
        nid4 = 4'd5;
4456 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[4])
4457 52 robfinch
        nid4 = 4'd6;
4458 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[4])
4459 52 robfinch
        nid4 = 4'd7;
4460
else if (iqentry_thrd[8]==iqentry_thrd[4])
4461
        nid4 = 4'd8;
4462
else if (iqentry_thrd[9]==iqentry_thrd[4])
4463
        nid4 = 4'd9;
4464 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[4])
4465 52 robfinch
        nid4 = 4'd0;
4466 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[4])
4467 52 robfinch
        nid4 = 4'd1;
4468 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[4])
4469 52 robfinch
        nid4 = 4'd2;
4470 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[4])
4471 52 robfinch
        nid4 = 4'd3;
4472 48 robfinch
else
4473 52 robfinch
        nid4 = 4'd4;
4474 48 robfinch
 
4475
reg [`QBITS] nid5;
4476
always @*
4477
if (iqentry_thrd[6]==iqentry_thrd[5])
4478 52 robfinch
        nid5 = 4'd6;
4479 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[5])
4480 52 robfinch
        nid5 = 4'd7;
4481
else if (iqentry_thrd[8]==iqentry_thrd[5])
4482
        nid5 = 4'd8;
4483
else if (iqentry_thrd[9]==iqentry_thrd[5])
4484
        nid5 = 4'd9;
4485 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[5])
4486 52 robfinch
        nid5 = 4'd0;
4487 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[5])
4488 52 robfinch
        nid5 = 4'd1;
4489 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[5])
4490 52 robfinch
        nid5 = 4'd2;
4491 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[5])
4492 52 robfinch
        nid5 = 4'd3;
4493 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[5])
4494 52 robfinch
        nid5 = 4'd4;
4495 48 robfinch
else
4496 52 robfinch
        nid5 = 4'd5;
4497 48 robfinch
 
4498
reg [`QBITS] nid6;
4499
always @*
4500
if (iqentry_thrd[7]==iqentry_thrd[6])
4501 52 robfinch
        nid6 = 4'd7;
4502
else if (iqentry_thrd[8]==iqentry_thrd[6])
4503
        nid6 = 4'd8;
4504
else if (iqentry_thrd[9]==iqentry_thrd[6])
4505
        nid6 = 4'd9;
4506 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[6])
4507 52 robfinch
        nid6 = 4'd0;
4508 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[6])
4509 52 robfinch
        nid6 = 4'd1;
4510 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[6])
4511 52 robfinch
        nid6 = 4'd2;
4512 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[6])
4513 52 robfinch
        nid6 = 4'd3;
4514 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[6])
4515 52 robfinch
        nid6 = 4'd4;
4516 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[6])
4517 52 robfinch
        nid6 = 4'd5;
4518 48 robfinch
else
4519 52 robfinch
        nid6 = 4'd6;
4520 48 robfinch
 
4521
reg [`QBITS] nid7;
4522
always @*
4523 52 robfinch
if (iqentry_thrd[8]==iqentry_thrd[7])
4524
        nid7 = 4'd8;
4525
else if (iqentry_thrd[9]==iqentry_thrd[7])
4526
        nid7 = 4'd9;
4527
else if (iqentry_thrd[0]==iqentry_thrd[7])
4528
        nid7 = 4'd0;
4529 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[7])
4530 52 robfinch
        nid7 = 4'd1;
4531 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[7])
4532 52 robfinch
        nid7 = 4'd2;
4533 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[7])
4534 52 robfinch
        nid7 = 4'd3;
4535 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[7])
4536 52 robfinch
        nid7 = 4'd4;
4537 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[7])
4538 52 robfinch
        nid7 = 4'd5;
4539 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[7])
4540 52 robfinch
        nid7 = 4'd6;
4541 48 robfinch
else
4542 52 robfinch
        nid7 = 4'd7;
4543 48 robfinch
 
4544 52 robfinch
reg [`QBITS] nid8;
4545
always @*
4546
if (iqentry_thrd[9]==iqentry_thrd[8])
4547
        nid8 = 4'd9;
4548
else if (iqentry_thrd[0]==iqentry_thrd[8])
4549
        nid8 = 4'd0;
4550
else if (iqentry_thrd[1]==iqentry_thrd[8])
4551
        nid8 = 4'd1;
4552
else if (iqentry_thrd[2]==iqentry_thrd[8])
4553
        nid8 = 4'd2;
4554
else if (iqentry_thrd[3]==iqentry_thrd[8])
4555
        nid8 = 4'd3;
4556
else if (iqentry_thrd[4]==iqentry_thrd[8])
4557
        nid8 = 4'd4;
4558
else if (iqentry_thrd[5]==iqentry_thrd[8])
4559
        nid8 = 4'd5;
4560
else if (iqentry_thrd[6]==iqentry_thrd[8])
4561
        nid8 = 4'd6;
4562
else if (iqentry_thrd[7]==iqentry_thrd[8])
4563
        nid8 = 4'd7;
4564
else
4565
        nid8 = 4'd8;
4566
 
4567
reg [`QBITS] nid9;
4568
always @*
4569
if (iqentry_thrd[0]==iqentry_thrd[9])
4570
        nid9 = 4'd0;
4571
else if (iqentry_thrd[1]==iqentry_thrd[9])
4572
        nid9 = 4'd1;
4573
else if (iqentry_thrd[2]==iqentry_thrd[9])
4574
        nid9 = 4'd2;
4575
else if (iqentry_thrd[3]==iqentry_thrd[9])
4576
        nid9 = 4'd3;
4577
else if (iqentry_thrd[4]==iqentry_thrd[9])
4578
        nid9 = 4'd4;
4579
else if (iqentry_thrd[5]==iqentry_thrd[9])
4580
        nid9 = 4'd5;
4581
else if (iqentry_thrd[6]==iqentry_thrd[9])
4582
        nid9 = 4'd6;
4583
else if (iqentry_thrd[7]==iqentry_thrd[9])
4584
        nid9 = 4'd7;
4585
else if (iqentry_thrd[8]==iqentry_thrd[9])
4586
        nid9 = 4'd8;
4587
else
4588
        nid9 = 4'd9;
4589
 
4590 48 robfinch
// Search the queue for the next entry on the same thread.
4591
reg [`QBITS] nid;
4592
always @*
4593
if (iqentry_thrd[idp1(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4594
        nid = idp1(fcu_id);
4595
else if (iqentry_thrd[idp2(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4596
        nid = idp2(fcu_id);
4597
else if (iqentry_thrd[idp3(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4598
        nid = idp3(fcu_id);
4599
else if (iqentry_thrd[idp4(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4600
        nid = idp4(fcu_id);
4601
else if (iqentry_thrd[idp5(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4602
        nid = idp5(fcu_id);
4603
else if (iqentry_thrd[idp6(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4604
        nid = idp6(fcu_id);
4605
else if (iqentry_thrd[idp7(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4606
        nid = idp7(fcu_id);
4607 52 robfinch
else if (iqentry_thrd[idp8(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4608
        nid = idp8(fcu_id);
4609
else if (iqentry_thrd[idp9(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4610
        nid = idp9(fcu_id);
4611 48 robfinch
else
4612
        nid = fcu_id;
4613
 
4614
 
4615
assign  nextqd[0] = iqentry_sn[nid0] > iqentry_sn[0] || iqentry_v[0];
4616
assign  nextqd[1] = iqentry_sn[nid1] > iqentry_sn[1] || iqentry_v[1];
4617
assign  nextqd[2] = iqentry_sn[nid2] > iqentry_sn[2] || iqentry_v[2];
4618
assign  nextqd[3] = iqentry_sn[nid3] > iqentry_sn[3] || iqentry_v[3];
4619
assign  nextqd[4] = iqentry_sn[nid4] > iqentry_sn[4] || iqentry_v[4];
4620
assign  nextqd[5] = iqentry_sn[nid5] > iqentry_sn[5] || iqentry_v[5];
4621
assign  nextqd[6] = iqentry_sn[nid6] > iqentry_sn[6] || iqentry_v[6];
4622
assign  nextqd[7] = iqentry_sn[nid7] > iqentry_sn[7] || iqentry_v[7];
4623 52 robfinch
assign  nextqd[8] = iqentry_sn[nid8] > iqentry_sn[8] || iqentry_v[8];
4624
assign  nextqd[9] = iqentry_sn[nid9] > iqentry_sn[9] || iqentry_v[9];
4625 48 robfinch
 
4626
//assign nextqd = 8'hFF;
4627
 
4628
// Don't issue to the fcu until the following instruction is enqueued.
4629
// However, if the queue is full then issue anyway. A branch miss will likely occur.
4630
always @*//(could_issue or head0 or head1 or head2 or head3 or head4 or head5 or head6 or head7)
4631
begin
4632 49 robfinch
        iqentry_fcu_issue = {QENTRIES{1'b0}};
4633 48 robfinch
        if (fcu_done) begin
4634
    if (could_issue[head0] && iqentry_fc[head0] && nextqd[head0]) begin
4635
      iqentry_fcu_issue[head0] = `TRUE;
4636
    end
4637
    else if (could_issue[head1] && iqentry_fc[head1] && nextqd[head1])
4638
    begin
4639
      iqentry_fcu_issue[head1] = `TRUE;
4640
    end
4641
    else if (could_issue[head2] && iqentry_fc[head2] && nextqd[head2]
4642
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4643
    ) begin
4644
                iqentry_fcu_issue[head2] = `TRUE;
4645
    end
4646
    else if (could_issue[head3] && iqentry_fc[head3] && nextqd[head3]
4647
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4648
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4649
                ((!iqentry_v[head0])
4650
        &&   (!iqentry_v[head1]))
4651
        )
4652
    ) begin
4653
                iqentry_fcu_issue[head3] = `TRUE;
4654
    end
4655
    else if (could_issue[head4] && iqentry_fc[head4] && nextqd[head4]
4656
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4657
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4658
                ((!iqentry_v[head0])
4659
        &&   (!iqentry_v[head1]))
4660
        )
4661
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4662
                ((!iqentry_v[head0])
4663
        &&   (!iqentry_v[head1])
4664
        &&   (!iqentry_v[head2]))
4665
        )
4666
    ) begin
4667
                iqentry_fcu_issue[head4] = `TRUE;
4668
    end
4669
    else if (could_issue[head5] && iqentry_fc[head5] && nextqd[head5]
4670
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4671
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4672
                ((!iqentry_v[head0])
4673
        &&   (!iqentry_v[head1]))
4674
        )
4675
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4676
                ((!iqentry_v[head0])
4677
        &&   (!iqentry_v[head1])
4678
        &&   (!iqentry_v[head2]))
4679
        )
4680
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4681
                ((!iqentry_v[head0])
4682
        &&   (!iqentry_v[head1])
4683
        &&   (!iqentry_v[head2])
4684
        &&   (!iqentry_v[head3]))
4685
        )
4686
    ) begin
4687
                iqentry_fcu_issue[head5] = `TRUE;
4688
    end
4689
 
4690
`ifdef FULL_ISSUE_LOGIC
4691
    else if (could_issue[head6] && iqentry_fc[head6] && nextqd[head6]
4692
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4693
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4694
                ((!iqentry_v[head0])
4695
        &&   (!iqentry_v[head1]))
4696
        )
4697
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4698
                ((!iqentry_v[head0])
4699
        &&   (!iqentry_v[head1])
4700
        &&   (!iqentry_v[head2]))
4701
        )
4702
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4703
                ((!iqentry_v[head0])
4704
        &&   (!iqentry_v[head1])
4705
        &&   (!iqentry_v[head2])
4706
        &&   (!iqentry_v[head3]))
4707
        )
4708
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4709
                ((!iqentry_v[head0])
4710
        &&   (!iqentry_v[head1])
4711
        &&   (!iqentry_v[head2])
4712
        &&   (!iqentry_v[head3])
4713
        &&   (!iqentry_v[head4]))
4714
        )
4715
    ) begin
4716
                iqentry_fcu_issue[head6] = `TRUE;
4717
    end
4718
 
4719
    else if (could_issue[head7] && iqentry_fc[head7]
4720
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4721
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4722
                ((!iqentry_v[head0])
4723
        &&   (!iqentry_v[head1]))
4724
        )
4725
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4726
                ((!iqentry_v[head0])
4727
        &&   (!iqentry_v[head1])
4728
        &&   (!iqentry_v[head2]))
4729
        )
4730
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4731
                ((!iqentry_v[head0])
4732
        &&   (!iqentry_v[head1])
4733
        &&   (!iqentry_v[head2])
4734
        &&   (!iqentry_v[head3]))
4735
        )
4736
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4737
                ((!iqentry_v[head0])
4738
        &&   (!iqentry_v[head1])
4739
        &&   (!iqentry_v[head2])
4740
        &&   (!iqentry_v[head3])
4741
        &&   (!iqentry_v[head4]))
4742
        )
4743
    && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4744
                ((!iqentry_v[head0])
4745
        &&   (!iqentry_v[head1])
4746
        &&   (!iqentry_v[head2])
4747
        &&   (!iqentry_v[head3])
4748
        &&   (!iqentry_v[head4])
4749
        &&   (!iqentry_v[head5]))
4750
        )
4751
    ) begin
4752
                iqentry_fcu_issue[head7] = `TRUE;
4753
        end
4754
`endif
4755
        end
4756
end
4757
 
4758
//
4759
// determine if the instructions ready to issue can, in fact, issue.
4760
// "ready" means that the instruction has valid operands but has not gone yet
4761
reg [1:0] issue_count, missue_count;
4762
always @*
4763
begin
4764
        issue_count = 0;
4765
         memissue[ head0 ] =    iqentry_memready[ head0 ];              // first in line ... go as soon as ready
4766
         if (memissue[head0])
4767
                issue_count = issue_count + 1;
4768
 
4769
         memissue[ head1 ] =    ~iqentry_stomp[head1] && iqentry_memready[ head1 ]              // addr and data are valid
4770 49 robfinch
                                        && issue_count < `NUM_MEM
4771 48 robfinch
                                        // ... and no preceding instruction is ready to go
4772
                                        //&& ~iqentry_memready[head0]
4773
                                        // ... and there is no address-overlap with any preceding instruction
4774 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4775
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head1][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4776 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4777
                                        && (iqentry_rl[head1] ? iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0] : 1'b1)
4778
                                        // ... if a preivous op has the aquire bit set
4779
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4780
                                        // ... and, if it is a SW, there is no chance of it being undone
4781
                                        && (iqentry_load[head1] ||
4782
                                           !(iqentry_fc[head0]||iqentry_canex[head0]));
4783
         if (memissue[head1])
4784
                issue_count = issue_count + 1;
4785
 
4786
         memissue[ head2 ] =    ~iqentry_stomp[head2] && iqentry_memready[ head2 ]              // addr and data are valid
4787
                                        // ... and no preceding instruction is ready to go
4788 49 robfinch
                                        && issue_count < `NUM_MEM
4789 48 robfinch
                                        //&& ~iqentry_memready[head0]
4790
                                        //&& ~iqentry_memready[head1] 
4791
                                        // ... and there is no address-overlap with any preceding instruction
4792 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4793
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head2][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4794
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4795
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head2][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4796 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4797
                                        && (iqentry_rl[head2] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4798
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4799
                                                                                         : 1'b1)
4800
                                        // ... if a preivous op has the aquire bit set
4801
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4802
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4803
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4804 49 robfinch
            && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4805
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4806 48 robfinch
                                        // ... and, if it is a SW, there is no chance of it being undone
4807
                                        && (iqentry_load[head2] ||
4808
                                              !(iqentry_fc[head0]||iqentry_canex[head0])
4809
                                           && !(iqentry_fc[head1]||iqentry_canex[head1]));
4810
         if (memissue[head2])
4811
                issue_count = issue_count + 1;
4812
 
4813
         memissue[ head3 ] =    ~iqentry_stomp[head3] && iqentry_memready[ head3 ]              // addr and data are valid
4814
                                        // ... and no preceding instruction is ready to go
4815 49 robfinch
                                        && issue_count < `NUM_MEM
4816 48 robfinch
                                        //&& ~iqentry_memready[head0]
4817
                                        //&& ~iqentry_memready[head1] 
4818
                                        //&& ~iqentry_memready[head2] 
4819
                                        // ... and there is no address-overlap with any preceding instruction
4820 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4821
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4822
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4823
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4824
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])  || iqentry_done[head2]
4825
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4826 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4827
                                        && (iqentry_rl[head3] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4828
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4829
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4830
                                                                                         : 1'b1)
4831
                                        // ... if a preivous op has the aquire bit set
4832
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4833
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4834
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4835
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4836 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4837
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4838 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4839
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4840
                                )
4841 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4842
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4843 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4844
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4845
                                )
4846
                    // ... and, if it is a SW, there is no chance of it being undone
4847
                                        && (iqentry_load[head3] ||
4848
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4849
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4850
                       && !(iqentry_fc[head2]||iqentry_canex[head2]));
4851
         if (memissue[head3])
4852
                issue_count = issue_count + 1;
4853
 
4854
         memissue[ head4 ] =    ~iqentry_stomp[head4] && iqentry_memready[ head4 ]              // addr and data are valid
4855
                                        // ... and no preceding instruction is ready to go
4856 49 robfinch
                                        && issue_count < `NUM_MEM
4857 48 robfinch
                                        //&& ~iqentry_memready[head0]
4858
                                        //&& ~iqentry_memready[head1] 
4859
                                        //&& ~iqentry_memready[head2] 
4860
                                        //&& ~iqentry_memready[head3] 
4861
                                        // ... and there is no address-overlap with any preceding instruction
4862 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4863
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4864
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4865
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4866
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])  || iqentry_done[head2]
4867
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4868
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])  || iqentry_done[head3]
4869
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
4870 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4871
                                        && (iqentry_rl[head4] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4872
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4873
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4874
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4875
                                                                                         : 1'b1)
4876
                                        // ... if a preivous op has the aquire bit set
4877
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4878
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4879
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4880
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4881
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4882 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4883
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4884 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4885
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4886
                                )
4887 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4888 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4889
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4890
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4891
                                )
4892
                                && (!(iqentry_v[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4893 49 robfinch
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4894 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4895
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4896
                                )
4897 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
4898 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4899
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4900
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4901
                                )
4902
                                        // ... and, if it is a SW, there is no chance of it being undone
4903
                                        && (iqentry_load[head4] ||
4904
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4905
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4906
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4907
                       && !(iqentry_fc[head3]||iqentry_canex[head3]));
4908
         if (memissue[head4])
4909
                issue_count = issue_count + 1;
4910
 
4911
         memissue[ head5 ] =    ~iqentry_stomp[head5] && iqentry_memready[ head5 ]              // addr and data are valid
4912
                                        // ... and no preceding instruction is ready to go
4913 49 robfinch
                                        && issue_count < `NUM_MEM
4914 48 robfinch
                                        //&& ~iqentry_memready[head0]
4915
                                        //&& ~iqentry_memready[head1] 
4916
                                        //&& ~iqentry_memready[head2] 
4917
                                        //&& ~iqentry_memready[head3] 
4918
                                        //&& ~iqentry_memready[head4] 
4919
                                        // ... and there is no address-overlap with any preceding instruction
4920 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4921
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4922
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
4923
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4924
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
4925
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4926
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
4927
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
4928
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
4929
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head4][AMSB:3] || iqentry_out[head4] || iqentry_done[head4])))
4930 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4931
                                        && (iqentry_rl[head5] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4932
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4933
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4934
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4935
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
4936
                                                                                         : 1'b1)
4937
                                        // ... if a preivous op has the aquire bit set
4938
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4939
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4940
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4941
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4942
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
4943
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4944 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4945
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4946 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4947
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4948
                                )
4949 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4950 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4951
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4952
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4953
                                )
4954 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
4955 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4956
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4957
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4958
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
4959
                                )
4960 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4961
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4962 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4963
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4964
                                )
4965 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
4966 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4967
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4968
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4969
                                )
4970 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
4971 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4972
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4973
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4974
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
4975
                                )
4976
                                        // ... and, if it is a SW, there is no chance of it being undone
4977
                                        && (iqentry_load[head5] ||
4978
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4979
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4980
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4981
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
4982
                       && !(iqentry_fc[head4]||iqentry_canex[head4]));
4983
         if (memissue[head5])
4984
                issue_count = issue_count + 1;
4985
 
4986
`ifdef FULL_ISSUE_LOGIC
4987
         memissue[ head6 ] =    ~iqentry_stomp[head6] && iqentry_memready[ head6 ]              // addr and data are valid
4988
                                        // ... and no preceding instruction is ready to go
4989 49 robfinch
                                        && issue_count < `NUM_MEM
4990 48 robfinch
                                        //&& ~iqentry_memready[head0]
4991
                                        //&& ~iqentry_memready[head1] 
4992
                                        //&& ~iqentry_memready[head2] 
4993
                                        //&& ~iqentry_memready[head3] 
4994
                                        //&& ~iqentry_memready[head4] 
4995
                                        //&& ~iqentry_memready[head5] 
4996
                                        // ... and there is no address-overlap with any preceding instruction
4997 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4998
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4999
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
5000
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
5001
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
5002
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
5003
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
5004
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
5005
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
5006
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head4][AMSB:3] || iqentry_out[head4] || iqentry_done[head4])))
5007
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5]) || iqentry_done[head5]
5008
                                                || (iqentry_a1_v[head5] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head5][AMSB:3] || iqentry_out[head5] || iqentry_done[head5])))
5009 48 robfinch
                                        && (iqentry_rl[head6] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
5010
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
5011
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
5012
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
5013
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
5014
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
5015
                                                                                         : 1'b1)
5016
                                        // ... if a preivous op has the aquire bit set
5017
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
5018
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
5019
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5020
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5021
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
5022
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
5023
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5024 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5025
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5026 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5027
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5028
                                )
5029 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5030 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5031
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5032
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5033
                                )
5034 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
5035 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5036
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5037
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5038
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
5039
                                )
5040 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
5041 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5042
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5043
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5044
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5045
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
5046
                                )
5047 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5048
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5049 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5050
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5051
                                )
5052 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5053 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5054
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5055
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5056
                                )
5057 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
5058 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5059
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5060
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5061
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
5062
                                )
5063 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
5064 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5065
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5066
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5067
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5068
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
5069
                                )
5070
                                        // ... and, if it is a SW, there is no chance of it being undone
5071
                                        && (iqentry_load[head6] ||
5072
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5073
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5074
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5075
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5076
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
5077
                       && !(iqentry_fc[head5]||iqentry_canex[head5]));
5078
         if (memissue[head6])
5079
                issue_count = issue_count + 1;
5080
 
5081
         memissue[ head7 ] =    ~iqentry_stomp[head7] && iqentry_memready[ head7 ]              // addr and data are valid
5082
                                        // ... and no preceding instruction is ready to go
5083 49 robfinch
                                        && issue_count < `NUM_MEM
5084 48 robfinch
                                        //&& ~iqentry_memready[head0]
5085
                                        //&& ~iqentry_memready[head1] 
5086
                                        //&& ~iqentry_memready[head2] 
5087
                                        //&& ~iqentry_memready[head3] 
5088
                                        //&& ~iqentry_memready[head4] 
5089
                                        //&& ~iqentry_memready[head5] 
5090
                                        //&& ~iqentry_memready[head6] 
5091
                                        // ... and there is no address-overlap with any preceding instruction
5092 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
5093
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
5094
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
5095
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
5096
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
5097
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
5098
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
5099
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
5100
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
5101
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head4][AMSB:3] || iqentry_out[head4] || iqentry_done[head4])))
5102
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5]) || iqentry_done[head5]
5103
                                                || (iqentry_a1_v[head5] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head5][AMSB:3] || iqentry_out[head5] || iqentry_done[head5])))
5104
                                        && (!iqentry_mem[head6] || (iqentry_agen[head6] & iqentry_out[head6]) || iqentry_done[head6]
5105
                                                || (iqentry_a1_v[head6] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head6][AMSB:3] || iqentry_out[head6] || iqentry_done[head6])))
5106 48 robfinch
                                        && (iqentry_rl[head7] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
5107
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
5108
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
5109
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
5110
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
5111
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
5112
                                                                                 && (iqentry_done[head6] || !iqentry_v[head6] || !iqentry_mem[head6])
5113
                                                                                         : 1'b1)
5114
                                        // ... if a preivous op has the aquire bit set
5115
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
5116
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
5117
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5118
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5119
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
5120
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
5121
                                        && !(iqentry_aq[head6] && iqentry_v[head6])
5122
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5123 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5124
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5125 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5126
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5127
                                )
5128 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5129 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5130
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5131
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5132
                                )
5133 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
5134 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5135
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5136
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5137
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
5138
                                )
5139 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
5140 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5141
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5142
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5143
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5144
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
5145
                                )
5146 49 robfinch
                    && (!(iqentry_iv[head6] && iqentry_memsb[head6]) ||
5147 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5148
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5149
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5150
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5151
                                &&   (iqentry_done[head4] || !iqentry_v[head4])
5152
                                &&   (iqentry_done[head5] || !iqentry_v[head5]))
5153
                                )
5154 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5155
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5156 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5157
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5158
                                )
5159 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5160 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5161
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5162
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5163
                                )
5164 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
5165 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5166
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5167
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5168
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
5169
                                )
5170 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
5171 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5172
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5173
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5174
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5175
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
5176
                                )
5177 49 robfinch
                    && (!(iqentry_iv[head6] && iqentry_memdb[head6]) ||
5178 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5179
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5180
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5181
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5182
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4])
5183
                                && (!iqentry_mem[head5] || iqentry_done[head5] || !iqentry_v[head5]))
5184
                                )
5185
                                        // ... and, if it is a SW, there is no chance of it being undone
5186
                                        && (iqentry_load[head7] ||
5187
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5188
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5189
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5190
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5191
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
5192
                       && !(iqentry_fc[head5]||iqentry_canex[head5])
5193
                       && !(iqentry_fc[head6]||iqentry_canex[head6]));
5194
`endif
5195
end
5196
 
5197 49 robfinch
reg [2:0] wbptr;
5198
always @*
5199
begin
5200
        // Crashes sim
5201
//      wbptr <= `WB_DEPTH-1;
5202
//      if (wb_v==8'h0)
5203
//              wbptr <= 3'd0;
5204
//      else
5205
//      begin
5206
//              for (n = `WB_DEPTH-2; n >= 0; n = n - 1)
5207
//                      if (wb_v[n] && wbptr==`WB_DEPTH-1)
5208
//                              wbptr <= n + 1;
5209
//      end
5210
        if (wb_v[6])
5211
                wbptr <= 3'd7;
5212
        else if (wb_v[5])
5213
                wbptr <= 3'd6;
5214
        else if (wb_v[4])
5215
                wbptr <= 3'd5;
5216
        else if (wb_v[3])
5217
                wbptr <= 3'd4;
5218
        else if (wb_v[2])
5219
                wbptr <= 3'd3;
5220
        else if (wb_v[1])
5221
                wbptr <= 3'd2;
5222
        else if (wb_v[0])
5223
                wbptr <= 3'd1;
5224
        else
5225
                wbptr <= 3'd0;
5226
end
5227
 
5228 48 robfinch
// Stomp logic for branch miss.
5229
 
5230
FT64_stomp #(QENTRIES) ustmp1
5231
(
5232
        .branchmiss(branchmiss),
5233
        .branchmiss_thrd(branchmiss_thrd),
5234
        .missid(missid),
5235
        .head0(head0),
5236
        .thrd(iqentry_thrd),
5237
        .iqentry_v(iqentry_v),
5238
        .stomp(iqentry_stomp)
5239
);
5240
 
5241
always @*
5242
begin
5243 51 robfinch
        if (iqentry_stomp[0] && iqentry_ret[0])
5244 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5245 51 robfinch
        if (iqentry_stomp[1] && iqentry_ret[1])
5246 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5247 51 robfinch
        if (iqentry_stomp[2] && iqentry_ret[2])
5248 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5249 51 robfinch
        if (iqentry_stomp[3] && iqentry_ret[3])
5250 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5251 51 robfinch
        if (iqentry_stomp[4] && iqentry_ret[4])
5252 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5253 51 robfinch
        if (iqentry_stomp[5] && iqentry_ret[5])
5254 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5255 51 robfinch
        if (iqentry_stomp[6] && iqentry_ret[6])
5256 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5257 51 robfinch
        if (iqentry_stomp[7] && iqentry_ret[7])
5258 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5259 52 robfinch
        if (iqentry_stomp[8] && iqentry_ret[8])
5260
                stompedOnRets = stompedOnRets + 4'd1;
5261
        if (iqentry_stomp[9] && iqentry_ret[9])
5262
                stompedOnRets = stompedOnRets + 4'd1;
5263 48 robfinch
end
5264
 
5265 49 robfinch
reg id1_vi, id2_vi, id3_vi;
5266
wire [4:0] id1_ido, id2_ido, id3_ido;
5267
wire id1_vo, id2_vo, id3_vo;
5268
wire id1_clk, id2_clk, id3_clk;
5269 48 robfinch
 
5270 49 robfinch
// Always at least one decoder
5271 50 robfinch
assign id1_clk = clk_i;
5272
//BUFGCE uclkb2
5273
//(
5274
//      .I(clk_i),
5275
//      .CE(id1_available),
5276
//      .O(id1_clk)
5277
//);
5278 48 robfinch
 
5279
FT64_idecoder uid1
5280
(
5281
        .clk(id1_clk),
5282
        .idv_i(id1_vi),
5283
        .id_i(id1_id),
5284
        .instr(id1_instr),
5285
        .ven(id1_ven),
5286
        .vl(id1_vl),
5287
        .thrd(id1_thrd),
5288
        .predict_taken(id1_pt),
5289
        .Rt(id1_Rt),
5290
        .bus(id1_bus),
5291
        .id_o(id1_ido),
5292
        .idv_o(id1_vo)
5293
);
5294
 
5295 49 robfinch
generate begin : gIDUInst
5296
if (`NUM_IDU > 1) begin
5297 50 robfinch
//BUFGCE uclkb3
5298
//(
5299
//      .I(clk_i),
5300
//      .CE(id2_available),
5301
//      .O(id2_clk)
5302
//);
5303
assign id2_clk = clk_i;
5304 48 robfinch
 
5305
FT64_idecoder uid2
5306
(
5307
        .clk(id2_clk),
5308
        .idv_i(id2_vi),
5309
        .id_i(id2_id),
5310
        .instr(id2_instr),
5311
        .ven(id2_ven),
5312
        .vl(id2_vl),
5313
        .thrd(id2_thrd),
5314
        .predict_taken(id2_pt),
5315
        .Rt(id2_Rt),
5316
        .bus(id2_bus),
5317
        .id_o(id2_ido),
5318
        .idv_o(id2_vo)
5319
);
5320 49 robfinch
end
5321
if (`NUM_IDU > 2) begin
5322 50 robfinch
//BUFGCE uclkb4
5323
//(
5324
//      .I(clk_i),
5325
//      .CE(id3_available),
5326
//      .O(id3_clk)
5327
//);
5328
assign id3_clk = clk_i;
5329 48 robfinch
 
5330 49 robfinch
FT64_idecoder uid2
5331
(
5332
        .clk(id3_clk),
5333
        .idv_i(id3_vi),
5334
        .id_i(id3_id),
5335
        .instr(id3_instr),
5336
        .ven(id3_ven),
5337
        .vl(id3_vl),
5338
        .thrd(id3_thrd),
5339
        .predict_taken(id3_pt),
5340
        .Rt(id3_Rt),
5341
        .bus(id3_bus),
5342
        .id_o(id3_ido),
5343
        .idv_o(id3_vo)
5344
);
5345
end
5346
end
5347
endgenerate
5348
 
5349 48 robfinch
//
5350
// EXECUTE
5351
//
5352
reg [63:0] csr_r;
5353
always @*
5354
    read_csr(alu0_instr[29:18],csr_r,alu0_thrd);
5355
FT64_alu #(.BIG(1'b1),.SUP_VECTOR(SUP_VECTOR)) ualu0 (
5356
  .rst(rst),
5357
  .clk(clk),
5358
  .ld(alu0_ld),
5359
  .abort(1'b0),
5360
  .instr(alu0_instr),
5361
  .a(alu0_argA),
5362
  .b(alu0_argB),
5363
  .c(alu0_argC),
5364
  .pc(alu0_pc),
5365
//    .imm(alu0_argI),
5366
  .tgt(alu0_tgt),
5367
  .ven(alu0_ven),
5368
  .vm(vm[alu0_instr[25:23]]),
5369
  .sbl(sbl),
5370
  .sbu(sbu),
5371
  .csr(csr_r),
5372
  .o(alu0_bus),
5373
  .ob(alu0b_bus),
5374
  .done(alu0_done),
5375
  .idle(alu0_idle),
5376
  .excen(aec[4:0]),
5377
  .exc(alu0_exc),
5378
  .thrd(alu0_thrd),
5379
  .mem(alu0_mem),
5380
  .shift48(alu0_shft48)
5381
);
5382 49 robfinch
generate begin : gAluInst
5383
if (`NUM_ALU > 1) begin
5384 48 robfinch
FT64_alu #(.BIG(1'b0),.SUP_VECTOR(SUP_VECTOR)) ualu1 (
5385
  .rst(rst),
5386
  .clk(clk),
5387
  .ld(alu1_ld),
5388
  .abort(1'b0),
5389
  .instr(alu1_instr),
5390
  .a(alu1_argA),
5391
  .b(alu1_argB),
5392
  .c(alu1_argC),
5393
  .pc(alu1_pc),
5394
  //.imm(alu1_argI),
5395
  .tgt(alu1_tgt),
5396
  .ven(alu1_ven),
5397
  .vm(vm[alu1_instr[25:23]]),
5398
  .sbl(sbl),
5399
  .sbu(sbu),
5400
  .csr(64'd0),
5401
  .o(alu1_bus),
5402
  .ob(alu1b_bus),
5403
  .done(alu1_done),
5404
  .idle(alu1_idle),
5405
  .excen(aec[4:0]),
5406
  .exc(alu1_exc),
5407
  .thrd(1'b0),
5408
  .mem(alu1_mem),
5409
  .shift48(alu1_shft48)
5410
);
5411 49 robfinch
end
5412
end
5413
endgenerate
5414
 
5415
generate begin : gFPUInst
5416
if (`NUM_FPU > 0) begin
5417
wire fpu1_clk;
5418 50 robfinch
//BUFGCE ufpc1
5419
//(
5420
//      .I(clk_i),
5421
//      .CE(fpu1_available),
5422
//      .O(fpu1_clk)
5423
//);
5424
assign fpu1_clk = clk_i;
5425
 
5426 48 robfinch
fpUnit ufp1
5427
(
5428
  .rst(rst),
5429 49 robfinch
  .clk(fpu1_clk),
5430 48 robfinch
  .clk4x(clk4x),
5431
  .ce(1'b1),
5432 49 robfinch
  .ir(fpu1_instr),
5433
  .ld(fpu1_ld),
5434
  .a(fpu1_argA),
5435
  .b(fpu1_argB),
5436
  .imm(fpu1_argI),
5437
  .o(fpu1_bus),
5438 48 robfinch
  .csr_i(),
5439 52 robfinch
  .status(fpu1_status),
5440 48 robfinch
  .exception(),
5441 49 robfinch
  .done(fpu1_done)
5442 48 robfinch
);
5443 49 robfinch
end
5444
if (`NUM_FPU > 1) begin
5445
wire fpu2_clk;
5446 50 robfinch
//BUFGCE ufpc2
5447
//(
5448
//      .I(clk_i),
5449
//      .CE(fpu2_available),
5450
//      .O(fpu2_clk)
5451
//);
5452
assign fpu2_clk = clk_i;
5453 49 robfinch
fpUnit ufp1
5454
(
5455
  .rst(rst),
5456
  .clk(fpu2_clk),
5457
  .clk4x(clk4x),
5458
  .ce(1'b1),
5459
  .ir(fpu2_instr),
5460
  .ld(fpu2_ld),
5461
  .a(fpu2_argA),
5462
  .b(fpu2_argB),
5463
  .imm(fpu2_argI),
5464
  .o(fpu2_bus),
5465
  .csr_i(),
5466 52 robfinch
  .status(fpu2_status),
5467 49 robfinch
  .exception(),
5468
  .done(fpu2_done)
5469
);
5470
end
5471
end
5472
endgenerate
5473 48 robfinch
 
5474 52 robfinch
assign fpu1_exc = (fpu1_available) ?
5475
                                                                        ((|fpu1_status[15:0]) ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
5476
assign fpu2_exc = (fpu2_available) ?
5477
                                                                        ((|fpu2_status[15:0]) ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
5478 49 robfinch
 
5479 48 robfinch
assign  alu0_v = alu0_dataready,
5480
        alu1_v = alu1_dataready;
5481
assign  alu0_id = alu0_sourceid,
5482
            alu1_id = alu1_sourceid;
5483 49 robfinch
assign  fpu1_v = fpu1_dataready;
5484
assign  fpu1_id = fpu1_sourceid;
5485
assign  fpu2_v = fpu2_dataready;
5486
assign  fpu2_id = fpu2_sourceid;
5487 48 robfinch
 
5488
`ifdef SUPPORT_SMT
5489
wire [1:0] olm = ol[fcu_thrd];
5490
`else
5491
wire [1:0] olm = ol;
5492
`endif
5493
 
5494
assign  fcu_v = fcu_dataready;
5495
assign  fcu_id = fcu_sourceid;
5496
 
5497
wire [4:0] fcmpo;
5498
wire fnanx;
5499
fp_cmp_unit ufcmp1 (fcu_argA, fcu_argB, fcmpo, fnanx);
5500
 
5501
wire fcu_takb;
5502
 
5503
always @*
5504
begin
5505
    fcu_exc <= `FLT_NONE;
5506
    casez(fcu_instr[`INSTRUCTION_OP])
5507
    `CHK:   begin
5508
                if (fcu_instr[21])
5509
                    fcu_exc <= fcu_argA >= fcu_argB && fcu_argA < fcu_argC ? `FLT_NONE : `FLT_CHK;
5510
            end
5511
    `REX:
5512
        case(olm)
5513
        `OL_USER:   fcu_exc <= `FLT_PRIV;
5514
        default:    ;
5515
        endcase
5516
        endcase
5517
end
5518
 
5519
FT64_EvalBranch ube1
5520
(
5521
        .instr(fcu_instr),
5522
        .a(fcu_argA),
5523
        .b(fcu_argB),
5524
        .c(fcu_argC),
5525
        .takb(fcu_takb)
5526
);
5527
 
5528
FT64_FCU_Calc ufcuc1
5529
(
5530
        .ol(olm),
5531
        .instr(fcu_instr),
5532
        .tvec(tvec[fcu_instr[14:13]]),
5533
        .a(fcu_argA),
5534
        .i(fcu_argI),
5535
        .pc(fcu_pc),
5536
        .im(im),
5537
        .waitctr(waitctr),
5538
        .bus(fcu_bus)
5539
);
5540
 
5541
always @*
5542
begin
5543
case(fcu_instr[`INSTRUCTION_OP])
5544
`R2:    fcu_misspc = fcu_argB;  // RTI (we don't bother fully decoding this as it's the only R2)
5545
`RET:   fcu_misspc = fcu_argB;
5546
`REX:   fcu_misspc = fcu_bus;
5547
`BRK:   fcu_misspc = {tvec[0][31:8], 1'b0, olm, 5'h0};
5548
`JAL:   fcu_misspc = fcu_argA + fcu_argI;
5549
//`CHK: fcu_misspc = fcu_nextpc + fcu_argI;     // Handled as an instruction exception
5550
// Default: branch
5551
default:        fcu_misspc = fcu_takb ? fcu_nextpc + fcu_brdisp : fcu_nextpc;
5552
endcase
5553
fcu_misspc[0] = 1'b0;
5554
end
5555
 
5556
// To avoid false branch mispredicts the branch isn't evaluated until the
5557
// following instruction queues. The address of the next instruction is
5558
// looked at to see if the BTB predicted correctly.
5559
 
5560 51 robfinch
wire fcu_brk_miss = (fcu_brk || fcu_rti) && fcu_v;
5561
wire fcu_ret_miss = fcu_ret && fcu_v && (fcu_argB != iqentry_pc[nid]);
5562
wire fcu_jal_miss = fcu_jal && fcu_v && fcu_argA + fcu_argI != iqentry_pc[nid];
5563 48 robfinch
wire fcu_followed = iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]];
5564
always @*
5565
if (fcu_dataready) begin
5566
//      if (fcu_timeout[7])
5567
//              fcu_branchmiss = TRUE;
5568
        // Break and RTI switch register sets, and so are always treated as a branch miss in order to
5569
        // flush the pipeline. Hardware interrupts also stream break instructions so they need to 
5570
        // flushed from the queue so the interrupt is recognized only once.
5571
        // BRK and RTI are handled as excmiss types which are processed during the commit stage.
5572
//      else
5573
        if (fcu_brk_miss)
5574
                fcu_branchmiss = TRUE & ~fcu_clearbm;
5575
    // the following instruction is queued
5576
        else
5577
        if (fcu_followed) begin
5578
`ifdef SUPPORT_SMT
5579
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol[fcu_thrd]) && fcu_v)
5580
`else
5581
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol) && fcu_v)
5582
`endif
5583
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5584
                else if (fcu_ret_miss)
5585
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5586 52 robfinch
                else if (fcu_branch && fcu_v && (((fcu_takb && (fcu_misspc != iqentry_pc[nid])) ||
5587
                                            (~fcu_takb && (fcu_pc + fcu_insln != iqentry_pc[nid])))))// || iqentry_v[nid]))
5588 48 robfinch
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5589
                else if (fcu_jal_miss)
5590
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5591
                else if (fcu_instr[`INSTRUCTION_OP] == `CHK && ~fcu_takb && fcu_v)
5592
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5593
                else
5594
                    fcu_branchmiss = FALSE;
5595
        end
5596
        else begin
5597
                // Stuck at the head and can't finish because there's still an uncommitted instruction in the queue.
5598
                // -> cause a branch miss to clear the queue.
5599
                if (iqentry_v[nid] && !IsCall(fcu_instr) && !IsJmp(fcu_instr) && fcu_v)
5600
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5601
                else
5602
                /*
5603
                if (fcu_id==head0 && iqentry_v[idp1(head0)]) begin
5604
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
5605
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
5606
                        fcu_branchmiss = FALSE;
5607
                    else
5608
                                fcu_branchmiss = TRUE;
5609
                end
5610
                else if (fcu_id==head1 && iqentry_v[idp2(head1)]) begin
5611
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
5612
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
5613
                        fcu_branchmiss = FALSE;
5614
                    else
5615
                                fcu_branchmiss = TRUE;
5616
                end
5617
                else*/
5618
                        fcu_branchmiss = FALSE;
5619
        end
5620
end
5621
else
5622
        fcu_branchmiss = FALSE;
5623
 
5624
// Flow control ops don't issue until the next instruction queues.
5625
// The fcu_timeout tracks how long the flow control op has been in the "out" state.
5626
// It should never be that way more than a couple of cycles. Sometimes the fcu_wr pulse got missed
5627
// because the following instruction got stomped on during a branchmiss, hence iqentry_v isn't true.
5628
wire fcu_wr = (fcu_v && iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]]);//      // && iqentry_v[nid]
5629
//                                      && fcu_instr==iqentry_instr[fcu_id[`QBITS]]);// || fcu_timeout==8'h05;
5630
 
5631
FT64_RMW_alu urmwalu0 (rmw_instr, rmw_argA, rmw_argB, rmw_argC, rmw_res);
5632
 
5633
//assign fcu_done = IsWait(fcu_instr) ? ((waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]]) :
5634
//                                      fcu_v && iqentry_v[idp1(fcu_id)] && iqentry_sn[idp1(fcu_id)]==iqentry_sn[fcu_id[`QBITS]]+5'd1;
5635
 
5636
// An exception in a committing instruction takes precedence
5637
/*
5638
Too slow. Needs to be registered
5639
assign  branchmiss = excmiss|fcu_branchmiss,
5640
    misspc = excmiss ? excmisspc : fcu_misspc,
5641
    missid = excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
5642
assign branchmiss_thrd =  excmiss ? excthrd : fcu_thrd;
5643
*/
5644
 
5645
//
5646
// additional DRAM-enqueue logic
5647
 
5648
assign dram_avail = (dram0 == `DRAMSLOT_AVAIL || dram1 == `DRAMSLOT_AVAIL || dram2 == `DRAMSLOT_AVAIL);
5649
 
5650
assign  iqentry_memopsvalid[0] = (iqentry_mem[0] & iqentry_a2_v[0] & iqentry_agen[0]),
5651
    iqentry_memopsvalid[1] = (iqentry_mem[1] & iqentry_a2_v[1] & iqentry_agen[1]),
5652
    iqentry_memopsvalid[2] = (iqentry_mem[2] & iqentry_a2_v[2] & iqentry_agen[2]),
5653
    iqentry_memopsvalid[3] = (iqentry_mem[3] & iqentry_a2_v[3] & iqentry_agen[3]),
5654
    iqentry_memopsvalid[4] = (iqentry_mem[4] & iqentry_a2_v[4] & iqentry_agen[4]),
5655
    iqentry_memopsvalid[5] = (iqentry_mem[5] & iqentry_a2_v[5] & iqentry_agen[5]),
5656
    iqentry_memopsvalid[6] = (iqentry_mem[6] & iqentry_a2_v[6] & iqentry_agen[6]),
5657 52 robfinch
    iqentry_memopsvalid[7] = (iqentry_mem[7] & iqentry_a2_v[7] & iqentry_agen[7]),
5658
    iqentry_memopsvalid[8] = (iqentry_mem[8] & iqentry_a2_v[8] & iqentry_agen[8]),
5659
    iqentry_memopsvalid[9] = (iqentry_mem[9] & iqentry_a2_v[9] & iqentry_agen[9])
5660
    ;
5661 48 robfinch
 
5662
assign  iqentry_memready[0] = (iqentry_v[0] & iqentry_memopsvalid[0] & ~iqentry_memissue[0] & ~iqentry_done[0] & ~iqentry_out[0] & ~iqentry_stomp[0]),
5663
    iqentry_memready[1] = (iqentry_v[1] & iqentry_memopsvalid[1] & ~iqentry_memissue[1] & ~iqentry_done[1] & ~iqentry_out[1] & ~iqentry_stomp[1]),
5664
    iqentry_memready[2] = (iqentry_v[2] & iqentry_memopsvalid[2] & ~iqentry_memissue[2] & ~iqentry_done[2] & ~iqentry_out[2] & ~iqentry_stomp[2]),
5665
    iqentry_memready[3] = (iqentry_v[3] & iqentry_memopsvalid[3] & ~iqentry_memissue[3] & ~iqentry_done[3] & ~iqentry_out[3] & ~iqentry_stomp[3]),
5666
    iqentry_memready[4] = (iqentry_v[4] & iqentry_memopsvalid[4] & ~iqentry_memissue[4] & ~iqentry_done[4] & ~iqentry_out[4] & ~iqentry_stomp[4]),
5667
    iqentry_memready[5] = (iqentry_v[5] & iqentry_memopsvalid[5] & ~iqentry_memissue[5] & ~iqentry_done[5] & ~iqentry_out[5] & ~iqentry_stomp[5]),
5668
    iqentry_memready[6] = (iqentry_v[6] & iqentry_memopsvalid[6] & ~iqentry_memissue[6] & ~iqentry_done[6] & ~iqentry_out[6] & ~iqentry_stomp[6]),
5669 52 robfinch
    iqentry_memready[7] = (iqentry_v[7] & iqentry_memopsvalid[7] & ~iqentry_memissue[7] & ~iqentry_done[7] & ~iqentry_out[7] & ~iqentry_stomp[7]),
5670
    iqentry_memready[8] = (iqentry_v[8] & iqentry_memopsvalid[8] & ~iqentry_memissue[8] & ~iqentry_done[8] & ~iqentry_out[8] & ~iqentry_stomp[8]),
5671
    iqentry_memready[9] = (iqentry_v[9] & iqentry_memopsvalid[9] & ~iqentry_memissue[9] & ~iqentry_done[9] & ~iqentry_out[9] & ~iqentry_stomp[9])
5672
    ;
5673 48 robfinch
 
5674 50 robfinch
assign outstanding_stores = (dram0 && dram0_store) ||
5675
                            (dram1 && dram1_store) ||
5676
                            (dram2 && dram2_store);
5677 48 robfinch
 
5678
//
5679
// additional COMMIT logic
5680
//
5681
always @*
5682
begin
5683
    commit0_v <= ({iqentry_v[head0], iqentry_cmt[head0]} == 2'b11 && ~|panic);
5684
    commit0_id <= {iqentry_mem[head0], head0};  // if a memory op, it has a DRAM-bus id
5685
    commit0_tgt <= iqentry_tgt[head0];
5686
    commit0_we  <= iqentry_we[head0];
5687
    commit0_bus <= iqentry_res[head0];
5688 49 robfinch
    if (`NUM_CMT > 1) begin
5689
            commit1_v <= ({iqentry_v[head0], iqentry_cmt[head0]} != 2'b10
5690
                       && {iqentry_v[head1], iqentry_cmt[head1]} == 2'b11
5691
                       && ~|panic);
5692
            commit1_id <= {iqentry_mem[head1], head1};
5693
            commit1_tgt <= iqentry_tgt[head1];
5694
            commit1_we  <= iqentry_we[head1];
5695
            commit1_bus <= iqentry_res[head1];
5696
        end
5697
        else begin
5698
                commit1_tgt <= 12'h000;
5699
                commit1_we <= 8'h00;
5700
        end
5701 48 robfinch
end
5702
 
5703 51 robfinch
assign int_commit = (commit0_v && iqentry_irq[head0]) ||
5704
                    (commit0_v && commit1_v && iqentry_irq[head1] && `NUM_CMT > 1);
5705 48 robfinch
 
5706
// Detect if a given register will become valid during the current cycle.
5707
// We want a signal that is active during the current clock cycle for the read
5708
// through register file, which trims a cycle off register access for every
5709
// instruction. But two different kinds of assignment statements can't be
5710
// placed under the same always block, it's a bad practice and may not work.
5711
// So a signal is created here with it's own always block.
5712
reg [AREGS-1:0] regIsValid;
5713
always @*
5714
begin
5715
        for (n = 1; n < AREGS; n = n + 1)
5716
        begin
5717
                regIsValid[n] = rf_v[n];
5718
                if (branchmiss)
5719
               if (~livetarget[n]) begin
5720
                        if (branchmiss_thrd) begin
5721
                                if (n >= 128)
5722
                                        regIsValid[n] = `VAL;
5723
                        end
5724
                        else begin
5725
                                if (n < 128)
5726
                                        regIsValid[n] = `VAL;
5727
                        end
5728
               end
5729
                if (commit0_v && n=={commit0_tgt[7:0]})
5730
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit0_tgt[7:0]} ] == commit0_id
5731
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit0_id[`QBITS] ]));
5732 49 robfinch
                if (commit1_v && n=={commit1_tgt[7:0]} && `NUM_CMT > 1)
5733 48 robfinch
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit1_tgt[7:0]} ] == commit1_id
5734
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit1_id[`QBITS] ]));
5735
        end
5736
        regIsValid[0] = `VAL;
5737
end
5738
 
5739
// Wait until the cycle after Ra becomes valid to give time to read
5740
// the vector element from the register file.
5741
reg rf_vra0, rf_vra1;
5742
/*always @(posedge clk)
5743
    rf_vra0 <= regIsValid[Ra0s];
5744
always @(posedge clk)
5745
    rf_vra1 <= regIsValid[Ra1s];
5746
*/
5747
// Check how many instructions can be queued. This might be fewer than the
5748
// number ready to queue from the fetch stage if queue slots aren't
5749
// available or if there are no more physical registers left for remapping.
5750
// The fetch stage needs to know how many instructions will queue so this
5751
// logic is placed here.
5752
// NOPs are filtered out and do not enter the instruction queue. The core
5753
// will stream NOPs on a cache miss and they would mess up the queue order
5754
// if there are immediate prefixes in the queue.
5755
// For the VEX instruction, the instruction can't queue until register Ra
5756
// is valid, because register Ra is used to specify the vector element to
5757
// read.
5758
wire q2open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV;
5759
wire q3open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV && iqentry_v[idp1(tail1)]==`INV;
5760
always @*
5761
begin
5762
        canq1 <= FALSE;
5763
        canq2 <= FALSE;
5764
        queued1 <= FALSE;
5765
        queued2 <= FALSE;
5766
        queuedNop <= FALSE;
5767
        vqueued2 <= FALSE;
5768
        if (!branchmiss) begin
5769
      // Two available
5770
      if (fetchbuf1_v & fetchbuf0_v) begin
5771
          // Is there a pair of NOPs ? (cache miss)
5772
          if ((fetchbuf0_instr[`INSTRUCTION_OP]==`NOP) && (fetchbuf1_instr[`INSTRUCTION_OP]==`NOP))
5773
              queuedNop <= TRUE;
5774
          else begin
5775
              // If it's a predicted branch queue only the first instruction, the second
5776
              // instruction will be stomped on.
5777
              if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
5778
                  if (iqentry_v[tail0]==`INV) begin
5779
                      canq1 <= TRUE;
5780
                      queued1 <= TRUE;
5781
                  end
5782
              end
5783
              // This is where a single NOP is allowed through to simplify the code. A
5784
              // single NOP can't be a cache miss. Otherwise it would be necessary to queue
5785
              // fetchbuf1 on tail0 it would add a nightmare to the enqueue code.
5786
              // Not a branch and there are two instructions fetched, see whether or not
5787
              // both instructions can be queued.
5788
              else begin
5789
                  if (iqentry_v[tail0]==`INV) begin
5790
                      canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5791
                      queued1 <= (
5792
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5793
                      if (iqentry_v[tail1]==`INV) begin
5794
                          canq2 <= ((!IsVex(fetchbuf1_instr) || rf_vra1)) || !SUP_VECTOR;
5795
                          queued2 <= (
5796
                                (!IsVector(fetchbuf1_instr) && (!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5797
                          vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5798
                      end
5799
                  end
5800
                  // If an irq is active during a vector instruction fetch, claim the vector instruction
5801
                  // is finished queueing even though it may not be. It'll pick up where it left off after
5802
                  // the exception is processed.
5803 52 robfinch
                  if (freezePC) begin
5804 48 robfinch
                        if (IsVector(fetchbuf0_instr) && IsVector(fetchbuf1_instr) && vechain) begin
5805
                                queued1 <= TRUE;
5806
                                queued2 <= TRUE;
5807
                        end
5808
                        else if (IsVector(fetchbuf0_instr)) begin
5809
                                queued1 <= TRUE;
5810
                                if (vqe0 < vl-2)
5811
                                        queued2 <= TRUE;
5812
                                else
5813
                                        queued2 <= iqentry_v[tail1]==`INV;
5814
                        end
5815
                  end
5816
              end
5817
          end
5818
      end
5819
      // One available
5820
      else if (fetchbuf0_v) begin
5821
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
5822
              if (iqentry_v[tail0]==`INV) begin
5823
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5824
                  queued1 <=
5825
                        (((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5826
              end
5827
              if (iqentry_v[tail1]==`INV) begin
5828
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
5829
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5830
                end
5831 52 robfinch
                if (freezePC) begin
5832 48 robfinch
                if (IsVector(fetchbuf0_instr)) begin
5833
                        queued1 <= TRUE;
5834
                        if (vqe0 < vl-2)
5835
                                queued2 <= iqentry_v[tail1]==`INV;
5836
                end
5837
                end
5838
          end
5839
          else
5840
              queuedNop <= TRUE;
5841
      end
5842
      else if (fetchbuf1_v) begin
5843
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
5844
              if (iqentry_v[tail0]==`INV) begin
5845
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
5846
                  queued1 <= (
5847
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
5848
              end
5849
              if (iqentry_v[tail1]==`INV) begin
5850
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
5851
                  vqueued2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2;
5852
                end
5853 52 robfinch
                if (freezePC) begin
5854 48 robfinch
                if (IsVector(fetchbuf1_instr)) begin
5855
                        queued1 <= TRUE;
5856
                        if (vqe1 < vl-2)
5857
                                queued2 <= iqentry_v[tail1]==`INV;
5858
                end
5859
                end
5860
          end
5861
          else
5862
              queuedNop <= TRUE;
5863
      end
5864
      //else no instructions available to queue
5865
    end
5866
    else begin
5867
      // One available
5868
      if (fetchbuf0_v && fetchbuf0_thrd != branchmiss_thrd) begin
5869
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
5870
              if (iqentry_v[tail0]==`INV) begin
5871
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5872
                  queued1 <= (
5873
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5874
              end
5875
              if (iqentry_v[tail1]==`INV) begin
5876
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
5877
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5878
                end
5879
          end
5880
          else
5881
              queuedNop <= TRUE;
5882
      end
5883
      else if (fetchbuf1_v && fetchbuf1_thrd != branchmiss_thrd) begin
5884
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
5885
              if (iqentry_v[tail0]==`INV) begin
5886
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
5887
                  queued1 <= (
5888
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
5889
              end
5890
              if (iqentry_v[tail1]==`INV) begin
5891
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
5892
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5893
                end
5894
          end
5895
          else
5896
              queuedNop <= TRUE;
5897
      end
5898
        else
5899
                queuedNop <= TRUE;
5900
    end
5901
end
5902
 
5903
//
5904
// Branchmiss seems to be sticky sometimes during simulation. For instance branch miss
5905
// and cache miss at same time. The branchmiss should clear before the core continues
5906
// so the positive edge is detected to avoid incrementing the sequnce number too many
5907
// times.
5908
wire pebm;
5909
edge_det uedbm (.rst(rst), .clk(clk), .ce(1'b1), .i(branchmiss), .pe(pebm), .ne(), .ee() );
5910
 
5911
reg [5:0] ld_time;
5912
reg [63:0] wc_time_dat;
5913
reg [63:0] wc_times;
5914
always @(posedge tm_clk_i)
5915
begin
5916
        if (|ld_time)
5917
                wc_time <= wc_time_dat;
5918
        else begin
5919
                wc_time[31:0] <= wc_time[31:0] + 32'd1;
5920
                if (wc_time[31:0] >= TM_CLKFREQ-1) begin
5921
                        wc_time[31:0] <= 32'd0;
5922
                        wc_time[63:32] <= wc_time[63:32] + 32'd1;
5923
                end
5924
        end
5925
end
5926
 
5927
 
5928
// Monster clock domain.
5929
// Like to move some of this to clocking under different always blocks in order
5930
// to help out the toolset's synthesis, but it ain't gonna be easy.
5931
// Simulation doesn't like it if things are under separate always blocks.
5932
// Synthesis doesn't like it if things are under the same always block.
5933
 
5934 49 robfinch
//always @(posedge clk)
5935
//begin
5936
//      branchmiss <= excmiss|fcu_branchmiss;
5937
//    misspc <= excmiss ? excmisspc : fcu_misspc;
5938
//    missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
5939
//      branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
5940
//end
5941 48 robfinch
 
5942
always @(posedge clk)
5943
if (rst) begin
5944
`ifdef SUPPORT_SMT
5945
     mstatus[0] <= 64'h0007;     // select register set #0 for thread 0
5946
     mstatus[1] <= 64'h8007;    // select register set #2 for thread 1
5947
`else
5948
     mstatus <= 64'h0007;       // select register set #0 for thread 0
5949
`endif
5950
    for (n = 0; n < QENTRIES; n = n + 1) begin
5951 51 robfinch
       iqentry_v[n] <= `INV;
5952
       iqentry_iv[n] <= `INV;
5953
       iqentry_is[n] <= 3'b00;
5954
       iqentry_done[n] <= FALSE;
5955
       iqentry_cmt[n] <= FALSE;
5956
       iqentry_out[n] <= FALSE;
5957
       iqentry_agen[n] <= FALSE;
5958
       iqentry_sn[n] <= 32'd0;
5959
       iqentry_pt[n] <= FALSE;
5960
       iqentry_bt[n] <= FALSE;
5961
       iqentry_br[n] <= FALSE;
5962
       iqentry_aq[n] <= FALSE;
5963
       iqentry_rl[n] <= FALSE;
5964
       iqentry_alu0[n] <= FALSE;
5965
       iqentry_alu[n] <= FALSE;
5966
       iqentry_alu0_issue[n] <= FALSE;
5967
       iqentry_alu1_issue[n] <= FALSE;
5968
       iqentry_fpu[n] <= FALSE;
5969
       iqentry_fpu1_issue[n] <= FALSE;
5970
       iqentry_fpu2_issue[n] <= FALSE;
5971
       iqentry_fsync[n] <= FALSE;
5972
       iqentry_fc[n] <= FALSE;
5973
       iqentry_fcu_issue[n] <= FALSE;
5974 52 robfinch
       iqentry_takb[n] <= FALSE;
5975 51 robfinch
       iqentry_jmp[n] <= FALSE;
5976
       iqentry_jal[n] <= FALSE;
5977
       iqentry_ret[n] <= FALSE;
5978
       iqentry_brk[n] <= FALSE;
5979
       iqentry_irq[n] <= FALSE;
5980
       iqentry_rti[n] <= FALSE;
5981
       iqentry_ldcmp[n] <= FALSE;
5982
       iqentry_load[n] <= FALSE;
5983
       iqentry_rtop[n] <= FALSE;
5984
       iqentry_sei[n] <= FALSE;
5985
       iqentry_shft48[n] <= FALSE;
5986
       iqentry_sync[n] <= FALSE;
5987
       iqentry_ven[n] <= 6'd0;
5988
       iqentry_vl[n] <= 8'd0;
5989
       iqentry_we[n] <= 8'h00;
5990
       iqentry_rfw[n] <= FALSE;
5991
       iqentry_rmw[n] <= FALSE;
5992
       iqentry_pc[n] <= RSTPC;
5993 48 robfinch
         iqentry_instr[n] <= `NOP_INSN;
5994
         iqentry_insln[n] <= 4'd4;
5995
         iqentry_preload[n] <= FALSE;
5996
         iqentry_mem[n] <= FALSE;
5997
         iqentry_memndx[n] <= FALSE;
5998 51 robfinch
       iqentry_memissue[n] <= FALSE;
5999
       iqentry_mem_islot[n] <= 3'd0;
6000
       iqentry_memdb[n] <= FALSE;
6001
       iqentry_memsb[n] <= FALSE;
6002
       iqentry_tgt[n] <= 6'd0;
6003
       iqentry_imm[n] <= 1'b0;
6004
       iqentry_a0[n] <= 64'd0;
6005
       iqentry_a1[n] <= 64'd0;
6006
       iqentry_a2[n] <= 64'd0;
6007
       iqentry_a3[n] <= 64'd0;
6008
       iqentry_a1_v[n] <= `INV;
6009
       iqentry_a2_v[n] <= `INV;
6010
       iqentry_a3_v[n] <= `INV;
6011
       iqentry_a1_s[n] <= 5'd0;
6012
       iqentry_a2_s[n] <= 5'd0;
6013
       iqentry_a3_s[n] <= 5'd0;
6014
       iqentry_canex[n] <= FALSE;
6015 48 robfinch
    end
6016 49 robfinch
     bwhich <= 2'b00;
6017 48 robfinch
     dram0 <= `DRAMSLOT_AVAIL;
6018
     dram1 <= `DRAMSLOT_AVAIL;
6019
     dram2 <= `DRAMSLOT_AVAIL;
6020
     dram0_instr <= `NOP_INSN;
6021
     dram1_instr <= `NOP_INSN;
6022
     dram2_instr <= `NOP_INSN;
6023
     dram0_addr <= 32'h0;
6024
     dram1_addr <= 32'h0;
6025
     dram2_addr <= 32'h0;
6026
     L1_adr <= RSTPC;
6027
     invic <= FALSE;
6028
     tail0 <= 3'd0;
6029
     tail1 <= 3'd1;
6030
     head0 <= 0;
6031
     head1 <= 1;
6032
     head2 <= 2;
6033
     head3 <= 3;
6034
     head4 <= 4;
6035
     head5 <= 5;
6036
     head6 <= 6;
6037
     head7 <= 7;
6038 52 robfinch
     head8 <= 8;
6039
     head9 <= 9;
6040 48 robfinch
     panic = `PANIC_NONE;
6041
     alu0_dataready <= 0;
6042
     alu1_dataready <= 0;
6043
     alu0_sourceid <= 5'd0;
6044
     alu1_sourceid <= 5'd0;
6045
`ifdef SIM
6046
                alu0_pc <= RSTPC;
6047
                alu0_instr <= `NOP_INSN;
6048
                alu0_argA <= 64'h0;
6049
                alu0_argB <= 64'h0;
6050
                alu0_argC <= 64'h0;
6051
                alu0_argI <= 64'h0;
6052
                alu0_bt <= 1'b0;
6053
                alu0_mem <= 1'b0;
6054
                alu0_shft48 <= 1'b0;
6055
                alu0_thrd <= 1'b0;
6056
                alu0_tgt <= 6'h00;
6057
                alu0_ven <= 6'd0;
6058
                alu1_pc <= RSTPC;
6059
                alu1_instr <= `NOP_INSN;
6060
                alu1_argA <= 64'h0;
6061
                alu1_argB <= 64'h0;
6062
                alu1_argC <= 64'h0;
6063
                alu1_argI <= 64'h0;
6064
                alu1_bt <= 1'b0;
6065
                alu1_mem <= 1'b0;
6066
                alu1_shft48 <= 1'b0;
6067
                alu1_thrd <= 1'b0;
6068
                alu1_tgt <= 6'h00;
6069
                alu1_ven <= 6'd0;
6070
`endif
6071
     fcu_dataready <= 0;
6072
     fcu_instr <= `NOP_INSN;
6073
     dramA_v <= 0;
6074
     dramB_v <= 0;
6075
     dramC_v <= 0;
6076
     I <= 0;
6077
     icstate <= IDLE;
6078
     bstate <= BIDLE;
6079
     tick <= 64'd0;
6080
     bte_o <= 2'b00;
6081
     cti_o <= 3'b000;
6082
     cyc_o <= `LOW;
6083
     stb_o <= `LOW;
6084
     we_o <= `LOW;
6085
     sel_o <= 8'h00;
6086
     sr_o <= `LOW;
6087
     cr_o <= `LOW;
6088
     adr_o <= RSTPC;
6089
     icl_o <= `LOW;             // instruction cache load
6090
     cr0 <= 64'd0;
6091
     cr0[13:8] <= 6'd0;         // select register set #0
6092
     cr0[30] <= TRUE;           // enable data caching
6093
     cr0[32] <= TRUE;           // enable branch predictor
6094
     cr0[16] <= 1'b0;           // disable SMT
6095
     cr0[17] <= 1'b0;           // sequence number reset = 1
6096 52 robfinch
     cr0[34] <= FALSE;  // write buffer merging enable
6097 48 robfinch
     pcr <= 32'd0;
6098
     pcr2 <= 64'd0;
6099
    for (n = 0; n < PREGS; n = n + 1)
6100
         rf_v[n] <= `VAL;
6101
     tgtq <= FALSE;
6102 51 robfinch
     fp_rm <= 3'd0;                     // round nearest even - default rounding mode
6103
     fpu_csr[37:32] <= 5'd31;   // register set #31
6104 48 robfinch
     waitctr <= 64'd0;
6105
    for (n = 0; n < 16; n = n + 1)
6106
         badaddr[n] <= 64'd0;
6107
     sbl <= 32'h0;
6108
     sbu <= 32'hFFFFFFFF;
6109
    // Vector
6110
     vqe0 <= 6'd0;
6111
     vqet0 <= 6'd0;
6112
     vqe1 <= 6'd0;
6113
     vqet1 <= 6'd0;
6114
     vl <= 7'd62;
6115
    for (n = 0; n < 8; n = n + 1)
6116
         vm[n] <= 64'h7FFFFFFFFFFFFFFF;
6117
     nop_fetchbuf <= 4'h0;
6118
     seq_num <= 5'd0;
6119
     seq_num1 <= 5'd0;
6120
     fcu_done <= `TRUE;
6121
     sema <= 64'h0;
6122
     tvec[0] <= RSTPC;
6123 49 robfinch
     pmr <= 64'hFFFFFFFFFFFFFFFF;
6124
     pmr[0] <= `ID1_AVAIL;
6125
     pmr[1] <= `ID2_AVAIL;
6126
     pmr[2] <= `ID3_AVAIL;
6127
     pmr[8] <= `ALU0_AVAIL;
6128
     pmr[9] <= `ALU1_AVAIL;
6129
     pmr[16] <= `FPU1_AVAIL;
6130
     pmr[17] <= `FPU2_AVAIL;
6131
     pmr[24] <= `MEM1_AVAIL;
6132
     pmr[25] <= `MEM2_AVAIL;
6133
                 pmr[26] <= `MEM3_AVAIL;
6134
     pmr[32] <= `FCU_AVAIL;
6135
     for (n = 0; n < `WB_DEPTH; n = n + 1) begin
6136
        wb_v[n] <= 1'b0;
6137
        wb_rmw[n] <= 1'b0;
6138
        wb_id[n] <= {QENTRIES{1'b0}};
6139
     end
6140
     wb_en <= `TRUE;
6141
     wbo_id <= {QENTRIES{1'b0}};
6142
`ifdef SIM
6143
                wb_merges <= 32'd0;
6144
`endif
6145 48 robfinch
end
6146
else begin
6147 49 robfinch
        if (|fb_panic)
6148
                panic <= fb_panic;
6149
        begin
6150
                branchmiss <= excmiss|fcu_branchmiss;
6151 51 robfinch
                misspc <= excmiss ? excmisspc : fcu_misspc;
6152
                missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
6153 49 robfinch
                branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
6154
        end
6155 48 robfinch
        // The following signals only pulse
6156
 
6157
        // Instruction decode output should only pulse once for a queue entry. We
6158
        // want the decode to be invalidated after a clock cycle so that it isn't
6159
        // inadvertently used to update the queue at a later point.
6160
        id1_vi <= `INV;
6161 49 robfinch
        if (`NUM_IDU > 1)
6162
                id2_vi <= `INV;
6163
        if (`NUM_IDU > 2)
6164
                id3_vi <= `INV;
6165
        if (iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]])
6166
                fcu_dataready <= `INV;
6167 52 robfinch
        wb_shift <= FALSE;
6168 48 robfinch
        ld_time <= {ld_time[4:0],1'b0};
6169
        wc_times <= wc_time;
6170
     rf_vra0 <= regIsValid[Ra0s];
6171
     rf_vra1 <= regIsValid[Ra1s];
6172
    if (vqe0 >= vl) begin
6173
         vqe0 <= 6'd0;
6174
         vqet0 <= 6'h0;
6175
    end
6176
    if (vqe1 >= vl) begin
6177
         vqe1 <= 6'd0;
6178
         vqet1 <= 6'h0;
6179
    end
6180
    // Turn off vector chaining indicator when chained instructions are done.
6181
    if ((vqe0 >= vl || vqe0==6'd0) && (vqe1 >= vl || vqe1==6'd0))
6182
`ifdef SUPPORT_SMT
6183
        mstatus[0][32] <= 1'b0;
6184
`else
6185
        mstatus[32] <= 1'b0;
6186
`endif
6187
 
6188
     nop_fetchbuf <= 4'h0;
6189
     excmiss <= FALSE;
6190
     invic <= FALSE;
6191
     tick <= tick + 64'd1;
6192
     alu0_ld <= FALSE;
6193
     alu1_ld <= FALSE;
6194 49 robfinch
     fpu1_ld <= FALSE;
6195
     fpu2_ld <= FALSE;
6196 48 robfinch
     fcu_ld <= FALSE;
6197
     dramA_v <= FALSE;
6198
     dramB_v <= FALSE;
6199
     dramC_v <= FALSE;
6200
     cr0[17] <= 1'b0;
6201
    if (waitctr != 64'd0)
6202
         waitctr <= waitctr - 64'd1;
6203
 
6204
 
6205 50 robfinch
    if (iqentry_fc[fcu_id[`QBITS]] && iqentry_v[fcu_id[`QBITS]] && !iqentry_done[fcu_id[`QBITS]] && iqentry_out[fcu_id[`QBITS]])
6206 48 robfinch
        fcu_timeout <= fcu_timeout + 8'd1;
6207
 
6208
        if (branchmiss) begin
6209
        for (n = 1; n < PREGS; n = n + 1)
6210
           if (~livetarget[n]) begin
6211
                        if (branchmiss_thrd) begin
6212
                                if (n >= 128)
6213
                                rf_v[n] <= `VAL;
6214
                        end
6215
                        else begin
6216
                                if (n < 128)
6217
                                rf_v[n] <= `VAL;
6218
                end
6219
           end
6220
 
6221 52 robfinch
            if (|iqentry_0_latestID)     if (iqentry_thrd[0]==branchmiss_thrd) rf_source[ {iqentry_tgt[0][7:0]} ] <= { 1'b0, iqentry_mem[0], 4'd0 };
6222
        if (|iqentry_1_latestID)     if (iqentry_thrd[1]==branchmiss_thrd) rf_source[ {iqentry_tgt[1][7:0]} ] <= { 1'b0, iqentry_mem[1], 4'd1 };
6223
        if (|iqentry_2_latestID)     if (iqentry_thrd[2]==branchmiss_thrd) rf_source[ {iqentry_tgt[2][7:0]} ] <= { 1'b0, iqentry_mem[2], 4'd2 };
6224
        if (|iqentry_3_latestID)     if (iqentry_thrd[3]==branchmiss_thrd) rf_source[ {iqentry_tgt[3][7:0]} ] <= { 1'b0, iqentry_mem[3], 4'd3 };
6225
        if (|iqentry_4_latestID)     if (iqentry_thrd[4]==branchmiss_thrd) rf_source[ {iqentry_tgt[4][7:0]} ] <= { 1'b0, iqentry_mem[4], 4'd4 };
6226
        if (|iqentry_5_latestID)     if (iqentry_thrd[5]==branchmiss_thrd) rf_source[ {iqentry_tgt[5][7:0]} ] <= { 1'b0, iqentry_mem[5], 4'd5 };
6227
        if (|iqentry_6_latestID)     if (iqentry_thrd[6]==branchmiss_thrd) rf_source[ {iqentry_tgt[6][7:0]} ] <= { 1'b0, iqentry_mem[6], 4'd6 };
6228
        if (|iqentry_7_latestID)     if (iqentry_thrd[7]==branchmiss_thrd) rf_source[ {iqentry_tgt[7][7:0]} ] <= { 1'b0, iqentry_mem[7], 4'd7 };
6229
        if (|iqentry_8_latestID)     if (iqentry_thrd[8]==branchmiss_thrd) rf_source[ {iqentry_tgt[8][7:0]} ] <= { 1'b0, iqentry_mem[8], 4'd8 };
6230
        if (|iqentry_9_latestID)     if (iqentry_thrd[9]==branchmiss_thrd) rf_source[ {iqentry_tgt[9][7:0]} ] <= { 1'b0, iqentry_mem[9], 4'd9 };
6231 48 robfinch
 
6232
    end
6233
 
6234
    // The source for the register file data might have changed since it was
6235
    // placed on the commit bus. So it's needed to check that the source is
6236
    // still as expected to validate the register.
6237
        if (commit0_v) begin
6238
        if (!rf_v[ {commit0_tgt[7:0]} ])
6239
//             rf_v[ {commit0_tgt[7:0]} ] <= rf_source[ commit0_tgt[7:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]);
6240
             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] ]);
6241
        if (commit0_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit0_tgt, commit0_bus, regIsValid[commit0_tgt[5:0]],
6242
        rf_source[ {commit0_tgt[7:0]} ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]));
6243
        if (commit0_tgt[5:0]==6'd30 && commit0_bus==64'd0)
6244
                $display("FP <= 0");
6245
    end
6246 49 robfinch
    if (commit1_v && `NUM_CMT > 1) begin
6247 48 robfinch
        if (!rf_v[ {commit1_tgt[7:0]} ]) begin
6248
                if ({commit1_tgt[7:0]}=={commit0_tgt[7:0]})
6249
                         rf_v[ {commit1_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}];
6250
                        /*
6251
                                (rf_source[ commit0_tgt[4:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ])) ||
6252
                                (rf_source[ commit1_tgt[4:0] ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6253
                        */
6254
                else
6255
                 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] ]);
6256
        end
6257
        if (commit1_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit1_tgt, commit1_bus, regIsValid[commit1_tgt[5:0]],
6258
        rf_source[ {commit1_tgt[7:0]} ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6259
        if (commit1_tgt[5:0]==6'd30 && commit1_bus==64'd0)
6260
                $display("FP <= 0");
6261
    end
6262
     rf_v[0] <= 1;
6263
 
6264 49 robfinch
  //
6265
  // ENQUEUE
6266
  //
6267
  // place up to two instructions from the fetch buffer into slots in the IQ.
6268
  //   note: they are placed in-order, and they are expected to be executed
6269
  // 0, 1, or 2 of the fetch buffers may have valid data
6270
  // 0, 1, or 2 slots in the instruction queue may be available.
6271
  // if we notice that one of the instructions in the fetch buffer is a predicted branch,
6272
  // (set branchback/backpc and delete any instructions after it in fetchbuf)
6273
  //
6274 48 robfinch
 
6275
        // enqueue fetchbuf0 and fetchbuf1, but only if there is room, 
6276
        // and ignore fetchbuf1 if fetchbuf0 has a backwards branch in it.
6277
        //
6278
        // also, do some instruction-decode ... set the operand_valid bits in the IQ
6279
        // appropriately so that the DATAINCOMING stage does not have to look at the opcode
6280
        //
6281
        if (!branchmiss)        // don't bother doing anything if there's been a branch miss
6282
 
6283
                case ({fetchbuf0_v, fetchbuf1_v})
6284
 
6285
            2'b00: ; // do nothing
6286
 
6287
            2'b01:
6288
                    if (canq1) begin
6289
                    if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6290
                         vqe1 <= vqe1 + 4'd1;
6291
                        if (IsVCmprss(fetchbuf1_instr)) begin
6292
                            if (vm[fetchbuf1_instr[25:23]][vqe1])
6293
                                 vqet1 <= vqet1 + 4'd1;
6294
                        end
6295
                        else
6296
                             vqet1 <= vqet1 + 4'd1;
6297
                        if (vqe1 >= vl-2)
6298
                                 nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6299
                            enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, vqe1);
6300
                            if (fetchbuf1_thrd)
6301
                                seq_num1 <= seq_num1 + 5'd1;
6302
                            else
6303
                                seq_num <= seq_num + 5'd1;
6304
                             tgtq <= FALSE;
6305
                            if (fetchbuf1_rfw) begin
6306
                                 rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail0 }; // top bit indicates ALU/MEM bus
6307
                                 rf_v [Rt1s] <= `INV;
6308
                            end
6309
                        if (canq2 && vqe1 < vl-2) begin
6310
                                 vqe1 <= vqe1 + 4'd2;
6311
                                if (IsVCmprss(fetchbuf1_instr)) begin
6312
                                    if (vm[fetchbuf1_instr[25:23]][vqe1+6'd1])
6313
                                         vqet1 <= vqet1 + 4'd2;
6314
                                end
6315
                                else
6316
                                     vqet1 <= vqet1 + 4'd2;
6317
                                    enque1(tail1, fetchbuf1_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe1 + 6'd1);
6318
                                    if (fetchbuf1_thrd)
6319
                                        seq_num1 <= seq_num1 + 5'd2;
6320
                                    else
6321
                                        seq_num <= seq_num + 5'd2;
6322
                                     tgtq <= FALSE;
6323
                                    if (fetchbuf1_rfw) begin
6324
                                         rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail1 }; // top bit indicates ALU/MEM bus
6325
                                         rf_v [Rt1s] <= `INV;
6326
                                    end
6327
                        end
6328
                    end
6329
                    else begin
6330
                            enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, 6'd0);
6331
                            if (fetchbuf1_thrd)
6332
                                seq_num1 <= seq_num1 + 5'd1;
6333
                            else
6334
                                seq_num <= seq_num + 5'd1;
6335
                             tgtq <= FALSE;
6336
                            if (fetchbuf1_rfw) begin
6337
                                 rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail0 }; // top bit indicates ALU/MEM bus
6338
                                 rf_v [Rt1s] <= `INV;
6339
                            end
6340
                        end
6341
                    end
6342
 
6343
            2'b10:
6344
                if (canq1) begin
6345
//                  $display("queued1: %d", queued1);
6346
//                      if (!IsBranch(fetchbuf0_instr))         panic <= `PANIC_FETCHBUFBEQ;
6347
//                      if (!predict_taken0)    panic <= `PANIC_FETCHBUFBEQ;
6348
                        //
6349
                        // this should only happen when the first instruction is a BEQ-backwards and the IQ
6350
                        // happened to be full on the previous cycle (thus we deleted fetchbuf1 but did not
6351
                        // enqueue fetchbuf0) ... probably no need to check for LW -- sanity check, just in case
6352
                        //
6353
                    if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
6354
                         vqe0 <= vqe0 + 4'd1;
6355
                        if (IsVCmprss(fetchbuf0_instr)) begin
6356
                            if (vm[fetchbuf0_instr[25:23]][vqe0])
6357
                                 vqet0 <= vqet0 + 4'd1;
6358
                        end
6359
                        else
6360
                             vqet0 <= vqet0 + 4'd1;
6361
                        if (vqe0 >= vl-2)
6362
                                 nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6363
                                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
6364
                                if (fetchbuf0_thrd)
6365
                                        seq_num1 <= seq_num1 + 5'd1;
6366
                                else
6367
                                        seq_num <= seq_num + 5'd1;
6368
                             tgtq <= FALSE;
6369
                                if (fetchbuf0_rfw) begin
6370
                                 rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
6371
                                 rf_v[Rt0s] <= `INV;
6372
                            end
6373
                        if (canq2) begin
6374
                                    if (vqe0 < vl-2) begin
6375
                                         vqe0 <= vqe0 + 4'd2;
6376
                                        if (IsVCmprss(fetchbuf0_instr)) begin
6377
                                            if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
6378
                                                 vqet0 <= vqet0 + 4'd2;
6379
                                        end
6380
                                        else
6381
                                             vqet0 <= vqet0 + 4'd2;
6382
                                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num+5'd1, vqe0 + 6'd1);
6383
                                                if (fetchbuf0_thrd)
6384
                                                        seq_num1 <= seq_num1 + 5'd2;
6385
                                                else
6386
                                                        seq_num <= seq_num + 5'd2;
6387
                                             tgtq <= FALSE;
6388
                                                if (fetchbuf0_rfw) begin
6389
                                                 rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };    // top bit indicates ALU/MEM bus
6390
                                                 rf_v[Rt0s] <= `INV;
6391
                                            end
6392
                                    end
6393
                        end
6394
                    end
6395
                    else begin
6396
                                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, 6'd0);
6397
                                if (fetchbuf0_thrd)
6398
                                        seq_num1 <= seq_num1 + 5'd1;
6399
                                else
6400
                                        seq_num <= seq_num + 5'd1;
6401
                             tgtq <= FALSE;
6402
                                if (fetchbuf0_rfw) begin
6403
                                 rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
6404
                                 rf_v[Rt0s] <= `INV;
6405
                            end
6406
                        end
6407
                    end
6408
 
6409
            2'b11:
6410
                    if (canq1) begin
6411
                                //
6412
                                // if the first instruction is a predicted branch, enqueue it & stomp on all following instructions
6413
                                // but only if the following instruction is in the same thread. Otherwise we want to queue two.
6414
                                //
6415
                                if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
6416
                             tgtq <= FALSE;
6417
                            enque0(tail0,fetchbuf0_thrd ? seq_num1 : seq_num,6'd0);
6418
                                if (fetchbuf0_thrd)
6419
                                        seq_num1 <= seq_num1 + 5'd1;
6420
                                else
6421
                                        seq_num <= seq_num + 5'd1;
6422
                                        if (fetchbuf0_rfw) begin
6423
                                             rf_source[ Rt0s ] <= {1'b0,fetchbuf0_memld, tail0};
6424
                                             rf_v [ Rt0s ] <= `INV;
6425
                                        end
6426
                                end
6427
 
6428
                                else begin      // fetchbuf0 doesn't contain a predicted branch
6429
                                    //
6430
                                    // so -- we can enqueue 1 or 2 instructions, depending on space in the IQ
6431
                                    // update the rf_v and rf_source bits separately (at end)
6432
                                    //   the problem is that if we do have two instructions, 
6433
                                    //   they may interact with each other, so we have to be
6434
                                    //   careful about where things point.
6435
                                    //
6436
                                    // enqueue the first instruction ...
6437
                                    //
6438
                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
6439
                                 vqe0 <= vqe0 + 4'd1;
6440
                                if (IsVCmprss(fetchbuf0_instr)) begin
6441
                                    if (vm[fetchbuf0_instr[25:23]][vqe0])
6442
                                         vqet0 <= vqet0 + 4'd1;
6443
                                end
6444
                                else
6445
                                     vqet0 <= vqet0 + 4'd1;
6446
                                if (vqe0 >= vl-2)
6447
                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6448
                            end
6449
                            tgtq <= FALSE;
6450
                            if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
6451
                                    enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
6452
                                        if (fetchbuf0_thrd)
6453
                                                seq_num1 <= seq_num1 + 5'd1;
6454
                                        else
6455
                                                seq_num <= seq_num + 5'd1;
6456
                                            //
6457
                                            // if there is room for a second instruction, enqueue it
6458
                                            //
6459
                                            if (canq2) begin
6460
                                                if (vechain && IsVector(fetchbuf1_instr)
6461
                                                && Ra1s != Rt0s // And there is no dependency
6462
                                                && Rb1s != Rt0s
6463
                                                && Rc1s != Rt0s
6464
                                                ) begin
6465
`ifdef SUPPORT_SMT
6466
                                                        mstatus[0][32] <= 1'b1;
6467
`else
6468
                                                        mstatus[32] <= 1'b1;
6469
`endif
6470
                                                vqe1 <= vqe1 + 4'd1;
6471
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6472
                                                    if (vm[fetchbuf1_instr[25:23]][vqe1])
6473
                                                         vqet1 <= vqet1 + 4'd1;
6474
                                                end
6475
                                                else
6476
                                                     vqet1 <= vqet1 + 4'd1;
6477
                                                if (vqe1 >= vl-2)
6478
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6479
                                                        enque1(tail1,
6480
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6481
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6482
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
6483
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6484
                                                                if (fetchbuf1_thrd)
6485
                                                                        seq_num1 <= seq_num1 + 5'd2;
6486
                                                                else
6487
                                                                        seq_num <= seq_num + 5'd2;
6488
                                                        end
6489
                                                        else begin
6490
                                                                if (fetchbuf1_thrd)
6491
                                                                        seq_num1 <= seq_num1 + 5'd1;
6492
                                                                else
6493
                                                                        seq_num <= seq_num + 5'd1;
6494
                                                        end
6495
 
6496
                                                                // SOURCE 1 ...
6497
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6498
                                                                if (~fetchbuf0_rfw) begin
6499
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6500
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6501
                                                                end
6502
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6503
                                                                else if (Ra1 == Rt0) begin
6504
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6505
                                                                     iqentry_a1_v [tail1] <= `INV;
6506
                                                                     iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6507
                                                                end
6508
                                                                // if no overlap, get info from rf_v and rf_source
6509
                                                                else begin
6510
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6511
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6512
                                                                end
6513
 
6514
                                                                // SOURCE 2 ...
6515
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6516
                                                                if (~fetchbuf0_rfw) begin
6517
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6518
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6519
                                                                end
6520
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6521
                                                                else if (Rb1s == Rt0s) begin
6522
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6523
                                                                     iqentry_a2_v [tail1] <= `INV;
6524
                                                                     iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6525
                                                                end
6526
                                                                // if no overlap, get info from rf_v and rf_source
6527
                                                                else begin
6528
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6529
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6530
                                                                end
6531
 
6532
                                                                // SOURCE 3 ...
6533
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6534
                                                                if (~fetchbuf0_rfw) begin
6535
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6536
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6537
                                                                end
6538
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6539
                                                                else if (Rc1 == Rt0) begin
6540
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6541
                                                                     iqentry_a3_v [tail1] <= `INV;
6542
                                                                     iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6543
                                                                end
6544
                                                                // if no overlap, get info from rf_v and rf_source
6545
                                                                else begin
6546
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6547
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6548
                                                                end
6549
 
6550
                                                                // if the two instructions enqueued target the same register, 
6551
                                                                // make sure only the second writes to rf_v and rf_source.
6552
                                                                // first is allowed to update rf_v and rf_source only if the
6553
                                                                // second has no target
6554
                                                                //
6555
                                                            if (fetchbuf0_rfw) begin
6556
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6557
                                                                     rf_v [ Rt0s] <= `INV;
6558
                                                            end
6559
                                                            if (fetchbuf1_rfw) begin
6560
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6561
                                                                     rf_v [ Rt1s ] <= `INV;
6562
                                                            end
6563
                                                end
6564
                                                // If there was a vector instruction in fetchbuf0, we really
6565
                                                // want to queue the next vector element, not the next
6566
                                                // instruction waiting in fetchbuf1.
6567
                                            else if (IsVector(fetchbuf0_instr) && SUP_VECTOR && vqe0 < vl-1) begin
6568
                                                 vqe0 <= vqe0 + 4'd2;
6569
                                                if (IsVCmprss(fetchbuf0_instr)) begin
6570
                                                    if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
6571
                                                         vqet0 <= vqet0 + 4'd2;
6572
                                                end
6573
                                                else
6574
                                                     vqet0 <= vqet0 + 4'd2;
6575
                                                if (vqe0 >= vl-3)
6576
                                                 nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6577
                                            if (vqe0 < vl-1) begin
6578
                                                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe0 + 6'd1);
6579
                                                                if (fetchbuf0_thrd)
6580
                                                                        seq_num1 <= seq_num1 + 5'd2;
6581
                                                                else
6582
                                                                        seq_num <= seq_num + 5'd2;
6583
 
6584
                                                                        // SOURCE 1 ...
6585
                                                     iqentry_a1_v [tail1] <= regIsValid[Ra0s];
6586
                                                     iqentry_a1_s [tail1] <= rf_source [Ra0s];
6587
 
6588
                                                                        // SOURCE 2 ...
6589
                                                     iqentry_a2_v [tail1] <= regIsValid[Rb0s];
6590
                                                     iqentry_a2_s [tail1] <= rf_source[ Rb0s ];
6591
 
6592
                                                                        // SOURCE 3 ...
6593
                                                     iqentry_a3_v [tail1] <= regIsValid[Rc0s];
6594
                                                     iqentry_a3_s [tail1] <= rf_source[ Rc0s ];
6595
 
6596
                                                                        // if the two instructions enqueued target the same register, 
6597
                                                                        // make sure only the second writes to rf_v and rf_source.
6598
                                                                        // first is allowed to update rf_v and rf_source only if the
6599
                                                                        // second has no target (BEQ or SW)
6600
                                                                        //
6601
                                                                    if (fetchbuf0_rfw) begin
6602
                                                                             rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };
6603
                                                                             rf_v [ Rt0s ] <= `INV;
6604
                                                                    end
6605
                                                                end
6606
                                                end
6607
                                            else if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6608
                                                 vqe1 <= 6'd1;
6609
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6610
                                                    if (vm[fetchbuf1_instr[25:23]][IsVector(fetchbuf0_instr)? 6'd0:vqe1+6'd1])
6611
                                                         vqet1 <= 6'd1;
6612
                                                else
6613
                                                         vqet1 <= 6'd0;
6614
                                                end
6615
                                                else
6616
                                                         vqet1 <= 6'd1;
6617
                                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR)
6618
                                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6619
                                                        enque1(tail1,
6620
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6621
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6622
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
6623
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6624
                                                                if (fetchbuf1_thrd)
6625
                                                                        seq_num1 <= seq_num1 + 5'd2;
6626
                                                                else
6627
                                                                        seq_num <= seq_num + 5'd2;
6628
                                                        end
6629
                                                        else begin
6630
                                                                if (fetchbuf1_thrd)
6631
                                                                        seq_num1 <= seq_num1 + 5'd1;
6632
                                                                else
6633
                                                                        seq_num <= seq_num + 5'd1;
6634
                                                        end
6635
 
6636
                                                                // SOURCE 1 ...
6637
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6638
                                                                if (~fetchbuf0_rfw) begin
6639
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6640
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6641
                                                                end
6642
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6643
                                                                else if (Ra1 == Rt0) begin
6644
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6645
                                                                     iqentry_a1_v [tail1] <= `INV;
6646
                                                                     iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6647
                                                                end
6648
                                                                // if no overlap, get info from rf_v and rf_source
6649
                                                                else begin
6650
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6651
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6652
                                                                end
6653
 
6654
                                                                // SOURCE 2 ...
6655
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6656
                                                                if (~fetchbuf0_rfw) begin
6657
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6658
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6659
                                                                end
6660
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6661
                                                                else if (Rb1s == Rt0s) begin
6662
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6663
                                                                     iqentry_a2_v [tail1] <= `INV;
6664
                                                                     iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6665
                                                                end
6666
                                                                // if no overlap, get info from rf_v and rf_source
6667
                                                                else begin
6668
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6669
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6670
                                                                end
6671
 
6672
                                                                // SOURCE 3 ...
6673
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6674
                                                                if (~fetchbuf0_rfw) begin
6675
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6676
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6677
                                                                end
6678
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6679
                                                                else if (Rc1 == Rt0) begin
6680
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6681
                                                                     iqentry_a3_v [tail1] <= `INV;
6682
                                                                     iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6683
                                                                end
6684
                                                                // if no overlap, get info from rf_v and rf_source
6685
                                                                else begin
6686
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6687
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6688
                                                                end
6689
 
6690
                                                                // if the two instructions enqueued target the same register, 
6691
                                                                // make sure only the second writes to rf_v and rf_source.
6692
                                                                // first is allowed to update rf_v and rf_source only if the
6693
                                                                // second has no target
6694
                                                                //
6695
                                                            if (fetchbuf0_rfw) begin
6696
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6697
                                                                     rf_v [ Rt0s] <= `INV;
6698
                                                            end
6699
                                                            if (fetchbuf1_rfw) begin
6700
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6701
                                                                     rf_v [ Rt1s ] <= `INV;
6702
                                                            end
6703
                                            end
6704
                                            else begin
6705
//                                                      enque1(tail1, seq_num + 5'd1, 6'd0);
6706
                                                        enque1(tail1,
6707
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6708
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6709
                                                                fetchbuf1_thrd ? seq_num1: seq_num, 6'd0);
6710
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6711
                                                                if (fetchbuf1_thrd)
6712
                                                                        seq_num1 <= seq_num1 + 5'd2;
6713
                                                                else
6714
                                                                        seq_num <= seq_num + 5'd2;
6715
                                                        end
6716
                                                        else begin
6717
                                                                        seq_num1 <= seq_num1 + 5'd1;
6718
                                                                        seq_num <= seq_num + 5'd1;
6719
                                                        end
6720
 
6721
                                                                // SOURCE 1 ...
6722
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6723
                                                                if (~fetchbuf0_rfw) begin
6724
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6725
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6726
                                                                end
6727
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6728
                                                                else if (Ra1s == Rt0s) begin
6729
                                                                     iqentry_a1_v [tail1] <= `INV;
6730
                                                                     iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
6731
                                                                end
6732
                                                                // if no overlap, get info from regIsValid and rf_source
6733
                                                                else begin
6734
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6735
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6736
                                                                end
6737
 
6738
                                                                // SOURCE 2 ...
6739
                                                                // if the argument is an immediate or not needed, we're done
6740
                                                                $display("Rb1s=%h, Rt0s=%h", Rb1s, Rt0s);
6741
                                                                $display("instr=%h", fetchbuf1_instr);
6742
                                                                // if previous instruction writes nothing to RF, then get info from regIsValid and rf_source
6743
                                                                if (~fetchbuf0_rfw) begin
6744
                                                                        $display("fetchbuf0_rfw=0");
6745
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6746
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6747
                                                                end
6748
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6749
                                                                else if (Rb1s == Rt0s) begin
6750
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6751
                                                                     iqentry_a2_v [tail1] <= `INV;
6752
                                                                     iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
6753
                                                                end
6754
                                                                // if no overlap, get info from regIsValid and rf_source
6755
                                                                else begin
6756
                                                                                $display("No overlap");
6757
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6758
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6759
                                                                end
6760
 
6761
                                                                // SOURCE 3 ...
6762
                                                                // if previous instruction writes nothing to RF, then get info from regIsValid and rf_source
6763
                                                                if (~fetchbuf0_rfw) begin
6764
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6765
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6766
                                                                end
6767
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6768
                                                                else if (Rc1s == Rt0s) begin
6769
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6770
                                                                     iqentry_a3_v [tail1] <= `INV;
6771
                                                                     iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
6772
                                                                end
6773
                                                                // if no overlap, get info from regIsValid and rf_source
6774
                                                                else begin
6775
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6776
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6777
                                                                end
6778
 
6779
                                                                // if the two instructions enqueued target the same register, 
6780
                                                                // make sure only the second writes to regIsValid and rf_source.
6781
                                                                // first is allowed to update regIsValid and rf_source only if the
6782
                                                                // second has no target (BEQ or SW)
6783
                                                                //
6784
                                                            if (fetchbuf0_rfw) begin
6785
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6786
                                                                     rf_v [ Rt0s] <= `INV;
6787
                                                                     $display("r%dx (%d) Invalidated", Rt0s, Rt0s[4:0]);
6788
                                                            end
6789
                                                            else
6790
                                                                $display("No rfw");
6791
                                                            if (fetchbuf1_rfw) begin
6792
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6793
                                                                     $display("r%dx (%d) Invalidated", Rt1s, Rt1s[4:0]);
6794
                                                                     rf_v [ Rt1s ] <= `INV;
6795
                                                            end
6796
                                                            else
6797
                                                                $display("No rfw");
6798
                                                        end
6799
 
6800
                                            end // ends the "if IQ[tail1] is available" clause
6801
                                            else begin  // only first instruction was enqueued
6802
                                                        if (fetchbuf0_rfw) begin
6803
                                                             $display("r%dx (%d) Invalidated 1", Rt0s, Rt0s[4:0]);
6804
                                                             rf_source[ Rt0s ] <= {1'b0,fetchbuf0_memld, tail0};
6805
                                                             rf_v [ Rt0s ] <= `INV;
6806
                                                        end
6807
                                                end
6808
                                    end
6809
 
6810
                                end     // ends the "else fetchbuf0 doesn't have a backwards branch" clause
6811
                    end
6812
                endcase
6813
        if (pebm) begin
6814
                if (branchmiss_thrd==1'b0)
6815
                        seq_num <= seq_num + 5'd3;
6816
                else
6817
                        seq_num1 <= seq_num1 + 5'd3;
6818
        end
6819
 
6820
//
6821
// DATAINCOMING
6822
//
6823
// wait for operand/s to appear on alu busses and puts them into 
6824
// the iqentry_a1 and iqentry_a2 slots (if appropriate)
6825
// as well as the appropriate iqentry_res slots (and setting valid bits)
6826
//
6827
// put results into the appropriate instruction entries
6828
//
6829
// This chunk of code has to be before the enqueue stage so that the agen bit
6830
// can be reset to zero by enqueue.
6831
// put results into the appropriate instruction entries
6832
//
6833
if (IsMul(alu0_instr)|IsDivmod(alu0_instr)|alu0_shft48) begin
6834
        if (alu0_done) begin
6835
                alu0_dataready <= `TRUE;
6836
        end
6837
end
6838
 
6839
if (alu0_v) begin
6840
        iqentry_tgt [ alu0_id[`QBITS] ] <= alu0_tgt;
6841
        iqentry_res     [ alu0_id[`QBITS] ] <= alu0_bus;
6842
        iqentry_exc     [ alu0_id[`QBITS] ] <= alu0_exc;
6843
        iqentry_done[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
6844
        iqentry_cmt[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
6845
        iqentry_out     [ alu0_id[`QBITS] ] <= `INV;
6846
        iqentry_agen[ alu0_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
6847
        alu0_dataready <= FALSE;
6848
end
6849
 
6850 49 robfinch
if (alu1_v && `NUM_ALU > 1) begin
6851 48 robfinch
        iqentry_tgt [ alu1_id[`QBITS] ] <= alu1_tgt;
6852
        iqentry_res     [ alu1_id[`QBITS] ] <= alu1_bus;
6853
        iqentry_exc     [ alu1_id[`QBITS] ] <= alu1_exc;
6854
        iqentry_done[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
6855
        iqentry_cmt[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
6856
        iqentry_out     [ alu1_id[`QBITS] ] <= `INV;
6857
        iqentry_agen[ alu1_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
6858
        alu1_dataready <= FALSE;
6859
end
6860
 
6861 49 robfinch
if (fpu1_v) begin
6862 51 robfinch
        iqentry_res [ fpu1_id[`QBITS] ] <= fpu1_bus;
6863
        iqentry_a0  [ fpu1_id[`QBITS] ] <= fpu1_status;
6864
        iqentry_exc [ fpu1_id[`QBITS] ] <= fpu1_exc;
6865 49 robfinch
        iqentry_done[ fpu1_id[`QBITS] ] <= fpu1_done;
6866 51 robfinch
        iqentry_cmt     [ fpu1_id[`QBITS] ] <= fpu1_done;
6867
        iqentry_out [ fpu1_id[`QBITS] ] <= `INV;
6868 49 robfinch
        fpu1_dataready <= FALSE;
6869 48 robfinch
end
6870
 
6871 49 robfinch
if (fpu2_v && `NUM_FPU > 1) begin
6872 51 robfinch
        iqentry_res [ fpu2_id[`QBITS] ] <= fpu2_bus;
6873
        iqentry_a0  [ fpu2_id[`QBITS] ] <= fpu2_status;
6874
        iqentry_exc [ fpu2_id[`QBITS] ] <= fpu2_exc;
6875 49 robfinch
        iqentry_done[ fpu2_id[`QBITS] ] <= fpu2_done;
6876 51 robfinch
        iqentry_cmt [ fpu2_id[`QBITS] ] <= fpu2_done;
6877
        iqentry_out [ fpu2_id[`QBITS] ] <= `INV;
6878 49 robfinch
        //iqentry_agen[ fpu_id[`QBITS] ] <= `VAL;  // RET
6879
        fpu2_dataready <= FALSE;
6880
end
6881
 
6882 51 robfinch
if (fcu_wr & ~fcu_done) begin
6883
        fcu_done <= `TRUE;
6884
  if (fcu_ld)
6885
    waitctr <= fcu_argA;
6886
  iqentry_res [ fcu_id[`QBITS] ] <= fcu_bus;
6887
  iqentry_exc [ fcu_id[`QBITS] ] <= fcu_exc;
6888
  if (IsWait(fcu_instr)) begin
6889
                iqentry_done [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
6890
                iqentry_cmt [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
6891
  end
6892
  else begin
6893
                iqentry_done[ fcu_id[`QBITS] ] <= `TRUE;
6894
                iqentry_cmt[ fcu_id[`QBITS] ] <= `TRUE;
6895
  end
6896
        // Only safe place to propagate the miss pc is a0.
6897
        iqentry_a0[ fcu_id[`QBITS] ] <= fcu_misspc;
6898
        // Update branch taken indicator.
6899
        if (fcu_jal || fcu_ret || fcu_brk || fcu_rti) begin
6900
                iqentry_bt[ fcu_id[`QBITS] ] <= `VAL;
6901
        end
6902
// Branch target is only updated for branch-to-register
6903 52 robfinch
        else if (fcu_branch) begin
6904
                iqentry_takb[ fcu_id[`QBITS] ] <= fcu_takb;
6905
        end
6906 51 robfinch
        iqentry_out [ fcu_id[`QBITS] ] <= `INV;
6907
        //iqentry_agen[ fcu_id[`QBITS] ] <= `VAL;//!IsRet(fcu_instr);
6908
        fcu_dataready <= `VAL;
6909 48 robfinch
         //fcu_dataready <= fcu_branchmiss || !iqentry_agen[ fcu_id[`QBITS] ] || !(iqentry_mem[ fcu_id[`QBITS] ] && IsLoad(iqentry_instr[fcu_id[`QBITS]]));
6910
         //fcu_instr[`INSTRUCTION_OP] <= fcu_branchmiss|| (!IsMem(fcu_instr) && !IsWait(fcu_instr))? `NOP : fcu_instr[`INSTRUCTION_OP]; // to clear branchmiss
6911 51 robfinch
end
6912
// Clear a branch miss when target instruction is fetched.
6913
if (fcu_branchmiss) begin
6914
        if ((fetchbuf0_v && fetchbuf0_pc==misspc) ||
6915
                (fetchbuf1_v && fetchbuf1_pc==misspc))
6916
        fcu_clearbm <= `TRUE;
6917
end
6918
 
6919
if (mem1_available && dramA_v && iqentry_v[ dramA_id[`QBITS] ] && iqentry_load[ dramA_id[`QBITS] ]) begin
6920
        iqentry_res     [ dramA_id[`QBITS] ] <= dramA_bus;
6921
        iqentry_exc     [ dramA_id[`QBITS] ] <= dramA_exc;
6922
        iqentry_done[ dramA_id[`QBITS] ] <= `VAL;
6923
        iqentry_out [ dramA_id[`QBITS] ] <= `INV;
6924
        iqentry_cmt [ dramA_id[`QBITS] ] <= `VAL;
6925
        iqentry_aq  [ dramA_id[`QBITS] ] <= `INV;
6926
end
6927
if (mem2_available && `NUM_MEM > 1 && dramB_v && iqentry_v[ dramB_id[`QBITS] ] && iqentry_load[ dramB_id[`QBITS] ]) begin
6928
        iqentry_res     [ dramB_id[`QBITS] ] <= dramB_bus;
6929
        iqentry_exc     [ dramB_id[`QBITS] ] <= dramB_exc;
6930
        iqentry_done[ dramB_id[`QBITS] ] <= `VAL;
6931
        iqentry_out [ dramB_id[`QBITS] ] <= `INV;
6932
        iqentry_cmt [ dramB_id[`QBITS] ] <= `VAL;
6933
        iqentry_aq  [ dramB_id[`QBITS] ] <= `INV;
6934
end
6935
if (mem3_available && `NUM_MEM > 2 && dramC_v && iqentry_v[ dramC_id[`QBITS] ] && iqentry_load[ dramC_id[`QBITS] ]) begin
6936
        iqentry_res     [ dramC_id[`QBITS] ] <= dramC_bus;
6937
        iqentry_exc     [ dramC_id[`QBITS] ] <= dramC_exc;
6938
        iqentry_done[ dramC_id[`QBITS] ] <= `VAL;
6939
        iqentry_out [ dramC_id[`QBITS] ] <= `INV;
6940
        iqentry_cmt [ dramC_id[`QBITS] ] <= `VAL;
6941
        iqentry_aq  [ dramC_id[`QBITS] ] <= `INV;
6942 48 robfinch
//          if (iqentry_lptr[dram2_id[`QBITS]])
6943
//              wbrcd[pcr[5:0]] <= 1'b1;
6944 51 robfinch
end
6945 48 robfinch
 
6946
//
6947
// set the IQ entry == DONE as soon as the SW is let loose to the memory system
6948
//
6949 50 robfinch
if (mem1_available && dram0 == `DRAMSLOT_BUSY && dram0_store) begin
6950 48 robfinch
        if ((alu0_v && (dram0_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram0_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6951
        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
6952
        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
6953
end
6954 50 robfinch
if (mem2_available && `NUM_MEM > 1 && dram1 == `DRAMSLOT_BUSY && dram1_store) begin
6955 48 robfinch
        if ((alu0_v && (dram1_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram1_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6956
        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
6957
        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
6958
end
6959 50 robfinch
if (mem3_available && `NUM_MEM > 2 && dram2 == `DRAMSLOT_BUSY && dram2_store) begin
6960 48 robfinch
        if ((alu0_v && (dram2_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram2_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6961
        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
6962
        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
6963
end
6964
 
6965
//
6966
// see if anybody else wants the results ... look at lots of buses:
6967
//  - fpu_bus
6968
//  - alu0_bus
6969
//  - alu1_bus
6970
//  - fcu_bus
6971
//  - dram_bus
6972
//  - commit0_bus
6973
//  - commit1_bus
6974
//
6975
 
6976
for (n = 0; n < QENTRIES; n = n + 1)
6977
begin
6978 49 robfinch
        if (`NUM_FPU > 0)
6979
                setargs(n,{1'b0,fpu1_id},fpu1_v,fpu1_bus);
6980
        if (`NUM_FPU > 1)
6981
                setargs(n,{1'b0,fpu2_id},fpu2_v,fpu2_bus);
6982
 
6983 48 robfinch
        setargs(n,{1'b0,alu0_id},alu0_v,alu0_bus);
6984 49 robfinch
        if (`NUM_ALU > 1)
6985
                setargs(n,{1'b0,alu1_id},alu1_v,alu1_bus);
6986
 
6987 48 robfinch
        setargs(n,{1'b0,fcu_id},fcu_wr,fcu_bus);
6988 49 robfinch
 
6989 48 robfinch
        setargs(n,{1'b0,dramA_id},dramA_v,dramA_bus);
6990 49 robfinch
        if (`NUM_MEM > 1)
6991
                setargs(n,{1'b0,dramB_id},dramB_v,dramB_bus);
6992
        if (`NUM_MEM > 2)
6993
                setargs(n,{1'b0,dramC_id},dramC_v,dramC_bus);
6994
 
6995 48 robfinch
        setargs(n,commit0_id,commit0_v,commit0_bus);
6996 49 robfinch
        if (`NUM_CMT > 1)
6997
                setargs(n,commit1_id,commit1_v,commit1_bus);
6998 48 robfinch
 
6999
        setinsn(n[`QBITS],id1_ido,id1_available&id1_vo,id1_bus);
7000 49 robfinch
        if (`NUM_IDU > 1)
7001
                setinsn(n[`QBITS],id2_ido,id2_available&id2_vo,id2_bus);
7002
        if (`NUM_IDU > 2)
7003
                setinsn(n[`QBITS],id3_ido,id3_available&id3_vo,id3_bus);
7004 48 robfinch
end
7005
 
7006
//
7007
// ISSUE 
7008
//
7009
// determines what instructions are ready to go, then places them
7010
// in the various ALU queues.  
7011
// also invalidates instructions following a branch-miss BEQ or any JALR (STOMP logic)
7012
//
7013
 
7014
for (n = 0; n < QENTRIES; n = n + 1)
7015
if (id1_available) begin
7016
if (iqentry_id1issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7017
                id1_vi <= `VAL;
7018
                id1_id                  <= n[4:0];
7019
                id1_instr       <= iqentry_rtop[n] ? (
7020
                                                                                iqentry_a3_v[n] ? iqentry_a3[n]
7021 49 robfinch
`ifdef FU_BYPASS
7022 48 robfinch
                                : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7023
                                : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7024 49 robfinch
`endif
7025 48 robfinch
                                : `NOP_INSN)
7026
                                                                 : iqentry_instr[n];
7027
                id1_ven    <= iqentry_ven[n];
7028
                id1_vl     <= iqentry_vl[n];
7029
                id1_thrd   <= iqentry_thrd[n];
7030
                id1_Rt     <= iqentry_tgt[n][4:0];
7031
                id1_pt                  <= iqentry_pt[n];
7032
  end
7033
end
7034 49 robfinch
if (`NUM_IDU > 1) begin
7035 48 robfinch
for (n = 0; n < QENTRIES; n = n + 1)
7036 49 robfinch
        if (id2_available) begin
7037
                if (iqentry_id2issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7038
                        id2_vi <= `VAL;
7039
                        id2_id                  <= n[4:0];
7040
                        id2_instr       <= iqentry_rtop[n] ? (
7041
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7042
`ifdef FU_BYPASS
7043
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7044
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7045
`endif
7046
                                        : `NOP_INSN)
7047
                                                                         : iqentry_instr[n];
7048
                        id2_ven    <= iqentry_ven[n];
7049
                        id2_vl     <= iqentry_vl[n];
7050
                        id2_thrd   <= iqentry_thrd[n];
7051
                        id2_Rt     <= iqentry_tgt[n][4:0];
7052
                        id2_pt                  <= iqentry_pt[n];
7053
                end
7054 48 robfinch
        end
7055
end
7056 49 robfinch
if (`NUM_IDU > 2) begin
7057
for (n = 0; n < QENTRIES; n = n + 1)
7058
        if (id3_available) begin
7059
                if (iqentry_id3issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7060
                        id3_vi <= `VAL;
7061
                        id3_id                  <= n[4:0];
7062
                        id3_instr       <= iqentry_rtop[n] ? (
7063
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7064
`ifdef FU_BYPASS
7065
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7066
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7067
`endif
7068
                                        : `NOP_INSN)
7069
                                                                         : iqentry_instr[n];
7070
                        id3_ven    <= iqentry_ven[n];
7071
                        id3_vl     <= iqentry_vl[n];
7072
                        id3_thrd   <= iqentry_thrd[n];
7073
                        id3_Rt     <= iqentry_tgt[n][4:0];
7074
                        id3_pt                  <= iqentry_pt[n];
7075
                end
7076
        end
7077
end
7078 48 robfinch
 
7079
    for (n = 0; n < QENTRIES; n = n + 1)
7080
        if (iqentry_alu0_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7081
            if (alu0_available & alu0_done) begin
7082
                 alu0_sourceid  <= n[3:0];
7083
                 alu0_instr     <= iqentry_rtop[n] ? (
7084 49 robfinch
`ifdef FU_BYPASS
7085 48 robfinch
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7086 49 robfinch
                                                    : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7087
                                                    : (iqentry_a3_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7088
                                                    : alu1_bus)
7089
`else
7090
                                                                                                                                        iqentry_a3[n])
7091
`endif
7092 48 robfinch
                                                                         : iqentry_instr[n];
7093
                 alu0_bt                <= iqentry_bt[n];
7094
                 alu0_mem   <= iqentry_mem[n];
7095
                 alu0_shft48 <= iqentry_shft48[n];
7096
                 alu0_pc                <= iqentry_pc[n];
7097 49 robfinch
                 alu0_argA      <=
7098
`ifdef FU_BYPASS
7099
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7100
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7101
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7102
                            : alu1_bus;
7103
`else
7104
                                                                                                                iqentry_a1[n];
7105
`endif
7106 48 robfinch
                 alu0_argB      <= iqentry_imm[n]
7107
                            ? iqentry_a0[n]
7108 49 robfinch
`ifdef FU_BYPASS
7109 48 robfinch
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7110 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7111
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7112
                            : alu1_bus);
7113
`else
7114
                                                                                                                : iqentry_a2[n];
7115
`endif
7116
                 alu0_argC      <=
7117
`ifdef FU_BYPASS
7118
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7119 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7120 49 robfinch
`else
7121
                                                                                                                        iqentry_a3[n];
7122
`endif
7123 48 robfinch
                 alu0_argI      <= iqentry_a0[n];
7124
                 alu0_tgt    <= IsVeins(iqentry_instr[n]) ?
7125 49 robfinch
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((
7126
                                                                                        iqentry_a2_v[n] ? iqentry_a2[n][5:0]
7127 48 robfinch
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
7128
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
7129
                                            : {4{16'h0000}})) << 6 :
7130
                                iqentry_tgt[n];
7131
                 alu0_ven    <= iqentry_ven[n];
7132
                 alu0_thrd   <= iqentry_thrd[n];
7133
                 alu0_dataready <= IsSingleCycle(iqentry_instr[n]);
7134
                 alu0_ld <= TRUE;
7135
                 iqentry_out[n] <= `VAL;
7136
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
7137
                if (iqentry_mem[n]) begin
7138
                 iqentry_a1_v[n] <= `INV;
7139
                 iqentry_a1_s[n] <= n[3:0];
7140
                end
7141
            end
7142
        end
7143 49 robfinch
        if (`NUM_ALU > 1) begin
7144 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
7145
        if (iqentry_alu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7146
            if (alu1_available && alu1_done) begin
7147
                        if (iqentry_alu0[n])
7148
                                panic <= `PANIC_ALU0ONLY;
7149
                 alu1_sourceid  <= n[3:0];
7150
                 alu1_instr     <= iqentry_instr[n];
7151
                 alu1_bt                <= iqentry_bt[n];
7152
                 alu1_mem   <= iqentry_mem[n];
7153
                 alu1_shft48 <= iqentry_shft48[n];
7154
                 alu1_pc                <= iqentry_pc[n];
7155 49 robfinch
                 alu1_argA      <=
7156
`ifdef FU_BYPASS
7157
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7158
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7159
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7160
                            : alu1_bus;
7161
`else
7162
                                                                                                                        iqentry_a1[n];
7163
`endif
7164 48 robfinch
                 alu1_argB      <= iqentry_imm[n]
7165
                            ? iqentry_a0[n]
7166 49 robfinch
`ifdef FU_BYPASS
7167 48 robfinch
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7168 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7169
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7170
                            : alu1_bus);
7171
`else
7172
                                                                                                                : iqentry_a2[n];
7173
`endif
7174
                 alu1_argC      <=
7175
`ifdef FU_BYPASS
7176
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7177 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7178 49 robfinch
`else
7179
                                                                                                                        iqentry_a3[n];
7180
`endif
7181 48 robfinch
                 alu1_argI      <= iqentry_a0[n];
7182
                 alu1_tgt    <= IsVeins(iqentry_instr[n]) ?
7183
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((iqentry_a2_v[n] ? iqentry_a2[n][5:0]
7184
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
7185
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
7186
                                            : {4{16'h0000}})) << 6 :
7187
                                iqentry_tgt[n];
7188
                 alu1_ven    <= iqentry_ven[n];
7189
                 alu1_dataready <= IsSingleCycle(iqentry_instr[n]);
7190
                 alu1_ld <= TRUE;
7191
                 iqentry_out[n] <= `VAL;
7192
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
7193
                if (iqentry_mem[n]) begin
7194
                 iqentry_a1_v[n] <= `INV;
7195
                 iqentry_a1_s[n] <= n[3:0];
7196
                end
7197
            end
7198
        end
7199 49 robfinch
  end
7200 48 robfinch
 
7201
    for (n = 0; n < QENTRIES; n = n + 1)
7202 49 robfinch
        if (iqentry_fpu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7203
            if (fpu1_available & fpu1_done) begin
7204
                 fpu1_sourceid  <= n[3:0];
7205
                 fpu1_instr     <= iqentry_instr[n];
7206
                 fpu1_pc                <= iqentry_pc[n];
7207
                 fpu1_argA      <=
7208
`ifdef FU_BYPASS
7209
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7210
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7211
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7212
                            : alu1_bus;
7213
`else
7214
                                                                                                                        iqentry_a1[n];
7215
`endif
7216
                 fpu1_argB      <=
7217
`ifdef FU_BYPASS
7218
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
7219
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7220
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7221
                            : alu1_bus);
7222
`else
7223
                                                                                                                        iqentry_a2[n];
7224
`endif
7225
                 fpu1_argC      <=
7226
`ifdef FU_BYPASS
7227
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
7228 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7229 49 robfinch
`else
7230
                                                                                                                        iqentry_a3[n];
7231
`endif
7232
                 fpu1_argI      <= iqentry_a0[n];
7233
                 fpu1_dataready <= `VAL;
7234
                 fpu1_ld <= TRUE;
7235 48 robfinch
                 iqentry_out[n] <= `VAL;
7236
            end
7237
        end
7238
 
7239
    for (n = 0; n < QENTRIES; n = n + 1)
7240 49 robfinch
        if (`NUM_FPU > 1 && iqentry_fpu2_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7241
            if (fpu2_available & fpu2_done) begin
7242
                 fpu2_sourceid  <= n[3:0];
7243
                 fpu2_instr     <= iqentry_instr[n];
7244
                 fpu2_pc                <= iqentry_pc[n];
7245
                 fpu2_argA      <=
7246
`ifdef FU_BYPASS
7247
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7248
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7249
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7250
                            : alu1_bus;
7251
`else
7252
                                                                                                                        iqentry_a1[n];
7253
`endif
7254
                 fpu2_argB      <=
7255
`ifdef FU_BYPASS
7256
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
7257
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7258
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7259
                            : alu1_bus);
7260
`else
7261
                                                                                                                        iqentry_a2[n];
7262
`endif
7263
                 fpu2_argC      <=
7264
`ifdef FU_BYPASS
7265
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
7266
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7267
`else
7268
                                                                                                                        iqentry_a3[n];
7269
`endif
7270
                 fpu2_argI      <= iqentry_a0[n];
7271
                 fpu2_dataready <= `VAL;
7272
                 fpu2_ld <= TRUE;
7273
                 iqentry_out[n] <= `VAL;
7274
            end
7275
        end
7276
 
7277
    for (n = 0; n < QENTRIES; n = n + 1)
7278 48 robfinch
        if (iqentry_fcu_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7279
            if (fcu_done) begin
7280
                 fcu_sourceid   <= n[3:0];
7281
                 fcu_instr      <= iqentry_instr[n];
7282
                 fcu_insln  <= iqentry_insln[n];
7283
                 fcu_pc         <= iqentry_pc[n];
7284
                 fcu_nextpc <= iqentry_pc[n] + iqentry_insln[n];
7285
                 fcu_brdisp <= {{52{iqentry_instr[n][31]}},iqentry_instr[n][31:21],1'b0};
7286 51 robfinch
                 fcu_branch <= iqentry_br[n];
7287
                 fcu_call    <= IsCall(iqentry_instr[n])|iqentry_jal[n];
7288
                 fcu_jal     <= iqentry_jal[n];
7289
                 fcu_ret    <= iqentry_ret[n];
7290
                 fcu_brk  <= iqentry_brk[n];
7291
                 fcu_rti  <= iqentry_rti[n];
7292 48 robfinch
                 fcu_bt         <= iqentry_bt[n];
7293
                 fcu_pc         <= iqentry_pc[n];
7294
                 fcu_argA       <= iqentry_a1_v[n] ? iqentry_a1[n]
7295 49 robfinch
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7296
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7297
                            : alu1_bus;
7298 48 robfinch
`ifdef SUPPORT_SMT
7299 51 robfinch
                 fcu_argB       <= iqentry_rti[n] ? epc0[iqentry_thrd[n]]
7300 48 robfinch
`else
7301 51 robfinch
                 fcu_argB       <= iqentry_rti[n] ? epc0
7302 48 robfinch
`endif
7303
                                        : (iqentry_a2_v[n] ? iqentry_a2[n]
7304 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7305
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7306
                            : alu1_bus);
7307 48 robfinch
                 waitctr            <= iqentry_imm[n]
7308
                            ? iqentry_a0[n]
7309
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7310
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus : alu1_bus);
7311
                 fcu_argC       <= iqentry_a3_v[n] ? iqentry_a3[n]
7312
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7313
                 fcu_argI       <= iqentry_a0[n];
7314
                 fcu_thrd   <= iqentry_thrd[n];
7315
                 fcu_dataready <= `VAL;
7316
                 fcu_clearbm <= `FALSE;
7317
                 fcu_ld <= TRUE;
7318
                 fcu_timeout <= 8'h00;
7319
                 iqentry_out[n] <= `VAL;
7320
                 fcu_done <= `FALSE;
7321
            end
7322
        end
7323
//
7324
// MEMORY
7325
//
7326
// update the memory queues and put data out on bus if appropriate
7327
//
7328
 
7329
//
7330
// dram0, dram1, dram2 are the "state machines" that keep track
7331
// of three pipelined DRAM requests.  if any has the value "00", 
7332
// then it can accept a request (which bumps it up to the value "01"
7333
// at the end of the cycle).  once it hits the value "11" the request
7334
// is finished and the dram_bus takes the value.  if it is a store, the 
7335
// dram_bus value is not used, but the dram_v value along with the
7336
// dram_id value signals the waiting memq entry that the store is
7337
// completed and the instruction can commit.
7338
//
7339
 
7340
//      if (dram0 != `DRAMSLOT_AVAIL)   dram0 <= dram0 + 2'd1;
7341
//      if (dram1 != `DRAMSLOT_AVAIL)   dram1 <= dram1 + 2'd1;
7342
//      if (dram2 != `DRAMSLOT_AVAIL)   dram2 <= dram2 + 2'd1;
7343
 
7344
//
7345
// grab requests that have finished and put them on the dram_bus
7346 49 robfinch
if (mem1_available && dram0 == `DRAMREQ_READY) begin
7347 48 robfinch
        dram0 <= `DRAMSLOT_AVAIL;
7348
        dramA_v <= dram0_load;
7349
        dramA_id <= dram0_id;
7350
        dramA_exc <= dram0_exc;
7351
        dramA_bus <= fnDati(dram0_instr,dram0_addr,rdat0);
7352 50 robfinch
        if (dram0_store)        $display("m[%h] <- %h", dram0_addr, dram0_data);
7353 48 robfinch
end
7354
//    else
7355
//      dramA_v <= `INV;
7356 49 robfinch
if (mem2_available && dram1 == `DRAMREQ_READY && `NUM_MEM > 1) begin
7357 48 robfinch
        dram1 <= `DRAMSLOT_AVAIL;
7358
        dramB_v <= dram1_load;
7359
        dramB_id <= dram1_id;
7360
        dramB_exc <= dram1_exc;
7361
        dramB_bus <= fnDati(dram1_instr,dram1_addr,rdat1);
7362 50 robfinch
        if (dram1_store)     $display("m[%h] <- %h", dram1_addr, dram1_data);
7363 48 robfinch
end
7364
//    else
7365
//      dramB_v <= `INV;
7366 49 robfinch
if (mem3_available && dram2 == `DRAMREQ_READY && `NUM_MEM > 2) begin
7367 48 robfinch
        dram2 <= `DRAMSLOT_AVAIL;
7368
        dramC_v <= dram2_load;
7369
        dramC_id <= dram2_id;
7370
        dramC_exc <= dram2_exc;
7371
        dramC_bus <= fnDati(dram2_instr,dram2_addr,rdat2);
7372 50 robfinch
        if (dram2_store)     $display("m[%h] <- %h", dram2_addr, dram2_data);
7373 48 robfinch
end
7374
//    else
7375
//      dramC_v <= `INV;
7376
 
7377
        //
7378
        // determine if the instructions ready to issue can, in fact, issue.
7379
        // "ready" means that the instruction has valid operands but has not gone yet
7380
        iqentry_memissue <= memissue;
7381
        missue_count <= issue_count;
7382
 
7383
 
7384
        //
7385
        // take requests that are ready and put them into DRAM slots
7386
 
7387
        if (dram0 == `DRAMSLOT_AVAIL)    dram0_exc <= `FLT_NONE;
7388
        if (dram1 == `DRAMSLOT_AVAIL)    dram1_exc <= `FLT_NONE;
7389
        if (dram2 == `DRAMSLOT_AVAIL)    dram2_exc <= `FLT_NONE;
7390
 
7391
        for (n = 0; n < QENTRIES; n = n + 1)
7392
                if (iqentry_v[n] && iqentry_stomp[n]) begin
7393
                        iqentry_v[n] <= `INV;
7394
                        iqentry_iv[n] <= `INV;
7395
                        if (dram0_id[`QBITS] == n[`QBITS])  dram0 <= `DRAMSLOT_AVAIL;
7396
                        if (dram1_id[`QBITS] == n[`QBITS])  dram1 <= `DRAMSLOT_AVAIL;
7397
                        if (dram2_id[`QBITS] == n[`QBITS])  dram2 <= `DRAMSLOT_AVAIL;
7398
                end
7399
 
7400
        last_issue = 8;
7401
    for (n = 0; n < QENTRIES; n = n + 1)
7402 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7403
            if (mem1_available && dram0 == `DRAMSLOT_AVAIL) begin
7404 48 robfinch
                dramA_v <= `INV;
7405
             dram0              <= `DRAMSLOT_BUSY;
7406
             dram0_id   <= { 1'b1, n[`QBITS] };
7407
             dram0_instr <= iqentry_instr[n];
7408
             dram0_rmw  <= iqentry_rmw[n];
7409
             dram0_preload <= iqentry_preload[n];
7410
             dram0_tgt  <= iqentry_tgt[n];
7411
             dram0_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7412
             dram0_addr <= iqentry_a1[n];
7413
//             if (ol[iqentry_thrd[n]]==`OL_USER)
7414
//              dram0_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7415
//             else
7416 50 robfinch
             dram0_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7417
             dram0_memsize <= iqentry_memsz[n];
7418 48 robfinch
             dram0_load <= iqentry_load[n];
7419 50 robfinch
             dram0_store <= iqentry_store[n];
7420 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]];
7421
             // Once the memory op is issued reset the a1_v flag.
7422
             // This will cause the a1 bus to look for new data from memory (a1_s is pointed to a memory bus)
7423
             // This is used for the load and compare instructions.
7424
             iqentry_a1_v[n] <= `INV;
7425
             last_issue = n;
7426
            end
7427
        end
7428
    if (last_issue < 8)
7429
        iqentry_out[last_issue] <= `VAL;
7430
    for (n = 0; n < QENTRIES; n = n + 1)
7431 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7432
                if (mem2_available && n < last_issue && `NUM_MEM > 1) begin
7433 48 robfinch
                    if (dram1 == `DRAMSLOT_AVAIL) begin
7434
                        dramB_v <= `INV;
7435
                     dram1              <= `DRAMSLOT_BUSY;
7436
                     dram1_id   <= { 1'b1, n[`QBITS] };
7437
                     dram1_instr <= iqentry_instr[n];
7438
                     dram1_rmw  <= iqentry_rmw[n];
7439
                     dram1_preload <= iqentry_preload[n];
7440
                     dram1_tgt  <= iqentry_tgt[n];
7441
                     dram1_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7442
                     dram1_addr <= iqentry_a1[n];
7443
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
7444
//                      dram1_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7445
//                   else
7446 50 robfinch
                     dram1_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7447
                     dram1_memsize <= iqentry_memsz[n];
7448 48 robfinch
                     dram1_load <= iqentry_load[n];
7449 50 robfinch
                     dram1_store <= iqentry_store[n];
7450 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]];
7451
                     iqentry_a1_v[n] <= `INV;
7452
                     last_issue = n;
7453
                    end
7454
                end
7455
        end
7456
    if (last_issue < 8)
7457
        iqentry_out[last_issue] <= `VAL;
7458
    for (n = 0; n < QENTRIES; n = n + 1)
7459 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7460
                if (mem3_available && n < last_issue && `NUM_MEM > 2) begin
7461 48 robfinch
                    if (dram2 == `DRAMSLOT_AVAIL) begin
7462
                        dramC_v <= `INV;
7463
                     dram2              <= `DRAMSLOT_BUSY;
7464
                     dram2_id   <= { 1'b1, n[`QBITS] };
7465
                     dram2_instr        <= iqentry_instr[n];
7466
                     dram2_rmw  <= iqentry_rmw[n];
7467
                     dram2_preload <= iqentry_preload[n];
7468
                     dram2_tgt  <= iqentry_tgt[n];
7469
                     dram2_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7470
                     dram2_addr <= iqentry_a1[n];
7471
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
7472
//                      dram2_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7473
//                   else
7474 50 robfinch
                     dram2_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7475
                     dram2_memsize <= iqentry_memsz[n];
7476 48 robfinch
                     dram2_load <= iqentry_load[n];
7477 50 robfinch
                     dram2_store <= iqentry_store[n];
7478 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]];
7479
                     iqentry_a1_v[n] <= `INV;
7480
                    end
7481
                end
7482
        end
7483
    if (last_issue < 8)
7484
        iqentry_out[last_issue] <= `VAL;
7485
 
7486 51 robfinch
for (n = 0; n < QENTRIES; n = n + 1)
7487
begin
7488
        if (!iqentry_v[n])
7489
                iqentry_done[n] <= FALSE;
7490
end
7491 48 robfinch
 
7492
 
7493
 
7494 49 robfinch
//
7495
// COMMIT PHASE (dequeue only ... not register-file update)
7496
//
7497
// look at head0 and head1 and let 'em write to the register file if they are ready
7498
//
7499 48 robfinch
//    always @(posedge clk) begin: commit_phase
7500
 
7501 49 robfinch
oddball_commit(commit0_v, head0);
7502
if (`NUM_CMT > 1)
7503
        oddball_commit(commit1_v, head1);
7504 50 robfinch
//if (`NUM_CMT > 2)
7505
//      oddball_commit(commit2_v, head2);
7506 48 robfinch
 
7507
// Fetch and queue are limited to two instructions per cycle, so we might as
7508
// well limit retiring to two instructions max to conserve logic.
7509
//
7510
if (~|panic)
7511 49 robfinch
  casez ({ iqentry_v[head0],
7512
                iqentry_cmt[head0],
7513
                iqentry_v[head1],
7514
                iqentry_cmt[head1],
7515
                iqentry_v[head2],
7516
                iqentry_cmt[head2]})
7517 48 robfinch
 
7518
        // retire 3
7519 49 robfinch
        6'b0?_0?_0?:
7520
                if (head0 != tail0 && head1 != tail0 && head2 != tail0) begin
7521
                                head_inc(3);
7522
                end
7523
                else if (head0 != tail0 && head1 != tail0) begin
7524 48 robfinch
                    head_inc(2);
7525
                end
7526
                else if (head0 != tail0) begin
7527
                    head_inc(1);
7528
                end
7529 49 robfinch
        6'b0?_0?_10:    ;
7530
        6'b0?_0?_11:
7531
                if (`NUM_CMT > 2 || iqentry_tgt[head2][4:0]==5'd0) begin
7532
      iqentry_v[head2] <= `INV;
7533
      head_inc(3);
7534
                end
7535
                else begin
7536
      head_inc(2);
7537
                end
7538 48 robfinch
 
7539
        // retire 1 (wait for regfile for head1)
7540 49 robfinch
        6'b0?_10_??:
7541
                head_inc(1);
7542 48 robfinch
 
7543
        // retire 2
7544 49 robfinch
        6'b0?_11_0?,
7545
        6'b0?_11_10:
7546
        if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7547
          iqentry_v[head1] <= `INV;
7548
          head_inc(2);
7549 48 robfinch
        end
7550 49 robfinch
        else begin
7551
                head_inc(1);
7552
        end
7553
  6'b0?_11_11:
7554 50 robfinch
        if (`NUM_CMT > 2 || (`NUM_CMT > 1 && iqentry_tgt[head2] == 12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7555 49 robfinch
                iqentry_v[head1] <= `INV;
7556
          iqentry_v[head2] <= `INV;
7557
                head_inc(3);
7558
        end
7559
        else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7560
                iqentry_v[head1] <= `INV;
7561
                head_inc(2);
7562
        end
7563
        else
7564
                head_inc(1);
7565
  6'b10_??_??:  ;
7566
  6'b11_0?_0?:
7567
        if (head1 != tail0 && head2 != tail0) begin
7568 48 robfinch
                        iqentry_v[head0] <= `INV;
7569 49 robfinch
                        head_inc(3);
7570
        end
7571
        else if (head1 != tail0) begin
7572
                        iqentry_v[head0] <= `INV;
7573 48 robfinch
                        head_inc(2);
7574 49 robfinch
        end
7575
        else begin
7576 48 robfinch
                        iqentry_v[head0] <= `INV;
7577
                        head_inc(1);
7578 49 robfinch
        end
7579
  6'b11_0?_10:
7580
        if (head1 != tail0) begin
7581
                        iqentry_v[head0] <= `INV;
7582
                        head_inc(2);
7583
        end
7584
        else begin
7585
                        iqentry_v[head0] <= `INV;
7586
                        head_inc(1);
7587
        end
7588
  6'b11_0?_11:
7589
        if (head1 != tail0) begin
7590 50 robfinch
                if (`NUM_CMT > 2 || (iqentry_tgt[head2]==12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7591 49 robfinch
                                iqentry_v[head0] <= `INV;
7592
                                iqentry_v[head2] <= `INV;
7593
                                head_inc(3);
7594
                end
7595
                else begin
7596
                                iqentry_v[head0] <= `INV;
7597
                                head_inc(2);
7598
                        end
7599
        end
7600
        else begin
7601
                        iqentry_v[head0] <= `INV;
7602
                        head_inc(1);
7603
        end
7604
  6'b11_10_??:
7605
        begin
7606
                        iqentry_v[head0] <= `INV;
7607
                        head_inc(1);
7608
        end
7609
  6'b11_11_0?:
7610
        if (`NUM_CMT > 1 && head2 != tail0) begin
7611
                        iqentry_v[head0] <= `INV;
7612
                        iqentry_v[head1] <= `INV;
7613
                        head_inc(3);
7614
        end
7615
        else if (iqentry_tgt[head1]== 12'd0 && head2 != tail0) begin
7616
                        iqentry_v[head0] <= `INV;
7617
                        iqentry_v[head1] <= `INV;
7618
                        head_inc(3);
7619
        end
7620
        else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7621
                        iqentry_v[head0] <= `INV;
7622
                        iqentry_v[head1] <= `INV;
7623
                        head_inc(2);
7624
        end
7625
        else begin
7626
                        iqentry_v[head0] <= `INV;
7627
                        head_inc(1);
7628
        end
7629
  6'b11_11_10:
7630
        if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7631
                        iqentry_v[head0] <= `INV;
7632
                        iqentry_v[head1] <= `INV;
7633
                        head_inc(2);
7634
        end
7635
        else begin
7636
                        iqentry_v[head0] <= `INV;
7637
                        head_inc(1);
7638
        end
7639
        6'b11_11_11:
7640 50 robfinch
                if (`NUM_CMT > 2 || (`NUM_CMT > 1 && iqentry_tgt[head2]==12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7641 49 robfinch
                        iqentry_v[head0] <= `INV;
7642
                        iqentry_v[head1] <= `INV;
7643
                        iqentry_v[head2] <= `INV;
7644
                        head_inc(3);
7645 48 robfinch
                end
7646 49 robfinch
                else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7647 48 robfinch
                        iqentry_v[head0] <= `INV;
7648 49 robfinch
                        iqentry_v[head1] <= `INV;
7649
                        head_inc(2);
7650
                end
7651
                else begin
7652
                        iqentry_v[head0] <= `INV;
7653 48 robfinch
                        head_inc(1);
7654
                end
7655 49 robfinch
  endcase
7656 48 robfinch
 
7657
 
7658
        rf_source[0] <= 0;
7659
        L1_wr0 <= FALSE;
7660
        L1_wr1 <= FALSE;
7661
        L1_invline <= FALSE;
7662
        icnxt <= FALSE;
7663
        L2_nxt <= FALSE;
7664
// Instruction cache state machine.
7665
// On a miss first see if the instruction is in the L2 cache. No need to go to
7666
// the BIU on an L1 miss.
7667
// If not the machine will wait until the BIU loads the L2 cache.
7668
 
7669
// Capture the previous ic state, used to determine how long to wait in
7670
// icstate #4.
7671
        picstate <= icstate;
7672
case(icstate)
7673
IDLE:
7674
        // If the bus unit is busy doing an update involving L1_adr or L2_adr
7675
        // we have to wait.
7676
        if (bstate != B7 && bstate != B9) begin
7677
                if (!ihit0) begin
7678
                        L1_adr <= {pcr[5:0],pc0[31:3],3'h0};
7679
                        L2_adr <= {pcr[5:0],pc0[31:3],3'h0};
7680
                        L1_invline <= TRUE;
7681 49 robfinch
                        icwhich <= 2'b00;
7682 48 robfinch
                        iccnt <= 3'b00;
7683
                        icstate <= IC2;
7684
                end
7685 49 robfinch
                else if (!ihit1 && `WAYS > 1) begin
7686 48 robfinch
`ifdef SUPPORT_SMT
7687
                        L1_adr <= {pcr[5:0],pc1[31:3],3'h0};
7688
                        L2_adr <= {pcr[5:0],pc1[31:3],3'h0};
7689
`else
7690
                        L1_adr <= {pcr[5:0],pc0plus6[31:3],3'h0};
7691
                        L2_adr <= {pcr[5:0],pc0plus6[31:3],3'h0};
7692
`endif
7693
                        L1_invline <= TRUE;
7694 49 robfinch
                        icwhich <= 2'b01;
7695 48 robfinch
                        iccnt <= 3'b00;
7696
                        icstate <= IC2;
7697
                end
7698 49 robfinch
                else if (!ihit2 && `WAYS > 2) begin
7699
`ifdef SUPPORT_SMT
7700
                        L1_adr <= {pcr[5:0],pc2[31:3],3'h0};
7701
                        L2_adr <= {pcr[5:0],pc2[31:3],3'h0};
7702
`else
7703
                        L1_adr <= {pcr[5:0],pc0plus12[31:3],3'h0};
7704
                        L2_adr <= {pcr[5:0],pc0plus12[31:3],3'h0};
7705
`endif
7706
                        L1_invline <= TRUE;
7707
                        icwhich <= 2'b10;
7708
                        iccnt <= 3'b00;
7709
                        icstate <= IC2;
7710
                end
7711 48 robfinch
        end
7712
IC2:     icstate <= IC3;
7713
IC3:     icstate <= IC3a;
7714
IC3a:     icstate <= IC4;
7715
        // If data was in the L2 cache already there's no need to wait on the
7716
        // BIU to retrieve data. It can be determined if the hit signal was
7717
        // already active when this state was entered in which case waiting
7718
        // will do no good.
7719
        // The IC machine will stall in this state until the BIU has loaded the
7720
        // L2 cache. 
7721
IC4:
7722 49 robfinch
        if (ihitL2 && picstate==IC3a) begin
7723
                L1_en <= 9'h1FF;
7724 48 robfinch
                L1_wr0 <= TRUE;
7725 49 robfinch
                L1_wr1 <= TRUE && `WAYS > 1;
7726
                L1_wr2 <= TRUE && `WAYS > 2;
7727 48 robfinch
                L1_adr <= L2_adr;
7728
                L2_rdat <= L2_dato;
7729
                icstate <= IC5;
7730
        end
7731
        else if (bstate!=B9)
7732
                ;
7733
        else begin
7734 49 robfinch
                L1_en <= 9'h1FF;
7735 48 robfinch
                L1_wr0 <= TRUE;
7736 49 robfinch
                L1_wr1 <= TRUE && `WAYS > 1;
7737
                L1_wr2 <= TRUE && `WAYS > 2;
7738 48 robfinch
                L1_adr <= L2_adr;
7739
                L2_rdat <= L2_dato;
7740
                icstate <= IC5;
7741
        end
7742
IC5:
7743
        begin
7744 49 robfinch
                L1_en <= 9'h000;
7745 48 robfinch
                L1_wr0 <= FALSE;
7746
                L1_wr1 <= FALSE;
7747 49 robfinch
                L1_wr2 <= FALSE;
7748 48 robfinch
                icstate <= IC6;
7749
        end
7750
IC6:  icstate <= IC7;
7751
IC7:    icstate <= IC8;
7752
IC8:    begin
7753
             icstate <= IDLE;
7754
             icnxt <= TRUE;
7755
        end
7756
default:     icstate <= IDLE;
7757
endcase
7758
 
7759 49 robfinch
if (mem1_available && dram0_load)
7760 48 robfinch
case(dram0)
7761
`DRAMSLOT_AVAIL:        ;
7762
`DRAMSLOT_BUSY:         dram0 <= dram0 + !dram0_unc;
7763
3'd2:                           dram0 <= dram0 + 3'd1;
7764
3'd3:                           dram0 <= dram0 + 3'd1;
7765
3'd4:                           if (dhit0) dram0 <= `DRAMREQ_READY; else dram0 <= `DRAMSLOT_REQBUS;
7766
`DRAMSLOT_REQBUS:       ;
7767
`DRAMSLOT_HASBUS:       ;
7768
`DRAMREQ_READY:         ;
7769
endcase
7770
 
7771 49 robfinch
if (mem2_available && dram1_load && `NUM_MEM > 1)
7772 48 robfinch
case(dram1)
7773
`DRAMSLOT_AVAIL:        ;
7774
`DRAMSLOT_BUSY:         dram1 <= dram1 + !dram1_unc;
7775
3'd2:                           dram1 <= dram1 + 3'd1;
7776
3'd3:                           dram1 <= dram1 + 3'd1;
7777
3'd4:                           if (dhit1) dram1 <= `DRAMREQ_READY; else dram1 <= `DRAMSLOT_REQBUS;
7778
`DRAMSLOT_REQBUS:       ;
7779
`DRAMSLOT_HASBUS:       ;
7780
`DRAMREQ_READY:         ;
7781
endcase
7782
 
7783 49 robfinch
if (mem3_available && dram2_load && `NUM_MEM > 2)
7784 48 robfinch
case(dram2)
7785
`DRAMSLOT_AVAIL:        ;
7786
`DRAMSLOT_BUSY:         dram2 <= dram2 + !dram2_unc;
7787
3'd2:                           dram2 <= dram2 + 3'd1;
7788
3'd3:                           dram2 <= dram2 + 3'd1;
7789
3'd4:                           if (dhit2) dram2 <= `DRAMREQ_READY; else dram2 <= `DRAMSLOT_REQBUS;
7790
`DRAMSLOT_REQBUS:       ;
7791
`DRAMSLOT_HASBUS:       ;
7792
`DRAMREQ_READY:         ;
7793
endcase
7794
 
7795
// Bus Interface Unit (BIU)
7796
// Interfaces to the external bus which is WISHBONE compatible.
7797
// Stores take precedence over other operations.
7798
// Next data cache read misses are serviced.
7799
// Uncached data reads are serviced.
7800
// Finally L2 instruction cache misses are serviced.
7801
 
7802
case(bstate)
7803
BIDLE:
7804 49 robfinch
        begin
7805
                isCAS <= FALSE;
7806
                isAMO <= FALSE;
7807
                isInc <= FALSE;
7808
                isSpt <= FALSE;
7809
                isRMW <= FALSE;
7810
                rdvq <= 1'b0;
7811
                errq <= 1'b0;
7812
                exvq <= 1'b0;
7813
                bwhich <= 2'b00;
7814
                preload <= FALSE;
7815
`ifdef HAS_WB
7816
                if (wb_v[0] & wb_en) begin
7817
                        cyc_o <= `HIGH;
7818
                        stb_o <= `HIGH;
7819
                        we_o <= `HIGH;
7820
                        sel_o <= wb_sel[0];
7821
                        adr_o <= wb_addr[0];
7822
                        dat_o <= wb_data[0];
7823
                        ol_o  <= wb_ol[0];
7824
                        wbo_id <= wb_id[0];
7825
                        bstate <= wb_rmw[0] ? B12 : B1;
7826
                end
7827
                begin
7828
                        for (j = 1; j < `WB_DEPTH; j = j + 1) begin
7829
                wb_v[j-1] <= wb_v[j];
7830
                wb_id[j-1] <= wb_id[j];
7831
                wb_rmw[j-1] <= wb_rmw[j];
7832
                wb_sel[j-1] <= wb_sel[j];
7833
                wb_addr[j-1] <= wb_addr[j];
7834
                wb_data[j-1] <= wb_data[j];
7835
                wb_ol[j-1] <= wb_ol[j];
7836
        end
7837
        wb_v[`WB_DEPTH-1] <= `INV;
7838
        wb_rmw[`WB_DEPTH-1] <= `FALSE;
7839
    end
7840
 
7841
`endif
7842
      if (~|wb_v && mem1_available && dram0==`DRAMSLOT_BUSY && dram0_rmw) begin
7843 48 robfinch
`ifdef SUPPORT_DBG
7844
            if (dbg_smatch0|dbg_lmatch0) begin
7845
                 dramA_v <= `TRUE;
7846
                 dramA_id <= dram0_id;
7847
                 dramA_exc <= `FLT_DBG;
7848
                 dramA_bus <= 64'h0;
7849
                 dram0 <= `DRAMSLOT_AVAIL;
7850
            end
7851
            else
7852
`endif
7853
            begin
7854
                 isRMW <= dram0_rmw;
7855
                 isCAS <= IsCAS(dram0_instr);
7856
                 isAMO <= IsAMO(dram0_instr);
7857
                 isInc <= IsInc(dram0_instr);
7858
                 casid <= dram0_id;
7859
                 bwhich <= 2'b00;
7860 49 robfinch
                 dram0 <= `DRAMSLOT_HASBUS;
7861 48 robfinch
                 cyc_o <= `HIGH;
7862
                 stb_o <= `HIGH;
7863
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7864
                 adr_o <= dram0_addr;
7865
                 dat_o <= fnDato(dram0_instr,dram0_data);
7866
                 ol_o  <= dram0_ol;
7867
                 bstate <= B12;
7868
            end
7869
        end
7870 49 robfinch
        else if (~|wb_v && mem2_available && dram1==`DRAMSLOT_BUSY && dram1_rmw && `NUM_MEM > 1) begin
7871 48 robfinch
`ifdef SUPPORT_DBG
7872
            if (dbg_smatch1|dbg_lmatch1) begin
7873
                 dramB_v <= `TRUE;
7874
                 dramB_id <= dram1_id;
7875
                 dramB_exc <= `FLT_DBG;
7876
                 dramB_bus <= 64'h0;
7877
                 dram1 <= `DRAMSLOT_AVAIL;
7878
            end
7879
            else
7880
`endif
7881
            begin
7882
                 isRMW <= dram1_rmw;
7883
                 isCAS <= IsCAS(dram1_instr);
7884
                 isAMO <= IsAMO(dram1_instr);
7885
                 isInc <= IsInc(dram1_instr);
7886
                 casid <= dram1_id;
7887
                 bwhich <= 2'b01;
7888 49 robfinch
                 dram1 <= `DRAMSLOT_HASBUS;
7889 48 robfinch
                 cyc_o <= `HIGH;
7890
                 stb_o <= `HIGH;
7891
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7892
                 adr_o <= dram1_addr;
7893
                 dat_o <= fnDato(dram1_instr,dram1_data);
7894
                 ol_o  <= dram1_ol;
7895
                 bstate <= B12;
7896
            end
7897
        end
7898 49 robfinch
        else if (~|wb_v && mem3_available && dram2==`DRAMSLOT_BUSY && dram2_rmw && `NUM_MEM > 2) begin
7899 48 robfinch
`ifdef SUPPORT_DBG
7900
            if (dbg_smatch2|dbg_lmatch2) begin
7901
                 dramC_v <= `TRUE;
7902
                 dramC_id <= dram2_id;
7903
                 dramC_exc <= `FLT_DBG;
7904
                 dramC_bus <= 64'h0;
7905
                 dram2 <= `DRAMSLOT_AVAIL;
7906
            end
7907
            else
7908
`endif
7909
            begin
7910
                 isRMW <= dram2_rmw;
7911
                 isCAS <= IsCAS(dram2_instr);
7912
                 isAMO <= IsAMO(dram2_instr);
7913
                 isInc <= IsInc(dram2_instr);
7914
                 casid <= dram2_id;
7915
                 bwhich <= 2'b10;
7916 49 robfinch
                 dram2 <= `DRAMSLOT_HASBUS;
7917 48 robfinch
                 cyc_o <= `HIGH;
7918
                 stb_o <= `HIGH;
7919
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
7920
                 adr_o <= dram2_addr;
7921
                 dat_o <= fnDato(dram2_instr,dram2_data);
7922
                 ol_o  <= dram2_ol;
7923
                 bstate <= B12;
7924
            end
7925
        end
7926 50 robfinch
        else if (mem1_available && dram0==`DRAMSLOT_BUSY && dram0_store) begin
7927 48 robfinch
`ifdef SUPPORT_DBG
7928
            if (dbg_smatch0) begin
7929
                 dramA_v <= `TRUE;
7930
                 dramA_id <= dram0_id;
7931
                 dramA_exc <= `FLT_DBG;
7932
                 dramA_bus <= 64'h0;
7933
                 dram0 <= `DRAMSLOT_AVAIL;
7934
            end
7935
            else
7936
`endif
7937
            begin
7938 49 robfinch
                                                        bwhich <= 2'b00;
7939
`ifndef HAS_WB
7940
                                                        dram0 <= `DRAMSLOT_HASBUS;
7941
                                                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
7942
                 cyc_o <= `HIGH;
7943
                 stb_o <= `HIGH;
7944 48 robfinch
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7945
                 adr_o <= dram0_addr;
7946
                 dat_o <= fnDato(dram0_instr,dram0_data);
7947
                 ol_o  <= dram0_ol;
7948
                 bstate <= B1;
7949 49 robfinch
`else
7950
                                                                if (wbptr<`WB_DEPTH-1) begin
7951
                                                                        dram0 <= `DRAMREQ_READY;
7952
                                                                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
7953
                                                                        wb_update(
7954
                                                                                dram0_id,
7955
                                                                                `FALSE,
7956
                                                                                fnSelect(dram0_instr,dram0_addr),
7957
                                                                                dram0_ol,
7958
                                                                                dram0_addr,
7959
                                                                                fnDato(dram0_instr,dram0_data)
7960
                                                                        );
7961
                                                                        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
7962
                                                                        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
7963
                                                                end
7964
`endif
7965
//                 cr_o <= IsSWC(dram0_instr);
7966 48 robfinch
            end
7967
        end
7968 50 robfinch
        else if (mem2_available && dram1==`DRAMSLOT_BUSY && dram1_store && `NUM_MEM > 1) begin
7969 48 robfinch
`ifdef SUPPORT_DBG
7970
            if (dbg_smatch1) begin
7971
                 dramB_v <= `TRUE;
7972
                 dramB_id <= dram1_id;
7973
                 dramB_exc <= `FLT_DBG;
7974
                 dramB_bus <= 64'h0;
7975
                 dram1 <= `DRAMSLOT_AVAIL;
7976
            end
7977
            else
7978
`endif
7979
            begin
7980 49 robfinch
                 bwhich <= 2'b01;
7981
`ifndef HAS_WB
7982 48 robfinch
                 dram1 <= `DRAMSLOT_HASBUS;
7983
                 dram1_instr[`INSTRUCTION_OP] <= `NOP;
7984 49 robfinch
                 cyc_o <= `HIGH;
7985
                 stb_o <= `HIGH;
7986 48 robfinch
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7987
                 adr_o <= dram1_addr;
7988
                 dat_o <= fnDato(dram1_instr,dram1_data);
7989
                 ol_o  <= dram1_ol;
7990
                 bstate <= B1;
7991 49 robfinch
`else
7992
                                                                if (wbptr<`WB_DEPTH-1) begin
7993
                                                                        dram1 <= `DRAMREQ_READY;
7994
                        dram1_instr[`INSTRUCTION_OP] <= `NOP;
7995
                                                                        wb_update(
7996
                                                                                dram1_id,
7997
                                                                                `FALSE,
7998
                                                                                fnSelect(dram1_instr,dram1_addr),
7999
                                                                                dram1_ol,
8000
                                                                                dram1_addr,
8001
                                                                                fnDato(dram1_instr,dram1_data)
8002
                                                                        );
8003
                                                                        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
8004
                                                                        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
8005
                                                                end
8006
`endif
8007
//                 cr_o <= IsSWC(dram0_instr);
8008 48 robfinch
            end
8009
        end
8010 50 robfinch
        else if (mem3_available && dram2==`DRAMSLOT_BUSY && dram2_store && `NUM_MEM > 2) begin
8011 48 robfinch
`ifdef SUPPORT_DBG
8012
            if (dbg_smatch2) begin
8013
                 dramC_v <= `TRUE;
8014
                 dramC_id <= dram2_id;
8015
                 dramC_exc <= `FLT_DBG;
8016
                 dramC_bus <= 64'h0;
8017
                 dram2 <= `DRAMSLOT_AVAIL;
8018
            end
8019
            else
8020
`endif
8021
            begin
8022 49 robfinch
                 bwhich <= 2'b10;
8023
`ifndef HAS_WB
8024 48 robfinch
                 dram2 <= `DRAMSLOT_HASBUS;
8025
                 dram2_instr[`INSTRUCTION_OP] <= `NOP;
8026 49 robfinch
                 cyc_o <= `HIGH;
8027
                 stb_o <= `HIGH;
8028 48 robfinch
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
8029
                 adr_o <= dram2_addr;
8030
                 dat_o <= fnDato(dram2_instr,dram2_data);
8031
                 ol_o  <= dram2_ol;
8032
                 bstate <= B1;
8033 49 robfinch
`else
8034
                                                                if (wbptr<`WB_DEPTH-1) begin
8035
                                                                        dram2 <= `DRAMREQ_READY;
8036
                        dram2_instr[`INSTRUCTION_OP] <= `NOP;
8037
                                                                        wb_update(
8038
                                                                                dram2_id,
8039
                                                                                `FALSE,
8040
                                                                                fnSelect(dram2_instr,dram2_addr),
8041
                                                                                dram2_ol,
8042
                                                                                dram2_addr,
8043
                                                                                fnDato(dram2_instr,dram2_data)
8044
                                                                        );
8045
                                                                        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
8046
                                                                        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
8047
                                                                end
8048
`endif
8049
//                 cr_o <= IsSWC(dram0_instr);
8050 48 robfinch
            end
8051
        end
8052
        // Check for read misses on the data cache
8053 51 robfinch
        else if (~|wb_v && mem1_available && !dram0_unc && dram0==`DRAMSLOT_REQBUS && dram0_load) begin
8054 48 robfinch
`ifdef SUPPORT_DBG
8055
            if (dbg_lmatch0) begin
8056
                 dramA_v <= `TRUE;
8057
                 dramA_id <= dram0_id;
8058
                 dramA_exc <= `FLT_DBG;
8059
                 dramA_bus <= 64'h0;
8060
                 dram0 <= `DRAMSLOT_AVAIL;
8061
            end
8062
            else
8063
`endif
8064
            begin
8065
                 dram0 <= `DRAMSLOT_HASBUS;
8066
                 bwhich <= 2'b00;
8067
                 preload <= dram0_preload;
8068
                 bstate <= B2;
8069
            end
8070
        end
8071 49 robfinch
        else if (~|wb_v && mem2_available && !dram1_unc && dram1==`DRAMSLOT_REQBUS && dram1_load && `NUM_MEM > 1) begin
8072 48 robfinch
`ifdef SUPPORT_DBG
8073
            if (dbg_lmatch1) begin
8074
                 dramB_v <= `TRUE;
8075
                 dramB_id <= dram1_id;
8076
                 dramB_exc <= `FLT_DBG;
8077
                 dramB_bus <= 64'h0;
8078
                 dram1 <= `DRAMSLOT_AVAIL;
8079
            end
8080
            else
8081
`endif
8082
            begin
8083
                 dram1 <= `DRAMSLOT_HASBUS;
8084
                 bwhich <= 2'b01;
8085
                 preload <= dram1_preload;
8086
                 bstate <= B2;
8087
            end
8088
        end
8089 49 robfinch
        else if (~|wb_v && mem3_available && !dram2_unc && dram2==`DRAMSLOT_REQBUS && dram2_load && `NUM_MEM > 2) begin
8090 48 robfinch
`ifdef SUPPORT_DBG
8091
            if (dbg_lmatch2) begin
8092
                 dramC_v <= `TRUE;
8093
                 dramC_id <= dram2_id;
8094
                 dramC_exc <= `FLT_DBG;
8095
                 dramC_bus <= 64'h0;
8096
                 dram2 <= `DRAMSLOT_AVAIL;
8097
            end
8098
            else
8099
`endif
8100
            begin
8101
                 dram2 <= `DRAMSLOT_HASBUS;
8102
                 preload <= dram2_preload;
8103
                 bwhich <= 2'b10;
8104
                 bstate <= B2;
8105
            end
8106
        end
8107 49 robfinch
        else if (~|wb_v && mem1_available && dram0_unc && dram0==`DRAMSLOT_BUSY && dram0_load) begin
8108 48 robfinch
`ifdef SUPPORT_DBG
8109
            if (dbg_lmatch0) begin
8110
                 dramA_v <= `TRUE;
8111
                 dramA_id <= dram0_id;
8112
                 dramA_exc <= `FLT_DBG;
8113
                 dramA_bus <= 64'h0;
8114
                 dram0 <= `DRAMSLOT_AVAIL;
8115
            end
8116
            else
8117
`endif
8118
            begin
8119
                 bwhich <= 2'b00;
8120
                 cyc_o <= `HIGH;
8121
                 stb_o <= `HIGH;
8122
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
8123
                 adr_o <= {dram0_addr[31:3],3'b0};
8124
                 sr_o <=  IsLWR(dram0_instr);
8125
                 ol_o  <= dram0_ol;
8126
                 bstate <= B12;
8127
            end
8128
        end
8129 49 robfinch
        else if (~|wb_v && mem2_available && dram1_unc && dram1==`DRAMSLOT_BUSY && dram1_load && `NUM_MEM > 1) begin
8130 48 robfinch
`ifdef SUPPORT_DBG
8131
            if (dbg_lmatch1) begin
8132
                 dramB_v <= `TRUE;
8133
                 dramB_id <= dram1_id;
8134
                 dramB_exc <= `FLT_DBG;
8135
                 dramB_bus <= 64'h0;
8136
                 dram1 <= `DRAMSLOT_AVAIL;
8137
            end
8138
            else
8139
`endif
8140
            begin
8141
                 bwhich <= 2'b01;
8142
                 cyc_o <= `HIGH;
8143
                 stb_o <= `HIGH;
8144
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
8145
                 adr_o <= {dram1_addr[31:3],3'b0};
8146
                 sr_o <=  IsLWR(dram1_instr);
8147
                 ol_o  <= dram1_ol;
8148
                 bstate <= B12;
8149
            end
8150
        end
8151 49 robfinch
        else if (~|wb_v && mem3_available && dram2_unc && dram2==`DRAMSLOT_BUSY && dram2_load && `NUM_MEM > 2) begin
8152 48 robfinch
`ifdef SUPPORT_DBG
8153
            if (dbg_lmatch2) begin
8154
                 dramC_v <= `TRUE;
8155
                 dramC_id <= dram2_id;
8156
                 dramC_exc <= `FLT_DBG;
8157
                 dramC_bus <= 64'h0;
8158
                 dram2 <= 2'd0;
8159
            end
8160
            else
8161
`endif
8162
            begin
8163
                 bwhich <= 2'b10;
8164
                 cyc_o <= `HIGH;
8165
                 stb_o <= `HIGH;
8166
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
8167
                 adr_o <= {dram2_addr[31:3],3'b0};
8168
                 sr_o <=  IsLWR(dram2_instr);
8169
                 ol_o  <= dram2_ol;
8170
                 bstate <= B12;
8171
            end
8172
        end
8173
        // Check for L2 cache miss
8174 49 robfinch
        else if (~|wb_v && !ihitL2) begin
8175 48 robfinch
             cti_o <= 3'b001;
8176 49 robfinch
             bte_o <= 2'b00;//2'b01;    // 4 beat burst wrap
8177 48 robfinch
             cyc_o <= `HIGH;
8178
             stb_o <= `HIGH;
8179
             sel_o <= 8'hFF;
8180
             icl_o <= `HIGH;
8181 49 robfinch
             iccnt <= 3'd0;
8182 48 robfinch
//            adr_o <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
8183
//            L2_adr <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
8184
             adr_o <= {pcr[5:0],L1_adr[31:5],5'h0};
8185
             ol_o  <= ol[0];
8186
             L2_adr <= {pcr[5:0],L1_adr[31:5],5'h0};
8187
             L2_xsel <= 1'b0;
8188
             bstate <= B7;
8189
        end
8190
    end
8191
// Terminal state for a store operation.
8192 49 robfinch
// Note that if only a single memory channel is selected, bwhich will be a
8193
// constant 0. This should cause the extra code to be removed.
8194 48 robfinch
B1:
8195
    if (acki|err_i) begin
8196
         isStore <= `TRUE;
8197
         cyc_o <= `LOW;
8198
         stb_o <= `LOW;
8199
         we_o <= `LOW;
8200
         sel_o <= 8'h00;
8201
         cr_o <= 1'b0;
8202
        // This isn't a good way of doing things; the state should be propagated
8203
        // to the commit stage, however since this is a store we know there will
8204
        // be no change of program flow. So the reservation status bit is set
8205
        // here. The author wanted to avoid the complexity of propagating the
8206
        // input signal to the commit stage. It does mean that the SWC
8207
        // instruction should be surrounded by SYNC's.
8208
        if (cr_o)
8209
             sema[0] <= rbi_i;
8210 49 robfinch
`ifdef HAS_WB
8211
                                for (n = 0; n < QENTRIES; n = n + 1) begin
8212
                                        if (wbo_id[n]) begin
8213
                        iqentry_exc[n] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8214
                        if (err_i|wrv_i) begin
8215
                                iqentry_a1[n] <= adr_o;
8216
                                wb_v <= 8'h00;          // Invalidate write buffer if there is a problem with the store
8217
                                wb_en <= `FALSE;        // and disable write buffer
8218
                        end
8219
                                                iqentry_cmt[n] <= `VAL;
8220
                                                iqentry_aq[n] <= `INV;
8221
                                        end
8222
                                end
8223
`else
8224 48 robfinch
        case(bwhich)
8225 49 robfinch
        2'd0:   if (mem1_available) begin
8226 48 robfinch
                 dram0 <= `DRAMREQ_READY;
8227
                 iqentry_exc[dram0_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8228
                if (err_i|wrv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8229 49 robfinch
                                                                        iqentry_cmt[ dram0_id[`QBITS] ] <= `VAL;
8230
                                                                        iqentry_aq[ dram0_id[`QBITS] ] <= `INV;
8231 48 robfinch
                        //iqentry_out[ dram0_id[`QBITS] ] <= `INV;
8232
                end
8233 49 robfinch
        2'd1:   if (`NUM_MEM > 1) begin
8234 48 robfinch
                 dram1 <= `DRAMREQ_READY;
8235
                 iqentry_exc[dram1_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8236
                if (err_i|wrv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8237 49 robfinch
                                                                        iqentry_cmt[ dram1_id[`QBITS] ] <= `VAL;
8238
                                                                        iqentry_aq[ dram1_id[`QBITS] ] <= `INV;
8239 48 robfinch
                        //iqentry_out[ dram1_id[`QBITS] ] <= `INV;
8240
                end
8241 49 robfinch
        2'd2:   if (`NUM_MEM > 2) begin
8242 48 robfinch
                 dram2 <= `DRAMREQ_READY;
8243
                 iqentry_exc[dram2_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8244
                if (err_i|wrv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8245 49 robfinch
                                                                        iqentry_cmt[ dram2_id[`QBITS] ] <= `VAL;
8246
                                                                        iqentry_aq[ dram2_id[`QBITS] ] <= `INV;
8247 48 robfinch
                        //iqentry_out[ dram2_id[`QBITS] ] <= `INV;
8248
                end
8249
        default:    ;
8250
        endcase
8251 49 robfinch
`endif
8252 48 robfinch
         bstate <= B19;
8253
    end
8254
B2:
8255
    begin
8256
    dccnt <= 2'd0;
8257
    case(bwhich)
8258
    2'd0:   begin
8259
             cti_o <= 3'b001;
8260
             bte_o <= 2'b01;
8261
             cyc_o <= `HIGH;
8262
             stb_o <= `HIGH;
8263
             sel_o <= fnSelect(dram0_instr,dram0_addr);
8264
             adr_o <= {dram0_addr[31:5],5'b0};
8265
             ol_o  <= dram0_ol;
8266
             bstate <= B2d;
8267
            end
8268 49 robfinch
    2'd1:   if (`NUM_MEM > 1) begin
8269 48 robfinch
             cti_o <= 3'b001;
8270
             bte_o <= 2'b01;
8271
             cyc_o <= `HIGH;
8272
             stb_o <= `HIGH;
8273
             sel_o <= fnSelect(dram1_instr,dram1_addr);
8274
             adr_o <= {dram1_addr[31:5],5'b0};
8275
             ol_o  <= dram1_ol;
8276
             bstate <= B2d;
8277
            end
8278 49 robfinch
    2'd2:   if (`NUM_MEM > 2) begin
8279 48 robfinch
             cti_o <= 3'b001;
8280
             bte_o <= 2'b01;
8281
             cyc_o <= `HIGH;
8282
             stb_o <= `HIGH;
8283
             sel_o <= fnSelect(dram2_instr,dram2_addr);
8284
             adr_o <= {dram2_addr[31:5],5'b0};
8285
             ol_o  <= dram2_ol;
8286
             bstate <= B2d;
8287
            end
8288
    default:    if (~acki)  bstate <= BIDLE;
8289
    endcase
8290
    end
8291
// Data cache load terminal state
8292
B2d:
8293
    if (ack_i|err_i) begin
8294
        errq <= errq | err_i;
8295
        rdvq <= rdvq | rdv_i;
8296
        if (!preload)   // A preload instruction ignores any error
8297
        case(bwhich)
8298
        2'd0:   if (err_i|rdv_i) begin
8299
                     iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8300
                     iqentry_exc[dram0_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8301
                end
8302 49 robfinch
        2'd1:   if ((err_i|rdv_i) && `NUM_MEM > 1) begin
8303 48 robfinch
                     iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8304
                     iqentry_exc[dram1_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8305
                end
8306 49 robfinch
        2'd2:   if ((err_i|rdv_i) && `NUM_MEM > 2) begin
8307 48 robfinch
                     iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8308
                     iqentry_exc[dram2_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8309
                end
8310
        default:    ;
8311
        endcase
8312
        dccnt <= dccnt + 2'd1;
8313
        adr_o[4:3] <= adr_o[4:3] + 2'd1;
8314
        bstate <= B2d;
8315
        if (dccnt==2'd2)
8316
             cti_o <= 3'b111;
8317
        if (dccnt==2'd3) begin
8318
             cti_o <= 3'b000;
8319
             bte_o <= 2'b00;
8320
             cyc_o <= `LOW;
8321
             stb_o <= `LOW;
8322
             sel_o <= 8'h00;
8323
             bstate <= B4;
8324
        end
8325
    end
8326
B3: begin
8327
         stb_o <= `HIGH;
8328
         bstate <= B2d;
8329
    end
8330
B4:  bstate <= B5;
8331
B5:  bstate <= B6;
8332
B6: begin
8333
    case(bwhich)
8334
    2'd0:    dram0 <= `DRAMSLOT_BUSY;  // causes retest of dhit
8335
    2'd1:    dram1 <= `DRAMSLOT_BUSY;
8336
    2'd2:    dram2 <= `DRAMSLOT_BUSY;
8337
    default:    ;
8338
    endcase
8339
    if (~ack_i)  bstate <= BIDLE;
8340
    end
8341
 
8342
// Ack state for instruction cache load
8343
B7:
8344
    if (ack_i|err_i) begin
8345
        errq <= errq | err_i;
8346
        exvq <= exvq | exv_i;
8347 49 robfinch
//        L1_en <= 9'h3 << {L2_xsel,L2_adr[4:3],1'b0};
8348 48 robfinch
//        L1_wr0 <= `TRUE;
8349
//        L1_wr1 <= `TRUE;
8350
//        L1_adr <= L2_adr;
8351
        if (err_i)
8352 49 robfinch
                L2_rdat <= {9{11'b0,4'd7,1'b0,`FLT_IBE,2'b00,`BRK}};
8353 48 robfinch
        else
8354 49 robfinch
                L2_rdat <= {dat_i[31:0],{4{dat_i}}};
8355 48 robfinch
        iccnt <= iccnt + 3'd1;
8356
        //stb_o <= `LOW;
8357
        if (iccnt==3'd3)
8358
            cti_o <= 3'b111;
8359
        if (iccnt==3'd4) begin
8360
            cti_o <= 3'b000;
8361
            bte_o <= 2'b00;             // linear burst
8362
            cyc_o <= `LOW;
8363
            stb_o <= `LOW;
8364
            sel_o <= 8'h00;
8365
            icl_o <= `LOW;
8366
            bstate <= B9;
8367
        end
8368
        else begin
8369
            L2_adr[4:3] <= L2_adr[4:3] + 2'd1;
8370
            if (L2_adr[4:3]==2'b11)
8371
                L2_xsel <= 1'b1;
8372
        end
8373
    end
8374
B9:
8375
        begin
8376
                L1_wr0 <= `FALSE;
8377
                L1_wr1 <= `FALSE;
8378 49 robfinch
                L1_wr2 <= `FALSE;
8379
                L1_en <= 9'h1FF;
8380 48 robfinch
                L2_xsel <= 1'b0;
8381
                if (~ack_i) begin
8382
                        bstate <= BIDLE;
8383
                        L2_nxt <= TRUE;
8384
                end
8385
        end
8386
B12:
8387
    if (ack_i|err_i) begin
8388
        if (isCAS) begin
8389
             iqentry_res        [ casid[`QBITS] ] <= (dat_i == cas);
8390
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8391
             iqentry_done[ casid[`QBITS] ] <= `VAL;
8392
             iqentry_instr[ casid[`QBITS]] <= `NOP_INSN;
8393
             iqentry_out [ casid[`QBITS] ] <= `INV;
8394
            if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
8395
            if (dat_i == cas) begin
8396
                 stb_o <= `LOW;
8397
                 we_o <= `TRUE;
8398
                 bstate <= B15;
8399
            end
8400
            else begin
8401
                 cas <= dat_i;
8402
                 cyc_o <= `LOW;
8403
                 stb_o <= `LOW;
8404
                 sel_o <= 8'h00;
8405
                case(bwhich)
8406
                2'b00:   dram0 <= `DRAMREQ_READY;
8407
                2'b01:   dram1 <= `DRAMREQ_READY;
8408
                2'b10:   dram2 <= `DRAMREQ_READY;
8409
                default:    ;
8410
                endcase
8411
                 bstate <= B19;
8412
            end
8413
        end
8414
        else if (isRMW) begin
8415
             rmw_instr <= iqentry_instr[casid[`QBITS]];
8416
             rmw_argA <= dat_i;
8417
                 if (isSpt) begin
8418
                        rmw_argB <= 64'd1 << iqentry_a1[casid[`QBITS]][63:58];
8419
                        rmw_argC <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ?
8420
                                                iqentry_a3[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58] :
8421
                                                iqentry_a2[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58];
8422
                 end
8423
                 else if (isInc) begin
8424
                        rmw_argB <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ? {{59{iqentry_instr[casid[`QBITS]][22]}},iqentry_instr[casid[`QBITS]][22:18]} :
8425
                                                                                                                                 {{59{iqentry_instr[casid[`QBITS]][17]}},iqentry_instr[casid[`QBITS]][17:13]};
8426
                 end
8427
                 else begin // isAMO
8428
                     iqentry_res [ casid[`QBITS] ] <= dat_i;
8429
                     rmw_argB <= iqentry_instr[casid[`QBITS]][31] ? {{59{iqentry_instr[casid[`QBITS]][20:16]}},iqentry_instr[casid[`QBITS]][20:16]} : iqentry_a2[casid[`QBITS]];
8430
                 end
8431
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8432
             if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
8433
             stb_o <= `LOW;
8434
             bstate <= B20;
8435
                end
8436
        else begin
8437
             cyc_o <= `LOW;
8438
             stb_o <= `LOW;
8439
             sel_o <= 8'h00;
8440
             sr_o <= `LOW;
8441
             xdati <= dat_i;
8442
            case(bwhich)
8443
            2'b00:  begin
8444
                     dram0 <= `DRAMREQ_READY;
8445
                     iqentry_exc [ dram0_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8446
                    if (err_i|rdv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8447
                    end
8448 49 robfinch
            2'b01:  if (`NUM_MEM > 1) begin
8449 48 robfinch
                     dram1 <= `DRAMREQ_READY;
8450
                     iqentry_exc [ dram1_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8451
                    if (err_i|rdv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8452
                    end
8453 49 robfinch
            2'b10:  if (`NUM_MEM > 2) begin
8454 48 robfinch
                     dram2 <= `DRAMREQ_READY;
8455
                     iqentry_exc [ dram2_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8456
                    if (err_i|rdv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8457
                    end
8458
            default:    ;
8459
            endcase
8460
             bstate <= B19;
8461
        end
8462
    end
8463
// Three cycles to detemrine if there's a cache hit during a store.
8464
B16:    begin
8465
            case(bwhich)
8466
            2'd0:      if (dhit0) begin  dram0 <= `DRAMREQ_READY; bstate <= B17; end
8467
            2'd1:      if (dhit1) begin  dram1 <= `DRAMREQ_READY; bstate <= B17; end
8468
            2'd2:      if (dhit2) begin  dram2 <= `DRAMREQ_READY; bstate <= B17; end
8469
            default:    bstate <= BIDLE;
8470
            endcase
8471
            end
8472
B17:     bstate <= B18;
8473
B18:     bstate <= B19;
8474
B19:    if (~acki)  begin bstate <= BIDLE; isStore <= `FALSE; end
8475
B20:
8476
        if (~ack_i) begin
8477
                stb_o <= `HIGH;
8478
                we_o  <= `HIGH;
8479
                dat_o <= fnDato(rmw_instr,rmw_res);
8480
                bstate <= B1;
8481
        end
8482
B21:
8483
        if (~ack_i) begin
8484
                stb_o <= `HIGH;
8485
                bstate <= B12;
8486
        end
8487
default:     bstate <= BIDLE;
8488
endcase
8489
 
8490
if (!branchmiss) begin
8491
    case({fetchbuf0_v, fetchbuf1_v})
8492
    2'b00:  ;
8493
    2'b01:
8494
        if (canq1) begin
8495
                tail0 <= idp1(tail0);
8496
                tail1 <= idp1(tail1);
8497
        end
8498
    2'b10:
8499
        if (canq1) begin
8500
            tail0 <= idp1(tail0);
8501
            tail1 <= idp1(tail1);
8502
        end
8503
    2'b11:
8504
        if (canq1) begin
8505
            if (IsBranch(fetchbuf0_instr) && predict_taken0 && fetchbuf0_thrd==fetchbuf1_thrd) begin
8506
                 tail0 <= idp1(tail0);
8507
                 tail1 <= idp1(tail1);
8508
            end
8509
            else begin
8510
                                if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
8511
                        if (canq2) begin
8512
                             tail0 <= idp2(tail0);
8513
                             tail1 <= idp2(tail1);
8514
                        end
8515
                        else begin    // queued1 will be true
8516
                             tail0 <= idp1(tail0);
8517
                             tail1 <= idp1(tail1);
8518
                        end
8519
                end
8520
            end
8521
        end
8522
    endcase
8523
end
8524 52 robfinch
else if (!thread_en) begin      // if branchmiss
8525 48 robfinch
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
8526 52 robfinch
         tail0 <= 4'd0;
8527
         tail1 <= 4'd1;
8528 48 robfinch
    end
8529
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
8530 52 robfinch
         tail0 <= 4'd1;
8531
         tail1 <= 4'd2;
8532 48 robfinch
    end
8533
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
8534 52 robfinch
         tail0 <= 4'd2;
8535
         tail1 <= 4'd3;
8536 48 robfinch
    end
8537
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
8538 52 robfinch
         tail0 <= 4'd3;
8539
         tail1 <= 4'd4;
8540 48 robfinch
    end
8541
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
8542 52 robfinch
         tail0 <= 4'd4;
8543
         tail1 <= 4'd5;
8544 48 robfinch
    end
8545
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
8546 52 robfinch
         tail0 <= 4'd5;
8547
         tail1 <= 4'd6;
8548 48 robfinch
    end
8549
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
8550 52 robfinch
         tail0 <= 4'd6;
8551
         tail1 <= 4'd7;
8552 48 robfinch
    end
8553
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
8554 52 robfinch
         tail0 <= 4'd7;
8555
         tail1 <= 4'd8;
8556 48 robfinch
    end
8557 52 robfinch
    else if (iqentry_stomp[8] & ~iqentry_stomp[7]) begin
8558
         tail0 <= 4'd8;
8559
         tail1 <= 4'd9;
8560
    end
8561
    else if (iqentry_stomp[9] & ~iqentry_stomp[8]) begin
8562
         tail0 <= 4'd9;
8563
         tail1 <= 4'd0;
8564
    end
8565 48 robfinch
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
8566
end
8567 51 robfinch
 
8568 48 robfinch
/*
8569
    if (pebm)
8570
         seq_num <= seq_num + 5'd3;
8571
    else if (queued2)
8572
         seq_num <= seq_num + 5'd2;
8573
    else if (queued1)
8574
         seq_num <= seq_num + 5'd1;
8575
*/
8576
//      #5 rf[0] = 0; rf_v[0] = 1; rf_source[0] = 0;
8577 51 robfinch
`ifdef SIM
8578 48 robfinch
        $display("\n\n\n\n\n\n\n\n");
8579
        $display("TIME %0d", $time);
8580
        $display("%h #", pc0);
8581
`ifdef SUPPORT_SMT
8582
    $display ("Regfile: %d", rgs[0]);
8583
        for (n=0; n < 32; n=n+4) begin
8584
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8585
               n[4:0]+0, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8586
               n[4:0]+1, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8587
               n[4:0]+2, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8588
               n[4:0]+3, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8589
               );
8590
        end
8591
    $display ("Regfile: %d", rgs[1]);
8592
        for (n=128; n < 160; n=n+4) begin
8593
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8594
               n[4:0]+0, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8595
               n[4:0]+1, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8596
               n[4:0]+2, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8597
               n[4:0]+3, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8598
               );
8599
        end
8600
`else
8601
    $display ("Regfile: %d", rgs);
8602
        for (n=0; n < 32; n=n+4) begin
8603
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8604
               n[4:0]+0, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8605
               n[4:0]+1, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8606
               n[4:0]+2, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8607
               n[4:0]+3, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8608
               );
8609
        end
8610
`endif
8611 49 robfinch
`ifdef FCU_ENH
8612 48 robfinch
        $display("Call Stack:");
8613 49 robfinch
        for (n = 0; n < 16; n = n + 4)
8614 48 robfinch
                $display("%c%d: %h   %c%d: %h   %c%d: %h   %c%d: %h",
8615
                        ufb1.ursb1.rasp==n+0 ?">" : " ", n[4:0]+0, ufb1.ursb1.ras[n+0],
8616
                        ufb1.ursb1.rasp==n+1 ?">" : " ", n[4:0]+1, ufb1.ursb1.ras[n+1],
8617
                        ufb1.ursb1.rasp==n+2 ?">" : " ", n[4:0]+2, ufb1.ursb1.ras[n+2],
8618
                        ufb1.ursb1.rasp==n+3 ?">" : " ", n[4:0]+3, ufb1.ursb1.ras[n+3]
8619
                );
8620
        $display("\n");
8621 49 robfinch
`endif
8622 48 robfinch
//    $display("Return address stack:");
8623
//    for (n = 0; n < 16; n = n + 1)
8624
//        $display("%d %h", rasp+n[3:0], ras[rasp+n[3:0]]);
8625
        $display("TakeBr:%d #", take_branch);//, backpc);
8626 51 robfinch
        $display("Insn%d: %h", 0, insn0);
8627
        if (`WAYS > 1)
8628
                $display("Insn%d: %h", 1, insn1);
8629 48 robfinch
        $display("%c%c A: %d %h %h #",
8630
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
8631
        $display("%c%c B: %d %h %h #",
8632
            45, fetchbuf?45:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
8633
        $display("%c%c C: %d %h %h #",
8634
            45, fetchbuf?62:45, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
8635
        $display("%c%c D: %d %h %h #",
8636
            45, fetchbuf?62:45, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
8637
 
8638
        for (i=0; i<QENTRIES; i=i+1)
8639
            $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#",
8640
                 (i[`QBITS]==head0)?"C":".",
8641
                 (i[`QBITS]==tail0)?"Q":".",
8642
                  i[`QBITS],
8643
                 iqentry_v[i] ? "v" : "-",
8644
                 iqentry_iv[i] ? "I" : "-",
8645
                 iqentry_done[i]?"d":"-",
8646
                 iqentry_out[i]?"o":"-",
8647
                 iqentry_bt[i],
8648
                 iqentry_memissue[i],
8649
                 iqentry_agen[i] ? "a": "-",
8650
                 iqentry_alu0_issue[i]?"0":iqentry_alu1_issue[i]?"1":"-",
8651
                 iqentry_stomp[i]?"s":"-",
8652
                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",
8653
                iqentry_instr[i], iqentry_tgt[i][4:0],
8654
                iqentry_exc[i], iqentry_res[i], iqentry_a0[i], iqentry_a1[i], iqentry_a1_v[i],
8655
                iqentry_a1_s[i],
8656
                iqentry_a2[i], iqentry_a2_v[i], iqentry_a2_s[i],
8657
                iqentry_a3[i], iqentry_a3_v[i], iqentry_a3_s[i],
8658
                iqentry_thrd[i],
8659
                iqentry_pc[i],
8660
                iqentry_sn[i], iqentry_ven[i]
8661
                );
8662
    $display("DRAM");
8663
        $display("%d %h %h %c%h %o #",
8664
            dram0, dram0_addr, dram0_data, (IsFlowCtrl(dram0_instr) ? 98 : (IsMem(dram0_instr)) ? 109 : 97),
8665
            dram0_instr, dram0_id);
8666 49 robfinch
          if (`NUM_MEM > 1)
8667 48 robfinch
        $display("%d %h %h %c%h %o #",
8668
            dram1, dram1_addr, dram1_data, (IsFlowCtrl(dram1_instr) ? 98 : (IsMem(dram1_instr)) ? 109 : 97),
8669
            dram1_instr, dram1_id);
8670 49 robfinch
          if (`NUM_MEM > 2)
8671 48 robfinch
        $display("%d %h %h %c%h %o #",
8672
            dram2, dram2_addr, dram2_data, (IsFlowCtrl(dram2_instr) ? 98 : (IsMem(dram2_instr)) ? 109 : 97),
8673
            dram2_instr, dram2_id);
8674
        $display("%d %h %o %h #", dramA_v, dramA_bus, dramA_id, dramA_exc);
8675 49 robfinch
        if (`NUM_MEM > 1)
8676 48 robfinch
        $display("%d %h %o %h #", dramB_v, dramB_bus, dramB_id, dramB_exc);
8677 49 robfinch
        if (`NUM_MEM > 2)
8678 48 robfinch
        $display("%d %h %o %h #", dramC_v, dramC_bus, dramC_id, dramC_exc);
8679
    $display("ALU");
8680
        $display("%d %h %h %h %c%h %d %o %h #",
8681
                alu0_dataready, alu0_argI, alu0_argA, alu0_argB,
8682
                 (IsFlowCtrl(alu0_instr) ? 98 : IsMem(alu0_instr) ? 109 : 97),
8683
                alu0_instr, alu0_bt, alu0_sourceid, alu0_pc);
8684
        $display("%d %h %o 0 #", alu0_v, alu0_bus, alu0_id);
8685 49 robfinch
        if (`NUM_ALU > 1) begin
8686
                $display("%d %h %h %h %c%h %d %o %h #",
8687
                        alu1_dataready, alu1_argI, alu1_argA, alu1_argB,
8688
                        (IsFlowCtrl(alu1_instr) ? 98 : IsMem(alu1_instr) ? 109 : 97),
8689
                        alu1_instr, alu1_bt, alu1_sourceid, alu1_pc);
8690
                $display("%d %h %o 0 #", alu1_v, alu1_bus, alu1_id);
8691
        end
8692 48 robfinch
        $display("FCU");
8693
        $display("%d %h %h %h %h #", fcu_v, fcu_bus, fcu_argI, fcu_argA, fcu_argB);
8694
        $display("%c %h %h #", fcu_branchmiss?"m":" ", fcu_sourceid, fcu_misspc);
8695
    $display("Commit");
8696
        $display("0: %c %h %o %d #", commit0_v?"v":" ", commit0_bus, commit0_id, commit0_tgt[4:0]);
8697
        $display("1: %c %h %o %d #", commit1_v?"v":" ", commit1_bus, commit1_id, commit1_tgt[4:0]);
8698
    $display("instructions committed: %d ticks: %d ", I, tick);
8699 49 robfinch
    $display("Write merges: %d", wb_merges);
8700 51 robfinch
`endif  // SIM
8701 48 robfinch
 
8702
//
8703
//      $display("\n\n\n\n\n\n\n\n");
8704
//      $display("TIME %0d", $time);
8705
//      $display("  pc0=%h", pc0);
8706
//      $display("  pc1=%h", pc1);
8707
//      $display("  reg0=%h, v=%d, src=%o", rf[0], rf_v[0], rf_source[0]);
8708
//      $display("  reg1=%h, v=%d, src=%o", rf[1], rf_v[1], rf_source[1]);
8709
//      $display("  reg2=%h, v=%d, src=%o", rf[2], rf_v[2], rf_source[2]);
8710
//      $display("  reg3=%h, v=%d, src=%o", rf[3], rf_v[3], rf_source[3]);
8711
//      $display("  reg4=%h, v=%d, src=%o", rf[4], rf_v[4], rf_source[4]);
8712
//      $display("  reg5=%h, v=%d, src=%o", rf[5], rf_v[5], rf_source[5]);
8713
//      $display("  reg6=%h, v=%d, src=%o", rf[6], rf_v[6], rf_source[6]);
8714
//      $display("  reg7=%h, v=%d, src=%o", rf[7], rf_v[7], rf_source[7]);
8715
 
8716
//      $display("Fetch Buffers:");
8717
//      $display("  %c%c fbA: v=%d instr=%h pc=%h     %c%c fbC: v=%d instr=%h pc=%h", 
8718
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc,
8719
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
8720
//      $display("  %c%c fbB: v=%d instr=%h pc=%h     %c%c fbD: v=%d instr=%h pc=%h", 
8721
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc,
8722
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
8723
//      $display("  branchback=%d backpc=%h", branchback, backpc);
8724
 
8725
//      $display("Instruction Queue:");
8726
//      for (i=0; i<8; i=i+1) 
8727
//          $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",
8728
//              (i[`QBITS]==head0)?72:32, (i[`QBITS]==tail0)?84:32, i,
8729
//              iqentry_v[i], iqentry_done[i], iqentry_out[i], iqentry_agen[i], iqentry_res[i], iqentry_op[i], 
8730
//              iqentry_bt[i], iqentry_tgt[i], iqentry_a1[i], iqentry_a1_v[i], iqentry_a1_s[i], iqentry_a2[i], iqentry_a2_v[i], 
8731
//              iqentry_a2_s[i], iqentry_a0[i], iqentry_pc[i], iqentry_exc[i]);
8732
 
8733
//      $display("Scheduling Status:");
8734
//      $display("  iqentry0 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8735
//              iqentry_0_issue, iqentry_0_islot, iqentry_stomp[0], iqentry_source[0], iqentry_memready[0], iqentry_memissue[0]);
8736
//      $display("  iqentry1 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8737
//              iqentry_1_issue, iqentry_1_islot, iqentry_stomp[1], iqentry_source[1], iqentry_memready[1], iqentry_memissue[1]);
8738
//      $display("  iqentry2 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8739
//              iqentry_2_issue, iqentry_2_islot, iqentry_stomp[2], iqentry_source[2], iqentry_memready[2], iqentry_memissue[2]);
8740
//      $display("  iqentry3 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8741
//              iqentry_3_issue, iqentry_3_islot, iqentry_stomp[3], iqentry_source[3], iqentry_memready[3], iqentry_memissue[3]);
8742
//      $display("  iqentry4 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8743
//              iqentry_4_issue, iqentry_4_islot, iqentry_stomp[4], iqentry_source[4], iqentry_memready[4], iqentry_memissue[4]);
8744
//      $display("  iqentry5 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8745
//              iqentry_5_issue, iqentry_5_islot, iqentry_stomp[5], iqentry_source[5], iqentry_memready[5], iqentry_memissue[5]);
8746
//      $display("  iqentry6 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8747
//              iqentry_6_issue, iqentry_6_islot, iqentry_stomp[6], iqentry_source[6], iqentry_memready[6], iqentry_memissue[6]);
8748
//      $display("  iqentry7 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8749
//              iqentry_7_issue, iqentry_7_islot, iqentry_stomp[7], iqentry_source[7], iqentry_memready[7], iqentry_memissue[7]);
8750
 
8751
//      $display("ALU Inputs:");
8752
//      $display("  0: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
8753
//              alu0_available, alu0_dataready, alu0_sourceid, alu0_op, alu0_argA,
8754
//              alu0_argB, alu0_argI, alu0_bt);
8755
//      $display("  1: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
8756
//              alu1_available, alu1_dataready, alu1_sourceid, alu1_op, alu1_argA,
8757
//              alu1_argB, alu1_argI, alu1_bt);
8758
 
8759
//      $display("ALU Outputs:");
8760
//      $display("  0: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
8761
//              alu0_v, alu0_bus, alu0_id, alu0_branchmiss, alu0_misspc, alu0_sourceid);
8762
//      $display("  1: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
8763
//              alu1_v, alu1_bus, alu1_id, alu1_branchmiss, alu1_misspc, alu1_sourceid);
8764
 
8765
//      $display("DRAM Status:");
8766
//      $display("  OUT: v=%d data=%h tgt=%d id=%o", dram_v, dram_bus, dram_tgt, dram_id);
8767
//      $display("  dram0: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
8768
//          dram0, dram0_addr, dram0_data, dram0_op, dram0_tgt, dram0_id);
8769
//      $display("  dram1: status=%h addr=%h data=%h op=%d tgt=%d id=%o", 
8770
//          dram1, dram1_addr, dram1_data, dram1_op, dram1_tgt, dram1_id);
8771
//      $display("  dram2: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
8772
//          dram2, dram2_addr, dram2_data, dram2_op, dram2_tgt, dram2_id);
8773
 
8774
//      $display("Commit Buses:");
8775
//      $display("  0: v=%d id=%o data=%h", commit0_v, commit0_id, commit0_bus);
8776
//      $display("  1: v=%d id=%o data=%h", commit1_v, commit1_id, commit1_bus);
8777
 
8778
//
8779
//      $display("Memory Contents:");
8780
//      for (j=0; j<64; j=j+16)
8781
//          $display("  %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h", 
8782
//              m[j+0], m[j+1], m[j+2], m[j+3], m[j+4], m[j+5], m[j+6], m[j+7],
8783
//              m[j+8], m[j+9], m[j+10], m[j+11], m[j+12], m[j+13], m[j+14], m[j+15]);
8784
 
8785
        $display("");
8786
 
8787
        if (|panic) begin
8788
            $display("");
8789
            $display("-----------------------------------------------------------------");
8790
            $display("-----------------------------------------------------------------");
8791
            $display("---------------     PANIC:%s     -----------------", message[panic]);
8792
            $display("-----------------------------------------------------------------");
8793
            $display("-----------------------------------------------------------------");
8794
            $display("");
8795
            $display("instructions committed: %d", I);
8796
            $display("total execution cycles: %d", $time / 10);
8797
            $display("");
8798
        end
8799
        if (|panic && ~outstanding_stores) begin
8800
            $finish;
8801
        end
8802
    for (n = 0; n < QENTRIES; n = n + 1)
8803
        if (branchmiss) begin
8804
            if (!setpred[n]) begin
8805
                 iqentry_instr[n][`INSTRUCTION_OP] <= `NOP;
8806
                 iqentry_done[n] <= `VAL;
8807
                 iqentry_cmt[n] <= `VAL;
8808
            end
8809
        end
8810
 
8811
        if (snr) begin
8812
                seq_num <= 32'd0;
8813
                seq_num1 <= 32'd0;
8814
        end
8815
end // clock domain
8816
/*
8817
always @(posedge clk)
8818
if (rst) begin
8819
     tail0 <= 3'd0;
8820
     tail1 <= 3'd1;
8821
end
8822
else begin
8823
if (!branchmiss) begin
8824
    case({fetchbuf0_v, fetchbuf1_v})
8825
    2'b00:  ;
8826
    2'b01:
8827
        if (canq1) begin
8828
             tail0 <= idp1(tail0);
8829
             tail1 <= idp1(tail1);
8830
        end
8831
    2'b10:
8832
        if (canq1) begin
8833
             tail0 <= idp1(tail0);
8834
             tail1 <= idp1(tail1);
8835
        end
8836
    2'b11:
8837
        if (canq1) begin
8838
            if (IsBranch(fetchbuf0_instr) && predict_taken0) begin
8839
                 tail0 <= idp1(tail0);
8840
                 tail1 <= idp1(tail1);
8841
            end
8842
            else begin
8843
                                if (vqe < vl || !IsVector(fetchbuf0_instr)) begin
8844
                        if (canq2) begin
8845
                             tail0 <= idp2(tail0);
8846
                             tail1 <= idp2(tail1);
8847
                        end
8848
                        else begin    // queued1 will be true
8849
                             tail0 <= idp1(tail0);
8850
                             tail1 <= idp1(tail1);
8851
                        end
8852
                end
8853
            end
8854
        end
8855
    endcase
8856
end
8857
else begin      // if branchmiss
8858
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
8859
         tail0 <= 3'd0;
8860
         tail1 <= 3'd1;
8861
    end
8862
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
8863
         tail0 <= 3'd1;
8864
         tail1 <= 3'd2;
8865
    end
8866
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
8867
         tail0 <= 3'd2;
8868
         tail1 <= 3'd3;
8869
    end
8870
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
8871
         tail0 <= 3'd3;
8872
         tail1 <= 3'd4;
8873
    end
8874
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
8875
         tail0 <= 3'd4;
8876
         tail1 <= 3'd5;
8877
    end
8878
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
8879
         tail0 <= 3'd5;
8880
         tail1 <= 3'd6;
8881
    end
8882
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
8883
         tail0 <= 3'd6;
8884
         tail1 <= 3'd7;
8885
    end
8886
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
8887
         tail0 <= 3'd7;
8888
         tail1 <= 3'd0;
8889
    end
8890
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
8891
end
8892
end
8893
*/
8894
/*
8895
always @(posedge clk)
8896
if (rst)
8897
     seq_num <= 5'd0;
8898
else begin
8899
    if (pebm)
8900
         seq_num <= seq_num + 5'd3;
8901
    else if (queued2)
8902
         seq_num <= seq_num + 5'd2;
8903
    else if (queued1)
8904
         seq_num <= seq_num + 5'd1;
8905
end
8906
*/
8907 49 robfinch
 
8908 51 robfinch
// Update the write buffer.
8909 49 robfinch
task wb_update;
8910
input [`QBITS] id;
8911
input rmw;
8912
input [7:0] sel;
8913
input [1:0] ol;
8914
input [`ABITS] addr;
8915
input [63:0] data;
8916
begin
8917 52 robfinch
        if (wbm && wbptr > 1 && wb_addr[wbptr-1][AMSB:3]==addr[AMSB:3]
8918
         && wb_ol[wbptr-1]==ol && wb_rmw[wbptr-1]==rmw && wb_v[wbptr-1]) begin
8919
                // The write buffer is always shifted during the bus IDLE state. That means
8920
                // the data is out of place by a slot. The slot the data is moved from is
8921
                // invalidated.
8922
                wb_v[wbptr-2] <= `INV;
8923
                wb_v[wbptr-1] <= wb_en;
8924
                wb_id[wbptr-1] <= wb_id[wbptr-1] | (16'd1 << id);
8925
                wb_rmw[wbptr-1] <= rmw;
8926
                wb_ol[wbptr-1] <= ol;
8927 49 robfinch
                wb_sel[wbptr-1] <= wb_sel[wbptr-1] | sel;
8928 52 robfinch
                wb_addr[wbptr-1] <= wb_addr[wbptr-1];
8929
                wb_data[wbptr-1] <= wb_data[wbptr-1];
8930 49 robfinch
                if (sel[0]) wb_data[wbptr-1][ 7: 0] <= data[ 7: 0];
8931
                if (sel[1]) wb_data[wbptr-1][15: 8] <= data[15: 8];
8932
                if (sel[2]) wb_data[wbptr-1][23:16] <= data[23:16];
8933
                if (sel[3]) wb_data[wbptr-1][31:24] <= data[31:24];
8934
                if (sel[4]) wb_data[wbptr-1][39:32] <= data[39:32];
8935
                if (sel[5]) wb_data[wbptr-1][47:40] <= data[47:40];
8936
                if (sel[6]) wb_data[wbptr-1][55:48] <= data[55:48];
8937
                if (sel[7]) wb_data[wbptr-1][63:56] <= data[63:56];
8938
                wb_merges <= wb_merges + 32'd1;
8939
        end
8940
        else begin
8941
                wb_v[wbptr] <= wb_en;
8942
                wb_id[wbptr] <= (16'd1 << id);
8943
                wb_rmw[wbptr] <= rmw;
8944
                wb_ol[wbptr] <= ol;
8945
                wb_sel[wbptr] <= sel;
8946
                wb_addr[wbptr] <= {addr[AMSB:3],3'b0};
8947
                wb_data[wbptr] <= data;
8948
        end
8949
end
8950
endtask
8951 52 robfinch
 
8952 48 robfinch
// Increment the head pointers
8953
// Also increments the instruction counter
8954
// Used when instructions are committed.
8955
// Also clear any outstanding state bits that foul things up.
8956
//
8957
task head_inc;
8958
input [`QBITS] amt;
8959
begin
8960 52 robfinch
     head0 <= (head0 + amt) % QENTRIES;
8961
     head1 <= (head1 + amt) % QENTRIES;
8962
     head2 <= (head2 + amt) % QENTRIES;
8963
     head3 <= (head3 + amt) % QENTRIES;
8964
     head4 <= (head4 + amt) % QENTRIES;
8965
     head5 <= (head5 + amt) % QENTRIES;
8966
     head6 <= (head6 + amt) % QENTRIES;
8967
     head7 <= (head7 + amt) % QENTRIES;
8968
     head8 <= (head8 + amt) % QENTRIES;
8969
     head9 <= (head9 + amt) % QENTRIES;
8970 48 robfinch
     I <= I + amt;
8971 49 robfinch
    if (amt==3'd3) begin
8972
        iqentry_agen[head0] <= `INV;
8973
        iqentry_agen[head1] <= `INV;
8974
        iqentry_agen[head2] <= `INV;
8975
        iqentry_mem[head0] <= `FALSE;
8976
        iqentry_mem[head1] <= `FALSE;
8977
        iqentry_mem[head2] <= `FALSE;
8978
        iqentry_iv[head0] <= `INV;
8979
        iqentry_iv[head1] <= `INV;
8980
        iqentry_iv[head2] <= `INV;
8981
        iqentry_alu[head0] <= `FALSE;
8982
        iqentry_alu[head1] <= `FALSE;
8983
        iqentry_alu[head2] <= `FALSE;
8984
        end
8985
    else if (amt==3'd2) begin
8986 48 robfinch
     iqentry_agen[head0] <= `INV;
8987
     iqentry_agen[head1] <= `INV;
8988 49 robfinch
     iqentry_mem[head0] <= `FALSE;
8989
     iqentry_mem[head1] <= `FALSE;
8990
     iqentry_iv[head0] <= `INV;
8991
     iqentry_iv[head1] <= `INV;
8992
        iqentry_alu[head0] <= `FALSE;
8993
     iqentry_alu[head1] <= `FALSE;
8994 48 robfinch
    end else if (amt==3'd1) begin
8995 49 robfinch
            iqentry_agen[head0] <= `INV;
8996
            iqentry_mem[head0] <= `FALSE;
8997
        iqentry_iv[head0] <= `INV;
8998
        iqentry_alu[head0] <= `FALSE;
8999 48 robfinch
        end
9000
end
9001
endtask
9002
 
9003
task setargs;
9004
input [`QBITS] nn;
9005
input [4:0] id;
9006
input v;
9007
input [63:0] bus;
9008
begin
9009
  if (iqentry_a1_v[nn] == `INV && iqentry_a1_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9010
                iqentry_a1[nn] <= bus;
9011
                iqentry_a1_v[nn] <= `VAL;
9012
  end
9013
  if (iqentry_a2_v[nn] == `INV && iqentry_a2_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9014
                iqentry_a2[nn] <= bus;
9015
                iqentry_a2_v[nn] <= `VAL;
9016
  end
9017
  if (iqentry_a3_v[nn] == `INV && iqentry_a3_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9018
                iqentry_a3[nn] <= bus;
9019
                iqentry_a3_v[nn] <= `VAL;
9020
  end
9021
end
9022
endtask
9023
 
9024
task setinsn;
9025
input [`QBITS] nn;
9026
input [4:0] id;
9027
input v;
9028 51 robfinch
input [143:0] bus;
9029 48 robfinch
begin
9030
  if (iqentry_iv[nn] == `INV && iqentry_is[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9031
        iqentry_iv   [nn]  <= `VAL;
9032
//      iqentry_Rt   [nn]  <= bus[`IB_RT];
9033
//      iqentry_Rc   [nn]  <= bus[`IB_RC];
9034
//      iqentry_Ra   [nn]  <= bus[`IB_RA];
9035
        iqentry_a0       [nn]  <= bus[`IB_CONST];
9036
        iqentry_imm  [nn]  <= bus[`IB_IMM];
9037
                iqentry_insln[nn]  <= bus[`IB_LN];
9038 51 robfinch
                iqentry_jal      [nn]  <= bus[`IB_JAL];
9039
                iqentry_ret  [nn]  <= bus[`IB_RET];
9040
                iqentry_irq  [nn]  <= bus[`IB_IRQ];
9041
                iqentry_brk      [nn]  <= bus[`IB_BRK];
9042
                iqentry_rti  [nn]  <= bus[`IB_RTI];
9043 48 robfinch
                iqentry_bt   [nn]  <= bus[`IB_BT];
9044
                iqentry_alu  [nn]  <= bus[`IB_ALU];
9045
                iqentry_alu0 [nn]  <= bus[`IB_ALU0];
9046
                iqentry_fpu  [nn]  <= bus[`IB_FPU];
9047
                iqentry_fc   [nn]  <= bus[`IB_FC];
9048
                iqentry_canex[nn]  <= bus[`IB_CANEX];
9049 50 robfinch
                iqentry_loadv[nn]  <= bus[`IB_LOADV];
9050 48 robfinch
                iqentry_load [nn]  <= bus[`IB_LOAD];
9051
                iqentry_preload[nn]<= bus[`IB_PRELOAD];
9052 50 robfinch
                iqentry_store[nn]  <= bus[`IB_STORE];
9053
                iqentry_oddball[nn] <= bus[`IB_ODDBALL];
9054
                iqentry_memsz[nn]  <= bus[`IB_MEMSZ];
9055 48 robfinch
                iqentry_mem  [nn]  <= bus[`IB_MEM];
9056
                iqentry_memndx[nn] <= bus[`IB_MEMNDX];
9057
                iqentry_rmw  [nn]  <= bus[`IB_RMW];
9058
                iqentry_memdb[nn]  <= bus[`IB_MEMDB];
9059
                iqentry_memsb[nn]  <= bus[`IB_MEMSB];
9060
                iqentry_shft48[nn] <= bus[`IB_SHFT48];
9061
                iqentry_sei      [nn]    <= bus[`IB_SEI];
9062
                iqentry_aq   [nn]  <= bus[`IB_AQ];
9063
                iqentry_rl   [nn]  <= bus[`IB_RL];
9064
                iqentry_jmp  [nn]  <= bus[`IB_JMP];
9065
                iqentry_br   [nn]  <= bus[`IB_BR];
9066
                iqentry_sync [nn]  <= bus[`IB_SYNC];
9067
                iqentry_fsync[nn]  <= bus[`IB_FSYNC];
9068
        iqentry_rfw  [nn]  <= bus[`IB_RFW];
9069
        iqentry_we   [nn]  <= bus[`IB_WE];
9070
  end
9071
end
9072
endtask
9073
 
9074
// Enqueue fetchbuf0 onto the tail of the instruction queue
9075
task enque0;
9076
input [`QBITS] tail;
9077
input [63:0] seqnum;
9078
input [5:0] venno;
9079
begin
9080
        iqentry_exc[tail] <= `FLT_NONE;
9081
`ifdef SUPPORT_DBG
9082
    if (dbg_imatchA)
9083
        iqentry_exc[tail] <= `FLT_DBG;
9084
    else if (dbg_ctrl[63])
9085
        iqentry_exc[tail] <= `FLT_SSM;
9086
`endif
9087
        iqentry_sn   [tail]    <=  seqnum;
9088
        iqentry_v    [tail]    <=   `VAL;
9089
        iqentry_iv       [tail]    <=   `INV;
9090
        iqentry_is   [tail]    <= tail;
9091
        iqentry_thrd [tail]    <=   fetchbuf0_thrd;
9092
        iqentry_done [tail]    <=    `INV;
9093
        iqentry_cmt  [tail]    <=       `INV;
9094
        iqentry_out  [tail]    <=    `INV;
9095
        iqentry_res  [tail]    <=    `ZERO;
9096
        iqentry_instr[tail]    <=    IsVLS(fetchbuf0_instr) ? (vm[fnM2(fetchbuf0_instr)] ? fetchbuf0_instr : `NOP_INSN) : fetchbuf0_instr;
9097
        iqentry_pt   [tail]    <=  predict_taken0;
9098
        iqentry_agen [tail]    <=    `INV;
9099
        iqentry_state[tail]    <=   IQS_IDLE;
9100
// If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9101
// inherit the previous pc.
9102
//if (IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15] &&
9103
//   (IsBrk(iqentry_instr[idm1(tail)]) && !iqentry_instr[idm1(tail1)][15] && iqentry_v[idm1(tail)]))
9104
//   iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
9105
//else
9106
         iqentry_pc   [tail] <= fetchbuf0_pc;
9107
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf0_instr);
9108
        iqentry_tgt  [tail]    <=       Rt0;
9109
        iqentry_Ra   [tail]    <= Ra0;
9110
        iqentry_Rb   [tail]    <= Rb0;
9111
        iqentry_Rc   [tail]    <= Rc0;
9112
        iqentry_vl   [tail]    <=  vl;
9113
        iqentry_ven  [tail]    <=   venno;
9114
        iqentry_exc  [tail]    <=    `EXC_NONE;
9115
        iqentry_a1   [tail]    <=    rfoa0;
9116
        iqentry_a1_v [tail]    <=    Source1Valid(fetchbuf0_instr) | regIsValid[Ra0s];
9117
        iqentry_a1_s [tail]    <=    rf_source[Ra0s];
9118
        iqentry_a2   [tail]    <=    rfob0;
9119
        iqentry_a2_v [tail]    <=    Source2Valid(fetchbuf0_instr) | regIsValid[Rb0s];
9120
        iqentry_a2_s [tail]    <=    rf_source[Rb0s];
9121
        iqentry_a3   [tail]    <=    rfoc0;
9122
        iqentry_a3_v [tail]    <=    Source3Valid(fetchbuf0_instr) | regIsValid[Rc0s];
9123
        iqentry_a3_s [tail]    <=    rf_source[Rc0s];
9124
end
9125
endtask
9126
 
9127
// Enque fetchbuf1. Fetchbuf1 might be the second instruction to queue so some
9128
// of this code checks to see which tail it is being queued on.
9129
task enque1;
9130
input [`QBITS] tail;
9131
input [63:0] seqnum;
9132
input [5:0] venno;
9133
begin
9134
 iqentry_exc[tail] <= `FLT_NONE;
9135
`ifdef SUPPORT_DBG
9136
    if (dbg_imatchB)
9137
        iqentry_exc[tail] <= `FLT_DBG;
9138
    else if (dbg_ctrl[63])
9139
        iqentry_exc[tail] <= `FLT_SSM;
9140
`endif
9141
        iqentry_sn   [tail]    <=   seqnum;
9142
        iqentry_v    [tail]    <=   `VAL;
9143
        iqentry_iv       [tail]    <=   `INV;
9144
        iqentry_is   [tail]    <= tail;
9145
        iqentry_thrd [tail]    <=   fetchbuf1_thrd;
9146
        iqentry_done [tail]    <=   `INV;
9147
        iqentry_cmt  [tail]    <=       `INV;
9148
        iqentry_out  [tail]    <=   `INV;
9149
        iqentry_res  [tail]    <=   `ZERO;
9150
        iqentry_instr[tail]    <=   IsVLS(fetchbuf1_instr) ? (vm[fnM2(fetchbuf1_instr)] ? fetchbuf1_instr : `NOP_INSN) : fetchbuf1_instr;
9151
        iqentry_pt   [tail]    <=  predict_taken1;
9152
        iqentry_agen [tail]    <=   `INV;
9153
        iqentry_state[tail]    <=   IQS_IDLE;
9154
// If queing 2nd instruction must read from first
9155
if (tail==tail1) begin
9156
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9157
    // inherit the previous pc.
9158
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
9159
//        IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15])
9160
//       iqentry_pc   [tail]    <= fetchbuf0_pc;
9161
//    else
9162
                iqentry_pc   [tail] <= fetchbuf1_pc;
9163
end
9164
else begin
9165
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9166
    // inherit the previous pc.
9167
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
9168
//       (IsBrk(iqentry_instr[idp7(tail)]) && !iqentry_instr[idm1(tail)][15] && iqentry_v[idm1(tail)]))
9169
//       iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
9170
//    else
9171
                iqentry_pc   [tail] <= fetchbuf1_pc;
9172
end
9173
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf1_instr);
9174
        iqentry_tgt  [tail]    <= Rt1;
9175
        iqentry_Ra   [tail]    <= Ra1;
9176
        iqentry_Rb   [tail]    <= Rb1;
9177
        iqentry_Rc   [tail]    <= Rc1;
9178
        iqentry_vl   [tail]    <=  vl;
9179
        iqentry_ven  [tail]    <=   venno;
9180
        iqentry_exc  [tail]    <=   `EXC_NONE;
9181
        iqentry_a1   [tail]    <=       rfoa1;
9182
        iqentry_a1_v [tail]    <=       Source1Valid(fetchbuf1_instr) | regIsValid[Ra1s];
9183
        iqentry_a1_s [tail]    <=       rf_source[Ra1s];
9184
        iqentry_a2   [tail]    <=       rfob1;
9185
        iqentry_a2_v [tail]    <=       Source2Valid(fetchbuf1_instr) | regIsValid[Rb1s];
9186
        iqentry_a2_s [tail]    <=       rf_source[Rb1s];
9187
        iqentry_a3   [tail]    <=       rfoc1;
9188
        iqentry_a3_v [tail]    <=       Source3Valid(fetchbuf1_instr) | regIsValid[Rc1s];
9189
        iqentry_a3_s [tail]    <=       rf_source[Rc1s];
9190
end
9191
endtask
9192
 
9193
// This task takes care of commits for things other than the register file.
9194
task oddball_commit;
9195
input v;
9196
input [`QBITS] head;
9197
reg thread;
9198
begin
9199
    thread = iqentry_thrd[head];
9200
    if (v) begin
9201
        if (|iqentry_exc[head]) begin
9202
            excmiss <= TRUE;
9203
`ifdef SUPPORT_SMT
9204 51 robfinch
                excmisspc <= {tvec[3'd0][31:8],1'b0,ol[thread],5'h00};
9205 48 robfinch
            excthrd <= iqentry_thrd[head];
9206
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
9207
            epc0[thread] <= iqentry_pc[head]+ 32'd4;
9208
            epc1[thread] <= epc0[thread];
9209
            epc2[thread] <= epc1[thread];
9210
            epc3[thread] <= epc2[thread];
9211
            epc4[thread] <= epc3[thread];
9212
            epc5[thread] <= epc4[thread];
9213
            epc6[thread] <= epc5[thread];
9214
            epc7[thread] <= epc6[thread];
9215
            epc8[thread] <= epc7[thread];
9216
            im_stack[thread] <= {im_stack[thread][27:0],im};
9217
            ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9218
            pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9219
            rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
9220
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
9221
            mstatus[thread][5:3] <= 3'd0;
9222
            mstatus[thread][13:6] <= 8'h00;
9223
            mstatus[thread][19:14] <= 6'd0;
9224
`else
9225 51 robfinch
                excmisspc <= {tvec[3'd0][31:8],1'b0,ol,5'h00};
9226 48 robfinch
            excthrd <= iqentry_thrd[head];
9227
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
9228
            epc0 <= iqentry_pc[head]+ 32'd4;
9229
            epc1 <= epc0;
9230
            epc2 <= epc1;
9231
            epc3 <= epc2;
9232
            epc4 <= epc3;
9233
            epc5 <= epc4;
9234
            epc6 <= epc5;
9235
            epc7 <= epc6;
9236
            epc8 <= epc7;
9237
            im_stack <= {im_stack[27:0],im};
9238
            ol_stack <= {ol_stack[13:0],ol};
9239
            pl_stack <= {pl_stack[55:0],cpl};
9240
            rs_stack <= {rs_stack[55:0],rgs};
9241
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
9242
            mstatus[5:3] <= 3'd0;
9243
            mstatus[13:6] <= 8'h00;
9244
            mstatus[19:14] <= 6'd0;
9245
`endif
9246 49 robfinch
                                                wb_en <= `TRUE;
9247 48 robfinch
            sema[0] <= 1'b0;
9248
            ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9249
`ifdef SUPPORT_DBG
9250
            dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9251
            dbg_ctrl[63] <= FALSE;
9252
`endif
9253
        end
9254
        else
9255
        case(iqentry_instr[head][`INSTRUCTION_OP])
9256
        `BRK:
9257
                        // BRK is treated as a nop unless it's a software interrupt or a
9258
                        // hardware interrupt at a higher priority than the current priority.
9259
                if ((iqentry_instr[head][23:19] > 5'd0) || iqentry_instr[head][18:16] > im) begin
9260
                            excmiss <= TRUE;
9261
`ifdef SUPPORT_SMT
9262 51 robfinch
                        excmisspc <= {tvec[3'd0][31:8],1'b0,ol[thread],5'h00};
9263 48 robfinch
                        excthrd <= iqentry_thrd[head];
9264
                    epc0[thread] <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
9265
                    epc1[thread] <= epc0[thread];
9266
                    epc2[thread] <= epc1[thread];
9267
                    epc3[thread] <= epc2[thread];
9268
                    epc4[thread] <= epc3[thread];
9269
                    epc5[thread] <= epc4[thread];
9270
                    epc6[thread] <= epc5[thread];
9271
                    epc7[thread] <= epc6[thread];
9272
                    epc8[thread] <= epc7[thread];
9273
                    im_stack[thread] <= {im_stack[thread][27:0],im};
9274
                    ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9275
                    pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9276
                    rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
9277
                    mstatus[thread][19:14] <= 6'd0;
9278
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
9279
                    mstatus[thread][5:3] <= 3'd0;
9280
                        mstatus[thread][13:6] <= 8'h00;
9281
                    // For hardware interrupts only, set a new mask level
9282
                    // Select register set according to interrupt level
9283
                    if (iqentry_instr[head][23:19]==5'd0) begin
9284
                        mstatus[thread][2:0] <= 3'd7;//iqentry_instr[head][18:16];
9285
                        mstatus[thread][42:40] <= iqentry_instr[head][18:16];
9286
                        mstatus[thread][19:14] <= {3'b0,iqentry_instr[head][18:16]};
9287
                    end
9288
                    else
9289
                        mstatus[thread][19:14] <= 6'd0;
9290
`else
9291 51 robfinch
                        excmisspc <= {tvec[3'd0][31:8],1'b0,ol,5'h00};
9292 48 robfinch
                        excthrd <= iqentry_thrd[head];
9293
                    epc0 <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
9294
                    epc1 <= epc0;
9295
                    epc2 <= epc1;
9296
                    epc3 <= epc2;
9297
                    epc4 <= epc3;
9298
                    epc5 <= epc4;
9299
                    epc6 <= epc5;
9300
                    epc7 <= epc6;
9301
                    epc8 <= epc7;
9302
                    im_stack <= {im_stack[27:0],im};
9303
                    ol_stack <= {ol_stack[13:0],ol};
9304
                    pl_stack <= {pl_stack[55:0],cpl};
9305
                    rs_stack <= {rs_stack[55:0],rgs};
9306
                    mstatus[19:14] <= 6'd0;
9307
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
9308
                    mstatus[5:3] <= 3'd0;
9309
                        mstatus[13:6] <= 8'h00;
9310
                    // For hardware interrupts only, set a new mask level
9311
                    // Select register set according to interrupt level
9312
                    if (iqentry_instr[head][23:19]==5'd0) begin
9313
                        mstatus[2:0] <= 3'd7;//iqentry_instr[head][18:16];
9314
                        mstatus[42:40] <= iqentry_instr[head][18:16];
9315
                        mstatus[19:14] <= {3'b0,iqentry_instr[head][18:16]};
9316
                    end
9317
                    else
9318
                        mstatus[19:14] <= 6'd0;
9319
`endif
9320
                    sema[0] <= 1'b0;
9321
                    ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9322
`ifdef SUPPORT_DBG
9323
                    dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9324
                    dbg_ctrl[63] <= FALSE;
9325
`endif
9326
                end
9327
        `IVECTOR:
9328
            casez(iqentry_tgt[head])
9329
            8'b00100xxx:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9330
            8'b00101111:  vl <= iqentry_res[head];
9331
            default:    ;
9332
            endcase
9333
        `R2:
9334
            case(iqentry_instr[head][`INSTRUCTION_S2])
9335
            `R1:        case(iqentry_instr[head][20:16])
9336
                        `CHAIN_OFF:     cr0[18] <= 1'b0;
9337
                        `CHAIN_ON:      cr0[18] <= 1'b1;
9338
                        //`SETWB:               wbrcd[pcr[5:0]] <= 1'b1;
9339
                        default:        ;
9340
                                endcase
9341
            `VMOV:  casez(iqentry_tgt[head])
9342
                    12'b1111111_00???:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9343
                    12'b1111111_01111:  vl <= iqentry_res[head];
9344
                    default:    ;
9345
                    endcase
9346
`ifdef SUPPORT_SMT
9347
            `SEI:   mstatus[thread][2:0] <= iqentry_res[head][2:0];   // S1
9348
`else
9349
            `SEI:   mstatus[2:0] <= iqentry_res[head][2:0];   // S1
9350
`endif
9351
            `RTI:   begin
9352
                            excmiss <= TRUE;
9353
`ifdef SUPPORT_SMT
9354
                        excmisspc <= epc0[thread];
9355
                        excthrd <= thread;
9356
                        mstatus[thread][3:0] <= im_stack[thread][3:0];
9357
                        mstatus[thread][5:4] <= ol_stack[thread][1:0];
9358
                        mstatus[thread][13:6] <= pl_stack[thread][7:0];
9359
                        mstatus[thread][19:14] <= rs_stack[thread][5:0];
9360
                        im_stack[thread] <= {4'd15,im_stack[thread][27:4]};
9361
                        ol_stack[thread] <= {2'd0,ol_stack[thread][15:2]};
9362
                        pl_stack[thread] <= {8'h00,pl_stack[thread][63:8]};
9363
                        rs_stack[thread] <= {8'h00,rs_stack[thread][63:8]};
9364
                    epc0[thread] <= epc1[thread];
9365
                    epc1[thread] <= epc2[thread];
9366
                    epc2[thread] <= epc3[thread];
9367
                    epc3[thread] <= epc4[thread];
9368
                    epc4[thread] <= epc5[thread];
9369
                    epc5[thread] <= epc6[thread];
9370
                    epc6[thread] <= epc7[thread];
9371
                    epc7[thread] <= epc8[thread];
9372 51 robfinch
                    epc8[thread] <= {tvec[0][31:8], 1'b0, ol[thread], 5'h0};
9373 48 robfinch
`else
9374
                        excmisspc <= epc0;
9375
                        excthrd <= thread;
9376
                        mstatus[3:0] <= im_stack[3:0];
9377
                        mstatus[5:4] <= ol_stack[1:0];
9378
                        mstatus[13:6] <= pl_stack[7:0];
9379
                        mstatus[19:14] <= rs_stack[5:0];
9380
                        im_stack <= {4'd15,im_stack[31:4]};
9381
                        ol_stack <= {2'd0,ol_stack[15:2]};
9382
                        pl_stack <= {8'h00,pl_stack[63:8]};
9383
                        rs_stack <= {8'h00,rs_stack[63:8]};
9384
                    epc0 <= epc1;
9385
                    epc1 <= epc2;
9386
                    epc2 <= epc3;
9387
                    epc3 <= epc4;
9388
                    epc4 <= epc5;
9389
                    epc5 <= epc6;
9390
                    epc6 <= epc7;
9391
                    epc7 <= epc8;
9392 51 robfinch
                    epc8 <= {tvec[0][31:8], 1'b0, ol, 5'h0};
9393 48 robfinch
`endif
9394
                    sema[0] <= 1'b0;
9395
                    sema[iqentry_res[head][5:0]] <= 1'b0;
9396
                    vqe0  <= ve_hold[ 5: 0];
9397
                    vqet0 <= ve_hold[21:16];
9398
                    vqe1  <= ve_hold[37:32];
9399
                    vqet1 <= ve_hold[53:48];
9400
`ifdef SUPPORT_DBG
9401
                    dbg_ctrl[62:55] <= {FALSE,dbg_ctrl[62:56]};
9402
                    dbg_ctrl[63] <= dbg_ctrl[55];
9403
`endif
9404
                    end
9405 49 robfinch
            default: ;
9406
            endcase
9407
        `MEMNDX:
9408
            case(iqentry_instr[head][`INSTRUCTION_S2])
9409 48 robfinch
            `CACHEX:
9410 49 robfinch
                    case(iqentry_instr[head][22:18])
9411 48 robfinch
                    5'h03:  invic <= TRUE;
9412
                    5'h10:  cr0[30] <= FALSE;
9413
                    5'h11:  cr0[30] <= TRUE;
9414
                    default:    ;
9415
                    endcase
9416
            default: ;
9417
            endcase
9418
        `CSRRW:
9419
                        begin
9420 51 robfinch
                        write_csr(iqentry_instr[head][31:18],iqentry_a1[head],thread);
9421 48 robfinch
                        end
9422
        `REX:
9423
`ifdef SUPPORT_SMT
9424
            // Can only redirect to a lower level
9425
            if (ol[thread] < iqentry_instr[head][13:11]) begin
9426
                mstatus[thread][5:3] <= iqentry_instr[head][13:11];
9427
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol[thread]}];
9428
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol[thread]}];
9429
                mstatus[thread][13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
9430
            end
9431
`else
9432
            if (ol < iqentry_instr[head][13:11]) begin
9433
                mstatus[5:3] <= iqentry_instr[head][13:11];
9434
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol}];
9435
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol}];
9436
                mstatus[13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
9437
            end
9438
`endif
9439
        `CACHE:
9440 49 robfinch
            case(iqentry_instr[head][17:13])
9441 48 robfinch
            5'h03:  invic <= TRUE;
9442
            5'h10:  cr0[30] <= FALSE;
9443
            5'h11:  cr0[30] <= TRUE;
9444
            default:    ;
9445
            endcase
9446
        `FLOAT:
9447
            case(iqentry_instr[head][`INSTRUCTION_S2])
9448 49 robfinch
            `FRM: begin
9449 51 robfinch
                                fp_rm <= iqentry_res[head][2:0];
9450 49 robfinch
                                end
9451 48 robfinch
            `FCX:
9452
                begin
9453 51 robfinch
                    fp_sx <= fp_sx & ~iqentry_res[head][5];
9454
                    fp_inex <= fp_inex & ~iqentry_res[head][4];
9455
                    fp_dbzx <= fp_dbzx & ~(iqentry_res[head][3]|iqentry_res[head][0]);
9456
                    fp_underx <= fp_underx & ~iqentry_res[head][2];
9457
                    fp_overx <= fp_overx & ~iqentry_res[head][1];
9458
                    fp_giopx <= fp_giopx & ~iqentry_res[head][0];
9459
                    fp_infdivx <= fp_infdivx & ~iqentry_res[head][0];
9460
                    fp_zerozerox <= fp_zerozerox & ~iqentry_res[head][0];
9461
                    fp_subinfx   <= fp_subinfx   & ~iqentry_res[head][0];
9462
                    fp_infzerox  <= fp_infzerox  & ~iqentry_res[head][0];
9463
                    fp_NaNCmpx   <= fp_NaNCmpx   & ~iqentry_res[head][0];
9464
                    fp_swtx <= 1'b0;
9465 48 robfinch
                end
9466
            `FDX:
9467
                begin
9468 51 robfinch
                    fp_inexe <= fp_inexe     & ~iqentry_res[head][4];
9469
                    fp_dbzxe <= fp_dbzxe     & ~iqentry_res[head][3];
9470
                    fp_underxe <= fp_underxe & ~iqentry_res[head][2];
9471
                    fp_overxe <= fp_overxe   & ~iqentry_res[head][1];
9472
                    fp_invopxe <= fp_invopxe & ~iqentry_res[head][0];
9473 48 robfinch
                end
9474
            `FEX:
9475
                begin
9476 51 robfinch
                    fp_inexe <= fp_inexe     | iqentry_res[head][4];
9477
                    fp_dbzxe <= fp_dbzxe     | iqentry_res[head][3];
9478
                    fp_underxe <= fp_underxe | iqentry_res[head][2];
9479
                    fp_overxe <= fp_overxe   | iqentry_res[head][1];
9480
                    fp_invopxe <= fp_invopxe | iqentry_res[head][0];
9481 48 robfinch
                end
9482
            default:
9483
                begin
9484
                    // 31 to 29 is rounding mode
9485
                    // 28 to 24 are exception enables
9486
                    // 23 is nsfp
9487
                    // 22 is a fractie
9488 51 robfinch
                    fp_fractie <= iqentry_a0[head][22];
9489
                    fp_raz <= iqentry_a0[head][21];
9490 48 robfinch
                    // 20 is a 0
9491 51 robfinch
                    fp_neg <= iqentry_a0[head][19];
9492
                    fp_pos <= iqentry_a0[head][18];
9493
                    fp_zero <= iqentry_a0[head][17];
9494
                    fp_inf <= iqentry_a0[head][16];
9495 48 robfinch
                    // 15 swtx
9496
                    // 14 
9497 51 robfinch
                    fp_inex <= fp_inex | (fp_inexe & iqentry_a0[head][14]);
9498
                    fp_dbzx <= fp_dbzx | (fp_dbzxe & iqentry_a0[head][13]);
9499
                    fp_underx <= fp_underx | (fp_underxe & iqentry_a0[head][12]);
9500
                    fp_overx <= fp_overx | (fp_overxe & iqentry_a0[head][11]);
9501 48 robfinch
                    //fp_giopx <= fp_giopx | (fp_giopxe & iqentry_res2[head][10]);
9502
                    //fp_invopx <= fp_invopx | (fp_invopxe & iqentry_res2[head][24]);
9503
                    //
9504 51 robfinch
                    fp_cvtx <= fp_cvtx |  (fp_giopxe & iqentry_a0[head][7]);
9505
                    fp_sqrtx <= fp_sqrtx |  (fp_giopxe & iqentry_a0[head][6]);
9506
                    fp_NaNCmpx <= fp_NaNCmpx |  (fp_giopxe & iqentry_a0[head][5]);
9507
                    fp_infzerox <= fp_infzerox |  (fp_giopxe & iqentry_a0[head][4]);
9508
                    fp_zerozerox <= fp_zerozerox |  (fp_giopxe & iqentry_a0[head][3]);
9509
                    fp_infdivx <= fp_infdivx | (fp_giopxe & iqentry_a0[head][2]);
9510
                    fp_subinfx <= fp_subinfx | (fp_giopxe & iqentry_a0[head][1]);
9511
                    fp_snanx <= fp_snanx | (fp_giopxe & iqentry_a0[head][0]);
9512 48 robfinch
 
9513
                end
9514
            endcase
9515
        default:    ;
9516
        endcase
9517
        // Once the flow control instruction commits, NOP it out to allow
9518
        // pending stores to be issued.
9519
        iqentry_instr[head][5:0] <= `NOP;
9520
    end
9521
end
9522
endtask
9523
 
9524
// CSR access tasks
9525
task read_csr;
9526 51 robfinch
input [11:0] csrno;
9527 48 robfinch
output [63:0] dat;
9528
input thread;
9529
begin
9530
`ifdef SUPPORT_SMT
9531
    if (csrno[11:10] >= ol[thread])
9532
`else
9533
    if (csrno[11:10] >= ol)
9534
`endif
9535
    casez(csrno[9:0])
9536
    `CSR_CR0:       dat <= cr0;
9537
    `CSR_HARTID:    dat <= hartid;
9538
    `CSR_TICK:      dat <= tick;
9539
    `CSR_PCR:       dat <= pcr;
9540
    `CSR_PCR2:      dat <= pcr2;
9541 49 robfinch
    `CSR_PMR:                           dat <= pmr;
9542 48 robfinch
    `CSR_WBRCD:         dat <= wbrcd;
9543
    `CSR_SEMA:      dat <= sema;
9544
    `CSR_SBL:       dat <= sbl;
9545
    `CSR_SBU:       dat <= sbu;
9546
    `CSR_TCB:           dat <= tcb;
9547 51 robfinch
    `CSR_FSTAT:     dat <= {fp_rgs,fp_status};
9548 48 robfinch
`ifdef SUPPORT_DBG
9549
    `CSR_DBAD0:     dat <= dbg_adr0;
9550
    `CSR_DBAD1:     dat <= dbg_adr1;
9551
    `CSR_DBAD2:     dat <= dbg_adr2;
9552
    `CSR_DBAD3:     dat <= dbg_adr3;
9553
    `CSR_DBCTRL:    dat <= dbg_ctrl;
9554
    `CSR_DBSTAT:    dat <= dbg_stat;
9555
`endif
9556
    `CSR_CAS:       dat <= cas;
9557
    `CSR_TVEC:      dat <= tvec[csrno[2:0]];
9558 52 robfinch
    `CSR_BADADR:    dat <= badaddr[{thread,csrno[11:10]}];
9559
    `CSR_CAUSE:     dat <= {48'd0,cause[{thread,csrno[11:10]}]};
9560 48 robfinch
`ifdef SUPPORT_SMT
9561
    `CSR_IM_STACK:      dat <= im_stack[thread];
9562
    `CSR_OL_STACK:      dat <= ol_stack[thread];
9563
    `CSR_PL_STACK:      dat <= pl_stack[thread];
9564
    `CSR_RS_STACK:      dat <= rs_stack[thread];
9565
    `CSR_STATUS:    dat <= mstatus[thread][63:0];
9566
    `CSR_EPC0:      dat <= epc0[thread];
9567
    `CSR_EPC1:      dat <= epc1[thread];
9568
    `CSR_EPC2:      dat <= epc2[thread];
9569
    `CSR_EPC3:      dat <= epc3[thread];
9570
    `CSR_EPC4:      dat <= epc4[thread];
9571
    `CSR_EPC5:      dat <= epc5[thread];
9572
    `CSR_EPC6:      dat <= epc6[thread];
9573
    `CSR_EPC7:      dat <= epc7[thread];
9574
`else
9575
    `CSR_IM_STACK:      dat <= im_stack;
9576
    `CSR_OL_STACK:      dat <= ol_stack;
9577
    `CSR_PL_STACK:      dat <= pl_stack;
9578
    `CSR_RS_STACK:      dat <= rs_stack;
9579
    `CSR_STATUS:    dat <= mstatus[63:0];
9580
    `CSR_EPC0:      dat <= epc0;
9581
    `CSR_EPC1:      dat <= epc1;
9582
    `CSR_EPC2:      dat <= epc2;
9583
    `CSR_EPC3:      dat <= epc3;
9584
    `CSR_EPC4:      dat <= epc4;
9585
    `CSR_EPC5:      dat <= epc5;
9586
    `CSR_EPC6:      dat <= epc6;
9587
    `CSR_EPC7:      dat <= epc7;
9588
`endif
9589
    `CSR_CODEBUF:   dat <= codebuf[csrno[5:0]];
9590
    `CSR_TIME:          dat <= wc_times;
9591
    `CSR_INFO:
9592
                    case(csrno[3:0])
9593
                    4'd0:   dat <= "Finitron";  // manufacturer
9594
                    4'd1:   dat <= "        ";
9595
                    4'd2:   dat <= "64 bit  ";  // CPU class
9596
                    4'd3:   dat <= "        ";
9597
                    4'd4:   dat <= "FT64    ";  // Name
9598
                    4'd5:   dat <= "        ";
9599
                    4'd6:   dat <= 64'd1;       // model #
9600
                    4'd7:   dat <= 64'd1;       // serial number
9601
                    4'd8:   dat <= {32'd16384,32'd16384};   // cache sizes instruction,data
9602
                    4'd9:   dat <= 64'd0;
9603
                    default:    dat <= 64'd0;
9604
                    endcase
9605
    default:    begin
9606
                        $display("Unsupported CSR:%h",csrno[10:0]);
9607
                        dat <= 64'hEEEEEEEEEEEEEEEE;
9608
                        end
9609
    endcase
9610
    else
9611
        dat <= 64'h0;
9612
end
9613
endtask
9614
 
9615
task write_csr;
9616
input [13:0] csrno;
9617
input [63:0] dat;
9618
input thread;
9619
begin
9620
`ifdef SUPPORT_SMT
9621
    if (csrno[11:10] >= ol[thread])
9622
`else
9623
    if (csrno[11:10] >= ol)
9624
`endif
9625
    case(csrno[13:12])
9626
    2'd1:   // CSRRW
9627
        casez(csrno[9:0])
9628
        `CSR_CR0:       cr0 <= dat;
9629
        `CSR_PCR:       pcr <= dat[31:0];
9630
        `CSR_PCR2:      pcr2 <= dat;
9631 49 robfinch
        `CSR_PMR:       case(`NUM_IDU)
9632
                                                0,1:     pmr[0] <= 1'b1;
9633
                                                2:
9634
                                                        begin
9635
                                                                        if (dat[1:0]==2'b00)
9636
                                                                                pmr[1:0] <= 2'b01;
9637
                                                                        else
9638
                                                                                pmr[1:0] <= dat[1:0];
9639
                                                                        pmr[63:2] <= dat[63:2];
9640
                                                                end
9641
                                                3:
9642
                                                        begin
9643
                                                                        if (dat[2:0]==3'b000)
9644
                                                                                pmr[2:0] <= 3'b001;
9645
                                                                        else
9646
                                                                                pmr[2:0] <= dat[2:0];
9647
                                                                        pmr[63:3] <= dat[63:3];
9648
                                                                end
9649
                                                default:        pmr[0] <= 1'b1;
9650
                                                endcase
9651 48 robfinch
        `CSR_WBRCD:             wbrcd <= dat;
9652
        `CSR_SEMA:      sema <= dat;
9653
        `CSR_SBL:       sbl <= dat[31:0];
9654
        `CSR_SBU:       sbu <= dat[31:0];
9655
        `CSR_TCB:               tcb <= dat;
9656 51 robfinch
        `CSR_FSTAT:             fpu_csr[37:32] <= dat[37:32];
9657 52 robfinch
        `CSR_BADADR:    badaddr[{thread,csrno[11:10]}] <= dat;
9658
        `CSR_CAUSE:     cause[{thread,csrno[11:10]}] <= dat[15:0];
9659 48 robfinch
`ifdef SUPPORT_DBG
9660
        `CSR_DBAD0:     dbg_adr0 <= dat[AMSB:0];
9661
        `CSR_DBAD1:     dbg_adr1 <= dat[AMSB:0];
9662
        `CSR_DBAD2:     dbg_adr2 <= dat[AMSB:0];
9663
        `CSR_DBAD3:     dbg_adr3 <= dat[AMSB:0];
9664
        `CSR_DBCTRL:    dbg_ctrl <= dat;
9665
`endif
9666
        `CSR_CAS:       cas <= dat;
9667
        `CSR_TVEC:      tvec[csrno[2:0]] <= dat[31:0];
9668
`ifdef SUPPORT_SMT
9669
        `CSR_IM_STACK:  im_stack[thread] <= dat[31:0];
9670
        `CSR_OL_STACK:  ol_stack[thread] <= dat[15:0];
9671
        `CSR_PL_STACK:  pl_stack[thread] <= dat;
9672
        `CSR_RS_STACK:  rs_stack[thread] <= dat;
9673
        `CSR_STATUS:    mstatus[thread][63:0] <= dat;
9674
        `CSR_EPC0:      epc0[thread] <= dat;
9675
        `CSR_EPC1:      epc1[thread] <= dat;
9676
        `CSR_EPC2:      epc2[thread] <= dat;
9677
        `CSR_EPC3:      epc3[thread] <= dat;
9678
        `CSR_EPC4:      epc4[thread] <= dat;
9679
        `CSR_EPC5:      epc5[thread] <= dat;
9680
        `CSR_EPC6:      epc6[thread] <= dat;
9681
        `CSR_EPC7:      epc7[thread] <= dat;
9682
`else
9683
        `CSR_IM_STACK:  im_stack <= dat[31:0];
9684
        `CSR_OL_STACK:  ol_stack <= dat[15:0];
9685
        `CSR_PL_STACK:  pl_stack <= dat;
9686
        `CSR_RS_STACK:  rs_stack <= dat;
9687
        `CSR_STATUS:    mstatus[63:0] <= dat;
9688
        `CSR_EPC0:      epc0 <= dat;
9689
        `CSR_EPC1:      epc1 <= dat;
9690
        `CSR_EPC2:      epc2 <= dat;
9691
        `CSR_EPC3:      epc3 <= dat;
9692
        `CSR_EPC4:      epc4 <= dat;
9693
        `CSR_EPC5:      epc5 <= dat;
9694
        `CSR_EPC6:      epc6 <= dat;
9695
        `CSR_EPC7:      epc7 <= dat;
9696
`endif
9697
                `CSR_TIME:              begin
9698
                                                ld_time <= 6'h3f;
9699
                                                wc_time_dat <= dat;
9700
                                                end
9701
        `CSR_CODEBUF:   codebuf[csrno[5:0]] <= dat;
9702
        default:    ;
9703
        endcase
9704
    2'd2:   // CSRRS
9705
        case(csrno[9:0])
9706
        `CSR_CR0:       cr0 <= cr0 | dat;
9707
        `CSR_PCR:       pcr[31:0] <= pcr[31:0] | dat[31:0];
9708
        `CSR_PCR2:      pcr2 <= pcr2 | dat;
9709 49 robfinch
        `CSR_PMR:                               pmr <= pmr | dat;
9710 48 robfinch
        `CSR_WBRCD:             wbrcd <= wbrcd | dat;
9711
`ifdef SUPPORT_DBG
9712
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl | dat;
9713
`endif
9714
        `CSR_SEMA:      sema <= sema | dat;
9715
`ifdef SUPPORT_SMT
9716
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] | dat;
9717
`else
9718
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] | dat;
9719
`endif
9720
        default:    ;
9721
        endcase
9722
    2'd3:   // CSRRC
9723
        case(csrno[9:0])
9724
        `CSR_CR0:       cr0 <= cr0 & ~dat;
9725
        `CSR_PCR:       pcr <= pcr & ~dat;
9726
        `CSR_PCR2:      pcr2 <= pcr2 & ~dat;
9727 49 robfinch
        `CSR_PMR:                       begin
9728
                                                                if (dat[1:0]==2'b11)
9729
                                                                        pmr[1:0] <= 2'b01;
9730
                                                                else
9731
                                                                        pmr[1:0] <= pmr[1:0] & ~dat[1:0];
9732
                                                                pmr[63:2] <= pmr[63:2] & ~dat[63:2];
9733
                                                                end
9734 48 robfinch
        `CSR_WBRCD:             wbrcd <= wbrcd & ~dat;
9735
`ifdef SUPPORT_DBG
9736
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl & ~dat;
9737
`endif
9738
        `CSR_SEMA:      sema <= sema & ~dat;
9739
`ifdef SUPPORT_SMT
9740
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] & ~dat;
9741
`else
9742
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] & ~dat;
9743
`endif
9744
        default:    ;
9745
        endcase
9746
    default:    ;
9747
    endcase
9748
end
9749
endtask
9750
 
9751
 
9752
endmodule
9753
 
9754
 
9755
module decoder5 (num, out);
9756
input [4:0] num;
9757
output [31:1] out;
9758
reg [31:1] out;
9759
 
9760
always @(num)
9761
case (num)
9762
    5'd0 :      out <= 31'b0000000000000000000000000000000;
9763
    5'd1 :      out <= 31'b0000000000000000000000000000001;
9764
    5'd2 :      out <= 31'b0000000000000000000000000000010;
9765
    5'd3 :      out <= 31'b0000000000000000000000000000100;
9766
    5'd4 :      out <= 31'b0000000000000000000000000001000;
9767
    5'd5 :      out <= 31'b0000000000000000000000000010000;
9768
    5'd6 :      out <= 31'b0000000000000000000000000100000;
9769
    5'd7 :      out <= 31'b0000000000000000000000001000000;
9770
    5'd8 :      out <= 31'b0000000000000000000000010000000;
9771
    5'd9 :      out <= 31'b0000000000000000000000100000000;
9772
    5'd10:      out <= 31'b0000000000000000000001000000000;
9773
    5'd11:      out <= 31'b0000000000000000000010000000000;
9774
    5'd12:      out <= 31'b0000000000000000000100000000000;
9775
    5'd13:      out <= 31'b0000000000000000001000000000000;
9776
    5'd14:      out <= 31'b0000000000000000010000000000000;
9777
    5'd15:      out <= 31'b0000000000000000100000000000000;
9778
    5'd16:      out <= 31'b0000000000000001000000000000000;
9779
    5'd17:      out <= 31'b0000000000000010000000000000000;
9780
    5'd18:      out <= 31'b0000000000000100000000000000000;
9781
    5'd19:      out <= 31'b0000000000001000000000000000000;
9782
    5'd20:      out <= 31'b0000000000010000000000000000000;
9783
    5'd21:      out <= 31'b0000000000100000000000000000000;
9784
    5'd22:      out <= 31'b0000000001000000000000000000000;
9785
    5'd23:      out <= 31'b0000000010000000000000000000000;
9786
    5'd24:      out <= 31'b0000000100000000000000000000000;
9787
    5'd25:      out <= 31'b0000001000000000000000000000000;
9788
    5'd26:      out <= 31'b0000010000000000000000000000000;
9789
    5'd27:      out <= 31'b0000100000000000000000000000000;
9790
    5'd28:      out <= 31'b0001000000000000000000000000000;
9791
    5'd29:      out <= 31'b0010000000000000000000000000000;
9792
    5'd30:      out <= 31'b0100000000000000000000000000000;
9793
    5'd31:      out <= 31'b1000000000000000000000000000000;
9794
endcase
9795
 
9796
endmodule
9797
 
9798
module decoder6 (num, out);
9799
input [5:0] num;
9800
output [63:1] out;
9801
 
9802
wire [63:0] out1;
9803
 
9804
assign out1 = 64'd1 << num;
9805
assign out = out1[63:1];
9806
 
9807
endmodule
9808
 
9809
module decoder7 (num, out);
9810
input [6:0] num;
9811
output [127:1] out;
9812
 
9813
wire [127:0] out1;
9814
 
9815
assign out1 = 128'd1 << num;
9816
assign out = out1[127:1];
9817
 
9818
endmodule
9819
 
9820
module decoder8 (num, out);
9821
input [7:0] num;
9822
output [255:1] out;
9823
 
9824
wire [255:0] out1;
9825
 
9826
assign out1 = 256'd1 << num;
9827
assign out = out1[255:1];
9828
 
9829
endmodule
9830
 

powered by: WebSVN 2.1.0

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