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

Subversion Repositories thor

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

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

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2017-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      FT64.v
9
//      Features include:
10
//  - 16/32/48 bit instructions
11
//  - vector instruction set,
12
//  - SIMD instructions
13
//  - data width of 64 bits
14
//      - 32 general purpose registers
15
//  - 32 floating point registers
16
//      - 32 vector registers, length 63
17
//  - powerful branch prediction
18
//  - branch target buffer (BTB)
19
//  - return address predictor (RSB)
20
//  - bus interface unit
21
//  - instruction and data caches
22
//  - asynchronous logic loops for issue and branch miss
23
//    re-written for synchronous operation, not as elegant
24
//    but required for operation in an FPGA
25
//      - fine-grained simultaneous multi-threading (SMT)
26
//
27
// This source file is free software: you can redistribute it and/or modify 
28
// it under the terms of the GNU Lesser General Public License as published 
29
// by the Free Software Foundation, either version 3 of the License, or     
30
// (at your option) any later version.                                      
31
//                                                                          
32
// This source file is distributed in the hope that it will be useful,      
33
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
34
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
35
// GNU General Public License for more details.                             
36
//                                                                          
37
// You should have received a copy of the GNU General Public License        
38
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
39
//
40 55 robfinch
// Approx 41,000 LUTs. 66,000 LC's.
41 48 robfinch
// ============================================================================
42
//
43 49 robfinch
`include "FT64_config.vh"
44 48 robfinch
`include "FT64_defines.vh"
45
 
46
module FT64(hartid, rst, clk_i, clk4x, tm_clk_i, irq_i, vec_i, bte_o, cti_o, cyc_o, stb_o, ack_i, err_i, we_o, sel_o, adr_o, dat_o, dat_i,
47
    ol_o, pcr_o, pcr2_o, exv_i, rdv_i, wrv_i, icl_o, sr_o, cr_o, rbi_i, signal_i);
48
input [63:0] hartid;
49
input rst;
50
input clk_i;
51
input clk4x;
52
input tm_clk_i;
53 49 robfinch
input [3:0] irq_i;
54 48 robfinch
input [7:0] vec_i;
55
output reg [1:0] bte_o;
56
output reg [2:0] cti_o;
57
output reg cyc_o;
58
output reg stb_o;
59
input ack_i;
60
input err_i;
61
output reg we_o;
62
output reg [7:0] sel_o;
63 49 robfinch
output reg [`ABITS] adr_o;
64 48 robfinch
output reg [63:0] dat_o;
65
input [63:0] dat_i;
66
output reg [1:0] ol_o;
67
output [31:0] pcr_o;
68
output [63:0] pcr2_o;
69
input exv_i;
70
input rdv_i;
71
input wrv_i;
72
output reg icl_o;
73
output reg cr_o;
74
output reg sr_o;
75
input rbi_i;
76
input [31:0] signal_i;
77
 
78
parameter TM_CLKFREQ = 20000000;
79
parameter QENTRIES = `QENTRIES;
80
parameter RSTPC = 32'hFFFC0100;
81
parameter BRKPC = 32'hFFFC0000;
82
`ifdef SUPPORT_SMT
83
parameter PREGS = 256;   // number of physical registers - 1
84
parameter AREGS = 256;   // number of architectural registers
85
`else
86
parameter PREGS = 128;
87
parameter AREGS = 128;
88
`endif
89
parameter RBIT = 11;
90
parameter DEBUG = 1'b0;
91
parameter NMAP = QENTRIES;
92
parameter BRANCH_PRED = 1'b0;
93
parameter SUP_TXE = 1'b0;
94 55 robfinch
parameter SUP_VECTOR = `SUPPORT_VECTOR;
95 48 robfinch
parameter DBW = 64;
96
parameter ABW = 32;
97
parameter AMSB = ABW-1;
98
parameter NTHREAD = 1;
99
reg [3:0] i;
100
integer n;
101 52 robfinch
integer j, k;
102 48 robfinch
genvar g;
103
parameter TRUE = 1'b1;
104
parameter FALSE = 1'b0;
105
// Memory access sizes
106
parameter byt = 3'd0;
107
parameter wyde = 3'd1;
108
parameter tetra = 3'd2;
109
parameter octa = 3'd3;
110
// IQ states
111
parameter IQS_IDLE = 2'd0;
112
parameter IQS_AGEN = 2'd1;
113
parameter IQS_LDDONE = 2'd2;
114
parameter IQS_S3 = 2'd3;
115
 
116
wire clk;
117 50 robfinch
//BUFG uclkb1
118
//(
119
//      .I(clk_i),
120
//      .O(clk)
121
//);
122
assign clk = clk_i;
123 48 robfinch
 
124
wire dc_ack;
125
wire acki = ack_i|dc_ack;
126 57 robfinch
wire [RBIT:0] Ra0, Ra1, Ra2;
127
wire [RBIT:0] Rb0, Rb1, Rb2;
128
wire [RBIT:0] Rc0, Rc1, Rc2;
129
wire [RBIT:0] Rt0, Rt1, Rt2;
130 48 robfinch
wire [63:0] rfoa0,rfob0,rfoc0,rfoc0a;
131
wire [63:0] rfoa1,rfob1,rfoc1,rfoc1a;
132 57 robfinch
wire [63:0] rfoa2,rfob2,rfoc2,rfoc2a;
133 48 robfinch
`ifdef SUPPORT_SMT
134
wire [7:0] Ra0s = {Ra0[7:0]};
135
wire [7:0] Ra1s = {Ra1[7:0]};
136 57 robfinch
wire [7:0] Ra2s = {Ra2[7:0]};
137 48 robfinch
wire [7:0] Rb0s = {Rb0[7:0]};
138
wire [7:0] Rb1s = {Rb1[7:0]};
139 57 robfinch
wire [7:0] Rb2s = {Rb2[7:0]};
140 48 robfinch
wire [7:0] Rc0s = {Rc0[7:0]};
141
wire [7:0] Rc1s = {Rc1[7:0]};
142 57 robfinch
wire [7:0] Rc2s = {Rc2[7:0]};
143 48 robfinch
wire [7:0] Rt0s = {Rt0[7:0]};
144
wire [7:0] Rt1s = {Rt1[7:0]};
145 57 robfinch
wire [7:0] Rt2s = {Rt2[7:0]};
146 48 robfinch
`else
147
wire [6:0] Ra0s = {Ra0[7],Ra0[5:0]};
148
wire [6:0] Ra1s = {Ra1[7],Ra1[5:0]};
149 57 robfinch
wire [6:0] Ra2s = {Ra2[7],Ra2[5:0]};
150 48 robfinch
wire [6:0] Rb0s = {Rb0[7],Rb0[5:0]};
151
wire [6:0] Rb1s = {Rb1[7],Rb1[5:0]};
152 57 robfinch
wire [6:0] Rb2s = {Rb2[7],Rb2[5:0]};
153 48 robfinch
wire [6:0] Rc0s = {Rc0[7],Rc0[5:0]};
154
wire [6:0] Rc1s = {Rc1[7],Rc1[5:0]};
155 57 robfinch
wire [6:0] Rc2s = {Rc2[7],Rc2[5:0]};
156 48 robfinch
wire [6:0] Rt0s = {Rt0[7],Rt0[5:0]};
157
wire [6:0] Rt1s = {Rt1[7],Rt1[5:0]};
158 57 robfinch
wire [6:0] Rt2s = {Rt2[7],Rt2[5:0]};
159 48 robfinch
/*
160
wire [5:0] Ra0s = {Ra0[5:0]};
161
wire [5:0] Ra1s = {Ra1[5:0]};
162
wire [5:0] Rb0s = {Rb0[5:0]};
163
wire [5:0] Rb1s = {Rb1[5:0]};
164
wire [5:0] Rc0s = {Rc0[5:0]};
165
wire [5:0] Rc1s = {Rc1[5:0]};
166
wire [5:0] Rt0s = {Rt0[5:0]};
167
wire [5:0] Rt1s = {Rt1[5:0]};
168
*/
169
`endif
170
 
171
reg [63:0] ds [0:NTHREAD];
172
reg [63:0] ss [0:NTHREAD];
173
reg [63:0] ptrmask [0:NTHREAD];
174
reg [63:0] ptrkey = "  OBJECT";
175
reg [63:0] wbrcd;
176
 
177
reg  [PREGS-1:0] rf_v;
178 52 robfinch
reg  [5:0] rf_source[0:AREGS-1];
179 48 robfinch
initial begin
180
for (n = 0; n < AREGS; n = n + 1)
181 52 robfinch
        rf_source[n] = 6'd0;
182 48 robfinch
end
183 49 robfinch
wire [`ABITS] pc0;
184
wire [`ABITS] pc1;
185
wire [`ABITS] pc2;
186 48 robfinch
 
187
reg excmiss;
188 49 robfinch
reg [`ABITS] excmisspc;
189 48 robfinch
reg excthrd;
190
reg exception_set;
191
reg rdvq;               // accumulated read violation
192
reg errq;               // accumulated err_i input status
193
reg exvq;
194
 
195
// Vector
196 57 robfinch
reg [5:0] vqe0, vqe1, vqe2;   // vector element being queued
197
reg [5:0] vqet0, vqet1, vqet2;
198 48 robfinch
reg [7:0] vl;           // vector length
199
reg [63:0] vm [0:7];    // vector mask registers
200
reg [1:0] m2;
201
 
202 49 robfinch
reg [31:0] wb_merges;
203 48 robfinch
// CSR's
204
reg [63:0] cr0;
205
wire snr = cr0[17];             // sequence number reset
206
wire dce = cr0[30];     // data cache enable
207
wire bpe = cr0[32];     // branch predictor enable
208 52 robfinch
wire wbm = cr0[34];
209 48 robfinch
wire ctgtxe = cr0[33];
210 49 robfinch
reg [63:0] pmr;
211
wire id1_available = pmr[0];
212
wire id2_available = pmr[1];
213
wire id3_available = pmr[2];
214
wire alu0_available = pmr[8];
215
wire alu1_available = pmr[9];
216
wire fpu1_available = pmr[16];
217
wire fpu2_available = pmr[17];
218
wire mem1_available = pmr[24];
219
wire mem2_available = pmr[25];
220
wire mem3_available = pmr[26];
221
wire fcu_available = pmr[32];
222 48 robfinch
// Simply setting this flag to zero should strip out almost all the logic
223
// associated SMT.
224
`ifdef SUPPORT_SMT
225
wire thread_en = cr0[16];
226
`else
227
wire thread_en = 1'b0;
228
`endif
229
wire vechain = cr0[18];
230
reg [7:0] fcu_timeout;
231
reg [63:0] tick;
232
reg [63:0] wc_time;
233
reg [31:0] pcr;
234
reg [63:0] pcr2;
235
assign pcr_o = pcr;
236
assign pcr2_o = pcr2;
237
reg [63:0] aec;
238
reg [15:0] cause[0:15];
239
`ifdef SUPPORT_SMT
240 49 robfinch
reg [`ABITS] epc [0:NTHREAD];
241
reg [`ABITS] epc0 [0:NTHREAD];
242
reg [`ABITS] epc1 [0:NTHREAD];
243
reg [`ABITS] epc2 [0:NTHREAD];
244
reg [`ABITS] epc3 [0:NTHREAD];
245
reg [`ABITS] epc4 [0:NTHREAD];
246
reg [`ABITS] epc5 [0:NTHREAD];
247
reg [`ABITS] epc6 [0:NTHREAD];
248
reg [`ABITS] epc7 [0:NTHREAD];
249
reg [`ABITS] epc8 [0:NTHREAD];                   // exception pc and stack
250 48 robfinch
reg [63:0] mstatus [0:NTHREAD];           // machine status
251 49 robfinch
wire [3:0] im = mstatus[0][3:0];
252 48 robfinch
wire [1:0] ol [0:NTHREAD];
253
wire [1:0] dl [0:NTHREAD];
254
assign ol[0] = mstatus[0][5:3];   // operating level
255
assign dl[0] = mstatus[0][21:20];
256
wire [7:0] cpl [0:NTHREAD];
257
assign cpl[0] = mstatus[0][13:6]; // current privilege level
258
wire [5:0] rgs [0:NTHREAD];
259
assign rgs[0] = mstatus[0][19:14];
260
assign ol[1] = mstatus[1][5:3]; // operating level
261
assign cpl[1] = mstatus[1][13:6];       // current privilege level
262
assign rgs[1] = mstatus[1][19:14];
263
assign dl[1] = mstatus[1][21:20];
264
reg [15:0] ol_stack [0:NTHREAD];
265
reg [31:0] im_stack [0:NTHREAD];
266
reg [63:0] pl_stack [0:NTHREAD];
267
reg [63:0] rs_stack [0:NTHREAD];
268
reg [63:0] fr_stack [0:NTHREAD];
269
wire mprv = mstatus[0][55];
270
wire [5:0] fprgs = mstatus[0][25:20];
271
//assign ol_o = mprv ? ol_stack[0][2:0] : ol[0];
272
wire vca = mstatus[0][32];               // vector chaining active
273
`else
274 49 robfinch
reg [`ABITS] epc ;
275
reg [`ABITS] epc0 ;
276
reg [`ABITS] epc1 ;
277
reg [`ABITS] epc2 ;
278
reg [`ABITS] epc3 ;
279
reg [`ABITS] epc4 ;
280
reg [`ABITS] epc5 ;
281
reg [`ABITS] epc6 ;
282
reg [`ABITS] epc7 ;
283
reg [`ABITS] epc8 ;                     // exception pc and stack
284 48 robfinch
reg [63:0] mstatus ;             // machine status
285 49 robfinch
wire [3:0] im = mstatus[3:0];
286 48 robfinch
wire [1:0] ol ;
287
wire [1:0] dl;
288
assign ol = mstatus[5:3];       // operating level
289
assign dl = mstatus[21:20];
290
wire [7:0] cpl ;
291
assign cpl = mstatus[13:6];     // current privilege level
292
wire [5:0] rgs ;
293
assign rgs = mstatus[19:14];
294
reg [15:0] ol_stack ;
295
reg [31:0] im_stack ;
296
reg [63:0] pl_stack ;
297
reg [63:0] rs_stack ;
298
reg [63:0] fr_stack ;
299
wire mprv = mstatus[55];
300
wire [5:0] fprgs = mstatus[25:20];
301
//assign ol_o = mprv ? ol_stack[2:0] : ol;
302
wire vca = mstatus[32];         // vector chaining active
303
`endif
304
reg [63:0] tcb;
305 49 robfinch
reg [`ABITS] badaddr[0:15];
306
reg [`ABITS] tvec[0:7];
307 48 robfinch
reg [63:0] sema;
308
reg [63:0] vm_sema;
309
reg [63:0] cas;         // compare and swap
310
reg [63:0] ve_hold;
311
reg isCAS, isAMO, isInc, isSpt, isRMW;
312
reg [`QBITS] casid;
313 49 robfinch
reg [`ABITS] sbl, sbu;
314 48 robfinch
reg [4:0] regLR = 5'd29;
315
 
316 51 robfinch
reg [2:0] fp_rm;
317
reg fp_inexe;
318
reg fp_dbzxe;
319
reg fp_underxe;
320
reg fp_overxe;
321
reg fp_invopxe;
322
reg fp_giopxe;
323
reg fp_nsfp = 1'b0;
324
reg fp_fractie;
325
reg fp_raz;
326 48 robfinch
 
327 51 robfinch
reg fp_neg;
328
reg fp_pos;
329
reg fp_zero;
330
reg fp_inf;
331 48 robfinch
 
332 51 robfinch
reg fp_inex;            // inexact exception
333
reg fp_dbzx;            // divide by zero exception
334
reg fp_underx;          // underflow exception
335
reg fp_overx;           // overflow exception
336
reg fp_giopx;           // global invalid operation exception
337
reg fp_sx;                      // summary exception
338
reg fp_swtx;        // software triggered exception
339
reg fp_gx;
340
reg fp_invopx;
341 48 robfinch
 
342 51 robfinch
reg fp_infzerox;
343
reg fp_zerozerox;
344
reg fp_subinfx;
345
reg fp_infdivx;
346
reg fp_NaNCmpx;
347
reg fp_cvtx;
348
reg fp_sqrtx;
349
reg fp_snanx;
350 48 robfinch
 
351 51 robfinch
wire [31:0] fp_status = {
352 48 robfinch
 
353 51 robfinch
        fp_rm,
354
        fp_inexe,
355
        fp_dbzxe,
356
        fp_underxe,
357
        fp_overxe,
358
        fp_invopxe,
359
        fp_nsfp,
360 48 robfinch
 
361 51 robfinch
        fp_fractie,
362
        fp_raz,
363 48 robfinch
        1'b0,
364 51 robfinch
        fp_neg,
365
        fp_pos,
366
        fp_zero,
367
        fp_inf,
368 48 robfinch
 
369 51 robfinch
        fp_swtx,
370
        fp_inex,
371
        fp_dbzx,
372
        fp_underx,
373
        fp_overx,
374
        fp_giopx,
375
        fp_gx,
376
        fp_sx,
377 48 robfinch
 
378 51 robfinch
        fp_cvtx,
379
        fp_sqrtx,
380
        fp_NaNCmpx,
381
        fp_infzerox,
382
        fp_zerozerox,
383
        fp_infdivx,
384
        fp_subinfx,
385
        fp_snanx
386 48 robfinch
        };
387
 
388 51 robfinch
reg [63:0] fpu_csr;
389
wire [5:0] fp_rgs = fpu_csr[37:32];
390 48 robfinch
 
391
//reg [25:0] m[0:8191];
392
reg  [3:0] panic;                // indexes the message structure
393
reg [128:0] message [0:15];       // indexed by panic
394
 
395
wire int_commit;
396
reg StatusHWI;
397 49 robfinch
reg [47:0] insn0, insn1, insn2;
398 52 robfinch
wire [47:0] insn0a, insn1b, insn2b;
399
reg [47:0] insn1a, insn2a;
400 48 robfinch
// Only need enough bits in the seqnence number to cover the instructions in
401
// the queue plus an extra count for skipping on branch misses. In this case
402
// that would be four bits minimum (count 0 to 8). 
403
reg [31:0] seq_num;
404
reg [31:0] seq_num1;
405 57 robfinch
reg [31:0] seq_num2;
406 48 robfinch
wire [63:0] rdat0,rdat1,rdat2;
407
reg [63:0] xdati;
408
 
409 57 robfinch
reg canq1, canq2, canq3;
410 48 robfinch
reg queued1;
411
reg queued2;
412 57 robfinch
reg queued3;
413 48 robfinch
reg queuedNop;
414
 
415
reg [47:0] codebuf[0:63];
416 52 robfinch
reg [QENTRIES-1:0] setpred;
417 48 robfinch
 
418
// instruction queue (ROB)
419
reg [31:0]  iqentry_sn   [0:QENTRIES-1];  // instruction sequence number
420
reg [QENTRIES-1:0] iqentry_v;                    // entry valid?  -- this should be the first bit
421
reg [QENTRIES-1:0] iqentry_iv;           // instruction is valid
422
reg [4:0]  iqentry_is   [0:QENTRIES-1];   // source of instruction
423
reg [QENTRIES-1:0] iqentry_out;  // instruction has been issued to an ALU ... 
424
reg [QENTRIES-1:0] iqentry_done; // instruction result valid
425
reg [QENTRIES-1:0] iqentry_cmt;
426
reg [QENTRIES-1:0] iqentry_thrd;         // which thread the instruction is in
427
reg [QENTRIES-1:0] iqentry_pt;           // predict taken
428 51 robfinch
reg [QENTRIES-1:0] iqentry_bt;           // update branch target buffer
429 52 robfinch
reg [QENTRIES-1:0] iqentry_takb; // take branch record
430 51 robfinch
reg [QENTRIES-1:0] iqentry_jal;
431 48 robfinch
reg [QENTRIES-1:0] iqentry_agen; // address-generate ... signifies that address is ready (only for LW/SW)
432
reg  [1:0] iqentry_state [0:QENTRIES-1];
433
reg [QENTRIES-1:0] iqentry_alu = 8'h00;  // alu type instruction
434
reg [QENTRIES-1:0] iqentry_alu0;  // only valid on alu #0
435
reg [QENTRIES-1:0] iqentry_fpu;  // floating point instruction
436
reg [QENTRIES-1:0] iqentry_fc;   // flow control instruction
437
reg [QENTRIES-1:0] iqentry_canex = 8'h00;        // true if it's an instruction that can exception
438 50 robfinch
reg [QENTRIES-1:0] iqentry_oddball = 8'h00;      // writes to register file
439 49 robfinch
reg [QENTRIES-1:0] iqentry_load; // is a memory load instruction
440 50 robfinch
reg [QENTRIES-1:0] iqentry_loadv;        // is a volatile memory load instruction
441
reg [QENTRIES-1:0] iqentry_store;        // is a memory store instruction
442 49 robfinch
reg [QENTRIES-1:0] iqentry_preload;      // is a memory preload instruction
443
reg [QENTRIES-1:0] iqentry_ldcmp;
444
reg [QENTRIES-1:0] iqentry_mem;  // touches memory: 1 if LW/SW
445
reg [QENTRIES-1:0] iqentry_memndx;  // indexed memory operation 
446 50 robfinch
reg [2:0] iqentry_memsz [0:QENTRIES-1];   // size of memory op
447 49 robfinch
reg [QENTRIES-1:0] iqentry_rmw;  // memory RMW op
448
reg [QENTRIES-1:0] iqentry_memdb;
449
reg [QENTRIES-1:0] iqentry_memsb;
450
reg [QENTRIES-1:0] iqentry_rtop;
451 48 robfinch
reg [QENTRIES-1:0] iqentry_sei;
452
reg [QENTRIES-1:0] iqentry_aq;   // memory aquire
453
reg [QENTRIES-1:0] iqentry_rl;   // memory release
454 49 robfinch
reg [QENTRIES-1:0] iqentry_shft48;
455
reg [QENTRIES-1:0] iqentry_jmp;  // changes control flow: 1 if BEQ/JALR
456 48 robfinch
reg [QENTRIES-1:0] iqentry_br;  // Bcc (for predictor)
457 51 robfinch
reg [QENTRIES-1:0] iqentry_ret;
458
reg [QENTRIES-1:0] iqentry_irq;
459
reg [QENTRIES-1:0] iqentry_brk;
460
reg [QENTRIES-1:0] iqentry_rti;
461 49 robfinch
reg [QENTRIES-1:0] iqentry_sync;  // sync instruction
462
reg [QENTRIES-1:0] iqentry_fsync;
463 48 robfinch
reg [QENTRIES-1:0] iqentry_rfw = 8'h00;  // writes to register file
464
reg  [7:0] iqentry_we   [0:QENTRIES-1];   // enable strobe
465
reg [63:0] iqentry_res   [0:QENTRIES-1];  // instruction result
466
reg [47:0] iqentry_instr[0:QENTRIES-1];   // instruction opcode
467
reg  [2:0] iqentry_insln[0:QENTRIES-1]; // instruction length
468
reg  [7:0] iqentry_exc   [0:QENTRIES-1];  // only for branches ... indicates a HALT instruction
469
reg [RBIT:0] iqentry_tgt [0:QENTRIES-1];  // Rt field or ZERO -- this is the instruction's target (if any)
470
reg  [7:0] iqentry_vl   [0:QENTRIES-1];
471
reg  [5:0] iqentry_ven  [0:QENTRIES-1];  // vector element number
472
reg [63:0] iqentry_a0    [0:QENTRIES-1];  // argument 0 (immediate)
473
reg [63:0] iqentry_a1    [0:QENTRIES-1];  // argument 1
474
reg        iqentry_a1_v [0:QENTRIES-1];  // arg1 valid
475
reg  [4:0] iqentry_a1_s  [0:QENTRIES-1];  // arg1 source (iq entry # with top bit representing ALU/DRAM bus)
476
reg [63:0] iqentry_a2    [0:QENTRIES-1];  // argument 2
477
reg        iqentry_a2_v [0:QENTRIES-1];  // arg2 valid
478
reg  [4:0] iqentry_a2_s  [0:QENTRIES-1];  // arg2 source (iq entry # with top bit representing ALU/DRAM bus)
479
reg [63:0] iqentry_a3    [0:QENTRIES-1];  // argument 3
480
reg        iqentry_a3_v [0:QENTRIES-1];  // arg3 valid
481
reg  [4:0] iqentry_a3_s  [0:QENTRIES-1];  // arg3 source (iq entry # with top bit representing ALU/DRAM bus)
482 49 robfinch
reg [`ABITS] iqentry_pc [0:QENTRIES-1];  // program counter for this instruction
483 48 robfinch
reg [RBIT:0] iqentry_Ra [0:QENTRIES-1];
484
reg [RBIT:0] iqentry_Rb [0:QENTRIES-1];
485
reg [RBIT:0] iqentry_Rc [0:QENTRIES-1];
486
// debugging
487
//reg  [4:0] iqentry_ra   [0:7];  // Ra
488
initial begin
489
for (n = 0; n < QENTRIES; n = n + 1)
490
        iqentry_a1_s[n] = 5'd0;
491
        iqentry_a2_s[n] = 5'd0;
492
        iqentry_a3_s[n] = 5'd0;
493
end
494
 
495 53 robfinch
reg [QENTRIES-1:0] iqentry_source = {QENTRIES{1'b0}};
496 48 robfinch
reg   [QENTRIES-1:0] iqentry_imm;
497 53 robfinch
reg  [QENTRIES-1:0] iqentry_memready;
498
reg  [QENTRIES-1:0] iqentry_memopsvalid;
499 48 robfinch
 
500 53 robfinch
reg  [QENTRIES-1:0] memissue = {QENTRIES{1'b0}};
501 48 robfinch
reg [1:0] missued;
502
integer last_issue;
503
reg  [QENTRIES-1:0] iqentry_memissue;
504
wire [QENTRIES-1:0] iqentry_stomp;
505
reg [3:0] stompedOnRets;
506
reg  [QENTRIES-1:0] iqentry_alu0_issue;
507
reg  [QENTRIES-1:0] iqentry_alu1_issue;
508 49 robfinch
reg  [QENTRIES-1:0] iqentry_alu2_issue;
509 48 robfinch
reg  [QENTRIES-1:0] iqentry_id1issue;
510
reg  [QENTRIES-1:0] iqentry_id2issue;
511 49 robfinch
reg  [QENTRIES-1:0] iqentry_id3issue;
512 48 robfinch
reg [1:0] iqentry_mem_islot [0:QENTRIES-1];
513
reg [QENTRIES-1:0] iqentry_fcu_issue;
514 49 robfinch
reg [QENTRIES-1:0] iqentry_fpu1_issue;
515
reg [QENTRIES-1:0] iqentry_fpu2_issue;
516 48 robfinch
 
517
wire [PREGS-1:1] livetarget;
518
wire  [PREGS-1:1] iqentry_0_livetarget;
519
wire  [PREGS-1:1] iqentry_1_livetarget;
520
wire  [PREGS-1:1] iqentry_2_livetarget;
521
wire  [PREGS-1:1] iqentry_3_livetarget;
522
wire  [PREGS-1:1] iqentry_4_livetarget;
523
wire  [PREGS-1:1] iqentry_5_livetarget;
524
wire  [PREGS-1:1] iqentry_6_livetarget;
525
wire  [PREGS-1:1] iqentry_7_livetarget;
526 52 robfinch
wire  [PREGS-1:1] iqentry_8_livetarget;
527
wire  [PREGS-1:1] iqentry_9_livetarget;
528
wire [PREGS-1:1] iqentry_livetarget [0:QENTRIES-1];
529
assign iqentry_livetarget[0] = iqentry_0_livetarget;
530
assign iqentry_livetarget[1] = iqentry_1_livetarget;
531
assign iqentry_livetarget[2] = iqentry_2_livetarget;
532
assign iqentry_livetarget[3] = iqentry_3_livetarget;
533
assign iqentry_livetarget[4] = iqentry_4_livetarget;
534
assign iqentry_livetarget[5] = iqentry_5_livetarget;
535
assign iqentry_livetarget[6] = iqentry_6_livetarget;
536
assign iqentry_livetarget[7] = iqentry_7_livetarget;
537
assign iqentry_livetarget[8] = iqentry_8_livetarget;
538
assign iqentry_livetarget[9] = iqentry_9_livetarget;
539 53 robfinch
reg [PREGS-1:1] iqentry_latestID [0:QENTRIES-1];
540 52 robfinch
reg [PREGS-1:1] iqentry_cumulative [0:QENTRIES-1];
541 53 robfinch
wire  [PREGS-1:1] iq_out [0:QENTRIES-1];
542 48 robfinch
 
543
reg  [`QBITS] tail0;
544
reg  [`QBITS] tail1;
545
reg  [`QBITS] head0;
546
reg  [`QBITS] head1;
547
reg  [`QBITS] head2;    // used only to determine memory-access ordering
548
reg  [`QBITS] head3;    // used only to determine memory-access ordering
549
reg  [`QBITS] head4;    // used only to determine memory-access ordering
550
reg  [`QBITS] head5;    // used only to determine memory-access ordering
551
reg  [`QBITS] head6;    // used only to determine memory-access ordering
552
reg  [`QBITS] head7;    // used only to determine memory-access ordering
553 52 robfinch
reg  [`QBITS] head8;
554
reg  [`QBITS] head9;
555 48 robfinch
 
556
wire take_branch0;
557
wire take_branch1;
558
 
559
reg [3:0] nop_fetchbuf;
560
wire        fetchbuf;   // determines which pair to read from & write to
561 49 robfinch
wire [3:0] fb_panic;
562 48 robfinch
 
563
wire [47:0] fetchbuf0_instr;
564
wire  [2:0] fetchbuf0_insln;
565 49 robfinch
wire [`ABITS] fetchbuf0_pc;
566 48 robfinch
wire        fetchbuf0_v;
567
wire            fetchbuf0_thrd;
568
wire        fetchbuf0_mem;
569
wire            fetchbuf0_memld;
570
wire        fetchbuf0_rfw;
571
wire [47:0] fetchbuf1_instr;
572
wire  [2:0] fetchbuf1_insln;
573 49 robfinch
wire [`ABITS] fetchbuf1_pc;
574 48 robfinch
wire        fetchbuf1_v;
575
wire            fetchbuf1_thrd;
576
wire        fetchbuf1_mem;
577
wire            fetchbuf1_memld;
578
wire        fetchbuf1_rfw;
579 57 robfinch
wire [47:0] fetchbuf2_instr;
580
wire  [2:0] fetchbuf2_insln;
581
wire [`ABITS] fetchbuf2_pc;
582
wire        fetchbuf2_v;
583
wire            fetchbuf2_thrd;
584
wire        fetchbuf2_mem;
585
wire            fetchbuf2_memld;
586
wire        fetchbuf2_rfw;
587 48 robfinch
 
588
wire [47:0] fetchbufA_instr;
589 49 robfinch
wire [`ABITS] fetchbufA_pc;
590 48 robfinch
wire        fetchbufA_v;
591
wire [47:0] fetchbufB_instr;
592 49 robfinch
wire [`ABITS] fetchbufB_pc;
593 48 robfinch
wire        fetchbufB_v;
594
wire [47:0] fetchbufC_instr;
595 49 robfinch
wire [`ABITS] fetchbufC_pc;
596 48 robfinch
wire        fetchbufC_v;
597
wire [47:0] fetchbufD_instr;
598 49 robfinch
wire [`ABITS] fetchbufD_pc;
599 48 robfinch
wire        fetchbufD_v;
600 57 robfinch
wire [47:0] fetchbufE_instr;
601
wire [`ABITS] fetchbufE_pc;
602
wire        fetchbufE_v;
603
wire [47:0] fetchbufF_instr;
604
wire [`ABITS] fetchbufF_pc;
605
wire        fetchbufF_v;
606 48 robfinch
 
607
//reg        did_branchback0;
608
//reg        did_branchback1;
609
 
610
reg         id1_v;
611
reg   [4:0] id1_id;
612
reg  [47:0] id1_instr;
613
reg   [5:0] id1_ven;
614
reg   [7:0] id1_vl;
615
reg         id1_thrd;
616
reg         id1_pt;
617
reg   [4:0] id1_Rt;
618 51 robfinch
wire [143:0] id1_bus;
619 48 robfinch
 
620
reg         id2_v;
621
reg   [4:0] id2_id;
622
reg  [47:0] id2_instr;
623
reg   [5:0] id2_ven;
624
reg   [7:0] id2_vl;
625
reg         id2_thrd;
626
reg         id2_pt;
627
reg   [4:0] id2_Rt;
628 51 robfinch
wire [143:0] id2_bus;
629 48 robfinch
 
630 49 robfinch
reg         id3_v;
631
reg   [4:0] id3_id;
632
reg  [47:0] id3_instr;
633
reg   [5:0] id3_ven;
634
reg   [7:0] id3_vl;
635
reg         id3_thrd;
636
reg         id3_pt;
637
reg   [4:0] id3_Rt;
638 51 robfinch
wire [143:0] id3_bus;
639 49 robfinch
 
640 48 robfinch
reg        alu0_ld;
641
reg        alu0_dataready;
642
wire       alu0_done;
643
wire       alu0_idle;
644
reg  [3:0] alu0_sourceid;
645
reg [47:0] alu0_instr;
646
reg        alu0_bt;
647
reg        alu0_mem;
648
reg        alu0_shft48;
649
reg [63:0] alu0_argA;
650
reg [63:0] alu0_argB;
651
reg [63:0] alu0_argC;
652
reg [63:0] alu0_argI;    // only used by BEQ
653
reg [RBIT:0] alu0_tgt;
654
reg [5:0]  alu0_ven;
655
reg        alu0_thrd;
656 49 robfinch
reg [`ABITS] alu0_pc;
657 48 robfinch
wire [63:0] alu0_bus;
658
wire [63:0] alu0b_bus;
659
wire  [3:0] alu0_id;
660 49 robfinch
wire  [`XBITS] alu0_exc;
661 48 robfinch
wire        alu0_v;
662
wire        alu0_branchmiss;
663 49 robfinch
wire [`ABITS] alu0_misspc;
664 48 robfinch
 
665
reg        alu1_ld;
666
reg        alu1_dataready;
667
wire       alu1_done;
668
wire       alu1_idle;
669
reg  [3:0] alu1_sourceid;
670
reg [47:0] alu1_instr;
671
reg        alu1_bt;
672
reg        alu1_mem;
673
reg        alu1_shft48;
674
reg [63:0] alu1_argA;
675
reg [63:0] alu1_argB;
676
reg [63:0] alu1_argC;
677
reg [63:0] alu1_argI;    // only used by BEQ
678
reg [RBIT:0] alu1_tgt;
679
reg [5:0]  alu1_ven;
680 49 robfinch
reg [`ABITS] alu1_pc;
681 48 robfinch
reg        alu1_thrd;
682
wire [63:0] alu1_bus;
683
wire [63:0] alu1b_bus;
684
wire  [3:0] alu1_id;
685 49 robfinch
wire  [`XBITS] alu1_exc;
686 48 robfinch
wire        alu1_v;
687
wire        alu1_branchmiss;
688 49 robfinch
wire [`ABITS] alu1_misspc;
689 48 robfinch
 
690 52 robfinch
wire [`XBITS] fpu_exc;
691 49 robfinch
reg        fpu1_ld;
692
reg        fpu1_dataready = 1'b1;
693
wire       fpu1_done = 1'b1;
694
wire       fpu1_idle;
695
reg  [3:0] fpu1_sourceid;
696
reg [47:0] fpu1_instr;
697
reg [63:0] fpu1_argA;
698
reg [63:0] fpu1_argB;
699
reg [63:0] fpu1_argC;
700
reg [63:0] fpu1_argI;    // only used by BEQ
701
reg [RBIT:0] fpu1_tgt;
702
reg [`ABITS] fpu1_pc;
703 53 robfinch
wire [63:0] fpu1_bus = 64'h0;
704 49 robfinch
wire  [3:0] fpu1_id;
705
wire  [`XBITS] fpu1_exc = 9'h000;
706
wire        fpu1_v;
707
wire [31:0] fpu1_status;
708 48 robfinch
 
709 49 robfinch
reg        fpu2_ld;
710
reg        fpu2_dataready = 1'b1;
711
wire       fpu2_done = 1'b1;
712
wire       fpu2_idle;
713
reg  [3:0] fpu2_sourceid;
714
reg [47:0] fpu2_instr;
715
reg [63:0] fpu2_argA;
716
reg [63:0] fpu2_argB;
717
reg [63:0] fpu2_argC;
718
reg [63:0] fpu2_argI;    // only used by BEQ
719
reg [RBIT:0] fpu2_tgt;
720
reg [`ABITS] fpu2_pc;
721 53 robfinch
wire [63:0] fpu2_bus = 64'h0;
722 49 robfinch
wire  [3:0] fpu2_id;
723
wire  [`XBITS] fpu2_exc = 9'h000;
724
wire        fpu2_v;
725
wire [31:0] fpu2_status;
726
 
727 48 robfinch
reg [63:0] waitctr;
728
reg        fcu_ld;
729
reg        fcu_dataready;
730
reg        fcu_done;
731
reg         fcu_idle = 1'b1;
732
reg  [3:0] fcu_sourceid;
733
reg [47:0] fcu_instr;
734
reg  [2:0] fcu_insln;
735 51 robfinch
reg        fcu_branch;
736 48 robfinch
reg        fcu_call;
737 51 robfinch
reg        fcu_ret;
738
reg        fcu_jal;
739
reg        fcu_brk;
740
reg        fcu_rti;
741 48 robfinch
reg        fcu_bt;
742
reg [63:0] fcu_argA;
743
reg [63:0] fcu_argB;
744
reg [63:0] fcu_argC;
745
reg [63:0] fcu_argI;     // only used by BEQ
746
reg [63:0] fcu_argT;
747
reg [63:0] fcu_argT2;
748 49 robfinch
reg [`ABITS] fcu_pc;
749
reg [`ABITS] fcu_nextpc;
750
reg [`ABITS] fcu_brdisp;
751 48 robfinch
wire [63:0] fcu_bus;
752
wire  [3:0] fcu_id;
753 49 robfinch
reg   [`XBITS] fcu_exc;
754 48 robfinch
wire        fcu_v;
755
reg        fcu_thrd;
756
reg        fcu_branchmiss;
757
reg  fcu_clearbm;
758 49 robfinch
reg [`ABITS] fcu_misspc;
759 48 robfinch
 
760
reg [63:0] rmw_argA;
761
reg [63:0] rmw_argB;
762
reg [63:0] rmw_argC;
763
wire [63:0] rmw_res;
764
reg [31:0] rmw_instr;
765
 
766 49 robfinch
// write buffer
767
reg [63:0] wb_data [0:`WB_DEPTH-1];
768
reg [`ABITS] wb_addr [0:`WB_DEPTH-1];
769
reg [1:0] wb_ol [0:`WB_DEPTH-1];
770
reg [`WB_DEPTH-1:0] wb_v;
771
reg [`WB_DEPTH-1:0] wb_rmw;
772
reg [QENTRIES-1:0] wb_id [0:`WB_DEPTH-1];
773
reg [QENTRIES-1:0] wbo_id;
774
reg [7:0] wb_sel [0:`WB_DEPTH-1];
775
reg wb_en;
776 52 robfinch
reg wb_shift;
777 49 robfinch
 
778 48 robfinch
reg branchmiss = 1'b0;
779
reg branchmiss_thrd = 1'b0;
780 49 robfinch
reg [`ABITS] misspc;
781 48 robfinch
reg  [`QBITS] missid;
782
 
783
wire take_branch;
784
wire take_branchA;
785
wire take_branchB;
786
wire take_branchC;
787
wire take_branchD;
788
 
789
wire        dram_avail;
790
reg      [2:0] dram0;    // state of the DRAM request (latency = 4; can have three in pipeline)
791
reg      [2:0] dram1;    // state of the DRAM request (latency = 4; can have three in pipeline)
792
reg      [2:0] dram2;    // state of the DRAM request (latency = 4; can have three in pipeline)
793
reg [63:0] dram0_data;
794 49 robfinch
reg [`ABITS] dram0_addr;
795 48 robfinch
reg [47:0] dram0_instr;
796
reg        dram0_rmw;
797
reg                dram0_preload;
798
reg [RBIT:0] dram0_tgt;
799
reg  [3:0] dram0_id;
800 49 robfinch
reg  [`XBITS] dram0_exc;
801 48 robfinch
reg        dram0_unc;
802
reg [2:0]  dram0_memsize;
803
reg        dram0_load;  // is a load operation
804 50 robfinch
reg        dram0_store;
805 48 robfinch
reg  [1:0] dram0_ol;
806
reg [63:0] dram1_data;
807 49 robfinch
reg [`ABITS] dram1_addr;
808 48 robfinch
reg [47:0] dram1_instr;
809
reg        dram1_rmw;
810
reg                dram1_preload;
811
reg [RBIT:0] dram1_tgt;
812
reg  [3:0] dram1_id;
813 49 robfinch
reg  [`XBITS] dram1_exc;
814 48 robfinch
reg        dram1_unc;
815
reg [2:0]  dram1_memsize;
816
reg        dram1_load;
817 50 robfinch
reg        dram1_store;
818 48 robfinch
reg  [1:0] dram1_ol;
819
reg [63:0] dram2_data;
820 49 robfinch
reg [`ABITS] dram2_addr;
821 48 robfinch
reg [47:0] dram2_instr;
822
reg        dram2_rmw;
823
reg                dram2_preload;
824
reg [RBIT:0] dram2_tgt;
825
reg  [3:0] dram2_id;
826 49 robfinch
reg  [`XBITS] dram2_exc;
827 48 robfinch
reg        dram2_unc;
828
reg [2:0]  dram2_memsize;
829
reg        dram2_load;
830 50 robfinch
reg        dram2_store;
831 48 robfinch
reg  [1:0] dram2_ol;
832
 
833
reg        dramA_v;
834
reg  [3:0] dramA_id;
835
reg [63:0] dramA_bus;
836 49 robfinch
reg  [`XBITS] dramA_exc;
837 48 robfinch
reg        dramB_v;
838
reg  [3:0] dramB_id;
839
reg [63:0] dramB_bus;
840 49 robfinch
reg  [`XBITS] dramB_exc;
841 48 robfinch
reg        dramC_v;
842
reg  [3:0] dramC_id;
843
reg [63:0] dramC_bus;
844 49 robfinch
reg  [`XBITS] dramC_exc;
845 48 robfinch
 
846
wire        outstanding_stores;
847
reg [63:0] I;    // instruction count
848
 
849
reg        commit0_v;
850
reg  [4:0] commit0_id;
851
reg [RBIT:0] commit0_tgt;
852
reg  [7:0] commit0_we = 8'h00;
853
reg [63:0] commit0_bus;
854
reg        commit1_v;
855
reg  [4:0] commit1_id;
856
reg [RBIT:0] commit1_tgt;
857
reg  [7:0] commit1_we = 8'h00;
858
reg [63:0] commit1_bus;
859
 
860
reg [4:0] bstate;
861
parameter BIDLE = 5'd0;
862
parameter B1 = 5'd1;
863
parameter B2 = 5'd2;
864
parameter B3 = 5'd3;
865
parameter B4 = 5'd4;
866
parameter B5 = 5'd5;
867
parameter B6 = 5'd6;
868
parameter B7 = 5'd7;
869
parameter B8 = 5'd8;
870
parameter B9 = 5'd9;
871
parameter B10 = 5'd10;
872
parameter B11 = 5'd11;
873
parameter B12 = 5'd12;
874
parameter B13 = 5'd13;
875
parameter B14 = 5'd14;
876
parameter B15 = 5'd15;
877
parameter B16 = 5'd16;
878
parameter B17 = 5'd17;
879
parameter B18 = 5'd18;
880
parameter B19 = 5'd19;
881
parameter B2a = 5'd20;
882
parameter B2b = 5'd21;
883
parameter B2c = 5'd22;
884
parameter B2d = 5'd23;
885
parameter B20 = 5'd24;
886
parameter B21 = 5'd25;
887
reg [1:0] bwhich;
888
reg [3:0] icstate,picstate;
889
parameter IDLE = 4'd0;
890
parameter IC1 = 4'd1;
891
parameter IC2 = 4'd2;
892
parameter IC3 = 4'd3;
893
parameter IC4 = 4'd4;
894
parameter IC5 = 4'd5;
895
parameter IC6 = 4'd6;
896
parameter IC7 = 4'd7;
897
parameter IC8 = 4'd8;
898
parameter IC9 = 4'd9;
899
parameter IC10 = 4'd10;
900
parameter IC3a = 4'd11;
901
reg invic, invdc;
902 49 robfinch
reg [1:0] icwhich;
903
reg icnxt,L2_nxt;
904
wire ihit0,ihit1,ihit2,ihitL2;
905
wire ihit = ihit0&ihit1&ihit2;
906 48 robfinch
reg phit;
907
wire threadx;
908
always @*
909
        phit <= ihit&&icstate==IDLE;
910
reg [2:0] iccnt;
911 49 robfinch
reg L1_wr0,L1_wr1,L1_wr2;
912 48 robfinch
reg L1_invline;
913 49 robfinch
reg [8:0] L1_en;
914 48 robfinch
reg [37:0] L1_adr, L2_adr;
915 49 robfinch
reg [287:0] L2_rdat;
916
wire [287:0] L2_dato;
917 48 robfinch
reg L2_xsel;
918
 
919 57 robfinch
generate begin : gRegfileInst
920
if (`WAYS > 2) begin : gb1
921
FT64_regfile2w9r_oc #(.RBIT(RBIT)) urf1
922 48 robfinch
(
923
  .clk(clk),
924
  .clk4x(clk4x),
925
  .wr0(commit0_v),
926
  .wr1(commit1_v),
927
  .we0(commit0_we),
928
  .we1(commit1_we),
929
  .wa0(commit0_tgt),
930
  .wa1(commit1_tgt),
931
  .i0(commit0_bus),
932
  .i1(commit1_bus),
933
        .rclk(~clk),
934
        .ra0(Ra0),
935
        .ra1(Rb0),
936
        .ra2(Rc0),
937 57 robfinch
        .o0(rfoa0),
938
        .o1(rfob0),
939
        .o2(rfoc0a),
940 48 robfinch
        .ra3(Ra1),
941
        .ra4(Rb1),
942
        .ra5(Rc1),
943 57 robfinch
        .o3(rfoa1),
944
        .o4(rfob1),
945
        .o5(rfoc1a),
946
        .ra6(Ra2),
947
        .ra7(Rb2),
948
        .ra8(Rc2),
949
        .o6(rfoa2),
950
        .o7(rfob2),
951
        .o8(rfoc2a)
952
);
953
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
954
assign rfoc1 = Rc1[11:6]==6'h3F ? vm[Rc1[2:0]] : rfoc1a;
955
assign rfoc2 = Rc2[11:6]==6'h3F ? vm[Rc2[2:0]] : rfoc2a;
956
end
957
else if (`WAYS > 1) begin : gb1
958
FT64_regfile2w6r_oc #(.RBIT(RBIT)) urf1
959
(
960
  .clk(clk),
961
  .clk4x(clk4x),
962
  .wr0(commit0_v),
963
  .wr1(commit1_v),
964
  .we0(commit0_we),
965
  .we1(commit1_we),
966
  .wa0(commit0_tgt),
967
  .wa1(commit1_tgt),
968
  .i0(commit0_bus),
969
  .i1(commit1_bus),
970
        .rclk(~clk),
971
        .ra0(Ra0),
972
        .ra1(Rb0),
973
        .ra2(Rc0),
974 48 robfinch
        .o0(rfoa0),
975
        .o1(rfob0),
976
        .o2(rfoc0a),
977 57 robfinch
        .ra3(Ra1),
978
        .ra4(Rb1),
979
        .ra5(Rc1),
980 48 robfinch
        .o3(rfoa1),
981
        .o4(rfob1),
982
        .o5(rfoc1a)
983
);
984
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
985
assign rfoc1 = Rc1[11:6]==6'h3F ? vm[Rc1[2:0]] : rfoc1a;
986 57 robfinch
end
987
else begin : gb1
988
FT64_regfile1w3r_oc #(.RBIT(RBIT)) urf1
989
(
990
  .clk(clk),
991
  .wr0(commit0_v),
992
  .we0(commit0_we),
993
  .wa0(commit0_tgt),
994
  .i0(commit0_bus),
995
        .rclk(~clk),
996
        .ra0(Ra0),
997
        .ra1(Rb0),
998
        .ra2(Rc0),
999
        .o0(rfoa0),
1000
        .o1(rfob0),
1001
        .o2(rfoc0a)
1002
);
1003
end
1004
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
1005
end
1006
endgenerate
1007 48 robfinch
 
1008 55 robfinch
function [3:0] fnInsLength;
1009 48 robfinch
input [47:0] ins;
1010 57 robfinch
`ifdef SUPPORT_DCI
1011 55 robfinch
if (ins[`INSTRUCTION_OP]==`CMPRSSD)
1012
        fnInsLength = 4'd2;
1013
else
1014 57 robfinch
`endif
1015 55 robfinch
        case(ins[7:6])
1016
        2'd0:   fnInsLength = 4'd4;
1017
        2'd1:   fnInsLength = 4'd6;
1018
        default:        fnInsLength = 4'd2;
1019
        endcase
1020 48 robfinch
endfunction
1021
 
1022 49 robfinch
wire [`ABITS] pc0plus6 = pc0 + 32'd6;
1023
wire [`ABITS] pc0plus12 = pc0 + 32'd12;
1024 48 robfinch
 
1025 49 robfinch
generate begin : gInsnVar
1026
        if (`WAYS > 1) begin
1027 52 robfinch
                always @*
1028
                        if (thread_en)
1029
                                insn1a <= insn1b;
1030
                        else
1031
                                insn1a = {insn1b,insn0a} >> {fnInsLength(insn0a),3'b0};
1032 49 robfinch
        end
1033
        if (`WAYS > 2) begin
1034 52 robfinch
                always @*
1035
                        if (thread_en)
1036
                                insn2a <= insn2b;
1037
                        else
1038
                                insn2a = {insn2b,insn1b,insn0a} >> {fnInsLength(insn0a) + fnInsLength(insn1a),3'b0};
1039 49 robfinch
        end
1040
end
1041
endgenerate
1042 48 robfinch
 
1043
FT64_L1_icache uic0
1044
(
1045
    .rst(rst),
1046
    .clk(clk),
1047
    .nxt(icnxt),
1048
    .wr(L1_wr0),
1049
    .en(L1_en),
1050
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc0} : L1_adr),
1051
    .wadr(L1_adr),
1052
    .i(L2_rdat),
1053
    .o(insn0a),
1054
    .hit(ihit0),
1055
    .invall(invic),
1056
    .invline(L1_invline)
1057
);
1058 49 robfinch
generate begin : gICacheInst
1059
if (`WAYS > 1) begin
1060 48 robfinch
FT64_L1_icache uic1
1061
(
1062
    .rst(rst),
1063
    .clk(clk),
1064
    .nxt(icnxt),
1065
    .wr(L1_wr1),
1066
    .en(L1_en),
1067 52 robfinch
    .adr(icstate==IDLE||icstate==IC8 ? (thread_en ? {pcr[5:0],pc1}: {pcr[5:0],pc0plus6} ): L1_adr),
1068 48 robfinch
    .wadr(L1_adr),
1069
    .i(L2_rdat),
1070
    .o(insn1b),
1071
    .hit(ihit1),
1072
    .invall(invic),
1073
    .invline(L1_invline)
1074
);
1075 49 robfinch
end
1076
else begin
1077
assign ihit1 = 1'b1;
1078
end
1079
if (`WAYS > 2) begin
1080
FT64_L1_icache uic2
1081
(
1082
    .rst(rst),
1083
    .clk(clk),
1084
    .nxt(icnxt),
1085
    .wr(L1_wr2),
1086
    .en(L1_en),
1087 52 robfinch
    .adr(icstate==IDLE||icstate==IC8 ? (thread_en ? {pcr[5:0],pc2} : {pcr[5:0],pc0plus12}) : L1_adr),
1088 49 robfinch
    .wadr(L1_adr),
1089
    .i(L2_rdat),
1090
    .o(insn2b),
1091
    .hit(ihit2),
1092
    .invall(invic),
1093
    .invline(L1_invline)
1094
);
1095
end
1096
else
1097
assign ihit2 = 1'b1;
1098
end
1099
endgenerate
1100
 
1101 48 robfinch
FT64_L2_icache uic2
1102
(
1103
    .rst(rst),
1104
    .clk(clk),
1105
    .nxt(L2_nxt),
1106
    .wr(bstate==B7 && ack_i),
1107
    .xsel(L2_xsel),
1108
    .adr(L2_adr),
1109
    .cnt(iccnt),
1110
    .exv_i(exvq),
1111
    .i(dat_i),
1112
    .err_i(errq),
1113
    .o(L2_dato),
1114 49 robfinch
    .hit(ihitL2),
1115 48 robfinch
    .invall(invic),
1116
    .invline()
1117
);
1118
 
1119
wire predict_taken;
1120
wire predict_taken0;
1121
wire predict_taken1;
1122 57 robfinch
wire predict_taken2;
1123 48 robfinch
wire predict_takenA;
1124
wire predict_takenB;
1125
wire predict_takenC;
1126
wire predict_takenD;
1127 57 robfinch
wire predict_takenE;
1128
wire predict_takenF;
1129 48 robfinch
wire predict_takenA1;
1130
wire predict_takenB1;
1131
wire predict_takenC1;
1132
wire predict_takenD1;
1133
 
1134 57 robfinch
wire [`ABITS] btgtA, btgtB, btgtC, btgtD, btgtE, btgtF;
1135 48 robfinch
wire btbwr0 = iqentry_v[head0] && iqentry_done[head0] &&
1136
        (
1137 51 robfinch
        iqentry_jal[head0] ||
1138
        iqentry_brk[head0] ||
1139
        iqentry_rti[head0]);
1140 57 robfinch
generate begin: gbtbvar
1141
if (`WAYS > 1) begin
1142 48 robfinch
wire btbwr1 = iqentry_v[head1] && iqentry_done[head1] &&
1143
        (
1144 51 robfinch
        iqentry_jal[head1] ||
1145
        iqentry_brk[head1] ||
1146
        iqentry_rti[head1]);
1147 57 robfinch
end
1148
end
1149
endgenerate
1150 48 robfinch
 
1151 50 robfinch
wire fcu_clk;
1152 49 robfinch
`ifdef FCU_ENH
1153 50 robfinch
//BUFGCE ufcuclk
1154
//(
1155
//      .I(clk_i),
1156
//      .CE(fcu_available),
1157
//      .O(fcu_clk)
1158
//);
1159 49 robfinch
`endif
1160 50 robfinch
assign fcu_clk = clk_i;
1161 49 robfinch
 
1162 57 robfinch
generate begin: gBTBInst
1163
if (`WAYS > 2) begin
1164 49 robfinch
`ifdef FCU_ENH
1165 48 robfinch
FT64_BTB ubtb1
1166
(
1167 49 robfinch
  .rst(rst),
1168
  .wclk(fcu_clk),
1169
  .wr(btbwr0 | btbwr1),
1170
  .wadr(btbwr0 ? iqentry_pc[head0] : iqentry_pc[head1]),
1171
  .wdat(btbwr0 ? iqentry_a0[head0] : iqentry_a0[head1]),
1172
  .valid(btbwr0 ? iqentry_bt[head0] & iqentry_v[head0] : iqentry_bt[head1] & iqentry_v[head1]),
1173
  .rclk(~clk),
1174
  .pcA(fetchbufA_pc),
1175
  .btgtA(btgtA),
1176
  .pcB(fetchbufB_pc),
1177
  .btgtB(btgtB),
1178
  .pcC(fetchbufC_pc),
1179
  .btgtC(btgtC),
1180
  .pcD(fetchbufD_pc),
1181
  .btgtD(btgtD),
1182 57 robfinch
  .pcE(fetchbufE_pc),
1183
  .btgtE(btgtE),
1184
  .pcF(fetchbufF_pc),
1185
  .btgtF(btgtF),
1186 49 robfinch
  .npcA(BRKPC),
1187
  .npcB(BRKPC),
1188
  .npcC(BRKPC),
1189 57 robfinch
  .npcD(BRKPC),
1190
  .npcE(BRKPC),
1191
  .npcF(BRKPC)
1192 48 robfinch
);
1193 49 robfinch
`else
1194
// Branch tergets are picked up by fetchbuf logic and need to be present.
1195
// Without a target predictor they are just set to the reset address.
1196
// This virtually guarentees a miss.
1197
assign btgtA = RSTPC;
1198
assign btgtB = RSTPC;
1199
assign btgtC = RSTPC;
1200
assign btgtD = RSTPC;
1201 57 robfinch
assign btgtE = RSTPC;
1202
assign btgtF = RSTPC;
1203 49 robfinch
`endif
1204 57 robfinch
end
1205
else if (`WAYS > 1) begin
1206
`ifdef FCU_ENH
1207
FT64_BTB ubtb1
1208
(
1209
  .rst(rst),
1210
  .wclk(fcu_clk),
1211
  .wr(btbwr0 | btbwr1),
1212
  .wadr(btbwr0 ? iqentry_pc[head0] : iqentry_pc[head1]),
1213
  .wdat(btbwr0 ? iqentry_a0[head0] : iqentry_a0[head1]),
1214
  .valid(btbwr0 ? iqentry_bt[head0] & iqentry_v[head0] : iqentry_bt[head1] & iqentry_v[head1]),
1215
  .rclk(~clk),
1216
  .pcA(fetchbufA_pc),
1217
  .btgtA(btgtA),
1218
  .pcB(fetchbufB_pc),
1219
  .btgtB(btgtB),
1220
  .pcC(fetchbufC_pc),
1221
  .btgtC(btgtC),
1222
  .pcD(fetchbufD_pc),
1223
  .btgtD(btgtD),
1224
  .pcE(32'd0),
1225
  .btgtE(),
1226
  .pcF(32'd0),
1227
  .btgtF(),
1228
  .npcA(BRKPC),
1229
  .npcB(BRKPC),
1230
  .npcC(BRKPC),
1231
  .npcD(BRKPC),
1232
  .npcE(BRKPC),
1233
  .npcF(BRKPC)
1234
);
1235
`else
1236
// Branch tergets are picked up by fetchbuf logic and need to be present.
1237
// Without a target predictor they are just set to the reset address.
1238
// This virtually guarentees a miss.
1239
assign btgtA = RSTPC;
1240
assign btgtB = RSTPC;
1241
assign btgtC = RSTPC;
1242
assign btgtD = RSTPC;
1243
`endif
1244
end
1245
else begin
1246
`ifdef FCU_ENH
1247
FT64_BTB ubtb1
1248
(
1249
  .rst(rst),
1250
  .wclk(fcu_clk),
1251
  .wr(btbwr0),
1252
  .wadr(iqentry_pc[head0]),
1253
  .wdat(iqentry_a0[head0]),
1254
  .valid(iqentry_bt[head0] & iqentry_v[head0]),
1255
  .rclk(~clk),
1256
  .pcA(fetchbufA_pc),
1257
  .btgtA(btgtA),
1258
  .pcB(fetchbufB_pc),
1259
  .btgtB(btgtB),
1260
  .pcC(32'd0),
1261
  .btgtC(),
1262
  .pcD(32'd0),
1263
  .btgtD(),
1264
  .pcE(32'd0),
1265
  .btgtE(),
1266
  .pcF(32'd0),
1267
  .btgtF(),
1268
  .npcA(BRKPC),
1269
  .npcB(BRKPC),
1270
  .npcC(BRKPC),
1271
  .npcD(BRKPC),
1272
  .npcE(BRKPC),
1273
  .npcF(BRKPC)
1274
);
1275
`else
1276
// Branch tergets are picked up by fetchbuf logic and need to be present.
1277
// Without a target predictor they are just set to the reset address.
1278
// This virtually guarentees a miss.
1279
assign btgtA = RSTPC;
1280
assign btgtB = RSTPC;
1281
`endif
1282
end
1283
end
1284
endgenerate
1285 48 robfinch
 
1286 57 robfinch
generate begin: gBPInst
1287
if (`WAYS > 2) begin
1288 49 robfinch
`ifdef FCU_ENH
1289 48 robfinch
FT64_BranchPredictor ubp1
1290
(
1291 49 robfinch
  .rst(rst),
1292
  .clk(fcu_clk),
1293
  .en(bpe),
1294
  .xisBranch0(iqentry_br[head0] & commit0_v),
1295
  .xisBranch1(iqentry_br[head1] & commit1_v),
1296
  .pcA(fetchbufA_pc),
1297
  .pcB(fetchbufB_pc),
1298
  .pcC(fetchbufC_pc),
1299
  .pcD(fetchbufD_pc),
1300 57 robfinch
  .pcE(fetchbufE_pc),
1301
  .pcF(fetchbufF_pc),
1302 49 robfinch
  .xpc0(iqentry_pc[head0]),
1303
  .xpc1(iqentry_pc[head1]),
1304 52 robfinch
  .takb0(commit0_v & iqentry_takb[head0]),
1305
  .takb1(commit1_v & iqentry_takb[head1]),
1306 49 robfinch
  .predict_takenA(predict_takenA),
1307
  .predict_takenB(predict_takenB),
1308
  .predict_takenC(predict_takenC),
1309 57 robfinch
  .predict_takenD(predict_takenD),
1310
  .predict_takenE(predict_takenE),
1311
  .predict_takenF(predict_takenF)
1312 48 robfinch
);
1313 49 robfinch
`else
1314
// Predict based on sign of displacement
1315
assign predict_takenA = fetchbufA_instr[31];
1316
assign predict_takenB = fetchbufB_instr[31];
1317
assign predict_takenC = fetchbufC_instr[31];
1318
assign predict_takenD = fetchbufD_instr[31];
1319 57 robfinch
assign predict_takenE = fetchbufE_instr[31];
1320
assign predict_takenF = fetchbufF_instr[31];
1321 49 robfinch
`endif
1322 57 robfinch
end
1323
else if (`WAYS > 1) begin
1324
`ifdef FCU_ENH
1325
FT64_BranchPredictor ubp1
1326
(
1327
  .rst(rst),
1328
  .clk(fcu_clk),
1329
  .en(bpe),
1330
  .xisBranch0(iqentry_br[head0] & commit0_v),
1331
  .xisBranch1(iqentry_br[head1] & commit1_v),
1332
  .pcA(fetchbufA_pc),
1333
  .pcB(fetchbufB_pc),
1334
  .pcC(fetchbufC_pc),
1335
  .pcD(fetchbufD_pc),
1336
  .pcE(32'd0),
1337
  .pcF(32'd0),
1338
  .xpc0(iqentry_pc[head0]),
1339
  .xpc1(iqentry_pc[head1]),
1340
  .takb0(commit0_v & iqentry_takb[head0]),
1341
  .takb1(commit1_v & iqentry_takb[head1]),
1342
  .predict_takenA(predict_takenA),
1343
  .predict_takenB(predict_takenB),
1344
  .predict_takenC(predict_takenC),
1345
  .predict_takenD(predict_takenD),
1346
  .predict_takenE(),
1347
  .predict_takenF()
1348
);
1349
`else
1350
// Predict based on sign of displacement
1351
assign predict_takenA = fetchbufA_instr[31];
1352
assign predict_takenB = fetchbufB_instr[31];
1353
assign predict_takenC = fetchbufC_instr[31];
1354
assign predict_takenD = fetchbufD_instr[31];
1355
`endif
1356
end
1357
else begin
1358
`ifdef FCU_ENH
1359
FT64_BranchPredictor ubp1
1360
(
1361
  .rst(rst),
1362
  .clk(fcu_clk),
1363
  .en(bpe),
1364
  .xisBranch0(iqentry_br[head0] & commit0_v),
1365
  .xisBranch1(1'b0),
1366
  .pcA(fetchbufA_pc),
1367
  .pcB(fetchbufB_pc),
1368
  .pcC(32'd0),
1369
  .pcD(32'd0),
1370
  .pcE(32'd0),
1371
  .pcF(32'd0),
1372
  .xpc0(iqentry_pc[head0]),
1373
  .xpc1(32'd0),
1374
  .takb0(commit0_v & iqentry_takb[head0]),
1375
  .takb1(1'b0),
1376
  .predict_takenA(predict_takenA),
1377
  .predict_takenB(predict_takenB),
1378
  .predict_takenC(),
1379
  .predict_takenD(),
1380
  .predict_takenE(),
1381
  .predict_takenF()
1382
);
1383
`else
1384
// Predict based on sign of displacement
1385
assign predict_takenA = fetchbufA_instr[31];
1386
assign predict_takenB = fetchbufB_instr[31];
1387
`endif
1388
end
1389
end
1390
endgenerate
1391 48 robfinch
 
1392
//-----------------------------------------------------------------------------
1393
// Debug
1394
//-----------------------------------------------------------------------------
1395
`ifdef SUPPORT_DBG
1396
 
1397
wire [DBW-1:0] dbg_stat1x;
1398
reg [DBW-1:0] dbg_stat;
1399
reg [DBW-1:0] dbg_ctrl;
1400
reg [ABW-1:0] dbg_adr0;
1401
reg [ABW-1:0] dbg_adr1;
1402
reg [ABW-1:0] dbg_adr2;
1403
reg [ABW-1:0] dbg_adr3;
1404
reg dbg_imatchA0,dbg_imatchA1,dbg_imatchA2,dbg_imatchA3,dbg_imatchA;
1405
reg dbg_imatchB0,dbg_imatchB1,dbg_imatchB2,dbg_imatchB3,dbg_imatchB;
1406
 
1407
wire dbg_lmatch00 =
1408
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1409
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1410
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1411
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1412
                                 dbg_ctrl[19:18]==2'b11)
1413
                                 ;
1414
wire dbg_lmatch01 =
1415
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1416
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1417
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1418
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1419
                  dbg_ctrl[19:18]==2'b11)
1420
                  ;
1421
wire dbg_lmatch02 =
1422
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1423
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1424
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1425
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1426
                dbg_ctrl[19:18]==2'b11)
1427
                ;
1428
wire dbg_lmatch10 =
1429
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1430
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1431
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1432
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1433
                  dbg_ctrl[23:22]==2'b11)
1434
                  ;
1435
wire dbg_lmatch11 =
1436
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1437
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1438
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1439
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1440
                dbg_ctrl[23:22]==2'b11)
1441
                ;
1442
wire dbg_lmatch12 =
1443
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1444
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1445
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1446
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1447
                dbg_ctrl[23:22]==2'b11)
1448
                ;
1449
wire dbg_lmatch20 =
1450
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1451
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1452
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1453
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1454
                    dbg_ctrl[27:26]==2'b11)
1455
                    ;
1456
wire dbg_lmatch21 =
1457
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1458
                   ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1459
                    (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1460
                    (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1461
                    dbg_ctrl[27:26]==2'b11)
1462
                    ;
1463
wire dbg_lmatch22 =
1464
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1465
                   ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1466
                    (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1467
                    (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1468
                    dbg_ctrl[27:26]==2'b11)
1469
                    ;
1470
wire dbg_lmatch30 =
1471
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1472
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1473
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1474
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1475
                      dbg_ctrl[31:30]==2'b11)
1476
                      ;
1477
wire dbg_lmatch31 =
1478
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1479
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1480
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1481
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1482
                    dbg_ctrl[31:30]==2'b11)
1483
                    ;
1484
wire dbg_lmatch32 =
1485
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1486
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1487
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1488
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1489
                    dbg_ctrl[31:30]==2'b11)
1490
                    ;
1491
wire dbg_lmatch0 = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30;
1492
wire dbg_lmatch1 = dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31;
1493
wire dbg_lmatch2 = dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32;
1494
wire dbg_lmatch = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30|
1495
                  dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31|
1496
                  dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32
1497
                    ;
1498
 
1499
wire dbg_smatch00 =
1500
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1501
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1502
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1503
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1504
                                 dbg_ctrl[19:18]==2'b11)
1505
                                 ;
1506
wire dbg_smatch01 =
1507
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1508
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1509
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1510
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1511
                  dbg_ctrl[19:18]==2'b11)
1512
                  ;
1513
wire dbg_smatch02 =
1514
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1515
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1516
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1517
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1518
                dbg_ctrl[19:18]==2'b11)
1519
                ;
1520
wire dbg_smatch10 =
1521
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1522
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1523
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1524
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1525
                  dbg_ctrl[23:22]==2'b11)
1526
                  ;
1527
wire dbg_smatch11 =
1528
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1529
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1530
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1531
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1532
                dbg_ctrl[23:22]==2'b11)
1533
                ;
1534
wire dbg_smatch12 =
1535
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1536
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1537
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1538
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1539
                dbg_ctrl[23:22]==2'b11)
1540
                ;
1541
wire dbg_smatch20 =
1542
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1543
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1544
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1545
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1546
                    dbg_ctrl[27:26]==2'b11)
1547
                    ;
1548
wire dbg_smatch21 =
1549
           dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1550
                    ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1551
                     (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1552
                     (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1553
                     dbg_ctrl[27:26]==2'b11)
1554
                     ;
1555
wire dbg_smatch22 =
1556
            dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1557
                     ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1558
                      (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1559
                      (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1560
                      dbg_ctrl[27:26]==2'b11)
1561
                      ;
1562
wire dbg_smatch30 =
1563
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1564
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1565
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1566
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1567
                      dbg_ctrl[31:30]==2'b11)
1568
                      ;
1569
wire dbg_smatch31 =
1570
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1571
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1572
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1573
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1574
                    dbg_ctrl[31:30]==2'b11)
1575
                    ;
1576
wire dbg_smatch32 =
1577
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1578
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1579
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1580
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1581
                    dbg_ctrl[31:30]==2'b11)
1582
                    ;
1583
wire dbg_smatch0 = dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30;
1584
wire dbg_smatch1 = dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31;
1585
wire dbg_smatch2 = dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32;
1586
 
1587
wire dbg_smatch =   dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30|
1588
                    dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31|
1589
                    dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32
1590
                    ;
1591
 
1592
wire dbg_stat0 = dbg_imatchA0 | dbg_imatchB0 | dbg_lmatch00 | dbg_lmatch01 | dbg_lmatch02 | dbg_smatch00 | dbg_smatch01 | dbg_smatch02;
1593
wire dbg_stat1 = dbg_imatchA1 | dbg_imatchB1 | dbg_lmatch10 | dbg_lmatch11 | dbg_lmatch12 | dbg_smatch10 | dbg_smatch11 | dbg_smatch12;
1594
wire dbg_stat2 = dbg_imatchA2 | dbg_imatchB2 | dbg_lmatch20 | dbg_lmatch21 | dbg_lmatch22 | dbg_smatch20 | dbg_smatch21 | dbg_smatch22;
1595
wire dbg_stat3 = dbg_imatchA3 | dbg_imatchB3 | dbg_lmatch30 | dbg_lmatch31 | dbg_lmatch32 | dbg_smatch30 | dbg_smatch31 | dbg_smatch32;
1596
assign dbg_stat1x = {dbg_stat3,dbg_stat2,dbg_stat1,dbg_stat0};
1597
wire debug_on = |dbg_ctrl[3:0]|dbg_ctrl[7]|dbg_ctrl[63];
1598
 
1599
always @*
1600
begin
1601
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf0_pc==dbg_adr0)
1602
        dbg_imatchA0 = `TRUE;
1603
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf0_pc==dbg_adr1)
1604
        dbg_imatchA1 = `TRUE;
1605
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf0_pc==dbg_adr2)
1606
        dbg_imatchA2 = `TRUE;
1607
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf0_pc==dbg_adr3)
1608
        dbg_imatchA3 = `TRUE;
1609
    if (dbg_imatchA0|dbg_imatchA1|dbg_imatchA2|dbg_imatchA3)
1610
        dbg_imatchA = `TRUE;
1611
end
1612
 
1613
always @*
1614
begin
1615
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf1_pc==dbg_adr0)
1616
        dbg_imatchB0 = `TRUE;
1617
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf1_pc==dbg_adr1)
1618
        dbg_imatchB1 = `TRUE;
1619
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf1_pc==dbg_adr2)
1620
        dbg_imatchB2 = `TRUE;
1621
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf1_pc==dbg_adr3)
1622
        dbg_imatchB3 = `TRUE;
1623
    if (dbg_imatchB0|dbg_imatchB1|dbg_imatchB2|dbg_imatchB3)
1624
        dbg_imatchB = `TRUE;
1625
end
1626
`endif
1627
 
1628
//-----------------------------------------------------------------------------
1629
//-----------------------------------------------------------------------------
1630
 
1631 52 robfinch
// freezePC squashes the pc increment if there's an irq.
1632
wire freezePC = (irq_i > im) && ~int_commit;
1633 48 robfinch
always @*
1634 52 robfinch
if (freezePC)
1635 49 robfinch
        insn0 <= {8'd0,3'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1636 48 robfinch
else if (phit) begin
1637 49 robfinch
        if (insn0a[`INSTRUCTION_OP]==`BRK && insn0a[23:21]==3'd0 && insn0a[7:6]==2'b00)
1638
                insn0 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1639 48 robfinch
        else
1640
                insn0 <= insn0a;
1641
end
1642
else
1643
        insn0 <= `NOP_INSN;
1644 49 robfinch
generate begin : gInsnMux
1645
if (`WAYS > 1) begin
1646 48 robfinch
always @*
1647 52 robfinch
if (freezePC && !thread_en)
1648
        insn1 <= {8'd0,3'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1649
else if (phit) begin
1650 49 robfinch
        if (insn1a[`INSTRUCTION_OP]==`BRK && insn1a[23:21]==3'd0 && insn1a[7:6]==2'b00)
1651
                insn1 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1652 48 robfinch
        else
1653
                insn1 <= insn1a;
1654
end
1655
else
1656
        insn1 <= `NOP_INSN;
1657 49 robfinch
end
1658
if (`WAYS > 2) begin
1659
always @*
1660 52 robfinch
if (freezePC && !thread_en)
1661
        insn2 <= {8'd0,3'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1662
else if (phit) begin
1663 49 robfinch
        if (insn2a[`INSTRUCTION_OP]==`BRK && insn1a[23:21]==3'd0 && insn2a[7:6]==2'b00)
1664
                insn2 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1665
        else
1666
                insn2 <= insn2a;
1667
end
1668
else
1669
        insn2 <= `NOP_INSN;
1670
end
1671
end
1672
endgenerate
1673 48 robfinch
 
1674
wire [63:0] dc0_out, dc1_out, dc2_out;
1675
assign rdat0 = dram0_unc ? xdati : dc0_out;
1676
assign rdat1 = dram1_unc ? xdati : dc1_out;
1677
assign rdat2 = dram2_unc ? xdati : dc2_out;
1678
 
1679
reg preload;
1680
reg [1:0] dccnt;
1681
wire dhit0, dhit1, dhit2;
1682 57 robfinch
wire dhit0a, dhit1a, dhit2a;
1683 48 robfinch
wire dhit00, dhit10, dhit20;
1684
wire dhit01, dhit11, dhit21;
1685 49 robfinch
reg [`ABITS] dc_wadr;
1686 48 robfinch
reg [63:0] dc_wdat;
1687
reg isStore;
1688
 
1689 57 robfinch
// If the data is in the write buffer, give the buffer a chance to
1690
// write out the data before trying to load from the cache.
1691
reg wb_hit0, wb_hit1, wb_hit2;
1692
always @*
1693
begin
1694
        wb_hit0 <= FALSE;
1695
        wb_hit1 <= FALSE;
1696
        wb_hit2 <= FALSE;
1697
        for (n = 0; n < `WB_DEPTH; n = n + 1) begin
1698
                if (wb_v[n] && wb_addr[n][31:3]==dram0_addr[31:3])
1699
                        wb_hit0 <= TRUE;
1700
                if (`NUM_MEM > 1 && wb_addr[n][31:3]==dram1_addr[31:3])
1701
                        wb_hit1 <= TRUE;
1702
                if (`NUM_MEM > 2 && wb_addr[n][31:3]==dram2_addr[31:3])
1703
                        wb_hit2 <= TRUE;
1704
        end
1705
end
1706
 
1707
assign dhit0 = dhit0a & !wb_hit0;
1708
assign dhit1 = dhit1a & !wb_hit1;
1709
assign dhit2 = dhit2a & !wb_hit2;
1710
wire whit0, whit1, whit2;
1711
 
1712 48 robfinch
FT64_dcache udc0
1713
(
1714
    .rst(rst),
1715
    .wclk(clk),
1716 57 robfinch
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && whit0)),
1717 48 robfinch
    .sel(sel_o),
1718
    .wadr({pcr[5:0],adr_o}),
1719 57 robfinch
    .whit(whit0),
1720 48 robfinch
    .i(bstate==B2d ? dat_i : dat_o),
1721
    .rclk(clk),
1722
    .rdsize(dram0_memsize),
1723
    .radr({pcr[5:0],dram0_addr}),
1724
    .o(dc0_out),
1725
    .hit(),
1726 57 robfinch
    .hit0(dhit0a),
1727 48 robfinch
    .hit1()
1728
);
1729 49 robfinch
generate begin : gDCacheInst
1730
if (`NUM_MEM > 1) begin
1731 48 robfinch
FT64_dcache udc1
1732
(
1733
    .rst(rst),
1734
    .wclk(clk),
1735 57 robfinch
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && whit1)),
1736 48 robfinch
    .sel(sel_o),
1737
    .wadr({pcr[5:0],adr_o}),
1738 57 robfinch
    .whit(whit1),
1739 48 robfinch
    .i(bstate==B2d ? dat_i : dat_o),
1740
    .rclk(clk),
1741
    .rdsize(dram1_memsize),
1742
    .radr({pcr[5:0],dram1_addr}),
1743
    .o(dc1_out),
1744
    .hit(),
1745 57 robfinch
    .hit0(dhit1a),
1746 48 robfinch
    .hit1()
1747
);
1748 49 robfinch
end
1749
if (`NUM_MEM > 2) begin
1750 48 robfinch
FT64_dcache udc2
1751
(
1752
    .rst(rst),
1753
    .wclk(clk),
1754 57 robfinch
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && whit2)),
1755 48 robfinch
    .sel(sel_o),
1756
    .wadr({pcr[5:0],adr_o}),
1757 57 robfinch
    .whit(whit2),
1758 48 robfinch
    .i(bstate==B2d ? dat_i : dat_o),
1759
    .rclk(clk),
1760
    .rdsize(dram2_memsize),
1761
    .radr({pcr[5:0],dram2_addr}),
1762
    .o(dc2_out),
1763
    .hit(),
1764 57 robfinch
    .hit0(dhit2a),
1765 48 robfinch
    .hit1()
1766
);
1767 49 robfinch
end
1768
end
1769
endgenerate
1770 48 robfinch
 
1771
function [`QBITS] idp1;
1772
input [`QBITS] id;
1773 52 robfinch
idp1 = (id + 1) % QENTRIES;
1774 48 robfinch
endfunction
1775
 
1776
function [`QBITS] idp2;
1777
input [`QBITS] id;
1778 52 robfinch
idp2 = (id + 2) % QENTRIES;
1779 48 robfinch
endfunction
1780
 
1781
function [`QBITS] idp3;
1782
input [`QBITS] id;
1783 52 robfinch
idp3 = (id + 3) % QENTRIES;
1784 48 robfinch
endfunction
1785
 
1786
function [`QBITS] idp4;
1787
input [`QBITS] id;
1788 52 robfinch
idp4 = (id + 4) % QENTRIES;
1789 48 robfinch
endfunction
1790
 
1791
function [`QBITS] idp5;
1792
input [`QBITS] id;
1793 52 robfinch
idp5 = (id + 5) % QENTRIES;
1794 48 robfinch
endfunction
1795
 
1796
function [`QBITS] idp6;
1797
input [`QBITS] id;
1798 52 robfinch
idp6 = (id + 6) % QENTRIES;
1799 48 robfinch
endfunction
1800
 
1801
function [`QBITS] idp7;
1802
input [`QBITS] id;
1803 52 robfinch
idp7 = (id + 7) % QENTRIES;
1804 48 robfinch
endfunction
1805
 
1806 52 robfinch
function [`QBITS] idp8;
1807
input [`QBITS] id;
1808
idp8 = (id + 8) % QENTRIES;
1809
endfunction
1810
 
1811
function [`QBITS] idp9;
1812
input [`QBITS] id;
1813
idp9 = (id + 9) % QENTRIES;
1814
endfunction
1815
 
1816 48 robfinch
function [`QBITS] idm1;
1817
input [`QBITS] id;
1818 52 robfinch
idm1 = (id - 1) % QENTRIES;
1819 48 robfinch
endfunction
1820
 
1821
`ifdef SUPPORT_SMT
1822
function [RBIT:0] fnRa;
1823
input [47:0] isn;
1824
input [5:0] vqei;
1825
input [5:0] vli;
1826
input thrd;
1827
case(isn[`INSTRUCTION_OP])
1828
`IVECTOR:
1829
        case(isn[`INSTRUCTION_S2])
1830
        `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1831
        `VMxx:
1832
                case(isn[25:23])
1833
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
1834
                    fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1835
            `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1836
            default:fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1837
            endcase
1838
        `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
1839
        `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
1840
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1841
        default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1842
        endcase
1843 50 robfinch
`R2:    casez(isn[`INSTRUCTION_S2])
1844 48 robfinch
                `MOV:
1845
                        case(isn[25:23])
1846
                        3'd0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1847 50 robfinch
                        3'd1:   fnRa = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
1848 48 robfinch
                        3'd2:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1849
                        3'd3:   fnRa = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RA]};
1850
                        3'd4:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1851 51 robfinch
                        3'd5:   fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1852
                        3'd6:   fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1853 48 robfinch
                        default:fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1854
                        endcase
1855
        `VMOV:
1856
            case (isn[`INSTRUCTION_S1])
1857
            5'h0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1858
            5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
1859
            endcase
1860
        default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1861
        endcase
1862 51 robfinch
`FLOAT:         fnRa = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1863 48 robfinch
default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1864
endcase
1865
endfunction
1866
 
1867
function [RBIT:0] fnRb;
1868
input [47:0] isn;
1869
input fb;
1870
input [5:0] vqei;
1871
input [5:0] rfoa0i;
1872
input [5:0] rfoa1i;
1873
input thrd;
1874
case(isn[`INSTRUCTION_OP])
1875
`R2:        case(isn[`INSTRUCTION_S2])
1876
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
1877
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1878
            default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1879
            endcase
1880
`IVECTOR:
1881
                        case(isn[`INSTRUCTION_S2])
1882
                        `VMxx:
1883
                                case(isn[25:23])
1884
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
1885
                        fnRb = {6'h3F,1'b1,2'b0,isn[13:11]};
1886
                default:        fnRb = 12'h000;
1887
                endcase
1888
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1889
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1890
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
1891
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
1892
                fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1893
            `VSHL,`VSHR,`VASR:
1894
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
1895
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1896
            endcase
1897 51 robfinch
`FLOAT:         fnRb = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1898 48 robfinch
default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1899
endcase
1900
endfunction
1901
 
1902
function [RBIT:0] fnRc;
1903
input [47:0] isn;
1904
input [5:0] vqei;
1905
input thrd;
1906
case(isn[`INSTRUCTION_OP])
1907
`R2:        case(isn[`INSTRUCTION_S2])
1908
            `SVX:       fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1909
                `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1910
                        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1911
                `CMOVEZ,`CMOVNZ,`MAJ:
1912
                        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1913
            default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1914
            endcase
1915
`IVECTOR:
1916
                        case(isn[`INSTRUCTION_S2])
1917
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[18:16]};
1918
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1919
            endcase
1920 51 robfinch
`FLOAT:         fnRc = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1921 48 robfinch
default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1922
endcase
1923
endfunction
1924
 
1925
function [RBIT:0] fnRt;
1926
input [47:0] isn;
1927
input [5:0] vqei;
1928
input [5:0] vli;
1929
input thrd;
1930
casez(isn[`INSTRUCTION_OP])
1931
`IVECTOR:
1932
                case(isn[`INSTRUCTION_S2])
1933
                `VMxx:
1934
                        case(isn[25:23])
1935
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
1936
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1937
            `VMPOP:     fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1938
            default:
1939
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1940
            endcase
1941
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1942
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
1943
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
1944
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
1945
        `V2BITS:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1946
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1947
        endcase
1948
 
1949 50 robfinch
`R2:    casez(isn[`INSTRUCTION_S2])
1950 48 robfinch
                `MOV:
1951
                        case(isn[25:23])
1952 50 robfinch
                        3'd0:   fnRt = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RB]};
1953 48 robfinch
                        3'd1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1954
                        3'd2:   fnRt = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RB]};
1955
                        3'd3:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1956 51 robfinch
                        3'd4:   fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1957 48 robfinch
                        3'd5:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1958 51 robfinch
                        3'd6:   fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1959 48 robfinch
                        default:fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1960
                        endcase
1961
        `VMOV:
1962
            case (isn[`INSTRUCTION_S1])
1963
            5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RB]};
1964
            5'h1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1965
            default:    fnRt = 12'h000;
1966
            endcase
1967
        `R1:
1968
                case(isn[22:18])
1969
                `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT:
1970
                        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1971
                `MEMDB,`MEMSB,`SYNC:
1972
                        fnRt = 12'd0;
1973
                default:        fnRt = 12'd0;
1974
                endcase
1975
        `CMOVEZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1976
        `CMOVNZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1977
        `MUX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1978
        `MIN:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1979
        `MAX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1980
        `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
1981
        `SHIFTR:        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1982
        `SHIFT31,`SHIFT63:
1983
                                fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1984
        `SEI:           fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1985
        `WAIT,`RTI,`CHK:
1986
                        fnRt = 12'd0;
1987
                default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1988
        endcase
1989
`MEMNDX:
1990
    case(isn[`INSTRUCTION_S2])
1991
    `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1992
                        fnRt = 12'd0;
1993
    default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1994
        endcase
1995
`FLOAT:
1996
                case(isn[31:26])
1997
                `FTX,`FCX,`FEX,`FDX,`FRM:
1998
                                        fnRt = 12'd0;
1999
                `FSYNC:         fnRt = 12'd0;
2000 51 robfinch
                default:        fnRt = {fp_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2001 48 robfinch
                endcase
2002
`BRK:   fnRt = 12'd0;
2003
`REX:   fnRt = 12'd0;
2004
`CHK:   fnRt = 12'd0;
2005
`EXEC:  fnRt = 12'd0;
2006
`Bcc:   fnRt = 12'd0;
2007
`BBc:   case(isn[20:19])
2008
                `IBNE:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2009
                `DBNZ:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2010
                default:        fnRt = 12'd0;
2011
                endcase
2012
`BEQI:  fnRt = 12'd0;
2013
`SB,`Sx,`SWC,`CACHE:
2014
                fnRt = 12'd0;
2015
`JMP:   fnRt = 12'd0;
2016
`CALL:  fnRt = {rgs[thrd],1'b0,regLR};  // regLR
2017
`RET:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2018
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2019
`AMO:   fnRt = isn[31] ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
2020 56 robfinch
`AUIPC,`LUI:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
2021 48 robfinch
default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
2022
endcase
2023
endfunction
2024
`else
2025
function [RBIT:0] fnRa;
2026
input [47:0] isn;
2027
input [5:0] vqei;
2028
input [5:0] vli;
2029
input thrd;
2030
case(isn[`INSTRUCTION_OP])
2031
`IVECTOR:
2032
        case(isn[`INSTRUCTION_S2])
2033 51 robfinch
  `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
2034
  `VMxx:
2035
        case(isn[25:23])
2036
        `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
2037
              fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
2038
      `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
2039
      default:fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
2040
      endcase
2041
  `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
2042
  `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
2043
  `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
2044
  default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
2045
  endcase
2046 50 robfinch
`R2:
2047
        casez(isn[`INSTRUCTION_S2])
2048
        `MOV:
2049
                case(isn[25:23])
2050
                3'd0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2051
                3'd1:   fnRa = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
2052
                3'd2:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2053
                3'd3:   fnRa = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RA]};
2054
                3'd4:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2055 51 robfinch
                3'd5:   fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2056
                3'd6:   fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2057 50 robfinch
                default:fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2058
                endcase
2059
  `VMOV:
2060
    case (isn[`INSTRUCTION_S1])
2061
    5'h0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2062
    5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
2063
    endcase
2064
  default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2065
  endcase
2066 51 robfinch
`FLOAT:         fnRa = {fp_rgs,1'b0,isn[`INSTRUCTION_RA]};
2067 48 robfinch
default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2068
endcase
2069
endfunction
2070
 
2071
function [RBIT:0] fnRb;
2072
input [47:0] isn;
2073
input fb;
2074
input [5:0] vqei;
2075
input [5:0] rfoa0i;
2076
input [5:0] rfoa1i;
2077
input thrd;
2078
case(isn[`INSTRUCTION_OP])
2079
`RR:        case(isn[`INSTRUCTION_S2])
2080
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
2081
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2082
            default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2083
            endcase
2084
`IVECTOR:
2085
                        case(isn[`INSTRUCTION_S2])
2086
                        `VMxx:
2087
                                case(isn[25:23])
2088
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2089
                        fnRb = {6'h3F,1'b1,2'b0,isn[13:11]};
2090
                default:        fnRb = 12'h000;
2091
                endcase
2092
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2093
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2094
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
2095
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
2096
                fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2097
            `VSHL,`VSHR,`VASR:
2098
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
2099
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2100
            endcase
2101 51 robfinch
`FLOAT:         fnRb = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
2102 48 robfinch
default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2103
endcase
2104
endfunction
2105
 
2106
function [RBIT:0] fnRc;
2107
input [47:0] isn;
2108
input [5:0] vqei;
2109
input thrd;
2110
case(isn[`INSTRUCTION_OP])
2111
`R2:        case(isn[`INSTRUCTION_S2])
2112
            `SVX:       fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2113
                `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
2114
                        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2115
                `CMOVEZ,`CMOVNZ,`MAJ:
2116
                        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2117
            default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2118
            endcase
2119
`IVECTOR:
2120
                        case(isn[`INSTRUCTION_S2])
2121
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[18:16]};
2122
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2123
            endcase
2124 51 robfinch
`FLOAT:         fnRc = {fp_rgs,1'b0,isn[`INSTRUCTION_RC]};
2125 48 robfinch
default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2126
endcase
2127
endfunction
2128
 
2129
function [RBIT:0] fnRt;
2130
input [47:0] isn;
2131
input [5:0] vqei;
2132
input [5:0] vli;
2133
input thrd;
2134
casez(isn[`INSTRUCTION_OP])
2135
`IVECTOR:
2136
                case(isn[`INSTRUCTION_S2])
2137
                `VMxx:
2138
                        case(isn[25:23])
2139
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
2140
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2141
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2142
            default:
2143
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2144
            endcase
2145
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2146
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
2147
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
2148
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
2149
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2150
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2151
        endcase
2152
 
2153
`FVECTOR:
2154
                case(isn[`INSTRUCTION_S2])
2155
                `VMxx:
2156
                        case(isn[25:23])
2157
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
2158
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2159
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2160
            default:
2161
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2162
            endcase
2163
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2164
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
2165
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
2166
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
2167
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2168
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2169
        endcase
2170
 
2171 50 robfinch
`R2:
2172
        casez(isn[`INSTRUCTION_S2])
2173
        `MOV:
2174
                case(isn[25:23])
2175
                3'd0:   fnRt = {isn[26],isn[22:18],1'b0,isn[`INSTRUCTION_RB]};
2176
                3'd1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2177
                3'd2:   fnRt = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RB]};
2178
                3'd3:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2179 51 robfinch
                3'd4:   fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
2180 50 robfinch
                3'd5:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2181 51 robfinch
                3'd6:   fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RB]};
2182 50 robfinch
                default:fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2183
                endcase
2184
  `VMOV:
2185
    case (isn[`INSTRUCTION_S1])
2186
    5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RB]};
2187
    5'h1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2188
    default:    fnRt = 12'h000;
2189
    endcase
2190
  `R1:
2191
        case(isn[22:18])
2192
        `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT:
2193
                fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2194
        `MEMDB,`MEMSB,`SYNC:
2195
                fnRt = 12'd0;
2196
        default:        fnRt = 12'd0;
2197
        endcase
2198
  `CMOVEZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2199
  `CMOVNZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2200
  `MUX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2201
  `MIN:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2202
  `MAX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2203
  `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
2204
  `SHIFTR:      fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2205
  `SHIFT31,`SHIFT63:
2206
                        fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2207
  `SEI:         fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2208
  `WAIT,`RTI,`CHK:
2209
                        fnRt = 12'd0;
2210
  default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2211
  endcase
2212 48 robfinch
`MEMNDX:
2213
        case(isn[`INSTRUCTION_S2])
2214
  `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
2215
                        fnRt = 12'd0;
2216
  default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2217
  endcase
2218
`FLOAT:
2219
                case(isn[31:26])
2220
                `FTX,`FCX,`FEX,`FDX,`FRM:
2221
                                        fnRt = 12'd0;
2222
                `FSYNC:         fnRt = 12'd0;
2223 51 robfinch
                default:        fnRt = {fp_rgs,1'b0,isn[`INSTRUCTION_RC]};
2224 48 robfinch
                endcase
2225
`BRK:   fnRt = 12'd0;
2226
`REX:   fnRt = 12'd0;
2227
`CHK:   fnRt = 12'd0;
2228
`EXEC:  fnRt = 12'd0;
2229
`Bcc:   fnRt = 12'd0;
2230
`BBc:
2231
        case(isn[20:19])
2232
        `IBNE:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2233
        `DBNZ:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2234
        default:        fnRt = 12'd0;
2235
        endcase
2236
`BEQI:  fnRt = 12'd0;
2237
`SB,`Sx,`SWC,`CACHE:
2238
                fnRt = 12'd0;
2239
`JMP:   fnRt = 12'd0;
2240
`CALL:  fnRt = {rgs,1'b0,regLR};        // regLR
2241
`RET:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2242
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2243
`AMO:   fnRt = isn[31] ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {rgs,1'b0,isn[`INSTRUCTION_RC]};
2244 56 robfinch
`AUIPC,`LUI:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2245 48 robfinch
default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2246
endcase
2247
endfunction
2248
`endif
2249
 
2250
// Determines which lanes of the target register get updated.
2251
function [7:0] fnWe;
2252
input [47:0] isn;
2253
casez(isn[`INSTRUCTION_OP])
2254
`R2:
2255
        case(isn[`INSTRUCTION_S2])
2256
        `R1:
2257
                case(isn[22:18])
2258
                `ABS,`CNTLZ,`CNTLO,`CNTPOP:
2259
                        case(isn[25:23])
2260
                        3'b000: fnWe = 8'h01;
2261
                        3'b001: fnWe = 8'h03;
2262
                        3'b010: fnWe = 8'h0F;
2263
                        3'b011: fnWe = 8'hFF;
2264
                        default:        fnWe = 8'hFF;
2265
                        endcase
2266
                default: fnWe = 8'hFF;
2267
                endcase
2268
        `SHIFT31:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2269
        `SHIFT63:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2270
        `SLT,`SLTU,`SLE,`SLEU,
2271
        `ADD,`SUB,
2272
        `AND,`OR,`XOR,
2273
        `NAND,`NOR,`XNOR,
2274 50 robfinch
        `DIV,`DIVU,`DIVSU,
2275
        `MOD,`MODU,`MODSU,
2276
        `MUL,`MULU,`MULSU,
2277
        `MULH,`MULUH,`MULSUH:
2278 48 robfinch
                case(isn[25:23])
2279
                3'b000: fnWe = 8'h01;
2280
                3'b001: fnWe = 8'h03;
2281
                3'b010: fnWe = 8'h0F;
2282
                3'b011: fnWe = 8'hFF;
2283
                default:        fnWe = 8'hFF;
2284
                endcase
2285
        default: fnWe = 8'hFF;
2286
        endcase
2287
default:        fnWe = 8'hFF;
2288
endcase
2289
endfunction
2290
 
2291
// Detect if a source is automatically valid
2292
function Source1Valid;
2293
input [47:0] isn;
2294
casez(isn[`INSTRUCTION_OP])
2295
`BRK:   Source1Valid = TRUE;
2296
`Bcc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2297
`BBc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2298
`BEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2299
`CHK:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2300
`RR:    case(isn[`INSTRUCTION_S2])
2301
        `SHIFT31:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2302
        `SHIFT63:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2303
        `SHIFTR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2304
        default:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2305
        endcase
2306
`MEMNDX:Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2307
`ADDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2308
`SLTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2309
`SLTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2310
`SGTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2311
`SGTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2312
`ANDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2313
`ORI:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2314
`XORI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2315
`XNORI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2316
`MULUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2317
`AMO:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2318
`LB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2319
`LBU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2320
`Lx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2321
`LxU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2322
`LWR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2323
`LV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2324
`LVx:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2325
`SB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2326
`Sx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2327
`SWC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2328
`SV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2329
`INC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2330
`CAS:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2331
`JAL:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2332
`RET:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2333
`CSRRW: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2334 51 robfinch
`BITFIELD:      case(isn[47:44])
2335
        `BFINSI:        Source1Valid = TRUE;
2336
        default:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0 || isn[30]==1'b0;
2337
        endcase
2338 48 robfinch
`IVECTOR:
2339 51 robfinch
        Source1Valid = FALSE;
2340 48 robfinch
default:    Source1Valid = TRUE;
2341
endcase
2342
endfunction
2343
 
2344
function Source2Valid;
2345
input [47:0] isn;
2346
casez(isn[`INSTRUCTION_OP])
2347
`BRK:   Source2Valid = TRUE;
2348
`Bcc:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2349
`BBc:   Source2Valid = TRUE;
2350
`BEQI:  Source2Valid = TRUE;
2351
`CHK:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2352
`RR:    case(isn[`INSTRUCTION_S2])
2353
        `R1:       Source2Valid = TRUE;
2354
        `SHIFTR:   Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2355
        `SHIFT31:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2356
        `SHIFT63:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2357
        `LVX,`SVX: Source2Valid = FALSE;
2358
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2359
        endcase
2360
`MEMNDX:
2361
        case(isn[`INSTRUCTION_S2])
2362
        `LVX,`SVX: Source2Valid = FALSE;
2363
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2364
        endcase
2365
`ADDI:  Source2Valid = TRUE;
2366
`SLTI:  Source2Valid = TRUE;
2367
`SLTUI: Source2Valid = TRUE;
2368
`SGTI:  Source2Valid = TRUE;
2369
`SGTUI: Source2Valid = TRUE;
2370
`ANDI:  Source2Valid = TRUE;
2371
`ORI:   Source2Valid = TRUE;
2372
`XORI:  Source2Valid = TRUE;
2373
`XNORI: Source2Valid = TRUE;
2374
`MULUI: Source2Valid = TRUE;
2375
`LB:    Source2Valid = TRUE;
2376
`LBU:   Source2Valid = TRUE;
2377
`Lx:    Source2Valid = TRUE;
2378
`LxU:   Source2Valid = TRUE;
2379
`LWR:   Source2Valid = TRUE;
2380
`LVx:   Source2Valid = TRUE;
2381
`INC:           Source2Valid = TRUE;
2382
`SB:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2383
`Sx:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2384
`SWC:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2385
`CAS:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2386
`JAL:   Source2Valid = TRUE;
2387
`RET:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2388
`IVECTOR:
2389
                    case(isn[`INSTRUCTION_S2])
2390
            `VABS:  Source2Valid = TRUE;
2391
            `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2392
                Source2Valid = FALSE;
2393
            `VADDS,`VSUBS,`VANDS,`VORS,`VXORS:
2394
                Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2395
            `VBITS2V:   Source2Valid = TRUE;
2396
            `V2BITS:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2397
            `VSHL,`VSHR,`VASR:  Source2Valid = isn[22:21]==2'd2;
2398
            default:    Source2Valid = FALSE;
2399
            endcase
2400
`LV:        Source2Valid = TRUE;
2401
`SV:        Source2Valid = FALSE;
2402
`AMO:           Source2Valid = isn[31] || isn[`INSTRUCTION_RB]==5'd0;
2403 51 robfinch
`BITFIELD:      Source2Valid = isn[`INSTRUCTION_RB]==5'd0 || isn[31]==1'b0;
2404 48 robfinch
default:    Source2Valid = TRUE;
2405
endcase
2406
endfunction
2407
 
2408
function Source3Valid;
2409
input [47:0] isn;
2410
case(isn[`INSTRUCTION_OP])
2411
`IVECTOR:
2412
    case(isn[`INSTRUCTION_S2])
2413
    `VEX:       Source3Valid = TRUE;
2414
    default:    Source3Valid = TRUE;
2415
    endcase
2416
`CHK:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2417
`R2:
2418
        if (isn[`INSTRUCTION_L2]==2'b01)
2419
                case(isn[47:42])
2420
    `CMOVEZ,`CMOVNZ:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2421
                default:        Source3Valid = TRUE;
2422
                endcase
2423
        else
2424
    case(isn[`INSTRUCTION_S2])
2425
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2426
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2427
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2428
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2429
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2430
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2431
    `MAJ:               Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2432
    default:    Source3Valid = TRUE;
2433
    endcase
2434
`MEMNDX:
2435
        if (isn[`INSTRUCTION_L2]==2'b00)
2436
    case(isn[`INSTRUCTION_S2])
2437
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2438
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2439
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2440
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2441
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2442
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2443
    default:    Source3Valid = TRUE;
2444
    endcase
2445 51 robfinch
`BITFIELD:      Source3Valid = isn[`INSTRUCTION_RC]==5'd0 || isn[32]==1'b0;
2446 48 robfinch
default:    Source3Valid = TRUE;
2447
endcase
2448
endfunction
2449
 
2450
// Used to indicate to the queue logic that the instruction needs to be
2451
// recycled to the queue VL number of times.
2452
function IsVector;
2453
input [47:0] isn;
2454
case(isn[`INSTRUCTION_OP])
2455 51 robfinch
`MEMNDX:
2456
  case(isn[`INSTRUCTION_S2])
2457
  `LVX,`SVX:  IsVector = TRUE;
2458
  default:    IsVector = FALSE;
2459
  endcase
2460 48 robfinch
`IVECTOR:
2461 51 robfinch
        case(isn[`INSTRUCTION_S2])
2462
        `VMxx:
2463
                case(isn[25:23])
2464
        `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2465
              IsVector = FALSE;
2466
    default:    IsVector = TRUE;
2467
    endcase
2468
  `VEINS:     IsVector = FALSE;
2469
  `VEX:       IsVector = FALSE;
2470
  default:    IsVector = TRUE;
2471
  endcase
2472 48 robfinch
`LV,`SV:    IsVector = TRUE;
2473
default:    IsVector = FALSE;
2474
endcase
2475
endfunction
2476
 
2477
function IsVeins;
2478
input [47:0] isn;
2479
case(isn[`INSTRUCTION_OP])
2480
`IVECTOR:   IsVeins = isn[`INSTRUCTION_S2]==`VEINS;
2481
default:    IsVeins = FALSE;
2482
endcase
2483
endfunction
2484
 
2485
function IsVex;
2486
input [47:0] isn;
2487
case(isn[`INSTRUCTION_OP])
2488
`IVECTOR:   IsVex = isn[`INSTRUCTION_S2]==`VEX;
2489
default:    IsVex = FALSE;
2490
endcase
2491
endfunction
2492
 
2493
function IsVCmprss;
2494
input [47:0] isn;
2495
case(isn[`INSTRUCTION_OP])
2496
`IVECTOR:   IsVCmprss = isn[`INSTRUCTION_S2]==`VCMPRSS || isn[`INSTRUCTION_S2]==`VCIDX;
2497
default:    IsVCmprss = FALSE;
2498
endcase
2499
endfunction
2500
 
2501
function IsVShifti;
2502
input [47:0] isn;
2503
case(isn[`INSTRUCTION_OP])
2504
`IVECTOR:
2505
                    case(isn[`INSTRUCTION_S2])
2506
            `VSHL,`VSHR,`VASR:
2507
                IsVShifti = {isn[25],isn[22]}==2'd2;
2508
            default:    IsVShifti = FALSE;
2509
            endcase
2510
default:    IsVShifti = FALSE;
2511
endcase
2512
endfunction
2513
 
2514
function IsVLS;
2515
input [47:0] isn;
2516
case(isn[`INSTRUCTION_OP])
2517
`MEMNDX:
2518
    case(isn[`INSTRUCTION_S2])
2519
    `LVX,`SVX,`LVWS,`SVWS:  IsVLS = TRUE;
2520
    default:    IsVLS = FALSE;
2521
    endcase
2522
`LV,`SV:    IsVLS = TRUE;
2523
default:    IsVLS = FALSE;
2524
endcase
2525
endfunction
2526
 
2527
function [1:0] fnM2;
2528
input [31:0] isn;
2529
case(isn[`INSTRUCTION_OP])
2530
`RR:    fnM2 = isn[24:23];
2531
default:    fnM2 = 2'b00;
2532
endcase
2533
endfunction
2534
 
2535
function [0:0] IsMem;
2536
input [47:0] isn;
2537
case(isn[`INSTRUCTION_OP])
2538
`MEMNDX:        IsMem = TRUE;
2539
`AMO:   IsMem = TRUE;
2540
`LB:    IsMem = TRUE;
2541
`LBU:   IsMem = TRUE;
2542
`Lx:    IsMem = TRUE;
2543
`LxU:   IsMem = TRUE;
2544
`LWR:   IsMem = TRUE;
2545
`LV,`SV:    IsMem = TRUE;
2546
`INC:           IsMem = TRUE;
2547
`SB:    IsMem = TRUE;
2548
`Sx:    IsMem = TRUE;
2549
`SWC:   IsMem = TRUE;
2550
`CAS:   IsMem = TRUE;
2551
`LVx:           IsMem = TRUE;
2552
default:    IsMem = FALSE;
2553
endcase
2554
endfunction
2555
 
2556
function IsMemNdx;
2557
input [47:0] isn;
2558
case(isn[`INSTRUCTION_OP])
2559
`MEMNDX:        IsMemNdx = TRUE;
2560
default:    IsMemNdx = FALSE;
2561
endcase
2562
endfunction
2563
 
2564
function IsLoad;
2565
input [47:0] isn;
2566
case(isn[`INSTRUCTION_OP])
2567
`MEMNDX:
2568
        if (isn[`INSTRUCTION_L2]==2'b00)
2569 50 robfinch
    case(isn[`INSTRUCTION_S2])
2570
    `LBX:   IsLoad = TRUE;
2571
    `LBUX:  IsLoad = TRUE;
2572
    `LCX:   IsLoad = TRUE;
2573
    `LCUX:  IsLoad = TRUE;
2574
    `LHX:   IsLoad = TRUE;
2575
    `LHUX:  IsLoad = TRUE;
2576
    `LWX:   IsLoad = TRUE;
2577
    `LVBX:      IsLoad = TRUE;
2578
    `LVBUX: IsLoad = TRUE;
2579
    `LVCX:  IsLoad = TRUE;
2580
    `LVCUX: IsLoad = TRUE;
2581
    `LVHX:  IsLoad = TRUE;
2582
    `LVHUX: IsLoad = TRUE;
2583
    `LVWX:  IsLoad = TRUE;
2584
    `LWRX:  IsLoad = TRUE;
2585
    `LVX:   IsLoad = TRUE;
2586
    default: IsLoad = FALSE;
2587
    endcase
2588 48 robfinch
        else
2589
                IsLoad = FALSE;
2590
`LB:    IsLoad = TRUE;
2591
`LBU:   IsLoad = TRUE;
2592
`Lx:    IsLoad = TRUE;
2593
`LxU:   IsLoad = TRUE;
2594
`LWR:   IsLoad = TRUE;
2595
`LV:    IsLoad = TRUE;
2596
`LVx:   IsLoad = TRUE;
2597
default:    IsLoad = FALSE;
2598
endcase
2599
endfunction
2600
 
2601
function IsInc;
2602
input [47:0] isn;
2603
case(isn[`INSTRUCTION_OP])
2604
`MEMNDX:
2605
        if (isn[`INSTRUCTION_L2]==2'b00)
2606
                case(isn[`INSTRUCTION_S2])
2607
            `INC:   IsInc = TRUE;
2608
            default:    IsInc = FALSE;
2609
            endcase
2610
        else
2611
                IsInc = FALSE;
2612
`INC:    IsInc = TRUE;
2613
default:    IsInc = FALSE;
2614
endcase
2615
endfunction
2616
 
2617
function IsSWC;
2618
input [47:0] isn;
2619
case(isn[`INSTRUCTION_OP])
2620
`MEMNDX:
2621
        if (isn[`INSTRUCTION_L2]==2'b00)
2622
                case(isn[`INSTRUCTION_S2])
2623
            `SWCX:   IsSWC = TRUE;
2624
            default:    IsSWC = FALSE;
2625
            endcase
2626
        else
2627
                IsSWC = FALSE;
2628
`SWC:    IsSWC = TRUE;
2629
default:    IsSWC = FALSE;
2630
endcase
2631
endfunction
2632
 
2633
// Aquire / release bits are only available on indexed SWC / LWR
2634
function IsSWCX;
2635
input [47:0] isn;
2636
case(isn[`INSTRUCTION_OP])
2637
`MEMNDX:
2638
        if (isn[`INSTRUCTION_L2]==2'b00)
2639
            case(isn[`INSTRUCTION_S2])
2640
            `SWCX:   IsSWCX = TRUE;
2641
            default:    IsSWCX = FALSE;
2642
            endcase
2643
        else
2644
                IsSWCX = FALSE;
2645
default:    IsSWCX = FALSE;
2646
endcase
2647
endfunction
2648
 
2649
function IsLWR;
2650
input [47:0] isn;
2651
case(isn[`INSTRUCTION_OP])
2652
`MEMNDX:
2653
        if (isn[`INSTRUCTION_L2]==2'b00)
2654
            case(isn[`INSTRUCTION_S2])
2655
            `LWRX:   IsLWR = TRUE;
2656
            default:    IsLWR = FALSE;
2657
            endcase
2658
        else
2659
                IsLWR = FALSE;
2660
`LWR:    IsLWR = TRUE;
2661
default:    IsLWR = FALSE;
2662
endcase
2663
endfunction
2664
 
2665
function IsLWRX;
2666
input [47:0] isn;
2667
case(isn[`INSTRUCTION_OP])
2668
`MEMNDX:
2669
        if (isn[`INSTRUCTION_L2]==2'b00)
2670
            case(isn[`INSTRUCTION_S2])
2671
            `LWRX:   IsLWRX = TRUE;
2672
            default:    IsLWRX = FALSE;
2673
            endcase
2674
        else
2675
                IsLWRX = FALSE;
2676
default:    IsLWRX = FALSE;
2677
endcase
2678
endfunction
2679
 
2680
function IsCAS;
2681
input [47:0] isn;
2682
case(isn[`INSTRUCTION_OP])
2683
`MEMNDX:
2684
        if (isn[`INSTRUCTION_L2]==2'b00)
2685
            case(isn[`INSTRUCTION_S2])
2686
            `CASX:   IsCAS = TRUE;
2687
            default:    IsCAS = FALSE;
2688
            endcase
2689
        else
2690
                IsCAS = FALSE;
2691
`CAS:       IsCAS = TRUE;
2692
default:    IsCAS = FALSE;
2693
endcase
2694
endfunction
2695
 
2696
function IsAMO;
2697
input [47:0] isn;
2698
case(isn[`INSTRUCTION_OP])
2699
`AMO:       IsAMO = TRUE;
2700
default:    IsAMO = FALSE;
2701
endcase
2702
endfunction
2703
 
2704
// Really IsPredictableBranch
2705
// Does not include BccR's
2706
function IsBranch;
2707
input [47:0] isn;
2708
casez(isn[`INSTRUCTION_OP])
2709
`Bcc:   IsBranch = TRUE;
2710
`BBc:   IsBranch = TRUE;
2711
`BEQI:  IsBranch = TRUE;
2712
`CHK:   IsBranch = TRUE;
2713
default:    IsBranch = FALSE;
2714
endcase
2715
endfunction
2716
 
2717
function IsWait;
2718
input [47:0] isn;
2719
IsWait = isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`WAIT;
2720
endfunction
2721
 
2722
function IsCall;
2723
input [47:0] isn;
2724
IsCall = isn[`INSTRUCTION_OP]==`CALL && isn[7]==1'b0;
2725
endfunction
2726
 
2727
function IsJmp;
2728
input [47:0] isn;
2729
IsJmp = isn[`INSTRUCTION_OP]==`JMP && isn[7]==1'b0;
2730
endfunction
2731
 
2732
function IsFlowCtrl;
2733
input [47:0] isn;
2734
casez(isn[`INSTRUCTION_OP])
2735
`BRK:    IsFlowCtrl = TRUE;
2736 49 robfinch
`R2:    case(isn[`INSTRUCTION_S2])
2737 48 robfinch
        `RTI:   IsFlowCtrl = TRUE;
2738
        default:    IsFlowCtrl = FALSE;
2739
        endcase
2740
`Bcc:   IsFlowCtrl = TRUE;
2741
`BBc:           IsFlowCtrl = TRUE;
2742
`BEQI:  IsFlowCtrl = TRUE;
2743
`CHK:   IsFlowCtrl = TRUE;
2744
`JAL:   IsFlowCtrl = TRUE;
2745
`JMP:           IsFlowCtrl = TRUE;
2746
`CALL:  IsFlowCtrl = TRUE;
2747
`RET:   IsFlowCtrl = TRUE;
2748
default:    IsFlowCtrl = FALSE;
2749
endcase
2750
endfunction
2751
 
2752
function IsCache;
2753
input [47:0] isn;
2754
case(isn[`INSTRUCTION_OP])
2755
`MEMNDX:
2756
        if (isn[`INSTRUCTION_L2]==2'b00)
2757
            case(isn[`INSTRUCTION_S2])
2758
            `CACHEX:    IsCache = TRUE;
2759
            default:    IsCache = FALSE;
2760
            endcase
2761
        else
2762
                IsCache = FALSE;
2763
`CACHE: IsCache = TRUE;
2764
default: IsCache = FALSE;
2765
endcase
2766
endfunction
2767
 
2768
function [4:0] CacheCmd;
2769
input [47:0] isn;
2770
case(isn[`INSTRUCTION_OP])
2771
`MEMNDX:
2772
        if (isn[`INSTRUCTION_L2]==2'b00)
2773
            case(isn[`INSTRUCTION_S2])
2774
            `CACHEX:    CacheCmd = isn[22:18];
2775
            default:    CacheCmd = 5'd0;
2776
            endcase
2777
        else
2778
                CacheCmd = 5'd0;
2779
`CACHE: CacheCmd = isn[15:11];
2780
default: CacheCmd = 5'd0;
2781
endcase
2782
endfunction
2783
 
2784
function IsMemsb;
2785
input [47:0] isn;
2786
IsMemsb = (isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMSB);
2787
endfunction
2788
 
2789
function IsSEI;
2790
input [47:0] isn;
2791
IsSEI = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`SEI);
2792
endfunction
2793
 
2794
function IsLV;
2795
input [47:0] isn;
2796
case(isn[`INSTRUCTION_OP])
2797
`MEMNDX:
2798
        if (isn[`INSTRUCTION_L2]==2'b00)
2799
            case(isn[`INSTRUCTION_S2])
2800
            `LVX:   IsLV = TRUE;
2801
            default:    IsLV = FALSE;
2802
            endcase
2803
        else
2804
                IsLV = FALSE;
2805
`LV:        IsLV = TRUE;
2806
default:    IsLV = FALSE;
2807
endcase
2808
endfunction
2809
 
2810
function IsRFW;
2811
input [47:0] isn;
2812
input [5:0] vqei;
2813
input [5:0] vli;
2814
input thrd;
2815
if (fnRt(isn,vqei,vli,thrd)==12'd0)
2816
    IsRFW = FALSE;
2817
else
2818
casez(isn[`INSTRUCTION_OP])
2819
`IVECTOR:   IsRFW = TRUE;
2820
`FVECTOR:   IsRFW = TRUE;
2821
`R2:
2822
        if (isn[`INSTRUCTION_L2]==2'b00)
2823
            case(isn[`INSTRUCTION_S2])
2824
            `R1:    IsRFW = TRUE;
2825
            `ADD:   IsRFW = TRUE;
2826
            `SUB:   IsRFW = TRUE;
2827
            `SLT:   IsRFW = TRUE;
2828
            `SLTU:  IsRFW = TRUE;
2829
            `SLE:   IsRFW = TRUE;
2830
        `SLEU:  IsRFW = TRUE;
2831
            `AND:   IsRFW = TRUE;
2832
            `OR:    IsRFW = TRUE;
2833
            `XOR:   IsRFW = TRUE;
2834
            `MULU:  IsRFW = TRUE;
2835
            `MULSU: IsRFW = TRUE;
2836
            `MUL:   IsRFW = TRUE;
2837 50 robfinch
            `MULUH:  IsRFW = TRUE;
2838
            `MULSUH: IsRFW = TRUE;
2839
            `MULH:   IsRFW = TRUE;
2840
            `DIVU:  IsRFW = TRUE;
2841
            `DIVSU: IsRFW = TRUE;
2842
            `DIV:IsRFW = TRUE;
2843
            `MODU:  IsRFW = TRUE;
2844
            `MODSU: IsRFW = TRUE;
2845
            `MOD:IsRFW = TRUE;
2846 48 robfinch
            `MOV:       IsRFW = TRUE;
2847
            `VMOV:      IsRFW = TRUE;
2848
            `SHIFTR,`SHIFT31,`SHIFT63:
2849
                        IsRFW = TRUE;
2850
            `MIN,`MAX:    IsRFW = TRUE;
2851
            `SEI:       IsRFW = TRUE;
2852
            default:    IsRFW = FALSE;
2853
            endcase
2854
        else
2855
                IsRFW = FALSE;
2856
`MEMNDX:
2857
        if (isn[`INSTRUCTION_L2]==2'b00)
2858 50 robfinch
    case(isn[`INSTRUCTION_S2])
2859
    `LBX:   IsRFW = TRUE;
2860
    `LBUX:  IsRFW = TRUE;
2861
    `LCX:   IsRFW = TRUE;
2862
    `LCUX:  IsRFW = TRUE;
2863
    `LHX:   IsRFW = TRUE;
2864
    `LHUX:  IsRFW = TRUE;
2865
    `LWX:   IsRFW = TRUE;
2866
    `LVBX:  IsRFW = TRUE;
2867
    `LVBUX: IsRFW = TRUE;
2868
    `LVCX:  IsRFW = TRUE;
2869
    `LVCUX: IsRFW = TRUE;
2870
    `LVHX:  IsRFW = TRUE;
2871
    `LVHUX: IsRFW = TRUE;
2872
    `LVWX:  IsRFW = TRUE;
2873
    `LWRX:  IsRFW = TRUE;
2874
    `LVX:   IsRFW = TRUE;
2875
    `CASX:  IsRFW = TRUE;
2876
    default:    IsRFW = FALSE;
2877
    endcase
2878 48 robfinch
        else
2879
                IsRFW = FALSE;
2880
`BBc:
2881
        case(isn[20:19])
2882
        `IBNE:  IsRFW = TRUE;
2883
        `DBNZ:  IsRFW = TRUE;
2884
        default:        IsRFW = FALSE;
2885
        endcase
2886
`BITFIELD:  IsRFW = TRUE;
2887
`ADDI:      IsRFW = TRUE;
2888
`SLTI:      IsRFW = TRUE;
2889
`SLTUI:     IsRFW = TRUE;
2890
`SGTI:      IsRFW = TRUE;
2891
`SGTUI:     IsRFW = TRUE;
2892
`ANDI:      IsRFW = TRUE;
2893
`ORI:       IsRFW = TRUE;
2894
`XORI:      IsRFW = TRUE;
2895
`MULUI:     IsRFW = TRUE;
2896
`MULI:      IsRFW = TRUE;
2897
`DIVUI:     IsRFW = TRUE;
2898
`DIVI:      IsRFW = TRUE;
2899
`MODI:      IsRFW = TRUE;
2900
`JAL:       IsRFW = TRUE;
2901
`CALL:      IsRFW = TRUE;
2902
`RET:       IsRFW = TRUE;
2903
`LB:        IsRFW = TRUE;
2904
`LBU:       IsRFW = TRUE;
2905
`Lx:        IsRFW = TRUE;
2906
`LWR:       IsRFW = TRUE;
2907
`LV:        IsRFW = TRUE;
2908
`LVx:                           IsRFW = TRUE;
2909
`CAS:       IsRFW = TRUE;
2910
`AMO:                           IsRFW = TRUE;
2911
`CSRRW:                 IsRFW = TRUE;
2912 56 robfinch
`AUIPC:                 IsRFW = TRUE;
2913 55 robfinch
`LUI:                           IsRFW = TRUE;
2914 48 robfinch
default:    IsRFW = FALSE;
2915
endcase
2916
endfunction
2917
 
2918
function IsShifti;
2919
input [47:0] isn;
2920
case(isn[`INSTRUCTION_OP])
2921
`R2:
2922
        if (isn[`INSTRUCTION_L2]==2'b00)
2923
            case(isn[`INSTRUCTION_S2])
2924
            `SHIFT31,`SHIFT63:
2925
                IsShifti = TRUE;
2926
            default: IsShifti = FALSE;
2927
            endcase
2928
    else
2929
        IsShifti = FALSE;
2930
default: IsShifti = FALSE;
2931
endcase
2932
endfunction
2933
 
2934
function IsRtop;
2935
input [47:0] isn;
2936
case(isn[`INSTRUCTION_OP])
2937
`R2:
2938
        if (isn[`INSTRUCTION_L2]==2'b01)
2939
            case(isn[47:42])
2940
            `RTOP: IsRtop = TRUE;
2941
            default: IsRtop = FALSE;
2942
            endcase
2943
    else
2944
        IsRtop = FALSE;
2945
default: IsRtop = FALSE;
2946
endcase
2947
endfunction
2948
 
2949
function IsMul;
2950
input [47:0] isn;
2951
case(isn[`INSTRUCTION_OP])
2952 50 robfinch
`R2:
2953 48 robfinch
        if (isn[`INSTRUCTION_L2]==2'b00)
2954 50 robfinch
    case(isn[`INSTRUCTION_S2])
2955
    `MULU,`MULSU,`MUL: IsMul = TRUE;
2956
    `MULUH,`MULSUH,`MULH: IsMul = TRUE;
2957
    default:    IsMul = FALSE;
2958
    endcase
2959 48 robfinch
        else
2960
                IsMul = FALSE;
2961
`MULUI,`MULI:  IsMul = TRUE;
2962
default:    IsMul = FALSE;
2963
endcase
2964
endfunction
2965
 
2966
function IsDivmod;
2967
input [47:0] isn;
2968
case(isn[`INSTRUCTION_OP])
2969 50 robfinch
`R2:
2970 48 robfinch
        if (isn[`INSTRUCTION_L2]==2'b00)
2971 50 robfinch
    case(isn[`INSTRUCTION_S2])
2972
    `DIVU,`DIVSU,`DIV: IsDivmod = TRUE;
2973
    `MODU,`MODSU,`MOD: IsDivmod = TRUE;
2974
    default: IsDivmod = FALSE;
2975
    endcase
2976 48 robfinch
        else
2977
                IsDivmod = FALSE;
2978
`DIVUI,`DIVI,`MODI:  IsDivmod = TRUE;
2979
default:    IsDivmod = FALSE;
2980
endcase
2981
endfunction
2982
 
2983
function IsExec;
2984
input [47:0] isn;
2985
case(isn[`INSTRUCTION_OP])
2986
`EXEC:  IsExec = TRUE;
2987
default:        IsExec = FALSE;
2988
endcase
2989
endfunction
2990
 
2991
function [7:0] fnSelect;
2992
input [47:0] ins;
2993 49 robfinch
input [`ABITS] adr;
2994 48 robfinch
begin
2995
        case(ins[`INSTRUCTION_OP])
2996
        `MEMNDX:
2997
                if (ins[`INSTRUCTION_L2]==2'b00)
2998
                   case(ins[`INSTRUCTION_S2])
2999 53 robfinch
               `LBX,`LBUX,`SBX,`LVBX,`LVBUX:
3000 48 robfinch
                   case(adr[2:0])
3001
                   3'd0:    fnSelect = 8'h01;
3002
                   3'd1:    fnSelect = 8'h02;
3003
                   3'd2:    fnSelect = 8'h04;
3004
                   3'd3:    fnSelect = 8'h08;
3005
                   3'd4:    fnSelect = 8'h10;
3006
                   3'd5:    fnSelect = 8'h20;
3007
                   3'd6:    fnSelect = 8'h40;
3008
                   3'd7:    fnSelect = 8'h80;
3009
                   endcase
3010 53 robfinch
                `LCX,`LCUX,`SCX,`LVCX,`LVCUX:
3011 48 robfinch
                    case(adr[2:1])
3012
                    2'd0:   fnSelect = 8'h03;
3013
                    2'd1:   fnSelect = 8'h0C;
3014
                    2'd2:   fnSelect = 8'h30;
3015
                    2'd3:   fnSelect = 8'hC0;
3016
                    endcase
3017 53 robfinch
                `LHX,`LHUX,`SHX,`LVHX,`LVHUX:
3018 48 robfinch
                   case(adr[2])
3019
                   1'b0:    fnSelect = 8'h0F;
3020
                   1'b1:    fnSelect = 8'hF0;
3021
                   endcase
3022 53 robfinch
               `INC,`LVWX,
3023 48 robfinch
               `LWX,`SWX,`LWRX,`SWCX,`LVX,`SVX,`CASX:
3024
                   fnSelect = 8'hFF;
3025
               default: fnSelect = 8'h00;
3026
                   endcase
3027
           else
3028
                fnSelect = 8'h00;
3029 52 robfinch
  `LB,`LBU,`SB:
3030 48 robfinch
                case(adr[2:0])
3031
                3'd0:   fnSelect = 8'h01;
3032
                3'd1:   fnSelect = 8'h02;
3033
                3'd2:   fnSelect = 8'h04;
3034
                3'd3:   fnSelect = 8'h08;
3035
                3'd4:   fnSelect = 8'h10;
3036
                3'd5:   fnSelect = 8'h20;
3037
                3'd6:   fnSelect = 8'h40;
3038
                3'd7:   fnSelect = 8'h80;
3039
                endcase
3040 53 robfinch
    `Lx,`LxU,`Sx,`LVx:
3041 48 robfinch
        casez(ins[20:18])
3042
        3'b100: fnSelect = 8'hFF;
3043
        3'b?10: fnSelect = adr[2] ? 8'hF0 : 8'h0F;
3044
        3'b??1:
3045
        case(adr[2:1])
3046
        2'd0:   fnSelect = 8'h03;
3047
        2'd1:   fnSelect = 8'h0C;
3048
        2'd2:   fnSelect = 8'h30;
3049
        2'd3:   fnSelect = 8'hC0;
3050
        endcase
3051
      default: fnSelect = 8'h00;
3052
      endcase
3053
        `INC,
3054
        `LWR,`SWC,`CAS:   fnSelect = 8'hFF;
3055
        `LV,`SV:   fnSelect = 8'hFF;
3056
        `AMO:
3057
                case(ins[23:21])
3058
                3'd0:   fnSelect = {8'h01 << adr[2:0]};
3059
                3'd1:   fnSelect = {8'h03 << {adr[2:1],1'b0}};
3060
                3'd2:   fnSelect = {8'h0F << {adr[2],2'b00}};
3061
                3'd3:   fnSelect = 8'hFF;
3062
                default:        fnSelect = 8'hFF;
3063
                endcase
3064
        default:        fnSelect = 8'h00;
3065
        endcase
3066
end
3067
endfunction
3068
/*
3069
function [63:0] fnDatc;
3070
input [47:0] ins;
3071
input [63:0] dat;
3072
case(ins[`INSTRUCTION_OP])
3073
`R2:
3074
        if (isn[`INSTRUCTION_L2]==2'b01)
3075
                case(ins[47:42])
3076
                `FINDB:         fnDatc = dat[7:0];
3077
                `FINDC:         fnDatc = dat[15:0];
3078
                `FINDH:         fnDatc = dat[31:0];
3079
                `FINDW:         fnDatc = dat[63:0];
3080
                default:        fnDatc = dat[63:0];
3081
                endcase
3082
        else
3083
                fnDatc = dat[63:0];
3084
default:        fnDatc = dat[63:0];
3085
endcase
3086
endfunction
3087
*/
3088
/*
3089
function [63:0] fnMemInc;
3090
input [47:0] ins;
3091
case(ins[`INSTRUCTION_OP])
3092
`R2:
3093
        if (isn[`INSTRUCTION_L2]==2'b01)
3094
                case(ins[47:42])
3095
                `FINDB:         fnMemInc = 32'd1;
3096
                `FINDC:         fnMemInc = 32'd2;
3097
                `FINDH:         fnMemInc = 32'd4;
3098
                `FINDW:         fnMemInc = 32'd8;
3099
                default:        fnMemInc = 32'd8;
3100
                endcase
3101
        else
3102
                fnMemInc = 32'd8;
3103
default:        fnMemInc = 32'd8;
3104
endcase
3105
endfunction
3106
*/
3107
function [63:0] fnDati;
3108
input [47:0] ins;
3109 49 robfinch
input [`ABITS] adr;
3110 48 robfinch
input [63:0] dat;
3111
case(ins[`INSTRUCTION_OP])
3112
`MEMNDX:
3113
        if (ins[`INSTRUCTION_L2]==2'b00)
3114
            case(ins[`INSTRUCTION_S2])
3115 53 robfinch
            `LBX,`LVBX:
3116 48 robfinch
                case(adr[2:0])
3117
                3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3118
                3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3119
                3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3120
                3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3121
                3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3122
                3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3123
                3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3124
                3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3125
                endcase
3126 53 robfinch
            `LBUX,`LVBUX:
3127 48 robfinch
                case(adr[2:0])
3128
                3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3129
                3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3130
                3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3131
                3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3132
                3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3133
                3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3134
                3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3135
                3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3136
                endcase
3137 53 robfinch
            `LCX,`LVCX:
3138 48 robfinch
                case(adr[2:1])
3139
                2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3140
                2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3141
                2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3142
                2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3143
                endcase
3144 53 robfinch
            `LCUX,`LVCUX:
3145 48 robfinch
                case(adr[2:1])
3146
                2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3147
                2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3148
                2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3149
                2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3150
                endcase
3151 53 robfinch
            `LHX,`LVHX:
3152 48 robfinch
                case(adr[2])
3153
                1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3154
                1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3155
                endcase
3156 53 robfinch
            `LHUX,`LVHUX:
3157 48 robfinch
                case(adr[2])
3158
                1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3159
                1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3160
                endcase
3161 53 robfinch
            `LWX,`LWRX,`LVX,`CAS,`LVWX:  fnDati = dat;
3162 48 robfinch
            default:    fnDati = dat;
3163
            endcase
3164
        else
3165
                fnDati = dat;
3166
`LB:
3167
  case(adr[2:0])
3168
  3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3169
  3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3170
  3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3171
  3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3172
  3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3173
  3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3174
  3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3175
  3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3176
  endcase
3177
`LBU:
3178
  case(adr[2:0])
3179
  3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3180
  3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3181
  3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3182
  3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3183
  3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3184
  3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3185
  3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3186
  3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3187
  endcase
3188 53 robfinch
`Lx,`LVx:
3189 48 robfinch
        casez(ins[20:18])
3190
        3'b100: fnDati = dat;
3191
        3'b?10:
3192
          case(adr[2])
3193
          1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3194
          1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3195
          endcase
3196
        3'b??1:
3197
          case(adr[2:1])
3198
          2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3199
          2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3200
          2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3201
          2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3202
          endcase
3203
        endcase
3204
`LxU:
3205
        casez(ins[20:18])
3206
        3'b100: fnDati = dat;
3207
        3'b?10:
3208
          case(adr[2])
3209
          1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3210
          1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3211
          endcase
3212
        3'b??1:
3213
          case(adr[2:1])
3214
          2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3215
          2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3216
          2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3217
          2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3218
          endcase
3219
        endcase
3220
`LWR,`LV,`CAS,`AMO:   fnDati = dat;
3221
default:    fnDati = dat;
3222
endcase
3223
endfunction
3224
 
3225
function [63:0] fnDato;
3226
input [47:0] isn;
3227
input [63:0] dat;
3228
case(isn[`INSTRUCTION_OP])
3229
`MEMNDX:
3230
        if (isn[`INSTRUCTION_L2]==2'b00)
3231
                case(isn[`INSTRUCTION_S2])
3232
                `SBX:   fnDato = {8{dat[7:0]}};
3233
                `SCX:   fnDato = {4{dat[15:0]}};
3234
                `SHX:   fnDato = {2{dat[31:0]}};
3235
                default:    fnDato = dat;
3236
                endcase
3237
        else
3238
                fnDato = dat;
3239
`SB:   fnDato = {8{dat[7:0]}};
3240
`Sx:
3241 49 robfinch
        casez(isn[20:18])
3242 48 robfinch
        3'b100: fnDato = dat;
3243
        3'b?10: fnDato = {2{dat[31:0]}};
3244
        3'b??1: fnDato = {4{dat[15:0]}};
3245
        default:        fnDato = dat;
3246
        endcase
3247
`AMO:
3248
        case(isn[23:21])
3249
        3'd0:   fnDato = {8{dat[7:0]}};
3250
        3'd1:   fnDato = {4{dat[15:0]}};
3251
        3'd2:   fnDato = {2{dat[31:0]}};
3252
        3'd3:   fnDato = dat;
3253
        default:        fnDato = dat;
3254
        endcase
3255
default:    fnDato = dat;
3256
endcase
3257
endfunction
3258
 
3259
// Indicate if the ALU instruction is valid immediately (single cycle operation)
3260
function IsSingleCycle;
3261
input [47:0] isn;
3262
IsSingleCycle = !(IsMul(isn)|IsDivmod(isn));
3263
endfunction
3264
 
3265
 
3266 53 robfinch
generate begin : gDecocderInst
3267
for (g = 0; g < QENTRIES; g = g + 1) begin
3268 48 robfinch
`ifdef SUPPORT_SMT
3269 53 robfinch
decoder8 iq0(.num({iqentry_tgt[g][8:7],iqentry_tgt[g][5:0]}), .out(iq_out[g]));
3270 48 robfinch
`else
3271 53 robfinch
decoder7 iq0(.num({iqentry_tgt[g][7],iqentry_tgt[g][5:0]}), .out(iq_out[g]));
3272 48 robfinch
`endif
3273 53 robfinch
end
3274
end
3275
endgenerate
3276 48 robfinch
 
3277
initial begin: Init
3278
        //
3279
        //
3280
        // set up panic messages
3281
        message[ `PANIC_NONE ]                  = "NONE            ";
3282
        message[ `PANIC_FETCHBUFBEQ ]           = "FETCHBUFBEQ     ";
3283
        message[ `PANIC_INVALIDISLOT ]          = "INVALIDISLOT    ";
3284
        message[ `PANIC_IDENTICALDRAMS ]        = "IDENTICALDRAMS  ";
3285
        message[ `PANIC_OVERRUN ]               = "OVERRUN         ";
3286
        message[ `PANIC_HALTINSTRUCTION ]       = "HALTINSTRUCTION ";
3287
        message[ `PANIC_INVALIDMEMOP ]          = "INVALIDMEMOP    ";
3288
        message[ `PANIC_INVALIDFBSTATE ]        = "INVALIDFBSTATE  ";
3289
        message[ `PANIC_INVALIDIQSTATE ]        = "INVALIDIQSTATE  ";
3290
        message[ `PANIC_BRANCHBACK ]            = "BRANCHBACK      ";
3291
        message[ `PANIC_MEMORYRACE ]            = "MEMORYRACE      ";
3292
        message[ `PANIC_ALU0ONLY ] = "ALU0 Only       ";
3293
 
3294
        for (n = 0; n < 64; n = n + 1)
3295
                codebuf[n] <= 48'h0;
3296
 
3297
end
3298
 
3299
// ---------------------------------------------------------------------------
3300
// FETCH
3301
// ---------------------------------------------------------------------------
3302
//
3303
assign fetchbuf0_mem   = IsMem(fetchbuf0_instr);
3304
assign fetchbuf0_memld = IsMem(fetchbuf0_instr) & IsLoad(fetchbuf0_instr);
3305
assign fetchbuf0_rfw   = IsRFW(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd);
3306
 
3307 57 robfinch
generate begin: gFetchbufDec
3308
if (`WAYS > 1) begin
3309 48 robfinch
assign fetchbuf1_mem   = IsMem(fetchbuf1_instr);
3310
assign fetchbuf1_memld = IsMem(fetchbuf1_instr) & IsLoad(fetchbuf1_instr);
3311
assign fetchbuf1_rfw   = IsRFW(fetchbuf1_instr,vqe1,vl,fetchbuf1_thrd);
3312 57 robfinch
end
3313
if (`WAYS > 2) begin
3314
assign fetchbuf2_mem   = IsMem(fetchbuf2_instr);
3315
assign fetchbuf2_memld = IsMem(fetchbuf2_instr) & IsLoad(fetchbuf2_instr);
3316
assign fetchbuf2_rfw   = IsRFW(fetchbuf2_instr,vqe2,vl,fetchbuf2_thrd);
3317
end
3318
end
3319
endgenerate
3320 48 robfinch
 
3321 57 robfinch
generate begin : gFetchbufInst
3322
if (`WAYS > 2) begin : gb1
3323
FT64_fetchbuf_x3 #(AMSB,RSTPC) ufb1
3324
(
3325
  .rst(rst),
3326
  .clk4x(clk4x),
3327
  .clk(clk),
3328
  .fcu_clk(fcu_clk),
3329
  .cs_i(adr_o[31:16]==16'hFFFF),
3330
  .cyc_i(cyc_o),
3331
  .stb_i(stb_o),
3332
  .ack_o(dc_ack),
3333
  .we_i(we_o),
3334
  .adr_i(adr_o[15:0]),
3335
  .dat_i(dat_o[47:0]),
3336
  .cmpgrp(cr0[10:8]),
3337
  .freezePC(freezePC),
3338
  .regLR(regLR),
3339
  .thread_en(thread_en),
3340
  .insn0(insn0),
3341
  .insn1(insn1),
3342
  .insn1(insn2),
3343
  .phit(phit),
3344
  .threadx(threadx),
3345
  .branchmiss(branchmiss),
3346
  .misspc(misspc),
3347
  .branchmiss_thrd(branchmiss_thrd),
3348
  .predict_takenA(predict_takenA),
3349
  .predict_takenB(predict_takenB),
3350
  .predict_takenC(predict_takenC),
3351
  .predict_takenD(predict_takenD),
3352
  .predict_takenE(predict_takenE),
3353
  .predict_takenF(predict_takenF),
3354
  .predict_taken0(predict_taken0),
3355
  .predict_taken1(predict_taken1),
3356
  .predict_taken1(predict_taken2),
3357
  .queued1(queued1),
3358
  .queued2(queued2),
3359
  .queued2(queued3),
3360
  .queuedNop(queuedNop),
3361
  .pc0(pc0),
3362
  .pc1(pc1),
3363
  .fetchbuf(fetchbuf),
3364
  .fetchbufA_v(fetchbufA_v),
3365
  .fetchbufB_v(fetchbufB_v),
3366
  .fetchbufC_v(fetchbufC_v),
3367
  .fetchbufD_v(fetchbufD_v),
3368
  .fetchbufD_v(fetchbufE_v),
3369
  .fetchbufD_v(fetchbufF_v),
3370
  .fetchbufA_pc(fetchbufA_pc),
3371
  .fetchbufB_pc(fetchbufB_pc),
3372
  .fetchbufC_pc(fetchbufC_pc),
3373
  .fetchbufD_pc(fetchbufD_pc),
3374
  .fetchbufD_pc(fetchbufE_pc),
3375
  .fetchbufD_pc(fetchbufF_pc),
3376
  .fetchbufA_instr(fetchbufA_instr),
3377
  .fetchbufB_instr(fetchbufB_instr),
3378
  .fetchbufC_instr(fetchbufC_instr),
3379
  .fetchbufD_instr(fetchbufD_instr),
3380
  .fetchbufE_instr(fetchbufE_instr),
3381
  .fetchbufF_instr(fetchbufF_instr),
3382
  .fetchbuf0_instr(fetchbuf0_instr),
3383
  .fetchbuf1_instr(fetchbuf1_instr),
3384
  .fetchbuf0_thrd(fetchbuf0_thrd),
3385
  .fetchbuf1_thrd(fetchbuf1_thrd),
3386
  .fetchbuf2_thrd(fetchbuf2_thrd),
3387
  .fetchbuf0_pc(fetchbuf0_pc),
3388
  .fetchbuf1_pc(fetchbuf1_pc),
3389
  .fetchbuf2_pc(fetchbuf2_pc),
3390
  .fetchbuf0_v(fetchbuf0_v),
3391
  .fetchbuf1_v(fetchbuf1_v),
3392
  .fetchbuf2_v(fetchbuf2_v),
3393
  .fetchbuf0_insln(fetchbuf0_insln),
3394
  .fetchbuf1_insln(fetchbuf1_insln),
3395
  .fetchbuf2_insln(fetchbuf2_insln),
3396
  .codebuf0(codebuf[insn0[21:16]]),
3397
  .codebuf1(codebuf[insn1[21:16]]),
3398
  .codebuf2(codebuf[insn2[21:16]]),
3399
  .btgtA(btgtA),
3400
  .btgtB(btgtB),
3401
  .btgtC(btgtC),
3402
  .btgtD(btgtD),
3403
  .btgtE(btgtE),
3404
  .btgtF(btgtF),
3405
  .nop_fetchbuf(nop_fetchbuf),
3406
  .take_branch0(take_branch0),
3407
  .take_branch1(take_branch1),
3408
  .take_branch2(take_branch2),
3409
  .stompedRets(stompedOnRets),
3410
  .panic(fb_panic)
3411
);
3412
end
3413
else if (`WAYS > 1) begin : gb1
3414 48 robfinch
FT64_fetchbuf #(AMSB,RSTPC) ufb1
3415
(
3416 49 robfinch
  .rst(rst),
3417
  .clk4x(clk4x),
3418
  .clk(clk),
3419
  .fcu_clk(fcu_clk),
3420
  .cs_i(adr_o[31:16]==16'hFFFF),
3421
  .cyc_i(cyc_o),
3422
  .stb_i(stb_o),
3423
  .ack_o(dc_ack),
3424
  .we_i(we_o),
3425
  .adr_i(adr_o[15:0]),
3426 56 robfinch
  .dat_i(dat_o[47:0]),
3427 55 robfinch
  .cmpgrp(cr0[10:8]),
3428 52 robfinch
  .freezePC(freezePC),
3429 49 robfinch
  .regLR(regLR),
3430
  .thread_en(thread_en),
3431
  .insn0(insn0),
3432
  .insn1(insn1),
3433
  .phit(phit),
3434
  .threadx(threadx),
3435
  .branchmiss(branchmiss),
3436
  .misspc(misspc),
3437
  .branchmiss_thrd(branchmiss_thrd),
3438
  .predict_takenA(predict_takenA),
3439
  .predict_takenB(predict_takenB),
3440
  .predict_takenC(predict_takenC),
3441
  .predict_takenD(predict_takenD),
3442
  .predict_taken0(predict_taken0),
3443
  .predict_taken1(predict_taken1),
3444
  .queued1(queued1),
3445
  .queued2(queued2),
3446
  .queuedNop(queuedNop),
3447
  .pc0(pc0),
3448
  .pc1(pc1),
3449
  .fetchbuf(fetchbuf),
3450
  .fetchbufA_v(fetchbufA_v),
3451
  .fetchbufB_v(fetchbufB_v),
3452
  .fetchbufC_v(fetchbufC_v),
3453
  .fetchbufD_v(fetchbufD_v),
3454
  .fetchbufA_pc(fetchbufA_pc),
3455
  .fetchbufB_pc(fetchbufB_pc),
3456
  .fetchbufC_pc(fetchbufC_pc),
3457
  .fetchbufD_pc(fetchbufD_pc),
3458
  .fetchbufA_instr(fetchbufA_instr),
3459
  .fetchbufB_instr(fetchbufB_instr),
3460
  .fetchbufC_instr(fetchbufC_instr),
3461
  .fetchbufD_instr(fetchbufD_instr),
3462
  .fetchbuf0_instr(fetchbuf0_instr),
3463
  .fetchbuf1_instr(fetchbuf1_instr),
3464
  .fetchbuf0_thrd(fetchbuf0_thrd),
3465
  .fetchbuf1_thrd(fetchbuf1_thrd),
3466
  .fetchbuf0_pc(fetchbuf0_pc),
3467
  .fetchbuf1_pc(fetchbuf1_pc),
3468
  .fetchbuf0_v(fetchbuf0_v),
3469
  .fetchbuf1_v(fetchbuf1_v),
3470
  .fetchbuf0_insln(fetchbuf0_insln),
3471
  .fetchbuf1_insln(fetchbuf1_insln),
3472
  .codebuf0(codebuf[insn0[21:16]]),
3473
  .codebuf1(codebuf[insn1[21:16]]),
3474
  .btgtA(btgtA),
3475
  .btgtB(btgtB),
3476
  .btgtC(btgtC),
3477
  .btgtD(btgtD),
3478
  .nop_fetchbuf(nop_fetchbuf),
3479
  .take_branch0(take_branch0),
3480
  .take_branch1(take_branch1),
3481
  .stompedRets(stompedOnRets),
3482
  .panic(fb_panic)
3483 48 robfinch
);
3484 57 robfinch
end
3485
else begin : gb1
3486
FT64_fetchbuf_x1 #(AMSB,RSTPC) ufb1
3487
(
3488
  .rst(rst),
3489
  .clk4x(clk4x),
3490
  .clk(clk),
3491
  .fcu_clk(fcu_clk),
3492
  .cs_i(adr_o[31:16]==16'hFFFF),
3493
  .cyc_i(cyc_o),
3494
  .stb_i(stb_o),
3495
  .ack_o(dc_ack),
3496
  .we_i(we_o),
3497
  .adr_i(adr_o[15:0]),
3498
  .dat_i(dat_o[47:0]),
3499
  .cmpgrp(cr0[10:8]),
3500
  .freezePC(freezePC),
3501
  .regLR(regLR),
3502
  .thread_en(thread_en),
3503
  .insn0(insn0),
3504
  .phit(phit),
3505
  .threadx(threadx),
3506
  .branchmiss(branchmiss),
3507
  .misspc(misspc),
3508
  .branchmiss_thrd(branchmiss_thrd),
3509
  .predict_takenA(predict_takenA),
3510
  .predict_takenB(predict_takenB),
3511
  .predict_taken0(predict_taken0),
3512
  .queued1(queued1),
3513
  .queuedNop(queuedNop),
3514
  .pc0(pc0),
3515
  .fetchbuf(fetchbuf),
3516
  .fetchbufA_v(fetchbufA_v),
3517
  .fetchbufB_v(fetchbufB_v),
3518
  .fetchbufA_pc(fetchbufA_pc),
3519
  .fetchbufB_pc(fetchbufB_pc),
3520
  .fetchbufA_instr(fetchbufA_instr),
3521
  .fetchbufB_instr(fetchbufB_instr),
3522
  .fetchbuf0_instr(fetchbuf0_instr),
3523
  .fetchbuf0_thrd(fetchbuf0_thrd),
3524
  .fetchbuf0_pc(fetchbuf0_pc),
3525
  .fetchbuf0_v(fetchbuf0_v),
3526
  .fetchbuf0_insln(fetchbuf0_insln),
3527
  .codebuf0(codebuf[insn0[21:16]]),
3528
  .btgtA(btgtA),
3529
  .btgtB(btgtB),
3530
  .nop_fetchbuf(nop_fetchbuf),
3531
  .take_branch0(take_branch0),
3532
  .stompedRets(stompedOnRets),
3533
  .panic(fb_panic)
3534
);
3535
assign fetchbuf1_v = `INV;
3536
end
3537
end
3538
endgenerate
3539 48 robfinch
 
3540
 
3541
 
3542
//initial begin: stop_at
3543
//#1000000; panic <= `PANIC_OVERRUN;
3544
//end
3545
 
3546
//
3547
// BRANCH-MISS LOGIC: livetarget
3548
//
3549
// livetarget implies that there is a not-to-be-stomped instruction that targets the register in question
3550
// therefore, if it is zero it implies the rf_v value should become VALID on a branchmiss
3551
// 
3552
 
3553
generate begin : live_target
3554
    for (g = 1; g < PREGS; g = g + 1) begin : lvtgt
3555
    assign livetarget[g] = iqentry_0_livetarget[g] |
3556
                        iqentry_1_livetarget[g] |
3557
                        iqentry_2_livetarget[g] |
3558
                        iqentry_3_livetarget[g] |
3559
                        iqentry_4_livetarget[g] |
3560
                        iqentry_5_livetarget[g] |
3561
                        iqentry_6_livetarget[g] |
3562 52 robfinch
                        iqentry_7_livetarget[g] |
3563
                        iqentry_8_livetarget[g] |
3564
                        iqentry_9_livetarget[g]
3565
                        ;
3566 48 robfinch
    end
3567
end
3568
endgenerate
3569
 
3570 53 robfinch
    assign  iqentry_0_livetarget = {PREGS {iqentry_v[0]}} & {PREGS {~iqentry_stomp[0] && iqentry_thrd[0]==branchmiss_thrd}} & iq_out[0],
3571
            iqentry_1_livetarget = {PREGS {iqentry_v[1]}} & {PREGS {~iqentry_stomp[1] && iqentry_thrd[1]==branchmiss_thrd}} & iq_out[1],
3572
            iqentry_2_livetarget = {PREGS {iqentry_v[2]}} & {PREGS {~iqentry_stomp[2] && iqentry_thrd[2]==branchmiss_thrd}} & iq_out[2],
3573
            iqentry_3_livetarget = {PREGS {iqentry_v[3]}} & {PREGS {~iqentry_stomp[3] && iqentry_thrd[3]==branchmiss_thrd}} & iq_out[3],
3574
            iqentry_4_livetarget = {PREGS {iqentry_v[4]}} & {PREGS {~iqentry_stomp[4] && iqentry_thrd[4]==branchmiss_thrd}} & iq_out[4],
3575
            iqentry_5_livetarget = {PREGS {iqentry_v[5]}} & {PREGS {~iqentry_stomp[5] && iqentry_thrd[5]==branchmiss_thrd}} & iq_out[5],
3576
            iqentry_6_livetarget = {PREGS {iqentry_v[6]}} & {PREGS {~iqentry_stomp[6] && iqentry_thrd[6]==branchmiss_thrd}} & iq_out[6],
3577
            iqentry_7_livetarget = {PREGS {iqentry_v[7]}} & {PREGS {~iqentry_stomp[7] && iqentry_thrd[7]==branchmiss_thrd}} & iq_out[7],
3578
            iqentry_8_livetarget = {PREGS {iqentry_v[8]}} & {PREGS {~iqentry_stomp[8] && iqentry_thrd[8]==branchmiss_thrd}} & iq_out[8],
3579
            iqentry_9_livetarget = {PREGS {iqentry_v[9]}} & {PREGS {~iqentry_stomp[9] && iqentry_thrd[9]==branchmiss_thrd}} & iq_out[9]
3580 52 robfinch
            ;
3581 48 robfinch
 
3582 52 robfinch
//
3583
// BRANCH-MISS LOGIC: latestID
3584
//
3585
// latestID is the instruction queue ID of the newest instruction (latest) that targets
3586
// a particular register.  looks a lot like scheduling logic, but in reverse.
3587
// 
3588
always @*
3589
        for (n = 0; n < QENTRIES; n = n + 1) begin
3590
                iqentry_cumulative[n] = 0;
3591
                for (j = n; j < n + QENTRIES; j = j + 1) begin
3592
                        if (missid==(j % QENTRIES))
3593
                                for (k = n; k <= j; k = k + 1)
3594
                                        iqentry_cumulative[n] = iqentry_cumulative[n] | iqentry_livetarget[k % QENTRIES];
3595
                end
3596
        end
3597 48 robfinch
 
3598 53 robfinch
always @*
3599
        for (n = 0; n < QENTRIES; n = n + 1)
3600
    iqentry_latestID[n] = (missid == n || ((iqentry_livetarget[n] & iqentry_cumulative[(n+1)%QENTRIES]) == {PREGS{1'b0}}))
3601
                                    ? iqentry_livetarget[n]
3602 52 robfinch
                                    : {PREGS{1'b0}};
3603 48 robfinch
 
3604 53 robfinch
always @*
3605
        for (n = 0; n < QENTRIES; n = n + 1)
3606
          iqentry_source[n] = | iqentry_latestID[n];
3607 48 robfinch
 
3608
reg vqueued2;
3609
assign Ra0 = fnRa(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3610
assign Rb0 = fnRb(fetchbuf0_instr,1'b0,vqe0,rfoa0[5:0],rfoa1[5:0],fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3611
assign Rc0 = fnRc(fetchbuf0_instr,vqe0,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3612
assign Rt0 = fnRt(fetchbuf0_instr,vqet0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3613
assign Ra1 = fnRa(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3614
assign Rb1 = fnRb(fetchbuf1_instr,1'b1,vqueued2 ? vqe0 + 1 : vqe1,rfoa0[5:0],rfoa1[5:0],fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3615
assign Rc1 = fnRc(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3616
assign Rt1 = fnRt(fetchbuf1_instr,vqueued2 ? vqet0 + 1 : vqet1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3617
 
3618 49 robfinch
//
3619
// additional logic for ISSUE
3620
//
3621
// for the moment, we look at ALU-input buffers to allow back-to-back issue of 
3622
// dependent instructions ... we do not, however, look ahead for DRAM requests 
3623
// that will become valid in the next cycle.  instead, these have to propagate
3624
// their results into the IQ entry directly, at which point it becomes issue-able
3625
//
3626 48 robfinch
 
3627 49 robfinch
// note that, for all intents & purposes, iqentry_done == iqentry_agen ... no need to duplicate
3628 48 robfinch
 
3629
wire [QENTRIES-1:0] args_valid;
3630
wire [QENTRIES-1:0] could_issue;
3631
wire [QENTRIES-1:0] could_issueid;
3632
 
3633
generate begin : issue_logic
3634
for (g = 0; g < QENTRIES; g = g + 1)
3635
begin
3636
assign args_valid[g] =
3637
                  (iqentry_a1_v[g]
3638 49 robfinch
`ifdef FU_BYPASS
3639 48 robfinch
        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3640 49 robfinch
        || ((iqentry_a1_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3641
        || ((iqentry_a1_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
3642
`endif
3643
        )
3644 48 robfinch
    && (iqentry_a2_v[g]
3645
        || (iqentry_mem[g] & ~iqentry_agen[g] & ~iqentry_memndx[g])    // a2 needs to be valid for indexed instruction
3646 49 robfinch
`ifdef FU_BYPASS
3647 48 robfinch
        || (iqentry_a2_s[g] == alu0_sourceid && alu0_dataready)
3648 49 robfinch
        || ((iqentry_a2_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3649
        || ((iqentry_a2_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
3650
`endif
3651
        )
3652 48 robfinch
    && (iqentry_a3_v[g]
3653
//        || (iqentry_mem[g] & ~iqentry_agen[g])
3654 49 robfinch
`ifdef FU_BYPASS
3655 48 robfinch
        || (iqentry_a3_s[g] == alu0_sourceid && alu0_dataready)
3656 49 robfinch
        || ((iqentry_a3_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3657
`endif
3658
        )
3659 48 robfinch
    ;
3660
 
3661
assign could_issue[g] = iqentry_v[g] && !iqentry_done[g] && !iqentry_out[g]
3662
                                                                                                && args_valid[g]
3663
                                                                                                && iqentry_iv[g]
3664
                        && (iqentry_mem[g] ? !iqentry_agen[g] : 1'b1);
3665
 
3666 52 robfinch
assign could_issueid[g] = (iqentry_v[g])// || (g==tail0 && canq1))// || (g==tail1 && canq2))
3667
                                                                                                                && !iqentry_iv[g];
3668 48 robfinch
//                && (iqentry_a1_v[g] 
3669
//        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3670
//        || (iqentry_a1_s[g] == alu1_sourceid && alu1_dataready));
3671
 
3672
end
3673
end
3674
endgenerate
3675
 
3676
// The (old) simulator didn't handle the asynchronous race loop properly in the 
3677
// original code. It would issue two instructions to the same islot. So the
3678
// issue logic has been re-written to eliminate the asynchronous loop.
3679
// Can't issue to the ALU if it's busy doing a long running operation like a 
3680
// divide.
3681
// ToDo: fix the memory synchronization, see fp_issue below
3682
 
3683
wire [`QBITS] heads [QENTRIES-1:0];
3684
assign heads[0] = head0;
3685
assign heads[1] = head1;
3686
assign heads[2] = head2;
3687
assign heads[3] = head3;
3688
assign heads[4] = head4;
3689
assign heads[5] = head5;
3690
assign heads[6] = head6;
3691
assign heads[7] = head7;
3692 52 robfinch
assign heads[8] = head8;
3693
assign heads[9] = head9;
3694 48 robfinch
 
3695
always @*
3696
begin
3697 49 robfinch
        iqentry_id1issue = {QENTRIES{1'b0}};
3698 48 robfinch
        if (id1_available) begin
3699
                for (n = 0; n < QENTRIES; n = n + 1)
3700 49 robfinch
                        if (could_issueid[heads[n]] && iqentry_id1issue=={QENTRIES{1'b0}})
3701 48 robfinch
                          iqentry_id1issue[heads[n]] = `TRUE;
3702
        end
3703 49 robfinch
end
3704
generate begin : gIDUIssue
3705
        if (`NUM_IDU > 1) begin
3706
                always @*
3707
                begin
3708
                        iqentry_id2issue = {QENTRIES{1'b0}};
3709
                        if (id2_available) begin
3710
                                for (n = 0; n < QENTRIES; n = n + 1)
3711
                                        if (could_issueid[heads[n]] && !iqentry_id1issue[heads[n]] && iqentry_id2issue=={QENTRIES{1'b0}})
3712
                                          iqentry_id2issue[heads[n]] = `TRUE;
3713
                        end
3714
                end
3715 48 robfinch
        end
3716 49 robfinch
        if (`NUM_IDU > 2) begin
3717
                always @*
3718
                begin
3719
                        iqentry_id3issue = {QENTRIES{1'b0}};
3720
                        if (id3_available) begin
3721
                                for (n = 0; n < QENTRIES; n = n + 1)
3722
                                        if (could_issueid[heads[n]]
3723
                                        && !iqentry_id1issue[heads[n]]
3724
                                        && !iqentry_id2issue[heads[n]]
3725
                                        && iqentry_id3issue=={QENTRIES{1'b0}})
3726
                                          iqentry_id3issue[heads[n]] = `TRUE;
3727
                        end
3728
                end
3729
        end
3730 48 robfinch
end
3731 49 robfinch
endgenerate
3732 48 robfinch
 
3733
always @*
3734
begin
3735 49 robfinch
        iqentry_alu0_issue = {QENTRIES{1'b0}};
3736
        iqentry_alu1_issue = {QENTRIES{1'b0}};
3737 48 robfinch
 
3738
        if (alu0_available & alu0_idle) begin
3739
                if (could_issue[head0] && iqentry_alu[head0]) begin
3740
                  iqentry_alu0_issue[head0] = `TRUE;
3741
                end
3742
                else if (could_issue[head1] && iqentry_alu[head1])
3743
                begin
3744
                  iqentry_alu0_issue[head1] = `TRUE;
3745
                end
3746
                else if (could_issue[head2] && iqentry_alu[head2]
3747
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3748
                )
3749
                begin
3750
                        iqentry_alu0_issue[head2] = `TRUE;
3751
                end
3752
                else if (could_issue[head3] && iqentry_alu[head3]
3753
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3754
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3755
                                ((!iqentry_v[head0])
3756
                        &&   (!iqentry_v[head1]))
3757
                        )
3758
                ) begin
3759
                        iqentry_alu0_issue[head3] = `TRUE;
3760
                end
3761
                else if (could_issue[head4] && iqentry_alu[head4]
3762
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3763
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3764
                                ((!iqentry_v[head0])
3765
                        &&   (!iqentry_v[head1]))
3766
                        )
3767
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3768
                                ((!iqentry_v[head0])
3769
                        &&   (!iqentry_v[head1])
3770
                        &&   (!iqentry_v[head2]))
3771
                        )
3772
                ) begin
3773
                        iqentry_alu0_issue[head4] = `TRUE;
3774
                end
3775
                else if (could_issue[head5] && iqentry_alu[head5]
3776
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3777
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3778
                                ((!iqentry_v[head0])
3779
                        &&   (!iqentry_v[head1]))
3780
                        )
3781
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3782
                                ((!iqentry_v[head0])
3783
                        &&   (!iqentry_v[head1])
3784
                        &&   (!iqentry_v[head2]))
3785
                        )
3786
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3787
                                ((!iqentry_v[head0])
3788
                        &&   (!iqentry_v[head1])
3789
                        &&   (!iqentry_v[head2])
3790
                        &&   (!iqentry_v[head3]))
3791
                        )
3792
                ) begin
3793
                        iqentry_alu0_issue[head5] = `TRUE;
3794
                end
3795
`ifdef FULL_ISSUE_LOGIC
3796
                else if (could_issue[head6] && iqentry_alu[head6]
3797
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3798
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3799
                                ((!iqentry_v[head0])
3800
                        &&   (!iqentry_v[head1]))
3801
                        )
3802
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3803
                                ((!iqentry_v[head0])
3804
                        &&   (!iqentry_v[head1])
3805
                        &&   (!iqentry_v[head2]))
3806
                        )
3807
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3808
                                ((!iqentry_v[head0])
3809
                        &&   (!iqentry_v[head1])
3810
                        &&   (!iqentry_v[head2])
3811
                        &&   (!iqentry_v[head3]))
3812
                        )
3813
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3814
                                ((!iqentry_v[head0])
3815
                        &&   (!iqentry_v[head1])
3816
                        &&   (!iqentry_v[head2])
3817
                        &&   (!iqentry_v[head3])
3818
                        &&   (!iqentry_v[head4]))
3819
                        )
3820
                ) begin
3821
                        iqentry_alu0_issue[head6] = `TRUE;
3822
                end
3823
                else if (could_issue[head7] && iqentry_alu[head7]
3824
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3825
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3826
                                ((!iqentry_v[head0])
3827
                        &&   (!iqentry_v[head1]))
3828
                        )
3829
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3830
                                ((!iqentry_v[head0])
3831
                        &&   (!iqentry_v[head1])
3832
                        &&   (!iqentry_v[head2]))
3833
                        )
3834
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3835
                                ((!iqentry_v[head0])
3836
                        &&   (!iqentry_v[head1])
3837
                        &&   (!iqentry_v[head2])
3838
                        &&   (!iqentry_v[head3]))
3839
                        )
3840
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3841
                                ((!iqentry_v[head0])
3842
                        &&   (!iqentry_v[head1])
3843
                        &&   (!iqentry_v[head2])
3844
                        &&   (!iqentry_v[head3])
3845
                        &&   (!iqentry_v[head4]))
3846
                        )
3847
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
3848
                                ((!iqentry_v[head0])
3849
                        &&   (!iqentry_v[head1])
3850
                        &&   (!iqentry_v[head2])
3851
                        &&   (!iqentry_v[head3])
3852
                        &&   (!iqentry_v[head4])
3853
                        &&   (!iqentry_v[head5]))
3854
                        )
3855
                ) begin
3856
                        iqentry_alu0_issue[head7] = `TRUE;
3857
                end
3858
`endif
3859
        end
3860
 
3861 49 robfinch
        if (alu1_available && alu1_idle && `NUM_ALU > 1) begin
3862 48 robfinch
                if ((could_issue & ~iqentry_alu0_issue & ~iqentry_alu0) != 8'h00) begin
3863
                if (could_issue[head0] && iqentry_alu[head0]
3864
                && !iqentry_alu0[head0] // alu0only
3865
                && !iqentry_alu0_issue[head0]) begin
3866
                  iqentry_alu1_issue[head0] = `TRUE;
3867
                end
3868
                else if (could_issue[head1] && !iqentry_alu0_issue[head1] && iqentry_alu[head1]
3869
                && !iqentry_alu0[head1])
3870
                begin
3871
                  iqentry_alu1_issue[head1] = `TRUE;
3872
                end
3873
                else if (could_issue[head2] && !iqentry_alu0_issue[head2] && iqentry_alu[head2]
3874
                && !iqentry_alu0[head2]
3875
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3876
                )
3877
                begin
3878
                        iqentry_alu1_issue[head2] = `TRUE;
3879
                end
3880
                else if (could_issue[head3] && !iqentry_alu0_issue[head3] && iqentry_alu[head3]
3881
                && !iqentry_alu0[head3]
3882
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3883
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3884
                                ((!iqentry_v[head0])
3885
                        &&   (!iqentry_v[head1]))
3886
                        )
3887
                ) begin
3888
                        iqentry_alu1_issue[head3] = `TRUE;
3889
                end
3890
                else if (could_issue[head4] && !iqentry_alu0_issue[head4] && iqentry_alu[head4]
3891
                && !iqentry_alu0[head4]
3892
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3893
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3894
                                ((!iqentry_v[head0])
3895
                        &&   (!iqentry_v[head1]))
3896
                        )
3897
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3898
                                ((!iqentry_v[head0])
3899
                        &&   (!iqentry_v[head1])
3900
                        &&   (!iqentry_v[head2]))
3901
                        )
3902
                ) begin
3903
                        iqentry_alu1_issue[head4] = `TRUE;
3904
                end
3905
                else if (could_issue[head5] && !iqentry_alu0_issue[head5] && iqentry_alu[head5]
3906
                && !iqentry_alu0[head5]
3907
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3908
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3909
                                ((!iqentry_v[head0])
3910
                        &&   (!iqentry_v[head1]))
3911
                        )
3912
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3913
                                ((!iqentry_v[head0])
3914
                        &&   (!iqentry_v[head1])
3915
                        &&   (!iqentry_v[head2]))
3916
                        )
3917
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3918
                                ((!iqentry_v[head0])
3919
                        &&   (!iqentry_v[head1])
3920
                        &&   (!iqentry_v[head2])
3921
                        &&   (!iqentry_v[head3]))
3922
                        )
3923
                ) begin
3924
                        iqentry_alu1_issue[head5] = `TRUE;
3925
                end
3926
`ifdef FULL_ISSUE_LOGIC
3927
                else if (could_issue[head6] && !iqentry_alu0_issue[head6] && iqentry_alu[head6]
3928
                && !iqentry_alu0[head6]
3929
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3930
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3931
                                ((!iqentry_v[head0])
3932
                        &&   (!iqentry_v[head1]))
3933
                        )
3934
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3935
                                ((!iqentry_v[head0])
3936
                        &&   (!iqentry_v[head1])
3937
                        &&   (!iqentry_v[head2]))
3938
                        )
3939
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3940
                                ((!iqentry_v[head0])
3941
                        &&   (!iqentry_v[head1])
3942
                        &&   (!iqentry_v[head2])
3943
                        &&   (!iqentry_v[head3]))
3944
                        )
3945
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3946
                                ((!iqentry_v[head0])
3947
                        &&   (!iqentry_v[head1])
3948
                        &&   (!iqentry_v[head2])
3949
                        &&   (!iqentry_v[head3])
3950
                        &&   (!iqentry_v[head4]))
3951
                        )
3952
                ) begin
3953
                        iqentry_alu1_issue[head6] = `TRUE;
3954
                end
3955
                else if (could_issue[head7] && !iqentry_alu0_issue[head7] && iqentry_alu[head7]
3956
                && !iqentry_alu0[head7]
3957
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
3958
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
3959
                                ((!iqentry_v[head0])
3960
                        &&   (!iqentry_v[head1]))
3961
                        )
3962
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
3963
                                ((!iqentry_v[head0])
3964
                        &&   (!iqentry_v[head1])
3965
                        &&   (!iqentry_v[head2]))
3966
                        )
3967
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
3968
                                ((!iqentry_v[head0])
3969
                        &&   (!iqentry_v[head1])
3970
                        &&   (!iqentry_v[head2])
3971
                        &&   (!iqentry_v[head3]))
3972
                        )
3973
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
3974
                                ((!iqentry_v[head0])
3975
                        &&   (!iqentry_v[head1])
3976
                        &&   (!iqentry_v[head2])
3977
                        &&   (!iqentry_v[head3])
3978
                        &&   (!iqentry_v[head4]))
3979
                        )
3980
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
3981
                                ((!iqentry_v[head0])
3982
                        &&   (!iqentry_v[head1])
3983
                        &&   (!iqentry_v[head2])
3984
                        &&   (!iqentry_v[head3])
3985
                        &&   (!iqentry_v[head4])
3986
                        &&   (!iqentry_v[head5]))
3987
                        )
3988
                ) begin
3989
                        iqentry_alu1_issue[head7] = `TRUE;
3990
                end
3991
`endif
3992
        end
3993
//      aluissue(alu0_idle,8'h00,2'b00);
3994
//      aluissue(alu1_idle,iqentry_alu0,2'b01);
3995
        end
3996
end
3997
 
3998
always @*
3999
begin
4000 49 robfinch
        iqentry_fpu1_issue = {QENTRIES{1'b0}};
4001
//      fpu1issue(fpu1_idle,2'b00);
4002
        if (fpu1_idle && `NUM_FPU > 0) begin
4003 48 robfinch
    if (could_issue[head0] && iqentry_fpu[head0]) begin
4004 49 robfinch
      iqentry_fpu1_issue[head0] = `TRUE;
4005 48 robfinch
    end
4006
    else if (could_issue[head1] && iqentry_fpu[head1])
4007
    begin
4008 49 robfinch
      iqentry_fpu1_issue[head1] = `TRUE;
4009 48 robfinch
    end
4010
    else if (could_issue[head2] && iqentry_fpu[head2]
4011
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4012
    ) begin
4013 49 robfinch
      iqentry_fpu1_issue[head2] = `TRUE;
4014 48 robfinch
    end
4015
    else if (could_issue[head3] && iqentry_fpu[head3]
4016
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4017
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4018
                ((!iqentry_v[head0])
4019
        &&   (!iqentry_v[head1]))
4020
        )
4021
    ) begin
4022 49 robfinch
      iqentry_fpu1_issue[head3] = `TRUE;
4023 48 robfinch
    end
4024
    else if (could_issue[head4] && iqentry_fpu[head4]
4025
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4026
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4027
                ((!iqentry_v[head0])
4028
        &&   (!iqentry_v[head1]))
4029
        )
4030
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4031
                ((!iqentry_v[head0])
4032
        &&   (!iqentry_v[head1])
4033
        &&   (!iqentry_v[head2]))
4034
        )
4035
    ) begin
4036 49 robfinch
      iqentry_fpu1_issue[head4] = `TRUE;
4037 48 robfinch
    end
4038
    else if (could_issue[head5] && iqentry_fpu[head5]
4039
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4040
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4041
                ((!iqentry_v[head0])
4042
        &&   (!iqentry_v[head1]))
4043
        )
4044
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4045
                ((!iqentry_v[head0])
4046
        &&   (!iqentry_v[head1])
4047
        &&   (!iqentry_v[head2]))
4048
        )
4049
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4050
                ((!iqentry_v[head0])
4051
        &&   (!iqentry_v[head1])
4052
        &&   (!iqentry_v[head2])
4053
        &&   (!iqentry_v[head3]))
4054
        )
4055
        ) begin
4056 49 robfinch
              iqentry_fpu1_issue[head5] = `TRUE;
4057 48 robfinch
    end
4058
`ifdef FULL_ISSUE_LOGIC
4059
    else if (could_issue[head6] && iqentry_fpu[head6]
4060
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4061
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4062
                ((!iqentry_v[head0])
4063
        &&   (!iqentry_v[head1]))
4064
        )
4065
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4066
                ((!iqentry_v[head0])
4067
        &&   (!iqentry_v[head1])
4068
        &&   (!iqentry_v[head2]))
4069
        )
4070
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4071
                ((!iqentry_v[head0])
4072
        &&   (!iqentry_v[head1])
4073
        &&   (!iqentry_v[head2])
4074
        &&   (!iqentry_v[head3]))
4075
        )
4076
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4077
                ((!iqentry_v[head0])
4078
        &&   (!iqentry_v[head1])
4079
        &&   (!iqentry_v[head2])
4080
        &&   (!iqentry_v[head3])
4081
        &&   (!iqentry_v[head4]))
4082
        )
4083
    ) begin
4084 49 robfinch
        iqentry_fpu1_issue[head6] = `TRUE;
4085 48 robfinch
    end
4086
    else if (could_issue[head7] && iqentry_fpu[head7]
4087
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4088
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4089
                ((!iqentry_v[head0])
4090
        &&   (!iqentry_v[head1]))
4091
        )
4092
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4093
                ((!iqentry_v[head0])
4094
        &&   (!iqentry_v[head1])
4095
        &&   (!iqentry_v[head2]))
4096
        )
4097
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4098
                ((!iqentry_v[head0])
4099
        &&   (!iqentry_v[head1])
4100
        &&   (!iqentry_v[head2])
4101
        &&   (!iqentry_v[head3]))
4102
        )
4103
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4104
                ((!iqentry_v[head0])
4105
        &&   (!iqentry_v[head1])
4106
        &&   (!iqentry_v[head2])
4107
        &&   (!iqentry_v[head3])
4108
        &&   (!iqentry_v[head4]))
4109
        )
4110
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
4111
                ((!iqentry_v[head0])
4112
        &&   (!iqentry_v[head1])
4113
        &&   (!iqentry_v[head2])
4114
        &&   (!iqentry_v[head3])
4115
        &&   (!iqentry_v[head4])
4116
        &&   (!iqentry_v[head5]))
4117
        )
4118
        )
4119
    begin
4120 49 robfinch
                iqentry_fpu1_issue[head7] = `TRUE;
4121 48 robfinch
        end
4122
`endif
4123
        end
4124
end
4125
 
4126 49 robfinch
always @*
4127
begin
4128
        iqentry_fpu2_issue = {QENTRIES{1'b0}};
4129
//      fpu2issue(fpu2_idle,2'b00);
4130
        if (fpu2_idle && `NUM_FPU > 1) begin
4131
    if (could_issue[head0] && iqentry_fpu[head0] && !iqentry_fpu1_issue[head0]) begin
4132
      iqentry_fpu2_issue[head0] = `TRUE;
4133
    end
4134
    else if (could_issue[head1] && iqentry_fpu[head1] && !iqentry_fpu1_issue[head1])
4135
    begin
4136
      iqentry_fpu2_issue[head1] = `TRUE;
4137
    end
4138
    else if (could_issue[head2] && iqentry_fpu[head2] && !iqentry_fpu1_issue[head2]
4139
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4140
    ) begin
4141
      iqentry_fpu2_issue[head2] = `TRUE;
4142
    end
4143
    else if (could_issue[head3] && iqentry_fpu[head3] && !iqentry_fpu1_issue[head3]
4144
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4145
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4146
                ((!iqentry_v[head0])
4147
        &&   (!iqentry_v[head1]))
4148
        )
4149
    ) begin
4150
      iqentry_fpu2_issue[head3] = `TRUE;
4151
    end
4152
    else if (could_issue[head4] && iqentry_fpu[head4] && !iqentry_fpu1_issue[head4]
4153
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4154
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4155
                ((!iqentry_v[head0])
4156
        &&   (!iqentry_v[head1]))
4157
        )
4158
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4159
                ((!iqentry_v[head0])
4160
        &&   (!iqentry_v[head1])
4161
        &&   (!iqentry_v[head2]))
4162
        )
4163
    ) begin
4164
      iqentry_fpu2_issue[head4] = `TRUE;
4165
    end
4166
    else if (could_issue[head5] && iqentry_fpu[head5] && !iqentry_fpu1_issue[head5]
4167
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4168
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4169
                ((!iqentry_v[head0])
4170
        &&   (!iqentry_v[head1]))
4171
        )
4172
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4173
                ((!iqentry_v[head0])
4174
        &&   (!iqentry_v[head1])
4175
        &&   (!iqentry_v[head2]))
4176
        )
4177
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4178
                ((!iqentry_v[head0])
4179
        &&   (!iqentry_v[head1])
4180
        &&   (!iqentry_v[head2])
4181
        &&   (!iqentry_v[head3]))
4182
        )
4183
        ) begin
4184
              iqentry_fpu2_issue[head5] = `TRUE;
4185
    end
4186
`ifdef FULL_ISSUE_LOGIC
4187
    else if (could_issue[head6] && iqentry_fpu[head6] && !iqentry_fpu1_issue[head6]
4188
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4189
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4190
                ((!iqentry_v[head0])
4191
        &&   (!iqentry_v[head1]))
4192
        )
4193
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4194
                ((!iqentry_v[head0])
4195
        &&   (!iqentry_v[head1])
4196
        &&   (!iqentry_v[head2]))
4197
        )
4198
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4199
                ((!iqentry_v[head0])
4200
        &&   (!iqentry_v[head1])
4201
        &&   (!iqentry_v[head2])
4202
        &&   (!iqentry_v[head3]))
4203
        )
4204
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4205
                ((!iqentry_v[head0])
4206
        &&   (!iqentry_v[head1])
4207
        &&   (!iqentry_v[head2])
4208
        &&   (!iqentry_v[head3])
4209
        &&   (!iqentry_v[head4]))
4210
        )
4211
    ) begin
4212
        iqentry_fpu2_issue[head6] = `TRUE;
4213
    end
4214
    else if (could_issue[head7] && iqentry_fpu[head7] && !iqentry_fpu1_issue[head7]
4215
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4216
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4217
                ((!iqentry_v[head0])
4218
        &&   (!iqentry_v[head1]))
4219
        )
4220
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4221
                ((!iqentry_v[head0])
4222
        &&   (!iqentry_v[head1])
4223
        &&   (!iqentry_v[head2]))
4224
        )
4225
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4226
                ((!iqentry_v[head0])
4227
        &&   (!iqentry_v[head1])
4228
        &&   (!iqentry_v[head2])
4229
        &&   (!iqentry_v[head3]))
4230
        )
4231
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4232
                ((!iqentry_v[head0])
4233
        &&   (!iqentry_v[head1])
4234
        &&   (!iqentry_v[head2])
4235
        &&   (!iqentry_v[head3])
4236
        &&   (!iqentry_v[head4]))
4237
        )
4238
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
4239
                ((!iqentry_v[head0])
4240
        &&   (!iqentry_v[head1])
4241
        &&   (!iqentry_v[head2])
4242
        &&   (!iqentry_v[head3])
4243
        &&   (!iqentry_v[head4])
4244
        &&   (!iqentry_v[head5]))
4245
        )
4246
        )
4247
    begin
4248
                iqentry_fpu2_issue[head7] = `TRUE;
4249
        end
4250
`endif
4251
        end
4252
end
4253 48 robfinch
 
4254
wire [QENTRIES-1:0] nextqd;
4255
// Next queue id
4256
 
4257
reg [`QBITS] nid0;
4258
always @*
4259
if (iqentry_thrd[1]==iqentry_thrd[0])
4260 52 robfinch
        nid0 = 4'd1;
4261 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[0])
4262 52 robfinch
        nid0 = 4'd2;
4263 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[0])
4264 52 robfinch
        nid0 = 4'd3;
4265 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[0])
4266 52 robfinch
        nid0 = 4'd4;
4267 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[0])
4268 52 robfinch
        nid0 = 4'd5;
4269 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[0])
4270 52 robfinch
        nid0 = 4'd6;
4271 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[0])
4272 52 robfinch
        nid0 = 4'd7;
4273
else if (iqentry_thrd[8]==iqentry_thrd[0])
4274
        nid0 = 4'd8;
4275
else if (iqentry_thrd[9]==iqentry_thrd[0])
4276
        nid0 = 4'd9;
4277 48 robfinch
else
4278
        nid0 = 3'd0;
4279
 
4280
reg [`QBITS] nid1;
4281
always @*
4282
if (iqentry_thrd[2]==iqentry_thrd[1])
4283 52 robfinch
        nid1 = 4'd2;
4284 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[1])
4285 52 robfinch
        nid1 = 4'd3;
4286 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[1])
4287 52 robfinch
        nid1 = 4'd4;
4288 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[1])
4289 52 robfinch
        nid1 = 4'd5;
4290 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[1])
4291 52 robfinch
        nid1 = 4'd6;
4292 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[1])
4293 52 robfinch
        nid1 = 4'd7;
4294
else if (iqentry_thrd[8]==iqentry_thrd[1])
4295
        nid1 = 4'd8;
4296
else if (iqentry_thrd[9]==iqentry_thrd[1])
4297
        nid1 = 4'd9;
4298 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[1])
4299 52 robfinch
        nid1 = 4'd0;
4300 48 robfinch
else
4301 52 robfinch
        nid1 = 4'd1;
4302 48 robfinch
 
4303
reg [`QBITS] nid2;
4304
always @*
4305
if (iqentry_thrd[3]==iqentry_thrd[2])
4306 52 robfinch
        nid2 = 4'd3;
4307 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[2])
4308 52 robfinch
        nid2 = 4'd4;
4309 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[2])
4310 52 robfinch
        nid2 = 4'd5;
4311 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[2])
4312 52 robfinch
        nid2 = 4'd6;
4313 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[2])
4314 52 robfinch
        nid2 = 4'd7;
4315
else if (iqentry_thrd[8]==iqentry_thrd[2])
4316
        nid2 = 4'd8;
4317
else if (iqentry_thrd[9]==iqentry_thrd[2])
4318
        nid2 = 4'd9;
4319 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[2])
4320 52 robfinch
        nid2 = 4'd0;
4321 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[2])
4322 52 robfinch
        nid2 = 4'd1;
4323 48 robfinch
else
4324 52 robfinch
        nid2 = 4'd2;
4325 48 robfinch
 
4326
reg [`QBITS] nid3;
4327
always @*
4328
if (iqentry_thrd[4]==iqentry_thrd[3])
4329 52 robfinch
        nid3 = 4'd4;
4330 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[3])
4331 52 robfinch
        nid3 = 4'd5;
4332 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[3])
4333 52 robfinch
        nid3 = 4'd6;
4334 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[3])
4335 52 robfinch
        nid3 = 4'd7;
4336
else if (iqentry_thrd[8]==iqentry_thrd[3])
4337
        nid3 = 4'd8;
4338
else if (iqentry_thrd[9]==iqentry_thrd[3])
4339
        nid3 = 4'd9;
4340 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[3])
4341 52 robfinch
        nid3 = 4'd0;
4342 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[3])
4343 52 robfinch
        nid3 = 4'd1;
4344 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[3])
4345 52 robfinch
        nid3 = 4'd2;
4346 48 robfinch
else
4347 52 robfinch
        nid3 = 4'd3;
4348 48 robfinch
 
4349
reg [`QBITS] nid4;
4350
always @*
4351
if (iqentry_thrd[5]==iqentry_thrd[4])
4352 52 robfinch
        nid4 = 4'd5;
4353 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[4])
4354 52 robfinch
        nid4 = 4'd6;
4355 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[4])
4356 52 robfinch
        nid4 = 4'd7;
4357
else if (iqentry_thrd[8]==iqentry_thrd[4])
4358
        nid4 = 4'd8;
4359
else if (iqentry_thrd[9]==iqentry_thrd[4])
4360
        nid4 = 4'd9;
4361 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[4])
4362 52 robfinch
        nid4 = 4'd0;
4363 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[4])
4364 52 robfinch
        nid4 = 4'd1;
4365 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[4])
4366 52 robfinch
        nid4 = 4'd2;
4367 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[4])
4368 52 robfinch
        nid4 = 4'd3;
4369 48 robfinch
else
4370 52 robfinch
        nid4 = 4'd4;
4371 48 robfinch
 
4372
reg [`QBITS] nid5;
4373
always @*
4374
if (iqentry_thrd[6]==iqentry_thrd[5])
4375 52 robfinch
        nid5 = 4'd6;
4376 48 robfinch
else if (iqentry_thrd[7]==iqentry_thrd[5])
4377 52 robfinch
        nid5 = 4'd7;
4378
else if (iqentry_thrd[8]==iqentry_thrd[5])
4379
        nid5 = 4'd8;
4380
else if (iqentry_thrd[9]==iqentry_thrd[5])
4381
        nid5 = 4'd9;
4382 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[5])
4383 52 robfinch
        nid5 = 4'd0;
4384 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[5])
4385 52 robfinch
        nid5 = 4'd1;
4386 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[5])
4387 52 robfinch
        nid5 = 4'd2;
4388 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[5])
4389 52 robfinch
        nid5 = 4'd3;
4390 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[5])
4391 52 robfinch
        nid5 = 4'd4;
4392 48 robfinch
else
4393 52 robfinch
        nid5 = 4'd5;
4394 48 robfinch
 
4395
reg [`QBITS] nid6;
4396
always @*
4397
if (iqentry_thrd[7]==iqentry_thrd[6])
4398 52 robfinch
        nid6 = 4'd7;
4399
else if (iqentry_thrd[8]==iqentry_thrd[6])
4400
        nid6 = 4'd8;
4401
else if (iqentry_thrd[9]==iqentry_thrd[6])
4402
        nid6 = 4'd9;
4403 48 robfinch
else if (iqentry_thrd[0]==iqentry_thrd[6])
4404 52 robfinch
        nid6 = 4'd0;
4405 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[6])
4406 52 robfinch
        nid6 = 4'd1;
4407 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[6])
4408 52 robfinch
        nid6 = 4'd2;
4409 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[6])
4410 52 robfinch
        nid6 = 4'd3;
4411 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[6])
4412 52 robfinch
        nid6 = 4'd4;
4413 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[6])
4414 52 robfinch
        nid6 = 4'd5;
4415 48 robfinch
else
4416 52 robfinch
        nid6 = 4'd6;
4417 48 robfinch
 
4418
reg [`QBITS] nid7;
4419
always @*
4420 52 robfinch
if (iqentry_thrd[8]==iqentry_thrd[7])
4421
        nid7 = 4'd8;
4422
else if (iqentry_thrd[9]==iqentry_thrd[7])
4423
        nid7 = 4'd9;
4424
else if (iqentry_thrd[0]==iqentry_thrd[7])
4425
        nid7 = 4'd0;
4426 48 robfinch
else if (iqentry_thrd[1]==iqentry_thrd[7])
4427 52 robfinch
        nid7 = 4'd1;
4428 48 robfinch
else if (iqentry_thrd[2]==iqentry_thrd[7])
4429 52 robfinch
        nid7 = 4'd2;
4430 48 robfinch
else if (iqentry_thrd[3]==iqentry_thrd[7])
4431 52 robfinch
        nid7 = 4'd3;
4432 48 robfinch
else if (iqentry_thrd[4]==iqentry_thrd[7])
4433 52 robfinch
        nid7 = 4'd4;
4434 48 robfinch
else if (iqentry_thrd[5]==iqentry_thrd[7])
4435 52 robfinch
        nid7 = 4'd5;
4436 48 robfinch
else if (iqentry_thrd[6]==iqentry_thrd[7])
4437 52 robfinch
        nid7 = 4'd6;
4438 48 robfinch
else
4439 52 robfinch
        nid7 = 4'd7;
4440 48 robfinch
 
4441 52 robfinch
reg [`QBITS] nid8;
4442
always @*
4443
if (iqentry_thrd[9]==iqentry_thrd[8])
4444
        nid8 = 4'd9;
4445
else if (iqentry_thrd[0]==iqentry_thrd[8])
4446
        nid8 = 4'd0;
4447
else if (iqentry_thrd[1]==iqentry_thrd[8])
4448
        nid8 = 4'd1;
4449
else if (iqentry_thrd[2]==iqentry_thrd[8])
4450
        nid8 = 4'd2;
4451
else if (iqentry_thrd[3]==iqentry_thrd[8])
4452
        nid8 = 4'd3;
4453
else if (iqentry_thrd[4]==iqentry_thrd[8])
4454
        nid8 = 4'd4;
4455
else if (iqentry_thrd[5]==iqentry_thrd[8])
4456
        nid8 = 4'd5;
4457
else if (iqentry_thrd[6]==iqentry_thrd[8])
4458
        nid8 = 4'd6;
4459
else if (iqentry_thrd[7]==iqentry_thrd[8])
4460
        nid8 = 4'd7;
4461
else
4462
        nid8 = 4'd8;
4463
 
4464
reg [`QBITS] nid9;
4465
always @*
4466
if (iqentry_thrd[0]==iqentry_thrd[9])
4467
        nid9 = 4'd0;
4468
else if (iqentry_thrd[1]==iqentry_thrd[9])
4469
        nid9 = 4'd1;
4470
else if (iqentry_thrd[2]==iqentry_thrd[9])
4471
        nid9 = 4'd2;
4472
else if (iqentry_thrd[3]==iqentry_thrd[9])
4473
        nid9 = 4'd3;
4474
else if (iqentry_thrd[4]==iqentry_thrd[9])
4475
        nid9 = 4'd4;
4476
else if (iqentry_thrd[5]==iqentry_thrd[9])
4477
        nid9 = 4'd5;
4478
else if (iqentry_thrd[6]==iqentry_thrd[9])
4479
        nid9 = 4'd6;
4480
else if (iqentry_thrd[7]==iqentry_thrd[9])
4481
        nid9 = 4'd7;
4482
else if (iqentry_thrd[8]==iqentry_thrd[9])
4483
        nid9 = 4'd8;
4484
else
4485
        nid9 = 4'd9;
4486
 
4487 48 robfinch
// Search the queue for the next entry on the same thread.
4488
reg [`QBITS] nid;
4489
always @*
4490
if (iqentry_thrd[idp1(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4491
        nid = idp1(fcu_id);
4492
else if (iqentry_thrd[idp2(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4493
        nid = idp2(fcu_id);
4494
else if (iqentry_thrd[idp3(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4495
        nid = idp3(fcu_id);
4496
else if (iqentry_thrd[idp4(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4497
        nid = idp4(fcu_id);
4498
else if (iqentry_thrd[idp5(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4499
        nid = idp5(fcu_id);
4500
else if (iqentry_thrd[idp6(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4501
        nid = idp6(fcu_id);
4502
else if (iqentry_thrd[idp7(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4503
        nid = idp7(fcu_id);
4504 52 robfinch
else if (iqentry_thrd[idp8(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4505
        nid = idp8(fcu_id);
4506
else if (iqentry_thrd[idp9(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4507
        nid = idp9(fcu_id);
4508 48 robfinch
else
4509
        nid = fcu_id;
4510
 
4511
assign  nextqd[0] = iqentry_sn[nid0] > iqentry_sn[0] || iqentry_v[0];
4512
assign  nextqd[1] = iqentry_sn[nid1] > iqentry_sn[1] || iqentry_v[1];
4513
assign  nextqd[2] = iqentry_sn[nid2] > iqentry_sn[2] || iqentry_v[2];
4514
assign  nextqd[3] = iqentry_sn[nid3] > iqentry_sn[3] || iqentry_v[3];
4515
assign  nextqd[4] = iqentry_sn[nid4] > iqentry_sn[4] || iqentry_v[4];
4516
assign  nextqd[5] = iqentry_sn[nid5] > iqentry_sn[5] || iqentry_v[5];
4517
assign  nextqd[6] = iqentry_sn[nid6] > iqentry_sn[6] || iqentry_v[6];
4518
assign  nextqd[7] = iqentry_sn[nid7] > iqentry_sn[7] || iqentry_v[7];
4519 52 robfinch
assign  nextqd[8] = iqentry_sn[nid8] > iqentry_sn[8] || iqentry_v[8];
4520
assign  nextqd[9] = iqentry_sn[nid9] > iqentry_sn[9] || iqentry_v[9];
4521 48 robfinch
 
4522
//assign nextqd = 8'hFF;
4523
 
4524
// Don't issue to the fcu until the following instruction is enqueued.
4525
// However, if the queue is full then issue anyway. A branch miss will likely occur.
4526
always @*//(could_issue or head0 or head1 or head2 or head3 or head4 or head5 or head6 or head7)
4527
begin
4528 49 robfinch
        iqentry_fcu_issue = {QENTRIES{1'b0}};
4529 48 robfinch
        if (fcu_done) begin
4530
    if (could_issue[head0] && iqentry_fc[head0] && nextqd[head0]) begin
4531
      iqentry_fcu_issue[head0] = `TRUE;
4532
    end
4533
    else if (could_issue[head1] && iqentry_fc[head1] && nextqd[head1])
4534
    begin
4535
      iqentry_fcu_issue[head1] = `TRUE;
4536
    end
4537
    else if (could_issue[head2] && iqentry_fc[head2] && nextqd[head2]
4538
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4539
    ) begin
4540
                iqentry_fcu_issue[head2] = `TRUE;
4541
    end
4542
    else if (could_issue[head3] && iqentry_fc[head3] && nextqd[head3]
4543
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4544
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4545
                ((!iqentry_v[head0])
4546
        &&   (!iqentry_v[head1]))
4547
        )
4548
    ) begin
4549
                iqentry_fcu_issue[head3] = `TRUE;
4550
    end
4551
    else if (could_issue[head4] && iqentry_fc[head4] && nextqd[head4]
4552
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4553
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4554
                ((!iqentry_v[head0])
4555
        &&   (!iqentry_v[head1]))
4556
        )
4557
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4558
                ((!iqentry_v[head0])
4559
        &&   (!iqentry_v[head1])
4560
        &&   (!iqentry_v[head2]))
4561
        )
4562
    ) begin
4563
                iqentry_fcu_issue[head4] = `TRUE;
4564
    end
4565
    else if (could_issue[head5] && iqentry_fc[head5] && nextqd[head5]
4566
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4567
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4568
                ((!iqentry_v[head0])
4569
        &&   (!iqentry_v[head1]))
4570
        )
4571
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4572
                ((!iqentry_v[head0])
4573
        &&   (!iqentry_v[head1])
4574
        &&   (!iqentry_v[head2]))
4575
        )
4576
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4577
                ((!iqentry_v[head0])
4578
        &&   (!iqentry_v[head1])
4579
        &&   (!iqentry_v[head2])
4580
        &&   (!iqentry_v[head3]))
4581
        )
4582
    ) begin
4583
                iqentry_fcu_issue[head5] = `TRUE;
4584
    end
4585
 
4586
`ifdef FULL_ISSUE_LOGIC
4587
    else if (could_issue[head6] && iqentry_fc[head6] && nextqd[head6]
4588
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4589
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4590
                ((!iqentry_v[head0])
4591
        &&   (!iqentry_v[head1]))
4592
        )
4593
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4594
                ((!iqentry_v[head0])
4595
        &&   (!iqentry_v[head1])
4596
        &&   (!iqentry_v[head2]))
4597
        )
4598
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4599
                ((!iqentry_v[head0])
4600
        &&   (!iqentry_v[head1])
4601
        &&   (!iqentry_v[head2])
4602
        &&   (!iqentry_v[head3]))
4603
        )
4604
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4605
                ((!iqentry_v[head0])
4606
        &&   (!iqentry_v[head1])
4607
        &&   (!iqentry_v[head2])
4608
        &&   (!iqentry_v[head3])
4609
        &&   (!iqentry_v[head4]))
4610
        )
4611
    ) begin
4612
                iqentry_fcu_issue[head6] = `TRUE;
4613
    end
4614
 
4615
    else if (could_issue[head7] && iqentry_fc[head7]
4616
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4617
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4618
                ((!iqentry_v[head0])
4619
        &&   (!iqentry_v[head1]))
4620
        )
4621
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4622
                ((!iqentry_v[head0])
4623
        &&   (!iqentry_v[head1])
4624
        &&   (!iqentry_v[head2]))
4625
        )
4626
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4627
                ((!iqentry_v[head0])
4628
        &&   (!iqentry_v[head1])
4629
        &&   (!iqentry_v[head2])
4630
        &&   (!iqentry_v[head3]))
4631
        )
4632
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4633
                ((!iqentry_v[head0])
4634
        &&   (!iqentry_v[head1])
4635
        &&   (!iqentry_v[head2])
4636
        &&   (!iqentry_v[head3])
4637
        &&   (!iqentry_v[head4]))
4638
        )
4639
    && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4640
                ((!iqentry_v[head0])
4641
        &&   (!iqentry_v[head1])
4642
        &&   (!iqentry_v[head2])
4643
        &&   (!iqentry_v[head3])
4644
        &&   (!iqentry_v[head4])
4645
        &&   (!iqentry_v[head5]))
4646
        )
4647
    ) begin
4648
                iqentry_fcu_issue[head7] = `TRUE;
4649
        end
4650
`endif
4651
        end
4652
end
4653
 
4654
//
4655
// determine if the instructions ready to issue can, in fact, issue.
4656
// "ready" means that the instruction has valid operands but has not gone yet
4657
reg [1:0] issue_count, missue_count;
4658
always @*
4659
begin
4660
        issue_count = 0;
4661
         memissue[ head0 ] =    iqentry_memready[ head0 ];              // first in line ... go as soon as ready
4662
         if (memissue[head0])
4663
                issue_count = issue_count + 1;
4664
 
4665
         memissue[ head1 ] =    ~iqentry_stomp[head1] && iqentry_memready[ head1 ]              // addr and data are valid
4666 49 robfinch
                                        && issue_count < `NUM_MEM
4667 48 robfinch
                                        // ... and no preceding instruction is ready to go
4668
                                        //&& ~iqentry_memready[head0]
4669
                                        // ... and there is no address-overlap with any preceding instruction
4670 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4671
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head1][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4672 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4673
                                        && (iqentry_rl[head1] ? iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0] : 1'b1)
4674
                                        // ... if a preivous op has the aquire bit set
4675
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4676
                                        // ... and, if it is a SW, there is no chance of it being undone
4677
                                        && (iqentry_load[head1] ||
4678
                                           !(iqentry_fc[head0]||iqentry_canex[head0]));
4679
         if (memissue[head1])
4680
                issue_count = issue_count + 1;
4681
 
4682
         memissue[ head2 ] =    ~iqentry_stomp[head2] && iqentry_memready[ head2 ]              // addr and data are valid
4683
                                        // ... and no preceding instruction is ready to go
4684 49 robfinch
                                        && issue_count < `NUM_MEM
4685 48 robfinch
                                        //&& ~iqentry_memready[head0]
4686
                                        //&& ~iqentry_memready[head1] 
4687
                                        // ... and there is no address-overlap with any preceding instruction
4688 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4689
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head2][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4690
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4691
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head2][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4692 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4693
                                        && (iqentry_rl[head2] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4694
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4695
                                                                                         : 1'b1)
4696
                                        // ... if a preivous op has the aquire bit set
4697
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4698
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4699
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4700 49 robfinch
            && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4701
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4702 48 robfinch
                                        // ... and, if it is a SW, there is no chance of it being undone
4703
                                        && (iqentry_load[head2] ||
4704
                                              !(iqentry_fc[head0]||iqentry_canex[head0])
4705
                                           && !(iqentry_fc[head1]||iqentry_canex[head1]));
4706
         if (memissue[head2])
4707
                issue_count = issue_count + 1;
4708
 
4709
         memissue[ head3 ] =    ~iqentry_stomp[head3] && iqentry_memready[ head3 ]              // addr and data are valid
4710
                                        // ... and no preceding instruction is ready to go
4711 49 robfinch
                                        && issue_count < `NUM_MEM
4712 48 robfinch
                                        //&& ~iqentry_memready[head0]
4713
                                        //&& ~iqentry_memready[head1] 
4714
                                        //&& ~iqentry_memready[head2] 
4715
                                        // ... and there is no address-overlap with any preceding instruction
4716 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4717
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4718
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4719
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4720
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])  || iqentry_done[head2]
4721
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head3][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4722 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4723
                                        && (iqentry_rl[head3] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4724
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4725
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4726
                                                                                         : 1'b1)
4727
                                        // ... if a preivous op has the aquire bit set
4728
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4729
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4730
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4731
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4732 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4733
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4734 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4735
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4736
                                )
4737 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4738
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4739 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4740
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4741
                                )
4742
                    // ... and, if it is a SW, there is no chance of it being undone
4743
                                        && (iqentry_load[head3] ||
4744
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4745
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4746
                       && !(iqentry_fc[head2]||iqentry_canex[head2]));
4747
         if (memissue[head3])
4748
                issue_count = issue_count + 1;
4749
 
4750
         memissue[ head4 ] =    ~iqentry_stomp[head4] && iqentry_memready[ head4 ]              // addr and data are valid
4751
                                        // ... and no preceding instruction is ready to go
4752 49 robfinch
                                        && issue_count < `NUM_MEM
4753 48 robfinch
                                        //&& ~iqentry_memready[head0]
4754
                                        //&& ~iqentry_memready[head1] 
4755
                                        //&& ~iqentry_memready[head2] 
4756
                                        //&& ~iqentry_memready[head3] 
4757
                                        // ... and there is no address-overlap with any preceding instruction
4758 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])  || iqentry_done[head0]
4759
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4760
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])  || iqentry_done[head1]
4761
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4762
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])  || iqentry_done[head2]
4763
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4764
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])  || iqentry_done[head3]
4765
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head4][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
4766 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4767
                                        && (iqentry_rl[head4] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4768
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4769
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4770
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4771
                                                                                         : 1'b1)
4772
                                        // ... if a preivous op has the aquire bit set
4773
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4774
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4775
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4776
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4777
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4778 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4779
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4780 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4781
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4782
                                )
4783 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4784 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4785
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4786
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4787
                                )
4788
                                && (!(iqentry_v[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4789 49 robfinch
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4790 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4791
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4792
                                )
4793 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
4794 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4795
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4796
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4797
                                )
4798
                                        // ... and, if it is a SW, there is no chance of it being undone
4799
                                        && (iqentry_load[head4] ||
4800
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4801
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4802
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4803
                       && !(iqentry_fc[head3]||iqentry_canex[head3]));
4804
         if (memissue[head4])
4805
                issue_count = issue_count + 1;
4806
 
4807
         memissue[ head5 ] =    ~iqentry_stomp[head5] && iqentry_memready[ head5 ]              // addr and data are valid
4808
                                        // ... and no preceding instruction is ready to go
4809 49 robfinch
                                        && issue_count < `NUM_MEM
4810 48 robfinch
                                        //&& ~iqentry_memready[head0]
4811
                                        //&& ~iqentry_memready[head1] 
4812
                                        //&& ~iqentry_memready[head2] 
4813
                                        //&& ~iqentry_memready[head3] 
4814
                                        //&& ~iqentry_memready[head4] 
4815
                                        // ... and there is no address-overlap with any preceding instruction
4816 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4817
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4818
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
4819
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4820
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
4821
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4822
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
4823
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
4824
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
4825
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head5][AMSB:3] != iqentry_a1[head4][AMSB:3] || iqentry_out[head4] || iqentry_done[head4])))
4826 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4827
                                        && (iqentry_rl[head5] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4828
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4829
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4830
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4831
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
4832
                                                                                         : 1'b1)
4833
                                        // ... if a preivous op has the aquire bit set
4834
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4835
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4836
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4837
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4838
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
4839
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4840 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4841
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4842 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4843
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4844
                                )
4845 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4846 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4847
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4848
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4849
                                )
4850 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
4851 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4852
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4853
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4854
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
4855
                                )
4856 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4857
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4858 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4859
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4860
                                )
4861 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
4862 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4863
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4864
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4865
                                )
4866 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
4867 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4868
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4869
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4870
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
4871
                                )
4872
                                        // ... and, if it is a SW, there is no chance of it being undone
4873
                                        && (iqentry_load[head5] ||
4874
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4875
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4876
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4877
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
4878
                       && !(iqentry_fc[head4]||iqentry_canex[head4]));
4879
         if (memissue[head5])
4880
                issue_count = issue_count + 1;
4881
 
4882
`ifdef FULL_ISSUE_LOGIC
4883
         memissue[ head6 ] =    ~iqentry_stomp[head6] && iqentry_memready[ head6 ]              // addr and data are valid
4884
                                        // ... and no preceding instruction is ready to go
4885 49 robfinch
                                        && issue_count < `NUM_MEM
4886 48 robfinch
                                        //&& ~iqentry_memready[head0]
4887
                                        //&& ~iqentry_memready[head1] 
4888
                                        //&& ~iqentry_memready[head2] 
4889
                                        //&& ~iqentry_memready[head3] 
4890
                                        //&& ~iqentry_memready[head4] 
4891
                                        //&& ~iqentry_memready[head5] 
4892
                                        // ... and there is no address-overlap with any preceding instruction
4893 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4894 53 robfinch
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head0][AMSB:3])))
4895 52 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
4896 53 robfinch
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head1][AMSB:3])))
4897 52 robfinch
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
4898 53 robfinch
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head2][AMSB:3])))
4899 52 robfinch
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
4900 53 robfinch
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head3][AMSB:3])))
4901 52 robfinch
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
4902 53 robfinch
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head4][AMSB:3])))
4903 52 robfinch
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5]) || iqentry_done[head5]
4904 53 robfinch
                                                || (iqentry_a1_v[head5] && (iqentry_a1[head6][AMSB:3] != iqentry_a1[head5][AMSB:3])))
4905 48 robfinch
                                        && (iqentry_rl[head6] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4906
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4907
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4908
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4909
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
4910
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
4911
                                                                                         : 1'b1)
4912
                                        // ... if a preivous op has the aquire bit set
4913
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4914
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4915
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4916
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4917
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
4918
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
4919
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4920 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4921
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4922 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4923
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4924
                                )
4925 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4926 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4927
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4928
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4929
                                )
4930 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
4931 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4932
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4933
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4934
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
4935
                                )
4936 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
4937 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4938
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4939
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
4940
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
4941
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
4942
                                )
4943 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4944
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4945 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4946
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4947
                                )
4948 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
4949 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4950
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4951
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
4952
                                )
4953 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
4954 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4955
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4956
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4957
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
4958
                                )
4959 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
4960 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4961
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
4962
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
4963
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
4964
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
4965
                                )
4966
                                        // ... and, if it is a SW, there is no chance of it being undone
4967
                                        && (iqentry_load[head6] ||
4968
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4969
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4970
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
4971
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
4972
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
4973
                       && !(iqentry_fc[head5]||iqentry_canex[head5]));
4974
         if (memissue[head6])
4975
                issue_count = issue_count + 1;
4976
 
4977
         memissue[ head7 ] =    ~iqentry_stomp[head7] && iqentry_memready[ head7 ]              // addr and data are valid
4978
                                        // ... and no preceding instruction is ready to go
4979 49 robfinch
                                        && issue_count < `NUM_MEM
4980 48 robfinch
                                        //&& ~iqentry_memready[head0]
4981
                                        //&& ~iqentry_memready[head1] 
4982
                                        //&& ~iqentry_memready[head2] 
4983
                                        //&& ~iqentry_memready[head3] 
4984
                                        //&& ~iqentry_memready[head4] 
4985
                                        //&& ~iqentry_memready[head5] 
4986
                                        //&& ~iqentry_memready[head6] 
4987
                                        // ... and there is no address-overlap with any preceding instruction
4988 52 robfinch
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0]) || iqentry_done[head0]
4989
                                                || (iqentry_a1_v[head0] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head0][AMSB:3] || iqentry_out[head0] || iqentry_done[head0])))
4990
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1]) || iqentry_done[head1]
4991
                                                || (iqentry_a1_v[head1] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head1][AMSB:3] || iqentry_out[head1] || iqentry_done[head1])))
4992
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2]) || iqentry_done[head2]
4993
                                                || (iqentry_a1_v[head2] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head2][AMSB:3] || iqentry_out[head2] || iqentry_done[head2])))
4994
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3]) || iqentry_done[head3]
4995
                                                || (iqentry_a1_v[head3] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head3][AMSB:3] || iqentry_out[head3] || iqentry_done[head3])))
4996
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4]) || iqentry_done[head4]
4997
                                                || (iqentry_a1_v[head4] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head4][AMSB:3] || iqentry_out[head4] || iqentry_done[head4])))
4998
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5]) || iqentry_done[head5]
4999
                                                || (iqentry_a1_v[head5] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head5][AMSB:3] || iqentry_out[head5] || iqentry_done[head5])))
5000
                                        && (!iqentry_mem[head6] || (iqentry_agen[head6] & iqentry_out[head6]) || iqentry_done[head6]
5001
                                                || (iqentry_a1_v[head6] && (iqentry_a1[head7][AMSB:3] != iqentry_a1[head6][AMSB:3] || iqentry_out[head6] || iqentry_done[head6])))
5002 48 robfinch
                                        && (iqentry_rl[head7] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
5003
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
5004
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
5005
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
5006
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
5007
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
5008
                                                                                 && (iqentry_done[head6] || !iqentry_v[head6] || !iqentry_mem[head6])
5009
                                                                                         : 1'b1)
5010
                                        // ... if a preivous op has the aquire bit set
5011
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
5012
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
5013
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5014
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5015
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
5016
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
5017
                                        && !(iqentry_aq[head6] && iqentry_v[head6])
5018
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5019 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5020
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5021 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5022
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5023
                                )
5024 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5025 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5026
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5027
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5028
                                )
5029 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
5030 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5031
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5032
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5033
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
5034
                                )
5035 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
5036 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5037
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5038
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5039
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5040
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
5041
                                )
5042 49 robfinch
                    && (!(iqentry_iv[head6] && iqentry_memsb[head6]) ||
5043 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5044
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5045
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5046
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5047
                                &&   (iqentry_done[head4] || !iqentry_v[head4])
5048
                                &&   (iqentry_done[head5] || !iqentry_v[head5]))
5049
                                )
5050 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5051
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5052 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5053
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5054
                                )
5055 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5056 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5057
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5058
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5059
                                )
5060 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
5061 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5062
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5063
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5064
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
5065
                                )
5066 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
5067 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5068
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5069
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5070
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5071
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
5072
                                )
5073 49 robfinch
                    && (!(iqentry_iv[head6] && iqentry_memdb[head6]) ||
5074 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5075
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5076
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5077
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5078
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4])
5079
                                && (!iqentry_mem[head5] || iqentry_done[head5] || !iqentry_v[head5]))
5080
                                )
5081
                                        // ... and, if it is a SW, there is no chance of it being undone
5082
                                        && (iqentry_load[head7] ||
5083
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5084
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5085
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5086
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5087
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
5088
                       && !(iqentry_fc[head5]||iqentry_canex[head5])
5089
                       && !(iqentry_fc[head6]||iqentry_canex[head6]));
5090
`endif
5091
end
5092
 
5093 49 robfinch
reg [2:0] wbptr;
5094
always @*
5095
begin
5096
        // Crashes sim
5097
//      wbptr <= `WB_DEPTH-1;
5098
//      if (wb_v==8'h0)
5099
//              wbptr <= 3'd0;
5100
//      else
5101
//      begin
5102
//              for (n = `WB_DEPTH-2; n >= 0; n = n - 1)
5103
//                      if (wb_v[n] && wbptr==`WB_DEPTH-1)
5104
//                              wbptr <= n + 1;
5105
//      end
5106
        if (wb_v[6])
5107
                wbptr <= 3'd7;
5108
        else if (wb_v[5])
5109
                wbptr <= 3'd6;
5110
        else if (wb_v[4])
5111
                wbptr <= 3'd5;
5112
        else if (wb_v[3])
5113
                wbptr <= 3'd4;
5114
        else if (wb_v[2])
5115
                wbptr <= 3'd3;
5116
        else if (wb_v[1])
5117
                wbptr <= 3'd2;
5118
        else if (wb_v[0])
5119
                wbptr <= 3'd1;
5120
        else
5121
                wbptr <= 3'd0;
5122
end
5123
 
5124 48 robfinch
// Stomp logic for branch miss.
5125
 
5126
FT64_stomp #(QENTRIES) ustmp1
5127
(
5128
        .branchmiss(branchmiss),
5129
        .branchmiss_thrd(branchmiss_thrd),
5130
        .missid(missid),
5131
        .head0(head0),
5132
        .thrd(iqentry_thrd),
5133
        .iqentry_v(iqentry_v),
5134
        .stomp(iqentry_stomp)
5135
);
5136
 
5137
always @*
5138
begin
5139 51 robfinch
        if (iqentry_stomp[0] && iqentry_ret[0])
5140 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5141 51 robfinch
        if (iqentry_stomp[1] && iqentry_ret[1])
5142 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5143 51 robfinch
        if (iqentry_stomp[2] && iqentry_ret[2])
5144 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5145 51 robfinch
        if (iqentry_stomp[3] && iqentry_ret[3])
5146 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5147 51 robfinch
        if (iqentry_stomp[4] && iqentry_ret[4])
5148 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5149 51 robfinch
        if (iqentry_stomp[5] && iqentry_ret[5])
5150 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5151 51 robfinch
        if (iqentry_stomp[6] && iqentry_ret[6])
5152 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5153 51 robfinch
        if (iqentry_stomp[7] && iqentry_ret[7])
5154 48 robfinch
                stompedOnRets = stompedOnRets + 4'd1;
5155 52 robfinch
        if (iqentry_stomp[8] && iqentry_ret[8])
5156
                stompedOnRets = stompedOnRets + 4'd1;
5157
        if (iqentry_stomp[9] && iqentry_ret[9])
5158
                stompedOnRets = stompedOnRets + 4'd1;
5159 48 robfinch
end
5160
 
5161 49 robfinch
reg id1_vi, id2_vi, id3_vi;
5162
wire [4:0] id1_ido, id2_ido, id3_ido;
5163
wire id1_vo, id2_vo, id3_vo;
5164
wire id1_clk, id2_clk, id3_clk;
5165 48 robfinch
 
5166 49 robfinch
// Always at least one decoder
5167 50 robfinch
assign id1_clk = clk_i;
5168
//BUFGCE uclkb2
5169
//(
5170
//      .I(clk_i),
5171
//      .CE(id1_available),
5172
//      .O(id1_clk)
5173
//);
5174 48 robfinch
 
5175
FT64_idecoder uid1
5176
(
5177
        .clk(id1_clk),
5178
        .idv_i(id1_vi),
5179
        .id_i(id1_id),
5180
        .instr(id1_instr),
5181
        .ven(id1_ven),
5182
        .vl(id1_vl),
5183
        .thrd(id1_thrd),
5184
        .predict_taken(id1_pt),
5185
        .Rt(id1_Rt),
5186
        .bus(id1_bus),
5187
        .id_o(id1_ido),
5188
        .idv_o(id1_vo)
5189
);
5190
 
5191 49 robfinch
generate begin : gIDUInst
5192
if (`NUM_IDU > 1) begin
5193 50 robfinch
//BUFGCE uclkb3
5194
//(
5195
//      .I(clk_i),
5196
//      .CE(id2_available),
5197
//      .O(id2_clk)
5198
//);
5199
assign id2_clk = clk_i;
5200 48 robfinch
 
5201
FT64_idecoder uid2
5202
(
5203
        .clk(id2_clk),
5204
        .idv_i(id2_vi),
5205
        .id_i(id2_id),
5206
        .instr(id2_instr),
5207
        .ven(id2_ven),
5208
        .vl(id2_vl),
5209
        .thrd(id2_thrd),
5210
        .predict_taken(id2_pt),
5211
        .Rt(id2_Rt),
5212
        .bus(id2_bus),
5213
        .id_o(id2_ido),
5214
        .idv_o(id2_vo)
5215
);
5216 49 robfinch
end
5217
if (`NUM_IDU > 2) begin
5218 50 robfinch
//BUFGCE uclkb4
5219
//(
5220
//      .I(clk_i),
5221
//      .CE(id3_available),
5222
//      .O(id3_clk)
5223
//);
5224
assign id3_clk = clk_i;
5225 48 robfinch
 
5226 49 robfinch
FT64_idecoder uid2
5227
(
5228
        .clk(id3_clk),
5229
        .idv_i(id3_vi),
5230
        .id_i(id3_id),
5231
        .instr(id3_instr),
5232
        .ven(id3_ven),
5233
        .vl(id3_vl),
5234
        .thrd(id3_thrd),
5235
        .predict_taken(id3_pt),
5236
        .Rt(id3_Rt),
5237
        .bus(id3_bus),
5238
        .id_o(id3_ido),
5239
        .idv_o(id3_vo)
5240
);
5241
end
5242
end
5243
endgenerate
5244
 
5245 48 robfinch
//
5246
// EXECUTE
5247
//
5248
reg [63:0] csr_r;
5249
always @*
5250
    read_csr(alu0_instr[29:18],csr_r,alu0_thrd);
5251
FT64_alu #(.BIG(1'b1),.SUP_VECTOR(SUP_VECTOR)) ualu0 (
5252
  .rst(rst),
5253
  .clk(clk),
5254
  .ld(alu0_ld),
5255
  .abort(1'b0),
5256
  .instr(alu0_instr),
5257
  .a(alu0_argA),
5258
  .b(alu0_argB),
5259
  .c(alu0_argC),
5260
  .pc(alu0_pc),
5261
//    .imm(alu0_argI),
5262
  .tgt(alu0_tgt),
5263
  .ven(alu0_ven),
5264
  .vm(vm[alu0_instr[25:23]]),
5265
  .sbl(sbl),
5266
  .sbu(sbu),
5267
  .csr(csr_r),
5268
  .o(alu0_bus),
5269
  .ob(alu0b_bus),
5270
  .done(alu0_done),
5271
  .idle(alu0_idle),
5272
  .excen(aec[4:0]),
5273
  .exc(alu0_exc),
5274
  .thrd(alu0_thrd),
5275
  .mem(alu0_mem),
5276
  .shift48(alu0_shft48)
5277
);
5278 49 robfinch
generate begin : gAluInst
5279
if (`NUM_ALU > 1) begin
5280 48 robfinch
FT64_alu #(.BIG(1'b0),.SUP_VECTOR(SUP_VECTOR)) ualu1 (
5281
  .rst(rst),
5282
  .clk(clk),
5283
  .ld(alu1_ld),
5284
  .abort(1'b0),
5285
  .instr(alu1_instr),
5286
  .a(alu1_argA),
5287
  .b(alu1_argB),
5288
  .c(alu1_argC),
5289
  .pc(alu1_pc),
5290
  //.imm(alu1_argI),
5291
  .tgt(alu1_tgt),
5292
  .ven(alu1_ven),
5293
  .vm(vm[alu1_instr[25:23]]),
5294
  .sbl(sbl),
5295
  .sbu(sbu),
5296
  .csr(64'd0),
5297
  .o(alu1_bus),
5298
  .ob(alu1b_bus),
5299
  .done(alu1_done),
5300
  .idle(alu1_idle),
5301
  .excen(aec[4:0]),
5302
  .exc(alu1_exc),
5303
  .thrd(1'b0),
5304
  .mem(alu1_mem),
5305
  .shift48(alu1_shft48)
5306
);
5307 49 robfinch
end
5308
end
5309
endgenerate
5310
 
5311
generate begin : gFPUInst
5312
if (`NUM_FPU > 0) begin
5313
wire fpu1_clk;
5314 50 robfinch
//BUFGCE ufpc1
5315
//(
5316
//      .I(clk_i),
5317
//      .CE(fpu1_available),
5318
//      .O(fpu1_clk)
5319
//);
5320
assign fpu1_clk = clk_i;
5321
 
5322 48 robfinch
fpUnit ufp1
5323
(
5324
  .rst(rst),
5325 49 robfinch
  .clk(fpu1_clk),
5326 48 robfinch
  .clk4x(clk4x),
5327
  .ce(1'b1),
5328 49 robfinch
  .ir(fpu1_instr),
5329
  .ld(fpu1_ld),
5330
  .a(fpu1_argA),
5331
  .b(fpu1_argB),
5332
  .imm(fpu1_argI),
5333
  .o(fpu1_bus),
5334 48 robfinch
  .csr_i(),
5335 52 robfinch
  .status(fpu1_status),
5336 48 robfinch
  .exception(),
5337 49 robfinch
  .done(fpu1_done)
5338 48 robfinch
);
5339 49 robfinch
end
5340
if (`NUM_FPU > 1) begin
5341
wire fpu2_clk;
5342 50 robfinch
//BUFGCE ufpc2
5343
//(
5344
//      .I(clk_i),
5345
//      .CE(fpu2_available),
5346
//      .O(fpu2_clk)
5347
//);
5348
assign fpu2_clk = clk_i;
5349 49 robfinch
fpUnit ufp1
5350
(
5351
  .rst(rst),
5352
  .clk(fpu2_clk),
5353
  .clk4x(clk4x),
5354
  .ce(1'b1),
5355
  .ir(fpu2_instr),
5356
  .ld(fpu2_ld),
5357
  .a(fpu2_argA),
5358
  .b(fpu2_argB),
5359
  .imm(fpu2_argI),
5360
  .o(fpu2_bus),
5361
  .csr_i(),
5362 52 robfinch
  .status(fpu2_status),
5363 49 robfinch
  .exception(),
5364
  .done(fpu2_done)
5365
);
5366
end
5367
end
5368
endgenerate
5369 48 robfinch
 
5370 52 robfinch
assign fpu1_exc = (fpu1_available) ?
5371
                                                                        ((|fpu1_status[15:0]) ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
5372
assign fpu2_exc = (fpu2_available) ?
5373
                                                                        ((|fpu2_status[15:0]) ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
5374 49 robfinch
 
5375 48 robfinch
assign  alu0_v = alu0_dataready,
5376
        alu1_v = alu1_dataready;
5377
assign  alu0_id = alu0_sourceid,
5378
            alu1_id = alu1_sourceid;
5379 49 robfinch
assign  fpu1_v = fpu1_dataready;
5380
assign  fpu1_id = fpu1_sourceid;
5381
assign  fpu2_v = fpu2_dataready;
5382
assign  fpu2_id = fpu2_sourceid;
5383 48 robfinch
 
5384
`ifdef SUPPORT_SMT
5385
wire [1:0] olm = ol[fcu_thrd];
5386
`else
5387
wire [1:0] olm = ol;
5388
`endif
5389
 
5390
assign  fcu_v = fcu_dataready;
5391
assign  fcu_id = fcu_sourceid;
5392
 
5393
wire [4:0] fcmpo;
5394
wire fnanx;
5395
fp_cmp_unit ufcmp1 (fcu_argA, fcu_argB, fcmpo, fnanx);
5396
 
5397
wire fcu_takb;
5398
 
5399
always @*
5400
begin
5401
    fcu_exc <= `FLT_NONE;
5402
    casez(fcu_instr[`INSTRUCTION_OP])
5403
    `CHK:   begin
5404
                if (fcu_instr[21])
5405
                    fcu_exc <= fcu_argA >= fcu_argB && fcu_argA < fcu_argC ? `FLT_NONE : `FLT_CHK;
5406
            end
5407
    `REX:
5408
        case(olm)
5409
        `OL_USER:   fcu_exc <= `FLT_PRIV;
5410
        default:    ;
5411
        endcase
5412
        endcase
5413
end
5414
 
5415
FT64_EvalBranch ube1
5416
(
5417
        .instr(fcu_instr),
5418
        .a(fcu_argA),
5419
        .b(fcu_argB),
5420
        .c(fcu_argC),
5421
        .takb(fcu_takb)
5422
);
5423
 
5424
FT64_FCU_Calc ufcuc1
5425
(
5426
        .ol(olm),
5427
        .instr(fcu_instr),
5428
        .tvec(tvec[fcu_instr[14:13]]),
5429
        .a(fcu_argA),
5430
        .i(fcu_argI),
5431
        .pc(fcu_pc),
5432
        .im(im),
5433
        .waitctr(waitctr),
5434
        .bus(fcu_bus)
5435
);
5436
 
5437
always @*
5438
begin
5439
case(fcu_instr[`INSTRUCTION_OP])
5440
`R2:    fcu_misspc = fcu_argB;  // RTI (we don't bother fully decoding this as it's the only R2)
5441
`RET:   fcu_misspc = fcu_argB;
5442
`REX:   fcu_misspc = fcu_bus;
5443
`BRK:   fcu_misspc = {tvec[0][31:8], 1'b0, olm, 5'h0};
5444
`JAL:   fcu_misspc = fcu_argA + fcu_argI;
5445
//`CHK: fcu_misspc = fcu_nextpc + fcu_argI;     // Handled as an instruction exception
5446
// Default: branch
5447
default:        fcu_misspc = fcu_takb ? fcu_nextpc + fcu_brdisp : fcu_nextpc;
5448
endcase
5449
fcu_misspc[0] = 1'b0;
5450
end
5451
 
5452
// To avoid false branch mispredicts the branch isn't evaluated until the
5453
// following instruction queues. The address of the next instruction is
5454
// looked at to see if the BTB predicted correctly.
5455
 
5456 51 robfinch
wire fcu_brk_miss = (fcu_brk || fcu_rti) && fcu_v;
5457
wire fcu_ret_miss = fcu_ret && fcu_v && (fcu_argB != iqentry_pc[nid]);
5458
wire fcu_jal_miss = fcu_jal && fcu_v && fcu_argA + fcu_argI != iqentry_pc[nid];
5459 48 robfinch
wire fcu_followed = iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]];
5460
always @*
5461
if (fcu_dataready) begin
5462
//      if (fcu_timeout[7])
5463
//              fcu_branchmiss = TRUE;
5464
        // Break and RTI switch register sets, and so are always treated as a branch miss in order to
5465
        // flush the pipeline. Hardware interrupts also stream break instructions so they need to 
5466
        // flushed from the queue so the interrupt is recognized only once.
5467
        // BRK and RTI are handled as excmiss types which are processed during the commit stage.
5468
//      else
5469
        if (fcu_brk_miss)
5470
                fcu_branchmiss = TRUE & ~fcu_clearbm;
5471
    // the following instruction is queued
5472
        else
5473
        if (fcu_followed) begin
5474
`ifdef SUPPORT_SMT
5475
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol[fcu_thrd]) && fcu_v)
5476
`else
5477
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol) && fcu_v)
5478
`endif
5479
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5480
                else if (fcu_ret_miss)
5481
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5482 52 robfinch
                else if (fcu_branch && fcu_v && (((fcu_takb && (fcu_misspc != iqentry_pc[nid])) ||
5483
                                            (~fcu_takb && (fcu_pc + fcu_insln != iqentry_pc[nid])))))// || iqentry_v[nid]))
5484 48 robfinch
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5485
                else if (fcu_jal_miss)
5486
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5487
                else if (fcu_instr[`INSTRUCTION_OP] == `CHK && ~fcu_takb && fcu_v)
5488
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5489
                else
5490
                    fcu_branchmiss = FALSE;
5491
        end
5492
        else begin
5493
                // Stuck at the head and can't finish because there's still an uncommitted instruction in the queue.
5494
                // -> cause a branch miss to clear the queue.
5495
                if (iqentry_v[nid] && !IsCall(fcu_instr) && !IsJmp(fcu_instr) && fcu_v)
5496
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5497
                else
5498
                /*
5499
                if (fcu_id==head0 && iqentry_v[idp1(head0)]) begin
5500
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
5501
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
5502
                        fcu_branchmiss = FALSE;
5503
                    else
5504
                                fcu_branchmiss = TRUE;
5505
                end
5506
                else if (fcu_id==head1 && iqentry_v[idp2(head1)]) begin
5507
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
5508
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
5509
                        fcu_branchmiss = FALSE;
5510
                    else
5511
                                fcu_branchmiss = TRUE;
5512
                end
5513
                else*/
5514
                        fcu_branchmiss = FALSE;
5515
        end
5516
end
5517
else
5518
        fcu_branchmiss = FALSE;
5519
 
5520
// Flow control ops don't issue until the next instruction queues.
5521
// The fcu_timeout tracks how long the flow control op has been in the "out" state.
5522
// It should never be that way more than a couple of cycles. Sometimes the fcu_wr pulse got missed
5523
// because the following instruction got stomped on during a branchmiss, hence iqentry_v isn't true.
5524
wire fcu_wr = (fcu_v && iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]]);//      // && iqentry_v[nid]
5525
//                                      && fcu_instr==iqentry_instr[fcu_id[`QBITS]]);// || fcu_timeout==8'h05;
5526
 
5527
FT64_RMW_alu urmwalu0 (rmw_instr, rmw_argA, rmw_argB, rmw_argC, rmw_res);
5528
 
5529
//assign fcu_done = IsWait(fcu_instr) ? ((waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]]) :
5530
//                                      fcu_v && iqentry_v[idp1(fcu_id)] && iqentry_sn[idp1(fcu_id)]==iqentry_sn[fcu_id[`QBITS]]+5'd1;
5531
 
5532
// An exception in a committing instruction takes precedence
5533
/*
5534
Too slow. Needs to be registered
5535
assign  branchmiss = excmiss|fcu_branchmiss,
5536
    misspc = excmiss ? excmisspc : fcu_misspc,
5537
    missid = excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
5538
assign branchmiss_thrd =  excmiss ? excthrd : fcu_thrd;
5539
*/
5540
 
5541
//
5542
// additional DRAM-enqueue logic
5543
 
5544
assign dram_avail = (dram0 == `DRAMSLOT_AVAIL || dram1 == `DRAMSLOT_AVAIL || dram2 == `DRAMSLOT_AVAIL);
5545
 
5546 53 robfinch
always @*
5547
for (n = 0; n < QENTRIES; n = n + 1)
5548
        iqentry_memopsvalid[n] <= (iqentry_mem[n] & iqentry_a2_v[n] & iqentry_agen[n]);
5549 48 robfinch
 
5550 53 robfinch
always @*
5551
for (n = 0; n < QENTRIES; n = n + 1)
5552
        iqentry_memready[n] <= (iqentry_v[n] & iqentry_memopsvalid[n] & ~iqentry_memissue[n] & ~iqentry_done[n] & ~iqentry_out[n] & ~iqentry_stomp[n]);
5553 48 robfinch
 
5554 50 robfinch
assign outstanding_stores = (dram0 && dram0_store) ||
5555
                            (dram1 && dram1_store) ||
5556
                            (dram2 && dram2_store);
5557 48 robfinch
 
5558
//
5559
// additional COMMIT logic
5560
//
5561
always @*
5562
begin
5563
    commit0_v <= ({iqentry_v[head0], iqentry_cmt[head0]} == 2'b11 && ~|panic);
5564
    commit0_id <= {iqentry_mem[head0], head0};  // if a memory op, it has a DRAM-bus id
5565
    commit0_tgt <= iqentry_tgt[head0];
5566
    commit0_we  <= iqentry_we[head0];
5567
    commit0_bus <= iqentry_res[head0];
5568 49 robfinch
    if (`NUM_CMT > 1) begin
5569
            commit1_v <= ({iqentry_v[head0], iqentry_cmt[head0]} != 2'b10
5570
                       && {iqentry_v[head1], iqentry_cmt[head1]} == 2'b11
5571
                       && ~|panic);
5572
            commit1_id <= {iqentry_mem[head1], head1};
5573
            commit1_tgt <= iqentry_tgt[head1];
5574
            commit1_we  <= iqentry_we[head1];
5575
            commit1_bus <= iqentry_res[head1];
5576
        end
5577
        else begin
5578
                commit1_tgt <= 12'h000;
5579
                commit1_we <= 8'h00;
5580
        end
5581 48 robfinch
end
5582
 
5583 51 robfinch
assign int_commit = (commit0_v && iqentry_irq[head0]) ||
5584
                    (commit0_v && commit1_v && iqentry_irq[head1] && `NUM_CMT > 1);
5585 48 robfinch
 
5586
// Detect if a given register will become valid during the current cycle.
5587
// We want a signal that is active during the current clock cycle for the read
5588
// through register file, which trims a cycle off register access for every
5589
// instruction. But two different kinds of assignment statements can't be
5590
// placed under the same always block, it's a bad practice and may not work.
5591
// So a signal is created here with it's own always block.
5592
reg [AREGS-1:0] regIsValid;
5593
always @*
5594
begin
5595
        for (n = 1; n < AREGS; n = n + 1)
5596
        begin
5597
                regIsValid[n] = rf_v[n];
5598
                if (branchmiss)
5599
               if (~livetarget[n]) begin
5600
                        if (branchmiss_thrd) begin
5601
                                if (n >= 128)
5602
                                        regIsValid[n] = `VAL;
5603
                        end
5604
                        else begin
5605
                                if (n < 128)
5606
                                        regIsValid[n] = `VAL;
5607
                        end
5608
               end
5609
                if (commit0_v && n=={commit0_tgt[7:0]})
5610
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit0_tgt[7:0]} ] == commit0_id
5611
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit0_id[`QBITS] ]));
5612 49 robfinch
                if (commit1_v && n=={commit1_tgt[7:0]} && `NUM_CMT > 1)
5613 48 robfinch
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit1_tgt[7:0]} ] == commit1_id
5614
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit1_id[`QBITS] ]));
5615
        end
5616
        regIsValid[0] = `VAL;
5617 55 robfinch
        regIsValid[32] = `VAL;
5618
        regIsValid[64] = `VAL;
5619
        regIsValid[128] = `VAL;
5620
`ifdef SMT
5621
        regIsValid[144] = `VAL;
5622
        regIsValid[160] = `VAL;
5623
        regIsValid[192] = `VAL;
5624
        regIsValid[224] = `VAL;
5625
`endif
5626 48 robfinch
end
5627
 
5628
// Wait until the cycle after Ra becomes valid to give time to read
5629
// the vector element from the register file.
5630
reg rf_vra0, rf_vra1;
5631
/*always @(posedge clk)
5632
    rf_vra0 <= regIsValid[Ra0s];
5633
always @(posedge clk)
5634
    rf_vra1 <= regIsValid[Ra1s];
5635
*/
5636
// Check how many instructions can be queued. This might be fewer than the
5637
// number ready to queue from the fetch stage if queue slots aren't
5638
// available or if there are no more physical registers left for remapping.
5639
// The fetch stage needs to know how many instructions will queue so this
5640
// logic is placed here.
5641
// NOPs are filtered out and do not enter the instruction queue. The core
5642
// will stream NOPs on a cache miss and they would mess up the queue order
5643
// if there are immediate prefixes in the queue.
5644
// For the VEX instruction, the instruction can't queue until register Ra
5645
// is valid, because register Ra is used to specify the vector element to
5646
// read.
5647
wire q2open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV;
5648
wire q3open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV && iqentry_v[idp1(tail1)]==`INV;
5649
always @*
5650
begin
5651
        canq1 <= FALSE;
5652
        canq2 <= FALSE;
5653
        queued1 <= FALSE;
5654
        queued2 <= FALSE;
5655
        queuedNop <= FALSE;
5656
        vqueued2 <= FALSE;
5657
        if (!branchmiss) begin
5658
      // Two available
5659
      if (fetchbuf1_v & fetchbuf0_v) begin
5660
          // Is there a pair of NOPs ? (cache miss)
5661
          if ((fetchbuf0_instr[`INSTRUCTION_OP]==`NOP) && (fetchbuf1_instr[`INSTRUCTION_OP]==`NOP))
5662
              queuedNop <= TRUE;
5663
          else begin
5664
              // If it's a predicted branch queue only the first instruction, the second
5665
              // instruction will be stomped on.
5666
              if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
5667
                  if (iqentry_v[tail0]==`INV) begin
5668
                      canq1 <= TRUE;
5669
                      queued1 <= TRUE;
5670
                  end
5671
              end
5672
              // This is where a single NOP is allowed through to simplify the code. A
5673
              // single NOP can't be a cache miss. Otherwise it would be necessary to queue
5674
              // fetchbuf1 on tail0 it would add a nightmare to the enqueue code.
5675
              // Not a branch and there are two instructions fetched, see whether or not
5676
              // both instructions can be queued.
5677
              else begin
5678
                  if (iqentry_v[tail0]==`INV) begin
5679
                      canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5680
                      queued1 <= (
5681
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5682
                      if (iqentry_v[tail1]==`INV) begin
5683
                          canq2 <= ((!IsVex(fetchbuf1_instr) || rf_vra1)) || !SUP_VECTOR;
5684
                          queued2 <= (
5685
                                (!IsVector(fetchbuf1_instr) && (!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5686
                          vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5687
                      end
5688
                  end
5689
                  // If an irq is active during a vector instruction fetch, claim the vector instruction
5690
                  // is finished queueing even though it may not be. It'll pick up where it left off after
5691
                  // the exception is processed.
5692 52 robfinch
                  if (freezePC) begin
5693 48 robfinch
                        if (IsVector(fetchbuf0_instr) && IsVector(fetchbuf1_instr) && vechain) begin
5694
                                queued1 <= TRUE;
5695
                                queued2 <= TRUE;
5696
                        end
5697
                        else if (IsVector(fetchbuf0_instr)) begin
5698
                                queued1 <= TRUE;
5699
                                if (vqe0 < vl-2)
5700
                                        queued2 <= TRUE;
5701
                                else
5702
                                        queued2 <= iqentry_v[tail1]==`INV;
5703
                        end
5704
                  end
5705
              end
5706
          end
5707
      end
5708
      // One available
5709
      else if (fetchbuf0_v) begin
5710
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
5711
              if (iqentry_v[tail0]==`INV) begin
5712
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5713
                  queued1 <=
5714
                        (((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5715
              end
5716
              if (iqentry_v[tail1]==`INV) begin
5717
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
5718
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5719
                end
5720 52 robfinch
                if (freezePC) begin
5721 48 robfinch
                if (IsVector(fetchbuf0_instr)) begin
5722
                        queued1 <= TRUE;
5723
                        if (vqe0 < vl-2)
5724
                                queued2 <= iqentry_v[tail1]==`INV;
5725
                end
5726
                end
5727
          end
5728
          else
5729
              queuedNop <= TRUE;
5730
      end
5731
      else if (fetchbuf1_v) begin
5732
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
5733
              if (iqentry_v[tail0]==`INV) begin
5734
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
5735
                  queued1 <= (
5736
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
5737
              end
5738
              if (iqentry_v[tail1]==`INV) begin
5739
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
5740
                  vqueued2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2;
5741
                end
5742 52 robfinch
                if (freezePC) begin
5743 48 robfinch
                if (IsVector(fetchbuf1_instr)) begin
5744
                        queued1 <= TRUE;
5745
                        if (vqe1 < vl-2)
5746
                                queued2 <= iqentry_v[tail1]==`INV;
5747
                end
5748
                end
5749
          end
5750
          else
5751
              queuedNop <= TRUE;
5752
      end
5753
      //else no instructions available to queue
5754
    end
5755
    else begin
5756
      // One available
5757
      if (fetchbuf0_v && fetchbuf0_thrd != branchmiss_thrd) begin
5758
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
5759
              if (iqentry_v[tail0]==`INV) begin
5760
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5761
                  queued1 <= (
5762
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5763
              end
5764
              if (iqentry_v[tail1]==`INV) begin
5765
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
5766
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5767
                end
5768
          end
5769
          else
5770
              queuedNop <= TRUE;
5771
      end
5772
      else if (fetchbuf1_v && fetchbuf1_thrd != branchmiss_thrd) begin
5773
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
5774
              if (iqentry_v[tail0]==`INV) begin
5775
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
5776
                  queued1 <= (
5777
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
5778
              end
5779
              if (iqentry_v[tail1]==`INV) begin
5780
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
5781
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5782
                end
5783
          end
5784
          else
5785
              queuedNop <= TRUE;
5786
      end
5787
        else
5788
                queuedNop <= TRUE;
5789
    end
5790
end
5791
 
5792
//
5793
// Branchmiss seems to be sticky sometimes during simulation. For instance branch miss
5794
// and cache miss at same time. The branchmiss should clear before the core continues
5795
// so the positive edge is detected to avoid incrementing the sequnce number too many
5796
// times.
5797
wire pebm;
5798
edge_det uedbm (.rst(rst), .clk(clk), .ce(1'b1), .i(branchmiss), .pe(pebm), .ne(), .ee() );
5799
 
5800
reg [5:0] ld_time;
5801
reg [63:0] wc_time_dat;
5802
reg [63:0] wc_times;
5803
always @(posedge tm_clk_i)
5804
begin
5805
        if (|ld_time)
5806
                wc_time <= wc_time_dat;
5807
        else begin
5808
                wc_time[31:0] <= wc_time[31:0] + 32'd1;
5809
                if (wc_time[31:0] >= TM_CLKFREQ-1) begin
5810
                        wc_time[31:0] <= 32'd0;
5811
                        wc_time[63:32] <= wc_time[63:32] + 32'd1;
5812
                end
5813
        end
5814
end
5815
 
5816
 
5817
// Monster clock domain.
5818
// Like to move some of this to clocking under different always blocks in order
5819
// to help out the toolset's synthesis, but it ain't gonna be easy.
5820
// Simulation doesn't like it if things are under separate always blocks.
5821
// Synthesis doesn't like it if things are under the same always block.
5822
 
5823 49 robfinch
//always @(posedge clk)
5824
//begin
5825
//      branchmiss <= excmiss|fcu_branchmiss;
5826
//    misspc <= excmiss ? excmisspc : fcu_misspc;
5827
//    missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
5828
//      branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
5829
//end
5830 48 robfinch
 
5831
always @(posedge clk)
5832
if (rst) begin
5833
`ifdef SUPPORT_SMT
5834 55 robfinch
     mstatus[0] <= 64'h000F;     // select register set #0 for thread 0
5835
     mstatus[1] <= 64'h800F;    // select register set #2 for thread 1
5836 48 robfinch
`else
5837 55 robfinch
     mstatus <= 64'h000F;       // select register set #0 for thread 0
5838 48 robfinch
`endif
5839
    for (n = 0; n < QENTRIES; n = n + 1) begin
5840 51 robfinch
       iqentry_v[n] <= `INV;
5841
       iqentry_iv[n] <= `INV;
5842
       iqentry_is[n] <= 3'b00;
5843
       iqentry_done[n] <= FALSE;
5844
       iqentry_cmt[n] <= FALSE;
5845
       iqentry_out[n] <= FALSE;
5846
       iqentry_agen[n] <= FALSE;
5847
       iqentry_sn[n] <= 32'd0;
5848
       iqentry_pt[n] <= FALSE;
5849
       iqentry_bt[n] <= FALSE;
5850
       iqentry_br[n] <= FALSE;
5851
       iqentry_aq[n] <= FALSE;
5852
       iqentry_rl[n] <= FALSE;
5853
       iqentry_alu0[n] <= FALSE;
5854
       iqentry_alu[n] <= FALSE;
5855
       iqentry_alu0_issue[n] <= FALSE;
5856
       iqentry_alu1_issue[n] <= FALSE;
5857
       iqentry_fpu[n] <= FALSE;
5858
       iqentry_fpu1_issue[n] <= FALSE;
5859
       iqentry_fpu2_issue[n] <= FALSE;
5860
       iqentry_fsync[n] <= FALSE;
5861
       iqentry_fc[n] <= FALSE;
5862
       iqentry_fcu_issue[n] <= FALSE;
5863 52 robfinch
       iqentry_takb[n] <= FALSE;
5864 51 robfinch
       iqentry_jmp[n] <= FALSE;
5865
       iqentry_jal[n] <= FALSE;
5866
       iqentry_ret[n] <= FALSE;
5867
       iqentry_brk[n] <= FALSE;
5868
       iqentry_irq[n] <= FALSE;
5869
       iqentry_rti[n] <= FALSE;
5870
       iqentry_ldcmp[n] <= FALSE;
5871
       iqentry_load[n] <= FALSE;
5872
       iqentry_rtop[n] <= FALSE;
5873
       iqentry_sei[n] <= FALSE;
5874
       iqentry_shft48[n] <= FALSE;
5875
       iqentry_sync[n] <= FALSE;
5876
       iqentry_ven[n] <= 6'd0;
5877
       iqentry_vl[n] <= 8'd0;
5878
       iqentry_we[n] <= 8'h00;
5879
       iqentry_rfw[n] <= FALSE;
5880
       iqentry_rmw[n] <= FALSE;
5881
       iqentry_pc[n] <= RSTPC;
5882 48 robfinch
         iqentry_instr[n] <= `NOP_INSN;
5883 56 robfinch
         iqentry_insln[n] <= 3'd4;
5884 48 robfinch
         iqentry_preload[n] <= FALSE;
5885
         iqentry_mem[n] <= FALSE;
5886
         iqentry_memndx[n] <= FALSE;
5887 51 robfinch
       iqentry_memissue[n] <= FALSE;
5888
       iqentry_mem_islot[n] <= 3'd0;
5889
       iqentry_memdb[n] <= FALSE;
5890
       iqentry_memsb[n] <= FALSE;
5891
       iqentry_tgt[n] <= 6'd0;
5892
       iqentry_imm[n] <= 1'b0;
5893
       iqentry_a0[n] <= 64'd0;
5894
       iqentry_a1[n] <= 64'd0;
5895
       iqentry_a2[n] <= 64'd0;
5896
       iqentry_a3[n] <= 64'd0;
5897
       iqentry_a1_v[n] <= `INV;
5898
       iqentry_a2_v[n] <= `INV;
5899
       iqentry_a3_v[n] <= `INV;
5900
       iqentry_a1_s[n] <= 5'd0;
5901
       iqentry_a2_s[n] <= 5'd0;
5902
       iqentry_a3_s[n] <= 5'd0;
5903
       iqentry_canex[n] <= FALSE;
5904 48 robfinch
    end
5905 49 robfinch
     bwhich <= 2'b00;
5906 48 robfinch
     dram0 <= `DRAMSLOT_AVAIL;
5907
     dram1 <= `DRAMSLOT_AVAIL;
5908
     dram2 <= `DRAMSLOT_AVAIL;
5909
     dram0_instr <= `NOP_INSN;
5910
     dram1_instr <= `NOP_INSN;
5911
     dram2_instr <= `NOP_INSN;
5912
     dram0_addr <= 32'h0;
5913
     dram1_addr <= 32'h0;
5914
     dram2_addr <= 32'h0;
5915
     L1_adr <= RSTPC;
5916
     invic <= FALSE;
5917
     tail0 <= 3'd0;
5918
     tail1 <= 3'd1;
5919
     head0 <= 0;
5920
     head1 <= 1;
5921
     head2 <= 2;
5922
     head3 <= 3;
5923
     head4 <= 4;
5924
     head5 <= 5;
5925
     head6 <= 6;
5926
     head7 <= 7;
5927 52 robfinch
     head8 <= 8;
5928
     head9 <= 9;
5929 48 robfinch
     panic = `PANIC_NONE;
5930
     alu0_dataready <= 0;
5931
     alu1_dataready <= 0;
5932
     alu0_sourceid <= 5'd0;
5933
     alu1_sourceid <= 5'd0;
5934
`ifdef SIM
5935
                alu0_pc <= RSTPC;
5936
                alu0_instr <= `NOP_INSN;
5937
                alu0_argA <= 64'h0;
5938
                alu0_argB <= 64'h0;
5939
                alu0_argC <= 64'h0;
5940
                alu0_argI <= 64'h0;
5941
                alu0_bt <= 1'b0;
5942
                alu0_mem <= 1'b0;
5943
                alu0_shft48 <= 1'b0;
5944
                alu0_thrd <= 1'b0;
5945
                alu0_tgt <= 6'h00;
5946
                alu0_ven <= 6'd0;
5947
                alu1_pc <= RSTPC;
5948
                alu1_instr <= `NOP_INSN;
5949
                alu1_argA <= 64'h0;
5950
                alu1_argB <= 64'h0;
5951
                alu1_argC <= 64'h0;
5952
                alu1_argI <= 64'h0;
5953
                alu1_bt <= 1'b0;
5954
                alu1_mem <= 1'b0;
5955
                alu1_shft48 <= 1'b0;
5956
                alu1_thrd <= 1'b0;
5957
                alu1_tgt <= 6'h00;
5958
                alu1_ven <= 6'd0;
5959
`endif
5960
     fcu_dataready <= 0;
5961
     fcu_instr <= `NOP_INSN;
5962
     dramA_v <= 0;
5963
     dramB_v <= 0;
5964
     dramC_v <= 0;
5965
     I <= 0;
5966
     icstate <= IDLE;
5967
     bstate <= BIDLE;
5968
     tick <= 64'd0;
5969
     bte_o <= 2'b00;
5970
     cti_o <= 3'b000;
5971
     cyc_o <= `LOW;
5972
     stb_o <= `LOW;
5973
     we_o <= `LOW;
5974
     sel_o <= 8'h00;
5975
     sr_o <= `LOW;
5976
     cr_o <= `LOW;
5977
     adr_o <= RSTPC;
5978
     icl_o <= `LOW;             // instruction cache load
5979
     cr0 <= 64'd0;
5980 55 robfinch
     cr0[13:8] <= 6'd0;         // select compressed instruction group #0
5981 48 robfinch
     cr0[30] <= TRUE;           // enable data caching
5982
     cr0[32] <= TRUE;           // enable branch predictor
5983
     cr0[16] <= 1'b0;           // disable SMT
5984
     cr0[17] <= 1'b0;           // sequence number reset = 1
5985 52 robfinch
     cr0[34] <= FALSE;  // write buffer merging enable
5986 48 robfinch
     pcr <= 32'd0;
5987
     pcr2 <= 64'd0;
5988
    for (n = 0; n < PREGS; n = n + 1)
5989
         rf_v[n] <= `VAL;
5990 51 robfinch
     fp_rm <= 3'd0;                     // round nearest even - default rounding mode
5991
     fpu_csr[37:32] <= 5'd31;   // register set #31
5992 48 robfinch
     waitctr <= 64'd0;
5993
    for (n = 0; n < 16; n = n + 1)
5994
         badaddr[n] <= 64'd0;
5995
     sbl <= 32'h0;
5996
     sbu <= 32'hFFFFFFFF;
5997
    // Vector
5998
     vqe0 <= 6'd0;
5999
     vqet0 <= 6'd0;
6000
     vqe1 <= 6'd0;
6001
     vqet1 <= 6'd0;
6002
     vl <= 7'd62;
6003
    for (n = 0; n < 8; n = n + 1)
6004
         vm[n] <= 64'h7FFFFFFFFFFFFFFF;
6005
     nop_fetchbuf <= 4'h0;
6006
     seq_num <= 5'd0;
6007
     seq_num1 <= 5'd0;
6008
     fcu_done <= `TRUE;
6009
     sema <= 64'h0;
6010
     tvec[0] <= RSTPC;
6011 49 robfinch
     pmr <= 64'hFFFFFFFFFFFFFFFF;
6012
     pmr[0] <= `ID1_AVAIL;
6013
     pmr[1] <= `ID2_AVAIL;
6014
     pmr[2] <= `ID3_AVAIL;
6015
     pmr[8] <= `ALU0_AVAIL;
6016
     pmr[9] <= `ALU1_AVAIL;
6017
     pmr[16] <= `FPU1_AVAIL;
6018
     pmr[17] <= `FPU2_AVAIL;
6019
     pmr[24] <= `MEM1_AVAIL;
6020
     pmr[25] <= `MEM2_AVAIL;
6021
                 pmr[26] <= `MEM3_AVAIL;
6022
     pmr[32] <= `FCU_AVAIL;
6023
     for (n = 0; n < `WB_DEPTH; n = n + 1) begin
6024
        wb_v[n] <= 1'b0;
6025
        wb_rmw[n] <= 1'b0;
6026
        wb_id[n] <= {QENTRIES{1'b0}};
6027
     end
6028
     wb_en <= `TRUE;
6029
     wbo_id <= {QENTRIES{1'b0}};
6030
`ifdef SIM
6031
                wb_merges <= 32'd0;
6032
`endif
6033 48 robfinch
end
6034
else begin
6035 49 robfinch
        if (|fb_panic)
6036
                panic <= fb_panic;
6037
        begin
6038
                branchmiss <= excmiss|fcu_branchmiss;
6039 51 robfinch
                misspc <= excmiss ? excmisspc : fcu_misspc;
6040
                missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
6041 49 robfinch
                branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
6042
        end
6043 48 robfinch
        // The following signals only pulse
6044
 
6045
        // Instruction decode output should only pulse once for a queue entry. We
6046
        // want the decode to be invalidated after a clock cycle so that it isn't
6047
        // inadvertently used to update the queue at a later point.
6048 57 robfinch
        dramA_v <= `INV;
6049
        dramB_v <= `INV;
6050
        dramC_v <= `INV;
6051 48 robfinch
        id1_vi <= `INV;
6052 49 robfinch
        if (`NUM_IDU > 1)
6053
                id2_vi <= `INV;
6054
        if (`NUM_IDU > 2)
6055
                id3_vi <= `INV;
6056
        if (iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]])
6057
                fcu_dataready <= `INV;
6058 52 robfinch
        wb_shift <= FALSE;
6059 48 robfinch
        ld_time <= {ld_time[4:0],1'b0};
6060
        wc_times <= wc_time;
6061
     rf_vra0 <= regIsValid[Ra0s];
6062
     rf_vra1 <= regIsValid[Ra1s];
6063
    if (vqe0 >= vl) begin
6064
         vqe0 <= 6'd0;
6065
         vqet0 <= 6'h0;
6066
    end
6067
    if (vqe1 >= vl) begin
6068
         vqe1 <= 6'd0;
6069
         vqet1 <= 6'h0;
6070
    end
6071
    // Turn off vector chaining indicator when chained instructions are done.
6072
    if ((vqe0 >= vl || vqe0==6'd0) && (vqe1 >= vl || vqe1==6'd0))
6073
`ifdef SUPPORT_SMT
6074
        mstatus[0][32] <= 1'b0;
6075
`else
6076
        mstatus[32] <= 1'b0;
6077
`endif
6078
 
6079
     nop_fetchbuf <= 4'h0;
6080
     excmiss <= FALSE;
6081
     invic <= FALSE;
6082
     tick <= tick + 64'd1;
6083
     alu0_ld <= FALSE;
6084
     alu1_ld <= FALSE;
6085 49 robfinch
     fpu1_ld <= FALSE;
6086
     fpu2_ld <= FALSE;
6087 48 robfinch
     fcu_ld <= FALSE;
6088
     dramA_v <= FALSE;
6089
     dramB_v <= FALSE;
6090
     dramC_v <= FALSE;
6091
     cr0[17] <= 1'b0;
6092
    if (waitctr != 64'd0)
6093
         waitctr <= waitctr - 64'd1;
6094
 
6095
 
6096 50 robfinch
    if (iqentry_fc[fcu_id[`QBITS]] && iqentry_v[fcu_id[`QBITS]] && !iqentry_done[fcu_id[`QBITS]] && iqentry_out[fcu_id[`QBITS]])
6097 48 robfinch
        fcu_timeout <= fcu_timeout + 8'd1;
6098
 
6099
        if (branchmiss) begin
6100
        for (n = 1; n < PREGS; n = n + 1)
6101
           if (~livetarget[n]) begin
6102
                        if (branchmiss_thrd) begin
6103
                                if (n >= 128)
6104
                                rf_v[n] <= `VAL;
6105
                        end
6106
                        else begin
6107
                                if (n < 128)
6108
                                rf_v[n] <= `VAL;
6109
                end
6110
           end
6111
 
6112 53 robfinch
                        for (n = 0; n < QENTRIES; n = n + 1)
6113
                if (|iqentry_latestID[n])
6114
                        if (iqentry_thrd[n]==branchmiss_thrd) rf_source[ {iqentry_tgt[n][7:0]} ] <= { 1'b0, iqentry_mem[n], n[3:0] };
6115 48 robfinch
 
6116
    end
6117
 
6118
    // The source for the register file data might have changed since it was
6119
    // placed on the commit bus. So it's needed to check that the source is
6120
    // still as expected to validate the register.
6121
        if (commit0_v) begin
6122
        if (!rf_v[ {commit0_tgt[7:0]} ])
6123
//             rf_v[ {commit0_tgt[7:0]} ] <= rf_source[ commit0_tgt[7:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]);
6124
             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] ]);
6125
        if (commit0_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit0_tgt, commit0_bus, regIsValid[commit0_tgt[5:0]],
6126
        rf_source[ {commit0_tgt[7:0]} ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]));
6127
        if (commit0_tgt[5:0]==6'd30 && commit0_bus==64'd0)
6128
                $display("FP <= 0");
6129
    end
6130 49 robfinch
    if (commit1_v && `NUM_CMT > 1) begin
6131 48 robfinch
        if (!rf_v[ {commit1_tgt[7:0]} ]) begin
6132
                if ({commit1_tgt[7:0]}=={commit0_tgt[7:0]})
6133
                         rf_v[ {commit1_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}];
6134
                        /*
6135
                                (rf_source[ commit0_tgt[4:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ])) ||
6136
                                (rf_source[ commit1_tgt[4:0] ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6137
                        */
6138
                else
6139
                 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] ]);
6140
        end
6141
        if (commit1_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit1_tgt, commit1_bus, regIsValid[commit1_tgt[5:0]],
6142
        rf_source[ {commit1_tgt[7:0]} ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6143
        if (commit1_tgt[5:0]==6'd30 && commit1_bus==64'd0)
6144
                $display("FP <= 0");
6145
    end
6146
     rf_v[0] <= 1;
6147
 
6148 49 robfinch
  //
6149
  // ENQUEUE
6150
  //
6151
  // place up to two instructions from the fetch buffer into slots in the IQ.
6152
  //   note: they are placed in-order, and they are expected to be executed
6153
  // 0, 1, or 2 of the fetch buffers may have valid data
6154
  // 0, 1, or 2 slots in the instruction queue may be available.
6155
  // if we notice that one of the instructions in the fetch buffer is a predicted branch,
6156
  // (set branchback/backpc and delete any instructions after it in fetchbuf)
6157
  //
6158 48 robfinch
 
6159
        // enqueue fetchbuf0 and fetchbuf1, but only if there is room, 
6160
        // and ignore fetchbuf1 if fetchbuf0 has a backwards branch in it.
6161
        //
6162
        // also, do some instruction-decode ... set the operand_valid bits in the IQ
6163
        // appropriately so that the DATAINCOMING stage does not have to look at the opcode
6164
        //
6165
        if (!branchmiss)        // don't bother doing anything if there's been a branch miss
6166
 
6167
                case ({fetchbuf0_v, fetchbuf1_v})
6168
 
6169
            2'b00: ; // do nothing
6170
 
6171
            2'b01:
6172
                    if (canq1) begin
6173 56 robfinch
          if (fetchbuf1_thrd)
6174
                seq_num1 <= seq_num1 + 5'd1;
6175
          else
6176
                seq_num <= seq_num + 5'd1;
6177
                                        if (fetchbuf1_rfw) begin
6178
                                                rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail0 };  // top bit indicates ALU/MEM bus
6179
                                                rf_v [Rt1s] <= `INV;
6180
                                        end
6181
                                        if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6182
                                                vqe1 <= vqe1 + 4'd1;
6183
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6184
                                                        if (vm[fetchbuf1_instr[25:23]][vqe1])
6185
                                                                vqet1 <= vqet1 + 4'd1;
6186
                                                end
6187
                                                else
6188
                                                        vqet1 <= vqet1 + 4'd1;
6189
                                                if (vqe1 >= vl-2)
6190
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6191
                                                enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, vqe1);
6192
                                                if (canq2 && vqe1 < vl-2) begin
6193
                                                        vqe1 <= vqe1 + 4'd2;
6194
                                                        if (IsVCmprss(fetchbuf1_instr)) begin
6195
                                                                if (vm[fetchbuf1_instr[25:23]][vqe1+6'd1])
6196
                                                                        vqet1 <= vqet1 + 4'd2;
6197
                                                        end
6198
                                                        else
6199
                                                                vqet1 <= vqet1 + 4'd2;
6200
                                                        enque1(tail1, fetchbuf1_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe1 + 6'd1);
6201
                                                        // Override the earlier udpate
6202
                                                        if (fetchbuf1_thrd)
6203
                                                                seq_num1 <= seq_num1 + 5'd2;
6204
                                                        else
6205
                                                                seq_num <= seq_num + 5'd2;
6206
                                                end
6207
                                        end
6208
                                        else begin
6209
                                                enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, 6'd0);
6210
                                        end
6211 48 robfinch
                    end
6212
 
6213
            2'b10:
6214
                if (canq1) begin
6215 55 robfinch
                        enque0x();
6216 48 robfinch
                    end
6217
 
6218
            2'b11:
6219
                    if (canq1) begin
6220
                                //
6221
                                // if the first instruction is a predicted branch, enqueue it & stomp on all following instructions
6222
                                // but only if the following instruction is in the same thread. Otherwise we want to queue two.
6223
                                //
6224
                                if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
6225 55 robfinch
                                        enque0x();
6226 48 robfinch
                                end
6227
 
6228
                                else begin      // fetchbuf0 doesn't contain a predicted branch
6229
                                    //
6230
                                    // so -- we can enqueue 1 or 2 instructions, depending on space in the IQ
6231
                                    // update the rf_v and rf_source bits separately (at end)
6232
                                    //   the problem is that if we do have two instructions, 
6233
                                    //   they may interact with each other, so we have to be
6234
                                    //   careful about where things point.
6235
                                    //
6236
                                    // enqueue the first instruction ...
6237
                                    //
6238
                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
6239
                                 vqe0 <= vqe0 + 4'd1;
6240
                                if (IsVCmprss(fetchbuf0_instr)) begin
6241
                                    if (vm[fetchbuf0_instr[25:23]][vqe0])
6242
                                         vqet0 <= vqet0 + 4'd1;
6243
                                end
6244
                                else
6245
                                     vqet0 <= vqet0 + 4'd1;
6246
                                if (vqe0 >= vl-2)
6247
                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6248
                            end
6249
                            if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
6250
                                    enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
6251
                                        if (fetchbuf0_thrd)
6252
                                                seq_num1 <= seq_num1 + 5'd1;
6253
                                        else
6254
                                                seq_num <= seq_num + 5'd1;
6255
                                            //
6256
                                            // if there is room for a second instruction, enqueue it
6257
                                            //
6258
                                            if (canq2) begin
6259
                                                if (vechain && IsVector(fetchbuf1_instr)
6260
                                                && Ra1s != Rt0s // And there is no dependency
6261
                                                && Rb1s != Rt0s
6262
                                                && Rc1s != Rt0s
6263
                                                ) begin
6264
`ifdef SUPPORT_SMT
6265
                                                        mstatus[0][32] <= 1'b1;
6266
`else
6267
                                                        mstatus[32] <= 1'b1;
6268
`endif
6269
                                                vqe1 <= vqe1 + 4'd1;
6270
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6271
                                                    if (vm[fetchbuf1_instr[25:23]][vqe1])
6272
                                                         vqet1 <= vqet1 + 4'd1;
6273
                                                end
6274
                                                else
6275
                                                     vqet1 <= vqet1 + 4'd1;
6276
                                                if (vqe1 >= vl-2)
6277
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6278
                                                        enque1(tail1,
6279
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6280
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6281
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
6282
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6283
                                                                if (fetchbuf1_thrd)
6284
                                                                        seq_num1 <= seq_num1 + 5'd2;
6285
                                                                else
6286
                                                                        seq_num <= seq_num + 5'd2;
6287
                                                        end
6288
                                                        else begin
6289
                                                                if (fetchbuf1_thrd)
6290
                                                                        seq_num1 <= seq_num1 + 5'd1;
6291
                                                                else
6292
                                                                        seq_num <= seq_num + 5'd1;
6293
                                                        end
6294
 
6295
                                                                // SOURCE 1 ...
6296 55 robfinch
                                                                a1_vs();
6297 48 robfinch
 
6298
                                                                // SOURCE 2 ...
6299 55 robfinch
                                                                a2_vs();
6300 48 robfinch
 
6301
                                                                // SOURCE 3 ...
6302 55 robfinch
                                                                a3_vs();
6303 48 robfinch
 
6304
                                                                // if the two instructions enqueued target the same register, 
6305
                                                                // make sure only the second writes to rf_v and rf_source.
6306
                                                                // first is allowed to update rf_v and rf_source only if the
6307
                                                                // second has no target
6308
                                                                //
6309
                                                            if (fetchbuf0_rfw) begin
6310
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6311
                                                                     rf_v [ Rt0s] <= `INV;
6312
                                                            end
6313
                                                            if (fetchbuf1_rfw) begin
6314
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6315
                                                                     rf_v [ Rt1s ] <= `INV;
6316
                                                            end
6317
                                                end
6318
                                                // If there was a vector instruction in fetchbuf0, we really
6319
                                                // want to queue the next vector element, not the next
6320
                                                // instruction waiting in fetchbuf1.
6321
                                            else if (IsVector(fetchbuf0_instr) && SUP_VECTOR && vqe0 < vl-1) begin
6322
                                                 vqe0 <= vqe0 + 4'd2;
6323
                                                if (IsVCmprss(fetchbuf0_instr)) begin
6324
                                                    if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
6325
                                                         vqet0 <= vqet0 + 4'd2;
6326
                                                end
6327
                                                else
6328
                                                     vqet0 <= vqet0 + 4'd2;
6329
                                                if (vqe0 >= vl-3)
6330
                                                 nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6331
                                            if (vqe0 < vl-1) begin
6332
                                                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe0 + 6'd1);
6333
                                                                if (fetchbuf0_thrd)
6334
                                                                        seq_num1 <= seq_num1 + 5'd2;
6335
                                                                else
6336
                                                                        seq_num <= seq_num + 5'd2;
6337
 
6338
                                                                        // SOURCE 1 ...
6339
                                                     iqentry_a1_v [tail1] <= regIsValid[Ra0s];
6340
                                                     iqentry_a1_s [tail1] <= rf_source [Ra0s];
6341
 
6342
                                                                        // SOURCE 2 ...
6343
                                                     iqentry_a2_v [tail1] <= regIsValid[Rb0s];
6344
                                                     iqentry_a2_s [tail1] <= rf_source[ Rb0s ];
6345
 
6346
                                                                        // SOURCE 3 ...
6347
                                                     iqentry_a3_v [tail1] <= regIsValid[Rc0s];
6348
                                                     iqentry_a3_s [tail1] <= rf_source[ Rc0s ];
6349
 
6350
                                                                        // if the two instructions enqueued target the same register, 
6351
                                                                        // make sure only the second writes to rf_v and rf_source.
6352
                                                                        // first is allowed to update rf_v and rf_source only if the
6353
                                                                        // second has no target (BEQ or SW)
6354
                                                                        //
6355
                                                                    if (fetchbuf0_rfw) begin
6356
                                                                             rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };
6357
                                                                             rf_v [ Rt0s ] <= `INV;
6358
                                                                    end
6359
                                                                end
6360
                                                end
6361
                                            else if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6362
                                                 vqe1 <= 6'd1;
6363
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6364
                                                    if (vm[fetchbuf1_instr[25:23]][IsVector(fetchbuf0_instr)? 6'd0:vqe1+6'd1])
6365
                                                         vqet1 <= 6'd1;
6366
                                                else
6367
                                                         vqet1 <= 6'd0;
6368
                                                end
6369
                                                else
6370
                                                         vqet1 <= 6'd1;
6371
                                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR)
6372
                                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6373
                                                        enque1(tail1,
6374
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6375
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6376
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
6377
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6378
                                                                if (fetchbuf1_thrd)
6379
                                                                        seq_num1 <= seq_num1 + 5'd2;
6380
                                                                else
6381
                                                                        seq_num <= seq_num + 5'd2;
6382
                                                        end
6383
                                                        else begin
6384
                                                                if (fetchbuf1_thrd)
6385
                                                                        seq_num1 <= seq_num1 + 5'd1;
6386
                                                                else
6387
                                                                        seq_num <= seq_num + 5'd1;
6388
                                                        end
6389
 
6390
                                                                // SOURCE 1 ...
6391 55 robfinch
                                                                a1_vs();
6392 48 robfinch
 
6393 55 robfinch
                                                                // SOURCE 2 ..
6394
                                                                a2_vs();
6395 48 robfinch
 
6396
                                                                // SOURCE 3 ...
6397 55 robfinch
                                                                a3_vs();
6398 48 robfinch
 
6399
                                                                // if the two instructions enqueued target the same register, 
6400
                                                                // make sure only the second writes to rf_v and rf_source.
6401
                                                                // first is allowed to update rf_v and rf_source only if the
6402
                                                                // second has no target
6403
                                                                //
6404
                                                            if (fetchbuf0_rfw) begin
6405
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6406
                                                                     rf_v [ Rt0s] <= `INV;
6407
                                                            end
6408
                                                            if (fetchbuf1_rfw) begin
6409
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6410
                                                                     rf_v [ Rt1s ] <= `INV;
6411
                                                            end
6412
                                            end
6413
                                            else begin
6414
//                                                      enque1(tail1, seq_num + 5'd1, 6'd0);
6415
                                                        enque1(tail1,
6416
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6417
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6418
                                                                fetchbuf1_thrd ? seq_num1: seq_num, 6'd0);
6419
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6420
                                                                if (fetchbuf1_thrd)
6421
                                                                        seq_num1 <= seq_num1 + 5'd2;
6422
                                                                else
6423
                                                                        seq_num <= seq_num + 5'd2;
6424
                                                        end
6425
                                                        else begin
6426
                                                                        seq_num1 <= seq_num1 + 5'd1;
6427
                                                                        seq_num <= seq_num + 5'd1;
6428
                                                        end
6429
 
6430
                                                                // SOURCE 1 ...
6431 55 robfinch
                                                                a1_vs();
6432 48 robfinch
 
6433
                                                                // SOURCE 2 ...
6434 55 robfinch
                                                                a2_vs();
6435 48 robfinch
 
6436
                                                                // SOURCE 3 ...
6437 55 robfinch
                                                                a3_vs();
6438 48 robfinch
 
6439
                                                                // if the two instructions enqueued target the same register, 
6440
                                                                // make sure only the second writes to regIsValid and rf_source.
6441
                                                                // first is allowed to update regIsValid and rf_source only if the
6442
                                                                // second has no target (BEQ or SW)
6443
                                                                //
6444
                                                            if (fetchbuf0_rfw) begin
6445
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6446
                                                                     rf_v [ Rt0s] <= `INV;
6447
                                                                     $display("r%dx (%d) Invalidated", Rt0s, Rt0s[4:0]);
6448
                                                            end
6449
                                                            else
6450
                                                                $display("No rfw");
6451
                                                            if (fetchbuf1_rfw) begin
6452
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6453
                                                                     $display("r%dx (%d) Invalidated", Rt1s, Rt1s[4:0]);
6454
                                                                     rf_v [ Rt1s ] <= `INV;
6455
                                                            end
6456
                                                            else
6457
                                                                $display("No rfw");
6458
                                                        end
6459
 
6460
                                            end // ends the "if IQ[tail1] is available" clause
6461
                                            else begin  // only first instruction was enqueued
6462
                                                        if (fetchbuf0_rfw) begin
6463
                                                             $display("r%dx (%d) Invalidated 1", Rt0s, Rt0s[4:0]);
6464
                                                             rf_source[ Rt0s ] <= {1'b0,fetchbuf0_memld, tail0};
6465
                                                             rf_v [ Rt0s ] <= `INV;
6466
                                                        end
6467
                                                end
6468
                                    end
6469
 
6470
                                end     // ends the "else fetchbuf0 doesn't have a backwards branch" clause
6471
                    end
6472
                endcase
6473
        if (pebm) begin
6474
                if (branchmiss_thrd==1'b0)
6475
                        seq_num <= seq_num + 5'd3;
6476
                else
6477
                        seq_num1 <= seq_num1 + 5'd3;
6478
        end
6479
 
6480
//
6481
// DATAINCOMING
6482
//
6483
// wait for operand/s to appear on alu busses and puts them into 
6484
// the iqentry_a1 and iqentry_a2 slots (if appropriate)
6485
// as well as the appropriate iqentry_res slots (and setting valid bits)
6486
//
6487
// put results into the appropriate instruction entries
6488
//
6489
// This chunk of code has to be before the enqueue stage so that the agen bit
6490
// can be reset to zero by enqueue.
6491
// put results into the appropriate instruction entries
6492
//
6493
if (IsMul(alu0_instr)|IsDivmod(alu0_instr)|alu0_shft48) begin
6494
        if (alu0_done) begin
6495
                alu0_dataready <= `TRUE;
6496
        end
6497
end
6498
 
6499
if (alu0_v) begin
6500
        iqentry_tgt [ alu0_id[`QBITS] ] <= alu0_tgt;
6501
        iqentry_res     [ alu0_id[`QBITS] ] <= alu0_bus;
6502
        iqentry_exc     [ alu0_id[`QBITS] ] <= alu0_exc;
6503
        iqentry_done[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
6504
        iqentry_cmt[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
6505
        iqentry_out     [ alu0_id[`QBITS] ] <= `INV;
6506
        iqentry_agen[ alu0_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
6507
        alu0_dataready <= FALSE;
6508
end
6509
 
6510 49 robfinch
if (alu1_v && `NUM_ALU > 1) begin
6511 48 robfinch
        iqentry_tgt [ alu1_id[`QBITS] ] <= alu1_tgt;
6512
        iqentry_res     [ alu1_id[`QBITS] ] <= alu1_bus;
6513
        iqentry_exc     [ alu1_id[`QBITS] ] <= alu1_exc;
6514
        iqentry_done[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
6515
        iqentry_cmt[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
6516
        iqentry_out     [ alu1_id[`QBITS] ] <= `INV;
6517
        iqentry_agen[ alu1_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
6518
        alu1_dataready <= FALSE;
6519
end
6520
 
6521 49 robfinch
if (fpu1_v) begin
6522 51 robfinch
        iqentry_res [ fpu1_id[`QBITS] ] <= fpu1_bus;
6523
        iqentry_a0  [ fpu1_id[`QBITS] ] <= fpu1_status;
6524
        iqentry_exc [ fpu1_id[`QBITS] ] <= fpu1_exc;
6525 49 robfinch
        iqentry_done[ fpu1_id[`QBITS] ] <= fpu1_done;
6526 51 robfinch
        iqentry_cmt     [ fpu1_id[`QBITS] ] <= fpu1_done;
6527
        iqentry_out [ fpu1_id[`QBITS] ] <= `INV;
6528 49 robfinch
        fpu1_dataready <= FALSE;
6529 48 robfinch
end
6530
 
6531 49 robfinch
if (fpu2_v && `NUM_FPU > 1) begin
6532 51 robfinch
        iqentry_res [ fpu2_id[`QBITS] ] <= fpu2_bus;
6533
        iqentry_a0  [ fpu2_id[`QBITS] ] <= fpu2_status;
6534
        iqentry_exc [ fpu2_id[`QBITS] ] <= fpu2_exc;
6535 49 robfinch
        iqentry_done[ fpu2_id[`QBITS] ] <= fpu2_done;
6536 51 robfinch
        iqentry_cmt [ fpu2_id[`QBITS] ] <= fpu2_done;
6537
        iqentry_out [ fpu2_id[`QBITS] ] <= `INV;
6538 49 robfinch
        //iqentry_agen[ fpu_id[`QBITS] ] <= `VAL;  // RET
6539
        fpu2_dataready <= FALSE;
6540
end
6541
 
6542 51 robfinch
if (fcu_wr & ~fcu_done) begin
6543
        fcu_done <= `TRUE;
6544
  if (fcu_ld)
6545
    waitctr <= fcu_argA;
6546
  iqentry_res [ fcu_id[`QBITS] ] <= fcu_bus;
6547
  iqentry_exc [ fcu_id[`QBITS] ] <= fcu_exc;
6548
  if (IsWait(fcu_instr)) begin
6549
                iqentry_done [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
6550
                iqentry_cmt [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
6551
  end
6552
  else begin
6553
                iqentry_done[ fcu_id[`QBITS] ] <= `TRUE;
6554
                iqentry_cmt[ fcu_id[`QBITS] ] <= `TRUE;
6555
  end
6556
        // Only safe place to propagate the miss pc is a0.
6557
        iqentry_a0[ fcu_id[`QBITS] ] <= fcu_misspc;
6558 55 robfinch
        // Update branch target update indicator.
6559 51 robfinch
        if (fcu_jal || fcu_ret || fcu_brk || fcu_rti) begin
6560
                iqentry_bt[ fcu_id[`QBITS] ] <= `VAL;
6561
        end
6562
// Branch target is only updated for branch-to-register
6563 52 robfinch
        else if (fcu_branch) begin
6564
                iqentry_takb[ fcu_id[`QBITS] ] <= fcu_takb;
6565
        end
6566 51 robfinch
        iqentry_out [ fcu_id[`QBITS] ] <= `INV;
6567
        //iqentry_agen[ fcu_id[`QBITS] ] <= `VAL;//!IsRet(fcu_instr);
6568
        fcu_dataready <= `VAL;
6569 48 robfinch
         //fcu_dataready <= fcu_branchmiss || !iqentry_agen[ fcu_id[`QBITS] ] || !(iqentry_mem[ fcu_id[`QBITS] ] && IsLoad(iqentry_instr[fcu_id[`QBITS]]));
6570
         //fcu_instr[`INSTRUCTION_OP] <= fcu_branchmiss|| (!IsMem(fcu_instr) && !IsWait(fcu_instr))? `NOP : fcu_instr[`INSTRUCTION_OP]; // to clear branchmiss
6571 51 robfinch
end
6572
// Clear a branch miss when target instruction is fetched.
6573
if (fcu_branchmiss) begin
6574
        if ((fetchbuf0_v && fetchbuf0_pc==misspc) ||
6575
                (fetchbuf1_v && fetchbuf1_pc==misspc))
6576
        fcu_clearbm <= `TRUE;
6577
end
6578
 
6579
if (mem1_available && dramA_v && iqentry_v[ dramA_id[`QBITS] ] && iqentry_load[ dramA_id[`QBITS] ]) begin
6580
        iqentry_res     [ dramA_id[`QBITS] ] <= dramA_bus;
6581
        iqentry_exc     [ dramA_id[`QBITS] ] <= dramA_exc;
6582
        iqentry_done[ dramA_id[`QBITS] ] <= `VAL;
6583
        iqentry_out [ dramA_id[`QBITS] ] <= `INV;
6584
        iqentry_cmt [ dramA_id[`QBITS] ] <= `VAL;
6585
        iqentry_aq  [ dramA_id[`QBITS] ] <= `INV;
6586
end
6587
if (mem2_available && `NUM_MEM > 1 && dramB_v && iqentry_v[ dramB_id[`QBITS] ] && iqentry_load[ dramB_id[`QBITS] ]) begin
6588
        iqentry_res     [ dramB_id[`QBITS] ] <= dramB_bus;
6589
        iqentry_exc     [ dramB_id[`QBITS] ] <= dramB_exc;
6590
        iqentry_done[ dramB_id[`QBITS] ] <= `VAL;
6591
        iqentry_out [ dramB_id[`QBITS] ] <= `INV;
6592
        iqentry_cmt [ dramB_id[`QBITS] ] <= `VAL;
6593
        iqentry_aq  [ dramB_id[`QBITS] ] <= `INV;
6594
end
6595
if (mem3_available && `NUM_MEM > 2 && dramC_v && iqentry_v[ dramC_id[`QBITS] ] && iqentry_load[ dramC_id[`QBITS] ]) begin
6596
        iqentry_res     [ dramC_id[`QBITS] ] <= dramC_bus;
6597
        iqentry_exc     [ dramC_id[`QBITS] ] <= dramC_exc;
6598
        iqentry_done[ dramC_id[`QBITS] ] <= `VAL;
6599
        iqentry_out [ dramC_id[`QBITS] ] <= `INV;
6600
        iqentry_cmt [ dramC_id[`QBITS] ] <= `VAL;
6601
        iqentry_aq  [ dramC_id[`QBITS] ] <= `INV;
6602 48 robfinch
//          if (iqentry_lptr[dram2_id[`QBITS]])
6603
//              wbrcd[pcr[5:0]] <= 1'b1;
6604 51 robfinch
end
6605 48 robfinch
 
6606
//
6607
// set the IQ entry == DONE as soon as the SW is let loose to the memory system
6608
//
6609 50 robfinch
if (mem1_available && dram0 == `DRAMSLOT_BUSY && dram0_store) begin
6610 48 robfinch
        if ((alu0_v && (dram0_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram0_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6611
        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
6612
        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
6613
end
6614 50 robfinch
if (mem2_available && `NUM_MEM > 1 && dram1 == `DRAMSLOT_BUSY && dram1_store) begin
6615 48 robfinch
        if ((alu0_v && (dram1_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram1_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6616
        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
6617
        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
6618
end
6619 50 robfinch
if (mem3_available && `NUM_MEM > 2 && dram2 == `DRAMSLOT_BUSY && dram2_store) begin
6620 48 robfinch
        if ((alu0_v && (dram2_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram2_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
6621
        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
6622
        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
6623
end
6624
 
6625
//
6626
// see if anybody else wants the results ... look at lots of buses:
6627
//  - fpu_bus
6628
//  - alu0_bus
6629
//  - alu1_bus
6630
//  - fcu_bus
6631
//  - dram_bus
6632
//  - commit0_bus
6633
//  - commit1_bus
6634
//
6635
 
6636
for (n = 0; n < QENTRIES; n = n + 1)
6637
begin
6638 49 robfinch
        if (`NUM_FPU > 0)
6639
                setargs(n,{1'b0,fpu1_id},fpu1_v,fpu1_bus);
6640
        if (`NUM_FPU > 1)
6641
                setargs(n,{1'b0,fpu2_id},fpu2_v,fpu2_bus);
6642
 
6643 48 robfinch
        setargs(n,{1'b0,alu0_id},alu0_v,alu0_bus);
6644 49 robfinch
        if (`NUM_ALU > 1)
6645
                setargs(n,{1'b0,alu1_id},alu1_v,alu1_bus);
6646
 
6647 48 robfinch
        setargs(n,{1'b0,fcu_id},fcu_wr,fcu_bus);
6648 49 robfinch
 
6649 48 robfinch
        setargs(n,{1'b0,dramA_id},dramA_v,dramA_bus);
6650 49 robfinch
        if (`NUM_MEM > 1)
6651
                setargs(n,{1'b0,dramB_id},dramB_v,dramB_bus);
6652
        if (`NUM_MEM > 2)
6653
                setargs(n,{1'b0,dramC_id},dramC_v,dramC_bus);
6654
 
6655 48 robfinch
        setargs(n,commit0_id,commit0_v,commit0_bus);
6656 49 robfinch
        if (`NUM_CMT > 1)
6657
                setargs(n,commit1_id,commit1_v,commit1_bus);
6658 48 robfinch
 
6659
        setinsn(n[`QBITS],id1_ido,id1_available&id1_vo,id1_bus);
6660 49 robfinch
        if (`NUM_IDU > 1)
6661
                setinsn(n[`QBITS],id2_ido,id2_available&id2_vo,id2_bus);
6662
        if (`NUM_IDU > 2)
6663
                setinsn(n[`QBITS],id3_ido,id3_available&id3_vo,id3_bus);
6664 48 robfinch
end
6665
 
6666
//
6667
// ISSUE 
6668
//
6669
// determines what instructions are ready to go, then places them
6670
// in the various ALU queues.  
6671
// also invalidates instructions following a branch-miss BEQ or any JALR (STOMP logic)
6672
//
6673
 
6674
for (n = 0; n < QENTRIES; n = n + 1)
6675
if (id1_available) begin
6676
if (iqentry_id1issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6677
                id1_vi <= `VAL;
6678
                id1_id                  <= n[4:0];
6679
                id1_instr       <= iqentry_rtop[n] ? (
6680
                                                                                iqentry_a3_v[n] ? iqentry_a3[n]
6681 49 robfinch
`ifdef FU_BYPASS
6682 48 robfinch
                                : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
6683
                                : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
6684 49 robfinch
`endif
6685 48 robfinch
                                : `NOP_INSN)
6686
                                                                 : iqentry_instr[n];
6687
                id1_ven    <= iqentry_ven[n];
6688
                id1_vl     <= iqentry_vl[n];
6689
                id1_thrd   <= iqentry_thrd[n];
6690
                id1_Rt     <= iqentry_tgt[n][4:0];
6691
                id1_pt                  <= iqentry_pt[n];
6692
  end
6693
end
6694 49 robfinch
if (`NUM_IDU > 1) begin
6695 48 robfinch
for (n = 0; n < QENTRIES; n = n + 1)
6696 49 robfinch
        if (id2_available) begin
6697
                if (iqentry_id2issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6698
                        id2_vi <= `VAL;
6699
                        id2_id                  <= n[4:0];
6700
                        id2_instr       <= iqentry_rtop[n] ? (
6701
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6702
`ifdef FU_BYPASS
6703
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
6704
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
6705
`endif
6706
                                        : `NOP_INSN)
6707
                                                                         : iqentry_instr[n];
6708
                        id2_ven    <= iqentry_ven[n];
6709
                        id2_vl     <= iqentry_vl[n];
6710
                        id2_thrd   <= iqentry_thrd[n];
6711
                        id2_Rt     <= iqentry_tgt[n][4:0];
6712
                        id2_pt                  <= iqentry_pt[n];
6713
                end
6714 48 robfinch
        end
6715
end
6716 49 robfinch
if (`NUM_IDU > 2) begin
6717
for (n = 0; n < QENTRIES; n = n + 1)
6718
        if (id3_available) begin
6719
                if (iqentry_id3issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6720
                        id3_vi <= `VAL;
6721
                        id3_id                  <= n[4:0];
6722
                        id3_instr       <= iqentry_rtop[n] ? (
6723
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6724
`ifdef FU_BYPASS
6725
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
6726
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
6727
`endif
6728
                                        : `NOP_INSN)
6729
                                                                         : iqentry_instr[n];
6730
                        id3_ven    <= iqentry_ven[n];
6731
                        id3_vl     <= iqentry_vl[n];
6732
                        id3_thrd   <= iqentry_thrd[n];
6733
                        id3_Rt     <= iqentry_tgt[n][4:0];
6734
                        id3_pt                  <= iqentry_pt[n];
6735
                end
6736
        end
6737
end
6738 48 robfinch
 
6739 53 robfinch
// X's on unused busses cause problems in SIM.
6740 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
6741
        if (iqentry_alu0_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6742
            if (alu0_available & alu0_done) begin
6743
                 alu0_sourceid  <= n[3:0];
6744
                 alu0_instr     <= iqentry_rtop[n] ? (
6745 49 robfinch
`ifdef FU_BYPASS
6746 48 robfinch
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6747 49 robfinch
                                                    : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
6748 53 robfinch
                                                    : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
6749 49 robfinch
                                                    : (iqentry_a3_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6750 53 robfinch
                                                    : `NOP_INSN)
6751 49 robfinch
`else
6752
                                                                                                                                        iqentry_a3[n])
6753
`endif
6754 48 robfinch
                                                                         : iqentry_instr[n];
6755
                 alu0_bt                <= iqentry_bt[n];
6756
                 alu0_mem   <= iqentry_mem[n];
6757
                 alu0_shft48 <= iqentry_shft48[n];
6758
                 alu0_pc                <= iqentry_pc[n];
6759 49 robfinch
                 alu0_argA      <=
6760
`ifdef FU_BYPASS
6761
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
6762
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
6763 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
6764 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6765 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
6766 49 robfinch
`else
6767
                                                                                                                iqentry_a1[n];
6768
`endif
6769 48 robfinch
                 alu0_argB      <= iqentry_imm[n]
6770
                            ? iqentry_a0[n]
6771 49 robfinch
`ifdef FU_BYPASS
6772 48 robfinch
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
6773 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
6774 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
6775 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6776 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
6777 49 robfinch
`else
6778
                                                                                                                : iqentry_a2[n];
6779
`endif
6780
                 alu0_argC      <=
6781
`ifdef FU_BYPASS
6782
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6783 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6784 49 robfinch
`else
6785
                                                                                                                        iqentry_a3[n];
6786
`endif
6787 48 robfinch
                 alu0_argI      <= iqentry_a0[n];
6788
                 alu0_tgt    <= IsVeins(iqentry_instr[n]) ?
6789 49 robfinch
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((
6790
                                                                                        iqentry_a2_v[n] ? iqentry_a2[n][5:0]
6791 48 robfinch
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
6792
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
6793
                                            : {4{16'h0000}})) << 6 :
6794
                                iqentry_tgt[n];
6795
                 alu0_ven    <= iqentry_ven[n];
6796
                 alu0_thrd   <= iqentry_thrd[n];
6797
                 alu0_dataready <= IsSingleCycle(iqentry_instr[n]);
6798
                 alu0_ld <= TRUE;
6799
                 iqentry_out[n] <= `VAL;
6800
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
6801
                if (iqentry_mem[n]) begin
6802
                 iqentry_a1_v[n] <= `INV;
6803
                 iqentry_a1_s[n] <= n[3:0];
6804
                end
6805
            end
6806
        end
6807 49 robfinch
        if (`NUM_ALU > 1) begin
6808 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
6809
        if (iqentry_alu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6810
            if (alu1_available && alu1_done) begin
6811
                        if (iqentry_alu0[n])
6812
                                panic <= `PANIC_ALU0ONLY;
6813
                 alu1_sourceid  <= n[3:0];
6814
                 alu1_instr     <= iqentry_instr[n];
6815
                 alu1_bt                <= iqentry_bt[n];
6816
                 alu1_mem   <= iqentry_mem[n];
6817
                 alu1_shft48 <= iqentry_shft48[n];
6818
                 alu1_pc                <= iqentry_pc[n];
6819 49 robfinch
                 alu1_argA      <=
6820
`ifdef FU_BYPASS
6821
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
6822
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
6823 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
6824 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6825 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
6826 49 robfinch
`else
6827
                                                                                                                        iqentry_a1[n];
6828
`endif
6829 48 robfinch
                 alu1_argB      <= iqentry_imm[n]
6830
                            ? iqentry_a0[n]
6831 49 robfinch
`ifdef FU_BYPASS
6832 48 robfinch
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
6833 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
6834 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
6835 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6836 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
6837 49 robfinch
`else
6838
                                                                                                                : iqentry_a2[n];
6839
`endif
6840
                 alu1_argC      <=
6841
`ifdef FU_BYPASS
6842
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
6843 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6844 49 robfinch
`else
6845
                                                                                                                        iqentry_a3[n];
6846
`endif
6847 48 robfinch
                 alu1_argI      <= iqentry_a0[n];
6848
                 alu1_tgt    <= IsVeins(iqentry_instr[n]) ?
6849
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((iqentry_a2_v[n] ? iqentry_a2[n][5:0]
6850
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
6851
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
6852
                                            : {4{16'h0000}})) << 6 :
6853
                                iqentry_tgt[n];
6854
                 alu1_ven    <= iqentry_ven[n];
6855
                 alu1_dataready <= IsSingleCycle(iqentry_instr[n]);
6856
                 alu1_ld <= TRUE;
6857
                 iqentry_out[n] <= `VAL;
6858
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
6859
                if (iqentry_mem[n]) begin
6860
                 iqentry_a1_v[n] <= `INV;
6861
                 iqentry_a1_s[n] <= n[3:0];
6862
                end
6863
            end
6864
        end
6865 49 robfinch
  end
6866 48 robfinch
 
6867
    for (n = 0; n < QENTRIES; n = n + 1)
6868 49 robfinch
        if (iqentry_fpu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6869
            if (fpu1_available & fpu1_done) begin
6870
                 fpu1_sourceid  <= n[3:0];
6871
                 fpu1_instr     <= iqentry_instr[n];
6872
                 fpu1_pc                <= iqentry_pc[n];
6873
                 fpu1_argA      <=
6874
`ifdef FU_BYPASS
6875
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
6876
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
6877 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
6878 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6879 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
6880 49 robfinch
`else
6881
                                                                                                                        iqentry_a1[n];
6882
`endif
6883
                 fpu1_argB      <=
6884
`ifdef FU_BYPASS
6885
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
6886
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
6887 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
6888 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6889 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
6890 49 robfinch
`else
6891
                                                                                                                        iqentry_a2[n];
6892
`endif
6893
                 fpu1_argC      <=
6894
`ifdef FU_BYPASS
6895
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
6896 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6897 49 robfinch
`else
6898
                                                                                                                        iqentry_a3[n];
6899
`endif
6900
                 fpu1_argI      <= iqentry_a0[n];
6901
                 fpu1_dataready <= `VAL;
6902
                 fpu1_ld <= TRUE;
6903 48 robfinch
                 iqentry_out[n] <= `VAL;
6904
            end
6905
        end
6906
 
6907
    for (n = 0; n < QENTRIES; n = n + 1)
6908 49 robfinch
        if (`NUM_FPU > 1 && iqentry_fpu2_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6909
            if (fpu2_available & fpu2_done) begin
6910
                 fpu2_sourceid  <= n[3:0];
6911
                 fpu2_instr     <= iqentry_instr[n];
6912
                 fpu2_pc                <= iqentry_pc[n];
6913
                 fpu2_argA      <=
6914
`ifdef FU_BYPASS
6915
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
6916
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
6917 53 robfinch
                            : (iqentry_a1_s[n] == alu1_id) ? alu1_bus
6918 49 robfinch
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6919 53 robfinch
                            : 64'hDEADDEADDEADDEAD;
6920 49 robfinch
`else
6921
                                                                                                                        iqentry_a1[n];
6922
`endif
6923
                 fpu2_argB      <=
6924
`ifdef FU_BYPASS
6925
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
6926
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
6927 53 robfinch
                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus
6928 49 robfinch
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6929 53 robfinch
                            : 64'hDEADDEADDEADDEAD);
6930 49 robfinch
`else
6931
                                                                                                                        iqentry_a2[n];
6932
`endif
6933
                 fpu2_argC      <=
6934
`ifdef FU_BYPASS
6935
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
6936
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6937
`else
6938
                                                                                                                        iqentry_a3[n];
6939
`endif
6940
                 fpu2_argI      <= iqentry_a0[n];
6941
                 fpu2_dataready <= `VAL;
6942
                 fpu2_ld <= TRUE;
6943
                 iqentry_out[n] <= `VAL;
6944
            end
6945
        end
6946
 
6947
    for (n = 0; n < QENTRIES; n = n + 1)
6948 48 robfinch
        if (iqentry_fcu_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
6949
            if (fcu_done) begin
6950
                 fcu_sourceid   <= n[3:0];
6951
                 fcu_instr      <= iqentry_instr[n];
6952
                 fcu_insln  <= iqentry_insln[n];
6953
                 fcu_pc         <= iqentry_pc[n];
6954
                 fcu_nextpc <= iqentry_pc[n] + iqentry_insln[n];
6955
                 fcu_brdisp <= {{52{iqentry_instr[n][31]}},iqentry_instr[n][31:21],1'b0};
6956 51 robfinch
                 fcu_branch <= iqentry_br[n];
6957
                 fcu_call    <= IsCall(iqentry_instr[n])|iqentry_jal[n];
6958
                 fcu_jal     <= iqentry_jal[n];
6959
                 fcu_ret    <= iqentry_ret[n];
6960
                 fcu_brk  <= iqentry_brk[n];
6961
                 fcu_rti  <= iqentry_rti[n];
6962 48 robfinch
                 fcu_bt         <= iqentry_bt[n];
6963
                 fcu_pc         <= iqentry_pc[n];
6964
                 fcu_argA       <= iqentry_a1_v[n] ? iqentry_a1[n]
6965 49 robfinch
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
6966
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6967
                            : alu1_bus;
6968 48 robfinch
`ifdef SUPPORT_SMT
6969 51 robfinch
                 fcu_argB       <= iqentry_rti[n] ? epc0[iqentry_thrd[n]]
6970 48 robfinch
`else
6971 51 robfinch
                 fcu_argB       <= iqentry_rti[n] ? epc0
6972 48 robfinch
`endif
6973
                                        : (iqentry_a2_v[n] ? iqentry_a2[n]
6974 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
6975
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
6976
                            : alu1_bus);
6977 48 robfinch
                 waitctr            <= iqentry_imm[n]
6978
                            ? iqentry_a0[n]
6979
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
6980
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus : alu1_bus);
6981
                 fcu_argC       <= iqentry_a3_v[n] ? iqentry_a3[n]
6982
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
6983
                 fcu_argI       <= iqentry_a0[n];
6984
                 fcu_thrd   <= iqentry_thrd[n];
6985
                 fcu_dataready <= `VAL;
6986
                 fcu_clearbm <= `FALSE;
6987
                 fcu_ld <= TRUE;
6988
                 fcu_timeout <= 8'h00;
6989
                 iqentry_out[n] <= `VAL;
6990
                 fcu_done <= `FALSE;
6991
            end
6992
        end
6993
//
6994
// MEMORY
6995
//
6996
// update the memory queues and put data out on bus if appropriate
6997
//
6998
 
6999
//
7000
// dram0, dram1, dram2 are the "state machines" that keep track
7001
// of three pipelined DRAM requests.  if any has the value "00", 
7002
// then it can accept a request (which bumps it up to the value "01"
7003
// at the end of the cycle).  once it hits the value "11" the request
7004
// is finished and the dram_bus takes the value.  if it is a store, the 
7005
// dram_bus value is not used, but the dram_v value along with the
7006
// dram_id value signals the waiting memq entry that the store is
7007
// completed and the instruction can commit.
7008
//
7009
 
7010
//      if (dram0 != `DRAMSLOT_AVAIL)   dram0 <= dram0 + 2'd1;
7011
//      if (dram1 != `DRAMSLOT_AVAIL)   dram1 <= dram1 + 2'd1;
7012
//      if (dram2 != `DRAMSLOT_AVAIL)   dram2 <= dram2 + 2'd1;
7013
 
7014
//
7015
// grab requests that have finished and put them on the dram_bus
7016 49 robfinch
if (mem1_available && dram0 == `DRAMREQ_READY) begin
7017 48 robfinch
        dram0 <= `DRAMSLOT_AVAIL;
7018
        dramA_v <= dram0_load;
7019
        dramA_id <= dram0_id;
7020
        dramA_exc <= dram0_exc;
7021
        dramA_bus <= fnDati(dram0_instr,dram0_addr,rdat0);
7022 50 robfinch
        if (dram0_store)        $display("m[%h] <- %h", dram0_addr, dram0_data);
7023 48 robfinch
end
7024
//    else
7025
//      dramA_v <= `INV;
7026 49 robfinch
if (mem2_available && dram1 == `DRAMREQ_READY && `NUM_MEM > 1) begin
7027 48 robfinch
        dram1 <= `DRAMSLOT_AVAIL;
7028
        dramB_v <= dram1_load;
7029
        dramB_id <= dram1_id;
7030
        dramB_exc <= dram1_exc;
7031
        dramB_bus <= fnDati(dram1_instr,dram1_addr,rdat1);
7032 50 robfinch
        if (dram1_store)     $display("m[%h] <- %h", dram1_addr, dram1_data);
7033 48 robfinch
end
7034
//    else
7035
//      dramB_v <= `INV;
7036 49 robfinch
if (mem3_available && dram2 == `DRAMREQ_READY && `NUM_MEM > 2) begin
7037 48 robfinch
        dram2 <= `DRAMSLOT_AVAIL;
7038
        dramC_v <= dram2_load;
7039
        dramC_id <= dram2_id;
7040
        dramC_exc <= dram2_exc;
7041
        dramC_bus <= fnDati(dram2_instr,dram2_addr,rdat2);
7042 50 robfinch
        if (dram2_store)     $display("m[%h] <- %h", dram2_addr, dram2_data);
7043 48 robfinch
end
7044
//    else
7045
//      dramC_v <= `INV;
7046
 
7047
        //
7048
        // determine if the instructions ready to issue can, in fact, issue.
7049
        // "ready" means that the instruction has valid operands but has not gone yet
7050
        iqentry_memissue <= memissue;
7051
        missue_count <= issue_count;
7052
 
7053
 
7054
        //
7055
        // take requests that are ready and put them into DRAM slots
7056
 
7057
        if (dram0 == `DRAMSLOT_AVAIL)    dram0_exc <= `FLT_NONE;
7058
        if (dram1 == `DRAMSLOT_AVAIL)    dram1_exc <= `FLT_NONE;
7059
        if (dram2 == `DRAMSLOT_AVAIL)    dram2_exc <= `FLT_NONE;
7060
 
7061
        for (n = 0; n < QENTRIES; n = n + 1)
7062
                if (iqentry_v[n] && iqentry_stomp[n]) begin
7063
                        iqentry_v[n] <= `INV;
7064
                        iqentry_iv[n] <= `INV;
7065
                        if (dram0_id[`QBITS] == n[`QBITS])  dram0 <= `DRAMSLOT_AVAIL;
7066
                        if (dram1_id[`QBITS] == n[`QBITS])  dram1 <= `DRAMSLOT_AVAIL;
7067
                        if (dram2_id[`QBITS] == n[`QBITS])  dram2 <= `DRAMSLOT_AVAIL;
7068
                end
7069
 
7070 53 robfinch
        last_issue = QENTRIES;
7071 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
7072 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7073
            if (mem1_available && dram0 == `DRAMSLOT_AVAIL) begin
7074 48 robfinch
                dramA_v <= `INV;
7075
             dram0              <= `DRAMSLOT_BUSY;
7076
             dram0_id   <= { 1'b1, n[`QBITS] };
7077
             dram0_instr <= iqentry_instr[n];
7078
             dram0_rmw  <= iqentry_rmw[n];
7079
             dram0_preload <= iqentry_preload[n];
7080
             dram0_tgt  <= iqentry_tgt[n];
7081
             dram0_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7082
             dram0_addr <= iqentry_a1[n];
7083
//             if (ol[iqentry_thrd[n]]==`OL_USER)
7084
//              dram0_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7085
//             else
7086 50 robfinch
             dram0_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7087
             dram0_memsize <= iqentry_memsz[n];
7088 48 robfinch
             dram0_load <= iqentry_load[n];
7089 50 robfinch
             dram0_store <= iqentry_store[n];
7090 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]];
7091
             // Once the memory op is issued reset the a1_v flag.
7092
             // This will cause the a1 bus to look for new data from memory (a1_s is pointed to a memory bus)
7093
             // This is used for the load and compare instructions.
7094
             iqentry_a1_v[n] <= `INV;
7095
             last_issue = n;
7096
            end
7097
        end
7098 53 robfinch
    if (last_issue < QENTRIES)
7099 48 robfinch
        iqentry_out[last_issue] <= `VAL;
7100
    for (n = 0; n < QENTRIES; n = n + 1)
7101 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7102
                if (mem2_available && n < last_issue && `NUM_MEM > 1) begin
7103 48 robfinch
                    if (dram1 == `DRAMSLOT_AVAIL) begin
7104
                        dramB_v <= `INV;
7105
                     dram1              <= `DRAMSLOT_BUSY;
7106
                     dram1_id   <= { 1'b1, n[`QBITS] };
7107
                     dram1_instr <= iqentry_instr[n];
7108
                     dram1_rmw  <= iqentry_rmw[n];
7109
                     dram1_preload <= iqentry_preload[n];
7110
                     dram1_tgt  <= iqentry_tgt[n];
7111
                     dram1_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7112
                     dram1_addr <= iqentry_a1[n];
7113
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
7114
//                      dram1_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7115
//                   else
7116 50 robfinch
                     dram1_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7117
                     dram1_memsize <= iqentry_memsz[n];
7118 48 robfinch
                     dram1_load <= iqentry_load[n];
7119 50 robfinch
                     dram1_store <= iqentry_store[n];
7120 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]];
7121
                     iqentry_a1_v[n] <= `INV;
7122
                     last_issue = n;
7123
                    end
7124
                end
7125
        end
7126 53 robfinch
    if (last_issue < QENTRIES)
7127 48 robfinch
        iqentry_out[last_issue] <= `VAL;
7128
    for (n = 0; n < QENTRIES; n = n + 1)
7129 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7130
                if (mem3_available && n < last_issue && `NUM_MEM > 2) begin
7131 48 robfinch
                    if (dram2 == `DRAMSLOT_AVAIL) begin
7132
                        dramC_v <= `INV;
7133
                     dram2              <= `DRAMSLOT_BUSY;
7134
                     dram2_id   <= { 1'b1, n[`QBITS] };
7135
                     dram2_instr        <= iqentry_instr[n];
7136
                     dram2_rmw  <= iqentry_rmw[n];
7137
                     dram2_preload <= iqentry_preload[n];
7138
                     dram2_tgt  <= iqentry_tgt[n];
7139
                     dram2_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7140
                     dram2_addr <= iqentry_a1[n];
7141
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
7142
//                      dram2_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7143
//                   else
7144 50 robfinch
                     dram2_unc   <= iqentry_a1[n][39:20]==20'hFFFFD || !dce || iqentry_loadv[n];
7145
                     dram2_memsize <= iqentry_memsz[n];
7146 48 robfinch
                     dram2_load <= iqentry_load[n];
7147 50 robfinch
                     dram2_store <= iqentry_store[n];
7148 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]];
7149
                     iqentry_a1_v[n] <= `INV;
7150
                    end
7151
                end
7152
        end
7153 53 robfinch
    if (last_issue < QENTRIES)
7154 48 robfinch
        iqentry_out[last_issue] <= `VAL;
7155
 
7156 51 robfinch
for (n = 0; n < QENTRIES; n = n + 1)
7157
begin
7158
        if (!iqentry_v[n])
7159
                iqentry_done[n] <= FALSE;
7160
end
7161 48 robfinch
 
7162
 
7163
 
7164 49 robfinch
//
7165
// COMMIT PHASE (dequeue only ... not register-file update)
7166
//
7167
// look at head0 and head1 and let 'em write to the register file if they are ready
7168
//
7169 48 robfinch
//    always @(posedge clk) begin: commit_phase
7170
 
7171 49 robfinch
oddball_commit(commit0_v, head0);
7172
if (`NUM_CMT > 1)
7173
        oddball_commit(commit1_v, head1);
7174 50 robfinch
//if (`NUM_CMT > 2)
7175
//      oddball_commit(commit2_v, head2);
7176 48 robfinch
 
7177
// Fetch and queue are limited to two instructions per cycle, so we might as
7178
// well limit retiring to two instructions max to conserve logic.
7179
//
7180
if (~|panic)
7181 49 robfinch
  casez ({ iqentry_v[head0],
7182
                iqentry_cmt[head0],
7183
                iqentry_v[head1],
7184
                iqentry_cmt[head1],
7185
                iqentry_v[head2],
7186
                iqentry_cmt[head2]})
7187 48 robfinch
 
7188
        // retire 3
7189 49 robfinch
        6'b0?_0?_0?:
7190
                if (head0 != tail0 && head1 != tail0 && head2 != tail0) begin
7191
                                head_inc(3);
7192
                end
7193
                else if (head0 != tail0 && head1 != tail0) begin
7194 48 robfinch
                    head_inc(2);
7195
                end
7196
                else if (head0 != tail0) begin
7197
                    head_inc(1);
7198
                end
7199 49 robfinch
        6'b0?_0?_10:    ;
7200
        6'b0?_0?_11:
7201
                if (`NUM_CMT > 2 || iqentry_tgt[head2][4:0]==5'd0) begin
7202
      iqentry_v[head2] <= `INV;
7203
      head_inc(3);
7204
                end
7205
                else begin
7206
      head_inc(2);
7207
                end
7208 48 robfinch
 
7209
        // retire 1 (wait for regfile for head1)
7210 49 robfinch
        6'b0?_10_??:
7211
                head_inc(1);
7212 48 robfinch
 
7213
        // retire 2
7214 49 robfinch
        6'b0?_11_0?,
7215
        6'b0?_11_10:
7216
        if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7217
          iqentry_v[head1] <= `INV;
7218
          head_inc(2);
7219 48 robfinch
        end
7220 49 robfinch
        else begin
7221
                head_inc(1);
7222
        end
7223
  6'b0?_11_11:
7224 50 robfinch
        if (`NUM_CMT > 2 || (`NUM_CMT > 1 && iqentry_tgt[head2] == 12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7225 49 robfinch
                iqentry_v[head1] <= `INV;
7226
          iqentry_v[head2] <= `INV;
7227
                head_inc(3);
7228
        end
7229
        else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7230
                iqentry_v[head1] <= `INV;
7231
                head_inc(2);
7232
        end
7233
        else
7234
                head_inc(1);
7235
  6'b10_??_??:  ;
7236
  6'b11_0?_0?:
7237
        if (head1 != tail0 && head2 != tail0) begin
7238 48 robfinch
                        iqentry_v[head0] <= `INV;
7239 49 robfinch
                        head_inc(3);
7240
        end
7241
        else if (head1 != tail0) begin
7242
                        iqentry_v[head0] <= `INV;
7243 48 robfinch
                        head_inc(2);
7244 49 robfinch
        end
7245
        else begin
7246 48 robfinch
                        iqentry_v[head0] <= `INV;
7247
                        head_inc(1);
7248 49 robfinch
        end
7249
  6'b11_0?_10:
7250
        if (head1 != tail0) begin
7251
                        iqentry_v[head0] <= `INV;
7252
                        head_inc(2);
7253
        end
7254
        else begin
7255
                        iqentry_v[head0] <= `INV;
7256
                        head_inc(1);
7257
        end
7258
  6'b11_0?_11:
7259
        if (head1 != tail0) begin
7260 50 robfinch
                if (`NUM_CMT > 2 || (iqentry_tgt[head2]==12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7261 49 robfinch
                                iqentry_v[head0] <= `INV;
7262
                                iqentry_v[head2] <= `INV;
7263
                                head_inc(3);
7264
                end
7265
                else begin
7266
                                iqentry_v[head0] <= `INV;
7267
                                head_inc(2);
7268
                        end
7269
        end
7270
        else begin
7271
                        iqentry_v[head0] <= `INV;
7272
                        head_inc(1);
7273
        end
7274
  6'b11_10_??:
7275
        begin
7276
                        iqentry_v[head0] <= `INV;
7277
                        head_inc(1);
7278
        end
7279
  6'b11_11_0?:
7280
        if (`NUM_CMT > 1 && head2 != tail0) begin
7281
                        iqentry_v[head0] <= `INV;
7282
                        iqentry_v[head1] <= `INV;
7283
                        head_inc(3);
7284
        end
7285
        else if (iqentry_tgt[head1]== 12'd0 && head2 != tail0) begin
7286
                        iqentry_v[head0] <= `INV;
7287
                        iqentry_v[head1] <= `INV;
7288
                        head_inc(3);
7289
        end
7290
        else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7291
                        iqentry_v[head0] <= `INV;
7292
                        iqentry_v[head1] <= `INV;
7293
                        head_inc(2);
7294
        end
7295
        else begin
7296
                        iqentry_v[head0] <= `INV;
7297
                        head_inc(1);
7298
        end
7299
  6'b11_11_10:
7300
        if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7301
                        iqentry_v[head0] <= `INV;
7302
                        iqentry_v[head1] <= `INV;
7303
                        head_inc(2);
7304
        end
7305
        else begin
7306
                        iqentry_v[head0] <= `INV;
7307
                        head_inc(1);
7308
        end
7309
        6'b11_11_11:
7310 50 robfinch
                if (`NUM_CMT > 2 || (`NUM_CMT > 1 && iqentry_tgt[head2]==12'd0 && !iqentry_oddball[head2] && ~|iqentry_exc[head2])) begin
7311 49 robfinch
                        iqentry_v[head0] <= `INV;
7312
                        iqentry_v[head1] <= `INV;
7313
                        iqentry_v[head2] <= `INV;
7314
                        head_inc(3);
7315 48 robfinch
                end
7316 49 robfinch
                else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7317 48 robfinch
                        iqentry_v[head0] <= `INV;
7318 49 robfinch
                        iqentry_v[head1] <= `INV;
7319
                        head_inc(2);
7320
                end
7321
                else begin
7322
                        iqentry_v[head0] <= `INV;
7323 48 robfinch
                        head_inc(1);
7324
                end
7325 49 robfinch
  endcase
7326 48 robfinch
 
7327
 
7328 55 robfinch
rf_source[0] <= 0;
7329
L1_wr0 <= FALSE;
7330
L1_wr1 <= FALSE;
7331
L1_wr2 <= FALSE;
7332
L1_invline <= FALSE;
7333
icnxt <= FALSE;
7334
L2_nxt <= FALSE;
7335 48 robfinch
// Instruction cache state machine.
7336
// On a miss first see if the instruction is in the L2 cache. No need to go to
7337
// the BIU on an L1 miss.
7338
// If not the machine will wait until the BIU loads the L2 cache.
7339
 
7340
// Capture the previous ic state, used to determine how long to wait in
7341
// icstate #4.
7342 55 robfinch
picstate <= icstate;
7343 48 robfinch
case(icstate)
7344
IDLE:
7345
        // If the bus unit is busy doing an update involving L1_adr or L2_adr
7346
        // we have to wait.
7347
        if (bstate != B7 && bstate != B9) begin
7348
                if (!ihit0) begin
7349 55 robfinch
                        L1_adr <= {pcr[5:0],pc0[31:5],5'h0};
7350
                        L2_adr <= {pcr[5:0],pc0[31:5],5'h0};
7351 48 robfinch
                        L1_invline <= TRUE;
7352 49 robfinch
                        icwhich <= 2'b00;
7353 48 robfinch
                        iccnt <= 3'b00;
7354
                        icstate <= IC2;
7355
                end
7356 49 robfinch
                else if (!ihit1 && `WAYS > 1) begin
7357 55 robfinch
                        if (thread_en) begin
7358
                                L1_adr <= {pcr[5:0],pc1[31:5],5'h0};
7359
                                L2_adr <= {pcr[5:0],pc1[31:5],5'h0};
7360
                        end
7361
                        else begin
7362
                                L1_adr <= {pcr[5:0],pc0plus6[31:5],5'h0};
7363
                                L2_adr <= {pcr[5:0],pc0plus6[31:5],5'h0};
7364
                        end
7365 48 robfinch
                        L1_invline <= TRUE;
7366 49 robfinch
                        icwhich <= 2'b01;
7367 48 robfinch
                        iccnt <= 3'b00;
7368
                        icstate <= IC2;
7369
                end
7370 49 robfinch
                else if (!ihit2 && `WAYS > 2) begin
7371 55 robfinch
                        if (thread_en) begin
7372
                                L1_adr <= {pcr[5:0],pc2[31:5],5'h0};
7373
                                L2_adr <= {pcr[5:0],pc2[31:5],5'h0};
7374
                        end
7375
                        else begin
7376
                                L1_adr <= {pcr[5:0],pc0plus12[31:5],5'h0};
7377
                                L2_adr <= {pcr[5:0],pc0plus12[31:5],5'h0};
7378
                        end
7379 49 robfinch
                        L1_invline <= TRUE;
7380
                        icwhich <= 2'b10;
7381
                        iccnt <= 3'b00;
7382
                        icstate <= IC2;
7383
                end
7384 48 robfinch
        end
7385
IC2:     icstate <= IC3;
7386
IC3:     icstate <= IC3a;
7387
IC3a:     icstate <= IC4;
7388
        // If data was in the L2 cache already there's no need to wait on the
7389
        // BIU to retrieve data. It can be determined if the hit signal was
7390
        // already active when this state was entered in which case waiting
7391
        // will do no good.
7392
        // The IC machine will stall in this state until the BIU has loaded the
7393
        // L2 cache. 
7394
IC4:
7395 49 robfinch
        if (ihitL2 && picstate==IC3a) begin
7396
                L1_en <= 9'h1FF;
7397 48 robfinch
                L1_wr0 <= TRUE;
7398 49 robfinch
                L1_wr1 <= TRUE && `WAYS > 1;
7399
                L1_wr2 <= TRUE && `WAYS > 2;
7400 48 robfinch
                L1_adr <= L2_adr;
7401
                L2_rdat <= L2_dato;
7402
                icstate <= IC5;
7403
        end
7404
        else if (bstate!=B9)
7405
                ;
7406
        else begin
7407 49 robfinch
                L1_en <= 9'h1FF;
7408 48 robfinch
                L1_wr0 <= TRUE;
7409 49 robfinch
                L1_wr1 <= TRUE && `WAYS > 1;
7410
                L1_wr2 <= TRUE && `WAYS > 2;
7411 48 robfinch
                L1_adr <= L2_adr;
7412
                L2_rdat <= L2_dato;
7413
                icstate <= IC5;
7414
        end
7415
IC5:
7416
        begin
7417 49 robfinch
                L1_en <= 9'h000;
7418 48 robfinch
                L1_wr0 <= FALSE;
7419
                L1_wr1 <= FALSE;
7420 49 robfinch
                L1_wr2 <= FALSE;
7421 48 robfinch
                icstate <= IC6;
7422
        end
7423
IC6:  icstate <= IC7;
7424
IC7:    icstate <= IC8;
7425
IC8:    begin
7426
             icstate <= IDLE;
7427
             icnxt <= TRUE;
7428
        end
7429
default:     icstate <= IDLE;
7430
endcase
7431
 
7432 49 robfinch
if (mem1_available && dram0_load)
7433 48 robfinch
case(dram0)
7434
`DRAMSLOT_AVAIL:        ;
7435
`DRAMSLOT_BUSY:         dram0 <= dram0 + !dram0_unc;
7436
3'd2:                           dram0 <= dram0 + 3'd1;
7437
3'd3:                           dram0 <= dram0 + 3'd1;
7438
3'd4:                           if (dhit0) dram0 <= `DRAMREQ_READY; else dram0 <= `DRAMSLOT_REQBUS;
7439
`DRAMSLOT_REQBUS:       ;
7440
`DRAMSLOT_HASBUS:       ;
7441
`DRAMREQ_READY:         ;
7442
endcase
7443
 
7444 49 robfinch
if (mem2_available && dram1_load && `NUM_MEM > 1)
7445 48 robfinch
case(dram1)
7446
`DRAMSLOT_AVAIL:        ;
7447
`DRAMSLOT_BUSY:         dram1 <= dram1 + !dram1_unc;
7448
3'd2:                           dram1 <= dram1 + 3'd1;
7449
3'd3:                           dram1 <= dram1 + 3'd1;
7450
3'd4:                           if (dhit1) dram1 <= `DRAMREQ_READY; else dram1 <= `DRAMSLOT_REQBUS;
7451
`DRAMSLOT_REQBUS:       ;
7452
`DRAMSLOT_HASBUS:       ;
7453
`DRAMREQ_READY:         ;
7454
endcase
7455
 
7456 49 robfinch
if (mem3_available && dram2_load && `NUM_MEM > 2)
7457 48 robfinch
case(dram2)
7458
`DRAMSLOT_AVAIL:        ;
7459
`DRAMSLOT_BUSY:         dram2 <= dram2 + !dram2_unc;
7460
3'd2:                           dram2 <= dram2 + 3'd1;
7461
3'd3:                           dram2 <= dram2 + 3'd1;
7462
3'd4:                           if (dhit2) dram2 <= `DRAMREQ_READY; else dram2 <= `DRAMSLOT_REQBUS;
7463
`DRAMSLOT_REQBUS:       ;
7464
`DRAMSLOT_HASBUS:       ;
7465
`DRAMREQ_READY:         ;
7466
endcase
7467
 
7468
// Bus Interface Unit (BIU)
7469
// Interfaces to the external bus which is WISHBONE compatible.
7470
// Stores take precedence over other operations.
7471
// Next data cache read misses are serviced.
7472
// Uncached data reads are serviced.
7473
// Finally L2 instruction cache misses are serviced.
7474
 
7475
case(bstate)
7476
BIDLE:
7477 49 robfinch
        begin
7478
                isCAS <= FALSE;
7479
                isAMO <= FALSE;
7480
                isInc <= FALSE;
7481
                isSpt <= FALSE;
7482
                isRMW <= FALSE;
7483
                rdvq <= 1'b0;
7484
                errq <= 1'b0;
7485
                exvq <= 1'b0;
7486
                bwhich <= 2'b00;
7487
                preload <= FALSE;
7488
`ifdef HAS_WB
7489
                if (wb_v[0] & wb_en) begin
7490
                        cyc_o <= `HIGH;
7491
                        stb_o <= `HIGH;
7492
                        we_o <= `HIGH;
7493
                        sel_o <= wb_sel[0];
7494
                        adr_o <= wb_addr[0];
7495
                        dat_o <= wb_data[0];
7496
                        ol_o  <= wb_ol[0];
7497
                        wbo_id <= wb_id[0];
7498 57 robfinch
        isStore <= TRUE;
7499 49 robfinch
                        bstate <= wb_rmw[0] ? B12 : B1;
7500
                end
7501
                begin
7502
                        for (j = 1; j < `WB_DEPTH; j = j + 1) begin
7503
                wb_v[j-1] <= wb_v[j];
7504
                wb_id[j-1] <= wb_id[j];
7505
                wb_rmw[j-1] <= wb_rmw[j];
7506
                wb_sel[j-1] <= wb_sel[j];
7507
                wb_addr[j-1] <= wb_addr[j];
7508
                wb_data[j-1] <= wb_data[j];
7509
                wb_ol[j-1] <= wb_ol[j];
7510
        end
7511
        wb_v[`WB_DEPTH-1] <= `INV;
7512
        wb_rmw[`WB_DEPTH-1] <= `FALSE;
7513
    end
7514
 
7515
`endif
7516
      if (~|wb_v && mem1_available && dram0==`DRAMSLOT_BUSY && dram0_rmw) begin
7517 48 robfinch
`ifdef SUPPORT_DBG
7518
            if (dbg_smatch0|dbg_lmatch0) begin
7519
                 dramA_v <= `TRUE;
7520
                 dramA_id <= dram0_id;
7521
                 dramA_exc <= `FLT_DBG;
7522
                 dramA_bus <= 64'h0;
7523
                 dram0 <= `DRAMSLOT_AVAIL;
7524
            end
7525
            else
7526
`endif
7527
            begin
7528
                 isRMW <= dram0_rmw;
7529
                 isCAS <= IsCAS(dram0_instr);
7530
                 isAMO <= IsAMO(dram0_instr);
7531
                 isInc <= IsInc(dram0_instr);
7532
                 casid <= dram0_id;
7533
                 bwhich <= 2'b00;
7534 49 robfinch
                 dram0 <= `DRAMSLOT_HASBUS;
7535 48 robfinch
                 cyc_o <= `HIGH;
7536
                 stb_o <= `HIGH;
7537
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7538
                 adr_o <= dram0_addr;
7539
                 dat_o <= fnDato(dram0_instr,dram0_data);
7540
                 ol_o  <= dram0_ol;
7541
                 bstate <= B12;
7542
            end
7543
        end
7544 49 robfinch
        else if (~|wb_v && mem2_available && dram1==`DRAMSLOT_BUSY && dram1_rmw && `NUM_MEM > 1) begin
7545 48 robfinch
`ifdef SUPPORT_DBG
7546
            if (dbg_smatch1|dbg_lmatch1) begin
7547
                 dramB_v <= `TRUE;
7548
                 dramB_id <= dram1_id;
7549
                 dramB_exc <= `FLT_DBG;
7550
                 dramB_bus <= 64'h0;
7551
                 dram1 <= `DRAMSLOT_AVAIL;
7552
            end
7553
            else
7554
`endif
7555
            begin
7556
                 isRMW <= dram1_rmw;
7557
                 isCAS <= IsCAS(dram1_instr);
7558
                 isAMO <= IsAMO(dram1_instr);
7559
                 isInc <= IsInc(dram1_instr);
7560
                 casid <= dram1_id;
7561
                 bwhich <= 2'b01;
7562 49 robfinch
                 dram1 <= `DRAMSLOT_HASBUS;
7563 48 robfinch
                 cyc_o <= `HIGH;
7564
                 stb_o <= `HIGH;
7565
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7566
                 adr_o <= dram1_addr;
7567
                 dat_o <= fnDato(dram1_instr,dram1_data);
7568
                 ol_o  <= dram1_ol;
7569
                 bstate <= B12;
7570
            end
7571
        end
7572 49 robfinch
        else if (~|wb_v && mem3_available && dram2==`DRAMSLOT_BUSY && dram2_rmw && `NUM_MEM > 2) begin
7573 48 robfinch
`ifdef SUPPORT_DBG
7574
            if (dbg_smatch2|dbg_lmatch2) begin
7575
                 dramC_v <= `TRUE;
7576
                 dramC_id <= dram2_id;
7577
                 dramC_exc <= `FLT_DBG;
7578
                 dramC_bus <= 64'h0;
7579
                 dram2 <= `DRAMSLOT_AVAIL;
7580
            end
7581
            else
7582
`endif
7583
            begin
7584
                 isRMW <= dram2_rmw;
7585
                 isCAS <= IsCAS(dram2_instr);
7586
                 isAMO <= IsAMO(dram2_instr);
7587
                 isInc <= IsInc(dram2_instr);
7588
                 casid <= dram2_id;
7589
                 bwhich <= 2'b10;
7590 49 robfinch
                 dram2 <= `DRAMSLOT_HASBUS;
7591 48 robfinch
                 cyc_o <= `HIGH;
7592
                 stb_o <= `HIGH;
7593
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
7594
                 adr_o <= dram2_addr;
7595
                 dat_o <= fnDato(dram2_instr,dram2_data);
7596
                 ol_o  <= dram2_ol;
7597
                 bstate <= B12;
7598
            end
7599
        end
7600 50 robfinch
        else if (mem1_available && dram0==`DRAMSLOT_BUSY && dram0_store) begin
7601 48 robfinch
`ifdef SUPPORT_DBG
7602
            if (dbg_smatch0) begin
7603
                 dramA_v <= `TRUE;
7604
                 dramA_id <= dram0_id;
7605
                 dramA_exc <= `FLT_DBG;
7606
                 dramA_bus <= 64'h0;
7607
                 dram0 <= `DRAMSLOT_AVAIL;
7608
            end
7609
            else
7610
`endif
7611
            begin
7612 49 robfinch
                                                        bwhich <= 2'b00;
7613
`ifndef HAS_WB
7614
                                                        dram0 <= `DRAMSLOT_HASBUS;
7615
                                                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
7616
                 cyc_o <= `HIGH;
7617
                 stb_o <= `HIGH;
7618 48 robfinch
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7619
                 adr_o <= dram0_addr;
7620
                 dat_o <= fnDato(dram0_instr,dram0_data);
7621
                 ol_o  <= dram0_ol;
7622 57 robfinch
                                        isStore <= TRUE;
7623 48 robfinch
                 bstate <= B1;
7624 49 robfinch
`else
7625
                                                                if (wbptr<`WB_DEPTH-1) begin
7626
                                                                        dram0 <= `DRAMREQ_READY;
7627
                                                                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
7628
                                                                        wb_update(
7629
                                                                                dram0_id,
7630
                                                                                `FALSE,
7631
                                                                                fnSelect(dram0_instr,dram0_addr),
7632
                                                                                dram0_ol,
7633
                                                                                dram0_addr,
7634
                                                                                fnDato(dram0_instr,dram0_data)
7635
                                                                        );
7636
                                                                        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
7637
                                                                        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
7638
                                                                end
7639
`endif
7640
//                 cr_o <= IsSWC(dram0_instr);
7641 48 robfinch
            end
7642
        end
7643 50 robfinch
        else if (mem2_available && dram1==`DRAMSLOT_BUSY && dram1_store && `NUM_MEM > 1) begin
7644 48 robfinch
`ifdef SUPPORT_DBG
7645
            if (dbg_smatch1) begin
7646
                 dramB_v <= `TRUE;
7647
                 dramB_id <= dram1_id;
7648
                 dramB_exc <= `FLT_DBG;
7649
                 dramB_bus <= 64'h0;
7650
                 dram1 <= `DRAMSLOT_AVAIL;
7651
            end
7652
            else
7653
`endif
7654
            begin
7655 49 robfinch
                 bwhich <= 2'b01;
7656
`ifndef HAS_WB
7657 48 robfinch
                 dram1 <= `DRAMSLOT_HASBUS;
7658
                 dram1_instr[`INSTRUCTION_OP] <= `NOP;
7659 49 robfinch
                 cyc_o <= `HIGH;
7660
                 stb_o <= `HIGH;
7661 48 robfinch
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7662
                 adr_o <= dram1_addr;
7663
                 dat_o <= fnDato(dram1_instr,dram1_data);
7664
                 ol_o  <= dram1_ol;
7665 57 robfinch
                                        isStore <= TRUE;
7666 48 robfinch
                 bstate <= B1;
7667 49 robfinch
`else
7668
                                                                if (wbptr<`WB_DEPTH-1) begin
7669
                                                                        dram1 <= `DRAMREQ_READY;
7670
                        dram1_instr[`INSTRUCTION_OP] <= `NOP;
7671
                                                                        wb_update(
7672
                                                                                dram1_id,
7673
                                                                                `FALSE,
7674
                                                                                fnSelect(dram1_instr,dram1_addr),
7675
                                                                                dram1_ol,
7676
                                                                                dram1_addr,
7677
                                                                                fnDato(dram1_instr,dram1_data)
7678
                                                                        );
7679
                                                                        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
7680
                                                                        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
7681
                                                                end
7682
`endif
7683
//                 cr_o <= IsSWC(dram0_instr);
7684 48 robfinch
            end
7685
        end
7686 50 robfinch
        else if (mem3_available && dram2==`DRAMSLOT_BUSY && dram2_store && `NUM_MEM > 2) begin
7687 48 robfinch
`ifdef SUPPORT_DBG
7688
            if (dbg_smatch2) begin
7689
                 dramC_v <= `TRUE;
7690
                 dramC_id <= dram2_id;
7691
                 dramC_exc <= `FLT_DBG;
7692
                 dramC_bus <= 64'h0;
7693
                 dram2 <= `DRAMSLOT_AVAIL;
7694
            end
7695
            else
7696
`endif
7697
            begin
7698 49 robfinch
                 bwhich <= 2'b10;
7699
`ifndef HAS_WB
7700 48 robfinch
                 dram2 <= `DRAMSLOT_HASBUS;
7701
                 dram2_instr[`INSTRUCTION_OP] <= `NOP;
7702 49 robfinch
                 cyc_o <= `HIGH;
7703
                 stb_o <= `HIGH;
7704 48 robfinch
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
7705
                 adr_o <= dram2_addr;
7706
                 dat_o <= fnDato(dram2_instr,dram2_data);
7707
                 ol_o  <= dram2_ol;
7708 57 robfinch
                                        isStore <= TRUE;
7709 48 robfinch
                 bstate <= B1;
7710 49 robfinch
`else
7711
                                                                if (wbptr<`WB_DEPTH-1) begin
7712
                                                                        dram2 <= `DRAMREQ_READY;
7713
                        dram2_instr[`INSTRUCTION_OP] <= `NOP;
7714
                                                                        wb_update(
7715
                                                                                dram2_id,
7716
                                                                                `FALSE,
7717
                                                                                fnSelect(dram2_instr,dram2_addr),
7718
                                                                                dram2_ol,
7719
                                                                                dram2_addr,
7720
                                                                                fnDato(dram2_instr,dram2_data)
7721
                                                                        );
7722
                                                                        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
7723
                                                                        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
7724
                                                                end
7725
`endif
7726
//                 cr_o <= IsSWC(dram0_instr);
7727 48 robfinch
            end
7728
        end
7729
        // Check for read misses on the data cache
7730 51 robfinch
        else if (~|wb_v && mem1_available && !dram0_unc && dram0==`DRAMSLOT_REQBUS && dram0_load) begin
7731 48 robfinch
`ifdef SUPPORT_DBG
7732
            if (dbg_lmatch0) begin
7733
                 dramA_v <= `TRUE;
7734
                 dramA_id <= dram0_id;
7735
                 dramA_exc <= `FLT_DBG;
7736
                 dramA_bus <= 64'h0;
7737
                 dram0 <= `DRAMSLOT_AVAIL;
7738
            end
7739
            else
7740
`endif
7741
            begin
7742
                 dram0 <= `DRAMSLOT_HASBUS;
7743
                 bwhich <= 2'b00;
7744
                 preload <= dram0_preload;
7745
                 bstate <= B2;
7746
            end
7747
        end
7748 49 robfinch
        else if (~|wb_v && mem2_available && !dram1_unc && dram1==`DRAMSLOT_REQBUS && dram1_load && `NUM_MEM > 1) begin
7749 48 robfinch
`ifdef SUPPORT_DBG
7750
            if (dbg_lmatch1) begin
7751
                 dramB_v <= `TRUE;
7752
                 dramB_id <= dram1_id;
7753
                 dramB_exc <= `FLT_DBG;
7754
                 dramB_bus <= 64'h0;
7755
                 dram1 <= `DRAMSLOT_AVAIL;
7756
            end
7757
            else
7758
`endif
7759
            begin
7760
                 dram1 <= `DRAMSLOT_HASBUS;
7761
                 bwhich <= 2'b01;
7762
                 preload <= dram1_preload;
7763
                 bstate <= B2;
7764
            end
7765
        end
7766 49 robfinch
        else if (~|wb_v && mem3_available && !dram2_unc && dram2==`DRAMSLOT_REQBUS && dram2_load && `NUM_MEM > 2) begin
7767 48 robfinch
`ifdef SUPPORT_DBG
7768
            if (dbg_lmatch2) begin
7769
                 dramC_v <= `TRUE;
7770
                 dramC_id <= dram2_id;
7771
                 dramC_exc <= `FLT_DBG;
7772
                 dramC_bus <= 64'h0;
7773
                 dram2 <= `DRAMSLOT_AVAIL;
7774
            end
7775
            else
7776
`endif
7777
            begin
7778
                 dram2 <= `DRAMSLOT_HASBUS;
7779
                 preload <= dram2_preload;
7780
                 bwhich <= 2'b10;
7781
                 bstate <= B2;
7782
            end
7783
        end
7784 49 robfinch
        else if (~|wb_v && mem1_available && dram0_unc && dram0==`DRAMSLOT_BUSY && dram0_load) begin
7785 48 robfinch
`ifdef SUPPORT_DBG
7786
            if (dbg_lmatch0) begin
7787
                 dramA_v <= `TRUE;
7788
                 dramA_id <= dram0_id;
7789
                 dramA_exc <= `FLT_DBG;
7790
                 dramA_bus <= 64'h0;
7791
                 dram0 <= `DRAMSLOT_AVAIL;
7792
            end
7793
            else
7794
`endif
7795
            begin
7796
                 bwhich <= 2'b00;
7797
                 cyc_o <= `HIGH;
7798
                 stb_o <= `HIGH;
7799
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7800
                 adr_o <= {dram0_addr[31:3],3'b0};
7801
                 sr_o <=  IsLWR(dram0_instr);
7802
                 ol_o  <= dram0_ol;
7803
                 bstate <= B12;
7804
            end
7805
        end
7806 49 robfinch
        else if (~|wb_v && mem2_available && dram1_unc && dram1==`DRAMSLOT_BUSY && dram1_load && `NUM_MEM > 1) begin
7807 48 robfinch
`ifdef SUPPORT_DBG
7808
            if (dbg_lmatch1) begin
7809
                 dramB_v <= `TRUE;
7810
                 dramB_id <= dram1_id;
7811
                 dramB_exc <= `FLT_DBG;
7812
                 dramB_bus <= 64'h0;
7813
                 dram1 <= `DRAMSLOT_AVAIL;
7814
            end
7815
            else
7816
`endif
7817
            begin
7818
                 bwhich <= 2'b01;
7819
                 cyc_o <= `HIGH;
7820
                 stb_o <= `HIGH;
7821
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7822
                 adr_o <= {dram1_addr[31:3],3'b0};
7823
                 sr_o <=  IsLWR(dram1_instr);
7824
                 ol_o  <= dram1_ol;
7825
                 bstate <= B12;
7826
            end
7827
        end
7828 49 robfinch
        else if (~|wb_v && mem3_available && dram2_unc && dram2==`DRAMSLOT_BUSY && dram2_load && `NUM_MEM > 2) begin
7829 48 robfinch
`ifdef SUPPORT_DBG
7830
            if (dbg_lmatch2) begin
7831
                 dramC_v <= `TRUE;
7832
                 dramC_id <= dram2_id;
7833
                 dramC_exc <= `FLT_DBG;
7834
                 dramC_bus <= 64'h0;
7835
                 dram2 <= 2'd0;
7836
            end
7837
            else
7838
`endif
7839
            begin
7840
                 bwhich <= 2'b10;
7841
                 cyc_o <= `HIGH;
7842
                 stb_o <= `HIGH;
7843
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
7844
                 adr_o <= {dram2_addr[31:3],3'b0};
7845
                 sr_o <=  IsLWR(dram2_instr);
7846
                 ol_o  <= dram2_ol;
7847
                 bstate <= B12;
7848
            end
7849
        end
7850
        // Check for L2 cache miss
7851 49 robfinch
        else if (~|wb_v && !ihitL2) begin
7852 48 robfinch
             cti_o <= 3'b001;
7853 49 robfinch
             bte_o <= 2'b00;//2'b01;    // 4 beat burst wrap
7854 48 robfinch
             cyc_o <= `HIGH;
7855
             stb_o <= `HIGH;
7856
             sel_o <= 8'hFF;
7857
             icl_o <= `HIGH;
7858 49 robfinch
             iccnt <= 3'd0;
7859 48 robfinch
//            adr_o <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
7860
//            L2_adr <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
7861
             adr_o <= {pcr[5:0],L1_adr[31:5],5'h0};
7862
             ol_o  <= ol[0];
7863
             L2_adr <= {pcr[5:0],L1_adr[31:5],5'h0};
7864
             L2_xsel <= 1'b0;
7865
             bstate <= B7;
7866
        end
7867
    end
7868
// Terminal state for a store operation.
7869 49 robfinch
// Note that if only a single memory channel is selected, bwhich will be a
7870
// constant 0. This should cause the extra code to be removed.
7871 48 robfinch
B1:
7872
    if (acki|err_i) begin
7873
         isStore <= `TRUE;
7874
         cyc_o <= `LOW;
7875
         stb_o <= `LOW;
7876
         we_o <= `LOW;
7877
         cr_o <= 1'b0;
7878
        // This isn't a good way of doing things; the state should be propagated
7879
        // to the commit stage, however since this is a store we know there will
7880
        // be no change of program flow. So the reservation status bit is set
7881
        // here. The author wanted to avoid the complexity of propagating the
7882
        // input signal to the commit stage. It does mean that the SWC
7883
        // instruction should be surrounded by SYNC's.
7884
        if (cr_o)
7885
             sema[0] <= rbi_i;
7886 49 robfinch
`ifdef HAS_WB
7887
                                for (n = 0; n < QENTRIES; n = n + 1) begin
7888
                                        if (wbo_id[n]) begin
7889
                        iqentry_exc[n] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7890
                        if (err_i|wrv_i) begin
7891
                                iqentry_a1[n] <= adr_o;
7892
                                wb_v <= 8'h00;          // Invalidate write buffer if there is a problem with the store
7893
                                wb_en <= `FALSE;        // and disable write buffer
7894
                        end
7895
                                                iqentry_cmt[n] <= `VAL;
7896
                                                iqentry_aq[n] <= `INV;
7897
                                        end
7898
                                end
7899
`else
7900 48 robfinch
        case(bwhich)
7901 49 robfinch
        2'd0:   if (mem1_available) begin
7902 48 robfinch
                 dram0 <= `DRAMREQ_READY;
7903
                 iqentry_exc[dram0_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7904
                if (err_i|wrv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
7905 49 robfinch
                                                                        iqentry_cmt[ dram0_id[`QBITS] ] <= `VAL;
7906
                                                                        iqentry_aq[ dram0_id[`QBITS] ] <= `INV;
7907 48 robfinch
                        //iqentry_out[ dram0_id[`QBITS] ] <= `INV;
7908
                end
7909 49 robfinch
        2'd1:   if (`NUM_MEM > 1) begin
7910 48 robfinch
                 dram1 <= `DRAMREQ_READY;
7911
                 iqentry_exc[dram1_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7912
                if (err_i|wrv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
7913 49 robfinch
                                                                        iqentry_cmt[ dram1_id[`QBITS] ] <= `VAL;
7914
                                                                        iqentry_aq[ dram1_id[`QBITS] ] <= `INV;
7915 48 robfinch
                        //iqentry_out[ dram1_id[`QBITS] ] <= `INV;
7916
                end
7917 49 robfinch
        2'd2:   if (`NUM_MEM > 2) begin
7918 48 robfinch
                 dram2 <= `DRAMREQ_READY;
7919
                 iqentry_exc[dram2_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
7920
                if (err_i|wrv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
7921 49 robfinch
                                                                        iqentry_cmt[ dram2_id[`QBITS] ] <= `VAL;
7922
                                                                        iqentry_aq[ dram2_id[`QBITS] ] <= `INV;
7923 48 robfinch
                        //iqentry_out[ dram2_id[`QBITS] ] <= `INV;
7924
                end
7925
        default:    ;
7926
        endcase
7927 49 robfinch
`endif
7928 48 robfinch
         bstate <= B19;
7929
    end
7930
B2:
7931
    begin
7932
    dccnt <= 2'd0;
7933
    case(bwhich)
7934
    2'd0:   begin
7935
             cti_o <= 3'b001;
7936
             bte_o <= 2'b01;
7937
             cyc_o <= `HIGH;
7938
             stb_o <= `HIGH;
7939
             sel_o <= fnSelect(dram0_instr,dram0_addr);
7940
             adr_o <= {dram0_addr[31:5],5'b0};
7941
             ol_o  <= dram0_ol;
7942
             bstate <= B2d;
7943
            end
7944 49 robfinch
    2'd1:   if (`NUM_MEM > 1) begin
7945 48 robfinch
             cti_o <= 3'b001;
7946
             bte_o <= 2'b01;
7947
             cyc_o <= `HIGH;
7948
             stb_o <= `HIGH;
7949
             sel_o <= fnSelect(dram1_instr,dram1_addr);
7950
             adr_o <= {dram1_addr[31:5],5'b0};
7951
             ol_o  <= dram1_ol;
7952
             bstate <= B2d;
7953
            end
7954 49 robfinch
    2'd2:   if (`NUM_MEM > 2) begin
7955 48 robfinch
             cti_o <= 3'b001;
7956
             bte_o <= 2'b01;
7957
             cyc_o <= `HIGH;
7958
             stb_o <= `HIGH;
7959
             sel_o <= fnSelect(dram2_instr,dram2_addr);
7960
             adr_o <= {dram2_addr[31:5],5'b0};
7961
             ol_o  <= dram2_ol;
7962
             bstate <= B2d;
7963
            end
7964
    default:    if (~acki)  bstate <= BIDLE;
7965
    endcase
7966
    end
7967
// Data cache load terminal state
7968
B2d:
7969
    if (ack_i|err_i) begin
7970
        errq <= errq | err_i;
7971
        rdvq <= rdvq | rdv_i;
7972
        if (!preload)   // A preload instruction ignores any error
7973
        case(bwhich)
7974
        2'd0:   if (err_i|rdv_i) begin
7975
                     iqentry_a1[dram0_id[`QBITS]] <= adr_o;
7976
                     iqentry_exc[dram0_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
7977
                end
7978 49 robfinch
        2'd1:   if ((err_i|rdv_i) && `NUM_MEM > 1) begin
7979 48 robfinch
                     iqentry_a1[dram1_id[`QBITS]] <= adr_o;
7980
                     iqentry_exc[dram1_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
7981
                end
7982 49 robfinch
        2'd2:   if ((err_i|rdv_i) && `NUM_MEM > 2) begin
7983 48 robfinch
                     iqentry_a1[dram2_id[`QBITS]] <= adr_o;
7984
                     iqentry_exc[dram2_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
7985
                end
7986
        default:    ;
7987
        endcase
7988
        dccnt <= dccnt + 2'd1;
7989
        adr_o[4:3] <= adr_o[4:3] + 2'd1;
7990
        bstate <= B2d;
7991
        if (dccnt==2'd2)
7992
             cti_o <= 3'b111;
7993
        if (dccnt==2'd3) begin
7994
             cti_o <= 3'b000;
7995
             bte_o <= 2'b00;
7996
             cyc_o <= `LOW;
7997
             stb_o <= `LOW;
7998
             sel_o <= 8'h00;
7999
             bstate <= B4;
8000
        end
8001
    end
8002
B3: begin
8003
         stb_o <= `HIGH;
8004
         bstate <= B2d;
8005
    end
8006
B4:  bstate <= B5;
8007
B5:  bstate <= B6;
8008
B6: begin
8009
    case(bwhich)
8010
    2'd0:    dram0 <= `DRAMSLOT_BUSY;  // causes retest of dhit
8011
    2'd1:    dram1 <= `DRAMSLOT_BUSY;
8012
    2'd2:    dram2 <= `DRAMSLOT_BUSY;
8013
    default:    ;
8014
    endcase
8015
    if (~ack_i)  bstate <= BIDLE;
8016
    end
8017
 
8018
// Ack state for instruction cache load
8019
B7:
8020
    if (ack_i|err_i) begin
8021
        errq <= errq | err_i;
8022
        exvq <= exvq | exv_i;
8023 49 robfinch
//        L1_en <= 9'h3 << {L2_xsel,L2_adr[4:3],1'b0};
8024 48 robfinch
//        L1_wr0 <= `TRUE;
8025
//        L1_wr1 <= `TRUE;
8026
//        L1_adr <= L2_adr;
8027
        if (err_i)
8028 49 robfinch
                L2_rdat <= {9{11'b0,4'd7,1'b0,`FLT_IBE,2'b00,`BRK}};
8029 48 robfinch
        else
8030 49 robfinch
                L2_rdat <= {dat_i[31:0],{4{dat_i}}};
8031 48 robfinch
        iccnt <= iccnt + 3'd1;
8032
        //stb_o <= `LOW;
8033
        if (iccnt==3'd3)
8034
            cti_o <= 3'b111;
8035
        if (iccnt==3'd4) begin
8036
            cti_o <= 3'b000;
8037
            bte_o <= 2'b00;             // linear burst
8038
            cyc_o <= `LOW;
8039
            stb_o <= `LOW;
8040
            sel_o <= 8'h00;
8041
            icl_o <= `LOW;
8042
            bstate <= B9;
8043
        end
8044
        else begin
8045
            L2_adr[4:3] <= L2_adr[4:3] + 2'd1;
8046
            if (L2_adr[4:3]==2'b11)
8047
                L2_xsel <= 1'b1;
8048
        end
8049
    end
8050
B9:
8051
        begin
8052
                L1_wr0 <= `FALSE;
8053
                L1_wr1 <= `FALSE;
8054 49 robfinch
                L1_wr2 <= `FALSE;
8055
                L1_en <= 9'h1FF;
8056 48 robfinch
                L2_xsel <= 1'b0;
8057
                if (~ack_i) begin
8058
                        bstate <= BIDLE;
8059
                        L2_nxt <= TRUE;
8060
                end
8061
        end
8062
B12:
8063
    if (ack_i|err_i) begin
8064
        if (isCAS) begin
8065
             iqentry_res        [ casid[`QBITS] ] <= (dat_i == cas);
8066
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8067
             iqentry_done[ casid[`QBITS] ] <= `VAL;
8068
             iqentry_instr[ casid[`QBITS]] <= `NOP_INSN;
8069
             iqentry_out [ casid[`QBITS] ] <= `INV;
8070
            if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
8071
            if (dat_i == cas) begin
8072
                 stb_o <= `LOW;
8073
                 we_o <= `TRUE;
8074
                 bstate <= B15;
8075
            end
8076
            else begin
8077
                 cas <= dat_i;
8078
                 cyc_o <= `LOW;
8079
                 stb_o <= `LOW;
8080
                case(bwhich)
8081
                2'b00:   dram0 <= `DRAMREQ_READY;
8082
                2'b01:   dram1 <= `DRAMREQ_READY;
8083
                2'b10:   dram2 <= `DRAMREQ_READY;
8084
                default:    ;
8085
                endcase
8086
                 bstate <= B19;
8087
            end
8088
        end
8089
        else if (isRMW) begin
8090
             rmw_instr <= iqentry_instr[casid[`QBITS]];
8091
             rmw_argA <= dat_i;
8092
                 if (isSpt) begin
8093
                        rmw_argB <= 64'd1 << iqentry_a1[casid[`QBITS]][63:58];
8094
                        rmw_argC <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ?
8095
                                                iqentry_a3[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58] :
8096
                                                iqentry_a2[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58];
8097
                 end
8098
                 else if (isInc) begin
8099
                        rmw_argB <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ? {{59{iqentry_instr[casid[`QBITS]][22]}},iqentry_instr[casid[`QBITS]][22:18]} :
8100
                                                                                                                                 {{59{iqentry_instr[casid[`QBITS]][17]}},iqentry_instr[casid[`QBITS]][17:13]};
8101
                 end
8102
                 else begin // isAMO
8103
                     iqentry_res [ casid[`QBITS] ] <= dat_i;
8104
                     rmw_argB <= iqentry_instr[casid[`QBITS]][31] ? {{59{iqentry_instr[casid[`QBITS]][20:16]}},iqentry_instr[casid[`QBITS]][20:16]} : iqentry_a2[casid[`QBITS]];
8105
                 end
8106
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8107
             if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
8108
             stb_o <= `LOW;
8109
             bstate <= B20;
8110
                end
8111
        else begin
8112
             cyc_o <= `LOW;
8113
             stb_o <= `LOW;
8114
             sr_o <= `LOW;
8115
             xdati <= dat_i;
8116
            case(bwhich)
8117
            2'b00:  begin
8118
                     dram0 <= `DRAMREQ_READY;
8119
                     iqentry_exc [ dram0_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8120
                    if (err_i|rdv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8121
                    end
8122 49 robfinch
            2'b01:  if (`NUM_MEM > 1) begin
8123 48 robfinch
                     dram1 <= `DRAMREQ_READY;
8124
                     iqentry_exc [ dram1_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8125
                    if (err_i|rdv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8126
                    end
8127 49 robfinch
            2'b10:  if (`NUM_MEM > 2) begin
8128 48 robfinch
                     dram2 <= `DRAMREQ_READY;
8129
                     iqentry_exc [ dram2_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8130
                    if (err_i|rdv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8131
                    end
8132
            default:    ;
8133
            endcase
8134
             bstate <= B19;
8135
        end
8136
    end
8137
// Three cycles to detemrine if there's a cache hit during a store.
8138
B16:    begin
8139
            case(bwhich)
8140
            2'd0:      if (dhit0) begin  dram0 <= `DRAMREQ_READY; bstate <= B17; end
8141
            2'd1:      if (dhit1) begin  dram1 <= `DRAMREQ_READY; bstate <= B17; end
8142
            2'd2:      if (dhit2) begin  dram2 <= `DRAMREQ_READY; bstate <= B17; end
8143
            default:    bstate <= BIDLE;
8144
            endcase
8145
            end
8146
B17:     bstate <= B18;
8147
B18:     bstate <= B19;
8148 57 robfinch
B19:    if (~acki)  begin
8149
                                        sel_o <= 8'h00;
8150
                                        bstate <= BIDLE;
8151
                                        isStore <= `FALSE;
8152
                                end
8153 48 robfinch
B20:
8154
        if (~ack_i) begin
8155
                stb_o <= `HIGH;
8156
                we_o  <= `HIGH;
8157
                dat_o <= fnDato(rmw_instr,rmw_res);
8158
                bstate <= B1;
8159
        end
8160
B21:
8161
        if (~ack_i) begin
8162
                stb_o <= `HIGH;
8163
                bstate <= B12;
8164
        end
8165
default:     bstate <= BIDLE;
8166
endcase
8167
 
8168
if (!branchmiss) begin
8169
    case({fetchbuf0_v, fetchbuf1_v})
8170
    2'b00:  ;
8171
    2'b01:
8172
        if (canq1) begin
8173
                tail0 <= idp1(tail0);
8174
                tail1 <= idp1(tail1);
8175
        end
8176
    2'b10:
8177
        if (canq1) begin
8178
            tail0 <= idp1(tail0);
8179
            tail1 <= idp1(tail1);
8180
        end
8181
    2'b11:
8182
        if (canq1) begin
8183
            if (IsBranch(fetchbuf0_instr) && predict_taken0 && fetchbuf0_thrd==fetchbuf1_thrd) begin
8184
                 tail0 <= idp1(tail0);
8185
                 tail1 <= idp1(tail1);
8186
            end
8187
            else begin
8188
                                if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
8189
                        if (canq2) begin
8190
                             tail0 <= idp2(tail0);
8191
                             tail1 <= idp2(tail1);
8192
                        end
8193
                        else begin    // queued1 will be true
8194
                             tail0 <= idp1(tail0);
8195
                             tail1 <= idp1(tail1);
8196
                        end
8197
                end
8198
            end
8199
        end
8200
    endcase
8201
end
8202 52 robfinch
else if (!thread_en) begin      // if branchmiss
8203 48 robfinch
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
8204 52 robfinch
         tail0 <= 4'd0;
8205
         tail1 <= 4'd1;
8206 48 robfinch
    end
8207
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
8208 52 robfinch
         tail0 <= 4'd1;
8209
         tail1 <= 4'd2;
8210 48 robfinch
    end
8211
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
8212 52 robfinch
         tail0 <= 4'd2;
8213
         tail1 <= 4'd3;
8214 48 robfinch
    end
8215
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
8216 52 robfinch
         tail0 <= 4'd3;
8217
         tail1 <= 4'd4;
8218 48 robfinch
    end
8219
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
8220 52 robfinch
         tail0 <= 4'd4;
8221
         tail1 <= 4'd5;
8222 48 robfinch
    end
8223
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
8224 52 robfinch
         tail0 <= 4'd5;
8225
         tail1 <= 4'd6;
8226 48 robfinch
    end
8227
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
8228 52 robfinch
         tail0 <= 4'd6;
8229
         tail1 <= 4'd7;
8230 48 robfinch
    end
8231
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
8232 52 robfinch
         tail0 <= 4'd7;
8233
         tail1 <= 4'd8;
8234 48 robfinch
    end
8235 52 robfinch
    else if (iqentry_stomp[8] & ~iqentry_stomp[7]) begin
8236
         tail0 <= 4'd8;
8237
         tail1 <= 4'd9;
8238
    end
8239
    else if (iqentry_stomp[9] & ~iqentry_stomp[8]) begin
8240
         tail0 <= 4'd9;
8241
         tail1 <= 4'd0;
8242
    end
8243 48 robfinch
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
8244
end
8245 51 robfinch
 
8246 48 robfinch
/*
8247
    if (pebm)
8248
         seq_num <= seq_num + 5'd3;
8249
    else if (queued2)
8250
         seq_num <= seq_num + 5'd2;
8251
    else if (queued1)
8252
         seq_num <= seq_num + 5'd1;
8253
*/
8254
//      #5 rf[0] = 0; rf_v[0] = 1; rf_source[0] = 0;
8255 51 robfinch
`ifdef SIM
8256 48 robfinch
        $display("\n\n\n\n\n\n\n\n");
8257
        $display("TIME %0d", $time);
8258
        $display("%h #", pc0);
8259
`ifdef SUPPORT_SMT
8260
    $display ("Regfile: %d", rgs[0]);
8261
        for (n=0; n < 32; n=n+4) begin
8262
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8263
               n[4:0]+0, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8264
               n[4:0]+1, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8265
               n[4:0]+2, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8266
               n[4:0]+3, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8267
               );
8268
        end
8269
    $display ("Regfile: %d", rgs[1]);
8270
        for (n=128; n < 160; n=n+4) begin
8271
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8272
               n[4:0]+0, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8273
               n[4:0]+1, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8274
               n[4:0]+2, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8275
               n[4:0]+3, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8276
               );
8277
        end
8278
`else
8279
    $display ("Regfile: %d", rgs);
8280
        for (n=0; n < 32; n=n+4) begin
8281
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8282 57 robfinch
               n[4:0]+0, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8283
               n[4:0]+1, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8284
               n[4:0]+2, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8285
               n[4:0]+3, gRegfileInst.gb1.urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8286 48 robfinch
               );
8287
        end
8288
`endif
8289 49 robfinch
`ifdef FCU_ENH
8290 48 robfinch
        $display("Call Stack:");
8291 49 robfinch
        for (n = 0; n < 16; n = n + 4)
8292 48 robfinch
                $display("%c%d: %h   %c%d: %h   %c%d: %h   %c%d: %h",
8293 57 robfinch
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+0 ?">" : " ", n[4:0]+0, gFetchbufInst.gb1.ufb1.ursb1.ras[n+0],
8294
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+1 ?">" : " ", n[4:0]+1, gFetchbufInst.gb1.ufb1.ursb1.ras[n+1],
8295
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+2 ?">" : " ", n[4:0]+2, gFetchbufInst.gb1.ufb1.ursb1.ras[n+2],
8296
                        gFetchbufInst.gb1.ufb1.ursb1.rasp==n+3 ?">" : " ", n[4:0]+3, gFetchbufInst.gb1.ufb1.ursb1.ras[n+3]
8297 48 robfinch
                );
8298
        $display("\n");
8299 49 robfinch
`endif
8300 48 robfinch
//    $display("Return address stack:");
8301
//    for (n = 0; n < 16; n = n + 1)
8302
//        $display("%d %h", rasp+n[3:0], ras[rasp+n[3:0]]);
8303
        $display("TakeBr:%d #", take_branch);//, backpc);
8304 51 robfinch
        $display("Insn%d: %h", 0, insn0);
8305 57 robfinch
        if (`WAYS==1) begin
8306
        $display("%c%c A: %d %h %h #",
8307
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
8308
        $display("%c%c B: %d %h %h #",
8309
            45, fetchbuf?62:45, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
8310
        end
8311
        else if (`WAYS > 1) begin
8312 51 robfinch
                $display("Insn%d: %h", 1, insn1);
8313 48 robfinch
        $display("%c%c A: %d %h %h #",
8314
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
8315
        $display("%c%c B: %d %h %h #",
8316
            45, fetchbuf?45:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
8317 57 robfinch
        end
8318
        else if (`WAYS > 2) begin
8319
                $display("%c%c C: %d %h %h #",
8320
                    45, fetchbuf?62:45, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
8321
                $display("%c%c D: %d %h %h #",
8322
                    45, fetchbuf?62:45, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
8323
        end
8324 48 robfinch
        for (i=0; i<QENTRIES; i=i+1)
8325
            $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#",
8326
                 (i[`QBITS]==head0)?"C":".",
8327
                 (i[`QBITS]==tail0)?"Q":".",
8328
                  i[`QBITS],
8329
                 iqentry_v[i] ? "v" : "-",
8330
                 iqentry_iv[i] ? "I" : "-",
8331
                 iqentry_done[i]?"d":"-",
8332
                 iqentry_out[i]?"o":"-",
8333
                 iqentry_bt[i],
8334
                 iqentry_memissue[i],
8335
                 iqentry_agen[i] ? "a": "-",
8336
                 iqentry_alu0_issue[i]?"0":iqentry_alu1_issue[i]?"1":"-",
8337
                 iqentry_stomp[i]?"s":"-",
8338
                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",
8339
                iqentry_instr[i], iqentry_tgt[i][4:0],
8340
                iqentry_exc[i], iqentry_res[i], iqentry_a0[i], iqentry_a1[i], iqentry_a1_v[i],
8341
                iqentry_a1_s[i],
8342
                iqentry_a2[i], iqentry_a2_v[i], iqentry_a2_s[i],
8343
                iqentry_a3[i], iqentry_a3_v[i], iqentry_a3_s[i],
8344
                iqentry_thrd[i],
8345
                iqentry_pc[i],
8346
                iqentry_sn[i], iqentry_ven[i]
8347
                );
8348
    $display("DRAM");
8349
        $display("%d %h %h %c%h %o #",
8350
            dram0, dram0_addr, dram0_data, (IsFlowCtrl(dram0_instr) ? 98 : (IsMem(dram0_instr)) ? 109 : 97),
8351
            dram0_instr, dram0_id);
8352 49 robfinch
          if (`NUM_MEM > 1)
8353 48 robfinch
        $display("%d %h %h %c%h %o #",
8354
            dram1, dram1_addr, dram1_data, (IsFlowCtrl(dram1_instr) ? 98 : (IsMem(dram1_instr)) ? 109 : 97),
8355
            dram1_instr, dram1_id);
8356 49 robfinch
          if (`NUM_MEM > 2)
8357 48 robfinch
        $display("%d %h %h %c%h %o #",
8358
            dram2, dram2_addr, dram2_data, (IsFlowCtrl(dram2_instr) ? 98 : (IsMem(dram2_instr)) ? 109 : 97),
8359
            dram2_instr, dram2_id);
8360
        $display("%d %h %o %h #", dramA_v, dramA_bus, dramA_id, dramA_exc);
8361 49 robfinch
        if (`NUM_MEM > 1)
8362 48 robfinch
        $display("%d %h %o %h #", dramB_v, dramB_bus, dramB_id, dramB_exc);
8363 49 robfinch
        if (`NUM_MEM > 2)
8364 48 robfinch
        $display("%d %h %o %h #", dramC_v, dramC_bus, dramC_id, dramC_exc);
8365
    $display("ALU");
8366
        $display("%d %h %h %h %c%h %d %o %h #",
8367
                alu0_dataready, alu0_argI, alu0_argA, alu0_argB,
8368
                 (IsFlowCtrl(alu0_instr) ? 98 : IsMem(alu0_instr) ? 109 : 97),
8369
                alu0_instr, alu0_bt, alu0_sourceid, alu0_pc);
8370
        $display("%d %h %o 0 #", alu0_v, alu0_bus, alu0_id);
8371 49 robfinch
        if (`NUM_ALU > 1) begin
8372
                $display("%d %h %h %h %c%h %d %o %h #",
8373
                        alu1_dataready, alu1_argI, alu1_argA, alu1_argB,
8374
                        (IsFlowCtrl(alu1_instr) ? 98 : IsMem(alu1_instr) ? 109 : 97),
8375
                        alu1_instr, alu1_bt, alu1_sourceid, alu1_pc);
8376
                $display("%d %h %o 0 #", alu1_v, alu1_bus, alu1_id);
8377
        end
8378 48 robfinch
        $display("FCU");
8379
        $display("%d %h %h %h %h #", fcu_v, fcu_bus, fcu_argI, fcu_argA, fcu_argB);
8380 56 robfinch
        $display("%c %h %h %h %h #", fcu_branchmiss?"m":" ", fcu_sourceid, fcu_misspc, fcu_nextpc, fcu_brdisp);
8381 48 robfinch
    $display("Commit");
8382
        $display("0: %c %h %o %d #", commit0_v?"v":" ", commit0_bus, commit0_id, commit0_tgt[4:0]);
8383
        $display("1: %c %h %o %d #", commit1_v?"v":" ", commit1_bus, commit1_id, commit1_tgt[4:0]);
8384
    $display("instructions committed: %d ticks: %d ", I, tick);
8385 49 robfinch
    $display("Write merges: %d", wb_merges);
8386 51 robfinch
`endif  // SIM
8387 48 robfinch
 
8388
//
8389
//      $display("\n\n\n\n\n\n\n\n");
8390
//      $display("TIME %0d", $time);
8391
//      $display("  pc0=%h", pc0);
8392
//      $display("  pc1=%h", pc1);
8393
//      $display("  reg0=%h, v=%d, src=%o", rf[0], rf_v[0], rf_source[0]);
8394
//      $display("  reg1=%h, v=%d, src=%o", rf[1], rf_v[1], rf_source[1]);
8395
//      $display("  reg2=%h, v=%d, src=%o", rf[2], rf_v[2], rf_source[2]);
8396
//      $display("  reg3=%h, v=%d, src=%o", rf[3], rf_v[3], rf_source[3]);
8397
//      $display("  reg4=%h, v=%d, src=%o", rf[4], rf_v[4], rf_source[4]);
8398
//      $display("  reg5=%h, v=%d, src=%o", rf[5], rf_v[5], rf_source[5]);
8399
//      $display("  reg6=%h, v=%d, src=%o", rf[6], rf_v[6], rf_source[6]);
8400
//      $display("  reg7=%h, v=%d, src=%o", rf[7], rf_v[7], rf_source[7]);
8401
 
8402
//      $display("Fetch Buffers:");
8403
//      $display("  %c%c fbA: v=%d instr=%h pc=%h     %c%c fbC: v=%d instr=%h pc=%h", 
8404
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc,
8405
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
8406
//      $display("  %c%c fbB: v=%d instr=%h pc=%h     %c%c fbD: v=%d instr=%h pc=%h", 
8407
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc,
8408
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
8409
//      $display("  branchback=%d backpc=%h", branchback, backpc);
8410
 
8411
//      $display("Instruction Queue:");
8412
//      for (i=0; i<8; i=i+1) 
8413
//          $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",
8414
//              (i[`QBITS]==head0)?72:32, (i[`QBITS]==tail0)?84:32, i,
8415
//              iqentry_v[i], iqentry_done[i], iqentry_out[i], iqentry_agen[i], iqentry_res[i], iqentry_op[i], 
8416
//              iqentry_bt[i], iqentry_tgt[i], iqentry_a1[i], iqentry_a1_v[i], iqentry_a1_s[i], iqentry_a2[i], iqentry_a2_v[i], 
8417
//              iqentry_a2_s[i], iqentry_a0[i], iqentry_pc[i], iqentry_exc[i]);
8418
 
8419
//      $display("Scheduling Status:");
8420
//      $display("  iqentry0 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8421
//              iqentry_0_issue, iqentry_0_islot, iqentry_stomp[0], iqentry_source[0], iqentry_memready[0], iqentry_memissue[0]);
8422
//      $display("  iqentry1 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8423
//              iqentry_1_issue, iqentry_1_islot, iqentry_stomp[1], iqentry_source[1], iqentry_memready[1], iqentry_memissue[1]);
8424
//      $display("  iqentry2 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8425
//              iqentry_2_issue, iqentry_2_islot, iqentry_stomp[2], iqentry_source[2], iqentry_memready[2], iqentry_memissue[2]);
8426
//      $display("  iqentry3 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8427
//              iqentry_3_issue, iqentry_3_islot, iqentry_stomp[3], iqentry_source[3], iqentry_memready[3], iqentry_memissue[3]);
8428
//      $display("  iqentry4 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8429
//              iqentry_4_issue, iqentry_4_islot, iqentry_stomp[4], iqentry_source[4], iqentry_memready[4], iqentry_memissue[4]);
8430
//      $display("  iqentry5 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8431
//              iqentry_5_issue, iqentry_5_islot, iqentry_stomp[5], iqentry_source[5], iqentry_memready[5], iqentry_memissue[5]);
8432
//      $display("  iqentry6 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8433
//              iqentry_6_issue, iqentry_6_islot, iqentry_stomp[6], iqentry_source[6], iqentry_memready[6], iqentry_memissue[6]);
8434
//      $display("  iqentry7 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8435
//              iqentry_7_issue, iqentry_7_islot, iqentry_stomp[7], iqentry_source[7], iqentry_memready[7], iqentry_memissue[7]);
8436
 
8437
//      $display("ALU Inputs:");
8438
//      $display("  0: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
8439
//              alu0_available, alu0_dataready, alu0_sourceid, alu0_op, alu0_argA,
8440
//              alu0_argB, alu0_argI, alu0_bt);
8441
//      $display("  1: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
8442
//              alu1_available, alu1_dataready, alu1_sourceid, alu1_op, alu1_argA,
8443
//              alu1_argB, alu1_argI, alu1_bt);
8444
 
8445
//      $display("ALU Outputs:");
8446
//      $display("  0: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
8447
//              alu0_v, alu0_bus, alu0_id, alu0_branchmiss, alu0_misspc, alu0_sourceid);
8448
//      $display("  1: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
8449
//              alu1_v, alu1_bus, alu1_id, alu1_branchmiss, alu1_misspc, alu1_sourceid);
8450
 
8451
//      $display("DRAM Status:");
8452
//      $display("  OUT: v=%d data=%h tgt=%d id=%o", dram_v, dram_bus, dram_tgt, dram_id);
8453
//      $display("  dram0: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
8454
//          dram0, dram0_addr, dram0_data, dram0_op, dram0_tgt, dram0_id);
8455
//      $display("  dram1: status=%h addr=%h data=%h op=%d tgt=%d id=%o", 
8456
//          dram1, dram1_addr, dram1_data, dram1_op, dram1_tgt, dram1_id);
8457
//      $display("  dram2: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
8458
//          dram2, dram2_addr, dram2_data, dram2_op, dram2_tgt, dram2_id);
8459
 
8460
//      $display("Commit Buses:");
8461
//      $display("  0: v=%d id=%o data=%h", commit0_v, commit0_id, commit0_bus);
8462
//      $display("  1: v=%d id=%o data=%h", commit1_v, commit1_id, commit1_bus);
8463
 
8464
//
8465
//      $display("Memory Contents:");
8466
//      for (j=0; j<64; j=j+16)
8467
//          $display("  %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h", 
8468
//              m[j+0], m[j+1], m[j+2], m[j+3], m[j+4], m[j+5], m[j+6], m[j+7],
8469
//              m[j+8], m[j+9], m[j+10], m[j+11], m[j+12], m[j+13], m[j+14], m[j+15]);
8470
 
8471
        $display("");
8472
 
8473
        if (|panic) begin
8474
            $display("");
8475
            $display("-----------------------------------------------------------------");
8476
            $display("-----------------------------------------------------------------");
8477
            $display("---------------     PANIC:%s     -----------------", message[panic]);
8478
            $display("-----------------------------------------------------------------");
8479
            $display("-----------------------------------------------------------------");
8480
            $display("");
8481
            $display("instructions committed: %d", I);
8482
            $display("total execution cycles: %d", $time / 10);
8483
            $display("");
8484
        end
8485
        if (|panic && ~outstanding_stores) begin
8486
            $finish;
8487
        end
8488
    for (n = 0; n < QENTRIES; n = n + 1)
8489
        if (branchmiss) begin
8490
            if (!setpred[n]) begin
8491
                 iqentry_instr[n][`INSTRUCTION_OP] <= `NOP;
8492
                 iqentry_done[n] <= `VAL;
8493
                 iqentry_cmt[n] <= `VAL;
8494
            end
8495
        end
8496
 
8497
        if (snr) begin
8498
                seq_num <= 32'd0;
8499
                seq_num1 <= 32'd0;
8500
        end
8501
end // clock domain
8502
/*
8503
always @(posedge clk)
8504
if (rst) begin
8505
     tail0 <= 3'd0;
8506
     tail1 <= 3'd1;
8507
end
8508
else begin
8509
if (!branchmiss) begin
8510
    case({fetchbuf0_v, fetchbuf1_v})
8511
    2'b00:  ;
8512
    2'b01:
8513
        if (canq1) begin
8514
             tail0 <= idp1(tail0);
8515
             tail1 <= idp1(tail1);
8516
        end
8517
    2'b10:
8518
        if (canq1) begin
8519
             tail0 <= idp1(tail0);
8520
             tail1 <= idp1(tail1);
8521
        end
8522
    2'b11:
8523
        if (canq1) begin
8524
            if (IsBranch(fetchbuf0_instr) && predict_taken0) begin
8525
                 tail0 <= idp1(tail0);
8526
                 tail1 <= idp1(tail1);
8527
            end
8528
            else begin
8529
                                if (vqe < vl || !IsVector(fetchbuf0_instr)) begin
8530
                        if (canq2) begin
8531
                             tail0 <= idp2(tail0);
8532
                             tail1 <= idp2(tail1);
8533
                        end
8534
                        else begin    // queued1 will be true
8535
                             tail0 <= idp1(tail0);
8536
                             tail1 <= idp1(tail1);
8537
                        end
8538
                end
8539
            end
8540
        end
8541
    endcase
8542
end
8543
else begin      // if branchmiss
8544
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
8545
         tail0 <= 3'd0;
8546
         tail1 <= 3'd1;
8547
    end
8548
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
8549
         tail0 <= 3'd1;
8550
         tail1 <= 3'd2;
8551
    end
8552
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
8553
         tail0 <= 3'd2;
8554
         tail1 <= 3'd3;
8555
    end
8556
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
8557
         tail0 <= 3'd3;
8558
         tail1 <= 3'd4;
8559
    end
8560
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
8561
         tail0 <= 3'd4;
8562
         tail1 <= 3'd5;
8563
    end
8564
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
8565
         tail0 <= 3'd5;
8566
         tail1 <= 3'd6;
8567
    end
8568
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
8569
         tail0 <= 3'd6;
8570
         tail1 <= 3'd7;
8571
    end
8572
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
8573
         tail0 <= 3'd7;
8574
         tail1 <= 3'd0;
8575
    end
8576
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
8577
end
8578
end
8579
*/
8580
/*
8581
always @(posedge clk)
8582
if (rst)
8583
     seq_num <= 5'd0;
8584
else begin
8585
    if (pebm)
8586
         seq_num <= seq_num + 5'd3;
8587
    else if (queued2)
8588
         seq_num <= seq_num + 5'd2;
8589
    else if (queued1)
8590
         seq_num <= seq_num + 5'd1;
8591
end
8592
*/
8593 49 robfinch
 
8594 51 robfinch
// Update the write buffer.
8595 49 robfinch
task wb_update;
8596
input [`QBITS] id;
8597
input rmw;
8598
input [7:0] sel;
8599
input [1:0] ol;
8600
input [`ABITS] addr;
8601
input [63:0] data;
8602
begin
8603 52 robfinch
        if (wbm && wbptr > 1 && wb_addr[wbptr-1][AMSB:3]==addr[AMSB:3]
8604
         && wb_ol[wbptr-1]==ol && wb_rmw[wbptr-1]==rmw && wb_v[wbptr-1]) begin
8605
                // The write buffer is always shifted during the bus IDLE state. That means
8606
                // the data is out of place by a slot. The slot the data is moved from is
8607
                // invalidated.
8608
                wb_v[wbptr-2] <= `INV;
8609
                wb_v[wbptr-1] <= wb_en;
8610
                wb_id[wbptr-1] <= wb_id[wbptr-1] | (16'd1 << id);
8611
                wb_rmw[wbptr-1] <= rmw;
8612
                wb_ol[wbptr-1] <= ol;
8613 49 robfinch
                wb_sel[wbptr-1] <= wb_sel[wbptr-1] | sel;
8614 52 robfinch
                wb_addr[wbptr-1] <= wb_addr[wbptr-1];
8615
                wb_data[wbptr-1] <= wb_data[wbptr-1];
8616 49 robfinch
                if (sel[0]) wb_data[wbptr-1][ 7: 0] <= data[ 7: 0];
8617
                if (sel[1]) wb_data[wbptr-1][15: 8] <= data[15: 8];
8618
                if (sel[2]) wb_data[wbptr-1][23:16] <= data[23:16];
8619
                if (sel[3]) wb_data[wbptr-1][31:24] <= data[31:24];
8620
                if (sel[4]) wb_data[wbptr-1][39:32] <= data[39:32];
8621
                if (sel[5]) wb_data[wbptr-1][47:40] <= data[47:40];
8622
                if (sel[6]) wb_data[wbptr-1][55:48] <= data[55:48];
8623
                if (sel[7]) wb_data[wbptr-1][63:56] <= data[63:56];
8624
                wb_merges <= wb_merges + 32'd1;
8625
        end
8626
        else begin
8627
                wb_v[wbptr] <= wb_en;
8628
                wb_id[wbptr] <= (16'd1 << id);
8629
                wb_rmw[wbptr] <= rmw;
8630
                wb_ol[wbptr] <= ol;
8631
                wb_sel[wbptr] <= sel;
8632
                wb_addr[wbptr] <= {addr[AMSB:3],3'b0};
8633
                wb_data[wbptr] <= data;
8634
        end
8635
end
8636
endtask
8637 52 robfinch
 
8638 48 robfinch
// Increment the head pointers
8639
// Also increments the instruction counter
8640
// Used when instructions are committed.
8641
// Also clear any outstanding state bits that foul things up.
8642
//
8643
task head_inc;
8644
input [`QBITS] amt;
8645
begin
8646 52 robfinch
     head0 <= (head0 + amt) % QENTRIES;
8647
     head1 <= (head1 + amt) % QENTRIES;
8648
     head2 <= (head2 + amt) % QENTRIES;
8649
     head3 <= (head3 + amt) % QENTRIES;
8650
     head4 <= (head4 + amt) % QENTRIES;
8651
     head5 <= (head5 + amt) % QENTRIES;
8652
     head6 <= (head6 + amt) % QENTRIES;
8653
     head7 <= (head7 + amt) % QENTRIES;
8654
     head8 <= (head8 + amt) % QENTRIES;
8655
     head9 <= (head9 + amt) % QENTRIES;
8656 48 robfinch
     I <= I + amt;
8657 49 robfinch
    if (amt==3'd3) begin
8658
        iqentry_agen[head0] <= `INV;
8659
        iqentry_agen[head1] <= `INV;
8660
        iqentry_agen[head2] <= `INV;
8661
        iqentry_mem[head0] <= `FALSE;
8662
        iqentry_mem[head1] <= `FALSE;
8663
        iqentry_mem[head2] <= `FALSE;
8664
        iqentry_iv[head0] <= `INV;
8665
        iqentry_iv[head1] <= `INV;
8666
        iqentry_iv[head2] <= `INV;
8667
        iqentry_alu[head0] <= `FALSE;
8668
        iqentry_alu[head1] <= `FALSE;
8669
        iqentry_alu[head2] <= `FALSE;
8670
        end
8671
    else if (amt==3'd2) begin
8672 48 robfinch
     iqentry_agen[head0] <= `INV;
8673
     iqentry_agen[head1] <= `INV;
8674 49 robfinch
     iqentry_mem[head0] <= `FALSE;
8675
     iqentry_mem[head1] <= `FALSE;
8676
     iqentry_iv[head0] <= `INV;
8677
     iqentry_iv[head1] <= `INV;
8678
        iqentry_alu[head0] <= `FALSE;
8679
     iqentry_alu[head1] <= `FALSE;
8680 48 robfinch
    end else if (amt==3'd1) begin
8681 49 robfinch
            iqentry_agen[head0] <= `INV;
8682
            iqentry_mem[head0] <= `FALSE;
8683
        iqentry_iv[head0] <= `INV;
8684
        iqentry_alu[head0] <= `FALSE;
8685 48 robfinch
        end
8686
end
8687
endtask
8688
 
8689
task setargs;
8690
input [`QBITS] nn;
8691
input [4:0] id;
8692
input v;
8693
input [63:0] bus;
8694
begin
8695
  if (iqentry_a1_v[nn] == `INV && iqentry_a1_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8696
                iqentry_a1[nn] <= bus;
8697
                iqentry_a1_v[nn] <= `VAL;
8698
  end
8699
  if (iqentry_a2_v[nn] == `INV && iqentry_a2_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8700
                iqentry_a2[nn] <= bus;
8701
                iqentry_a2_v[nn] <= `VAL;
8702
  end
8703
  if (iqentry_a3_v[nn] == `INV && iqentry_a3_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8704
                iqentry_a3[nn] <= bus;
8705
                iqentry_a3_v[nn] <= `VAL;
8706
  end
8707
end
8708
endtask
8709
 
8710
task setinsn;
8711
input [`QBITS] nn;
8712
input [4:0] id;
8713
input v;
8714 51 robfinch
input [143:0] bus;
8715 48 robfinch
begin
8716
  if (iqentry_iv[nn] == `INV && iqentry_is[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
8717
        iqentry_iv   [nn]  <= `VAL;
8718
//      iqentry_Rt   [nn]  <= bus[`IB_RT];
8719
//      iqentry_Rc   [nn]  <= bus[`IB_RC];
8720
//      iqentry_Ra   [nn]  <= bus[`IB_RA];
8721
        iqentry_a0       [nn]  <= bus[`IB_CONST];
8722
        iqentry_imm  [nn]  <= bus[`IB_IMM];
8723 55 robfinch
//              iqentry_insln[nn]  <= bus[`IB_LN];
8724 56 robfinch
                if (iqentry_insln[nn] != bus[`IB_LN]) begin
8725
                        $display("Insn length mismatch.");
8726
                        $stop;
8727
                end
8728 51 robfinch
                iqentry_jal      [nn]  <= bus[`IB_JAL];
8729
                iqentry_ret  [nn]  <= bus[`IB_RET];
8730
                iqentry_irq  [nn]  <= bus[`IB_IRQ];
8731
                iqentry_brk      [nn]  <= bus[`IB_BRK];
8732
                iqentry_rti  [nn]  <= bus[`IB_RTI];
8733 48 robfinch
                iqentry_bt   [nn]  <= bus[`IB_BT];
8734
                iqentry_alu  [nn]  <= bus[`IB_ALU];
8735
                iqentry_alu0 [nn]  <= bus[`IB_ALU0];
8736
                iqentry_fpu  [nn]  <= bus[`IB_FPU];
8737
                iqentry_fc   [nn]  <= bus[`IB_FC];
8738
                iqentry_canex[nn]  <= bus[`IB_CANEX];
8739 50 robfinch
                iqentry_loadv[nn]  <= bus[`IB_LOADV];
8740 48 robfinch
                iqentry_load [nn]  <= bus[`IB_LOAD];
8741
                iqentry_preload[nn]<= bus[`IB_PRELOAD];
8742 50 robfinch
                iqentry_store[nn]  <= bus[`IB_STORE];
8743
                iqentry_oddball[nn] <= bus[`IB_ODDBALL];
8744
                iqentry_memsz[nn]  <= bus[`IB_MEMSZ];
8745 48 robfinch
                iqentry_mem  [nn]  <= bus[`IB_MEM];
8746
                iqentry_memndx[nn] <= bus[`IB_MEMNDX];
8747
                iqentry_rmw  [nn]  <= bus[`IB_RMW];
8748
                iqentry_memdb[nn]  <= bus[`IB_MEMDB];
8749
                iqentry_memsb[nn]  <= bus[`IB_MEMSB];
8750
                iqentry_shft48[nn] <= bus[`IB_SHFT48];
8751
                iqentry_sei      [nn]    <= bus[`IB_SEI];
8752
                iqentry_aq   [nn]  <= bus[`IB_AQ];
8753
                iqentry_rl   [nn]  <= bus[`IB_RL];
8754
                iqentry_jmp  [nn]  <= bus[`IB_JMP];
8755
                iqentry_br   [nn]  <= bus[`IB_BR];
8756
                iqentry_sync [nn]  <= bus[`IB_SYNC];
8757
                iqentry_fsync[nn]  <= bus[`IB_FSYNC];
8758
        iqentry_rfw  [nn]  <= bus[`IB_RFW];
8759
        iqentry_we   [nn]  <= bus[`IB_WE];
8760 56 robfinch
/*
8761
        if (iqentry_vector[nn]) begin
8762
                        iqentry_tgt[nn][RBIT:6] <= iqentry_Ra[nn][RBIT:6];
8763
                if (iqentry_Ra[nn][RBIT:6]==6'd0)
8764
                        iqentry_tgt[nn][RBIT:6] = 6'd0;
8765
                else begin
8766
                                if (iqentry_vcmprss[nn]) begin
8767
                                        if (vm[iqentry_instr[nn][25:23]][iqentry_Ra[nn][RBIT:6]])
8768
                                                if (qcnt==2'd2 && iqentry_vector[(nn-1)%QENTRIES] && iqentry_Ra[(nn-1)%QENTRIES][RBIT:6] >= 6'd1)
8769
                                                        iqentry_tgt[nn][RBIT:6] <= iqentry_tgt[(nn-2)%QENTRIES][RBIT:6] + 6'd2;
8770
                                                else
8771
                                                        iqentry_tgt[nn][RBIT:6] <= iqentry_tgt[(nn-1)%QENTRIES][RBIT:6] + 6'd1;
8772
                                end
8773
                        end
8774
                end
8775
*/
8776 48 robfinch
  end
8777
end
8778
endtask
8779
 
8780 55 robfinch
task a1_vs;
8781
begin
8782
        // if there is not an overlapping write to the register file.
8783
        if (Ra1s != Rt0s || !fetchbuf0_rfw) begin
8784
                iqentry_a1_v [tail1] <= regIsValid[Ra1s];
8785
                iqentry_a1_s [tail1] <= rf_source [Ra1s];
8786
        end
8787
        else begin
8788
                iqentry_a1_v [tail1] <= `INV;
8789
                iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
8790
        end
8791
end
8792
endtask
8793
 
8794
task a2_vs;
8795
begin
8796
        // if there is not an overlapping write to the register file.
8797
        if (Rb1s != Rt0s || !fetchbuf0_rfw) begin
8798
                iqentry_a2_v [tail1] <= regIsValid[Rb1s];
8799
                iqentry_a2_s [tail1] <= rf_source [Rb1s];
8800
        end
8801
        else begin
8802
                iqentry_a2_v [tail1] <= `INV;
8803
                iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
8804
        end
8805
end
8806
endtask
8807
 
8808
task a3_vs;
8809
begin
8810
        // if there is not an overlapping write to the register file.
8811
        if (Rc1s != Rt0s || !fetchbuf0_rfw) begin
8812
                iqentry_a3_v [tail1] <= regIsValid[Rc1s];
8813
                iqentry_a3_s [tail1] <= rf_source [Rc1s];
8814
        end
8815
        else begin
8816
                iqentry_a3_v [tail1] <= `INV;
8817
                iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
8818
        end
8819
end
8820
endtask
8821
 
8822
task enque0x;
8823
begin
8824
        if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
8825
                vqe0 <= vqe0 + 4'd1;
8826
                if (IsVCmprss(fetchbuf0_instr)) begin
8827
                        if (vm[fetchbuf0_instr[25:23]][vqe0])
8828
                        vqet0 <= vqet0 + 4'd1;
8829
                end
8830
                else
8831
                        vqet0 <= vqet0 + 4'd1;
8832
                if (vqe0 >= vl-2)
8833
                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
8834
                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
8835
                if (fetchbuf0_thrd)
8836
                        seq_num1 <= seq_num1 + 5'd1;
8837
                else
8838
                        seq_num <= seq_num + 5'd1;
8839
                if (fetchbuf0_rfw) begin
8840
                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
8841
                        rf_v[Rt0s] <= `INV;
8842
                end
8843
                if (canq2) begin
8844
                        if (vqe0 < vl-2) begin
8845
                                vqe0 <= vqe0 + 4'd2;
8846
                                if (IsVCmprss(fetchbuf0_instr)) begin
8847
                                        if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
8848
                                                vqet0 <= vqet0 + 4'd2;
8849
                                end
8850
                                else
8851
                                        vqet0 <= vqet0 + 4'd2;
8852
                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num+5'd1, vqe0 + 6'd1);
8853
                                if (fetchbuf0_thrd)
8854
                                        seq_num1 <= seq_num1 + 5'd2;
8855
                                else
8856
                                        seq_num <= seq_num + 5'd2;
8857
                                if (fetchbuf0_rfw) begin
8858
                                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };    // top bit indicates ALU/MEM bus
8859
                                        rf_v[Rt0s] <= `INV;
8860
                                end
8861
                        end
8862
                end
8863
        end
8864
        else begin
8865
                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, 6'd0);
8866
                if (fetchbuf0_thrd)
8867
                        seq_num1 <= seq_num1 + 5'd1;
8868
                else
8869
                        seq_num <= seq_num + 5'd1;
8870
                if (fetchbuf0_rfw) begin
8871
                        rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
8872
                        rf_v[Rt0s] <= `INV;
8873
                end
8874
        end
8875
end
8876
endtask
8877
 
8878 48 robfinch
// Enqueue fetchbuf0 onto the tail of the instruction queue
8879
task enque0;
8880
input [`QBITS] tail;
8881
input [63:0] seqnum;
8882
input [5:0] venno;
8883
begin
8884
        iqentry_exc[tail] <= `FLT_NONE;
8885
`ifdef SUPPORT_DBG
8886
    if (dbg_imatchA)
8887
        iqentry_exc[tail] <= `FLT_DBG;
8888
    else if (dbg_ctrl[63])
8889
        iqentry_exc[tail] <= `FLT_SSM;
8890
`endif
8891
        iqentry_sn   [tail]    <=  seqnum;
8892
        iqentry_v    [tail]    <=   `VAL;
8893
        iqentry_iv       [tail]    <=   `INV;
8894
        iqentry_is   [tail]    <= tail;
8895
        iqentry_thrd [tail]    <=   fetchbuf0_thrd;
8896
        iqentry_done [tail]    <=    `INV;
8897
        iqentry_cmt  [tail]    <=       `INV;
8898
        iqentry_out  [tail]    <=    `INV;
8899
        iqentry_res  [tail]    <=    `ZERO;
8900
        iqentry_instr[tail]    <=    IsVLS(fetchbuf0_instr) ? (vm[fnM2(fetchbuf0_instr)] ? fetchbuf0_instr : `NOP_INSN) : fetchbuf0_instr;
8901 55 robfinch
        iqentry_insln[tail]              <=  fetchbuf0_insln;
8902 48 robfinch
        iqentry_pt   [tail]    <=  predict_taken0;
8903
        iqentry_agen [tail]    <=    `INV;
8904
        iqentry_state[tail]    <=   IQS_IDLE;
8905
// If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
8906
// inherit the previous pc.
8907
//if (IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15] &&
8908
//   (IsBrk(iqentry_instr[idm1(tail)]) && !iqentry_instr[idm1(tail1)][15] && iqentry_v[idm1(tail)]))
8909
//   iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
8910
//else
8911
         iqentry_pc   [tail] <= fetchbuf0_pc;
8912
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf0_instr);
8913
        iqentry_tgt  [tail]    <=       Rt0;
8914
        iqentry_Ra   [tail]    <= Ra0;
8915
        iqentry_Rb   [tail]    <= Rb0;
8916
        iqentry_Rc   [tail]    <= Rc0;
8917
        iqentry_vl   [tail]    <=  vl;
8918
        iqentry_ven  [tail]    <=   venno;
8919
        iqentry_exc  [tail]    <=    `EXC_NONE;
8920
        iqentry_a1   [tail]    <=    rfoa0;
8921
        iqentry_a1_v [tail]    <=    Source1Valid(fetchbuf0_instr) | regIsValid[Ra0s];
8922
        iqentry_a1_s [tail]    <=    rf_source[Ra0s];
8923
        iqentry_a2   [tail]    <=    rfob0;
8924
        iqentry_a2_v [tail]    <=    Source2Valid(fetchbuf0_instr) | regIsValid[Rb0s];
8925
        iqentry_a2_s [tail]    <=    rf_source[Rb0s];
8926
        iqentry_a3   [tail]    <=    rfoc0;
8927
        iqentry_a3_v [tail]    <=    Source3Valid(fetchbuf0_instr) | regIsValid[Rc0s];
8928
        iqentry_a3_s [tail]    <=    rf_source[Rc0s];
8929
end
8930
endtask
8931
 
8932
// Enque fetchbuf1. Fetchbuf1 might be the second instruction to queue so some
8933
// of this code checks to see which tail it is being queued on.
8934
task enque1;
8935
input [`QBITS] tail;
8936
input [63:0] seqnum;
8937
input [5:0] venno;
8938
begin
8939
 iqentry_exc[tail] <= `FLT_NONE;
8940
`ifdef SUPPORT_DBG
8941
    if (dbg_imatchB)
8942
        iqentry_exc[tail] <= `FLT_DBG;
8943
    else if (dbg_ctrl[63])
8944
        iqentry_exc[tail] <= `FLT_SSM;
8945
`endif
8946
        iqentry_sn   [tail]    <=   seqnum;
8947
        iqentry_v    [tail]    <=   `VAL;
8948
        iqentry_iv       [tail]    <=   `INV;
8949
        iqentry_is   [tail]    <= tail;
8950
        iqentry_thrd [tail]    <=   fetchbuf1_thrd;
8951
        iqentry_done [tail]    <=   `INV;
8952
        iqentry_cmt  [tail]    <=       `INV;
8953
        iqentry_out  [tail]    <=   `INV;
8954
        iqentry_res  [tail]    <=   `ZERO;
8955
        iqentry_instr[tail]    <=   IsVLS(fetchbuf1_instr) ? (vm[fnM2(fetchbuf1_instr)] ? fetchbuf1_instr : `NOP_INSN) : fetchbuf1_instr;
8956 55 robfinch
        iqentry_insln[tail]              <=  fetchbuf1_insln;
8957 48 robfinch
        iqentry_pt   [tail]    <=  predict_taken1;
8958
        iqentry_agen [tail]    <=   `INV;
8959
        iqentry_state[tail]    <=   IQS_IDLE;
8960
// If queing 2nd instruction must read from first
8961
if (tail==tail1) begin
8962
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
8963
    // inherit the previous pc.
8964
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
8965
//        IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15])
8966
//       iqentry_pc   [tail]    <= fetchbuf0_pc;
8967
//    else
8968
                iqentry_pc   [tail] <= fetchbuf1_pc;
8969
end
8970
else begin
8971
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
8972
    // inherit the previous pc.
8973
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
8974
//       (IsBrk(iqentry_instr[idp7(tail)]) && !iqentry_instr[idm1(tail)][15] && iqentry_v[idm1(tail)]))
8975
//       iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
8976
//    else
8977
                iqentry_pc   [tail] <= fetchbuf1_pc;
8978
end
8979
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf1_instr);
8980
        iqentry_tgt  [tail]    <= Rt1;
8981
        iqentry_Ra   [tail]    <= Ra1;
8982
        iqentry_Rb   [tail]    <= Rb1;
8983
        iqentry_Rc   [tail]    <= Rc1;
8984
        iqentry_vl   [tail]    <=  vl;
8985
        iqentry_ven  [tail]    <=   venno;
8986
        iqentry_exc  [tail]    <=   `EXC_NONE;
8987
        iqentry_a1   [tail]    <=       rfoa1;
8988
        iqentry_a1_v [tail]    <=       Source1Valid(fetchbuf1_instr) | regIsValid[Ra1s];
8989
        iqentry_a1_s [tail]    <=       rf_source[Ra1s];
8990
        iqentry_a2   [tail]    <=       rfob1;
8991
        iqentry_a2_v [tail]    <=       Source2Valid(fetchbuf1_instr) | regIsValid[Rb1s];
8992
        iqentry_a2_s [tail]    <=       rf_source[Rb1s];
8993
        iqentry_a3   [tail]    <=       rfoc1;
8994
        iqentry_a3_v [tail]    <=       Source3Valid(fetchbuf1_instr) | regIsValid[Rc1s];
8995
        iqentry_a3_s [tail]    <=       rf_source[Rc1s];
8996
end
8997
endtask
8998
 
8999
// This task takes care of commits for things other than the register file.
9000
task oddball_commit;
9001
input v;
9002
input [`QBITS] head;
9003
reg thread;
9004
begin
9005
    thread = iqentry_thrd[head];
9006
    if (v) begin
9007
        if (|iqentry_exc[head]) begin
9008
            excmiss <= TRUE;
9009
`ifdef SUPPORT_SMT
9010 51 robfinch
                excmisspc <= {tvec[3'd0][31:8],1'b0,ol[thread],5'h00};
9011 48 robfinch
            excthrd <= iqentry_thrd[head];
9012
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
9013
            epc0[thread] <= iqentry_pc[head]+ 32'd4;
9014
            epc1[thread] <= epc0[thread];
9015
            epc2[thread] <= epc1[thread];
9016
            epc3[thread] <= epc2[thread];
9017
            epc4[thread] <= epc3[thread];
9018
            epc5[thread] <= epc4[thread];
9019
            epc6[thread] <= epc5[thread];
9020
            epc7[thread] <= epc6[thread];
9021
            epc8[thread] <= epc7[thread];
9022
            im_stack[thread] <= {im_stack[thread][27:0],im};
9023
            ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9024
            pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9025
            rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
9026
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
9027
            mstatus[thread][5:3] <= 3'd0;
9028
            mstatus[thread][13:6] <= 8'h00;
9029
            mstatus[thread][19:14] <= 6'd0;
9030
`else
9031 51 robfinch
                excmisspc <= {tvec[3'd0][31:8],1'b0,ol,5'h00};
9032 48 robfinch
            excthrd <= iqentry_thrd[head];
9033
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
9034
            epc0 <= iqentry_pc[head]+ 32'd4;
9035
            epc1 <= epc0;
9036
            epc2 <= epc1;
9037
            epc3 <= epc2;
9038
            epc4 <= epc3;
9039
            epc5 <= epc4;
9040
            epc6 <= epc5;
9041
            epc7 <= epc6;
9042
            epc8 <= epc7;
9043
            im_stack <= {im_stack[27:0],im};
9044
            ol_stack <= {ol_stack[13:0],ol};
9045
            pl_stack <= {pl_stack[55:0],cpl};
9046
            rs_stack <= {rs_stack[55:0],rgs};
9047
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
9048
            mstatus[5:3] <= 3'd0;
9049
            mstatus[13:6] <= 8'h00;
9050
            mstatus[19:14] <= 6'd0;
9051
`endif
9052 49 robfinch
                                                wb_en <= `TRUE;
9053 48 robfinch
            sema[0] <= 1'b0;
9054
            ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9055
`ifdef SUPPORT_DBG
9056
            dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9057
            dbg_ctrl[63] <= FALSE;
9058
`endif
9059
        end
9060
        else
9061
        case(iqentry_instr[head][`INSTRUCTION_OP])
9062
        `BRK:
9063
                        // BRK is treated as a nop unless it's a software interrupt or a
9064
                        // hardware interrupt at a higher priority than the current priority.
9065
                if ((iqentry_instr[head][23:19] > 5'd0) || iqentry_instr[head][18:16] > im) begin
9066
                            excmiss <= TRUE;
9067
`ifdef SUPPORT_SMT
9068 51 robfinch
                        excmisspc <= {tvec[3'd0][31:8],1'b0,ol[thread],5'h00};
9069 48 robfinch
                        excthrd <= iqentry_thrd[head];
9070
                    epc0[thread] <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
9071
                    epc1[thread] <= epc0[thread];
9072
                    epc2[thread] <= epc1[thread];
9073
                    epc3[thread] <= epc2[thread];
9074
                    epc4[thread] <= epc3[thread];
9075
                    epc5[thread] <= epc4[thread];
9076
                    epc6[thread] <= epc5[thread];
9077
                    epc7[thread] <= epc6[thread];
9078
                    epc8[thread] <= epc7[thread];
9079
                    im_stack[thread] <= {im_stack[thread][27:0],im};
9080
                    ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9081
                    pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9082
                    rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
9083
                    mstatus[thread][19:14] <= 6'd0;
9084
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
9085
                    mstatus[thread][5:3] <= 3'd0;
9086
                        mstatus[thread][13:6] <= 8'h00;
9087
                    // For hardware interrupts only, set a new mask level
9088
                    // Select register set according to interrupt level
9089
                    if (iqentry_instr[head][23:19]==5'd0) begin
9090
                        mstatus[thread][2:0] <= 3'd7;//iqentry_instr[head][18:16];
9091
                        mstatus[thread][42:40] <= iqentry_instr[head][18:16];
9092
                        mstatus[thread][19:14] <= {3'b0,iqentry_instr[head][18:16]};
9093
                    end
9094
                    else
9095
                        mstatus[thread][19:14] <= 6'd0;
9096
`else
9097 51 robfinch
                        excmisspc <= {tvec[3'd0][31:8],1'b0,ol,5'h00};
9098 48 robfinch
                        excthrd <= iqentry_thrd[head];
9099
                    epc0 <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
9100
                    epc1 <= epc0;
9101
                    epc2 <= epc1;
9102
                    epc3 <= epc2;
9103
                    epc4 <= epc3;
9104
                    epc5 <= epc4;
9105
                    epc6 <= epc5;
9106
                    epc7 <= epc6;
9107
                    epc8 <= epc7;
9108
                    im_stack <= {im_stack[27:0],im};
9109
                    ol_stack <= {ol_stack[13:0],ol};
9110
                    pl_stack <= {pl_stack[55:0],cpl};
9111
                    rs_stack <= {rs_stack[55:0],rgs};
9112
                    mstatus[19:14] <= 6'd0;
9113
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
9114
                    mstatus[5:3] <= 3'd0;
9115
                        mstatus[13:6] <= 8'h00;
9116
                    // For hardware interrupts only, set a new mask level
9117
                    // Select register set according to interrupt level
9118
                    if (iqentry_instr[head][23:19]==5'd0) begin
9119
                        mstatus[2:0] <= 3'd7;//iqentry_instr[head][18:16];
9120
                        mstatus[42:40] <= iqentry_instr[head][18:16];
9121
                        mstatus[19:14] <= {3'b0,iqentry_instr[head][18:16]};
9122
                    end
9123
                    else
9124
                        mstatus[19:14] <= 6'd0;
9125
`endif
9126
                    sema[0] <= 1'b0;
9127
                    ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9128
`ifdef SUPPORT_DBG
9129
                    dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9130
                    dbg_ctrl[63] <= FALSE;
9131
`endif
9132
                end
9133
        `IVECTOR:
9134
            casez(iqentry_tgt[head])
9135
            8'b00100xxx:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9136
            8'b00101111:  vl <= iqentry_res[head];
9137
            default:    ;
9138
            endcase
9139
        `R2:
9140
            case(iqentry_instr[head][`INSTRUCTION_S2])
9141
            `R1:        case(iqentry_instr[head][20:16])
9142
                        `CHAIN_OFF:     cr0[18] <= 1'b0;
9143
                        `CHAIN_ON:      cr0[18] <= 1'b1;
9144
                        //`SETWB:               wbrcd[pcr[5:0]] <= 1'b1;
9145
                        default:        ;
9146
                                endcase
9147
            `VMOV:  casez(iqentry_tgt[head])
9148
                    12'b1111111_00???:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9149
                    12'b1111111_01111:  vl <= iqentry_res[head];
9150
                    default:    ;
9151
                    endcase
9152
`ifdef SUPPORT_SMT
9153
            `SEI:   mstatus[thread][2:0] <= iqentry_res[head][2:0];   // S1
9154
`else
9155
            `SEI:   mstatus[2:0] <= iqentry_res[head][2:0];   // S1
9156
`endif
9157
            `RTI:   begin
9158
                            excmiss <= TRUE;
9159
`ifdef SUPPORT_SMT
9160
                        excmisspc <= epc0[thread];
9161
                        excthrd <= thread;
9162
                        mstatus[thread][3:0] <= im_stack[thread][3:0];
9163
                        mstatus[thread][5:4] <= ol_stack[thread][1:0];
9164
                        mstatus[thread][13:6] <= pl_stack[thread][7:0];
9165
                        mstatus[thread][19:14] <= rs_stack[thread][5:0];
9166
                        im_stack[thread] <= {4'd15,im_stack[thread][27:4]};
9167
                        ol_stack[thread] <= {2'd0,ol_stack[thread][15:2]};
9168
                        pl_stack[thread] <= {8'h00,pl_stack[thread][63:8]};
9169
                        rs_stack[thread] <= {8'h00,rs_stack[thread][63:8]};
9170
                    epc0[thread] <= epc1[thread];
9171
                    epc1[thread] <= epc2[thread];
9172
                    epc2[thread] <= epc3[thread];
9173
                    epc3[thread] <= epc4[thread];
9174
                    epc4[thread] <= epc5[thread];
9175
                    epc5[thread] <= epc6[thread];
9176
                    epc6[thread] <= epc7[thread];
9177
                    epc7[thread] <= epc8[thread];
9178 51 robfinch
                    epc8[thread] <= {tvec[0][31:8], 1'b0, ol[thread], 5'h0};
9179 48 robfinch
`else
9180
                        excmisspc <= epc0;
9181
                        excthrd <= thread;
9182
                        mstatus[3:0] <= im_stack[3:0];
9183
                        mstatus[5:4] <= ol_stack[1:0];
9184
                        mstatus[13:6] <= pl_stack[7:0];
9185
                        mstatus[19:14] <= rs_stack[5:0];
9186
                        im_stack <= {4'd15,im_stack[31:4]};
9187
                        ol_stack <= {2'd0,ol_stack[15:2]};
9188
                        pl_stack <= {8'h00,pl_stack[63:8]};
9189
                        rs_stack <= {8'h00,rs_stack[63:8]};
9190
                    epc0 <= epc1;
9191
                    epc1 <= epc2;
9192
                    epc2 <= epc3;
9193
                    epc3 <= epc4;
9194
                    epc4 <= epc5;
9195
                    epc5 <= epc6;
9196
                    epc6 <= epc7;
9197
                    epc7 <= epc8;
9198 51 robfinch
                    epc8 <= {tvec[0][31:8], 1'b0, ol, 5'h0};
9199 48 robfinch
`endif
9200
                    sema[0] <= 1'b0;
9201
                    sema[iqentry_res[head][5:0]] <= 1'b0;
9202
                    vqe0  <= ve_hold[ 5: 0];
9203
                    vqet0 <= ve_hold[21:16];
9204
                    vqe1  <= ve_hold[37:32];
9205
                    vqet1 <= ve_hold[53:48];
9206
`ifdef SUPPORT_DBG
9207
                    dbg_ctrl[62:55] <= {FALSE,dbg_ctrl[62:56]};
9208
                    dbg_ctrl[63] <= dbg_ctrl[55];
9209
`endif
9210
                    end
9211 49 robfinch
            default: ;
9212
            endcase
9213
        `MEMNDX:
9214
            case(iqentry_instr[head][`INSTRUCTION_S2])
9215 48 robfinch
            `CACHEX:
9216 49 robfinch
                    case(iqentry_instr[head][22:18])
9217 48 robfinch
                    5'h03:  invic <= TRUE;
9218
                    5'h10:  cr0[30] <= FALSE;
9219
                    5'h11:  cr0[30] <= TRUE;
9220
                    default:    ;
9221
                    endcase
9222
            default: ;
9223
            endcase
9224
        `CSRRW:
9225
                        begin
9226 51 robfinch
                        write_csr(iqentry_instr[head][31:18],iqentry_a1[head],thread);
9227 48 robfinch
                        end
9228
        `REX:
9229
`ifdef SUPPORT_SMT
9230
            // Can only redirect to a lower level
9231
            if (ol[thread] < iqentry_instr[head][13:11]) begin
9232
                mstatus[thread][5:3] <= iqentry_instr[head][13:11];
9233
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol[thread]}];
9234
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol[thread]}];
9235
                mstatus[thread][13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
9236
            end
9237
`else
9238
            if (ol < iqentry_instr[head][13:11]) begin
9239
                mstatus[5:3] <= iqentry_instr[head][13:11];
9240
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol}];
9241
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol}];
9242
                mstatus[13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
9243
            end
9244
`endif
9245
        `CACHE:
9246 49 robfinch
            case(iqentry_instr[head][17:13])
9247 48 robfinch
            5'h03:  invic <= TRUE;
9248
            5'h10:  cr0[30] <= FALSE;
9249
            5'h11:  cr0[30] <= TRUE;
9250
            default:    ;
9251
            endcase
9252
        `FLOAT:
9253
            case(iqentry_instr[head][`INSTRUCTION_S2])
9254 49 robfinch
            `FRM: begin
9255 51 robfinch
                                fp_rm <= iqentry_res[head][2:0];
9256 49 robfinch
                                end
9257 48 robfinch
            `FCX:
9258
                begin
9259 51 robfinch
                    fp_sx <= fp_sx & ~iqentry_res[head][5];
9260
                    fp_inex <= fp_inex & ~iqentry_res[head][4];
9261
                    fp_dbzx <= fp_dbzx & ~(iqentry_res[head][3]|iqentry_res[head][0]);
9262
                    fp_underx <= fp_underx & ~iqentry_res[head][2];
9263
                    fp_overx <= fp_overx & ~iqentry_res[head][1];
9264
                    fp_giopx <= fp_giopx & ~iqentry_res[head][0];
9265
                    fp_infdivx <= fp_infdivx & ~iqentry_res[head][0];
9266
                    fp_zerozerox <= fp_zerozerox & ~iqentry_res[head][0];
9267
                    fp_subinfx   <= fp_subinfx   & ~iqentry_res[head][0];
9268
                    fp_infzerox  <= fp_infzerox  & ~iqentry_res[head][0];
9269
                    fp_NaNCmpx   <= fp_NaNCmpx   & ~iqentry_res[head][0];
9270
                    fp_swtx <= 1'b0;
9271 48 robfinch
                end
9272
            `FDX:
9273
                begin
9274 51 robfinch
                    fp_inexe <= fp_inexe     & ~iqentry_res[head][4];
9275
                    fp_dbzxe <= fp_dbzxe     & ~iqentry_res[head][3];
9276
                    fp_underxe <= fp_underxe & ~iqentry_res[head][2];
9277
                    fp_overxe <= fp_overxe   & ~iqentry_res[head][1];
9278
                    fp_invopxe <= fp_invopxe & ~iqentry_res[head][0];
9279 48 robfinch
                end
9280
            `FEX:
9281
                begin
9282 51 robfinch
                    fp_inexe <= fp_inexe     | iqentry_res[head][4];
9283
                    fp_dbzxe <= fp_dbzxe     | iqentry_res[head][3];
9284
                    fp_underxe <= fp_underxe | iqentry_res[head][2];
9285
                    fp_overxe <= fp_overxe   | iqentry_res[head][1];
9286
                    fp_invopxe <= fp_invopxe | iqentry_res[head][0];
9287 48 robfinch
                end
9288
            default:
9289
                begin
9290
                    // 31 to 29 is rounding mode
9291
                    // 28 to 24 are exception enables
9292
                    // 23 is nsfp
9293
                    // 22 is a fractie
9294 51 robfinch
                    fp_fractie <= iqentry_a0[head][22];
9295
                    fp_raz <= iqentry_a0[head][21];
9296 48 robfinch
                    // 20 is a 0
9297 51 robfinch
                    fp_neg <= iqentry_a0[head][19];
9298
                    fp_pos <= iqentry_a0[head][18];
9299
                    fp_zero <= iqentry_a0[head][17];
9300
                    fp_inf <= iqentry_a0[head][16];
9301 48 robfinch
                    // 15 swtx
9302
                    // 14 
9303 51 robfinch
                    fp_inex <= fp_inex | (fp_inexe & iqentry_a0[head][14]);
9304
                    fp_dbzx <= fp_dbzx | (fp_dbzxe & iqentry_a0[head][13]);
9305
                    fp_underx <= fp_underx | (fp_underxe & iqentry_a0[head][12]);
9306
                    fp_overx <= fp_overx | (fp_overxe & iqentry_a0[head][11]);
9307 48 robfinch
                    //fp_giopx <= fp_giopx | (fp_giopxe & iqentry_res2[head][10]);
9308
                    //fp_invopx <= fp_invopx | (fp_invopxe & iqentry_res2[head][24]);
9309
                    //
9310 51 robfinch
                    fp_cvtx <= fp_cvtx |  (fp_giopxe & iqentry_a0[head][7]);
9311
                    fp_sqrtx <= fp_sqrtx |  (fp_giopxe & iqentry_a0[head][6]);
9312
                    fp_NaNCmpx <= fp_NaNCmpx |  (fp_giopxe & iqentry_a0[head][5]);
9313
                    fp_infzerox <= fp_infzerox |  (fp_giopxe & iqentry_a0[head][4]);
9314
                    fp_zerozerox <= fp_zerozerox |  (fp_giopxe & iqentry_a0[head][3]);
9315
                    fp_infdivx <= fp_infdivx | (fp_giopxe & iqentry_a0[head][2]);
9316
                    fp_subinfx <= fp_subinfx | (fp_giopxe & iqentry_a0[head][1]);
9317
                    fp_snanx <= fp_snanx | (fp_giopxe & iqentry_a0[head][0]);
9318 48 robfinch
 
9319
                end
9320
            endcase
9321
        default:    ;
9322
        endcase
9323
        // Once the flow control instruction commits, NOP it out to allow
9324
        // pending stores to be issued.
9325
        iqentry_instr[head][5:0] <= `NOP;
9326
    end
9327
end
9328
endtask
9329
 
9330
// CSR access tasks
9331
task read_csr;
9332 51 robfinch
input [11:0] csrno;
9333 48 robfinch
output [63:0] dat;
9334
input thread;
9335
begin
9336
`ifdef SUPPORT_SMT
9337
    if (csrno[11:10] >= ol[thread])
9338
`else
9339
    if (csrno[11:10] >= ol)
9340
`endif
9341
    casez(csrno[9:0])
9342
    `CSR_CR0:       dat <= cr0;
9343
    `CSR_HARTID:    dat <= hartid;
9344
    `CSR_TICK:      dat <= tick;
9345
    `CSR_PCR:       dat <= pcr;
9346
    `CSR_PCR2:      dat <= pcr2;
9347 49 robfinch
    `CSR_PMR:                           dat <= pmr;
9348 48 robfinch
    `CSR_WBRCD:         dat <= wbrcd;
9349
    `CSR_SEMA:      dat <= sema;
9350
    `CSR_SBL:       dat <= sbl;
9351
    `CSR_SBU:       dat <= sbu;
9352
    `CSR_TCB:           dat <= tcb;
9353 51 robfinch
    `CSR_FSTAT:     dat <= {fp_rgs,fp_status};
9354 48 robfinch
`ifdef SUPPORT_DBG
9355
    `CSR_DBAD0:     dat <= dbg_adr0;
9356
    `CSR_DBAD1:     dat <= dbg_adr1;
9357
    `CSR_DBAD2:     dat <= dbg_adr2;
9358
    `CSR_DBAD3:     dat <= dbg_adr3;
9359
    `CSR_DBCTRL:    dat <= dbg_ctrl;
9360
    `CSR_DBSTAT:    dat <= dbg_stat;
9361
`endif
9362
    `CSR_CAS:       dat <= cas;
9363
    `CSR_TVEC:      dat <= tvec[csrno[2:0]];
9364 52 robfinch
    `CSR_BADADR:    dat <= badaddr[{thread,csrno[11:10]}];
9365
    `CSR_CAUSE:     dat <= {48'd0,cause[{thread,csrno[11:10]}]};
9366 48 robfinch
`ifdef SUPPORT_SMT
9367
    `CSR_IM_STACK:      dat <= im_stack[thread];
9368
    `CSR_OL_STACK:      dat <= ol_stack[thread];
9369
    `CSR_PL_STACK:      dat <= pl_stack[thread];
9370
    `CSR_RS_STACK:      dat <= rs_stack[thread];
9371
    `CSR_STATUS:    dat <= mstatus[thread][63:0];
9372
    `CSR_EPC0:      dat <= epc0[thread];
9373
    `CSR_EPC1:      dat <= epc1[thread];
9374
    `CSR_EPC2:      dat <= epc2[thread];
9375
    `CSR_EPC3:      dat <= epc3[thread];
9376
    `CSR_EPC4:      dat <= epc4[thread];
9377
    `CSR_EPC5:      dat <= epc5[thread];
9378
    `CSR_EPC6:      dat <= epc6[thread];
9379
    `CSR_EPC7:      dat <= epc7[thread];
9380
`else
9381
    `CSR_IM_STACK:      dat <= im_stack;
9382
    `CSR_OL_STACK:      dat <= ol_stack;
9383
    `CSR_PL_STACK:      dat <= pl_stack;
9384
    `CSR_RS_STACK:      dat <= rs_stack;
9385
    `CSR_STATUS:    dat <= mstatus[63:0];
9386
    `CSR_EPC0:      dat <= epc0;
9387
    `CSR_EPC1:      dat <= epc1;
9388
    `CSR_EPC2:      dat <= epc2;
9389
    `CSR_EPC3:      dat <= epc3;
9390
    `CSR_EPC4:      dat <= epc4;
9391
    `CSR_EPC5:      dat <= epc5;
9392
    `CSR_EPC6:      dat <= epc6;
9393
    `CSR_EPC7:      dat <= epc7;
9394
`endif
9395
    `CSR_CODEBUF:   dat <= codebuf[csrno[5:0]];
9396
    `CSR_TIME:          dat <= wc_times;
9397
    `CSR_INFO:
9398
                    case(csrno[3:0])
9399
                    4'd0:   dat <= "Finitron";  // manufacturer
9400
                    4'd1:   dat <= "        ";
9401
                    4'd2:   dat <= "64 bit  ";  // CPU class
9402
                    4'd3:   dat <= "        ";
9403
                    4'd4:   dat <= "FT64    ";  // Name
9404
                    4'd5:   dat <= "        ";
9405
                    4'd6:   dat <= 64'd1;       // model #
9406
                    4'd7:   dat <= 64'd1;       // serial number
9407
                    4'd8:   dat <= {32'd16384,32'd16384};   // cache sizes instruction,data
9408
                    4'd9:   dat <= 64'd0;
9409
                    default:    dat <= 64'd0;
9410
                    endcase
9411
    default:    begin
9412
                        $display("Unsupported CSR:%h",csrno[10:0]);
9413
                        dat <= 64'hEEEEEEEEEEEEEEEE;
9414
                        end
9415
    endcase
9416
    else
9417
        dat <= 64'h0;
9418
end
9419
endtask
9420
 
9421
task write_csr;
9422
input [13:0] csrno;
9423
input [63:0] dat;
9424
input thread;
9425
begin
9426
`ifdef SUPPORT_SMT
9427
    if (csrno[11:10] >= ol[thread])
9428
`else
9429
    if (csrno[11:10] >= ol)
9430
`endif
9431
    case(csrno[13:12])
9432
    2'd1:   // CSRRW
9433
        casez(csrno[9:0])
9434
        `CSR_CR0:       cr0 <= dat;
9435
        `CSR_PCR:       pcr <= dat[31:0];
9436
        `CSR_PCR2:      pcr2 <= dat;
9437 49 robfinch
        `CSR_PMR:       case(`NUM_IDU)
9438
                                                0,1:     pmr[0] <= 1'b1;
9439
                                                2:
9440
                                                        begin
9441
                                                                        if (dat[1:0]==2'b00)
9442
                                                                                pmr[1:0] <= 2'b01;
9443
                                                                        else
9444
                                                                                pmr[1:0] <= dat[1:0];
9445
                                                                        pmr[63:2] <= dat[63:2];
9446
                                                                end
9447
                                                3:
9448
                                                        begin
9449
                                                                        if (dat[2:0]==3'b000)
9450
                                                                                pmr[2:0] <= 3'b001;
9451
                                                                        else
9452
                                                                                pmr[2:0] <= dat[2:0];
9453
                                                                        pmr[63:3] <= dat[63:3];
9454
                                                                end
9455
                                                default:        pmr[0] <= 1'b1;
9456
                                                endcase
9457 48 robfinch
        `CSR_WBRCD:             wbrcd <= dat;
9458
        `CSR_SEMA:      sema <= dat;
9459
        `CSR_SBL:       sbl <= dat[31:0];
9460
        `CSR_SBU:       sbu <= dat[31:0];
9461
        `CSR_TCB:               tcb <= dat;
9462 51 robfinch
        `CSR_FSTAT:             fpu_csr[37:32] <= dat[37:32];
9463 52 robfinch
        `CSR_BADADR:    badaddr[{thread,csrno[11:10]}] <= dat;
9464
        `CSR_CAUSE:     cause[{thread,csrno[11:10]}] <= dat[15:0];
9465 48 robfinch
`ifdef SUPPORT_DBG
9466
        `CSR_DBAD0:     dbg_adr0 <= dat[AMSB:0];
9467
        `CSR_DBAD1:     dbg_adr1 <= dat[AMSB:0];
9468
        `CSR_DBAD2:     dbg_adr2 <= dat[AMSB:0];
9469
        `CSR_DBAD3:     dbg_adr3 <= dat[AMSB:0];
9470
        `CSR_DBCTRL:    dbg_ctrl <= dat;
9471
`endif
9472
        `CSR_CAS:       cas <= dat;
9473
        `CSR_TVEC:      tvec[csrno[2:0]] <= dat[31:0];
9474
`ifdef SUPPORT_SMT
9475
        `CSR_IM_STACK:  im_stack[thread] <= dat[31:0];
9476
        `CSR_OL_STACK:  ol_stack[thread] <= dat[15:0];
9477
        `CSR_PL_STACK:  pl_stack[thread] <= dat;
9478
        `CSR_RS_STACK:  rs_stack[thread] <= dat;
9479
        `CSR_STATUS:    mstatus[thread][63:0] <= dat;
9480
        `CSR_EPC0:      epc0[thread] <= dat;
9481
        `CSR_EPC1:      epc1[thread] <= dat;
9482
        `CSR_EPC2:      epc2[thread] <= dat;
9483
        `CSR_EPC3:      epc3[thread] <= dat;
9484
        `CSR_EPC4:      epc4[thread] <= dat;
9485
        `CSR_EPC5:      epc5[thread] <= dat;
9486
        `CSR_EPC6:      epc6[thread] <= dat;
9487
        `CSR_EPC7:      epc7[thread] <= dat;
9488
`else
9489
        `CSR_IM_STACK:  im_stack <= dat[31:0];
9490
        `CSR_OL_STACK:  ol_stack <= dat[15:0];
9491
        `CSR_PL_STACK:  pl_stack <= dat;
9492
        `CSR_RS_STACK:  rs_stack <= dat;
9493
        `CSR_STATUS:    mstatus[63:0] <= dat;
9494
        `CSR_EPC0:      epc0 <= dat;
9495
        `CSR_EPC1:      epc1 <= dat;
9496
        `CSR_EPC2:      epc2 <= dat;
9497
        `CSR_EPC3:      epc3 <= dat;
9498
        `CSR_EPC4:      epc4 <= dat;
9499
        `CSR_EPC5:      epc5 <= dat;
9500
        `CSR_EPC6:      epc6 <= dat;
9501
        `CSR_EPC7:      epc7 <= dat;
9502
`endif
9503
                `CSR_TIME:              begin
9504
                                                ld_time <= 6'h3f;
9505
                                                wc_time_dat <= dat;
9506
                                                end
9507
        `CSR_CODEBUF:   codebuf[csrno[5:0]] <= dat;
9508
        default:    ;
9509
        endcase
9510
    2'd2:   // CSRRS
9511
        case(csrno[9:0])
9512
        `CSR_CR0:       cr0 <= cr0 | dat;
9513
        `CSR_PCR:       pcr[31:0] <= pcr[31:0] | dat[31:0];
9514
        `CSR_PCR2:      pcr2 <= pcr2 | dat;
9515 49 robfinch
        `CSR_PMR:                               pmr <= pmr | dat;
9516 48 robfinch
        `CSR_WBRCD:             wbrcd <= wbrcd | dat;
9517
`ifdef SUPPORT_DBG
9518
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl | dat;
9519
`endif
9520
        `CSR_SEMA:      sema <= sema | dat;
9521
`ifdef SUPPORT_SMT
9522
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] | dat;
9523
`else
9524
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] | dat;
9525
`endif
9526
        default:    ;
9527
        endcase
9528
    2'd3:   // CSRRC
9529
        case(csrno[9:0])
9530
        `CSR_CR0:       cr0 <= cr0 & ~dat;
9531
        `CSR_PCR:       pcr <= pcr & ~dat;
9532
        `CSR_PCR2:      pcr2 <= pcr2 & ~dat;
9533 49 robfinch
        `CSR_PMR:                       begin
9534
                                                                if (dat[1:0]==2'b11)
9535
                                                                        pmr[1:0] <= 2'b01;
9536
                                                                else
9537
                                                                        pmr[1:0] <= pmr[1:0] & ~dat[1:0];
9538
                                                                pmr[63:2] <= pmr[63:2] & ~dat[63:2];
9539
                                                                end
9540 48 robfinch
        `CSR_WBRCD:             wbrcd <= wbrcd & ~dat;
9541
`ifdef SUPPORT_DBG
9542
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl & ~dat;
9543
`endif
9544
        `CSR_SEMA:      sema <= sema & ~dat;
9545
`ifdef SUPPORT_SMT
9546
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] & ~dat;
9547
`else
9548
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] & ~dat;
9549
`endif
9550
        default:    ;
9551
        endcase
9552
    default:    ;
9553
    endcase
9554
end
9555
endtask
9556
 
9557
 
9558
endmodule
9559
 
9560
 
9561
module decoder5 (num, out);
9562
input [4:0] num;
9563
output [31:1] out;
9564
reg [31:1] out;
9565
 
9566
always @(num)
9567
case (num)
9568
    5'd0 :      out <= 31'b0000000000000000000000000000000;
9569
    5'd1 :      out <= 31'b0000000000000000000000000000001;
9570
    5'd2 :      out <= 31'b0000000000000000000000000000010;
9571
    5'd3 :      out <= 31'b0000000000000000000000000000100;
9572
    5'd4 :      out <= 31'b0000000000000000000000000001000;
9573
    5'd5 :      out <= 31'b0000000000000000000000000010000;
9574
    5'd6 :      out <= 31'b0000000000000000000000000100000;
9575
    5'd7 :      out <= 31'b0000000000000000000000001000000;
9576
    5'd8 :      out <= 31'b0000000000000000000000010000000;
9577
    5'd9 :      out <= 31'b0000000000000000000000100000000;
9578
    5'd10:      out <= 31'b0000000000000000000001000000000;
9579
    5'd11:      out <= 31'b0000000000000000000010000000000;
9580
    5'd12:      out <= 31'b0000000000000000000100000000000;
9581
    5'd13:      out <= 31'b0000000000000000001000000000000;
9582
    5'd14:      out <= 31'b0000000000000000010000000000000;
9583
    5'd15:      out <= 31'b0000000000000000100000000000000;
9584
    5'd16:      out <= 31'b0000000000000001000000000000000;
9585
    5'd17:      out <= 31'b0000000000000010000000000000000;
9586
    5'd18:      out <= 31'b0000000000000100000000000000000;
9587
    5'd19:      out <= 31'b0000000000001000000000000000000;
9588
    5'd20:      out <= 31'b0000000000010000000000000000000;
9589
    5'd21:      out <= 31'b0000000000100000000000000000000;
9590
    5'd22:      out <= 31'b0000000001000000000000000000000;
9591
    5'd23:      out <= 31'b0000000010000000000000000000000;
9592
    5'd24:      out <= 31'b0000000100000000000000000000000;
9593
    5'd25:      out <= 31'b0000001000000000000000000000000;
9594
    5'd26:      out <= 31'b0000010000000000000000000000000;
9595
    5'd27:      out <= 31'b0000100000000000000000000000000;
9596
    5'd28:      out <= 31'b0001000000000000000000000000000;
9597
    5'd29:      out <= 31'b0010000000000000000000000000000;
9598
    5'd30:      out <= 31'b0100000000000000000000000000000;
9599
    5'd31:      out <= 31'b1000000000000000000000000000000;
9600
endcase
9601
 
9602
endmodule
9603
 
9604
module decoder6 (num, out);
9605
input [5:0] num;
9606
output [63:1] out;
9607
 
9608
wire [63:0] out1;
9609
 
9610
assign out1 = 64'd1 << num;
9611
assign out = out1[63:1];
9612
 
9613
endmodule
9614
 
9615
module decoder7 (num, out);
9616
input [6:0] num;
9617
output [127:1] out;
9618
 
9619
wire [127:0] out1;
9620
 
9621
assign out1 = 128'd1 << num;
9622
assign out = out1[127:1];
9623
 
9624
endmodule
9625
 
9626
module decoder8 (num, out);
9627
input [7:0] num;
9628
output [255:1] out;
9629
 
9630
wire [255:0] out1;
9631
 
9632
assign out1 = 256'd1 << num;
9633
assign out = out1[255:1];
9634
 
9635
endmodule
9636
 

powered by: WebSVN 2.1.0

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