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

Subversion Repositories thor

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

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

powered by: WebSVN 2.1.0

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