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

Subversion Repositories thor

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

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

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2017-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      FT64.v
9
//      Features include:
10
//  - 16/32/48 bit instructions
11
//  - vector instruction set,
12
//  - SIMD instructions
13
//  - data width of 64 bits
14
//      - 32 general purpose registers
15
//  - 32 floating point registers
16
//      - 32 vector registers, length 63
17
//  - powerful branch prediction
18
//  - branch target buffer (BTB)
19
//  - return address predictor (RSB)
20
//  - bus interface unit
21
//  - instruction and data caches
22
//  - asynchronous logic loops for issue and branch miss
23
//    re-written for synchronous operation, not as elegant
24
//    but required for operation in an FPGA
25
//      - fine-grained simultaneous multi-threading (SMT)
26
//
27
// This source file is free software: you can redistribute it and/or modify 
28
// it under the terms of the GNU Lesser General Public License as published 
29
// by the Free Software Foundation, either version 3 of the License, or     
30
// (at your option) any later version.                                      
31
//                                                                          
32
// This source file is distributed in the hope that it will be useful,      
33
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
34
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
35
// GNU General Public License for more details.                             
36
//                                                                          
37
// You should have received a copy of the GNU General Public License        
38
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
39
//
40
// Approx. 100,000 LUTs. 160,000 LC's.
41
// ============================================================================
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
parameter SUP_VECTOR = 1;
95
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
integer j;
102
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
BUFG uclkb1
118
(
119
        .I(clk_i),
120
        .O(clk)
121
);
122
 
123
wire dc_ack;
124
wire acki = ack_i|dc_ack;
125
wire [RBIT:0] Ra0, Ra1;
126
wire [RBIT:0] Rb0, Rb1;
127
wire [RBIT:0] Rc0, Rc1;
128
wire [RBIT:0] Rt0, Rt1;
129
wire [63:0] rfoa0,rfob0,rfoc0,rfoc0a;
130
wire [63:0] rfoa1,rfob1,rfoc1,rfoc1a;
131
`ifdef SUPPORT_SMT
132
wire [7:0] Ra0s = {Ra0[7:0]};
133
wire [7:0] Ra1s = {Ra1[7:0]};
134
wire [7:0] Rb0s = {Rb0[7:0]};
135
wire [7:0] Rb1s = {Rb1[7:0]};
136
wire [7:0] Rc0s = {Rc0[7:0]};
137
wire [7:0] Rc1s = {Rc1[7:0]};
138
wire [7:0] Rt0s = {Rt0[7:0]};
139
wire [7:0] Rt1s = {Rt1[7:0]};
140
`else
141
wire [6:0] Ra0s = {Ra0[7],Ra0[5:0]};
142
wire [6:0] Ra1s = {Ra1[7],Ra1[5:0]};
143
wire [6:0] Rb0s = {Rb0[7],Rb0[5:0]};
144
wire [6:0] Rb1s = {Rb1[7],Rb1[5:0]};
145
wire [6:0] Rc0s = {Rc0[7],Rc0[5:0]};
146
wire [6:0] Rc1s = {Rc1[7],Rc1[5:0]};
147
wire [6:0] Rt0s = {Rt0[7],Rt0[5:0]};
148
wire [6:0] Rt1s = {Rt1[7],Rt1[5:0]};
149
/*
150
wire [5:0] Ra0s = {Ra0[5:0]};
151
wire [5:0] Ra1s = {Ra1[5:0]};
152
wire [5:0] Rb0s = {Rb0[5:0]};
153
wire [5:0] Rb1s = {Rb1[5:0]};
154
wire [5:0] Rc0s = {Rc0[5:0]};
155
wire [5:0] Rc1s = {Rc1[5:0]};
156
wire [5:0] Rt0s = {Rt0[5:0]};
157
wire [5:0] Rt1s = {Rt1[5:0]};
158
*/
159
`endif
160
 
161
reg [63:0] ds [0:NTHREAD];
162
reg [63:0] ss [0:NTHREAD];
163
reg [63:0] ptrmask [0:NTHREAD];
164
reg [63:0] ptrkey = "  OBJECT";
165
reg [63:0] wbrcd;
166
 
167
reg  [PREGS-1:0] rf_v;
168
reg  [4:0] rf_source[0:AREGS-1];
169
initial begin
170
for (n = 0; n < AREGS; n = n + 1)
171
        rf_source[n] = 5'd0;
172
end
173 49 robfinch
wire [`ABITS] pc0;
174
wire [`ABITS] pc1;
175
wire [`ABITS] pc2;
176 48 robfinch
 
177
reg excmiss;
178 49 robfinch
reg [`ABITS] excmisspc;
179 48 robfinch
reg excthrd;
180
reg exception_set;
181
reg rdvq;               // accumulated read violation
182
reg errq;               // accumulated err_i input status
183
reg exvq;
184
 
185
// Vector
186
reg [5:0] vqe0, vqe1;   // vector element being queued
187
reg [5:0] vqet0, vqet1;
188
reg [7:0] vl;           // vector length
189
reg [63:0] vm [0:7];    // vector mask registers
190
reg [1:0] m2;
191
 
192 49 robfinch
reg [31:0] wb_merges;
193 48 robfinch
// CSR's
194
reg [63:0] cr0;
195
wire snr = cr0[17];             // sequence number reset
196
wire dce = cr0[30];     // data cache enable
197
wire bpe = cr0[32];     // branch predictor enable
198
wire ctgtxe = cr0[33];
199 49 robfinch
reg [63:0] pmr;
200
wire id1_available = pmr[0];
201
wire id2_available = pmr[1];
202
wire id3_available = pmr[2];
203
wire alu0_available = pmr[8];
204
wire alu1_available = pmr[9];
205
wire fpu1_available = pmr[16];
206
wire fpu2_available = pmr[17];
207
wire mem1_available = pmr[24];
208
wire mem2_available = pmr[25];
209
wire mem3_available = pmr[26];
210
wire fcu_available = pmr[32];
211 48 robfinch
// Simply setting this flag to zero should strip out almost all the logic
212
// associated SMT.
213
`ifdef SUPPORT_SMT
214
wire thread_en = cr0[16];
215
`else
216
wire thread_en = 1'b0;
217
`endif
218
wire vechain = cr0[18];
219
reg [7:0] fcu_timeout;
220
reg [63:0] tick;
221
reg [63:0] wc_time;
222
reg [31:0] pcr;
223
reg [63:0] pcr2;
224
assign pcr_o = pcr;
225
assign pcr2_o = pcr2;
226
reg [63:0] aec;
227
reg [15:0] cause[0:15];
228
`ifdef SUPPORT_SMT
229 49 robfinch
reg [`ABITS] epc [0:NTHREAD];
230
reg [`ABITS] epc0 [0:NTHREAD];
231
reg [`ABITS] epc1 [0:NTHREAD];
232
reg [`ABITS] epc2 [0:NTHREAD];
233
reg [`ABITS] epc3 [0:NTHREAD];
234
reg [`ABITS] epc4 [0:NTHREAD];
235
reg [`ABITS] epc5 [0:NTHREAD];
236
reg [`ABITS] epc6 [0:NTHREAD];
237
reg [`ABITS] epc7 [0:NTHREAD];
238
reg [`ABITS] epc8 [0:NTHREAD];                   // exception pc and stack
239 48 robfinch
reg [63:0] mstatus [0:NTHREAD];           // machine status
240 49 robfinch
wire [3:0] im = mstatus[0][3:0];
241 48 robfinch
wire [1:0] ol [0:NTHREAD];
242
wire [1:0] dl [0:NTHREAD];
243
assign ol[0] = mstatus[0][5:3];   // operating level
244
assign dl[0] = mstatus[0][21:20];
245
wire [7:0] cpl [0:NTHREAD];
246
assign cpl[0] = mstatus[0][13:6]; // current privilege level
247
wire [5:0] rgs [0:NTHREAD];
248
assign rgs[0] = mstatus[0][19:14];
249
assign ol[1] = mstatus[1][5:3]; // operating level
250
assign cpl[1] = mstatus[1][13:6];       // current privilege level
251
assign rgs[1] = mstatus[1][19:14];
252
assign dl[1] = mstatus[1][21:20];
253
reg [15:0] ol_stack [0:NTHREAD];
254
reg [31:0] im_stack [0:NTHREAD];
255
reg [63:0] pl_stack [0:NTHREAD];
256
reg [63:0] rs_stack [0:NTHREAD];
257
reg [63:0] fr_stack [0:NTHREAD];
258
wire mprv = mstatus[0][55];
259
wire [5:0] fprgs = mstatus[0][25:20];
260
//assign ol_o = mprv ? ol_stack[0][2:0] : ol[0];
261
wire vca = mstatus[0][32];               // vector chaining active
262
`else
263 49 robfinch
reg [`ABITS] epc ;
264
reg [`ABITS] epc0 ;
265
reg [`ABITS] epc1 ;
266
reg [`ABITS] epc2 ;
267
reg [`ABITS] epc3 ;
268
reg [`ABITS] epc4 ;
269
reg [`ABITS] epc5 ;
270
reg [`ABITS] epc6 ;
271
reg [`ABITS] epc7 ;
272
reg [`ABITS] epc8 ;                     // exception pc and stack
273 48 robfinch
reg [63:0] mstatus ;             // machine status
274 49 robfinch
wire [3:0] im = mstatus[3:0];
275 48 robfinch
wire [1:0] ol ;
276
wire [1:0] dl;
277
assign ol = mstatus[5:3];       // operating level
278
assign dl = mstatus[21:20];
279
wire [7:0] cpl ;
280
assign cpl = mstatus[13:6];     // current privilege level
281
wire [5:0] rgs ;
282
assign rgs = mstatus[19:14];
283
reg [15:0] ol_stack ;
284
reg [31:0] im_stack ;
285
reg [63:0] pl_stack ;
286
reg [63:0] rs_stack ;
287
reg [63:0] fr_stack ;
288
wire mprv = mstatus[55];
289
wire [5:0] fprgs = mstatus[25:20];
290
//assign ol_o = mprv ? ol_stack[2:0] : ol;
291
wire vca = mstatus[32];         // vector chaining active
292
`endif
293
reg [63:0] tcb;
294 49 robfinch
reg [`ABITS] badaddr[0:15];
295
reg [`ABITS] tvec[0:7];
296 48 robfinch
reg [63:0] sema;
297
reg [63:0] vm_sema;
298
reg [63:0] cas;         // compare and swap
299
reg [63:0] ve_hold;
300
reg isCAS, isAMO, isInc, isSpt, isRMW;
301
reg [`QBITS] casid;
302 49 robfinch
reg [`ABITS] sbl, sbu;
303 48 robfinch
reg [4:0] regLR = 5'd29;
304
 
305 49 robfinch
reg [2:0] fp1_rm;
306
reg fp1_inexe;
307
reg fp1_dbzxe;
308
reg fp1_underxe;
309
reg fp1_overxe;
310
reg fp1_invopxe;
311
reg fp1_giopxe;
312
reg fp1_nsfp = 1'b0;
313
reg fp1_fractie;
314
reg fp1_raz;
315 48 robfinch
 
316 49 robfinch
reg fp1_neg;
317
reg fp1_pos;
318
reg fp1_zero;
319
reg fp1_inf;
320 48 robfinch
 
321 49 robfinch
reg fp1_inex;           // inexact exception
322
reg fp1_dbzx;           // divide by zero exception
323
reg fp1_underx;         // underflow exception
324
reg fp1_overx;          // overflow exception
325
reg fp1_giopx;          // global invalid operation exception
326
reg fp1_sx;                     // summary exception
327
reg fp1_swtx;        // software triggered exception
328
reg fp1_gx;
329
reg fp1_invopx;
330 48 robfinch
 
331 49 robfinch
reg fp1_infzerox;
332
reg fp1_zerozerox;
333
reg fp1_subinfx;
334
reg fp1_infdivx;
335
reg fp1_NaNCmpx;
336
reg fp1_cvtx;
337
reg fp1_sqrtx;
338
reg fp1_snanx;
339 48 robfinch
 
340 49 robfinch
reg [2:0] fp2_rm;
341
reg fp2_inexe;
342
reg fp2_dbzxe;
343
reg fp2_underxe;
344
reg fp2_overxe;
345
reg fp2_invopxe;
346
reg fp2_giopxe;
347
reg fp2_nsfp = 1'b0;
348
reg fp2_fractie;
349
reg fp2_raz;
350 48 robfinch
 
351 49 robfinch
reg fp2_neg;
352
reg fp2_pos;
353
reg fp2_zero;
354
reg fp2_inf;
355 48 robfinch
 
356 49 robfinch
reg fp2_inex;           // inexact exception
357
reg fp2_dbzx;           // divide by zero exception
358
reg fp2_underx;         // underflow exception
359
reg fp2_overx;          // overflow exception
360
reg fp2_giopx;          // global invalid operation exception
361
reg fp2_sx;                     // summary exception
362
reg fp2_swtx;        // software triggered exception
363
reg fp2_gx;
364
reg fp2_invopx;
365
 
366
reg fp2_infzerox;
367
reg fp2_zerozerox;
368
reg fp2_subinfx;
369
reg fp2_infdivx;
370
reg fp2_NaNCmpx;
371
reg fp2_cvtx;
372
reg fp2_sqrtx;
373
reg fp2_snanx;
374
 
375
wire [31:0] fp1_status = {
376
 
377
        fp1_rm,
378
        fp1_inexe,
379
        fp1_dbzxe,
380
        fp1_underxe,
381
        fp1_overxe,
382
        fp1_invopxe,
383
        fp1_nsfp,
384
 
385
        fp1_fractie,
386
        fp1_raz,
387 48 robfinch
        1'b0,
388 49 robfinch
        fp1_neg,
389
        fp1_pos,
390
        fp1_zero,
391
        fp1_inf,
392 48 robfinch
 
393 49 robfinch
        fp1_swtx,
394
        fp1_inex,
395
        fp1_dbzx,
396
        fp1_underx,
397
        fp1_overx,
398
        fp1_giopx,
399
        fp1_gx,
400
        fp1_sx,
401 48 robfinch
 
402 49 robfinch
        fp1_cvtx,
403
        fp1_sqrtx,
404
        fp1_NaNCmpx,
405
        fp1_infzerox,
406
        fp1_zerozerox,
407
        fp1_infdivx,
408
        fp1_subinfx,
409
        fp1_snanx
410 48 robfinch
        };
411
 
412 49 robfinch
wire [31:0] fp2_status = {
413 48 robfinch
 
414 49 robfinch
        fp2_rm,
415
        fp2_inexe,
416
        fp2_dbzxe,
417
        fp2_underxe,
418
        fp2_overxe,
419
        fp2_invopxe,
420
        fp2_nsfp,
421
 
422
        fp2_fractie,
423
        fp2_raz,
424
        1'b0,
425
        fp2_neg,
426
        fp2_pos,
427
        fp2_zero,
428
        fp2_inf,
429
 
430
        fp2_swtx,
431
        fp2_inex,
432
        fp2_dbzx,
433
        fp2_underx,
434
        fp2_overx,
435
        fp2_giopx,
436
        fp2_gx,
437
        fp2_sx,
438
 
439
        fp2_cvtx,
440
        fp2_sqrtx,
441
        fp2_NaNCmpx,
442
        fp2_infzerox,
443
        fp2_zerozerox,
444
        fp2_infdivx,
445
        fp2_subinfx,
446
        fp2_snanx
447
};
448
 
449
reg [63:0] fpu1_csr;
450
wire [5:0] fp1_rgs = fpu1_csr[37:32];
451
 
452 48 robfinch
//reg [25:0] m[0:8191];
453
reg  [3:0] panic;                // indexes the message structure
454
reg [128:0] message [0:15];       // indexed by panic
455
 
456
wire int_commit;
457
reg StatusHWI;
458 49 robfinch
reg [47:0] insn0, insn1, insn2;
459
wire [47:0] insn0a, insn1a, insn1b, insn2a, insn2b;
460 48 robfinch
reg tgtq;
461
// Only need enough bits in the seqnence number to cover the instructions in
462
// the queue plus an extra count for skipping on branch misses. In this case
463
// that would be four bits minimum (count 0 to 8). 
464
reg [31:0] seq_num;
465
reg [31:0] seq_num1;
466
wire [63:0] rdat0,rdat1,rdat2;
467
reg [63:0] xdati;
468
 
469
reg canq1, canq2;
470
reg queued1;
471
reg queued2;
472
reg queuedNop;
473
 
474
reg [47:0] codebuf[0:63];
475
reg [7:0] setpred;
476
 
477
// instruction queue (ROB)
478
reg [31:0]  iqentry_sn   [0:QENTRIES-1];  // instruction sequence number
479
reg [QENTRIES-1:0] iqentry_v;                    // entry valid?  -- this should be the first bit
480
reg [QENTRIES-1:0] iqentry_iv;           // instruction is valid
481
reg [4:0]  iqentry_is   [0:QENTRIES-1];   // source of instruction
482
reg [QENTRIES-1:0] iqentry_out;  // instruction has been issued to an ALU ... 
483
reg [QENTRIES-1:0] iqentry_done; // instruction result valid
484
reg [QENTRIES-1:0] iqentry_cmt;
485
reg [QENTRIES-1:0] iqentry_thrd;         // which thread the instruction is in
486
reg [QENTRIES-1:0] iqentry_pt;           // predict taken
487
reg [QENTRIES-1:0] iqentry_bt;   // branch-taken (used only for branches)
488
reg [QENTRIES-1:0] iqentry_agen; // address-generate ... signifies that address is ready (only for LW/SW)
489
reg  [1:0] iqentry_state [0:QENTRIES-1];
490
reg [QENTRIES-1:0] iqentry_alu = 8'h00;  // alu type instruction
491
reg [QENTRIES-1:0] iqentry_alu0;  // only valid on alu #0
492
reg [QENTRIES-1:0] iqentry_fpu;  // floating point instruction
493
reg [QENTRIES-1:0] iqentry_fc;   // flow control instruction
494
reg [QENTRIES-1:0] iqentry_canex = 8'h00;        // true if it's an instruction that can exception
495 49 robfinch
reg [QENTRIES-1:0] iqentry_load; // is a memory load instruction
496
reg [QENTRIES-1:0] iqentry_preload;      // is a memory preload instruction
497
reg [QENTRIES-1:0] iqentry_ldcmp;
498
reg [QENTRIES-1:0] iqentry_mem;  // touches memory: 1 if LW/SW
499
reg [QENTRIES-1:0] iqentry_memndx;  // indexed memory operation 
500
reg [QENTRIES-1:0] iqentry_rmw;  // memory RMW op
501
reg [QENTRIES-1:0] iqentry_memdb;
502
reg [QENTRIES-1:0] iqentry_memsb;
503
reg [QENTRIES-1:0] iqentry_rtop;
504 48 robfinch
reg [QENTRIES-1:0] iqentry_sei;
505
reg [QENTRIES-1:0] iqentry_aq;   // memory aquire
506
reg [QENTRIES-1:0] iqentry_rl;   // memory release
507 49 robfinch
reg [QENTRIES-1:0] iqentry_shft48;
508
reg [QENTRIES-1:0] iqentry_jmp;  // changes control flow: 1 if BEQ/JALR
509 48 robfinch
reg [QENTRIES-1:0] iqentry_br;  // Bcc (for predictor)
510 49 robfinch
reg [QENTRIES-1:0] iqentry_sync;  // sync instruction
511
reg [QENTRIES-1:0] iqentry_fsync;
512 48 robfinch
reg [QENTRIES-1:0] iqentry_rfw = 8'h00;  // writes to register file
513
reg  [7:0] iqentry_we   [0:QENTRIES-1];   // enable strobe
514
reg [63:0] iqentry_res   [0:QENTRIES-1];  // instruction result
515
reg [47:0] iqentry_instr[0:QENTRIES-1];   // instruction opcode
516
reg  [2:0] iqentry_insln[0:QENTRIES-1]; // instruction length
517
reg  [7:0] iqentry_exc   [0:QENTRIES-1];  // only for branches ... indicates a HALT instruction
518
reg [RBIT:0] iqentry_tgt [0:QENTRIES-1];  // Rt field or ZERO -- this is the instruction's target (if any)
519
reg  [7:0] iqentry_vl   [0:QENTRIES-1];
520
reg  [5:0] iqentry_ven  [0:QENTRIES-1];  // vector element number
521
reg [63:0] iqentry_a0    [0:QENTRIES-1];  // argument 0 (immediate)
522
reg [63:0] iqentry_a1    [0:QENTRIES-1];  // argument 1
523
reg        iqentry_a1_v [0:QENTRIES-1];  // arg1 valid
524
reg  [4:0] iqentry_a1_s  [0:QENTRIES-1];  // arg1 source (iq entry # with top bit representing ALU/DRAM bus)
525
reg [63:0] iqentry_a2    [0:QENTRIES-1];  // argument 2
526
reg        iqentry_a2_v [0:QENTRIES-1];  // arg2 valid
527
reg  [4:0] iqentry_a2_s  [0:QENTRIES-1];  // arg2 source (iq entry # with top bit representing ALU/DRAM bus)
528
reg [63:0] iqentry_a3    [0:QENTRIES-1];  // argument 3
529
reg        iqentry_a3_v [0:QENTRIES-1];  // arg3 valid
530
reg  [4:0] iqentry_a3_s  [0:QENTRIES-1];  // arg3 source (iq entry # with top bit representing ALU/DRAM bus)
531 49 robfinch
reg [`ABITS] iqentry_pc [0:QENTRIES-1];  // program counter for this instruction
532 48 robfinch
reg [RBIT:0] iqentry_Ra [0:QENTRIES-1];
533
reg [RBIT:0] iqentry_Rb [0:QENTRIES-1];
534
reg [RBIT:0] iqentry_Rc [0:QENTRIES-1];
535
// debugging
536
//reg  [4:0] iqentry_ra   [0:7];  // Ra
537
initial begin
538
for (n = 0; n < QENTRIES; n = n + 1)
539
        iqentry_a1_s[n] = 5'd0;
540
        iqentry_a2_s[n] = 5'd0;
541
        iqentry_a3_s[n] = 5'd0;
542
end
543
 
544
wire  [QENTRIES-1:0] iqentry_source = 8'h00;
545
reg   [QENTRIES-1:0] iqentry_imm;
546
wire  [QENTRIES-1:0] iqentry_memready;
547
wire  [QENTRIES-1:0] iqentry_memopsvalid;
548
 
549
reg  [QENTRIES-1:0] memissue = 8'h00;
550
reg [1:0] missued;
551
integer last_issue;
552
reg  [QENTRIES-1:0] iqentry_memissue;
553
wire [QENTRIES-1:0] iqentry_stomp;
554
reg [3:0] stompedOnRets;
555
reg  [QENTRIES-1:0] iqentry_alu0_issue;
556
reg  [QENTRIES-1:0] iqentry_alu1_issue;
557 49 robfinch
reg  [QENTRIES-1:0] iqentry_alu2_issue;
558 48 robfinch
reg  [QENTRIES-1:0] iqentry_id1issue;
559
reg  [QENTRIES-1:0] iqentry_id2issue;
560 49 robfinch
reg  [QENTRIES-1:0] iqentry_id3issue;
561 48 robfinch
reg [1:0] iqentry_mem_islot [0:QENTRIES-1];
562
reg [QENTRIES-1:0] iqentry_fcu_issue;
563 49 robfinch
reg [QENTRIES-1:0] iqentry_fpu1_issue;
564
reg [QENTRIES-1:0] iqentry_fpu2_issue;
565 48 robfinch
 
566
wire [PREGS-1:1] livetarget;
567
wire  [PREGS-1:1] iqentry_0_livetarget;
568
wire  [PREGS-1:1] iqentry_1_livetarget;
569
wire  [PREGS-1:1] iqentry_2_livetarget;
570
wire  [PREGS-1:1] iqentry_3_livetarget;
571
wire  [PREGS-1:1] iqentry_4_livetarget;
572
wire  [PREGS-1:1] iqentry_5_livetarget;
573
wire  [PREGS-1:1] iqentry_6_livetarget;
574
wire  [PREGS-1:1] iqentry_7_livetarget;
575
wire  [PREGS-1:1] iqentry_0_latestID;
576
wire  [PREGS-1:1] iqentry_1_latestID;
577
wire  [PREGS-1:1] iqentry_2_latestID;
578
wire  [PREGS-1:1] iqentry_3_latestID;
579
wire  [PREGS-1:1] iqentry_4_latestID;
580
wire  [PREGS-1:1] iqentry_5_latestID;
581
wire  [PREGS-1:1] iqentry_6_latestID;
582
wire  [PREGS-1:1] iqentry_7_latestID;
583
wire  [PREGS-1:1] iqentry_0_cumulative;
584
wire  [PREGS-1:1] iqentry_1_cumulative;
585
wire  [PREGS-1:1] iqentry_2_cumulative;
586
wire  [PREGS-1:1] iqentry_3_cumulative;
587
wire  [PREGS-1:1] iqentry_4_cumulative;
588
wire  [PREGS-1:1] iqentry_5_cumulative;
589
wire  [PREGS-1:1] iqentry_6_cumulative;
590
wire  [PREGS-1:1] iqentry_7_cumulative;
591
wire  [PREGS-1:1] iq0_out;
592
wire  [PREGS-1:1] iq1_out;
593
wire  [PREGS-1:1] iq2_out;
594
wire  [PREGS-1:1] iq3_out;
595
wire  [PREGS-1:1] iq4_out;
596
wire  [PREGS-1:1] iq5_out;
597
wire  [PREGS-1:1] iq6_out;
598
wire  [PREGS-1:1] iq7_out;
599
 
600
reg  [`QBITS] tail0;
601
reg  [`QBITS] tail1;
602
reg  [`QBITS] head0;
603
reg  [`QBITS] head1;
604
reg  [`QBITS] head2;    // used only to determine memory-access ordering
605
reg  [`QBITS] head3;    // used only to determine memory-access ordering
606
reg  [`QBITS] head4;    // used only to determine memory-access ordering
607
reg  [`QBITS] head5;    // used only to determine memory-access ordering
608
reg  [`QBITS] head6;    // used only to determine memory-access ordering
609
reg  [`QBITS] head7;    // used only to determine memory-access ordering
610
 
611
wire take_branch0;
612
wire take_branch1;
613
 
614
reg [3:0] nop_fetchbuf;
615
wire        fetchbuf;   // determines which pair to read from & write to
616 49 robfinch
wire [3:0] fb_panic;
617 48 robfinch
 
618
wire [47:0] fetchbuf0_instr;
619
wire  [2:0] fetchbuf0_insln;
620 49 robfinch
wire [`ABITS] fetchbuf0_pc;
621 48 robfinch
wire        fetchbuf0_v;
622
wire            fetchbuf0_thrd;
623
wire        fetchbuf0_mem;
624
wire            fetchbuf0_memld;
625
wire        fetchbuf0_jmp;
626
wire        fetchbuf0_rfw;
627
wire [47:0] fetchbuf1_instr;
628
wire  [2:0] fetchbuf1_insln;
629 49 robfinch
wire [`ABITS] fetchbuf1_pc;
630 48 robfinch
wire        fetchbuf1_v;
631
wire            fetchbuf1_thrd;
632
wire        fetchbuf1_mem;
633
wire            fetchbuf1_memld;
634
wire        fetchbuf1_jmp;
635
wire        fetchbuf1_rfw;
636
 
637
wire [47:0] fetchbufA_instr;
638 49 robfinch
wire [`ABITS] fetchbufA_pc;
639 48 robfinch
wire        fetchbufA_v;
640
wire [47:0] fetchbufB_instr;
641 49 robfinch
wire [`ABITS] fetchbufB_pc;
642 48 robfinch
wire        fetchbufB_v;
643
wire [47:0] fetchbufC_instr;
644 49 robfinch
wire [`ABITS] fetchbufC_pc;
645 48 robfinch
wire        fetchbufC_v;
646
wire [47:0] fetchbufD_instr;
647 49 robfinch
wire [`ABITS] fetchbufD_pc;
648 48 robfinch
wire        fetchbufD_v;
649
 
650
//reg        did_branchback0;
651
//reg        did_branchback1;
652
 
653
reg         id1_v;
654
reg   [4:0] id1_id;
655
reg  [47:0] id1_instr;
656
reg   [5:0] id1_ven;
657
reg   [7:0] id1_vl;
658
reg         id1_thrd;
659
reg         id1_pt;
660
reg   [4:0] id1_Rt;
661
wire [127:0] id1_bus;
662
 
663
reg         id2_v;
664
reg   [4:0] id2_id;
665
reg  [47:0] id2_instr;
666
reg   [5:0] id2_ven;
667
reg   [7:0] id2_vl;
668
reg         id2_thrd;
669
reg         id2_pt;
670
reg   [4:0] id2_Rt;
671
wire [127:0] id2_bus;
672
 
673 49 robfinch
reg         id3_v;
674
reg   [4:0] id3_id;
675
reg  [47:0] id3_instr;
676
reg   [5:0] id3_ven;
677
reg   [7:0] id3_vl;
678
reg         id3_thrd;
679
reg         id3_pt;
680
reg   [4:0] id3_Rt;
681
wire [127:0] id3_bus;
682
 
683 48 robfinch
reg        alu0_ld;
684
reg        alu0_dataready;
685
wire       alu0_done;
686
wire       alu0_idle;
687
reg  [3:0] alu0_sourceid;
688
reg [47:0] alu0_instr;
689
reg        alu0_bt;
690
reg        alu0_mem;
691
reg        alu0_shft48;
692
reg [63:0] alu0_argA;
693
reg [63:0] alu0_argB;
694
reg [63:0] alu0_argC;
695
reg [63:0] alu0_argI;    // only used by BEQ
696
reg [RBIT:0] alu0_tgt;
697
reg [5:0]  alu0_ven;
698
reg        alu0_thrd;
699 49 robfinch
reg [`ABITS] alu0_pc;
700 48 robfinch
wire [63:0] alu0_bus;
701
wire [63:0] alu0b_bus;
702
wire  [3:0] alu0_id;
703 49 robfinch
wire  [`XBITS] alu0_exc;
704 48 robfinch
wire        alu0_v;
705
wire        alu0_branchmiss;
706 49 robfinch
wire [`ABITS] alu0_misspc;
707 48 robfinch
 
708
reg        alu1_ld;
709
reg        alu1_dataready;
710
wire       alu1_done;
711
wire       alu1_idle;
712
reg  [3:0] alu1_sourceid;
713
reg [47:0] alu1_instr;
714
reg        alu1_bt;
715
reg        alu1_mem;
716
reg        alu1_shft48;
717
reg [63:0] alu1_argA;
718
reg [63:0] alu1_argB;
719
reg [63:0] alu1_argC;
720
reg [63:0] alu1_argI;    // only used by BEQ
721
reg [RBIT:0] alu1_tgt;
722
reg [5:0]  alu1_ven;
723 49 robfinch
reg [`ABITS] alu1_pc;
724 48 robfinch
reg        alu1_thrd;
725
wire [63:0] alu1_bus;
726
wire [63:0] alu1b_bus;
727
wire  [3:0] alu1_id;
728 49 robfinch
wire  [`XBITS] alu1_exc;
729 48 robfinch
wire        alu1_v;
730
wire        alu1_branchmiss;
731 49 robfinch
wire [`ABITS] alu1_misspc;
732 48 robfinch
 
733 49 robfinch
reg        fpu1_ld;
734
reg        fpu1_dataready = 1'b1;
735
wire       fpu1_done = 1'b1;
736
wire       fpu1_idle;
737
reg  [3:0] fpu1_sourceid;
738
reg [47:0] fpu1_instr;
739
reg [63:0] fpu1_argA;
740
reg [63:0] fpu1_argB;
741
reg [63:0] fpu1_argC;
742
reg [63:0] fpu1_argI;    // only used by BEQ
743
reg [RBIT:0] fpu1_tgt;
744
reg [`ABITS] fpu1_pc;
745
wire [63:0] fpu1_bus;
746
wire  [3:0] fpu1_id;
747
wire  [`XBITS] fpu1_exc = 9'h000;
748
wire        fpu1_v;
749
wire [31:0] fpu1_status;
750 48 robfinch
 
751 49 robfinch
reg        fpu2_ld;
752
reg        fpu2_dataready = 1'b1;
753
wire       fpu2_done = 1'b1;
754
wire       fpu2_idle;
755
reg  [3:0] fpu2_sourceid;
756
reg [47:0] fpu2_instr;
757
reg [63:0] fpu2_argA;
758
reg [63:0] fpu2_argB;
759
reg [63:0] fpu2_argC;
760
reg [63:0] fpu2_argI;    // only used by BEQ
761
reg [RBIT:0] fpu2_tgt;
762
reg [`ABITS] fpu2_pc;
763
wire [63:0] fpu2_bus;
764
wire  [3:0] fpu2_id;
765
wire  [`XBITS] fpu2_exc = 9'h000;
766
wire        fpu2_v;
767
wire [31:0] fpu2_status;
768
 
769 48 robfinch
reg [63:0] waitctr;
770
reg        fcu_ld;
771
reg        fcu_dataready;
772
reg        fcu_done;
773
reg         fcu_idle = 1'b1;
774
reg  [3:0] fcu_sourceid;
775
reg [47:0] fcu_instr;
776
reg  [2:0] fcu_insln;
777
reg        fcu_call;
778
reg        fcu_bt;
779
reg [63:0] fcu_argA;
780
reg [63:0] fcu_argB;
781
reg [63:0] fcu_argC;
782
reg [63:0] fcu_argI;     // only used by BEQ
783
reg [63:0] fcu_argT;
784
reg [63:0] fcu_argT2;
785 49 robfinch
reg [`ABITS] fcu_retadr;
786 48 robfinch
reg        fcu_retadr_v;
787 49 robfinch
reg [`ABITS] fcu_pc;
788
reg [`ABITS] fcu_nextpc;
789
reg [`ABITS] fcu_brdisp;
790 48 robfinch
wire [63:0] fcu_bus;
791
wire  [3:0] fcu_id;
792 49 robfinch
reg   [`XBITS] fcu_exc;
793 48 robfinch
wire        fcu_v;
794
reg        fcu_thrd;
795
reg        fcu_branchmiss;
796
reg  fcu_clearbm;
797 49 robfinch
reg [`ABITS] fcu_misspc;
798 48 robfinch
 
799
reg [63:0] rmw_argA;
800
reg [63:0] rmw_argB;
801
reg [63:0] rmw_argC;
802
wire [63:0] rmw_res;
803
reg [31:0] rmw_instr;
804
 
805 49 robfinch
// write buffer
806
reg [63:0] wb_data [0:`WB_DEPTH-1];
807
reg [`ABITS] wb_addr [0:`WB_DEPTH-1];
808
reg [1:0] wb_ol [0:`WB_DEPTH-1];
809
reg [`WB_DEPTH-1:0] wb_v;
810
reg [`WB_DEPTH-1:0] wb_rmw;
811
reg [QENTRIES-1:0] wb_id [0:`WB_DEPTH-1];
812
reg [QENTRIES-1:0] wbo_id;
813
reg [7:0] wb_sel [0:`WB_DEPTH-1];
814
reg wb_en;
815
 
816 48 robfinch
reg branchmiss = 1'b0;
817
reg branchmiss_thrd = 1'b0;
818 49 robfinch
reg [`ABITS] misspc;
819 48 robfinch
reg  [`QBITS] missid;
820
 
821
wire take_branch;
822
wire take_branchA;
823
wire take_branchB;
824
wire take_branchC;
825
wire take_branchD;
826
 
827
wire        dram_avail;
828
reg      [2:0] dram0;    // state of the DRAM request (latency = 4; can have three in pipeline)
829
reg      [2:0] dram1;    // state of the DRAM request (latency = 4; can have three in pipeline)
830
reg      [2:0] dram2;    // state of the DRAM request (latency = 4; can have three in pipeline)
831
reg [63:0] dram0_data;
832 49 robfinch
reg [`ABITS] dram0_addr;
833 48 robfinch
reg [31:0] dram0_seg;
834
reg [47:0] dram0_instr;
835
reg        dram0_rmw;
836
reg                dram0_preload;
837
reg [RBIT:0] dram0_tgt;
838
reg  [3:0] dram0_id;
839 49 robfinch
reg  [`XBITS] dram0_exc;
840 48 robfinch
reg        dram0_unc;
841
reg [2:0]  dram0_memsize;
842
reg        dram0_load;  // is a load operation
843
reg  [1:0] dram0_ol;
844
reg [63:0] dram1_data;
845 49 robfinch
reg [`ABITS] dram1_addr;
846 48 robfinch
reg [31:0] dram1_seg;
847
reg [47:0] dram1_instr;
848
reg        dram1_rmw;
849
reg                dram1_preload;
850
reg [RBIT:0] dram1_tgt;
851
reg  [3:0] dram1_id;
852 49 robfinch
reg  [`XBITS] dram1_exc;
853 48 robfinch
reg        dram1_unc;
854
reg [2:0]  dram1_memsize;
855
reg        dram1_load;
856
reg  [1:0] dram1_ol;
857
reg [63:0] dram2_data;
858 49 robfinch
reg [`ABITS] dram2_addr;
859 48 robfinch
reg [31:0] dram2_seg;
860
reg [47:0] dram2_instr;
861
reg        dram2_rmw;
862
reg                dram2_preload;
863
reg [RBIT:0] dram2_tgt;
864
reg  [3:0] dram2_id;
865 49 robfinch
reg  [`XBITS] dram2_exc;
866 48 robfinch
reg        dram2_unc;
867
reg [2:0]  dram2_memsize;
868
reg        dram2_load;
869
reg  [1:0] dram2_ol;
870
 
871
reg        dramA_v;
872
reg  [3:0] dramA_id;
873
reg [63:0] dramA_bus;
874 49 robfinch
reg  [`XBITS] dramA_exc;
875 48 robfinch
reg        dramB_v;
876
reg  [3:0] dramB_id;
877
reg [63:0] dramB_bus;
878 49 robfinch
reg  [`XBITS] dramB_exc;
879 48 robfinch
reg        dramC_v;
880
reg  [3:0] dramC_id;
881
reg [63:0] dramC_bus;
882 49 robfinch
reg  [`XBITS] dramC_exc;
883 48 robfinch
 
884
wire        outstanding_stores;
885
reg [63:0] I;    // instruction count
886
 
887
reg        commit0_v;
888
reg  [4:0] commit0_id;
889
reg [RBIT:0] commit0_tgt;
890
reg  [7:0] commit0_we = 8'h00;
891
reg [63:0] commit0_bus;
892
reg        commit1_v;
893
reg  [4:0] commit1_id;
894
reg [RBIT:0] commit1_tgt;
895
reg  [7:0] commit1_we = 8'h00;
896
reg [63:0] commit1_bus;
897
 
898
reg [4:0] bstate;
899
parameter BIDLE = 5'd0;
900
parameter B1 = 5'd1;
901
parameter B2 = 5'd2;
902
parameter B3 = 5'd3;
903
parameter B4 = 5'd4;
904
parameter B5 = 5'd5;
905
parameter B6 = 5'd6;
906
parameter B7 = 5'd7;
907
parameter B8 = 5'd8;
908
parameter B9 = 5'd9;
909
parameter B10 = 5'd10;
910
parameter B11 = 5'd11;
911
parameter B12 = 5'd12;
912
parameter B13 = 5'd13;
913
parameter B14 = 5'd14;
914
parameter B15 = 5'd15;
915
parameter B16 = 5'd16;
916
parameter B17 = 5'd17;
917
parameter B18 = 5'd18;
918
parameter B19 = 5'd19;
919
parameter B2a = 5'd20;
920
parameter B2b = 5'd21;
921
parameter B2c = 5'd22;
922
parameter B2d = 5'd23;
923
parameter B20 = 5'd24;
924
parameter B21 = 5'd25;
925
reg [1:0] bwhich;
926
reg [3:0] icstate,picstate;
927
parameter IDLE = 4'd0;
928
parameter IC1 = 4'd1;
929
parameter IC2 = 4'd2;
930
parameter IC3 = 4'd3;
931
parameter IC4 = 4'd4;
932
parameter IC5 = 4'd5;
933
parameter IC6 = 4'd6;
934
parameter IC7 = 4'd7;
935
parameter IC8 = 4'd8;
936
parameter IC9 = 4'd9;
937
parameter IC10 = 4'd10;
938
parameter IC3a = 4'd11;
939
reg invic, invdc;
940 49 robfinch
reg [1:0] icwhich;
941
reg icnxt,L2_nxt;
942
wire ihit0,ihit1,ihit2,ihitL2;
943
wire ihit = ihit0&ihit1&ihit2;
944 48 robfinch
reg phit;
945
wire threadx;
946
always @*
947
        phit <= ihit&&icstate==IDLE;
948
reg [2:0] iccnt;
949 49 robfinch
reg L1_wr0,L1_wr1,L1_wr2;
950 48 robfinch
reg L1_invline;
951 49 robfinch
reg [8:0] L1_en;
952 48 robfinch
reg [37:0] L1_adr, L2_adr;
953 49 robfinch
reg [287:0] L2_rdat;
954
wire [287:0] L2_dato;
955 48 robfinch
reg L2_xsel;
956
 
957
FT64_regfile2w6r_oc #(.RBIT(RBIT)) urf1
958
(
959
  .clk(clk),
960
  .clk4x(clk4x),
961
  .wr0(commit0_v),
962
  .wr1(commit1_v),
963
  .we0(commit0_we),
964
  .we1(commit1_we),
965
  .wa0(commit0_tgt),
966
  .wa1(commit1_tgt),
967
  .i0(commit0_bus),
968
  .i1(commit1_bus),
969
        .rclk(~clk),
970
        .ra0(Ra0),
971
        .ra1(Rb0),
972
        .ra2(Rc0),
973
        .ra3(Ra1),
974
        .ra4(Rb1),
975
        .ra5(Rc1),
976
        .o0(rfoa0),
977
        .o1(rfob0),
978
        .o2(rfoc0a),
979
        .o3(rfoa1),
980
        .o4(rfob1),
981
        .o5(rfoc1a)
982
);
983
assign rfoc0 = Rc0[11:6]==6'h3F ? vm[Rc0[2:0]] : rfoc0a;
984
assign rfoc1 = Rc1[11:6]==6'h3F ? vm[Rc1[2:0]] : rfoc1a;
985
 
986
function [2:0] fnInsLength;
987
input [47:0] ins;
988
case(ins[7:6])
989
2'b00:  fnInsLength = 3'd4;
990
2'b01:  fnInsLength = 3'd6;
991
2'b10:  fnInsLength = 3'd2;
992
2'b11:  fnInsLength = 3'd2;
993
endcase
994
endfunction
995
 
996 49 robfinch
wire [`ABITS] pc0plus6 = pc0 + 32'd6;
997
wire [`ABITS] pc0plus12 = pc0 + 32'd12;
998 48 robfinch
 
999
`ifdef SUPPORT_SMT
1000 49 robfinch
generate begin : gInsnVar
1001
        if (`WAYS > 1) begin
1002
                assign insn1a = insn1b;
1003
        end
1004
        if (`WAYS > 2) begin
1005
                assign insn2a = insn2b;
1006
        end
1007
end
1008
endgenerate
1009 48 robfinch
`else
1010 49 robfinch
generate begin : gInsnVar
1011
        if (`WAYS > 1) begin
1012
                assign insn1a = {insn1b,insn0a} >> {fnInsLength(insn0a),3'b0};
1013
        end
1014
        if (`WAYS > 2) begin
1015
                assign insn2a = {insn2b,insn1b,insn0a} >> {fnInsLength(insn0a) + fnInsLength(insn1a),3'b0};
1016
        end
1017
end
1018
endgenerate
1019 48 robfinch
`endif
1020
 
1021
FT64_L1_icache uic0
1022
(
1023
    .rst(rst),
1024
    .clk(clk),
1025
    .nxt(icnxt),
1026
    .wr(L1_wr0),
1027
    .en(L1_en),
1028
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc0} : L1_adr),
1029
    .wadr(L1_adr),
1030
    .i(L2_rdat),
1031
    .o(insn0a),
1032
    .hit(ihit0),
1033
    .invall(invic),
1034
    .invline(L1_invline)
1035
);
1036 49 robfinch
generate begin : gICacheInst
1037
if (`WAYS > 1) begin
1038 48 robfinch
FT64_L1_icache uic1
1039
(
1040
    .rst(rst),
1041
    .clk(clk),
1042
    .nxt(icnxt),
1043
    .wr(L1_wr1),
1044
    .en(L1_en),
1045
`ifdef SUPPORT_SMT
1046
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc1} : L1_adr),
1047
`else
1048
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc0plus6} : L1_adr),
1049
`endif
1050
    .wadr(L1_adr),
1051
    .i(L2_rdat),
1052
    .o(insn1b),
1053
    .hit(ihit1),
1054
    .invall(invic),
1055
    .invline(L1_invline)
1056
);
1057 49 robfinch
end
1058
else begin
1059
assign ihit1 = 1'b1;
1060
end
1061
if (`WAYS > 2) begin
1062
FT64_L1_icache uic2
1063
(
1064
    .rst(rst),
1065
    .clk(clk),
1066
    .nxt(icnxt),
1067
    .wr(L1_wr2),
1068
    .en(L1_en),
1069
`ifdef SUPPORT_SMT
1070
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc2} : L1_adr),
1071
`else
1072
    .adr(icstate==IDLE||icstate==IC8 ? {pcr[5:0],pc0plus12} : L1_adr),
1073
`endif
1074
    .wadr(L1_adr),
1075
    .i(L2_rdat),
1076
    .o(insn2b),
1077
    .hit(ihit2),
1078
    .invall(invic),
1079
    .invline(L1_invline)
1080
);
1081
end
1082
else
1083
assign ihit2 = 1'b1;
1084
end
1085
endgenerate
1086
 
1087 48 robfinch
FT64_L2_icache uic2
1088
(
1089
    .rst(rst),
1090
    .clk(clk),
1091
    .nxt(L2_nxt),
1092
    .wr(bstate==B7 && ack_i),
1093
    .xsel(L2_xsel),
1094
    .adr(L2_adr),
1095
    .cnt(iccnt),
1096
    .exv_i(exvq),
1097
    .i(dat_i),
1098
    .err_i(errq),
1099
    .o(L2_dato),
1100 49 robfinch
    .hit(ihitL2),
1101 48 robfinch
    .invall(invic),
1102
    .invline()
1103
);
1104
 
1105
wire predict_taken;
1106
wire predict_taken0;
1107
wire predict_taken1;
1108
wire predict_takenA;
1109
wire predict_takenB;
1110
wire predict_takenC;
1111
wire predict_takenD;
1112
wire predict_takenA1;
1113
wire predict_takenB1;
1114
wire predict_takenC1;
1115
wire predict_takenD1;
1116
 
1117 49 robfinch
wire [`ABITS] btgtA, btgtB, btgtC, btgtD;
1118 48 robfinch
wire btbwr0 = iqentry_v[head0] && iqentry_done[head0] &&
1119
        (
1120
        iqentry_instr[head0][`INSTRUCTION_OP]==`JAL ||
1121
        iqentry_instr[head0][`INSTRUCTION_OP]==`BRK ||
1122
        IsRTI(iqentry_instr[head0]));
1123
wire btbwr1 = iqentry_v[head1] && iqentry_done[head1] &&
1124
        (
1125
        iqentry_instr[head1][`INSTRUCTION_OP]==`JAL ||
1126
        iqentry_instr[head1][`INSTRUCTION_OP]==`BRK ||
1127
        IsRTI(iqentry_instr[head1]));
1128
 
1129 49 robfinch
`ifdef FCU_ENH
1130
wire fcu_clk;
1131
BUFGCE ufcuclk
1132
(
1133
        .I(clk_i),
1134
        .CE(fcu_available),
1135
        .O(fcu_clk)
1136
);
1137
`endif
1138
 
1139
`ifdef FCU_ENH
1140 48 robfinch
FT64_BTB ubtb1
1141
(
1142 49 robfinch
  .rst(rst),
1143
  .wclk(fcu_clk),
1144
  .wr(btbwr0 | btbwr1),
1145
  .wadr(btbwr0 ? iqentry_pc[head0] : iqentry_pc[head1]),
1146
  .wdat(btbwr0 ? iqentry_a0[head0] : iqentry_a0[head1]),
1147
  .valid(btbwr0 ? iqentry_bt[head0] & iqentry_v[head0] : iqentry_bt[head1] & iqentry_v[head1]),
1148
  .rclk(~clk),
1149
  .pcA(fetchbufA_pc),
1150
  .btgtA(btgtA),
1151
  .pcB(fetchbufB_pc),
1152
  .btgtB(btgtB),
1153
  .pcC(fetchbufC_pc),
1154
  .btgtC(btgtC),
1155
  .pcD(fetchbufD_pc),
1156
  .btgtD(btgtD),
1157
  .npcA(BRKPC),
1158
  .npcB(BRKPC),
1159
  .npcC(BRKPC),
1160
  .npcD(BRKPC)
1161 48 robfinch
);
1162 49 robfinch
`else
1163
// Branch tergets are picked up by fetchbuf logic and need to be present.
1164
// Without a target predictor they are just set to the reset address.
1165
// This virtually guarentees a miss.
1166
assign btgtA = RSTPC;
1167
assign btgtB = RSTPC;
1168
assign btgtC = RSTPC;
1169
assign btgtD = RSTPC;
1170
`endif
1171 48 robfinch
 
1172 49 robfinch
`ifdef FCU_ENH
1173 48 robfinch
FT64_BranchPredictor ubp1
1174
(
1175 49 robfinch
  .rst(rst),
1176
  .clk(fcu_clk),
1177
  .en(bpe),
1178
  .xisBranch0(iqentry_br[head0] & commit0_v),
1179
  .xisBranch1(iqentry_br[head1] & commit1_v),
1180
  .pcA(fetchbufA_pc),
1181
  .pcB(fetchbufB_pc),
1182
  .pcC(fetchbufC_pc),
1183
  .pcD(fetchbufD_pc),
1184
  .xpc0(iqentry_pc[head0]),
1185
  .xpc1(iqentry_pc[head1]),
1186
  .takb0(commit0_v & iqentry_res[head0][0]),
1187
  .takb1(commit1_v & iqentry_res[head1][0]),
1188
  .predict_takenA(predict_takenA),
1189
  .predict_takenB(predict_takenB),
1190
  .predict_takenC(predict_takenC),
1191
  .predict_takenD(predict_takenD)
1192 48 robfinch
);
1193 49 robfinch
`else
1194
// Predict based on sign of displacement
1195
assign predict_takenA = fetchbufA_instr[31];
1196
assign predict_takenB = fetchbufB_instr[31];
1197
assign predict_takenC = fetchbufC_instr[31];
1198
assign predict_takenD = fetchbufD_instr[31];
1199
`endif
1200 48 robfinch
 
1201
//-----------------------------------------------------------------------------
1202
// Debug
1203
//-----------------------------------------------------------------------------
1204
`ifdef SUPPORT_DBG
1205
 
1206
wire [DBW-1:0] dbg_stat1x;
1207
reg [DBW-1:0] dbg_stat;
1208
reg [DBW-1:0] dbg_ctrl;
1209
reg [ABW-1:0] dbg_adr0;
1210
reg [ABW-1:0] dbg_adr1;
1211
reg [ABW-1:0] dbg_adr2;
1212
reg [ABW-1:0] dbg_adr3;
1213
reg dbg_imatchA0,dbg_imatchA1,dbg_imatchA2,dbg_imatchA3,dbg_imatchA;
1214
reg dbg_imatchB0,dbg_imatchB1,dbg_imatchB2,dbg_imatchB3,dbg_imatchB;
1215
 
1216
wire dbg_lmatch00 =
1217
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1218
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1219
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1220
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1221
                                 dbg_ctrl[19:18]==2'b11)
1222
                                 ;
1223
wire dbg_lmatch01 =
1224
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1225
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1226
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1227
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1228
                  dbg_ctrl[19:18]==2'b11)
1229
                  ;
1230
wire dbg_lmatch02 =
1231
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1232
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1233
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1234
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1235
                dbg_ctrl[19:18]==2'b11)
1236
                ;
1237
wire dbg_lmatch10 =
1238
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1239
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1240
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1241
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1242
                  dbg_ctrl[23:22]==2'b11)
1243
                  ;
1244
wire dbg_lmatch11 =
1245
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1246
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1247
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1248
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1249
                dbg_ctrl[23:22]==2'b11)
1250
                ;
1251
wire dbg_lmatch12 =
1252
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1253
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1254
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1255
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1256
                dbg_ctrl[23:22]==2'b11)
1257
                ;
1258
wire dbg_lmatch20 =
1259
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1260
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1261
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1262
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1263
                    dbg_ctrl[27:26]==2'b11)
1264
                    ;
1265
wire dbg_lmatch21 =
1266
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1267
                   ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1268
                    (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1269
                    (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1270
                    dbg_ctrl[27:26]==2'b11)
1271
                    ;
1272
wire dbg_lmatch22 =
1273
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1274
                   ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1275
                    (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1276
                    (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1277
                    dbg_ctrl[27:26]==2'b11)
1278
                    ;
1279
wire dbg_lmatch30 =
1280
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1281
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1282
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1283
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1284
                      dbg_ctrl[31:30]==2'b11)
1285
                      ;
1286
wire dbg_lmatch31 =
1287
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1288
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1289
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1290
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1291
                    dbg_ctrl[31:30]==2'b11)
1292
                    ;
1293
wire dbg_lmatch32 =
1294
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1295
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1296
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1297
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1298
                    dbg_ctrl[31:30]==2'b11)
1299
                    ;
1300
wire dbg_lmatch0 = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30;
1301
wire dbg_lmatch1 = dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31;
1302
wire dbg_lmatch2 = dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32;
1303
wire dbg_lmatch = dbg_lmatch00|dbg_lmatch10|dbg_lmatch20|dbg_lmatch30|
1304
                  dbg_lmatch01|dbg_lmatch11|dbg_lmatch21|dbg_lmatch31|
1305
                  dbg_lmatch02|dbg_lmatch12|dbg_lmatch22|dbg_lmatch32
1306
                    ;
1307
 
1308
wire dbg_smatch00 =
1309
                        dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram0_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1310
                                ((dbg_ctrl[19:18]==2'b00 && dram0_addr[2:0]==dbg_adr0[2:0]) ||
1311
                                 (dbg_ctrl[19:18]==2'b01 && dram0_addr[2:1]==dbg_adr0[2:1]) ||
1312
                                 (dbg_ctrl[19:18]==2'b10 && dram0_addr[2]==dbg_adr0[2]) ||
1313
                                 dbg_ctrl[19:18]==2'b11)
1314
                                 ;
1315
wire dbg_smatch01 =
1316
             dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram1_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1317
                 ((dbg_ctrl[19:18]==2'b00 && dram1_addr[2:0]==dbg_adr0[2:0]) ||
1318
                  (dbg_ctrl[19:18]==2'b01 && dram1_addr[2:1]==dbg_adr0[2:1]) ||
1319
                  (dbg_ctrl[19:18]==2'b10 && dram1_addr[2]==dbg_adr0[2]) ||
1320
                  dbg_ctrl[19:18]==2'b11)
1321
                  ;
1322
wire dbg_smatch02 =
1323
           dbg_ctrl[0] && dbg_ctrl[17:16]==2'b11 && dram2_addr[AMSB:3]==dbg_adr0[AMSB:3] &&
1324
               ((dbg_ctrl[19:18]==2'b00 && dram2_addr[2:0]==dbg_adr0[2:0]) ||
1325
                (dbg_ctrl[19:18]==2'b01 && dram2_addr[2:1]==dbg_adr0[2:1]) ||
1326
                (dbg_ctrl[19:18]==2'b10 && dram2_addr[2]==dbg_adr0[2]) ||
1327
                dbg_ctrl[19:18]==2'b11)
1328
                ;
1329
wire dbg_smatch10 =
1330
             dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram0_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1331
                 ((dbg_ctrl[23:22]==2'b00 && dram0_addr[2:0]==dbg_adr1[2:0]) ||
1332
                  (dbg_ctrl[23:22]==2'b01 && dram0_addr[2:1]==dbg_adr1[2:1]) ||
1333
                  (dbg_ctrl[23:22]==2'b10 && dram0_addr[2]==dbg_adr1[2]) ||
1334
                  dbg_ctrl[23:22]==2'b11)
1335
                  ;
1336
wire dbg_smatch11 =
1337
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram1_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1338
               ((dbg_ctrl[23:22]==2'b00 && dram1_addr[2:0]==dbg_adr1[2:0]) ||
1339
                (dbg_ctrl[23:22]==2'b01 && dram1_addr[2:1]==dbg_adr1[2:1]) ||
1340
                (dbg_ctrl[23:22]==2'b10 && dram1_addr[2]==dbg_adr1[2]) ||
1341
                dbg_ctrl[23:22]==2'b11)
1342
                ;
1343
wire dbg_smatch12 =
1344
           dbg_ctrl[1] && dbg_ctrl[21:20]==2'b11 && dram2_addr[AMSB:3]==dbg_adr1[AMSB:3] &&
1345
               ((dbg_ctrl[23:22]==2'b00 && dram2_addr[2:0]==dbg_adr1[2:0]) ||
1346
                (dbg_ctrl[23:22]==2'b01 && dram2_addr[2:1]==dbg_adr1[2:1]) ||
1347
                (dbg_ctrl[23:22]==2'b10 && dram2_addr[2]==dbg_adr1[2]) ||
1348
                dbg_ctrl[23:22]==2'b11)
1349
                ;
1350
wire dbg_smatch20 =
1351
               dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram0_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1352
                   ((dbg_ctrl[27:26]==2'b00 && dram0_addr[2:0]==dbg_adr2[2:0]) ||
1353
                    (dbg_ctrl[27:26]==2'b01 && dram0_addr[2:1]==dbg_adr2[2:1]) ||
1354
                    (dbg_ctrl[27:26]==2'b10 && dram0_addr[2]==dbg_adr2[2]) ||
1355
                    dbg_ctrl[27:26]==2'b11)
1356
                    ;
1357
wire dbg_smatch21 =
1358
           dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram1_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1359
                    ((dbg_ctrl[27:26]==2'b00 && dram1_addr[2:0]==dbg_adr2[2:0]) ||
1360
                     (dbg_ctrl[27:26]==2'b01 && dram1_addr[2:1]==dbg_adr2[2:1]) ||
1361
                     (dbg_ctrl[27:26]==2'b10 && dram1_addr[2]==dbg_adr2[2]) ||
1362
                     dbg_ctrl[27:26]==2'b11)
1363
                     ;
1364
wire dbg_smatch22 =
1365
            dbg_ctrl[2] && dbg_ctrl[25:24]==2'b11 && dram2_addr[AMSB:3]==dbg_adr2[AMSB:3] &&
1366
                     ((dbg_ctrl[27:26]==2'b00 && dram2_addr[2:0]==dbg_adr2[2:0]) ||
1367
                      (dbg_ctrl[27:26]==2'b01 && dram2_addr[2:1]==dbg_adr2[2:1]) ||
1368
                      (dbg_ctrl[27:26]==2'b10 && dram2_addr[2]==dbg_adr2[2]) ||
1369
                      dbg_ctrl[27:26]==2'b11)
1370
                      ;
1371
wire dbg_smatch30 =
1372
                 dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram0_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1373
                     ((dbg_ctrl[31:30]==2'b00 && dram0_addr[2:0]==dbg_adr3[2:0]) ||
1374
                      (dbg_ctrl[31:30]==2'b01 && dram0_addr[2:1]==dbg_adr3[2:1]) ||
1375
                      (dbg_ctrl[31:30]==2'b10 && dram0_addr[2]==dbg_adr3[2]) ||
1376
                      dbg_ctrl[31:30]==2'b11)
1377
                      ;
1378
wire dbg_smatch31 =
1379
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram1_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1380
                   ((dbg_ctrl[31:30]==2'b00 && dram1_addr[2:0]==dbg_adr3[2:0]) ||
1381
                    (dbg_ctrl[31:30]==2'b01 && dram1_addr[2:1]==dbg_adr3[2:1]) ||
1382
                    (dbg_ctrl[31:30]==2'b10 && dram1_addr[2]==dbg_adr3[2]) ||
1383
                    dbg_ctrl[31:30]==2'b11)
1384
                    ;
1385
wire dbg_smatch32 =
1386
               dbg_ctrl[3] && dbg_ctrl[29:28]==2'b11 && dram2_addr[AMSB:3]==dbg_adr3[AMSB:3] &&
1387
                   ((dbg_ctrl[31:30]==2'b00 && dram2_addr[2:0]==dbg_adr3[2:0]) ||
1388
                    (dbg_ctrl[31:30]==2'b01 && dram2_addr[2:1]==dbg_adr3[2:1]) ||
1389
                    (dbg_ctrl[31:30]==2'b10 && dram2_addr[2]==dbg_adr3[2]) ||
1390
                    dbg_ctrl[31:30]==2'b11)
1391
                    ;
1392
wire dbg_smatch0 = dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30;
1393
wire dbg_smatch1 = dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31;
1394
wire dbg_smatch2 = dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32;
1395
 
1396
wire dbg_smatch =   dbg_smatch00|dbg_smatch10|dbg_smatch20|dbg_smatch30|
1397
                    dbg_smatch01|dbg_smatch11|dbg_smatch21|dbg_smatch31|
1398
                    dbg_smatch02|dbg_smatch12|dbg_smatch22|dbg_smatch32
1399
                    ;
1400
 
1401
wire dbg_stat0 = dbg_imatchA0 | dbg_imatchB0 | dbg_lmatch00 | dbg_lmatch01 | dbg_lmatch02 | dbg_smatch00 | dbg_smatch01 | dbg_smatch02;
1402
wire dbg_stat1 = dbg_imatchA1 | dbg_imatchB1 | dbg_lmatch10 | dbg_lmatch11 | dbg_lmatch12 | dbg_smatch10 | dbg_smatch11 | dbg_smatch12;
1403
wire dbg_stat2 = dbg_imatchA2 | dbg_imatchB2 | dbg_lmatch20 | dbg_lmatch21 | dbg_lmatch22 | dbg_smatch20 | dbg_smatch21 | dbg_smatch22;
1404
wire dbg_stat3 = dbg_imatchA3 | dbg_imatchB3 | dbg_lmatch30 | dbg_lmatch31 | dbg_lmatch32 | dbg_smatch30 | dbg_smatch31 | dbg_smatch32;
1405
assign dbg_stat1x = {dbg_stat3,dbg_stat2,dbg_stat1,dbg_stat0};
1406
wire debug_on = |dbg_ctrl[3:0]|dbg_ctrl[7]|dbg_ctrl[63];
1407
 
1408
always @*
1409
begin
1410
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf0_pc==dbg_adr0)
1411
        dbg_imatchA0 = `TRUE;
1412
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf0_pc==dbg_adr1)
1413
        dbg_imatchA1 = `TRUE;
1414
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf0_pc==dbg_adr2)
1415
        dbg_imatchA2 = `TRUE;
1416
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf0_pc==dbg_adr3)
1417
        dbg_imatchA3 = `TRUE;
1418
    if (dbg_imatchA0|dbg_imatchA1|dbg_imatchA2|dbg_imatchA3)
1419
        dbg_imatchA = `TRUE;
1420
end
1421
 
1422
always @*
1423
begin
1424
    if (dbg_ctrl[0] && dbg_ctrl[17:16]==2'b00 && fetchbuf1_pc==dbg_adr0)
1425
        dbg_imatchB0 = `TRUE;
1426
    if (dbg_ctrl[1] && dbg_ctrl[21:20]==2'b00 && fetchbuf1_pc==dbg_adr1)
1427
        dbg_imatchB1 = `TRUE;
1428
    if (dbg_ctrl[2] && dbg_ctrl[25:24]==2'b00 && fetchbuf1_pc==dbg_adr2)
1429
        dbg_imatchB2 = `TRUE;
1430
    if (dbg_ctrl[3] && dbg_ctrl[29:28]==2'b00 && fetchbuf1_pc==dbg_adr3)
1431
        dbg_imatchB3 = `TRUE;
1432
    if (dbg_imatchB0|dbg_imatchB1|dbg_imatchB2|dbg_imatchB3)
1433
        dbg_imatchB = `TRUE;
1434
end
1435
`endif
1436
 
1437
//-----------------------------------------------------------------------------
1438
//-----------------------------------------------------------------------------
1439
 
1440
// hirq squashes the pc increment if there's an irq.
1441
wire hirq = (irq_i > im) && ~int_commit;
1442
always @*
1443
if (hirq)
1444 49 robfinch
        insn0 <= {8'd0,3'd0,irq_i,1'b0,vec_i,2'b00,`BRK};
1445 48 robfinch
else if (phit) begin
1446 49 robfinch
        if (insn0a[`INSTRUCTION_OP]==`BRK && insn0a[23:21]==3'd0 && insn0a[7:6]==2'b00)
1447
                insn0 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1448 48 robfinch
        else
1449
                insn0 <= insn0a;
1450
end
1451
else
1452
        insn0 <= `NOP_INSN;
1453 49 robfinch
generate begin : gInsnMux
1454
if (`WAYS > 1) begin
1455 48 robfinch
always @*
1456
if (phit) begin
1457 49 robfinch
        if (insn1a[`INSTRUCTION_OP]==`BRK && insn1a[23:21]==3'd0 && insn1a[7:6]==2'b00)
1458
                insn1 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1459 48 robfinch
        else
1460
                insn1 <= insn1a;
1461
end
1462
else
1463
        insn1 <= `NOP_INSN;
1464 49 robfinch
end
1465
if (`WAYS > 2) begin
1466
always @*
1467
if (phit) begin
1468
        if (insn2a[`INSTRUCTION_OP]==`BRK && insn1a[23:21]==3'd0 && insn2a[7:6]==2'b00)
1469
                insn2 <= {8'd1,3'd0,4'b0,1'b0,`FLT_PRIV,2'b00,`BRK};
1470
        else
1471
                insn2 <= insn2a;
1472
end
1473
else
1474
        insn2 <= `NOP_INSN;
1475
end
1476
end
1477
endgenerate
1478 48 robfinch
 
1479
wire [63:0] dc0_out, dc1_out, dc2_out;
1480
assign rdat0 = dram0_unc ? xdati : dc0_out;
1481
assign rdat1 = dram1_unc ? xdati : dc1_out;
1482
assign rdat2 = dram2_unc ? xdati : dc2_out;
1483
 
1484
reg preload;
1485
reg [1:0] dccnt;
1486
wire dhit0, dhit1, dhit2;
1487
wire dhit00, dhit10, dhit20;
1488
wire dhit01, dhit11, dhit21;
1489 49 robfinch
reg [`ABITS] dc_wadr;
1490 48 robfinch
reg [63:0] dc_wdat;
1491
reg isStore;
1492
 
1493
FT64_dcache udc0
1494
(
1495
    .rst(rst),
1496
    .wclk(clk),
1497
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && dhit0)),
1498
    .sel(sel_o),
1499
    .wadr({pcr[5:0],adr_o}),
1500
    .i(bstate==B2d ? dat_i : dat_o),
1501
    .rclk(clk),
1502
    .rdsize(dram0_memsize),
1503
    .radr({pcr[5:0],dram0_addr}),
1504
    .o(dc0_out),
1505
    .hit(),
1506
    .hit0(dhit0),
1507
    .hit1()
1508
);
1509 49 robfinch
generate begin : gDCacheInst
1510
if (`NUM_MEM > 1) begin
1511 48 robfinch
FT64_dcache udc1
1512
(
1513
    .rst(rst),
1514
    .wclk(clk),
1515
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && dhit1)),
1516
    .sel(sel_o),
1517
    .wadr({pcr[5:0],adr_o}),
1518
    .i(bstate==B2d ? dat_i : dat_o),
1519
    .rclk(clk),
1520
    .rdsize(dram1_memsize),
1521
    .radr({pcr[5:0],dram1_addr}),
1522
    .o(dc1_out),
1523
    .hit(),
1524
    .hit0(dhit1),
1525
    .hit1()
1526
);
1527 49 robfinch
end
1528
if (`NUM_MEM > 2) begin
1529 48 robfinch
FT64_dcache udc2
1530
(
1531
    .rst(rst),
1532
    .wclk(clk),
1533
    .wr((bstate==B2d && ack_i)||((bstate==B1||(bstate==B19 && isStore)) && dhit2)),
1534
    .sel(sel_o),
1535
    .wadr({pcr[5:0],adr_o}),
1536
    .i(bstate==B2d ? dat_i : dat_o),
1537
    .rclk(clk),
1538
    .rdsize(dram2_memsize),
1539
    .radr({pcr[5:0],dram2_addr}),
1540
    .o(dc2_out),
1541
    .hit(),
1542
    .hit0(dhit2),
1543
    .hit1()
1544
);
1545 49 robfinch
end
1546
end
1547
endgenerate
1548 48 robfinch
 
1549
function [`QBITS] idp1;
1550
input [`QBITS] id;
1551
case(id)
1552
3'd0:   idp1 = 3'd1;
1553
3'd1:   idp1 = 3'd2;
1554
3'd2:   idp1 = 3'd3;
1555
3'd3:   idp1 = 3'd4;
1556
3'd4:   idp1 = 3'd5;
1557
3'd5:   idp1 = 3'd6;
1558
3'd6:   idp1 = 3'd7;
1559
3'd7:   idp1 = 3'd0;
1560
endcase
1561
endfunction
1562
 
1563
function [`QBITS] idp2;
1564
input [`QBITS] id;
1565
case(id)
1566
3'd0:   idp2 = 3'd2;
1567
3'd1:   idp2 = 3'd3;
1568
3'd2:   idp2 = 3'd4;
1569
3'd3:   idp2 = 3'd5;
1570
3'd4:   idp2 = 3'd6;
1571
3'd5:   idp2 = 3'd7;
1572
3'd6:   idp2 = 3'd0;
1573
3'd7:   idp2 = 3'd1;
1574
endcase
1575
endfunction
1576
 
1577
function [`QBITS] idp3;
1578
input [`QBITS] id;
1579
case(id)
1580
3'd0:   idp3 = 3'd3;
1581
3'd1:   idp3 = 3'd4;
1582
3'd2:   idp3 = 3'd5;
1583
3'd3:   idp3 = 3'd6;
1584
3'd4:   idp3 = 3'd7;
1585
3'd5:   idp3 = 3'd0;
1586
3'd6:   idp3 = 3'd1;
1587
3'd7:   idp3 = 3'd2;
1588
endcase
1589
endfunction
1590
 
1591
function [`QBITS] idp4;
1592
input [`QBITS] id;
1593
case(id)
1594
3'd0:   idp4 = 3'd4;
1595
3'd1:   idp4 = 3'd5;
1596
3'd2:   idp4 = 3'd6;
1597
3'd3:   idp4 = 3'd7;
1598
3'd4:   idp4 = 3'd0;
1599
3'd5:   idp4 = 3'd1;
1600
3'd6:   idp4 = 3'd2;
1601
3'd7:   idp4 = 3'd3;
1602
endcase
1603
endfunction
1604
 
1605
function [`QBITS] idp5;
1606
input [`QBITS] id;
1607
case(id)
1608
3'd0:   idp5 = 3'd5;
1609
3'd1:   idp5 = 3'd6;
1610
3'd2:   idp5 = 3'd7;
1611
3'd3:   idp5 = 3'd0;
1612
3'd4:   idp5 = 3'd1;
1613
3'd5:   idp5 = 3'd2;
1614
3'd6:   idp5 = 3'd3;
1615
3'd7:   idp5 = 3'd4;
1616
endcase
1617
endfunction
1618
 
1619
function [`QBITS] idp6;
1620
input [`QBITS] id;
1621
case(id)
1622
3'd0:   idp6 = 3'd6;
1623
3'd1:   idp6 = 3'd7;
1624
3'd2:   idp6 = 3'd0;
1625
3'd3:   idp6 = 3'd1;
1626
3'd4:   idp6 = 3'd2;
1627
3'd5:   idp6 = 3'd3;
1628
3'd6:   idp6 = 3'd4;
1629
3'd7:   idp6 = 3'd5;
1630
endcase
1631
endfunction
1632
 
1633
function [`QBITS] idp7;
1634
input [`QBITS] id;
1635
case(id)
1636
3'd0:   idp7 = 3'd7;
1637
3'd1:   idp7 = 3'd0;
1638
3'd2:   idp7 = 3'd1;
1639
3'd3:   idp7 = 3'd2;
1640
3'd4:   idp7 = 3'd3;
1641
3'd5:   idp7 = 3'd4;
1642
3'd6:   idp7 = 3'd5;
1643
3'd7:   idp7 = 3'd6;
1644
endcase
1645
endfunction
1646
 
1647
function [`QBITS] idm1;
1648
input [`QBITS] id;
1649
case(id)
1650
3'd0:   idm1 = 3'd7;
1651
3'd1:   idm1 = 3'd0;
1652
3'd2:   idm1 = 3'd1;
1653
3'd3:   idm1 = 3'd2;
1654
3'd4:   idm1 = 3'd3;
1655
3'd5:   idm1 = 3'd4;
1656
3'd6:   idm1 = 3'd5;
1657
3'd7:   idm1 = 3'd6;
1658
endcase
1659
endfunction
1660
 
1661
`ifdef SUPPORT_SMT
1662
function [RBIT:0] fnRa;
1663
input [47:0] isn;
1664
input [5:0] vqei;
1665
input [5:0] vli;
1666
input thrd;
1667
case(isn[`INSTRUCTION_OP])
1668
`IVECTOR:
1669
        case(isn[`INSTRUCTION_S2])
1670
        `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1671
        `VMxx:
1672
                case(isn[25:23])
1673
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
1674
                    fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1675
            `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1676
            default:fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1677
            endcase
1678
        `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
1679
        `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
1680
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1681
        default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1682
        endcase
1683
`R2:    case(isn[`INSTRUCTION_S2])
1684
                `MOV:
1685
                        case(isn[25:23])
1686
                        3'd0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1687
                        3'd1:   fnRa = {isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
1688
                        3'd2:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1689
                        3'd3:   fnRa = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RA]};
1690
                        3'd4:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1691 49 robfinch
                        3'd5:   fnRa = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1692
                        3'd6:   fnRa = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1693 48 robfinch
                        default:fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1694
                        endcase
1695
        `VMOV:
1696
            case (isn[`INSTRUCTION_S1])
1697
            5'h0:   fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1698
            5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
1699
            endcase
1700
        default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1701
        endcase
1702 49 robfinch
`FLOAT:         fnRa = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1703 48 robfinch
default:    fnRa = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1704
endcase
1705
endfunction
1706
 
1707
function [RBIT:0] fnRb;
1708
input [47:0] isn;
1709
input fb;
1710
input [5:0] vqei;
1711
input [5:0] rfoa0i;
1712
input [5:0] rfoa1i;
1713
input thrd;
1714
case(isn[`INSTRUCTION_OP])
1715
`R2:        case(isn[`INSTRUCTION_S2])
1716
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
1717
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1718
            default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1719
            endcase
1720
`IVECTOR:
1721
                        case(isn[`INSTRUCTION_S2])
1722
                        `VMxx:
1723
                                case(isn[25:23])
1724
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
1725
                        fnRb = {6'h3F,1'b1,2'b0,isn[13:11]};
1726
                default:        fnRb = 12'h000;
1727
                endcase
1728
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1729
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1730
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
1731
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
1732
                fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1733
            `VSHL,`VSHR,`VASR:
1734
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
1735
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1736
            endcase
1737 49 robfinch
`FLOAT:         fnRb = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1738 48 robfinch
default:    fnRb = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1739
endcase
1740
endfunction
1741
 
1742
function [RBIT:0] fnRc;
1743
input [47:0] isn;
1744
input [5:0] vqei;
1745
input thrd;
1746
case(isn[`INSTRUCTION_OP])
1747
`R2:        case(isn[`INSTRUCTION_S2])
1748
            `SVX:       fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1749
                `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1750
                        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1751
                `CMOVEZ,`CMOVNZ,`MAJ:
1752
                        fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1753
            default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1754
            endcase
1755
`IVECTOR:
1756
                        case(isn[`INSTRUCTION_S2])
1757
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[18:16]};
1758
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1759
            endcase
1760 49 robfinch
`FLOAT:         fnRc = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1761 48 robfinch
default:    fnRc = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1762
endcase
1763
endfunction
1764
 
1765
function [RBIT:0] fnRt;
1766
input [47:0] isn;
1767
input [5:0] vqei;
1768
input [5:0] vli;
1769
input thrd;
1770
casez(isn[`INSTRUCTION_OP])
1771
`IVECTOR:
1772
                case(isn[`INSTRUCTION_S2])
1773
                `VMxx:
1774
                        case(isn[25:23])
1775
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
1776
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1777
            `VMPOP:     fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1778
            default:
1779
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1780
            endcase
1781
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1782
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
1783
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
1784
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
1785
        `V2BITS:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1786
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1787
        endcase
1788
 
1789
`R2:    case(isn[`INSTRUCTION_S2])
1790
                `MOV:
1791
                        case(isn[25:23])
1792
                        3'd0:   fnRt = {isn[22:18],1'b0,isn[`INSTRUCTION_RB]};
1793
                        3'd1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1794
                        3'd2:   fnRt = {rs_stack[thrd][5:0],1'b0,isn[`INSTRUCTION_RB]};
1795
                        3'd3:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1796 49 robfinch
                        3'd4:   fnRt = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1797 48 robfinch
                        3'd5:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1798 49 robfinch
                        3'd6:   fnRt = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1799 48 robfinch
                        default:fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1800
                        endcase
1801
        `VMOV:
1802
            case (isn[`INSTRUCTION_S1])
1803
            5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RB]};
1804
            5'h1:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1805
            default:    fnRt = 12'h000;
1806
            endcase
1807
        `R1:
1808
                case(isn[22:18])
1809
                `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT:
1810
                        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1811
                `MEMDB,`MEMSB,`SYNC:
1812
                        fnRt = 12'd0;
1813
                default:        fnRt = 12'd0;
1814
                endcase
1815
        `CMOVEZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1816
        `CMOVNZ:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1817
        `MUX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1818
        `MIN:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1819
        `MAX:       fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_S1]};
1820
        `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
1821
        `SHIFTR:        fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1822
        `SHIFT31,`SHIFT63:
1823
                                fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1824
        `SEI:           fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1825
        `WAIT,`RTI,`CHK:
1826
                        fnRt = 12'd0;
1827
                default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1828
        endcase
1829
`MEMNDX:
1830
    case(isn[`INSTRUCTION_S2])
1831
    `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1832
                        fnRt = 12'd0;
1833
    default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1834
        endcase
1835
`FLOAT:
1836
                case(isn[31:26])
1837
                `FTX,`FCX,`FEX,`FDX,`FRM:
1838
                                        fnRt = 12'd0;
1839
                `FSYNC:         fnRt = 12'd0;
1840 49 robfinch
                default:        fnRt = {fp1_rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1841 48 robfinch
                endcase
1842
`BRK:   fnRt = 12'd0;
1843
`REX:   fnRt = 12'd0;
1844
`CHK:   fnRt = 12'd0;
1845
`EXEC:  fnRt = 12'd0;
1846
`Bcc:   fnRt = 12'd0;
1847
`BBc:   case(isn[20:19])
1848
                `IBNE:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1849
                `DBNZ:  fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1850
                default:        fnRt = 12'd0;
1851
                endcase
1852
`BEQI:  fnRt = 12'd0;
1853
`SB,`Sx,`SWC,`CACHE:
1854
                fnRt = 12'd0;
1855
`JMP:   fnRt = 12'd0;
1856
`CALL:  fnRt = {rgs[thrd],1'b0,regLR};  // regLR
1857
`RET:   fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RA]};
1858
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1859
`AMO:   fnRt = isn[31] ? {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]} : {rgs[thrd],1'b0,isn[`INSTRUCTION_RC]};
1860
default:    fnRt = {rgs[thrd],1'b0,isn[`INSTRUCTION_RB]};
1861
endcase
1862
endfunction
1863
`else
1864
function [RBIT:0] fnRa;
1865
input [47:0] isn;
1866
input [5:0] vqei;
1867
input [5:0] vli;
1868
input thrd;
1869
case(isn[`INSTRUCTION_OP])
1870
`IVECTOR:
1871
        case(isn[`INSTRUCTION_S2])
1872
        `VCIDX,`VSCAN:  fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1873
        `VMxx:
1874
                case(isn[25:23])
1875
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP,`VMFIRST,`VMLAST:
1876
                    fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1877
            `VMFILL:fnRa = {6'd0,1'b1,isn[`INSTRUCTION_RA]};
1878
            default:fnRa = {6'h3F,1'b1,2'b0,isn[8:6]};
1879
            endcase
1880
        `VSHLV:     fnRa = (vqei+1+isn[15:11] >= vli) ? 11'h000 : {vli-vqei-isn[15:11]-1,1'b1,isn[`INSTRUCTION_RA]};
1881
        `VSHRV:     fnRa = (vqei+isn[15:11] >= vli) ? 11'h000 : {vqei+isn[15:11],1'b1,isn[`INSTRUCTION_RA]};
1882
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1883
        default:    fnRa = {vqei,1'b1,isn[`INSTRUCTION_RA]};
1884
        endcase
1885
`RR:    case(isn[`INSTRUCTION_S2])
1886
                `MOV:
1887
                        case(isn[25:23])
1888
                        3'd0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1889
                        3'd1:   fnRa = {isn[22:18],1'b0,isn[`INSTRUCTION_RA]};
1890
                        3'd2:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1891
                        3'd3:   fnRa = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RA]};
1892
                        3'd4:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1893 49 robfinch
                        3'd5:   fnRa = {fp1_rgs,1'b0,isn[`INSTRUCTION_RA]};
1894
                        3'd6:   fnRa = {fp1_rgs,1'b0,isn[`INSTRUCTION_RA]};
1895 48 robfinch
                        default:fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1896
                        endcase
1897
        `VMOV:
1898
            case (isn[`INSTRUCTION_S1])
1899
            5'h0:   fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1900
            5'h1:   fnRa = {6'h3F,1'b1,isn[`INSTRUCTION_RA]};
1901
            endcase
1902
        default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1903
        endcase
1904 49 robfinch
`FLOAT:         fnRa = {fp1_rgs,1'b0,isn[`INSTRUCTION_RA]};
1905 48 robfinch
default:    fnRa = {rgs,1'b0,isn[`INSTRUCTION_RA]};
1906
endcase
1907
endfunction
1908
 
1909
function [RBIT:0] fnRb;
1910
input [47:0] isn;
1911
input fb;
1912
input [5:0] vqei;
1913
input [5:0] rfoa0i;
1914
input [5:0] rfoa1i;
1915
input thrd;
1916
case(isn[`INSTRUCTION_OP])
1917
`RR:        case(isn[`INSTRUCTION_S2])
1918
            `VEX:       fnRb = fb ? {rfoa1i,1'b1,isn[`INSTRUCTION_RB]} : {rfoa0i,1'b1,isn[`INSTRUCTION_RB]};
1919
            `LVX,`SVX:  fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1920
            default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1921
            endcase
1922
`IVECTOR:
1923
                        case(isn[`INSTRUCTION_S2])
1924
                        `VMxx:
1925
                                case(isn[25:23])
1926
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
1927
                        fnRb = {6'h3F,1'b1,2'b0,isn[13:11]};
1928
                default:        fnRb = 12'h000;
1929
                endcase
1930
            `VXCHG:     fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1931
            `VSxx,`VSxxU:   fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1932
                `VSxxS,`VSxxSU:    fnRb = {vqei,1'b0,isn[`INSTRUCTION_RB]};
1933
            `VADDS,`VSUBS,`VMULS,`VANDS,`VORS,`VXORS,`VXORS:
1934
                fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1935
            `VSHL,`VSHR,`VASR:
1936
                fnRb = {isn[25],isn[22]}==2'b00 ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {vqei,1'b1,isn[`INSTRUCTION_RB]};
1937
            default:    fnRb = {vqei,1'b1,isn[`INSTRUCTION_RB]};
1938
            endcase
1939 49 robfinch
`FLOAT:         fnRb = {fp1_rgs,1'b0,isn[`INSTRUCTION_RB]};
1940 48 robfinch
default:    fnRb = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1941
endcase
1942
endfunction
1943
 
1944
function [RBIT:0] fnRc;
1945
input [47:0] isn;
1946
input [5:0] vqei;
1947
input thrd;
1948
case(isn[`INSTRUCTION_OP])
1949
`R2:        case(isn[`INSTRUCTION_S2])
1950
            `SVX:       fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1951
                `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
1952
                        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1953
                `CMOVEZ,`CMOVNZ,`MAJ:
1954
                        fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1955
            default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1956
            endcase
1957
`IVECTOR:
1958
                        case(isn[`INSTRUCTION_S2])
1959
            `VSxx,`VSxxS,`VSxxU,`VSxxSU:    fnRc = {6'h3F,1'b1,2'b0,isn[18:16]};
1960
            default:    fnRc = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1961
            endcase
1962 49 robfinch
`FLOAT:         fnRc = {fp1_rgs,1'b0,isn[`INSTRUCTION_RC]};
1963 48 robfinch
default:    fnRc = {rgs,1'b0,isn[`INSTRUCTION_RC]};
1964
endcase
1965
endfunction
1966
 
1967
function [RBIT:0] fnRt;
1968
input [47:0] isn;
1969
input [5:0] vqei;
1970
input [5:0] vli;
1971
input thrd;
1972
casez(isn[`INSTRUCTION_OP])
1973
`IVECTOR:
1974
                case(isn[`INSTRUCTION_S2])
1975
                `VMxx:
1976
                        case(isn[25:23])
1977
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
1978
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1979
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1980
            default:
1981
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1982
            endcase
1983
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1984
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
1985
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
1986
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
1987
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1988
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
1989
        endcase
1990
 
1991
`FVECTOR:
1992
                case(isn[`INSTRUCTION_S2])
1993
                `VMxx:
1994
                        case(isn[25:23])
1995
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMFILL:
1996
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
1997
            `VMPOP:     fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
1998
            default:
1999
                    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2000
            endcase
2001
        `VSxx,`VSxxU,`VSxxS,`VSxxSU:    fnRt = {6'h3F,1'b1,2'b0,isn[18:16]};
2002
        `VSHLV:     fnRt = (vqei+1 >= vli) ? 11'h000 : {vli-vqei-1,1'b1,isn[`INSTRUCTION_RC]};
2003
        `VSHRV:     fnRt = (vqei >= vli) ? 11'h000 : {vqei,1'b1,isn[`INSTRUCTION_RC]};
2004
        `VEINS:     fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};    // ToDo: add element # from Ra
2005
        `V2BITS:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2006
        default:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RC]};
2007
        endcase
2008
 
2009
`R2:    case(isn[`INSTRUCTION_S2])
2010
                `MOV:
2011
                        case(isn[25:23])
2012
                        3'd0:   fnRt = {isn[22:18],1'b0,isn[`INSTRUCTION_RB]};
2013
                        3'd1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2014
                        3'd2:   fnRt = {rs_stack[5:0],1'b0,isn[`INSTRUCTION_RB]};
2015
                        3'd3:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2016 49 robfinch
                        3'd4:   fnRt = {fp1_rgs,1'b0,isn[`INSTRUCTION_RB]};
2017 48 robfinch
                        3'd5:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2018 49 robfinch
                        3'd6:   fnRt = {fp1_rgs,1'b0,isn[`INSTRUCTION_RB]};
2019 48 robfinch
                        default:fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2020
                        endcase
2021
        `VMOV:
2022
            case (isn[`INSTRUCTION_S1])
2023
            5'h0:   fnRt = {6'h3F,1'b1,isn[`INSTRUCTION_RB]};
2024
            5'h1:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2025
            default:    fnRt = 12'h000;
2026
            endcase
2027
        `R1:
2028
                case(isn[22:18])
2029
                `CNTLO,`CNTLZ,`CNTPOP,`ABS,`NOT:
2030
                        fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2031
                `MEMDB,`MEMSB,`SYNC:
2032
                        fnRt = 12'd0;
2033
                default:        fnRt = 12'd0;
2034
                endcase
2035
        `CMOVEZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2036
        `CMOVNZ:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2037
        `MUX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2038
        `MIN:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2039
        `MAX:       fnRt = {rgs,1'b0,isn[`INSTRUCTION_S1]};
2040
        `LVX:       fnRt = {vqei,1'b1,isn[20:16]};
2041
        `SHIFTR:        fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2042
        `SHIFT31,`SHIFT63:
2043
                                fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2044
        `SEI:           fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2045
        `WAIT,`RTI,`CHK:
2046
                                fnRt = 12'd0;
2047
        default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2048
        endcase
2049
`MEMNDX:
2050
        case(isn[`INSTRUCTION_S2])
2051
  `SBX,`SCX,`SHX,`SWX,`SWCX,`CACHEX:
2052
                        fnRt = 12'd0;
2053
  default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RC]};
2054
  endcase
2055
`FLOAT:
2056
                case(isn[31:26])
2057
                `FTX,`FCX,`FEX,`FDX,`FRM:
2058
                                        fnRt = 12'd0;
2059
                `FSYNC:         fnRt = 12'd0;
2060 49 robfinch
                default:        fnRt = {fp1_rgs,1'b0,isn[`INSTRUCTION_RC]};
2061 48 robfinch
                endcase
2062
`BRK:   fnRt = 12'd0;
2063
`REX:   fnRt = 12'd0;
2064
`CHK:   fnRt = 12'd0;
2065
`EXEC:  fnRt = 12'd0;
2066
`Bcc:   fnRt = 12'd0;
2067
`BBc:
2068
        case(isn[20:19])
2069
        `IBNE:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2070
        `DBNZ:  fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2071
        default:        fnRt = 12'd0;
2072
        endcase
2073
`BEQI:  fnRt = 12'd0;
2074
`SB,`Sx,`SWC,`CACHE:
2075
                fnRt = 12'd0;
2076
`JMP:   fnRt = 12'd0;
2077
`CALL:  fnRt = {rgs,1'b0,regLR};        // regLR
2078
`RET:   fnRt = {rgs,1'b0,isn[`INSTRUCTION_RA]};
2079
`LV:    fnRt = {vqei,1'b1,isn[`INSTRUCTION_RB]};
2080
`AMO:   fnRt = isn[31] ? {rgs,1'b0,isn[`INSTRUCTION_RB]} : {rgs,1'b0,isn[`INSTRUCTION_RC]};
2081
default:    fnRt = {rgs,1'b0,isn[`INSTRUCTION_RB]};
2082
endcase
2083
endfunction
2084
`endif
2085
 
2086
// Determines which lanes of the target register get updated.
2087
function [7:0] fnWe;
2088
input [47:0] isn;
2089
casez(isn[`INSTRUCTION_OP])
2090
`R2:
2091
        case(isn[`INSTRUCTION_S2])
2092
        `R1:
2093
                case(isn[22:18])
2094
                `ABS,`CNTLZ,`CNTLO,`CNTPOP:
2095
                        case(isn[25:23])
2096
                        3'b000: fnWe = 8'h01;
2097
                        3'b001: fnWe = 8'h03;
2098
                        3'b010: fnWe = 8'h0F;
2099
                        3'b011: fnWe = 8'hFF;
2100
                        default:        fnWe = 8'hFF;
2101
                        endcase
2102
                default: fnWe = 8'hFF;
2103
                endcase
2104
        `SHIFT31:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2105
        `SHIFT63:       fnWe = (~isn[25] & isn[21]) ? 8'hFF : 8'hFF;
2106
        `SLT,`SLTU,`SLE,`SLEU,
2107
        `ADD,`SUB,
2108
        `AND,`OR,`XOR,
2109
        `NAND,`NOR,`XNOR,
2110
        `DIVMOD,`DIVMODU,`DIVMODSU,
2111
        `MUL,`MULU,`MULSU:
2112
                case(isn[25:23])
2113
                3'b000: fnWe = 8'h01;
2114
                3'b001: fnWe = 8'h03;
2115
                3'b010: fnWe = 8'h0F;
2116
                3'b011: fnWe = 8'hFF;
2117
                default:        fnWe = 8'hFF;
2118
                endcase
2119
        default: fnWe = 8'hFF;
2120
        endcase
2121
default:        fnWe = 8'hFF;
2122
endcase
2123
endfunction
2124
 
2125
// Detect if a source is automatically valid
2126
function Source1Valid;
2127
input [47:0] isn;
2128
casez(isn[`INSTRUCTION_OP])
2129
`BRK:   Source1Valid = TRUE;
2130
`Bcc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2131
`BBc:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2132
`BEQI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2133
`CHK:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2134
`RR:    case(isn[`INSTRUCTION_S2])
2135
        `SHIFT31:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2136
        `SHIFT63:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2137
        `SHIFTR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2138
        default:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2139
        endcase
2140
`MEMNDX:Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2141
`ADDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2142
`SLTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2143
`SLTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2144
`SGTI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2145
`SGTUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2146
`ANDI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2147
`ORI:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2148
`XORI:  Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2149
`XNORI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2150
`MULUI: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2151
`AMO:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2152
`LB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2153
`LBU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2154
`Lx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2155
`LxU:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2156
`LWR:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2157
`LV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2158
`LVx:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2159
`SB:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2160
`Sx:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2161
`SWC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2162
`SV:    Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2163
`INC:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2164
`CAS:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2165
`JAL:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2166
`RET:   Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2167
`CSRRW: Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2168
`BITFIELD:      case(isn[31:28])
2169
                        `BFINSI:        Source1Valid = TRUE;
2170
                        default:        Source1Valid = isn[`INSTRUCTION_RA]==5'd0;
2171
                        endcase
2172
`IVECTOR:
2173
                        Source1Valid = FALSE;
2174
default:    Source1Valid = TRUE;
2175
endcase
2176
endfunction
2177
 
2178
function Source2Valid;
2179
input [47:0] isn;
2180
casez(isn[`INSTRUCTION_OP])
2181
`BRK:   Source2Valid = TRUE;
2182
`Bcc:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2183
`BBc:   Source2Valid = TRUE;
2184
`BEQI:  Source2Valid = TRUE;
2185
`CHK:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2186
`RR:    case(isn[`INSTRUCTION_S2])
2187
        `R1:       Source2Valid = TRUE;
2188
        `SHIFTR:   Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2189
        `SHIFT31:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2190
        `SHIFT63:  Source2Valid = isn[25] ? 1'b1 : isn[`INSTRUCTION_RB]==5'd0;
2191
        `LVX,`SVX: Source2Valid = FALSE;
2192
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2193
        endcase
2194
`MEMNDX:
2195
        case(isn[`INSTRUCTION_S2])
2196
        `LVX,`SVX: Source2Valid = FALSE;
2197
        default:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2198
        endcase
2199
`ADDI:  Source2Valid = TRUE;
2200
`SLTI:  Source2Valid = TRUE;
2201
`SLTUI: Source2Valid = TRUE;
2202
`SGTI:  Source2Valid = TRUE;
2203
`SGTUI: Source2Valid = TRUE;
2204
`ANDI:  Source2Valid = TRUE;
2205
`ORI:   Source2Valid = TRUE;
2206
`XORI:  Source2Valid = TRUE;
2207
`XNORI: Source2Valid = TRUE;
2208
`MULUI: Source2Valid = TRUE;
2209
`LB:    Source2Valid = TRUE;
2210
`LBU:   Source2Valid = TRUE;
2211
`Lx:    Source2Valid = TRUE;
2212
`LxU:   Source2Valid = TRUE;
2213
`LWR:   Source2Valid = TRUE;
2214
`LVx:   Source2Valid = TRUE;
2215
`INC:           Source2Valid = TRUE;
2216
`SB:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2217
`Sx:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2218
`SWC:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2219
`CAS:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2220
`JAL:   Source2Valid = TRUE;
2221
`RET:   Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2222
`IVECTOR:
2223
                    case(isn[`INSTRUCTION_S2])
2224
            `VABS:  Source2Valid = TRUE;
2225
            `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2226
                Source2Valid = FALSE;
2227
            `VADDS,`VSUBS,`VANDS,`VORS,`VXORS:
2228
                Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2229
            `VBITS2V:   Source2Valid = TRUE;
2230
            `V2BITS:    Source2Valid = isn[`INSTRUCTION_RB]==5'd0;
2231
            `VSHL,`VSHR,`VASR:  Source2Valid = isn[22:21]==2'd2;
2232
            default:    Source2Valid = FALSE;
2233
            endcase
2234
`LV:        Source2Valid = TRUE;
2235
`SV:        Source2Valid = FALSE;
2236
`AMO:           Source2Valid = isn[31] || isn[`INSTRUCTION_RB]==5'd0;
2237
default:    Source2Valid = TRUE;
2238
endcase
2239
endfunction
2240
 
2241
function Source3Valid;
2242
input [47:0] isn;
2243
case(isn[`INSTRUCTION_OP])
2244
`IVECTOR:
2245
    case(isn[`INSTRUCTION_S2])
2246
    `VEX:       Source3Valid = TRUE;
2247
    default:    Source3Valid = TRUE;
2248
    endcase
2249
`CHK:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2250
`R2:
2251
        if (isn[`INSTRUCTION_L2]==2'b01)
2252
                case(isn[47:42])
2253
    `CMOVEZ,`CMOVNZ:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2254
                default:        Source3Valid = TRUE;
2255
                endcase
2256
        else
2257
    case(isn[`INSTRUCTION_S2])
2258
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2259
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2260
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2261
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2262
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2263
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2264
    `MAJ:               Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2265
    default:    Source3Valid = TRUE;
2266
    endcase
2267
`MEMNDX:
2268
        if (isn[`INSTRUCTION_L2]==2'b00)
2269
    case(isn[`INSTRUCTION_S2])
2270
    `SBX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2271
    `SCX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2272
    `SHX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2273
    `SWX:   Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2274
    `SWCX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2275
    `CASX:  Source3Valid = isn[`INSTRUCTION_RC]==5'd0;
2276
    default:    Source3Valid = TRUE;
2277
    endcase
2278
default:    Source3Valid = TRUE;
2279
endcase
2280
endfunction
2281
 
2282
function SourceTValid;
2283
input [31:0] isn;
2284
SourceTValid = FALSE;
2285
endfunction
2286
function SourceT2Valid;
2287
input [31:0] isn;
2288
case(isn[`INSTRUCTION_OP])
2289
`Bcc:       SourceT2Valid = TRUE;
2290
`ORI:       SourceT2Valid = TRUE;
2291
default:    SourceT2Valid = FALSE;
2292
endcase
2293
endfunction
2294
 
2295
// Used to indicate to the queue logic that the instruction needs to be
2296
// recycled to the queue VL number of times.
2297
function IsVector;
2298
input [47:0] isn;
2299
case(isn[`INSTRUCTION_OP])
2300
`MEMNDX:    case(isn[`INSTRUCTION_S2])
2301
            `LVX,`SVX:  IsVector = TRUE;
2302
            default:    IsVector = FALSE;
2303
            endcase
2304
`IVECTOR:
2305
                        case(isn[`INSTRUCTION_S2])
2306
                        `VMxx:
2307
                                case(isn[25:23])
2308
                `VMAND,`VMOR,`VMXOR,`VMXNOR,`VMPOP:
2309
                        IsVector = FALSE;
2310
                default:        IsVector = TRUE;
2311
                endcase
2312
            `VEINS:     IsVector = FALSE;
2313
            `VEX:       IsVector = FALSE;
2314
            default:    IsVector = TRUE;
2315
            endcase
2316
`LV,`SV:    IsVector = TRUE;
2317
default:    IsVector = FALSE;
2318
endcase
2319
endfunction
2320
 
2321
function IsVeins;
2322
input [47:0] isn;
2323
case(isn[`INSTRUCTION_OP])
2324
`IVECTOR:   IsVeins = isn[`INSTRUCTION_S2]==`VEINS;
2325
default:    IsVeins = FALSE;
2326
endcase
2327
endfunction
2328
 
2329
function IsVex;
2330
input [47:0] isn;
2331
case(isn[`INSTRUCTION_OP])
2332
`IVECTOR:   IsVex = isn[`INSTRUCTION_S2]==`VEX;
2333
default:    IsVex = FALSE;
2334
endcase
2335
endfunction
2336
 
2337
function IsVCmprss;
2338
input [47:0] isn;
2339
case(isn[`INSTRUCTION_OP])
2340
`IVECTOR:   IsVCmprss = isn[`INSTRUCTION_S2]==`VCMPRSS || isn[`INSTRUCTION_S2]==`VCIDX;
2341
default:    IsVCmprss = FALSE;
2342
endcase
2343
endfunction
2344
 
2345
function IsVShifti;
2346
input [47:0] isn;
2347
case(isn[`INSTRUCTION_OP])
2348
`IVECTOR:
2349
                    case(isn[`INSTRUCTION_S2])
2350
            `VSHL,`VSHR,`VASR:
2351
                IsVShifti = {isn[25],isn[22]}==2'd2;
2352
            default:    IsVShifti = FALSE;
2353
            endcase
2354
default:    IsVShifti = FALSE;
2355
endcase
2356
endfunction
2357
 
2358
function IsVLS;
2359
input [47:0] isn;
2360
case(isn[`INSTRUCTION_OP])
2361
`MEMNDX:
2362
    case(isn[`INSTRUCTION_S2])
2363
    `LVX,`SVX,`LVWS,`SVWS:  IsVLS = TRUE;
2364
    default:    IsVLS = FALSE;
2365
    endcase
2366
`LV,`SV:    IsVLS = TRUE;
2367
default:    IsVLS = FALSE;
2368
endcase
2369
endfunction
2370
 
2371
function [1:0] fnM2;
2372
input [31:0] isn;
2373
case(isn[`INSTRUCTION_OP])
2374
`RR:    fnM2 = isn[24:23];
2375
default:    fnM2 = 2'b00;
2376
endcase
2377
endfunction
2378
 
2379
function [0:0] IsMem;
2380
input [47:0] isn;
2381
case(isn[`INSTRUCTION_OP])
2382
`MEMNDX:        IsMem = TRUE;
2383
`AMO:   IsMem = TRUE;
2384
`LB:    IsMem = TRUE;
2385
`LBU:   IsMem = TRUE;
2386
`Lx:    IsMem = TRUE;
2387
`LxU:   IsMem = TRUE;
2388
`LWR:   IsMem = TRUE;
2389
`LV,`SV:    IsMem = TRUE;
2390
`INC:           IsMem = TRUE;
2391
`SB:    IsMem = TRUE;
2392
`Sx:    IsMem = TRUE;
2393
`SWC:   IsMem = TRUE;
2394
`CAS:   IsMem = TRUE;
2395
`LVx:           IsMem = TRUE;
2396
default:    IsMem = FALSE;
2397
endcase
2398
endfunction
2399
 
2400
function IsMemNdx;
2401
input [47:0] isn;
2402
case(isn[`INSTRUCTION_OP])
2403
`MEMNDX:        IsMemNdx = TRUE;
2404
default:    IsMemNdx = FALSE;
2405
endcase
2406
endfunction
2407
 
2408
function IsLoad;
2409
input [47:0] isn;
2410
case(isn[`INSTRUCTION_OP])
2411
`MEMNDX:
2412
        if (isn[`INSTRUCTION_L2]==2'b00)
2413
            case(isn[`INSTRUCTION_S2])
2414
            `LBX:   IsLoad = TRUE;
2415
            `LBUX:  IsLoad = TRUE;
2416
            `LCX:   IsLoad = TRUE;
2417
            `LCUX:  IsLoad = TRUE;
2418
            `LHX:   IsLoad = TRUE;
2419
            `LHUX:  IsLoad = TRUE;
2420
            `LWX:   IsLoad = TRUE;
2421
            `LWRX:  IsLoad = TRUE;
2422
            `LVX:   IsLoad = TRUE;
2423
            `LVx:       IsLoad = TRUE;
2424
            default: IsLoad = FALSE;
2425
            endcase
2426
        else
2427
                IsLoad = FALSE;
2428
`LB:    IsLoad = TRUE;
2429
`LBU:   IsLoad = TRUE;
2430
`Lx:    IsLoad = TRUE;
2431
`LxU:   IsLoad = TRUE;
2432
`LWR:   IsLoad = TRUE;
2433
`LV:    IsLoad = TRUE;
2434
`LVx:   IsLoad = TRUE;
2435
default:    IsLoad = FALSE;
2436
endcase
2437
endfunction
2438
 
2439
function IsVolatileLoad;
2440
input [47:0] isn;
2441
case(isn[`INSTRUCTION_OP])
2442
`MEMNDX:
2443
        if (isn[`INSTRUCTION_L2]==2'b00)
2444
            case(isn[`INSTRUCTION_S2])
2445
            `LWRX:      IsVolatileLoad = TRUE;
2446
            `LVx:       IsVolatileLoad = TRUE;
2447
            default: IsVolatileLoad = FALSE;
2448
            endcase
2449
        else
2450
                IsVolatileLoad = FALSE;
2451
`LWR:   IsVolatileLoad = TRUE;
2452
`LVx:   IsVolatileLoad = TRUE;
2453
default:    IsVolatileLoad = FALSE;
2454
endcase
2455
endfunction
2456
 
2457
function [2:0] MemSize;
2458
input [47:0] isn;
2459
case(isn[`INSTRUCTION_OP])
2460
`MEMNDX:
2461
        if (isn[`INSTRUCTION_L2]==2'b00)
2462
            case(isn[`INSTRUCTION_S2])
2463
            `LBX,`LBUX,`SBX:   MemSize = byt;
2464
            `LCX,`LCUX,`SCX:   MemSize = wyde;
2465
            `LHX,`SHX:   MemSize = tetra;
2466
            `LHUX: MemSize = tetra;
2467
            `LWX,`SWX:   MemSize = octa;
2468
            `LWRX,`SWCX: MemSize = octa;
2469
            `LVX,`SVX:   MemSize = octa;
2470
            `LVx:
2471
                case(isn[25:23])
2472
                3'd0,3'd1:      MemSize = byt;
2473
                3'd2,3'd3:      MemSize = wyde;
2474
                3'd4,3'd5:      MemSize = tetra;
2475
                default:        MemSize = octa;
2476
                endcase
2477
            default: MemSize = octa;
2478
            endcase
2479
        else
2480
                MemSize = octa;
2481
`LB,`LBU,`SB:    MemSize = byt;
2482
`Lx,`LxU,`Sx:
2483
        casez(isn[20:18])
2484
        3'b100: MemSize = octa;
2485
        3'b?10: MemSize = tetra;
2486
        3'b??1: MemSize = wyde;
2487
        default:        MemSize = octa;
2488
        endcase
2489
`LWR,`SWC:  MemSize = octa;
2490
`LV,`SV:    MemSize = octa;
2491
`AMO:
2492
        case(isn[23:21])
2493
        3'd0:   MemSize = byt;
2494
        3'd1:   MemSize = wyde;
2495
        3'd2:   MemSize = tetra;
2496
        3'd3:   MemSize = octa;
2497
        default:        MemSize = octa;
2498
        endcase
2499
`LVx:
2500
        case(isn[30:28])
2501
        3'd0,3'd1:      MemSize = byt;
2502
        3'd2,3'd3:      MemSize = wyde;
2503
        3'd4,3'd5:      MemSize = tetra;
2504
        default:        MemSize = octa;
2505
        endcase
2506
default:    MemSize = octa;
2507
endcase
2508
endfunction
2509
 
2510
function IsStore;
2511
input [47:0] isn;
2512
case(isn[`INSTRUCTION_OP])
2513
`MEMNDX:
2514
        if (isn[`INSTRUCTION_L2]==2'b00)
2515
            case(isn[`INSTRUCTION_S2])
2516
            `SBX:   IsStore = TRUE;
2517
            `SCX:   IsStore = TRUE;
2518
            `SHX:   IsStore = TRUE;
2519
            `SWX:   IsStore = TRUE;
2520
            `SWCX:  IsStore = TRUE;
2521
            `SVX:   IsStore = TRUE;
2522
            `CASX:  IsStore = TRUE;
2523
            `INC:       IsStore = TRUE;
2524
            default:    IsStore = FALSE;
2525
            endcase
2526
        else
2527
                IsStore = FALSE;
2528
`SB:    IsStore = TRUE;
2529
`Sx:    IsStore = TRUE;
2530
`SWC:   IsStore = TRUE;
2531
`INC:   IsStore = TRUE;
2532
`SV:    IsStore = TRUE;
2533
`CAS:   IsStore = TRUE;
2534
`AMO:   IsStore = TRUE;
2535
default:    IsStore = FALSE;
2536
endcase
2537
endfunction
2538
 
2539
function IsInc;
2540
input [47:0] isn;
2541
case(isn[`INSTRUCTION_OP])
2542
`MEMNDX:
2543
        if (isn[`INSTRUCTION_L2]==2'b00)
2544
                case(isn[`INSTRUCTION_S2])
2545
            `INC:   IsInc = TRUE;
2546
            default:    IsInc = FALSE;
2547
            endcase
2548
        else
2549
                IsInc = FALSE;
2550
`INC:    IsInc = TRUE;
2551
default:    IsInc = FALSE;
2552
endcase
2553
endfunction
2554
 
2555
function IsSWC;
2556
input [47:0] isn;
2557
case(isn[`INSTRUCTION_OP])
2558
`MEMNDX:
2559
        if (isn[`INSTRUCTION_L2]==2'b00)
2560
                case(isn[`INSTRUCTION_S2])
2561
            `SWCX:   IsSWC = TRUE;
2562
            default:    IsSWC = FALSE;
2563
            endcase
2564
        else
2565
                IsSWC = FALSE;
2566
`SWC:    IsSWC = TRUE;
2567
default:    IsSWC = FALSE;
2568
endcase
2569
endfunction
2570
 
2571
// Aquire / release bits are only available on indexed SWC / LWR
2572
function IsSWCX;
2573
input [47:0] isn;
2574
case(isn[`INSTRUCTION_OP])
2575
`MEMNDX:
2576
        if (isn[`INSTRUCTION_L2]==2'b00)
2577
            case(isn[`INSTRUCTION_S2])
2578
            `SWCX:   IsSWCX = TRUE;
2579
            default:    IsSWCX = FALSE;
2580
            endcase
2581
        else
2582
                IsSWCX = FALSE;
2583
default:    IsSWCX = FALSE;
2584
endcase
2585
endfunction
2586
 
2587
function IsLWR;
2588
input [47:0] isn;
2589
case(isn[`INSTRUCTION_OP])
2590
`MEMNDX:
2591
        if (isn[`INSTRUCTION_L2]==2'b00)
2592
            case(isn[`INSTRUCTION_S2])
2593
            `LWRX:   IsLWR = TRUE;
2594
            default:    IsLWR = FALSE;
2595
            endcase
2596
        else
2597
                IsLWR = FALSE;
2598
`LWR:    IsLWR = TRUE;
2599
default:    IsLWR = FALSE;
2600
endcase
2601
endfunction
2602
 
2603
function IsLWRX;
2604
input [47:0] isn;
2605
case(isn[`INSTRUCTION_OP])
2606
`MEMNDX:
2607
        if (isn[`INSTRUCTION_L2]==2'b00)
2608
            case(isn[`INSTRUCTION_S2])
2609
            `LWRX:   IsLWRX = TRUE;
2610
            default:    IsLWRX = FALSE;
2611
            endcase
2612
        else
2613
                IsLWRX = FALSE;
2614
default:    IsLWRX = FALSE;
2615
endcase
2616
endfunction
2617
 
2618
function IsCAS;
2619
input [47:0] isn;
2620
case(isn[`INSTRUCTION_OP])
2621
`MEMNDX:
2622
        if (isn[`INSTRUCTION_L2]==2'b00)
2623
            case(isn[`INSTRUCTION_S2])
2624
            `CASX:   IsCAS = TRUE;
2625
            default:    IsCAS = FALSE;
2626
            endcase
2627
        else
2628
                IsCAS = FALSE;
2629
`CAS:       IsCAS = TRUE;
2630
default:    IsCAS = FALSE;
2631
endcase
2632
endfunction
2633
 
2634
function IsAMO;
2635
input [47:0] isn;
2636
case(isn[`INSTRUCTION_OP])
2637
`AMO:       IsAMO = TRUE;
2638
default:    IsAMO = FALSE;
2639
endcase
2640
endfunction
2641
 
2642
// Really IsPredictableBranch
2643
// Does not include BccR's
2644
function IsBranch;
2645
input [47:0] isn;
2646
casez(isn[`INSTRUCTION_OP])
2647
`Bcc:   IsBranch = TRUE;
2648
`BBc:   IsBranch = TRUE;
2649
`BEQI:  IsBranch = TRUE;
2650
`CHK:   IsBranch = TRUE;
2651
default:    IsBranch = FALSE;
2652
endcase
2653
endfunction
2654
 
2655
function IsWait;
2656
input [47:0] isn;
2657
IsWait = isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`WAIT;
2658
endfunction
2659
 
2660
function IsBrk;
2661
input [47:0] isn;
2662
IsBrk = isn[`INSTRUCTION_OP]==`BRK && isn[`INSTRUCTION_L2]==2'b00;
2663
endfunction
2664
 
2665
function IsIrq;
2666
input [47:0] isn;
2667
IsIrq = isn[`INSTRUCTION_OP]==`BRK && isn[`INSTRUCTION_L2]==2'b00 && isn[23:20]==4'h0;
2668
endfunction
2669
 
2670
function IsRTI;
2671
input [47:0] isn;
2672
IsRTI = isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`RTI;
2673
endfunction
2674
 
2675
function IsJAL;
2676
input [47:0] isn;
2677
IsJAL = isn[`INSTRUCTION_OP]==`JAL && isn[7]==1'b0;
2678
endfunction
2679
 
2680
function IsCall;
2681
input [47:0] isn;
2682
IsCall = isn[`INSTRUCTION_OP]==`CALL && isn[7]==1'b0;
2683
endfunction
2684
 
2685
function IsJmp;
2686
input [47:0] isn;
2687
IsJmp = isn[`INSTRUCTION_OP]==`JMP && isn[7]==1'b0;
2688
endfunction
2689
 
2690
function IsRet;
2691
input [47:0] isn;
2692
IsRet = isn[`INSTRUCTION_OP]==`RET && isn[7]==1'b0;
2693
endfunction
2694
 
2695
function IsFlowCtrl;
2696
input [47:0] isn;
2697
casez(isn[`INSTRUCTION_OP])
2698
`BRK:    IsFlowCtrl = TRUE;
2699 49 robfinch
`R2:    case(isn[`INSTRUCTION_S2])
2700 48 robfinch
        `RTI:   IsFlowCtrl = TRUE;
2701
        default:    IsFlowCtrl = FALSE;
2702
        endcase
2703
`Bcc:   IsFlowCtrl = TRUE;
2704
`BBc:           IsFlowCtrl = TRUE;
2705
`BEQI:  IsFlowCtrl = TRUE;
2706
`CHK:   IsFlowCtrl = TRUE;
2707
`JAL:   IsFlowCtrl = TRUE;
2708
`JMP:           IsFlowCtrl = TRUE;
2709
`CALL:  IsFlowCtrl = TRUE;
2710
`RET:   IsFlowCtrl = TRUE;
2711
default:    IsFlowCtrl = FALSE;
2712
endcase
2713
endfunction
2714
 
2715
function IsCache;
2716
input [47:0] isn;
2717
case(isn[`INSTRUCTION_OP])
2718
`MEMNDX:
2719
        if (isn[`INSTRUCTION_L2]==2'b00)
2720
            case(isn[`INSTRUCTION_S2])
2721
            `CACHEX:    IsCache = TRUE;
2722
            default:    IsCache = FALSE;
2723
            endcase
2724
        else
2725
                IsCache = FALSE;
2726
`CACHE: IsCache = TRUE;
2727
default: IsCache = FALSE;
2728
endcase
2729
endfunction
2730
 
2731
function [4:0] CacheCmd;
2732
input [47:0] isn;
2733
case(isn[`INSTRUCTION_OP])
2734
`MEMNDX:
2735
        if (isn[`INSTRUCTION_L2]==2'b00)
2736
            case(isn[`INSTRUCTION_S2])
2737
            `CACHEX:    CacheCmd = isn[22:18];
2738
            default:    CacheCmd = 5'd0;
2739
            endcase
2740
        else
2741
                CacheCmd = 5'd0;
2742
`CACHE: CacheCmd = isn[15:11];
2743
default: CacheCmd = 5'd0;
2744
endcase
2745
endfunction
2746
 
2747
function IsSync;
2748
input [47:0] isn;
2749
IsSync = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`SYNC);
2750
endfunction
2751
 
2752
function IsFSync;
2753
input [47:0] isn;
2754
IsFSync = (isn[`INSTRUCTION_OP]==`FLOAT && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`FSYNC);
2755
endfunction
2756
 
2757
function IsMemsb;
2758
input [47:0] isn;
2759
IsMemsb = (isn[`INSTRUCTION_OP]==`RR && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`R1 && isn[22:18]==`MEMSB);
2760
endfunction
2761
 
2762
function IsSEI;
2763
input [47:0] isn;
2764
IsSEI = (isn[`INSTRUCTION_OP]==`R2 && isn[`INSTRUCTION_L2]==2'b00 && isn[`INSTRUCTION_S2]==`SEI);
2765
endfunction
2766
 
2767
function IsLV;
2768
input [47:0] isn;
2769
case(isn[`INSTRUCTION_OP])
2770
`MEMNDX:
2771
        if (isn[`INSTRUCTION_L2]==2'b00)
2772
            case(isn[`INSTRUCTION_S2])
2773
            `LVX:   IsLV = TRUE;
2774
            default:    IsLV = FALSE;
2775
            endcase
2776
        else
2777
                IsLV = FALSE;
2778
`LV:        IsLV = TRUE;
2779
default:    IsLV = FALSE;
2780
endcase
2781
endfunction
2782
 
2783
function IsRFW;
2784
input [47:0] isn;
2785
input [5:0] vqei;
2786
input [5:0] vli;
2787
input thrd;
2788
if (fnRt(isn,vqei,vli,thrd)==12'd0)
2789
    IsRFW = FALSE;
2790
else
2791
casez(isn[`INSTRUCTION_OP])
2792
`IVECTOR:   IsRFW = TRUE;
2793
`FVECTOR:   IsRFW = TRUE;
2794
`R2:
2795
        if (isn[`INSTRUCTION_L2]==2'b00)
2796
            case(isn[`INSTRUCTION_S2])
2797
            `R1:    IsRFW = TRUE;
2798
            `ADD:   IsRFW = TRUE;
2799
            `SUB:   IsRFW = TRUE;
2800
            `SLT:   IsRFW = TRUE;
2801
            `SLTU:  IsRFW = TRUE;
2802
            `SLE:   IsRFW = TRUE;
2803
        `SLEU:  IsRFW = TRUE;
2804
            `AND:   IsRFW = TRUE;
2805
            `OR:    IsRFW = TRUE;
2806
            `XOR:   IsRFW = TRUE;
2807
            `MULU:  IsRFW = TRUE;
2808
            `MULSU: IsRFW = TRUE;
2809
            `MUL:   IsRFW = TRUE;
2810
            `DIVMODU:  IsRFW = TRUE;
2811
            `DIVMODSU: IsRFW = TRUE;
2812
            `DIVMOD:IsRFW = TRUE;
2813
            `MOV:       IsRFW = TRUE;
2814
            `VMOV:      IsRFW = TRUE;
2815
            `SHIFTR,`SHIFT31,`SHIFT63:
2816
                        IsRFW = TRUE;
2817
            `MIN,`MAX:    IsRFW = TRUE;
2818
            `SEI:       IsRFW = TRUE;
2819
            default:    IsRFW = FALSE;
2820
            endcase
2821
        else
2822
                IsRFW = FALSE;
2823
`MEMNDX:
2824
        if (isn[`INSTRUCTION_L2]==2'b00)
2825
            case(isn[`INSTRUCTION_S2])
2826
            `LBX:   IsRFW = TRUE;
2827
            `LBUX:  IsRFW = TRUE;
2828
            `LCX:   IsRFW = TRUE;
2829
            `LCUX:  IsRFW = TRUE;
2830
            `LHX:   IsRFW = TRUE;
2831
            `LHUX:  IsRFW = TRUE;
2832
            `LWX:   IsRFW = TRUE;
2833
            `LWRX:  IsRFW = TRUE;
2834
            `LVX:   IsRFW = TRUE;
2835
            `LVx:       IsRFW = TRUE;
2836
            `CASX:  IsRFW = TRUE;
2837
            default:    IsRFW = FALSE;
2838
            endcase
2839
        else
2840
                IsRFW = FALSE;
2841
`BBc:
2842
        case(isn[20:19])
2843
        `IBNE:  IsRFW = TRUE;
2844
        `DBNZ:  IsRFW = TRUE;
2845
        default:        IsRFW = FALSE;
2846
        endcase
2847
`BITFIELD:  IsRFW = TRUE;
2848
`ADDI:      IsRFW = TRUE;
2849
`SLTI:      IsRFW = TRUE;
2850
`SLTUI:     IsRFW = TRUE;
2851
`SGTI:      IsRFW = TRUE;
2852
`SGTUI:     IsRFW = TRUE;
2853
`ANDI:      IsRFW = TRUE;
2854
`ORI:       IsRFW = TRUE;
2855
`XORI:      IsRFW = TRUE;
2856
`MULUI:     IsRFW = TRUE;
2857
`MULI:      IsRFW = TRUE;
2858
`DIVUI:     IsRFW = TRUE;
2859
`DIVI:      IsRFW = TRUE;
2860
`MODI:      IsRFW = TRUE;
2861
`JAL:       IsRFW = TRUE;
2862
`CALL:      IsRFW = TRUE;
2863
`RET:       IsRFW = TRUE;
2864
`LB:        IsRFW = TRUE;
2865
`LBU:       IsRFW = TRUE;
2866
`Lx:        IsRFW = TRUE;
2867
`LWR:       IsRFW = TRUE;
2868
`LV:        IsRFW = TRUE;
2869
`LVx:                           IsRFW = TRUE;
2870
`CAS:       IsRFW = TRUE;
2871
`AMO:                           IsRFW = TRUE;
2872
`CSRRW:                 IsRFW = TRUE;
2873
default:    IsRFW = FALSE;
2874
endcase
2875
endfunction
2876
 
2877
function IsShifti;
2878
input [47:0] isn;
2879
case(isn[`INSTRUCTION_OP])
2880
`R2:
2881
        if (isn[`INSTRUCTION_L2]==2'b00)
2882
            case(isn[`INSTRUCTION_S2])
2883
            `SHIFT31,`SHIFT63:
2884
                IsShifti = TRUE;
2885
            default: IsShifti = FALSE;
2886
            endcase
2887
    else
2888
        IsShifti = FALSE;
2889
default: IsShifti = FALSE;
2890
endcase
2891
endfunction
2892
 
2893
function IsRtop;
2894
input [47:0] isn;
2895
case(isn[`INSTRUCTION_OP])
2896
`R2:
2897
        if (isn[`INSTRUCTION_L2]==2'b01)
2898
            case(isn[47:42])
2899
            `RTOP: IsRtop = TRUE;
2900
            default: IsRtop = FALSE;
2901
            endcase
2902
    else
2903
        IsRtop = FALSE;
2904
default: IsRtop = FALSE;
2905
endcase
2906
endfunction
2907
 
2908
function IsMul;
2909
input [47:0] isn;
2910
case(isn[`INSTRUCTION_OP])
2911
`RR:
2912
        if (isn[`INSTRUCTION_L2]==2'b00)
2913
            case(isn[`INSTRUCTION_S2])
2914
            `MULU,`MULSU,`MUL: IsMul = TRUE;
2915
            default:    IsMul = FALSE;
2916
            endcase
2917
        else
2918
                IsMul = FALSE;
2919
`MULUI,`MULI:  IsMul = TRUE;
2920
default:    IsMul = FALSE;
2921
endcase
2922
endfunction
2923
 
2924
function IsDivmod;
2925
input [47:0] isn;
2926
case(isn[`INSTRUCTION_OP])
2927
`RR:
2928
        if (isn[`INSTRUCTION_L2]==2'b00)
2929
            case(isn[`INSTRUCTION_S2])
2930
            `DIVMODU,`DIVMODSU,`DIVMOD: IsDivmod = TRUE;
2931
            default: IsDivmod = FALSE;
2932
            endcase
2933
        else
2934
                IsDivmod = FALSE;
2935
`DIVUI,`DIVI,`MODI:  IsDivmod = TRUE;
2936
default:    IsDivmod = FALSE;
2937
endcase
2938
endfunction
2939
 
2940
function IsExec;
2941
input [47:0] isn;
2942
case(isn[`INSTRUCTION_OP])
2943
`EXEC:  IsExec = TRUE;
2944
default:        IsExec = FALSE;
2945
endcase
2946
endfunction
2947
 
2948
function [7:0] fnSelect;
2949
input [47:0] ins;
2950 49 robfinch
input [`ABITS] adr;
2951 48 robfinch
begin
2952
        case(ins[`INSTRUCTION_OP])
2953
        `MEMNDX:
2954
                if (ins[`INSTRUCTION_L2]==2'b00)
2955
                   case(ins[`INSTRUCTION_S2])
2956
               `LBX,`LBUX,`SBX:
2957
                   case(adr[2:0])
2958
                   3'd0:    fnSelect = 8'h01;
2959
                   3'd1:    fnSelect = 8'h02;
2960
                   3'd2:    fnSelect = 8'h04;
2961
                   3'd3:    fnSelect = 8'h08;
2962
                   3'd4:    fnSelect = 8'h10;
2963
                   3'd5:    fnSelect = 8'h20;
2964
                   3'd6:    fnSelect = 8'h40;
2965
                   3'd7:    fnSelect = 8'h80;
2966
                   endcase
2967
                `LCX,`LCUX,`SCX:
2968
                    case(adr[2:1])
2969
                    2'd0:   fnSelect = 8'h03;
2970
                    2'd1:   fnSelect = 8'h0C;
2971
                    2'd2:   fnSelect = 8'h30;
2972
                    2'd3:   fnSelect = 8'hC0;
2973
                    endcase
2974
                `LHX,`LHUX,`SHX:
2975
                   case(adr[2])
2976
                   1'b0:    fnSelect = 8'h0F;
2977
                   1'b1:    fnSelect = 8'hF0;
2978
                   endcase
2979
               `INC,
2980
               `LWX,`SWX,`LWRX,`SWCX,`LVX,`SVX,`CASX:
2981
                   fnSelect = 8'hFF;
2982
               `LVx:   ;
2983
//                      case(ins[25:23])
2984
//                     `LVB,`LVBU:
2985
//                         case(adr[2:0])
2986
//                         3'd0:    fnSelect = 8'h01;
2987
//                         3'd1:    fnSelect = 8'h02;
2988
//                         3'd2:    fnSelect = 8'h04;
2989
//                         3'd3:    fnSelect = 8'h08;
2990
//                         3'd4:    fnSelect = 8'h10;
2991
//                         3'd5:    fnSelect = 8'h20;
2992
//                         3'd6:    fnSelect = 8'h40;
2993
//                         3'd7:    fnSelect = 8'h80;
2994
//                         endcase
2995
//                      `LVC,`LVCU:
2996
//                          case(adr[2:1])
2997
//                          2'd0:   fnSelect = 8'h03;
2998
//                          2'd1:   fnSelect = 8'h0C;
2999
//                          2'd2:   fnSelect = 8'h30;
3000
//                          2'd3:   fnSelect = 8'hC0;
3001
//                          endcase
3002
//                      `LVH,`LVHU:
3003
//                         case(adr[2])
3004
//                         1'b0:    fnSelect = 8'h0F;
3005
//                         1'b1:    fnSelect = 8'hF0;
3006
//                         endcase
3007
//                     `LVW:
3008
//                         fnSelect = 8'hFF;
3009
//                      endcase
3010
               default: fnSelect = 8'h00;
3011
                   endcase
3012
           else
3013
                fnSelect = 8'h00;
3014
    `LB,`LBU,`SB:
3015
                case(adr[2:0])
3016
                3'd0:   fnSelect = 8'h01;
3017
                3'd1:   fnSelect = 8'h02;
3018
                3'd2:   fnSelect = 8'h04;
3019
                3'd3:   fnSelect = 8'h08;
3020
                3'd4:   fnSelect = 8'h10;
3021
                3'd5:   fnSelect = 8'h20;
3022
                3'd6:   fnSelect = 8'h40;
3023
                3'd7:   fnSelect = 8'h80;
3024
                endcase
3025
    `Lx,`LxU,`Sx:
3026
        casez(ins[20:18])
3027
        3'b100: fnSelect = 8'hFF;
3028
        3'b?10: fnSelect = adr[2] ? 8'hF0 : 8'h0F;
3029
        3'b??1:
3030
        case(adr[2:1])
3031
        2'd0:   fnSelect = 8'h03;
3032
        2'd1:   fnSelect = 8'h0C;
3033
        2'd2:   fnSelect = 8'h30;
3034
        2'd3:   fnSelect = 8'hC0;
3035
        endcase
3036
      default: fnSelect = 8'h00;
3037
      endcase
3038
        `INC,
3039
        `LWR,`SWC,`CAS:   fnSelect = 8'hFF;
3040
        `LV,`SV:   fnSelect = 8'hFF;
3041
        `AMO:
3042
                case(ins[23:21])
3043
                3'd0:   fnSelect = {8'h01 << adr[2:0]};
3044
                3'd1:   fnSelect = {8'h03 << {adr[2:1],1'b0}};
3045
                3'd2:   fnSelect = {8'h0F << {adr[2],2'b00}};
3046
                3'd3:   fnSelect = 8'hFF;
3047
                default:        fnSelect = 8'hFF;
3048
                endcase
3049
//      `LVx:
3050
//       `LVB,`LVBU:
3051
//           case(adr[2:0])
3052
//           3'd0:    fnSelect = 8'h01;
3053
//           3'd1:    fnSelect = 8'h02;
3054
//           3'd2:    fnSelect = 8'h04;
3055
//           3'd3:    fnSelect = 8'h08;
3056
//           3'd4:    fnSelect = 8'h10;
3057
//           3'd5:    fnSelect = 8'h20;
3058
//           3'd6:    fnSelect = 8'h40;
3059
//           3'd7:    fnSelect = 8'h80;
3060
//           endcase
3061
//        `LVC,`LVCU:
3062
//            case(adr[2:1])
3063
//            2'd0:   fnSelect = 8'h03;
3064
//            2'd1:   fnSelect = 8'h0C;
3065
//            2'd2:   fnSelect = 8'h30;
3066
//            2'd3:   fnSelect = 8'hC0;
3067
//            endcase
3068
//      `LVH,`LVHU:
3069
//           case(adr[2])
3070
//           1'b0:    fnSelect = 8'h0F;
3071
//           1'b1:    fnSelect = 8'hF0;
3072
//           endcase
3073
//       `LVW:
3074
//           fnSelect = 8'hFF;
3075
        default:        fnSelect = 8'h00;
3076
        endcase
3077
end
3078
endfunction
3079
/*
3080
function [63:0] fnDatc;
3081
input [47:0] ins;
3082
input [63:0] dat;
3083
case(ins[`INSTRUCTION_OP])
3084
`R2:
3085
        if (isn[`INSTRUCTION_L2]==2'b01)
3086
                case(ins[47:42])
3087
                `FINDB:         fnDatc = dat[7:0];
3088
                `FINDC:         fnDatc = dat[15:0];
3089
                `FINDH:         fnDatc = dat[31:0];
3090
                `FINDW:         fnDatc = dat[63:0];
3091
                default:        fnDatc = dat[63:0];
3092
                endcase
3093
        else
3094
                fnDatc = dat[63:0];
3095
default:        fnDatc = dat[63:0];
3096
endcase
3097
endfunction
3098
*/
3099
/*
3100
function [63:0] fnMemInc;
3101
input [47:0] ins;
3102
case(ins[`INSTRUCTION_OP])
3103
`R2:
3104
        if (isn[`INSTRUCTION_L2]==2'b01)
3105
                case(ins[47:42])
3106
                `FINDB:         fnMemInc = 32'd1;
3107
                `FINDC:         fnMemInc = 32'd2;
3108
                `FINDH:         fnMemInc = 32'd4;
3109
                `FINDW:         fnMemInc = 32'd8;
3110
                default:        fnMemInc = 32'd8;
3111
                endcase
3112
        else
3113
                fnMemInc = 32'd8;
3114
default:        fnMemInc = 32'd8;
3115
endcase
3116
endfunction
3117
*/
3118
function [63:0] fnDati;
3119
input [47:0] ins;
3120 49 robfinch
input [`ABITS] adr;
3121 48 robfinch
input [63:0] dat;
3122
case(ins[`INSTRUCTION_OP])
3123
`MEMNDX:
3124
        if (ins[`INSTRUCTION_L2]==2'b00)
3125
            case(ins[`INSTRUCTION_S2])
3126
            `LBX:
3127
                case(adr[2:0])
3128
                3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3129
                3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3130
                3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3131
                3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3132
                3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3133
                3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3134
                3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3135
                3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3136
                endcase
3137
            `LBUX:
3138
                case(adr[2:0])
3139
                3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3140
                3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3141
                3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3142
                3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3143
                3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3144
                3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3145
                3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3146
                3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3147
                endcase
3148
            `LCX:
3149
                case(adr[2:1])
3150
                2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3151
                2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3152
                2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3153
                2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3154
                endcase
3155
            `LCUX:
3156
                case(adr[2:1])
3157
                2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3158
                2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3159
                2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3160
                2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3161
                endcase
3162
            `LHX:
3163
                case(adr[2])
3164
                1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3165
                1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3166
                endcase
3167
            `LHUX:
3168
                case(adr[2])
3169
                1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3170
                1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3171
                endcase
3172
            `LWX,`LWRX,`LVX,`CAS:  fnDati = dat;
3173
//          `LVx:
3174
//              case(ins[25:23])
3175
//                  `LVB:
3176
//                      case(adr[2:0])
3177
//                      3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3178
//                      3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3179
//                      3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3180
//                      3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3181
//                      3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3182
//                      3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3183
//                      3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3184
//                      3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3185
//                      endcase
3186
//                  `LVBU:
3187
//                      case(adr[2:0])
3188
//                      3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3189
//                      3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3190
//                      3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3191
//                      3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3192
//                      3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3193
//                      3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3194
//                      3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3195
//                      3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3196
//                      endcase
3197
//                  `LVC:
3198
//                      case(adr[2:1])
3199
//                      2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3200
//                      2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3201
//                      2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3202
//                      2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3203
//                      endcase
3204
//                  `LVCU:
3205
//                      case(adr[2:1])
3206
//                      2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3207
//                      2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3208
//                      2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3209
//                      2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3210
//                      endcase
3211
//                  `LVH:
3212
//                      case(adr[2])
3213
//                      1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3214
//                      1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3215
//                      endcase
3216
//                  `LVHU:
3217
//                      case(adr[2])
3218
//                      1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3219
//                      1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3220
//                      endcase
3221
//                  `LVW:  fnDati = dat;
3222
//                  default:    fnDati = dat;
3223
//              endcase
3224
            default:    fnDati = dat;
3225
            endcase
3226
        else
3227
                fnDati = dat;
3228
`LB:
3229
  case(adr[2:0])
3230
  3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3231
  3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3232
  3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3233
  3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3234
  3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3235
  3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3236
  3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3237
  3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3238
  endcase
3239
`LBU:
3240
  case(adr[2:0])
3241
  3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3242
  3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3243
  3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3244
  3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3245
  3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3246
  3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3247
  3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3248
  3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3249
  endcase
3250
`Lx:
3251
        casez(ins[20:18])
3252
        3'b100: fnDati = dat;
3253
        3'b?10:
3254
          case(adr[2])
3255
          1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3256
          1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3257
          endcase
3258
        3'b??1:
3259
          case(adr[2:1])
3260
          2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3261
          2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3262
          2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3263
          2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3264
          endcase
3265
        endcase
3266
`LxU:
3267
        casez(ins[20:18])
3268
        3'b100: fnDati = dat;
3269
        3'b?10:
3270
          case(adr[2])
3271
          1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3272
          1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3273
          endcase
3274
        3'b??1:
3275
          case(adr[2:1])
3276
          2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3277
          2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3278
          2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3279
          2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3280
          endcase
3281
        endcase
3282
`LWR,`LV,`CAS,`AMO:   fnDati = dat;
3283
//`LVx:
3284
//      case(ins[30:28])
3285
//    `LVB:
3286
//        case(adr[2:0])
3287
//        3'd0:   fnDati = {{56{dat[7]}},dat[7:0]};
3288
//        3'd1:   fnDati = {{56{dat[15]}},dat[15:8]};
3289
//        3'd2:   fnDati = {{56{dat[23]}},dat[23:16]};
3290
//        3'd3:   fnDati = {{56{dat[31]}},dat[31:24]};
3291
//        3'd4:   fnDati = {{56{dat[39]}},dat[39:32]};
3292
//        3'd5:   fnDati = {{56{dat[47]}},dat[47:40]};
3293
//        3'd6:   fnDati = {{56{dat[55]}},dat[55:48]};
3294
//        3'd7:   fnDati = {{56{dat[63]}},dat[63:56]};
3295
//        endcase
3296
//    `LVBU:
3297
//        case(adr[2:0])
3298
//        3'd0:   fnDati = {{56{1'b0}},dat[7:0]};
3299
//        3'd1:   fnDati = {{56{1'b0}},dat[15:8]};
3300
//        3'd2:   fnDati = {{56{1'b0}},dat[23:16]};
3301
//        3'd3:   fnDati = {{56{1'b0}},dat[31:24]};
3302
//        3'd4:   fnDati = {{56{1'b0}},dat[39:32]};
3303
//        3'd5:   fnDati = {{56{1'b0}},dat[47:40]};
3304
//        3'd6:   fnDati = {{56{1'b0}},dat[55:48]};
3305
//        3'd7:   fnDati = {{56{2'b0}},dat[63:56]};
3306
//        endcase
3307
//    `LVC:
3308
//        case(adr[2:1])
3309
//        2'd0:   fnDati = {{48{dat[15]}},dat[15:0]};
3310
//        2'd1:   fnDati = {{48{dat[31]}},dat[31:16]};
3311
//        2'd2:   fnDati = {{48{dat[47]}},dat[47:32]};
3312
//        2'd3:   fnDati = {{48{dat[63]}},dat[63:48]};
3313
//        endcase
3314
//    `LVCU:
3315
//        case(adr[2:1])
3316
//        2'd0:   fnDati = {{48{1'b0}},dat[15:0]};
3317
//        2'd1:   fnDati = {{48{1'b0}},dat[31:16]};
3318
//        2'd2:   fnDati = {{48{1'b0}},dat[47:32]};
3319
//        2'd3:   fnDati = {{48{1'b0}},dat[63:48]};
3320
//        endcase
3321
//    `LVH:
3322
//        case(adr[2])
3323
//        1'b0:   fnDati = {{32{dat[31]}},dat[31:0]};
3324
//        1'b1:   fnDati = {{32{dat[63]}},dat[63:32]};
3325
//        endcase
3326
//    `LVHU:
3327
//        case(adr[2])
3328
//        1'b0:   fnDati = {{32{1'b0}},dat[31:0]};
3329
//        1'b1:   fnDati = {{32{1'b0}},dat[63:32]};
3330
//        endcase
3331
////    `LVW:  fnDati = dat;
3332
//    default:  fnDati = dat;
3333
//      endcase
3334
default:    fnDati = dat;
3335
endcase
3336
endfunction
3337
 
3338
function [63:0] fnDato;
3339
input [47:0] isn;
3340
input [63:0] dat;
3341
case(isn[`INSTRUCTION_OP])
3342
`MEMNDX:
3343
        if (isn[`INSTRUCTION_L2]==2'b00)
3344
                case(isn[`INSTRUCTION_S2])
3345
                `SBX:   fnDato = {8{dat[7:0]}};
3346
                `SCX:   fnDato = {4{dat[15:0]}};
3347
                `SHX:   fnDato = {2{dat[31:0]}};
3348
                default:    fnDato = dat;
3349
                endcase
3350
        else
3351
                fnDato = dat;
3352
`SB:   fnDato = {8{dat[7:0]}};
3353
`Sx:
3354 49 robfinch
        casez(isn[20:18])
3355 48 robfinch
        3'b100: fnDato = dat;
3356
        3'b?10: fnDato = {2{dat[31:0]}};
3357
        3'b??1: fnDato = {4{dat[15:0]}};
3358
        default:        fnDato = dat;
3359
        endcase
3360
`AMO:
3361
        case(isn[23:21])
3362
        3'd0:   fnDato = {8{dat[7:0]}};
3363
        3'd1:   fnDato = {4{dat[15:0]}};
3364
        3'd2:   fnDato = {2{dat[31:0]}};
3365
        3'd3:   fnDato = dat;
3366
        default:        fnDato = dat;
3367
        endcase
3368
default:    fnDato = dat;
3369
endcase
3370
endfunction
3371
 
3372
// Indicate if the ALU instruction is valid immediately (single cycle operation)
3373
function IsSingleCycle;
3374
input [47:0] isn;
3375
IsSingleCycle = !(IsMul(isn)|IsDivmod(isn));
3376
endfunction
3377
 
3378
 
3379
`ifdef SUPPORT_SMT
3380
decoder8 iq0(.num({iqentry_tgt[0][8:7],iqentry_tgt[0][5:0]}), .out(iq0_out));
3381
decoder8 iq1(.num({iqentry_tgt[1][8:7],iqentry_tgt[1][5:0]}), .out(iq1_out));
3382
decoder8 iq2(.num({iqentry_tgt[2][8:7],iqentry_tgt[2][5:0]}), .out(iq2_out));
3383
decoder8 iq3(.num({iqentry_tgt[3][8:7],iqentry_tgt[3][5:0]}), .out(iq3_out));
3384
decoder8 iq4(.num({iqentry_tgt[4][8:7],iqentry_tgt[4][5:0]}), .out(iq4_out));
3385
decoder8 iq5(.num({iqentry_tgt[5][8:7],iqentry_tgt[5][5:0]}), .out(iq5_out));
3386
decoder8 iq6(.num({iqentry_tgt[6][8:7],iqentry_tgt[6][5:0]}), .out(iq6_out));
3387
decoder8 iq7(.num({iqentry_tgt[7][8:7],iqentry_tgt[7][5:0]}), .out(iq7_out));
3388
`else
3389
decoder7 iq0(.num({iqentry_tgt[0][7],iqentry_tgt[0][5:0]}), .out(iq0_out));
3390
decoder7 iq1(.num({iqentry_tgt[1][7],iqentry_tgt[1][5:0]}), .out(iq1_out));
3391
decoder7 iq2(.num({iqentry_tgt[2][7],iqentry_tgt[2][5:0]}), .out(iq2_out));
3392
decoder7 iq3(.num({iqentry_tgt[3][7],iqentry_tgt[3][5:0]}), .out(iq3_out));
3393
decoder7 iq4(.num({iqentry_tgt[4][7],iqentry_tgt[4][5:0]}), .out(iq4_out));
3394
decoder7 iq5(.num({iqentry_tgt[5][7],iqentry_tgt[5][5:0]}), .out(iq5_out));
3395
decoder7 iq6(.num({iqentry_tgt[6][7],iqentry_tgt[6][5:0]}), .out(iq6_out));
3396
decoder7 iq7(.num({iqentry_tgt[7][7],iqentry_tgt[7][5:0]}), .out(iq7_out));
3397
/*
3398
decoder6 iq0(.num({iqentry_tgt[0][5:0]}), .out(iq0_out));
3399
decoder6 iq1(.num({iqentry_tgt[1][5:0]}), .out(iq1_out));
3400
decoder6 iq2(.num({iqentry_tgt[2][5:0]}), .out(iq2_out));
3401
decoder6 iq3(.num({iqentry_tgt[3][5:0]}), .out(iq3_out));
3402
decoder6 iq4(.num({iqentry_tgt[4][5:0]}), .out(iq4_out));
3403
decoder6 iq5(.num({iqentry_tgt[5][5:0]}), .out(iq5_out));
3404
decoder6 iq6(.num({iqentry_tgt[6][5:0]}), .out(iq6_out));
3405
decoder6 iq7(.num({iqentry_tgt[7][5:0]}), .out(iq7_out));*/
3406
`endif
3407
 
3408
initial begin: Init
3409
        //
3410
        //
3411
        // set up panic messages
3412
        message[ `PANIC_NONE ]                  = "NONE            ";
3413
        message[ `PANIC_FETCHBUFBEQ ]           = "FETCHBUFBEQ     ";
3414
        message[ `PANIC_INVALIDISLOT ]          = "INVALIDISLOT    ";
3415
        message[ `PANIC_IDENTICALDRAMS ]        = "IDENTICALDRAMS  ";
3416
        message[ `PANIC_OVERRUN ]               = "OVERRUN         ";
3417
        message[ `PANIC_HALTINSTRUCTION ]       = "HALTINSTRUCTION ";
3418
        message[ `PANIC_INVALIDMEMOP ]          = "INVALIDMEMOP    ";
3419
        message[ `PANIC_INVALIDFBSTATE ]        = "INVALIDFBSTATE  ";
3420
        message[ `PANIC_INVALIDIQSTATE ]        = "INVALIDIQSTATE  ";
3421
        message[ `PANIC_BRANCHBACK ]            = "BRANCHBACK      ";
3422
        message[ `PANIC_MEMORYRACE ]            = "MEMORYRACE      ";
3423
        message[ `PANIC_ALU0ONLY ] = "ALU0 Only       ";
3424
 
3425
        for (n = 0; n < 64; n = n + 1)
3426
                codebuf[n] <= 48'h0;
3427
 
3428
end
3429
 
3430
// ---------------------------------------------------------------------------
3431
// FETCH
3432
// ---------------------------------------------------------------------------
3433
//
3434
assign fetchbuf0_mem   = IsMem(fetchbuf0_instr);
3435
assign fetchbuf0_memld = IsMem(fetchbuf0_instr) & IsLoad(fetchbuf0_instr);
3436
assign fetchbuf0_jmp   = IsFlowCtrl(fetchbuf0_instr);
3437
assign fetchbuf0_rfw   = IsRFW(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd);
3438
 
3439
assign fetchbuf1_mem   = IsMem(fetchbuf1_instr);
3440
assign fetchbuf1_memld = IsMem(fetchbuf1_instr) & IsLoad(fetchbuf1_instr);
3441
assign fetchbuf1_jmp   = IsFlowCtrl(fetchbuf1_instr);
3442
assign fetchbuf1_rfw   = IsRFW(fetchbuf1_instr,vqe1,vl,fetchbuf1_thrd);
3443
 
3444
FT64_fetchbuf #(AMSB,RSTPC) ufb1
3445
(
3446 49 robfinch
  .rst(rst),
3447
  .clk4x(clk4x),
3448
  .clk(clk),
3449
  .fcu_clk(fcu_clk),
3450
  .cs_i(adr_o[31:16]==16'hFFFF),
3451
  .cyc_i(cyc_o),
3452
  .stb_i(stb_o),
3453
  .ack_o(dc_ack),
3454
  .we_i(we_o),
3455
  .adr_i(adr_o[15:0]),
3456
  .dat_i(dat_o[31:0]),
3457
  .hirq(hirq),
3458
  .regLR(regLR),
3459
  .thread_en(thread_en),
3460
  .insn0(insn0),
3461
  .insn1(insn1),
3462
  .phit(phit),
3463
  .threadx(threadx),
3464
  .branchmiss(branchmiss),
3465
  .misspc(misspc),
3466
  .branchmiss_thrd(branchmiss_thrd),
3467
  .predict_takenA(predict_takenA),
3468
  .predict_takenB(predict_takenB),
3469
  .predict_takenC(predict_takenC),
3470
  .predict_takenD(predict_takenD),
3471
  .predict_taken0(predict_taken0),
3472
  .predict_taken1(predict_taken1),
3473
  .queued1(queued1),
3474
  .queued2(queued2),
3475
  .queuedNop(queuedNop),
3476
  .pc0(pc0),
3477
  .pc1(pc1),
3478
  .fetchbuf(fetchbuf),
3479
  .fetchbufA_v(fetchbufA_v),
3480
  .fetchbufB_v(fetchbufB_v),
3481
  .fetchbufC_v(fetchbufC_v),
3482
  .fetchbufD_v(fetchbufD_v),
3483
  .fetchbufA_pc(fetchbufA_pc),
3484
  .fetchbufB_pc(fetchbufB_pc),
3485
  .fetchbufC_pc(fetchbufC_pc),
3486
  .fetchbufD_pc(fetchbufD_pc),
3487
  .fetchbufA_instr(fetchbufA_instr),
3488
  .fetchbufB_instr(fetchbufB_instr),
3489
  .fetchbufC_instr(fetchbufC_instr),
3490
  .fetchbufD_instr(fetchbufD_instr),
3491
  .fetchbuf0_instr(fetchbuf0_instr),
3492
  .fetchbuf1_instr(fetchbuf1_instr),
3493
  .fetchbuf0_thrd(fetchbuf0_thrd),
3494
  .fetchbuf1_thrd(fetchbuf1_thrd),
3495
  .fetchbuf0_pc(fetchbuf0_pc),
3496
  .fetchbuf1_pc(fetchbuf1_pc),
3497
  .fetchbuf0_v(fetchbuf0_v),
3498
  .fetchbuf1_v(fetchbuf1_v),
3499
  .fetchbuf0_insln(fetchbuf0_insln),
3500
  .fetchbuf1_insln(fetchbuf1_insln),
3501
  .codebuf0(codebuf[insn0[21:16]]),
3502
  .codebuf1(codebuf[insn1[21:16]]),
3503
  .btgtA(btgtA),
3504
  .btgtB(btgtB),
3505
  .btgtC(btgtC),
3506
  .btgtD(btgtD),
3507
  .nop_fetchbuf(nop_fetchbuf),
3508
  .take_branch0(take_branch0),
3509
  .take_branch1(take_branch1),
3510
  .stompedRets(stompedOnRets),
3511
  .panic(fb_panic)
3512 48 robfinch
);
3513
 
3514
 
3515
 
3516
//initial begin: stop_at
3517
//#1000000; panic <= `PANIC_OVERRUN;
3518
//end
3519
 
3520
//
3521
// BRANCH-MISS LOGIC: livetarget
3522
//
3523
// livetarget implies that there is a not-to-be-stomped instruction that targets the register in question
3524
// therefore, if it is zero it implies the rf_v value should become VALID on a branchmiss
3525
// 
3526
 
3527
generate begin : live_target
3528
    for (g = 1; g < PREGS; g = g + 1) begin : lvtgt
3529
    assign livetarget[g] = iqentry_0_livetarget[g] |
3530
                        iqentry_1_livetarget[g] |
3531
                        iqentry_2_livetarget[g] |
3532
                        iqentry_3_livetarget[g] |
3533
                        iqentry_4_livetarget[g] |
3534
                        iqentry_5_livetarget[g] |
3535
                        iqentry_6_livetarget[g] |
3536
                        iqentry_7_livetarget[g];
3537
    end
3538
end
3539
endgenerate
3540
 
3541
    assign  iqentry_0_livetarget = {PREGS {iqentry_v[0]}} & {PREGS {~iqentry_stomp[0] && iqentry_thrd[0]==branchmiss_thrd}} & iq0_out,
3542
            iqentry_1_livetarget = {PREGS {iqentry_v[1]}} & {PREGS {~iqentry_stomp[1] && iqentry_thrd[1]==branchmiss_thrd}} & iq1_out,
3543
            iqentry_2_livetarget = {PREGS {iqentry_v[2]}} & {PREGS {~iqentry_stomp[2] && iqentry_thrd[2]==branchmiss_thrd}} & iq2_out,
3544
            iqentry_3_livetarget = {PREGS {iqentry_v[3]}} & {PREGS {~iqentry_stomp[3] && iqentry_thrd[3]==branchmiss_thrd}} & iq3_out,
3545
            iqentry_4_livetarget = {PREGS {iqentry_v[4]}} & {PREGS {~iqentry_stomp[4] && iqentry_thrd[4]==branchmiss_thrd}} & iq4_out,
3546
            iqentry_5_livetarget = {PREGS {iqentry_v[5]}} & {PREGS {~iqentry_stomp[5] && iqentry_thrd[5]==branchmiss_thrd}} & iq5_out,
3547
            iqentry_6_livetarget = {PREGS {iqentry_v[6]}} & {PREGS {~iqentry_stomp[6] && iqentry_thrd[6]==branchmiss_thrd}} & iq6_out,
3548
            iqentry_7_livetarget = {PREGS {iqentry_v[7]}} & {PREGS {~iqentry_stomp[7] && iqentry_thrd[7]==branchmiss_thrd}} & iq7_out;
3549
 
3550
    //
3551
    // BRANCH-MISS LOGIC: latestID
3552
    //
3553
    // latestID is the instruction queue ID of the newest instruction (latest) that targets
3554
    // a particular register.  looks a lot like scheduling logic, but in reverse.
3555
    // 
3556
    assign iqentry_0_cumulative = (missid==3'd0) ? iqentry_0_livetarget :
3557
                                  (missid==3'd1) ? iqentry_0_livetarget |
3558
                                                   iqentry_1_livetarget :
3559
                                  (missid==3'd2) ? iqentry_0_livetarget |
3560
                                                   iqentry_1_livetarget |
3561
                                                   iqentry_2_livetarget :
3562
                                  (missid==3'd3) ? iqentry_0_livetarget |
3563
                                                   iqentry_1_livetarget |
3564
                                                   iqentry_2_livetarget |
3565
                                                   iqentry_3_livetarget :
3566
                                  (missid==3'd4) ? iqentry_0_livetarget |
3567
                                                   iqentry_1_livetarget |
3568
                                                   iqentry_2_livetarget |
3569
                                                   iqentry_3_livetarget |
3570
                                                   iqentry_4_livetarget :
3571
                                  (missid==3'd5) ? iqentry_0_livetarget |
3572
                                                   iqentry_1_livetarget |
3573
                                                   iqentry_2_livetarget |
3574
                                                   iqentry_3_livetarget |
3575
                                                   iqentry_4_livetarget |
3576
                                                   iqentry_5_livetarget :
3577
                                  (missid==3'd6) ? iqentry_0_livetarget |
3578
                                                   iqentry_1_livetarget |
3579
                                                   iqentry_2_livetarget |
3580
                                                   iqentry_3_livetarget |
3581
                                                   iqentry_4_livetarget |
3582
                                                   iqentry_5_livetarget |
3583
                                                   iqentry_6_livetarget :
3584
                                  (missid==3'd7) ? iqentry_0_livetarget |
3585
                                                   iqentry_1_livetarget |
3586
                                                   iqentry_2_livetarget |
3587
                                                   iqentry_3_livetarget |
3588
                                                   iqentry_4_livetarget |
3589
                                                   iqentry_5_livetarget |
3590
                                                   iqentry_6_livetarget |
3591
                                                   iqentry_7_livetarget :
3592
                                                   {PREGS{1'b0}};
3593
 
3594
    assign iqentry_1_cumulative = (missid==3'd1) ? iqentry_1_livetarget :
3595
                                  (missid==3'd2) ? iqentry_1_livetarget |
3596
                                                   iqentry_2_livetarget :
3597
                                  (missid==3'd3) ? iqentry_1_livetarget |
3598
                                                   iqentry_2_livetarget |
3599
                                                   iqentry_3_livetarget :
3600
                                  (missid==3'd4) ? iqentry_1_livetarget |
3601
                                                   iqentry_2_livetarget |
3602
                                                   iqentry_3_livetarget |
3603
                                                   iqentry_4_livetarget :
3604
                                  (missid==3'd5) ? iqentry_1_livetarget |
3605
                                                   iqentry_2_livetarget |
3606
                                                   iqentry_3_livetarget |
3607
                                                   iqentry_4_livetarget |
3608
                                                   iqentry_5_livetarget :
3609
                                  (missid==3'd6) ? iqentry_1_livetarget |
3610
                                                   iqentry_2_livetarget |
3611
                                                   iqentry_3_livetarget |
3612
                                                   iqentry_4_livetarget |
3613
                                                   iqentry_5_livetarget |
3614
                                                   iqentry_6_livetarget :
3615
                                  (missid==3'd7) ? iqentry_1_livetarget |
3616
                                                   iqentry_2_livetarget |
3617
                                                   iqentry_3_livetarget |
3618
                                                   iqentry_4_livetarget |
3619
                                                   iqentry_5_livetarget |
3620
                                                   iqentry_6_livetarget |
3621
                                                   iqentry_7_livetarget :
3622
                                  (missid==3'd0) ? iqentry_1_livetarget |
3623
                                                   iqentry_2_livetarget |
3624
                                                   iqentry_3_livetarget |
3625
                                                   iqentry_4_livetarget |
3626
                                                   iqentry_5_livetarget |
3627
                                                   iqentry_6_livetarget |
3628
                                                   iqentry_7_livetarget |
3629
                                                   iqentry_0_livetarget :
3630
                                                   {PREGS{1'b0}};
3631
 
3632
    assign iqentry_2_cumulative = (missid==3'd2) ? iqentry_2_livetarget :
3633
                                     (missid==3'd3) ? iqentry_2_livetarget |
3634
                                                      iqentry_3_livetarget :
3635
                                     (missid==3'd4) ? iqentry_2_livetarget |
3636
                                                      iqentry_3_livetarget |
3637
                                                      iqentry_4_livetarget :
3638
                                     (missid==3'd5) ? iqentry_2_livetarget |
3639
                                                      iqentry_3_livetarget |
3640
                                                      iqentry_4_livetarget |
3641
                                                      iqentry_5_livetarget :
3642
                                     (missid==3'd6) ? iqentry_2_livetarget |
3643
                                                      iqentry_3_livetarget |
3644
                                                      iqentry_4_livetarget |
3645
                                                      iqentry_5_livetarget |
3646
                                                      iqentry_6_livetarget :
3647
                                     (missid==3'd7) ? iqentry_2_livetarget |
3648
                                                      iqentry_3_livetarget |
3649
                                                      iqentry_4_livetarget |
3650
                                                      iqentry_5_livetarget |
3651
                                                      iqentry_6_livetarget |
3652
                                                      iqentry_7_livetarget :
3653
                                     (missid==3'd0) ? iqentry_2_livetarget |
3654
                                                      iqentry_3_livetarget |
3655
                                                      iqentry_4_livetarget |
3656
                                                      iqentry_5_livetarget |
3657
                                                      iqentry_6_livetarget |
3658
                                                      iqentry_7_livetarget |
3659
                                                      iqentry_0_livetarget :
3660
                                     (missid==3'd1) ? iqentry_2_livetarget |
3661
                                                      iqentry_3_livetarget |
3662
                                                      iqentry_4_livetarget |
3663
                                                      iqentry_5_livetarget |
3664
                                                      iqentry_6_livetarget |
3665
                                                      iqentry_7_livetarget |
3666
                                                      iqentry_0_livetarget |
3667
                                                      iqentry_1_livetarget :
3668
                                                      {PREGS{1'b0}};
3669
 
3670
    assign iqentry_3_cumulative = (missid==3'd3) ? iqentry_3_livetarget :
3671
                                     (missid==3'd4) ? iqentry_3_livetarget |
3672
                                                      iqentry_4_livetarget :
3673
                                     (missid==3'd5) ? iqentry_3_livetarget |
3674
                                                      iqentry_4_livetarget |
3675
                                                      iqentry_5_livetarget :
3676
                                     (missid==3'd6) ? iqentry_3_livetarget |
3677
                                                      iqentry_4_livetarget |
3678
                                                      iqentry_5_livetarget |
3679
                                                      iqentry_6_livetarget :
3680
                                     (missid==3'd7) ? iqentry_3_livetarget |
3681
                                                      iqentry_4_livetarget |
3682
                                                      iqentry_5_livetarget |
3683
                                                      iqentry_6_livetarget |
3684
                                                      iqentry_7_livetarget :
3685
                                     (missid==3'd0) ? iqentry_3_livetarget |
3686
                                                      iqentry_4_livetarget |
3687
                                                      iqentry_5_livetarget |
3688
                                                      iqentry_6_livetarget |
3689
                                                      iqentry_7_livetarget |
3690
                                                      iqentry_0_livetarget :
3691
                                     (missid==3'd1) ? iqentry_3_livetarget |
3692
                                                      iqentry_4_livetarget |
3693
                                                      iqentry_5_livetarget |
3694
                                                      iqentry_6_livetarget |
3695
                                                      iqentry_7_livetarget |
3696
                                                      iqentry_0_livetarget |
3697
                                                      iqentry_1_livetarget :
3698
                                     (missid==3'd2) ? iqentry_3_livetarget |
3699
                                                      iqentry_4_livetarget |
3700
                                                      iqentry_5_livetarget |
3701
                                                      iqentry_6_livetarget |
3702
                                                      iqentry_7_livetarget |
3703
                                                      iqentry_0_livetarget |
3704
                                                      iqentry_1_livetarget |
3705
                                                      iqentry_2_livetarget :
3706
                                                      {PREGS{1'b0}};
3707
 
3708
    assign iqentry_4_cumulative = (missid==3'd4) ? iqentry_4_livetarget :
3709
                                     (missid==3'd5) ? iqentry_4_livetarget |
3710
                                                      iqentry_5_livetarget :
3711
                                     (missid==3'd6) ? iqentry_4_livetarget |
3712
                                                      iqentry_5_livetarget |
3713
                                                      iqentry_6_livetarget :
3714
                                     (missid==3'd7) ? iqentry_4_livetarget |
3715
                                                      iqentry_5_livetarget |
3716
                                                      iqentry_6_livetarget |
3717
                                                      iqentry_7_livetarget :
3718
                                     (missid==3'd0) ? iqentry_4_livetarget |
3719
                                                      iqentry_5_livetarget |
3720
                                                      iqentry_6_livetarget |
3721
                                                      iqentry_7_livetarget |
3722
                                                      iqentry_0_livetarget :
3723
                                     (missid==3'd1) ? iqentry_4_livetarget |
3724
                                                      iqentry_5_livetarget |
3725
                                                      iqentry_6_livetarget |
3726
                                                      iqentry_7_livetarget |
3727
                                                      iqentry_0_livetarget |
3728
                                                      iqentry_1_livetarget :
3729
                                     (missid==3'd2) ? iqentry_4_livetarget |
3730
                                                      iqentry_5_livetarget |
3731
                                                      iqentry_6_livetarget |
3732
                                                      iqentry_7_livetarget |
3733
                                                      iqentry_0_livetarget |
3734
                                                      iqentry_1_livetarget |
3735
                                                      iqentry_2_livetarget :
3736
                                     (missid==3'd3) ? iqentry_4_livetarget |
3737
                                                      iqentry_5_livetarget |
3738
                                                      iqentry_6_livetarget |
3739
                                                      iqentry_7_livetarget |
3740
                                                      iqentry_0_livetarget |
3741
                                                      iqentry_1_livetarget |
3742
                                                      iqentry_2_livetarget |
3743
                                                      iqentry_3_livetarget :
3744
                                                      {PREGS{1'b0}};
3745
 
3746
    assign iqentry_5_cumulative = (missid==3'd5) ? iqentry_5_livetarget :
3747
                                     (missid==3'd6) ? iqentry_5_livetarget |
3748
                                                      iqentry_6_livetarget :
3749
                                     (missid==3'd7) ? iqentry_5_livetarget |
3750
                                                      iqentry_6_livetarget |
3751
                                                      iqentry_7_livetarget :
3752
                                     (missid==3'd0) ? iqentry_5_livetarget |
3753
                                                      iqentry_6_livetarget |
3754
                                                      iqentry_7_livetarget |
3755
                                                      iqentry_0_livetarget :
3756
                                     (missid==3'd1) ? iqentry_5_livetarget |
3757
                                                      iqentry_6_livetarget |
3758
                                                      iqentry_7_livetarget |
3759
                                                      iqentry_0_livetarget |
3760
                                                      iqentry_1_livetarget :
3761
                                     (missid==3'd2) ? iqentry_5_livetarget |
3762
                                                      iqentry_6_livetarget |
3763
                                                      iqentry_7_livetarget |
3764
                                                      iqentry_0_livetarget |
3765
                                                      iqentry_1_livetarget |
3766
                                                      iqentry_2_livetarget :
3767
                                     (missid==3'd3) ? iqentry_5_livetarget |
3768
                                                      iqentry_6_livetarget |
3769
                                                      iqentry_7_livetarget |
3770
                                                      iqentry_0_livetarget |
3771
                                                      iqentry_1_livetarget |
3772
                                                      iqentry_2_livetarget |
3773
                                                      iqentry_3_livetarget :
3774
                                     (missid==3'd4) ? iqentry_5_livetarget |
3775
                                                      iqentry_6_livetarget |
3776
                                                      iqentry_7_livetarget |
3777
                                                      iqentry_0_livetarget |
3778
                                                      iqentry_1_livetarget |
3779
                                                      iqentry_2_livetarget |
3780
                                                      iqentry_3_livetarget |
3781
                                                      iqentry_4_livetarget :
3782
                                                      {PREGS{1'b0}};
3783
    assign iqentry_6_cumulative = (missid==3'd6) ? iqentry_6_livetarget :
3784
                                       (missid==3'd7) ? iqentry_6_livetarget |
3785
                                                        iqentry_7_livetarget :
3786
                                       (missid==3'd0) ? iqentry_6_livetarget |
3787
                                                        iqentry_7_livetarget |
3788
                                                        iqentry_0_livetarget :
3789
                                       (missid==3'd1) ? iqentry_6_livetarget |
3790
                                                        iqentry_7_livetarget |
3791
                                                        iqentry_0_livetarget |
3792
                                                        iqentry_1_livetarget :
3793
                                       (missid==3'd2) ? iqentry_6_livetarget |
3794
                                                        iqentry_7_livetarget |
3795
                                                        iqentry_0_livetarget |
3796
                                                        iqentry_1_livetarget |
3797
                                                        iqentry_2_livetarget :
3798
                                       (missid==3'd3) ? iqentry_6_livetarget |
3799
                                                        iqentry_7_livetarget |
3800
                                                        iqentry_0_livetarget |
3801
                                                        iqentry_1_livetarget |
3802
                                                        iqentry_2_livetarget |
3803
                                                        iqentry_3_livetarget :
3804
                                       (missid==3'd4) ? iqentry_6_livetarget |
3805
                                                        iqentry_7_livetarget |
3806
                                                        iqentry_0_livetarget |
3807
                                                        iqentry_1_livetarget |
3808
                                                        iqentry_2_livetarget |
3809
                                                        iqentry_3_livetarget |
3810
                                                        iqentry_4_livetarget :
3811
                                       (missid==3'd5) ? iqentry_6_livetarget |
3812
                                                        iqentry_7_livetarget |
3813
                                                        iqentry_0_livetarget |
3814
                                                        iqentry_1_livetarget |
3815
                                                        iqentry_2_livetarget |
3816
                                                        iqentry_3_livetarget |
3817
                                                        iqentry_4_livetarget |
3818
                                                        iqentry_5_livetarget :
3819
                                                        {PREGS{1'b0}};
3820
 
3821
    assign iqentry_7_cumulative = (missid==3'd7) ? iqentry_7_livetarget :
3822
                                       (missid==3'd0) ? iqentry_7_livetarget |
3823
                                                        iqentry_0_livetarget :
3824
                                       (missid==3'd1) ? iqentry_7_livetarget |
3825
                                                        iqentry_0_livetarget |
3826
                                                        iqentry_1_livetarget :
3827
                                       (missid==3'd2) ? iqentry_7_livetarget |
3828
                                                        iqentry_0_livetarget |
3829
                                                        iqentry_1_livetarget |
3830
                                                        iqentry_2_livetarget :
3831
                                       (missid==3'd3) ? iqentry_7_livetarget |
3832
                                                        iqentry_0_livetarget |
3833
                                                        iqentry_1_livetarget |
3834
                                                        iqentry_2_livetarget |
3835
                                                        iqentry_3_livetarget :
3836
                                       (missid==3'd4) ? iqentry_7_livetarget |
3837
                                                        iqentry_0_livetarget |
3838
                                                        iqentry_1_livetarget |
3839
                                                        iqentry_2_livetarget |
3840
                                                        iqentry_3_livetarget |
3841
                                                        iqentry_4_livetarget :
3842
                                       (missid==3'd5) ? iqentry_7_livetarget |
3843
                                                        iqentry_0_livetarget |
3844
                                                        iqentry_1_livetarget |
3845
                                                        iqentry_2_livetarget |
3846
                                                        iqentry_3_livetarget |
3847
                                                        iqentry_4_livetarget |
3848
                                                        iqentry_5_livetarget :
3849
                                       (missid==3'd6) ? iqentry_7_livetarget |
3850
                                                        iqentry_0_livetarget |
3851
                                                        iqentry_1_livetarget |
3852
                                                        iqentry_2_livetarget |
3853
                                                        iqentry_3_livetarget |
3854
                                                        iqentry_4_livetarget |
3855
                                                        iqentry_5_livetarget |
3856
                                                        iqentry_6_livetarget :
3857
                                                        {PREGS{1'b0}};
3858
 
3859
    assign iqentry_0_latestID = (missid == 3'd0 || ((iqentry_0_livetarget & iqentry_1_cumulative) == {PREGS{1'b0}}))
3860
                                    ? iqentry_0_livetarget
3861
                                    : {PREGS{1'b0}};
3862
 
3863
    assign iqentry_1_latestID = (missid == 3'd1 || ((iqentry_1_livetarget & iqentry_2_cumulative) == {PREGS{1'b0}}))
3864
                                    ? iqentry_1_livetarget
3865
                                    : {PREGS{1'b0}};
3866
 
3867
    assign iqentry_2_latestID = (missid == 3'd2 || ((iqentry_2_livetarget & iqentry_3_cumulative) == {PREGS{1'b0}}))
3868
                                    ? iqentry_2_livetarget
3869
                                    : {PREGS{1'b0}};
3870
 
3871
    assign iqentry_3_latestID = (missid == 3'd3 || ((iqentry_3_livetarget & iqentry_4_cumulative) == {PREGS{1'b0}}))
3872
                                    ? iqentry_3_livetarget
3873
                                    : {PREGS{1'b0}};
3874
 
3875
    assign iqentry_4_latestID = (missid == 3'd4 || ((iqentry_4_livetarget & iqentry_5_cumulative) == {PREGS{1'b0}}))
3876
                                    ? iqentry_4_livetarget
3877
                                    : {PREGS{1'b0}};
3878
 
3879
    assign iqentry_5_latestID = (missid == 3'd5 || ((iqentry_5_livetarget & iqentry_6_cumulative) == {PREGS{1'b0}}))
3880
                                    ? iqentry_5_livetarget
3881
                                    : {PREGS{1'b0}};
3882
 
3883
    assign iqentry_6_latestID = (missid == 3'd6 || ((iqentry_6_livetarget & iqentry_7_cumulative) == {PREGS{1'b0}}))
3884
                                    ? iqentry_6_livetarget
3885
                                    : {PREGS{1'b0}};
3886
 
3887
    assign iqentry_7_latestID = (missid == 3'd7 || ((iqentry_7_livetarget & iqentry_0_cumulative) == {PREGS{1'b0}}))
3888
                                    ? iqentry_7_livetarget
3889
                                    : {PREGS{1'b0}};
3890
 
3891 49 robfinch
assign  iqentry_source[0] = | iqentry_0_latestID,
3892
  iqentry_source[1] = | iqentry_1_latestID,
3893
  iqentry_source[2] = | iqentry_2_latestID,
3894
  iqentry_source[3] = | iqentry_3_latestID,
3895
  iqentry_source[4] = | iqentry_4_latestID,
3896
  iqentry_source[5] = | iqentry_5_latestID,
3897
  iqentry_source[6] = | iqentry_6_latestID,
3898
  iqentry_source[7] = | iqentry_7_latestID;
3899 48 robfinch
 
3900
 
3901
reg vqueued2;
3902
assign Ra0 = fnRa(fetchbuf0_instr,vqe0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3903
assign Rb0 = fnRb(fetchbuf0_instr,1'b0,vqe0,rfoa0[5:0],rfoa1[5:0],fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3904
assign Rc0 = fnRc(fetchbuf0_instr,vqe0,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3905
assign Rt0 = fnRt(fetchbuf0_instr,vqet0,vl,fetchbuf0_thrd) | {fetchbuf0_thrd,7'b0};
3906
assign Ra1 = fnRa(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3907
assign Rb1 = fnRb(fetchbuf1_instr,1'b1,vqueued2 ? vqe0 + 1 : vqe1,rfoa0[5:0],rfoa1[5:0],fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3908
assign Rc1 = fnRc(fetchbuf1_instr,vqueued2 ? vqe0 + 1 : vqe1,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3909
assign Rt1 = fnRt(fetchbuf1_instr,vqueued2 ? vqet0 + 1 : vqet1,vl,fetchbuf1_thrd) | {fetchbuf1_thrd,7'b0};
3910
 
3911 49 robfinch
//
3912
// additional logic for ISSUE
3913
//
3914
// for the moment, we look at ALU-input buffers to allow back-to-back issue of 
3915
// dependent instructions ... we do not, however, look ahead for DRAM requests 
3916
// that will become valid in the next cycle.  instead, these have to propagate
3917
// their results into the IQ entry directly, at which point it becomes issue-able
3918
//
3919 48 robfinch
 
3920 49 robfinch
// note that, for all intents & purposes, iqentry_done == iqentry_agen ... no need to duplicate
3921 48 robfinch
 
3922
wire [QENTRIES-1:0] args_valid;
3923
wire [QENTRIES-1:0] could_issue;
3924
wire [QENTRIES-1:0] could_issueid;
3925
 
3926
generate begin : issue_logic
3927
for (g = 0; g < QENTRIES; g = g + 1)
3928
begin
3929
assign args_valid[g] =
3930
                  (iqentry_a1_v[g]
3931 49 robfinch
`ifdef FU_BYPASS
3932 48 robfinch
        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3933 49 robfinch
        || ((iqentry_a1_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3934
        || ((iqentry_a1_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
3935
`endif
3936
        )
3937 48 robfinch
    && (iqentry_a2_v[g]
3938
        || (iqentry_mem[g] & ~iqentry_agen[g] & ~iqentry_memndx[g])    // a2 needs to be valid for indexed instruction
3939 49 robfinch
`ifdef FU_BYPASS
3940 48 robfinch
        || (iqentry_a2_s[g] == alu0_sourceid && alu0_dataready)
3941 49 robfinch
        || ((iqentry_a2_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3942
        || ((iqentry_a2_s[g] == fpu1_sourceid && fpu1_dataready) && (`NUM_FPU > 0))
3943
`endif
3944
        )
3945 48 robfinch
    && (iqentry_a3_v[g]
3946
//        || (iqentry_mem[g] & ~iqentry_agen[g])
3947 49 robfinch
`ifdef FU_BYPASS
3948 48 robfinch
        || (iqentry_a3_s[g] == alu0_sourceid && alu0_dataready)
3949 49 robfinch
        || ((iqentry_a3_s[g] == alu1_sourceid && alu1_dataready) && (`NUM_ALU > 1))
3950
`endif
3951
        )
3952 48 robfinch
    ;
3953
 
3954
assign could_issue[g] = iqentry_v[g] && !iqentry_done[g] && !iqentry_out[g]
3955
                                                                                                && args_valid[g]
3956
                                                                                                && iqentry_iv[g]
3957
                        && (iqentry_mem[g] ? !iqentry_agen[g] : 1'b1);
3958
 
3959
assign could_issueid[g] = iqentry_v[g] && !iqentry_iv[g];
3960
//                && (iqentry_a1_v[g] 
3961
//        || (iqentry_a1_s[g] == alu0_sourceid && alu0_dataready)
3962
//        || (iqentry_a1_s[g] == alu1_sourceid && alu1_dataready));
3963
 
3964
end
3965
end
3966
endgenerate
3967
 
3968
// The (old) simulator didn't handle the asynchronous race loop properly in the 
3969
// original code. It would issue two instructions to the same islot. So the
3970
// issue logic has been re-written to eliminate the asynchronous loop.
3971
// Can't issue to the ALU if it's busy doing a long running operation like a 
3972
// divide.
3973
// ToDo: fix the memory synchronization, see fp_issue below
3974
 
3975
wire [`QBITS] heads [QENTRIES-1:0];
3976
assign heads[0] = head0;
3977
assign heads[1] = head1;
3978
assign heads[2] = head2;
3979
assign heads[3] = head3;
3980
assign heads[4] = head4;
3981
assign heads[5] = head5;
3982
assign heads[6] = head6;
3983
assign heads[7] = head7;
3984
 
3985
always @*
3986
begin
3987 49 robfinch
        iqentry_id1issue = {QENTRIES{1'b0}};
3988 48 robfinch
        if (id1_available) begin
3989
                for (n = 0; n < QENTRIES; n = n + 1)
3990 49 robfinch
                        if (could_issueid[heads[n]] && iqentry_id1issue=={QENTRIES{1'b0}})
3991 48 robfinch
                          iqentry_id1issue[heads[n]] = `TRUE;
3992
        end
3993 49 robfinch
end
3994
generate begin : gIDUIssue
3995
        if (`NUM_IDU > 1) begin
3996
                always @*
3997
                begin
3998
                        iqentry_id2issue = {QENTRIES{1'b0}};
3999
                        if (id2_available) begin
4000
                                for (n = 0; n < QENTRIES; n = n + 1)
4001
                                        if (could_issueid[heads[n]] && !iqentry_id1issue[heads[n]] && iqentry_id2issue=={QENTRIES{1'b0}})
4002
                                          iqentry_id2issue[heads[n]] = `TRUE;
4003
                        end
4004
                end
4005 48 robfinch
        end
4006 49 robfinch
        if (`NUM_IDU > 2) begin
4007
                always @*
4008
                begin
4009
                        iqentry_id3issue = {QENTRIES{1'b0}};
4010
                        if (id3_available) begin
4011
                                for (n = 0; n < QENTRIES; n = n + 1)
4012
                                        if (could_issueid[heads[n]]
4013
                                        && !iqentry_id1issue[heads[n]]
4014
                                        && !iqentry_id2issue[heads[n]]
4015
                                        && iqentry_id3issue=={QENTRIES{1'b0}})
4016
                                          iqentry_id3issue[heads[n]] = `TRUE;
4017
                        end
4018
                end
4019
        end
4020 48 robfinch
end
4021 49 robfinch
endgenerate
4022 48 robfinch
 
4023
always @*
4024
begin
4025 49 robfinch
        iqentry_alu0_issue = {QENTRIES{1'b0}};
4026
        iqentry_alu1_issue = {QENTRIES{1'b0}};
4027 48 robfinch
 
4028
        if (alu0_available & alu0_idle) begin
4029
                if (could_issue[head0] && iqentry_alu[head0]) begin
4030
                  iqentry_alu0_issue[head0] = `TRUE;
4031
                end
4032
                else if (could_issue[head1] && iqentry_alu[head1])
4033
                begin
4034
                  iqentry_alu0_issue[head1] = `TRUE;
4035
                end
4036
                else if (could_issue[head2] && iqentry_alu[head2]
4037
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4038
                )
4039
                begin
4040
                        iqentry_alu0_issue[head2] = `TRUE;
4041
                end
4042
                else if (could_issue[head3] && iqentry_alu[head3]
4043
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4044
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4045
                                ((!iqentry_v[head0])
4046
                        &&   (!iqentry_v[head1]))
4047
                        )
4048
                ) begin
4049
                        iqentry_alu0_issue[head3] = `TRUE;
4050
                end
4051
                else if (could_issue[head4] && iqentry_alu[head4]
4052
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4053
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4054
                                ((!iqentry_v[head0])
4055
                        &&   (!iqentry_v[head1]))
4056
                        )
4057
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4058
                                ((!iqentry_v[head0])
4059
                        &&   (!iqentry_v[head1])
4060
                        &&   (!iqentry_v[head2]))
4061
                        )
4062
                ) begin
4063
                        iqentry_alu0_issue[head4] = `TRUE;
4064
                end
4065
                else if (could_issue[head5] && iqentry_alu[head5]
4066
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4067
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4068
                                ((!iqentry_v[head0])
4069
                        &&   (!iqentry_v[head1]))
4070
                        )
4071
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4072
                                ((!iqentry_v[head0])
4073
                        &&   (!iqentry_v[head1])
4074
                        &&   (!iqentry_v[head2]))
4075
                        )
4076
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4077
                                ((!iqentry_v[head0])
4078
                        &&   (!iqentry_v[head1])
4079
                        &&   (!iqentry_v[head2])
4080
                        &&   (!iqentry_v[head3]))
4081
                        )
4082
                ) begin
4083
                        iqentry_alu0_issue[head5] = `TRUE;
4084
                end
4085
`ifdef FULL_ISSUE_LOGIC
4086
                else if (could_issue[head6] && iqentry_alu[head6]
4087
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4088
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4089
                                ((!iqentry_v[head0])
4090
                        &&   (!iqentry_v[head1]))
4091
                        )
4092
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4093
                                ((!iqentry_v[head0])
4094
                        &&   (!iqentry_v[head1])
4095
                        &&   (!iqentry_v[head2]))
4096
                        )
4097
                && (!(iqentry_v[head4] && iqentry_sync[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]) ||
4104
                                ((!iqentry_v[head0])
4105
                        &&   (!iqentry_v[head1])
4106
                        &&   (!iqentry_v[head2])
4107
                        &&   (!iqentry_v[head3])
4108
                        &&   (!iqentry_v[head4]))
4109
                        )
4110
                ) begin
4111
                        iqentry_alu0_issue[head6] = `TRUE;
4112
                end
4113
                else if (could_issue[head7] && iqentry_alu[head7]
4114
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4115
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4116
                                ((!iqentry_v[head0])
4117
                        &&   (!iqentry_v[head1]))
4118
                        )
4119
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4120
                                ((!iqentry_v[head0])
4121
                        &&   (!iqentry_v[head1])
4122
                        &&   (!iqentry_v[head2]))
4123
                        )
4124
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4125
                                ((!iqentry_v[head0])
4126
                        &&   (!iqentry_v[head1])
4127
                        &&   (!iqentry_v[head2])
4128
                        &&   (!iqentry_v[head3]))
4129
                        )
4130
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4131
                                ((!iqentry_v[head0])
4132
                        &&   (!iqentry_v[head1])
4133
                        &&   (!iqentry_v[head2])
4134
                        &&   (!iqentry_v[head3])
4135
                        &&   (!iqentry_v[head4]))
4136
                        )
4137
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4138
                                ((!iqentry_v[head0])
4139
                        &&   (!iqentry_v[head1])
4140
                        &&   (!iqentry_v[head2])
4141
                        &&   (!iqentry_v[head3])
4142
                        &&   (!iqentry_v[head4])
4143
                        &&   (!iqentry_v[head5]))
4144
                        )
4145
                ) begin
4146
                        iqentry_alu0_issue[head7] = `TRUE;
4147
                end
4148
`endif
4149
        end
4150
 
4151 49 robfinch
        if (alu1_available && alu1_idle && `NUM_ALU > 1) begin
4152 48 robfinch
                if ((could_issue & ~iqentry_alu0_issue & ~iqentry_alu0) != 8'h00) begin
4153
                if (could_issue[head0] && iqentry_alu[head0]
4154
                && !iqentry_alu0[head0] // alu0only
4155
                && !iqentry_alu0_issue[head0]) begin
4156
                  iqentry_alu1_issue[head0] = `TRUE;
4157
                end
4158
                else if (could_issue[head1] && !iqentry_alu0_issue[head1] && iqentry_alu[head1]
4159
                && !iqentry_alu0[head1])
4160
                begin
4161
                  iqentry_alu1_issue[head1] = `TRUE;
4162
                end
4163
                else if (could_issue[head2] && !iqentry_alu0_issue[head2] && iqentry_alu[head2]
4164
                && !iqentry_alu0[head2]
4165
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4166
                )
4167
                begin
4168
                        iqentry_alu1_issue[head2] = `TRUE;
4169
                end
4170
                else if (could_issue[head3] && !iqentry_alu0_issue[head3] && iqentry_alu[head3]
4171
                && !iqentry_alu0[head3]
4172
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4173
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4174
                                ((!iqentry_v[head0])
4175
                        &&   (!iqentry_v[head1]))
4176
                        )
4177
                ) begin
4178
                        iqentry_alu1_issue[head3] = `TRUE;
4179
                end
4180
                else if (could_issue[head4] && !iqentry_alu0_issue[head4] && iqentry_alu[head4]
4181
                && !iqentry_alu0[head4]
4182
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4183
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4184
                                ((!iqentry_v[head0])
4185
                        &&   (!iqentry_v[head1]))
4186
                        )
4187
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4188
                                ((!iqentry_v[head0])
4189
                        &&   (!iqentry_v[head1])
4190
                        &&   (!iqentry_v[head2]))
4191
                        )
4192
                ) begin
4193
                        iqentry_alu1_issue[head4] = `TRUE;
4194
                end
4195
                else if (could_issue[head5] && !iqentry_alu0_issue[head5] && iqentry_alu[head5]
4196
                && !iqentry_alu0[head5]
4197
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4198
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4199
                                ((!iqentry_v[head0])
4200
                        &&   (!iqentry_v[head1]))
4201
                        )
4202
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4203
                                ((!iqentry_v[head0])
4204
                        &&   (!iqentry_v[head1])
4205
                        &&   (!iqentry_v[head2]))
4206
                        )
4207
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4208
                                ((!iqentry_v[head0])
4209
                        &&   (!iqentry_v[head1])
4210
                        &&   (!iqentry_v[head2])
4211
                        &&   (!iqentry_v[head3]))
4212
                        )
4213
                ) begin
4214
                        iqentry_alu1_issue[head5] = `TRUE;
4215
                end
4216
`ifdef FULL_ISSUE_LOGIC
4217
                else if (could_issue[head6] && !iqentry_alu0_issue[head6] && iqentry_alu[head6]
4218
                && !iqentry_alu0[head6]
4219
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4220
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4221
                                ((!iqentry_v[head0])
4222
                        &&   (!iqentry_v[head1]))
4223
                        )
4224
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4225
                                ((!iqentry_v[head0])
4226
                        &&   (!iqentry_v[head1])
4227
                        &&   (!iqentry_v[head2]))
4228
                        )
4229
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4230
                                ((!iqentry_v[head0])
4231
                        &&   (!iqentry_v[head1])
4232
                        &&   (!iqentry_v[head2])
4233
                        &&   (!iqentry_v[head3]))
4234
                        )
4235
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4236
                                ((!iqentry_v[head0])
4237
                        &&   (!iqentry_v[head1])
4238
                        &&   (!iqentry_v[head2])
4239
                        &&   (!iqentry_v[head3])
4240
                        &&   (!iqentry_v[head4]))
4241
                        )
4242
                ) begin
4243
                        iqentry_alu1_issue[head6] = `TRUE;
4244
                end
4245
                else if (could_issue[head7] && !iqentry_alu0_issue[head7] && iqentry_alu[head7]
4246
                && !iqentry_alu0[head7]
4247
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4248
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4249
                                ((!iqentry_v[head0])
4250
                        &&   (!iqentry_v[head1]))
4251
                        )
4252
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4253
                                ((!iqentry_v[head0])
4254
                        &&   (!iqentry_v[head1])
4255
                        &&   (!iqentry_v[head2]))
4256
                        )
4257
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4258
                                ((!iqentry_v[head0])
4259
                        &&   (!iqentry_v[head1])
4260
                        &&   (!iqentry_v[head2])
4261
                        &&   (!iqentry_v[head3]))
4262
                        )
4263
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4264
                                ((!iqentry_v[head0])
4265
                        &&   (!iqentry_v[head1])
4266
                        &&   (!iqentry_v[head2])
4267
                        &&   (!iqentry_v[head3])
4268
                        &&   (!iqentry_v[head4]))
4269
                        )
4270
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4271
                                ((!iqentry_v[head0])
4272
                        &&   (!iqentry_v[head1])
4273
                        &&   (!iqentry_v[head2])
4274
                        &&   (!iqentry_v[head3])
4275
                        &&   (!iqentry_v[head4])
4276
                        &&   (!iqentry_v[head5]))
4277
                        )
4278
                ) begin
4279
                        iqentry_alu1_issue[head7] = `TRUE;
4280
                end
4281
`endif
4282
        end
4283
//      aluissue(alu0_idle,8'h00,2'b00);
4284
//      aluissue(alu1_idle,iqentry_alu0,2'b01);
4285
        end
4286
end
4287
 
4288
always @*
4289
begin
4290 49 robfinch
        iqentry_fpu1_issue = {QENTRIES{1'b0}};
4291
//      fpu1issue(fpu1_idle,2'b00);
4292
        if (fpu1_idle && `NUM_FPU > 0) begin
4293 48 robfinch
    if (could_issue[head0] && iqentry_fpu[head0]) begin
4294 49 robfinch
      iqentry_fpu1_issue[head0] = `TRUE;
4295 48 robfinch
    end
4296
    else if (could_issue[head1] && iqentry_fpu[head1])
4297
    begin
4298 49 robfinch
      iqentry_fpu1_issue[head1] = `TRUE;
4299 48 robfinch
    end
4300
    else if (could_issue[head2] && iqentry_fpu[head2]
4301
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4302
    ) begin
4303 49 robfinch
      iqentry_fpu1_issue[head2] = `TRUE;
4304 48 robfinch
    end
4305
    else if (could_issue[head3] && iqentry_fpu[head3]
4306
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4307
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4308
                ((!iqentry_v[head0])
4309
        &&   (!iqentry_v[head1]))
4310
        )
4311
    ) begin
4312 49 robfinch
      iqentry_fpu1_issue[head3] = `TRUE;
4313 48 robfinch
    end
4314
    else if (could_issue[head4] && iqentry_fpu[head4]
4315
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4316
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4317
                ((!iqentry_v[head0])
4318
        &&   (!iqentry_v[head1]))
4319
        )
4320
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4321
                ((!iqentry_v[head0])
4322
        &&   (!iqentry_v[head1])
4323
        &&   (!iqentry_v[head2]))
4324
        )
4325
    ) begin
4326 49 robfinch
      iqentry_fpu1_issue[head4] = `TRUE;
4327 48 robfinch
    end
4328
    else if (could_issue[head5] && iqentry_fpu[head5]
4329
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4330
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4331
                ((!iqentry_v[head0])
4332
        &&   (!iqentry_v[head1]))
4333
        )
4334
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4335
                ((!iqentry_v[head0])
4336
        &&   (!iqentry_v[head1])
4337
        &&   (!iqentry_v[head2]))
4338
        )
4339
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4340
                ((!iqentry_v[head0])
4341
        &&   (!iqentry_v[head1])
4342
        &&   (!iqentry_v[head2])
4343
        &&   (!iqentry_v[head3]))
4344
        )
4345
        ) begin
4346 49 robfinch
              iqentry_fpu1_issue[head5] = `TRUE;
4347 48 robfinch
    end
4348
`ifdef FULL_ISSUE_LOGIC
4349
    else if (could_issue[head6] && iqentry_fpu[head6]
4350
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4351
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4352
                ((!iqentry_v[head0])
4353
        &&   (!iqentry_v[head1]))
4354
        )
4355
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4356
                ((!iqentry_v[head0])
4357
        &&   (!iqentry_v[head1])
4358
        &&   (!iqentry_v[head2]))
4359
        )
4360
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4361
                ((!iqentry_v[head0])
4362
        &&   (!iqentry_v[head1])
4363
        &&   (!iqentry_v[head2])
4364
        &&   (!iqentry_v[head3]))
4365
        )
4366
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4367
                ((!iqentry_v[head0])
4368
        &&   (!iqentry_v[head1])
4369
        &&   (!iqentry_v[head2])
4370
        &&   (!iqentry_v[head3])
4371
        &&   (!iqentry_v[head4]))
4372
        )
4373
    ) begin
4374 49 robfinch
        iqentry_fpu1_issue[head6] = `TRUE;
4375 48 robfinch
    end
4376
    else if (could_issue[head7] && iqentry_fpu[head7]
4377
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4378
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4379
                ((!iqentry_v[head0])
4380
        &&   (!iqentry_v[head1]))
4381
        )
4382
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4383
                ((!iqentry_v[head0])
4384
        &&   (!iqentry_v[head1])
4385
        &&   (!iqentry_v[head2]))
4386
        )
4387
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4388
                ((!iqentry_v[head0])
4389
        &&   (!iqentry_v[head1])
4390
        &&   (!iqentry_v[head2])
4391
        &&   (!iqentry_v[head3]))
4392
        )
4393
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4394
                ((!iqentry_v[head0])
4395
        &&   (!iqentry_v[head1])
4396
        &&   (!iqentry_v[head2])
4397
        &&   (!iqentry_v[head3])
4398
        &&   (!iqentry_v[head4]))
4399
        )
4400
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
4401
                ((!iqentry_v[head0])
4402
        &&   (!iqentry_v[head1])
4403
        &&   (!iqentry_v[head2])
4404
        &&   (!iqentry_v[head3])
4405
        &&   (!iqentry_v[head4])
4406
        &&   (!iqentry_v[head5]))
4407
        )
4408
        )
4409
    begin
4410 49 robfinch
                iqentry_fpu1_issue[head7] = `TRUE;
4411 48 robfinch
        end
4412
`endif
4413
        end
4414
end
4415
 
4416 49 robfinch
always @*
4417
begin
4418
        iqentry_fpu2_issue = {QENTRIES{1'b0}};
4419
//      fpu2issue(fpu2_idle,2'b00);
4420
        if (fpu2_idle && `NUM_FPU > 1) begin
4421
    if (could_issue[head0] && iqentry_fpu[head0] && !iqentry_fpu1_issue[head0]) begin
4422
      iqentry_fpu2_issue[head0] = `TRUE;
4423
    end
4424
    else if (could_issue[head1] && iqentry_fpu[head1] && !iqentry_fpu1_issue[head1])
4425
    begin
4426
      iqentry_fpu2_issue[head1] = `TRUE;
4427
    end
4428
    else if (could_issue[head2] && iqentry_fpu[head2] && !iqentry_fpu1_issue[head2]
4429
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4430
    ) begin
4431
      iqentry_fpu2_issue[head2] = `TRUE;
4432
    end
4433
    else if (could_issue[head3] && iqentry_fpu[head3] && !iqentry_fpu1_issue[head3]
4434
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4435
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4436
                ((!iqentry_v[head0])
4437
        &&   (!iqentry_v[head1]))
4438
        )
4439
    ) begin
4440
      iqentry_fpu2_issue[head3] = `TRUE;
4441
    end
4442
    else if (could_issue[head4] && iqentry_fpu[head4] && !iqentry_fpu1_issue[head4]
4443
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4444
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4445
                ((!iqentry_v[head0])
4446
        &&   (!iqentry_v[head1]))
4447
        )
4448
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4449
                ((!iqentry_v[head0])
4450
        &&   (!iqentry_v[head1])
4451
        &&   (!iqentry_v[head2]))
4452
        )
4453
    ) begin
4454
      iqentry_fpu2_issue[head4] = `TRUE;
4455
    end
4456
    else if (could_issue[head5] && iqentry_fpu[head5] && !iqentry_fpu1_issue[head5]
4457
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4458
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4459
                ((!iqentry_v[head0])
4460
        &&   (!iqentry_v[head1]))
4461
        )
4462
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4463
                ((!iqentry_v[head0])
4464
        &&   (!iqentry_v[head1])
4465
        &&   (!iqentry_v[head2]))
4466
        )
4467
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4468
                ((!iqentry_v[head0])
4469
        &&   (!iqentry_v[head1])
4470
        &&   (!iqentry_v[head2])
4471
        &&   (!iqentry_v[head3]))
4472
        )
4473
        ) begin
4474
              iqentry_fpu2_issue[head5] = `TRUE;
4475
    end
4476
`ifdef FULL_ISSUE_LOGIC
4477
    else if (could_issue[head6] && iqentry_fpu[head6] && !iqentry_fpu1_issue[head6]
4478
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4479
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4480
                ((!iqentry_v[head0])
4481
        &&   (!iqentry_v[head1]))
4482
        )
4483
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4484
                ((!iqentry_v[head0])
4485
        &&   (!iqentry_v[head1])
4486
        &&   (!iqentry_v[head2]))
4487
        )
4488
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4489
                ((!iqentry_v[head0])
4490
        &&   (!iqentry_v[head1])
4491
        &&   (!iqentry_v[head2])
4492
        &&   (!iqentry_v[head3]))
4493
        )
4494
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4495
                ((!iqentry_v[head0])
4496
        &&   (!iqentry_v[head1])
4497
        &&   (!iqentry_v[head2])
4498
        &&   (!iqentry_v[head3])
4499
        &&   (!iqentry_v[head4]))
4500
        )
4501
    ) begin
4502
        iqentry_fpu2_issue[head6] = `TRUE;
4503
    end
4504
    else if (could_issue[head7] && iqentry_fpu[head7] && !iqentry_fpu1_issue[head7]
4505
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
4506
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
4507
                ((!iqentry_v[head0])
4508
        &&   (!iqentry_v[head1]))
4509
        )
4510
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
4511
                ((!iqentry_v[head0])
4512
        &&   (!iqentry_v[head1])
4513
        &&   (!iqentry_v[head2]))
4514
        )
4515
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
4516
                ((!iqentry_v[head0])
4517
        &&   (!iqentry_v[head1])
4518
        &&   (!iqentry_v[head2])
4519
        &&   (!iqentry_v[head3]))
4520
        )
4521
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
4522
                ((!iqentry_v[head0])
4523
        &&   (!iqentry_v[head1])
4524
        &&   (!iqentry_v[head2])
4525
        &&   (!iqentry_v[head3])
4526
        &&   (!iqentry_v[head4]))
4527
        )
4528
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
4529
                ((!iqentry_v[head0])
4530
        &&   (!iqentry_v[head1])
4531
        &&   (!iqentry_v[head2])
4532
        &&   (!iqentry_v[head3])
4533
        &&   (!iqentry_v[head4])
4534
        &&   (!iqentry_v[head5]))
4535
        )
4536
        )
4537
    begin
4538
                iqentry_fpu2_issue[head7] = `TRUE;
4539
        end
4540
`endif
4541
        end
4542
end
4543 48 robfinch
 
4544
wire [QENTRIES-1:0] nextqd;
4545
// Next queue id
4546
 
4547
reg [`QBITS] nid0;
4548
always @*
4549
if (iqentry_thrd[1]==iqentry_thrd[0])
4550
        nid0 = 3'd1;
4551
else if (iqentry_thrd[2]==iqentry_thrd[0])
4552
        nid0 = 3'd2;
4553
else if (iqentry_thrd[3]==iqentry_thrd[0])
4554
        nid0 = 3'd3;
4555
else if (iqentry_thrd[4]==iqentry_thrd[0])
4556
        nid0 = 3'd4;
4557
else if (iqentry_thrd[5]==iqentry_thrd[0])
4558
        nid0 = 3'd5;
4559
else if (iqentry_thrd[6]==iqentry_thrd[0])
4560
        nid0 = 3'd6;
4561
else if (iqentry_thrd[7]==iqentry_thrd[0])
4562
        nid0 = 3'd7;
4563
else
4564
        nid0 = 3'd0;
4565
 
4566
reg [`QBITS] nid1;
4567
always @*
4568
if (iqentry_thrd[2]==iqentry_thrd[1])
4569
        nid1 = 3'd2;
4570
else if (iqentry_thrd[3]==iqentry_thrd[1])
4571
        nid1 = 3'd3;
4572
else if (iqentry_thrd[4]==iqentry_thrd[1])
4573
        nid1 = 3'd4;
4574
else if (iqentry_thrd[5]==iqentry_thrd[1])
4575
        nid1 = 3'd5;
4576
else if (iqentry_thrd[6]==iqentry_thrd[1])
4577
        nid1 = 3'd6;
4578
else if (iqentry_thrd[7]==iqentry_thrd[1])
4579
        nid1 = 3'd7;
4580
else if (iqentry_thrd[0]==iqentry_thrd[1])
4581
        nid1 = 3'd0;
4582
else
4583
        nid1 = 3'd1;
4584
 
4585
reg [`QBITS] nid2;
4586
always @*
4587
if (iqentry_thrd[3]==iqentry_thrd[2])
4588
        nid2 = 3'd3;
4589
else if (iqentry_thrd[4]==iqentry_thrd[2])
4590
        nid2 = 3'd4;
4591
else if (iqentry_thrd[5]==iqentry_thrd[2])
4592
        nid2 = 3'd5;
4593
else if (iqentry_thrd[6]==iqentry_thrd[2])
4594
        nid2 = 3'd6;
4595
else if (iqentry_thrd[7]==iqentry_thrd[2])
4596
        nid2 = 3'd7;
4597
else if (iqentry_thrd[0]==iqentry_thrd[2])
4598
        nid2 = 3'd0;
4599
else if (iqentry_thrd[1]==iqentry_thrd[2])
4600
        nid2 = 3'd1;
4601
else
4602
        nid2 = 3'd2;
4603
 
4604
reg [`QBITS] nid3;
4605
always @*
4606
if (iqentry_thrd[4]==iqentry_thrd[3])
4607
        nid3 = 3'd4;
4608
else if (iqentry_thrd[5]==iqentry_thrd[3])
4609
        nid3 = 3'd5;
4610
else if (iqentry_thrd[6]==iqentry_thrd[3])
4611
        nid3 = 3'd6;
4612
else if (iqentry_thrd[7]==iqentry_thrd[3])
4613
        nid3 = 3'd7;
4614
else if (iqentry_thrd[0]==iqentry_thrd[3])
4615
        nid3 = 3'd0;
4616
else if (iqentry_thrd[1]==iqentry_thrd[3])
4617
        nid3 = 3'd1;
4618
else if (iqentry_thrd[2]==iqentry_thrd[3])
4619
        nid3 = 3'd2;
4620
else
4621
        nid3 = 3'd3;
4622
 
4623
reg [`QBITS] nid4;
4624
always @*
4625
if (iqentry_thrd[5]==iqentry_thrd[4])
4626
        nid4 = 3'd5;
4627
else if (iqentry_thrd[6]==iqentry_thrd[4])
4628
        nid4 = 3'd6;
4629
else if (iqentry_thrd[7]==iqentry_thrd[4])
4630
        nid4 = 3'd7;
4631
else if (iqentry_thrd[0]==iqentry_thrd[4])
4632
        nid4 = 3'd0;
4633
else if (iqentry_thrd[1]==iqentry_thrd[4])
4634
        nid4 = 3'd1;
4635
else if (iqentry_thrd[2]==iqentry_thrd[4])
4636
        nid4 = 3'd2;
4637
else if (iqentry_thrd[3]==iqentry_thrd[4])
4638
        nid4 = 3'd3;
4639
else
4640
        nid4 = 3'd4;
4641
 
4642
reg [`QBITS] nid5;
4643
always @*
4644
if (iqentry_thrd[6]==iqentry_thrd[5])
4645
        nid5 = 3'd6;
4646
else if (iqentry_thrd[7]==iqentry_thrd[5])
4647
        nid5 = 3'd7;
4648
else if (iqentry_thrd[0]==iqentry_thrd[5])
4649
        nid5 = 3'd0;
4650
else if (iqentry_thrd[1]==iqentry_thrd[5])
4651
        nid5 = 3'd1;
4652
else if (iqentry_thrd[2]==iqentry_thrd[5])
4653
        nid5 = 3'd2;
4654
else if (iqentry_thrd[3]==iqentry_thrd[5])
4655
        nid5 = 3'd3;
4656
else if (iqentry_thrd[4]==iqentry_thrd[5])
4657
        nid5 = 3'd4;
4658
else
4659
        nid5 = 3'd5;
4660
 
4661
reg [`QBITS] nid6;
4662
always @*
4663
if (iqentry_thrd[7]==iqentry_thrd[6])
4664
        nid6 = 3'd7;
4665
else if (iqentry_thrd[0]==iqentry_thrd[6])
4666
        nid6 = 3'd0;
4667
else if (iqentry_thrd[1]==iqentry_thrd[6])
4668
        nid6 = 3'd1;
4669
else if (iqentry_thrd[2]==iqentry_thrd[6])
4670
        nid6 = 3'd2;
4671
else if (iqentry_thrd[3]==iqentry_thrd[6])
4672
        nid6 = 3'd3;
4673
else if (iqentry_thrd[4]==iqentry_thrd[6])
4674
        nid6 = 3'd4;
4675
else if (iqentry_thrd[5]==iqentry_thrd[6])
4676
        nid6 = 3'd5;
4677
else
4678
        nid6 = 3'd6;
4679
 
4680
reg [`QBITS] nid7;
4681
always @*
4682
if (iqentry_thrd[0]==iqentry_thrd[7])
4683
        nid7 = 3'd0;
4684
else if (iqentry_thrd[1]==iqentry_thrd[7])
4685
        nid7 = 3'd1;
4686
else if (iqentry_thrd[2]==iqentry_thrd[7])
4687
        nid7 = 3'd2;
4688
else if (iqentry_thrd[3]==iqentry_thrd[7])
4689
        nid7 = 3'd3;
4690
else if (iqentry_thrd[4]==iqentry_thrd[7])
4691
        nid7 = 3'd4;
4692
else if (iqentry_thrd[5]==iqentry_thrd[7])
4693
        nid7 = 3'd5;
4694
else if (iqentry_thrd[6]==iqentry_thrd[7])
4695
        nid7 = 3'd6;
4696
else
4697
        nid7 = 3'd7;
4698
 
4699
// Search the queue for the next entry on the same thread.
4700
reg [`QBITS] nid;
4701
always @*
4702
if (iqentry_thrd[idp1(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4703
        nid = idp1(fcu_id);
4704
else if (iqentry_thrd[idp2(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4705
        nid = idp2(fcu_id);
4706
else if (iqentry_thrd[idp3(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4707
        nid = idp3(fcu_id);
4708
else if (iqentry_thrd[idp4(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4709
        nid = idp4(fcu_id);
4710
else if (iqentry_thrd[idp5(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4711
        nid = idp5(fcu_id);
4712
else if (iqentry_thrd[idp6(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4713
        nid = idp6(fcu_id);
4714
else if (iqentry_thrd[idp7(fcu_id)]==iqentry_thrd[fcu_id[`QBITS]])
4715
        nid = idp7(fcu_id);
4716
else
4717
        nid = fcu_id;
4718
 
4719
 
4720
assign  nextqd[0] = iqentry_sn[nid0] > iqentry_sn[0] || iqentry_v[0];
4721
assign  nextqd[1] = iqentry_sn[nid1] > iqentry_sn[1] || iqentry_v[1];
4722
assign  nextqd[2] = iqentry_sn[nid2] > iqentry_sn[2] || iqentry_v[2];
4723
assign  nextqd[3] = iqentry_sn[nid3] > iqentry_sn[3] || iqentry_v[3];
4724
assign  nextqd[4] = iqentry_sn[nid4] > iqentry_sn[4] || iqentry_v[4];
4725
assign  nextqd[5] = iqentry_sn[nid5] > iqentry_sn[5] || iqentry_v[5];
4726
assign  nextqd[6] = iqentry_sn[nid6] > iqentry_sn[6] || iqentry_v[6];
4727
assign  nextqd[7] = iqentry_sn[nid7] > iqentry_sn[7] || iqentry_v[7];
4728
 
4729
//assign nextqd = 8'hFF;
4730
 
4731
// Don't issue to the fcu until the following instruction is enqueued.
4732
// However, if the queue is full then issue anyway. A branch miss will likely occur.
4733
always @*//(could_issue or head0 or head1 or head2 or head3 or head4 or head5 or head6 or head7)
4734
begin
4735 49 robfinch
        iqentry_fcu_issue = {QENTRIES{1'b0}};
4736 48 robfinch
        if (fcu_done) begin
4737
    if (could_issue[head0] && iqentry_fc[head0] && nextqd[head0]) begin
4738
      iqentry_fcu_issue[head0] = `TRUE;
4739
    end
4740
    else if (could_issue[head1] && iqentry_fc[head1] && nextqd[head1])
4741
    begin
4742
      iqentry_fcu_issue[head1] = `TRUE;
4743
    end
4744
    else if (could_issue[head2] && iqentry_fc[head2] && nextqd[head2]
4745
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4746
    ) begin
4747
                iqentry_fcu_issue[head2] = `TRUE;
4748
    end
4749
    else if (could_issue[head3] && iqentry_fc[head3] && nextqd[head3]
4750
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4751
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4752
                ((!iqentry_v[head0])
4753
        &&   (!iqentry_v[head1]))
4754
        )
4755
    ) begin
4756
                iqentry_fcu_issue[head3] = `TRUE;
4757
    end
4758
    else if (could_issue[head4] && iqentry_fc[head4] && nextqd[head4]
4759
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4760
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4761
                ((!iqentry_v[head0])
4762
        &&   (!iqentry_v[head1]))
4763
        )
4764
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4765
                ((!iqentry_v[head0])
4766
        &&   (!iqentry_v[head1])
4767
        &&   (!iqentry_v[head2]))
4768
        )
4769
    ) begin
4770
                iqentry_fcu_issue[head4] = `TRUE;
4771
    end
4772
    else if (could_issue[head5] && iqentry_fc[head5] && nextqd[head5]
4773
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4774
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4775
                ((!iqentry_v[head0])
4776
        &&   (!iqentry_v[head1]))
4777
        )
4778
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4779
                ((!iqentry_v[head0])
4780
        &&   (!iqentry_v[head1])
4781
        &&   (!iqentry_v[head2]))
4782
        )
4783
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4784
                ((!iqentry_v[head0])
4785
        &&   (!iqentry_v[head1])
4786
        &&   (!iqentry_v[head2])
4787
        &&   (!iqentry_v[head3]))
4788
        )
4789
    ) begin
4790
                iqentry_fcu_issue[head5] = `TRUE;
4791
    end
4792
 
4793
`ifdef FULL_ISSUE_LOGIC
4794
    else if (could_issue[head6] && iqentry_fc[head6] && nextqd[head6]
4795
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4796
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4797
                ((!iqentry_v[head0])
4798
        &&   (!iqentry_v[head1]))
4799
        )
4800
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4801
                ((!iqentry_v[head0])
4802
        &&   (!iqentry_v[head1])
4803
        &&   (!iqentry_v[head2]))
4804
        )
4805
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4806
                ((!iqentry_v[head0])
4807
        &&   (!iqentry_v[head1])
4808
        &&   (!iqentry_v[head2])
4809
        &&   (!iqentry_v[head3]))
4810
        )
4811
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4812
                ((!iqentry_v[head0])
4813
        &&   (!iqentry_v[head1])
4814
        &&   (!iqentry_v[head2])
4815
        &&   (!iqentry_v[head3])
4816
        &&   (!iqentry_v[head4]))
4817
        )
4818
    ) begin
4819
                iqentry_fcu_issue[head6] = `TRUE;
4820
    end
4821
 
4822
    else if (could_issue[head7] && iqentry_fc[head7]
4823
    && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
4824
    && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
4825
                ((!iqentry_v[head0])
4826
        &&   (!iqentry_v[head1]))
4827
        )
4828
    && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
4829
                ((!iqentry_v[head0])
4830
        &&   (!iqentry_v[head1])
4831
        &&   (!iqentry_v[head2]))
4832
        )
4833
    && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
4834
                ((!iqentry_v[head0])
4835
        &&   (!iqentry_v[head1])
4836
        &&   (!iqentry_v[head2])
4837
        &&   (!iqentry_v[head3]))
4838
        )
4839
    && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
4840
                ((!iqentry_v[head0])
4841
        &&   (!iqentry_v[head1])
4842
        &&   (!iqentry_v[head2])
4843
        &&   (!iqentry_v[head3])
4844
        &&   (!iqentry_v[head4]))
4845
        )
4846
    && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
4847
                ((!iqentry_v[head0])
4848
        &&   (!iqentry_v[head1])
4849
        &&   (!iqentry_v[head2])
4850
        &&   (!iqentry_v[head3])
4851
        &&   (!iqentry_v[head4])
4852
        &&   (!iqentry_v[head5]))
4853
        )
4854
    ) begin
4855
                iqentry_fcu_issue[head7] = `TRUE;
4856
        end
4857
`endif
4858
        end
4859
end
4860
 
4861
//
4862
// determine if the instructions ready to issue can, in fact, issue.
4863
// "ready" means that the instruction has valid operands but has not gone yet
4864
reg [1:0] issue_count, missue_count;
4865
always @*
4866
begin
4867
        issue_count = 0;
4868
         memissue[ head0 ] =    iqentry_memready[ head0 ];              // first in line ... go as soon as ready
4869
         if (memissue[head0])
4870
                issue_count = issue_count + 1;
4871
 
4872
         memissue[ head1 ] =    ~iqentry_stomp[head1] && iqentry_memready[ head1 ]              // addr and data are valid
4873 49 robfinch
                                        && issue_count < `NUM_MEM
4874 48 robfinch
                                        // ... and no preceding instruction is ready to go
4875
                                        //&& ~iqentry_memready[head0]
4876
                                        // ... and there is no address-overlap with any preceding instruction
4877
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4878 49 robfinch
                                                || (iqentry_a1_v[head0] && iqentry_a1[head1][AMSB:3] != iqentry_a1[head0][AMSB:3]))
4879 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4880
                                        && (iqentry_rl[head1] ? iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0] : 1'b1)
4881
                                        // ... if a preivous op has the aquire bit set
4882
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4883
                                        // ... and, if it is a SW, there is no chance of it being undone
4884
                                        && (iqentry_load[head1] ||
4885
                                           !(iqentry_fc[head0]||iqentry_canex[head0]));
4886
         if (memissue[head1])
4887
                issue_count = issue_count + 1;
4888
 
4889
         memissue[ head2 ] =    ~iqentry_stomp[head2] && iqentry_memready[ head2 ]              // addr and data are valid
4890
                                        // ... and no preceding instruction is ready to go
4891 49 robfinch
                                        && issue_count < `NUM_MEM
4892 48 robfinch
                                        //&& ~iqentry_memready[head0]
4893
                                        //&& ~iqentry_memready[head1] 
4894
                                        // ... and there is no address-overlap with any preceding instruction
4895
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4896 49 robfinch
                                                || (iqentry_a1_v[head0] && iqentry_a1[head2][AMSB:3] != iqentry_a1[head0][AMSB:3]))
4897 48 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
4898 49 robfinch
                                                || (iqentry_a1_v[head1] && iqentry_a1[head2][AMSB:3] != iqentry_a1[head1][AMSB:3]))
4899 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4900
                                        && (iqentry_rl[head2] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4901
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4902
                                                                                         : 1'b1)
4903
                                        // ... if a preivous op has the aquire bit set
4904
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4905
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4906
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4907 49 robfinch
            && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4908
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4909 48 robfinch
                                        // ... and, if it is a SW, there is no chance of it being undone
4910
                                        && (iqentry_load[head2] ||
4911
                                              !(iqentry_fc[head0]||iqentry_canex[head0])
4912
                                           && !(iqentry_fc[head1]||iqentry_canex[head1]));
4913
         if (memissue[head2])
4914
                issue_count = issue_count + 1;
4915
 
4916
         memissue[ head3 ] =    ~iqentry_stomp[head3] && iqentry_memready[ head3 ]              // addr and data are valid
4917
                                        // ... and no preceding instruction is ready to go
4918 49 robfinch
                                        && issue_count < `NUM_MEM
4919 48 robfinch
                                        //&& ~iqentry_memready[head0]
4920
                                        //&& ~iqentry_memready[head1] 
4921
                                        //&& ~iqentry_memready[head2] 
4922
                                        // ... and there is no address-overlap with any preceding instruction
4923
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4924 49 robfinch
                                                || (iqentry_a1_v[head0] && iqentry_a1[head3][AMSB:3] != iqentry_a1[head0][AMSB:3]))
4925 48 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
4926 49 robfinch
                                                || (iqentry_a1_v[head1] && iqentry_a1[head3][AMSB:3] != iqentry_a1[head1][AMSB:3]))
4927 48 robfinch
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
4928 49 robfinch
                                                || (iqentry_a1_v[head2] && iqentry_a1[head3][AMSB:3] != iqentry_a1[head2][AMSB:3]))
4929 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4930
                                        && (iqentry_rl[head3] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4931
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4932
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4933
                                                                                         : 1'b1)
4934
                                        // ... if a preivous op has the aquire bit set
4935
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4936
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4937
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4938
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4939 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4940
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4941 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4942
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4943
                                )
4944 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4945
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4946 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4947
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4948
                                )
4949
                    // ... and, if it is a SW, there is no chance of it being undone
4950
                                        && (iqentry_load[head3] ||
4951
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
4952
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
4953
                       && !(iqentry_fc[head2]||iqentry_canex[head2]));
4954
         if (memissue[head3])
4955
                issue_count = issue_count + 1;
4956
 
4957
         memissue[ head4 ] =    ~iqentry_stomp[head4] && iqentry_memready[ head4 ]              // addr and data are valid
4958
                                        // ... and no preceding instruction is ready to go
4959 49 robfinch
                                        && issue_count < `NUM_MEM
4960 48 robfinch
                                        //&& ~iqentry_memready[head0]
4961
                                        //&& ~iqentry_memready[head1] 
4962
                                        //&& ~iqentry_memready[head2] 
4963
                                        //&& ~iqentry_memready[head3] 
4964
                                        // ... and there is no address-overlap with any preceding instruction
4965
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
4966 49 robfinch
                                                || (iqentry_a1_v[head0] && iqentry_a1[head4][AMSB:3] != iqentry_a1[head0][AMSB:3]))
4967 48 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
4968 49 robfinch
                                                || (iqentry_a1_v[head1] && iqentry_a1[head4][AMSB:3] != iqentry_a1[head1][AMSB:3]))
4969 48 robfinch
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
4970 49 robfinch
                                                || (iqentry_a1_v[head2] && iqentry_a1[head4][AMSB:3] != iqentry_a1[head2][AMSB:3]))
4971 48 robfinch
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])
4972 49 robfinch
                                                || (iqentry_a1_v[head3] && iqentry_a1[head4][AMSB:3] != iqentry_a1[head3][AMSB:3]))
4973 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
4974
                                        && (iqentry_rl[head4] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
4975
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
4976
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
4977
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
4978
                                                                                         : 1'b1)
4979
                                        // ... if a preivous op has the aquire bit set
4980
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
4981
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
4982
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
4983
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
4984
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
4985 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
4986
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
4987 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4988
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
4989
                                )
4990 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
4991 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
4992
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
4993
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
4994
                                )
4995
                                && (!(iqentry_v[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
4996 49 robfinch
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
4997 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
4998
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
4999
                                )
5000 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5001 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5002
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5003
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5004
                                )
5005
                                        // ... and, if it is a SW, there is no chance of it being undone
5006
                                        && (iqentry_load[head4] ||
5007
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5008
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5009
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5010
                       && !(iqentry_fc[head3]||iqentry_canex[head3]));
5011
         if (memissue[head4])
5012
                issue_count = issue_count + 1;
5013
 
5014
         memissue[ head5 ] =    ~iqentry_stomp[head5] && iqentry_memready[ head5 ]              // addr and data are valid
5015
                                        // ... and no preceding instruction is ready to go
5016 49 robfinch
                                        && issue_count < `NUM_MEM
5017 48 robfinch
                                        //&& ~iqentry_memready[head0]
5018
                                        //&& ~iqentry_memready[head1] 
5019
                                        //&& ~iqentry_memready[head2] 
5020
                                        //&& ~iqentry_memready[head3] 
5021
                                        //&& ~iqentry_memready[head4] 
5022
                                        // ... and there is no address-overlap with any preceding instruction
5023
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
5024 49 robfinch
                                                || (iqentry_a1_v[head0] && iqentry_a1[head5][AMSB:3] != iqentry_a1[head0][AMSB:3]))
5025 48 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
5026 49 robfinch
                                                || (iqentry_a1_v[head1] && iqentry_a1[head5][AMSB:3] != iqentry_a1[head1][AMSB:3]))
5027 48 robfinch
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
5028 49 robfinch
                                                || (iqentry_a1_v[head2] && iqentry_a1[head5][AMSB:3] != iqentry_a1[head2][AMSB:3]))
5029 48 robfinch
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])
5030 49 robfinch
                                                || (iqentry_a1_v[head3] && iqentry_a1[head5][AMSB:3] != iqentry_a1[head3][AMSB:3]))
5031 48 robfinch
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4])
5032 49 robfinch
                                                || (iqentry_a1_v[head4] && iqentry_a1[head5][AMSB:3] != iqentry_a1[head4][AMSB:3]))
5033 48 robfinch
                                        // ... if a release, any prior memory ops must be done before this one
5034
                                        && (iqentry_rl[head5] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
5035
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
5036
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
5037
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
5038
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
5039
                                                                                         : 1'b1)
5040
                                        // ... if a preivous op has the aquire bit set
5041
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
5042
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
5043
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5044
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5045
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
5046
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5047 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5048
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5049 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5050
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5051
                                )
5052 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5053 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5054
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5055
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5056
                                )
5057 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
5058 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5059
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5060
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5061
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
5062
                                )
5063 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5064
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5065 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5066
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5067
                                )
5068 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5069 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5070
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5071
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5072
                                )
5073 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
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
                                )
5079
                                        // ... and, if it is a SW, there is no chance of it being undone
5080
                                        && (iqentry_load[head5] ||
5081
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5082
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5083
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5084
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5085
                       && !(iqentry_fc[head4]||iqentry_canex[head4]));
5086
         if (memissue[head5])
5087
                issue_count = issue_count + 1;
5088
 
5089
`ifdef FULL_ISSUE_LOGIC
5090
         memissue[ head6 ] =    ~iqentry_stomp[head6] && iqentry_memready[ head6 ]              // addr and data are valid
5091
                                        // ... and no preceding instruction is ready to go
5092 49 robfinch
                                        && issue_count < `NUM_MEM
5093 48 robfinch
                                        //&& ~iqentry_memready[head0]
5094
                                        //&& ~iqentry_memready[head1] 
5095
                                        //&& ~iqentry_memready[head2] 
5096
                                        //&& ~iqentry_memready[head3] 
5097
                                        //&& ~iqentry_memready[head4] 
5098
                                        //&& ~iqentry_memready[head5] 
5099
                                        // ... and there is no address-overlap with any preceding instruction
5100
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
5101 49 robfinch
                                                || (iqentry_a1_v[head0] && iqentry_a1[head6][AMSB:3] != iqentry_a1[head0][AMSB:3]))
5102 48 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
5103 49 robfinch
                                                || (iqentry_a1_v[head1] && iqentry_a1[head6][AMSB:3] != iqentry_a1[head1][AMSB:3]))
5104 48 robfinch
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
5105 49 robfinch
                                                || (iqentry_a1_v[head2] && iqentry_a1[head6][AMSB:3] != iqentry_a1[head2][AMSB:3]))
5106 48 robfinch
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])
5107 49 robfinch
                                                || (iqentry_a1_v[head3] && iqentry_a1[head6][AMSB:3] != iqentry_a1[head3][AMSB:3]))
5108 48 robfinch
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4])
5109 49 robfinch
                                                || (iqentry_a1_v[head4] && iqentry_a1[head6][AMSB:3] != iqentry_a1[head4][AMSB:3]))
5110 48 robfinch
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5])
5111 49 robfinch
                                                || (iqentry_a1_v[head5] && iqentry_a1[head6][AMSB:3] != iqentry_a1[head5][AMSB:3]))
5112 48 robfinch
                                        && (iqentry_rl[head6] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
5113
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
5114
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
5115
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
5116
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
5117
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
5118
                                                                                         : 1'b1)
5119
                                        // ... if a preivous op has the aquire bit set
5120
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
5121
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
5122
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5123
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5124
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
5125
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
5126
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5127 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5128
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5129 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5130
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5131
                                )
5132 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5133 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5134
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5135
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5136
                                )
5137 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
5138 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5139
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5140
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5141
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
5142
                                )
5143 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
5144 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5145
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5146
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5147
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5148
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
5149
                                )
5150 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5151
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5152 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5153
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5154
                                )
5155 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5156 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5157
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5158
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5159
                                )
5160 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
5161 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5162
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5163
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5164
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
5165
                                )
5166 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
5167 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5168
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5169
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5170
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5171
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
5172
                                )
5173
                                        // ... and, if it is a SW, there is no chance of it being undone
5174
                                        && (iqentry_load[head6] ||
5175
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5176
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5177
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5178
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5179
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
5180
                       && !(iqentry_fc[head5]||iqentry_canex[head5]));
5181
         if (memissue[head6])
5182
                issue_count = issue_count + 1;
5183
 
5184
         memissue[ head7 ] =    ~iqentry_stomp[head7] && iqentry_memready[ head7 ]              // addr and data are valid
5185
                                        // ... and no preceding instruction is ready to go
5186 49 robfinch
                                        && issue_count < `NUM_MEM
5187 48 robfinch
                                        //&& ~iqentry_memready[head0]
5188
                                        //&& ~iqentry_memready[head1] 
5189
                                        //&& ~iqentry_memready[head2] 
5190
                                        //&& ~iqentry_memready[head3] 
5191
                                        //&& ~iqentry_memready[head4] 
5192
                                        //&& ~iqentry_memready[head5] 
5193
                                        //&& ~iqentry_memready[head6] 
5194
                                        // ... and there is no address-overlap with any preceding instruction
5195
                                        && (!iqentry_mem[head0] || (iqentry_agen[head0] & iqentry_out[head0])
5196 49 robfinch
                                                || (iqentry_a1_v[head0] && iqentry_a1[head7][AMSB:3] != iqentry_a1[head0][AMSB:3]))
5197 48 robfinch
                                        && (!iqentry_mem[head1] || (iqentry_agen[head1] & iqentry_out[head1])
5198 49 robfinch
                                                || (iqentry_a1_v[head1] && iqentry_a1[head7][AMSB:3] != iqentry_a1[head1][AMSB:3]))
5199 48 robfinch
                                        && (!iqentry_mem[head2] || (iqentry_agen[head2] & iqentry_out[head2])
5200 49 robfinch
                                                || (iqentry_a1_v[head2] && iqentry_a1[head7][AMSB:3] != iqentry_a1[head2][AMSB:3]))
5201 48 robfinch
                                        && (!iqentry_mem[head3] || (iqentry_agen[head3] & iqentry_out[head3])
5202 49 robfinch
                                                || (iqentry_a1_v[head3] && iqentry_a1[head7][AMSB:3] != iqentry_a1[head3][AMSB:3]))
5203 48 robfinch
                                        && (!iqentry_mem[head4] || (iqentry_agen[head4] & iqentry_out[head4])
5204 49 robfinch
                                                || (iqentry_a1_v[head4] && iqentry_a1[head7][AMSB:3] != iqentry_a1[head4][AMSB:3]))
5205 48 robfinch
                                        && (!iqentry_mem[head5] || (iqentry_agen[head5] & iqentry_out[head5])
5206 49 robfinch
                                                || (iqentry_a1_v[head5] && iqentry_a1[head7][AMSB:3] != iqentry_a1[head5][AMSB:3]))
5207 48 robfinch
                                        && (!iqentry_mem[head6] || (iqentry_agen[head6] & iqentry_out[head6])
5208 49 robfinch
                                                || (iqentry_a1_v[head6] && iqentry_a1[head7][AMSB:3] != iqentry_a1[head6][AMSB:3]))
5209 48 robfinch
                                        && (iqentry_rl[head7] ? (iqentry_done[head0] || !iqentry_v[head0] || !iqentry_mem[head0])
5210
                                                                                 && (iqentry_done[head1] || !iqentry_v[head1] || !iqentry_mem[head1])
5211
                                                                                 && (iqentry_done[head2] || !iqentry_v[head2] || !iqentry_mem[head2])
5212
                                                                                 && (iqentry_done[head3] || !iqentry_v[head3] || !iqentry_mem[head3])
5213
                                                                                 && (iqentry_done[head4] || !iqentry_v[head4] || !iqentry_mem[head4])
5214
                                                                                 && (iqentry_done[head5] || !iqentry_v[head5] || !iqentry_mem[head5])
5215
                                                                                 && (iqentry_done[head6] || !iqentry_v[head6] || !iqentry_mem[head6])
5216
                                                                                         : 1'b1)
5217
                                        // ... if a preivous op has the aquire bit set
5218
                                        && !(iqentry_aq[head0] && iqentry_v[head0])
5219
                                        && !(iqentry_aq[head1] && iqentry_v[head1])
5220
                                        && !(iqentry_aq[head2] && iqentry_v[head2])
5221
                                        && !(iqentry_aq[head3] && iqentry_v[head3])
5222
                                        && !(iqentry_aq[head4] && iqentry_v[head4])
5223
                                        && !(iqentry_aq[head5] && iqentry_v[head5])
5224
                                        && !(iqentry_aq[head6] && iqentry_v[head6])
5225
                                        // ... and there isn't a barrier, or everything before the barrier is done or invalid
5226 49 robfinch
                    && (!(iqentry_iv[head1] && iqentry_memsb[head1]) || (iqentry_done[head0] || !iqentry_v[head0]))
5227
                    && (!(iqentry_iv[head2] && iqentry_memsb[head2]) ||
5228 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5229
                                &&   (iqentry_done[head1] || !iqentry_v[head1]))
5230
                                )
5231 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memsb[head3]) ||
5232 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5233
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5234
                                &&   (iqentry_done[head2] || !iqentry_v[head2]))
5235
                                )
5236 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memsb[head4]) ||
5237 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5238
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5239
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5240
                                &&   (iqentry_done[head3] || !iqentry_v[head3]))
5241
                                )
5242 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memsb[head5]) ||
5243 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5244
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5245
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5246
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5247
                                &&   (iqentry_done[head4] || !iqentry_v[head4]))
5248
                                )
5249 49 robfinch
                    && (!(iqentry_iv[head6] && iqentry_memsb[head6]) ||
5250 48 robfinch
                                        ((iqentry_done[head0] || !iqentry_v[head0])
5251
                                &&   (iqentry_done[head1] || !iqentry_v[head1])
5252
                                &&   (iqentry_done[head2] || !iqentry_v[head2])
5253
                                &&   (iqentry_done[head3] || !iqentry_v[head3])
5254
                                &&   (iqentry_done[head4] || !iqentry_v[head4])
5255
                                &&   (iqentry_done[head5] || !iqentry_v[head5]))
5256
                                )
5257 49 robfinch
                                && (!(iqentry_iv[head1] && iqentry_memdb[head1]) || (!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0]))
5258
                    && (!(iqentry_iv[head2] && iqentry_memdb[head2]) ||
5259 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5260
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1]))
5261
                                )
5262 49 robfinch
                    && (!(iqentry_iv[head3] && iqentry_memdb[head3]) ||
5263 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5264
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5265
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2]))
5266
                                )
5267 49 robfinch
                    && (!(iqentry_iv[head4] && iqentry_memdb[head4]) ||
5268 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5269
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5270
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5271
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3]))
5272
                                )
5273 49 robfinch
                    && (!(iqentry_iv[head5] && iqentry_memdb[head5]) ||
5274 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5275
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5276
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5277
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5278
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4]))
5279
                                )
5280 49 robfinch
                    && (!(iqentry_iv[head6] && iqentry_memdb[head6]) ||
5281 48 robfinch
                                  ((!iqentry_mem[head0] || iqentry_done[head0] || !iqentry_v[head0])
5282
                                && (!iqentry_mem[head1] || iqentry_done[head1] || !iqentry_v[head1])
5283
                                && (!iqentry_mem[head2] || iqentry_done[head2] || !iqentry_v[head2])
5284
                                && (!iqentry_mem[head3] || iqentry_done[head3] || !iqentry_v[head3])
5285
                                && (!iqentry_mem[head4] || iqentry_done[head4] || !iqentry_v[head4])
5286
                                && (!iqentry_mem[head5] || iqentry_done[head5] || !iqentry_v[head5]))
5287
                                )
5288
                                        // ... and, if it is a SW, there is no chance of it being undone
5289
                                        && (iqentry_load[head7] ||
5290
                                      !(iqentry_fc[head0]||iqentry_canex[head0])
5291
                       && !(iqentry_fc[head1]||iqentry_canex[head1])
5292
                       && !(iqentry_fc[head2]||iqentry_canex[head2])
5293
                       && !(iqentry_fc[head3]||iqentry_canex[head3])
5294
                       && !(iqentry_fc[head4]||iqentry_canex[head4])
5295
                       && !(iqentry_fc[head5]||iqentry_canex[head5])
5296
                       && !(iqentry_fc[head6]||iqentry_canex[head6]));
5297
`endif
5298
end
5299
 
5300 49 robfinch
reg [2:0] wbptr;
5301
always @*
5302
begin
5303
        // Crashes sim
5304
//      wbptr <= `WB_DEPTH-1;
5305
//      if (wb_v==8'h0)
5306
//              wbptr <= 3'd0;
5307
//      else
5308
//      begin
5309
//              for (n = `WB_DEPTH-2; n >= 0; n = n - 1)
5310
//                      if (wb_v[n] && wbptr==`WB_DEPTH-1)
5311
//                              wbptr <= n + 1;
5312
//      end
5313
        if (wb_v[6])
5314
                wbptr <= 3'd7;
5315
        else if (wb_v[5])
5316
                wbptr <= 3'd6;
5317
        else if (wb_v[4])
5318
                wbptr <= 3'd5;
5319
        else if (wb_v[3])
5320
                wbptr <= 3'd4;
5321
        else if (wb_v[2])
5322
                wbptr <= 3'd3;
5323
        else if (wb_v[1])
5324
                wbptr <= 3'd2;
5325
        else if (wb_v[0])
5326
                wbptr <= 3'd1;
5327
        else
5328
                wbptr <= 3'd0;
5329
end
5330
 
5331 48 robfinch
// Stomp logic for branch miss.
5332
 
5333
FT64_stomp #(QENTRIES) ustmp1
5334
(
5335
        .branchmiss(branchmiss),
5336
        .branchmiss_thrd(branchmiss_thrd),
5337
        .missid(missid),
5338
        .head0(head0),
5339
        .thrd(iqentry_thrd),
5340
        .iqentry_v(iqentry_v),
5341
        .stomp(iqentry_stomp)
5342
);
5343
 
5344
always @*
5345
begin
5346
        if (iqentry_stomp[0] && IsRet(iqentry_instr[0]))
5347
                stompedOnRets = stompedOnRets + 4'd1;
5348
        if (iqentry_stomp[1] && IsRet(iqentry_instr[1]))
5349
                stompedOnRets = stompedOnRets + 4'd1;
5350
        if (iqentry_stomp[2] && IsRet(iqentry_instr[2]))
5351
                stompedOnRets = stompedOnRets + 4'd1;
5352
        if (iqentry_stomp[3] && IsRet(iqentry_instr[3]))
5353
                stompedOnRets = stompedOnRets + 4'd1;
5354
        if (iqentry_stomp[4] && IsRet(iqentry_instr[4]))
5355
                stompedOnRets = stompedOnRets + 4'd1;
5356
        if (iqentry_stomp[5] && IsRet(iqentry_instr[5]))
5357
                stompedOnRets = stompedOnRets + 4'd1;
5358
        if (iqentry_stomp[6] && IsRet(iqentry_instr[6]))
5359
                stompedOnRets = stompedOnRets + 4'd1;
5360
        if (iqentry_stomp[7] && IsRet(iqentry_instr[7]))
5361
                stompedOnRets = stompedOnRets + 4'd1;
5362
end
5363
 
5364 49 robfinch
reg id1_vi, id2_vi, id3_vi;
5365
wire [4:0] id1_ido, id2_ido, id3_ido;
5366
wire id1_vo, id2_vo, id3_vo;
5367
wire id1_clk, id2_clk, id3_clk;
5368 48 robfinch
 
5369 49 robfinch
// Always at least one decoder
5370 48 robfinch
BUFGCE uclkb2
5371
(
5372
        .I(clk_i),
5373
        .CE(id1_available),
5374
        .O(id1_clk)
5375
);
5376
 
5377
FT64_idecoder uid1
5378
(
5379
        .clk(id1_clk),
5380
        .idv_i(id1_vi),
5381
        .id_i(id1_id),
5382
        .instr(id1_instr),
5383
        .ven(id1_ven),
5384
        .vl(id1_vl),
5385
        .thrd(id1_thrd),
5386
        .predict_taken(id1_pt),
5387
        .Rt(id1_Rt),
5388
        .bus(id1_bus),
5389
        .id_o(id1_ido),
5390
        .idv_o(id1_vo)
5391
);
5392
 
5393 49 robfinch
generate begin : gIDUInst
5394
if (`NUM_IDU > 1) begin
5395 48 robfinch
BUFGCE uclkb3
5396
(
5397
        .I(clk_i),
5398
        .CE(id2_available),
5399
        .O(id2_clk)
5400
);
5401
 
5402
FT64_idecoder uid2
5403
(
5404
        .clk(id2_clk),
5405
        .idv_i(id2_vi),
5406
        .id_i(id2_id),
5407
        .instr(id2_instr),
5408
        .ven(id2_ven),
5409
        .vl(id2_vl),
5410
        .thrd(id2_thrd),
5411
        .predict_taken(id2_pt),
5412
        .Rt(id2_Rt),
5413
        .bus(id2_bus),
5414
        .id_o(id2_ido),
5415
        .idv_o(id2_vo)
5416
);
5417 49 robfinch
end
5418
if (`NUM_IDU > 2) begin
5419
BUFGCE uclkb4
5420
(
5421
        .I(clk_i),
5422
        .CE(id3_available),
5423
        .O(id3_clk)
5424
);
5425 48 robfinch
 
5426 49 robfinch
FT64_idecoder uid2
5427
(
5428
        .clk(id3_clk),
5429
        .idv_i(id3_vi),
5430
        .id_i(id3_id),
5431
        .instr(id3_instr),
5432
        .ven(id3_ven),
5433
        .vl(id3_vl),
5434
        .thrd(id3_thrd),
5435
        .predict_taken(id3_pt),
5436
        .Rt(id3_Rt),
5437
        .bus(id3_bus),
5438
        .id_o(id3_ido),
5439
        .idv_o(id3_vo)
5440
);
5441
end
5442
end
5443
endgenerate
5444
 
5445 48 robfinch
//
5446
// EXECUTE
5447
//
5448
reg [63:0] csr_r;
5449
always @*
5450
    read_csr(alu0_instr[29:18],csr_r,alu0_thrd);
5451
FT64_alu #(.BIG(1'b1),.SUP_VECTOR(SUP_VECTOR)) ualu0 (
5452
  .rst(rst),
5453
  .clk(clk),
5454
  .ld(alu0_ld),
5455
  .abort(1'b0),
5456
  .instr(alu0_instr),
5457
  .a(alu0_argA),
5458
  .b(alu0_argB),
5459
  .c(alu0_argC),
5460
  .pc(alu0_pc),
5461
//    .imm(alu0_argI),
5462
  .tgt(alu0_tgt),
5463
  .ven(alu0_ven),
5464
  .vm(vm[alu0_instr[25:23]]),
5465
  .sbl(sbl),
5466
  .sbu(sbu),
5467
  .csr(csr_r),
5468
  .o(alu0_bus),
5469
  .ob(alu0b_bus),
5470
  .done(alu0_done),
5471
  .idle(alu0_idle),
5472
  .excen(aec[4:0]),
5473
  .exc(alu0_exc),
5474
  .thrd(alu0_thrd),
5475
  .mem(alu0_mem),
5476
  .shift48(alu0_shft48)
5477
);
5478 49 robfinch
generate begin : gAluInst
5479
if (`NUM_ALU > 1) begin
5480 48 robfinch
FT64_alu #(.BIG(1'b0),.SUP_VECTOR(SUP_VECTOR)) ualu1 (
5481
  .rst(rst),
5482
  .clk(clk),
5483
  .ld(alu1_ld),
5484
  .abort(1'b0),
5485
  .instr(alu1_instr),
5486
  .a(alu1_argA),
5487
  .b(alu1_argB),
5488
  .c(alu1_argC),
5489
  .pc(alu1_pc),
5490
  //.imm(alu1_argI),
5491
  .tgt(alu1_tgt),
5492
  .ven(alu1_ven),
5493
  .vm(vm[alu1_instr[25:23]]),
5494
  .sbl(sbl),
5495
  .sbu(sbu),
5496
  .csr(64'd0),
5497
  .o(alu1_bus),
5498
  .ob(alu1b_bus),
5499
  .done(alu1_done),
5500
  .idle(alu1_idle),
5501
  .excen(aec[4:0]),
5502
  .exc(alu1_exc),
5503
  .thrd(1'b0),
5504
  .mem(alu1_mem),
5505
  .shift48(alu1_shft48)
5506
);
5507 49 robfinch
end
5508
end
5509
endgenerate
5510
 
5511
generate begin : gFPUInst
5512
if (`NUM_FPU > 0) begin
5513
wire fpu1_clk;
5514
BUFGCE ufpc1
5515
(
5516
        .I(clk_i),
5517
        .CE(fpu1_available),
5518
        .O(fpu1_clk)
5519
);
5520 48 robfinch
fpUnit ufp1
5521
(
5522
  .rst(rst),
5523 49 robfinch
  .clk(fpu1_clk),
5524 48 robfinch
  .clk4x(clk4x),
5525
  .ce(1'b1),
5526 49 robfinch
  .ir(fpu1_instr),
5527
  .ld(fpu1_ld),
5528
  .a(fpu1_argA),
5529
  .b(fpu1_argB),
5530
  .imm(fpu1_argI),
5531
  .o(fpu1_bus),
5532 48 robfinch
  .csr_i(),
5533 49 robfinch
  .status(fpu1_status),
5534 48 robfinch
  .exception(),
5535 49 robfinch
  .done(fpu1_done)
5536 48 robfinch
);
5537 49 robfinch
end
5538
if (`NUM_FPU > 1) begin
5539
wire fpu2_clk;
5540
BUFGCE ufpc2
5541
(
5542
        .I(clk_i),
5543
        .CE(fpu2_available),
5544
        .O(fpu2_clk)
5545
);
5546
fpUnit ufp1
5547
(
5548
  .rst(rst),
5549
  .clk(fpu2_clk),
5550
  .clk4x(clk4x),
5551
  .ce(1'b1),
5552
  .ir(fpu2_instr),
5553
  .ld(fpu2_ld),
5554
  .a(fpu2_argA),
5555
  .b(fpu2_argB),
5556
  .imm(fpu2_argI),
5557
  .o(fpu2_bus),
5558
  .csr_i(),
5559
  .status(fpu2_status),
5560
  .exception(),
5561
  .done(fpu2_done)
5562
);
5563
end
5564
end
5565
endgenerate
5566 48 robfinch
 
5567 49 robfinch
assign fpu_exc = fpu1_available ? (|fpu1_status[15:0] ? `FLT_FLT : `FLT_NONE) : `FLT_UNIMP;
5568
 
5569 48 robfinch
assign  alu0_v = alu0_dataready,
5570
        alu1_v = alu1_dataready;
5571
assign  alu0_id = alu0_sourceid,
5572
            alu1_id = alu1_sourceid;
5573 49 robfinch
assign  fpu1_v = fpu1_dataready;
5574
assign  fpu1_id = fpu1_sourceid;
5575
assign  fpu2_v = fpu2_dataready;
5576
assign  fpu2_id = fpu2_sourceid;
5577 48 robfinch
 
5578
`ifdef SUPPORT_SMT
5579
wire [1:0] olm = ol[fcu_thrd];
5580
`else
5581
wire [1:0] olm = ol;
5582
`endif
5583
 
5584
assign  fcu_v = fcu_dataready;
5585
assign  fcu_id = fcu_sourceid;
5586
 
5587
wire [4:0] fcmpo;
5588
wire fnanx;
5589
fp_cmp_unit ufcmp1 (fcu_argA, fcu_argB, fcmpo, fnanx);
5590
 
5591
wire fcu_takb;
5592
 
5593
always @*
5594
begin
5595
    fcu_exc <= `FLT_NONE;
5596
    casez(fcu_instr[`INSTRUCTION_OP])
5597
    `CHK:   begin
5598
                if (fcu_instr[21])
5599
                    fcu_exc <= fcu_argA >= fcu_argB && fcu_argA < fcu_argC ? `FLT_NONE : `FLT_CHK;
5600
            end
5601
    `REX:
5602
        case(olm)
5603
        `OL_USER:   fcu_exc <= `FLT_PRIV;
5604
        default:    ;
5605
        endcase
5606
        endcase
5607
end
5608
 
5609
FT64_EvalBranch ube1
5610
(
5611
        .instr(fcu_instr),
5612
        .a(fcu_argA),
5613
        .b(fcu_argB),
5614
        .c(fcu_argC),
5615
        .takb(fcu_takb)
5616
);
5617
 
5618
FT64_FCU_Calc ufcuc1
5619
(
5620
        .ol(olm),
5621
        .instr(fcu_instr),
5622
        .tvec(tvec[fcu_instr[14:13]]),
5623
        .a(fcu_argA),
5624
        .i(fcu_argI),
5625
        .pc(fcu_pc),
5626
        .im(im),
5627
        .waitctr(waitctr),
5628
        .bus(fcu_bus)
5629
);
5630
 
5631
always @*
5632
begin
5633
case(fcu_instr[`INSTRUCTION_OP])
5634
`R2:    fcu_misspc = fcu_argB;  // RTI (we don't bother fully decoding this as it's the only R2)
5635
`RET:   fcu_misspc = fcu_argB;
5636
`REX:   fcu_misspc = fcu_bus;
5637
`BRK:   fcu_misspc = {tvec[0][31:8], 1'b0, olm, 5'h0};
5638
`JAL:   fcu_misspc = fcu_argA + fcu_argI;
5639
//`CHK: fcu_misspc = fcu_nextpc + fcu_argI;     // Handled as an instruction exception
5640
// Default: branch
5641
default:        fcu_misspc = fcu_takb ? fcu_nextpc + fcu_brdisp : fcu_nextpc;
5642
endcase
5643
fcu_misspc[0] = 1'b0;
5644
end
5645
 
5646
// To avoid false branch mispredicts the branch isn't evaluated until the
5647
// following instruction queues. The address of the next instruction is
5648
// looked at to see if the BTB predicted correctly.
5649
 
5650
wire fcu_brk_miss = (IsBrk(fcu_instr) || IsRTI(fcu_instr)) && fcu_v;
5651
wire fcu_ret_miss = IsRet(fcu_instr) && fcu_v && (fcu_argB != iqentry_pc[idp2(fcu_id)]);
5652
wire fcu_jal_miss = IsJAL(fcu_instr) && fcu_v && fcu_argA + fcu_argI != iqentry_pc[idp2(fcu_id)];
5653
wire fcu_followed = iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]];
5654
always @*
5655
if (fcu_dataready) begin
5656
//      if (fcu_timeout[7])
5657
//              fcu_branchmiss = TRUE;
5658
        // Break and RTI switch register sets, and so are always treated as a branch miss in order to
5659
        // flush the pipeline. Hardware interrupts also stream break instructions so they need to 
5660
        // flushed from the queue so the interrupt is recognized only once.
5661
        // BRK and RTI are handled as excmiss types which are processed during the commit stage.
5662
//      else
5663
        if (fcu_brk_miss)
5664
                fcu_branchmiss = TRUE & ~fcu_clearbm;
5665
    // the following instruction is queued
5666
        else
5667
        if (fcu_followed) begin
5668
`ifdef SUPPORT_SMT
5669
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol[fcu_thrd]) && fcu_v)
5670
`else
5671
                if (fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol) && fcu_v)
5672
`endif
5673
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5674
                else if (fcu_ret_miss)
5675
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5676
                else if (IsBranch(fcu_instr) && fcu_v && (((fcu_takb && (~fcu_bt || (fcu_misspc != iqentry_pc[nid]))) ||
5677
                                            (~fcu_takb && ( fcu_bt || (fcu_pc + 32'd4 != iqentry_pc[nid])))) || iqentry_v[nid]))
5678
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5679
                else if (fcu_jal_miss)
5680
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5681
                else if (fcu_instr[`INSTRUCTION_OP] == `CHK && ~fcu_takb && fcu_v)
5682
                    fcu_branchmiss = TRUE & ~fcu_clearbm;
5683
                else
5684
                    fcu_branchmiss = FALSE;
5685
        end
5686
        else begin
5687
                // Stuck at the head and can't finish because there's still an uncommitted instruction in the queue.
5688
                // -> cause a branch miss to clear the queue.
5689
                if (iqentry_v[nid] && !IsCall(fcu_instr) && !IsJmp(fcu_instr) && fcu_v)
5690
                        fcu_branchmiss = TRUE & ~fcu_clearbm;
5691
                else
5692
                /*
5693
                if (fcu_id==head0 && iqentry_v[idp1(head0)]) begin
5694
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
5695
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
5696
                        fcu_branchmiss = FALSE;
5697
                    else
5698
                                fcu_branchmiss = TRUE;
5699
                end
5700
                else if (fcu_id==head1 && iqentry_v[idp2(head1)]) begin
5701
                        if ((fcu_bus[0] && (~fcu_bt || (fcu_misspc == iqentry_pc[nid]))) ||
5702
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 == iqentry_pc[nid]))))
5703
                        fcu_branchmiss = FALSE;
5704
                    else
5705
                                fcu_branchmiss = TRUE;
5706
                end
5707
                else*/
5708
                        fcu_branchmiss = FALSE;
5709
        end
5710
end
5711
else
5712
        fcu_branchmiss = FALSE;
5713
/*
5714
assign fcu_branchmiss = fcu_dataready &&
5715
            // and the following instruction is queued
5716
            iqentry_v[idp1(fcu_id)] && iqentry_sn[idp1(fcu_id)]==iqentry_sn[fcu_id[`QBITS]]+5'd1 &&
5717
            ((IsBrk(fcu_instr) || IsRTI(fcu_instr)) ||
5718
            ((fcu_instr[`INSTRUCTION_OP] == `REX && (im < ~ol)) ||
5719
            (fcu_instr[`INSTRUCTION_OP] == `CHK && ~fcu_bus[0]) ||
5720
                   (IsRTI(fcu_instr) && epc != iqentry_pc[idp1(fcu_id[`QBITS])]) ||
5721
                   // If it's a ret and the return address doesn't match the address of the
5722
                   // next queued instruction then the return prediction was wrong.
5723
                   (/*IsRet(fcu_instr) &&
5724
                     IsRet(fcu_instr) && ((fcu_argB != iqentry_pc[idp1(fcu_id)]) || (iqentry_sn[fcu_id[`QBITS]]+5'd1!=iqentry_sn[idp1(fcu_id)]) || !iqentry_v[idp1(fcu_id)])) ||
5725
                   (IsBrk(fcu_instr) && {tvec[0][31:8], ol, 5'h0} != iqentry_pc[idp1(fcu_id)]) ||
5726
//                         (fcu_instr[`INSTRUCTION_OP] == `BccR && fcu_argC != iqentry_pc[(fcu_id[`QBITS]+3'd1)&7] && fcu_bus[0]) ||
5727
                    (IsBranch(fcu_instr) && ((fcu_bus[0] && (~fcu_bt || (fcu_misspc != iqentry_pc[idp1(fcu_id)]))) ||
5728
                                            (~fcu_bus[0] && ( fcu_bt || (fcu_pc + 32'd4 != iqentry_pc[idp1(fcu_id)]))))) ||
5729
                    (IsJAL(fcu_instr)) && fcu_argA + fcu_argI != iqentry_pc[idp1(fcu_id)]));
5730
*/
5731
 
5732
// Flow control ops don't issue until the next instruction queues.
5733
// The fcu_timeout tracks how long the flow control op has been in the "out" state.
5734
// It should never be that way more than a couple of cycles. Sometimes the fcu_wr pulse got missed
5735
// because the following instruction got stomped on during a branchmiss, hence iqentry_v isn't true.
5736
wire fcu_wr = (fcu_v && iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]]);//      // && iqentry_v[nid]
5737
//                                      && fcu_instr==iqentry_instr[fcu_id[`QBITS]]);// || fcu_timeout==8'h05;
5738
 
5739
FT64_RMW_alu urmwalu0 (rmw_instr, rmw_argA, rmw_argB, rmw_argC, rmw_res);
5740
 
5741
//assign fcu_done = IsWait(fcu_instr) ? ((waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]]) :
5742
//                                      fcu_v && iqentry_v[idp1(fcu_id)] && iqentry_sn[idp1(fcu_id)]==iqentry_sn[fcu_id[`QBITS]]+5'd1;
5743
 
5744
// An exception in a committing instruction takes precedence
5745
/*
5746
Too slow. Needs to be registered
5747
assign  branchmiss = excmiss|fcu_branchmiss,
5748
    misspc = excmiss ? excmisspc : fcu_misspc,
5749
    missid = excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
5750
assign branchmiss_thrd =  excmiss ? excthrd : fcu_thrd;
5751
*/
5752
 
5753
//
5754
// additional DRAM-enqueue logic
5755
 
5756
assign dram_avail = (dram0 == `DRAMSLOT_AVAIL || dram1 == `DRAMSLOT_AVAIL || dram2 == `DRAMSLOT_AVAIL);
5757
 
5758
assign  iqentry_memopsvalid[0] = (iqentry_mem[0] & iqentry_a2_v[0] & iqentry_agen[0]),
5759
    iqentry_memopsvalid[1] = (iqentry_mem[1] & iqentry_a2_v[1] & iqentry_agen[1]),
5760
    iqentry_memopsvalid[2] = (iqentry_mem[2] & iqentry_a2_v[2] & iqentry_agen[2]),
5761
    iqentry_memopsvalid[3] = (iqentry_mem[3] & iqentry_a2_v[3] & iqentry_agen[3]),
5762
    iqentry_memopsvalid[4] = (iqentry_mem[4] & iqentry_a2_v[4] & iqentry_agen[4]),
5763
    iqentry_memopsvalid[5] = (iqentry_mem[5] & iqentry_a2_v[5] & iqentry_agen[5]),
5764
    iqentry_memopsvalid[6] = (iqentry_mem[6] & iqentry_a2_v[6] & iqentry_agen[6]),
5765
    iqentry_memopsvalid[7] = (iqentry_mem[7] & iqentry_a2_v[7] & iqentry_agen[7]);
5766
 
5767
assign  iqentry_memready[0] = (iqentry_v[0] & iqentry_memopsvalid[0] & ~iqentry_memissue[0] & ~iqentry_done[0] & ~iqentry_out[0] & ~iqentry_stomp[0]),
5768
    iqentry_memready[1] = (iqentry_v[1] & iqentry_memopsvalid[1] & ~iqentry_memissue[1] & ~iqentry_done[1] & ~iqentry_out[1] & ~iqentry_stomp[1]),
5769
    iqentry_memready[2] = (iqentry_v[2] & iqentry_memopsvalid[2] & ~iqentry_memissue[2] & ~iqentry_done[2] & ~iqentry_out[2] & ~iqentry_stomp[2]),
5770
    iqentry_memready[3] = (iqentry_v[3] & iqentry_memopsvalid[3] & ~iqentry_memissue[3] & ~iqentry_done[3] & ~iqentry_out[3] & ~iqentry_stomp[3]),
5771
    iqentry_memready[4] = (iqentry_v[4] & iqentry_memopsvalid[4] & ~iqentry_memissue[4] & ~iqentry_done[4] & ~iqentry_out[4] & ~iqentry_stomp[4]),
5772
    iqentry_memready[5] = (iqentry_v[5] & iqentry_memopsvalid[5] & ~iqentry_memissue[5] & ~iqentry_done[5] & ~iqentry_out[5] & ~iqentry_stomp[5]),
5773
    iqentry_memready[6] = (iqentry_v[6] & iqentry_memopsvalid[6] & ~iqentry_memissue[6] & ~iqentry_done[6] & ~iqentry_out[6] & ~iqentry_stomp[6]),
5774
    iqentry_memready[7] = (iqentry_v[7] & iqentry_memopsvalid[7] & ~iqentry_memissue[7] & ~iqentry_done[7] & ~iqentry_out[7] & ~iqentry_stomp[7]);
5775
 
5776
assign outstanding_stores = (dram0 && IsStore(dram0_instr)) ||
5777
                            (dram1 && IsStore(dram1_instr)) ||
5778
                            (dram2 && IsStore(dram2_instr));
5779
 
5780
//
5781
// additional COMMIT logic
5782
//
5783
always @*
5784
begin
5785
    commit0_v <= ({iqentry_v[head0], iqentry_cmt[head0]} == 2'b11 && ~|panic);
5786
    commit0_id <= {iqentry_mem[head0], head0};  // if a memory op, it has a DRAM-bus id
5787
    commit0_tgt <= iqentry_tgt[head0];
5788
    commit0_we  <= iqentry_we[head0];
5789
    commit0_bus <= iqentry_res[head0];
5790 49 robfinch
    if (`NUM_CMT > 1) begin
5791
            commit1_v <= ({iqentry_v[head0], iqentry_cmt[head0]} != 2'b10
5792
                       && {iqentry_v[head1], iqentry_cmt[head1]} == 2'b11
5793
                       && ~|panic);
5794
            commit1_id <= {iqentry_mem[head1], head1};
5795
            commit1_tgt <= iqentry_tgt[head1];
5796
            commit1_we  <= iqentry_we[head1];
5797
            commit1_bus <= iqentry_res[head1];
5798
        end
5799
        else begin
5800
                commit1_tgt <= 12'h000;
5801
                commit1_we <= 8'h00;
5802
        end
5803 48 robfinch
end
5804
 
5805
assign int_commit = (commit0_v && IsIrq(iqentry_instr[head0])) ||
5806 49 robfinch
                    (commit0_v && commit1_v && IsIrq(iqentry_instr[head1]) && `NUM_CMT > 1);
5807 48 robfinch
 
5808
// Detect if a given register will become valid during the current cycle.
5809
// We want a signal that is active during the current clock cycle for the read
5810
// through register file, which trims a cycle off register access for every
5811
// instruction. But two different kinds of assignment statements can't be
5812
// placed under the same always block, it's a bad practice and may not work.
5813
// So a signal is created here with it's own always block.
5814
reg [AREGS-1:0] regIsValid;
5815
always @*
5816
begin
5817
        for (n = 1; n < AREGS; n = n + 1)
5818
        begin
5819
                regIsValid[n] = rf_v[n];
5820
                if (branchmiss)
5821
               if (~livetarget[n]) begin
5822
                        if (branchmiss_thrd) begin
5823
                                if (n >= 128)
5824
                                        regIsValid[n] = `VAL;
5825
                        end
5826
                        else begin
5827
                                if (n < 128)
5828
                                        regIsValid[n] = `VAL;
5829
                        end
5830
               end
5831
                if (commit0_v && n=={commit0_tgt[7:0]})
5832
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit0_tgt[7:0]} ] == commit0_id
5833
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit0_id[`QBITS] ]));
5834 49 robfinch
                if (commit1_v && n=={commit1_tgt[7:0]} && `NUM_CMT > 1)
5835 48 robfinch
                        regIsValid[n] = regIsValid[n] | (rf_source[ {commit1_tgt[7:0]} ] == commit1_id
5836
                        || (branchmiss && branchmiss_thrd == iqentry_thrd[commit0_id[`QBITS]] && iqentry_source[ commit1_id[`QBITS] ]));
5837
        end
5838
        regIsValid[0] = `VAL;
5839
end
5840
 
5841
// Wait until the cycle after Ra becomes valid to give time to read
5842
// the vector element from the register file.
5843
reg rf_vra0, rf_vra1;
5844
/*always @(posedge clk)
5845
    rf_vra0 <= regIsValid[Ra0s];
5846
always @(posedge clk)
5847
    rf_vra1 <= regIsValid[Ra1s];
5848
*/
5849
// Check how many instructions can be queued. This might be fewer than the
5850
// number ready to queue from the fetch stage if queue slots aren't
5851
// available or if there are no more physical registers left for remapping.
5852
// The fetch stage needs to know how many instructions will queue so this
5853
// logic is placed here.
5854
// NOPs are filtered out and do not enter the instruction queue. The core
5855
// will stream NOPs on a cache miss and they would mess up the queue order
5856
// if there are immediate prefixes in the queue.
5857
// For the VEX instruction, the instruction can't queue until register Ra
5858
// is valid, because register Ra is used to specify the vector element to
5859
// read.
5860
wire q2open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV;
5861
wire q3open = iqentry_v[tail0]==`INV && iqentry_v[tail1]==`INV && iqentry_v[idp1(tail1)]==`INV;
5862
always @*
5863
begin
5864
        canq1 <= FALSE;
5865
        canq2 <= FALSE;
5866
        queued1 <= FALSE;
5867
        queued2 <= FALSE;
5868
        queuedNop <= FALSE;
5869
        vqueued2 <= FALSE;
5870
        if (!branchmiss) begin
5871
      // Two available
5872
      if (fetchbuf1_v & fetchbuf0_v) begin
5873
          // Is there a pair of NOPs ? (cache miss)
5874
          if ((fetchbuf0_instr[`INSTRUCTION_OP]==`NOP) && (fetchbuf1_instr[`INSTRUCTION_OP]==`NOP))
5875
              queuedNop <= TRUE;
5876
          else begin
5877
              // If it's a predicted branch queue only the first instruction, the second
5878
              // instruction will be stomped on.
5879
              if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
5880
                  if (iqentry_v[tail0]==`INV) begin
5881
                      canq1 <= TRUE;
5882
                      queued1 <= TRUE;
5883
                  end
5884
              end
5885
              // This is where a single NOP is allowed through to simplify the code. A
5886
              // single NOP can't be a cache miss. Otherwise it would be necessary to queue
5887
              // fetchbuf1 on tail0 it would add a nightmare to the enqueue code.
5888
              // Not a branch and there are two instructions fetched, see whether or not
5889
              // both instructions can be queued.
5890
              else begin
5891
                  if (iqentry_v[tail0]==`INV) begin
5892
                      canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5893
                      queued1 <= (
5894
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5895
                      if (iqentry_v[tail1]==`INV) begin
5896
                          canq2 <= ((!IsVex(fetchbuf1_instr) || rf_vra1)) || !SUP_VECTOR;
5897
                          queued2 <= (
5898
                                (!IsVector(fetchbuf1_instr) && (!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5899
                          vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5900
                      end
5901
                  end
5902
                  // If an irq is active during a vector instruction fetch, claim the vector instruction
5903
                  // is finished queueing even though it may not be. It'll pick up where it left off after
5904
                  // the exception is processed.
5905
                  if (hirq) begin
5906
                        if (IsVector(fetchbuf0_instr) && IsVector(fetchbuf1_instr) && vechain) begin
5907
                                queued1 <= TRUE;
5908
                                queued2 <= TRUE;
5909
                        end
5910
                        else if (IsVector(fetchbuf0_instr)) begin
5911
                                queued1 <= TRUE;
5912
                                if (vqe0 < vl-2)
5913
                                        queued2 <= TRUE;
5914
                                else
5915
                                        queued2 <= iqentry_v[tail1]==`INV;
5916
                        end
5917
                  end
5918
              end
5919
          end
5920
      end
5921
      // One available
5922
      else if (fetchbuf0_v) begin
5923
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
5924
              if (iqentry_v[tail0]==`INV) begin
5925
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5926
                  queued1 <=
5927
                        (((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5928
              end
5929
              if (iqentry_v[tail1]==`INV) begin
5930
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
5931
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5932
                end
5933
                if (hirq) begin
5934
                if (IsVector(fetchbuf0_instr)) begin
5935
                        queued1 <= TRUE;
5936
                        if (vqe0 < vl-2)
5937
                                queued2 <= iqentry_v[tail1]==`INV;
5938
                end
5939
                end
5940
          end
5941
          else
5942
              queuedNop <= TRUE;
5943
      end
5944
      else if (fetchbuf1_v) begin
5945
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
5946
              if (iqentry_v[tail0]==`INV) begin
5947
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
5948
                  queued1 <= (
5949
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
5950
              end
5951
              if (iqentry_v[tail1]==`INV) begin
5952
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
5953
                  vqueued2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2;
5954
                end
5955
                if (hirq) begin
5956
                if (IsVector(fetchbuf1_instr)) begin
5957
                        queued1 <= TRUE;
5958
                        if (vqe1 < vl-2)
5959
                                queued2 <= iqentry_v[tail1]==`INV;
5960
                end
5961
                end
5962
          end
5963
          else
5964
              queuedNop <= TRUE;
5965
      end
5966
      //else no instructions available to queue
5967
    end
5968
    else begin
5969
      // One available
5970
      if (fetchbuf0_v && fetchbuf0_thrd != branchmiss_thrd) begin
5971
          if (fetchbuf0_instr[`INSTRUCTION_OP]!=`NOP) begin
5972
              if (iqentry_v[tail0]==`INV) begin
5973
                  canq1 <= !IsVex(fetchbuf0_instr) || rf_vra0 || !SUP_VECTOR;
5974
                  queued1 <= (
5975
                        ((!IsVex(fetchbuf0_instr) || rf_vra0) && (!IsVector(fetchbuf0_instr))) || !SUP_VECTOR);
5976
              end
5977
              if (iqentry_v[tail1]==`INV) begin
5978
                canq2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && SUP_VECTOR;
5979
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5980
                end
5981
          end
5982
          else
5983
              queuedNop <= TRUE;
5984
      end
5985
      else if (fetchbuf1_v && fetchbuf1_thrd != branchmiss_thrd) begin
5986
          if (fetchbuf1_instr[`INSTRUCTION_OP]!=`NOP) begin
5987
              if (iqentry_v[tail0]==`INV) begin
5988
                  canq1 <= !IsVex(fetchbuf1_instr) || rf_vra1 || !SUP_VECTOR;
5989
                  queued1 <= (
5990
                        ((!IsVex(fetchbuf1_instr) || rf_vra1) && (!IsVector(fetchbuf1_instr))) || !SUP_VECTOR);
5991
              end
5992
              if (iqentry_v[tail1]==`INV) begin
5993
                canq2 <= IsVector(fetchbuf1_instr) && vqe1 < vl-2 && SUP_VECTOR;
5994
                  vqueued2 <= IsVector(fetchbuf0_instr) && vqe0 < vl-2 && !vechain;
5995
                end
5996
          end
5997
          else
5998
              queuedNop <= TRUE;
5999
      end
6000
        else
6001
                queuedNop <= TRUE;
6002
    end
6003
end
6004
 
6005
//
6006
// Branchmiss seems to be sticky sometimes during simulation. For instance branch miss
6007
// and cache miss at same time. The branchmiss should clear before the core continues
6008
// so the positive edge is detected to avoid incrementing the sequnce number too many
6009
// times.
6010
wire pebm;
6011
edge_det uedbm (.rst(rst), .clk(clk), .ce(1'b1), .i(branchmiss), .pe(pebm), .ne(), .ee() );
6012
 
6013
reg [5:0] ld_time;
6014
reg [63:0] wc_time_dat;
6015
reg [63:0] wc_times;
6016
always @(posedge tm_clk_i)
6017
begin
6018
        if (|ld_time)
6019
                wc_time <= wc_time_dat;
6020
        else begin
6021
                wc_time[31:0] <= wc_time[31:0] + 32'd1;
6022
                if (wc_time[31:0] >= TM_CLKFREQ-1) begin
6023
                        wc_time[31:0] <= 32'd0;
6024
                        wc_time[63:32] <= wc_time[63:32] + 32'd1;
6025
                end
6026
        end
6027
end
6028
 
6029
 
6030
// Monster clock domain.
6031
// Like to move some of this to clocking under different always blocks in order
6032
// to help out the toolset's synthesis, but it ain't gonna be easy.
6033
// Simulation doesn't like it if things are under separate always blocks.
6034
// Synthesis doesn't like it if things are under the same always block.
6035
 
6036 49 robfinch
//always @(posedge clk)
6037
//begin
6038
//      branchmiss <= excmiss|fcu_branchmiss;
6039
//    misspc <= excmiss ? excmisspc : fcu_misspc;
6040
//    missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
6041
//      branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
6042
//end
6043 48 robfinch
 
6044
always @(posedge clk)
6045
if (rst) begin
6046
`ifdef SUPPORT_SMT
6047
     mstatus[0] <= 64'h0007;     // select register set #0 for thread 0
6048
     mstatus[1] <= 64'h8007;    // select register set #2 for thread 1
6049
`else
6050
     mstatus <= 64'h0007;       // select register set #0 for thread 0
6051
`endif
6052
    for (n = 0; n < QENTRIES; n = n + 1) begin
6053
         iqentry_v[n] <= `INV;
6054
         iqentry_iv[n] <= `INV;
6055
         iqentry_is[n] <= 3'b00;
6056
         iqentry_done[n] <= FALSE;
6057
         iqentry_cmt[n] <= FALSE;
6058
         iqentry_out[n] <= FALSE;
6059
         iqentry_agen[n] <= FALSE;
6060
         iqentry_sn[n] <= 32'd0;
6061
         iqentry_pt[n] <= FALSE;
6062
         iqentry_bt[n] <= FALSE;
6063
         iqentry_br[n] <= FALSE;
6064
         iqentry_aq[n] <= FALSE;
6065
         iqentry_rl[n] <= FALSE;
6066
         iqentry_alu0[n] <= FALSE;
6067
         iqentry_alu[n] <= FALSE;
6068
         iqentry_alu0_issue[n] <= FALSE;
6069
         iqentry_alu1_issue[n] <= FALSE;
6070
         iqentry_fpu[n] <= FALSE;
6071 49 robfinch
         iqentry_fpu1_issue[n] <= FALSE;
6072
         iqentry_fpu2_issue[n] <= FALSE;
6073 48 robfinch
         iqentry_fsync[n] <= FALSE;
6074
         iqentry_fc[n] <= FALSE;
6075
         iqentry_fcu_issue[n] <= FALSE;
6076
         iqentry_jmp[n] <= FALSE;
6077
         iqentry_ldcmp[n] <= FALSE;
6078
         iqentry_load[n] <= FALSE;
6079
         iqentry_rtop[n] <= FALSE;
6080
         iqentry_sei[n] <= FALSE;
6081
         iqentry_shft48[n] <= FALSE;
6082
         iqentry_sync[n] <= FALSE;
6083
         iqentry_ven[n] <= 6'd0;
6084
         iqentry_vl[n] <= 8'd0;
6085
         iqentry_we[n] <= 8'h00;
6086
         iqentry_rfw[n] <= FALSE;
6087
         iqentry_rmw[n] <= FALSE;
6088
         iqentry_pc[n] <= RSTPC;
6089
         iqentry_instr[n] <= `NOP_INSN;
6090
         iqentry_insln[n] <= 4'd4;
6091
         iqentry_preload[n] <= FALSE;
6092
         iqentry_mem[n] <= FALSE;
6093
         iqentry_memndx[n] <= FALSE;
6094
         iqentry_memissue[n] <= FALSE;
6095
         iqentry_mem_islot[n] <= 3'd0;
6096 49 robfinch
         iqentry_memdb[n] <= FALSE;
6097
         iqentry_memsb[n] <= FALSE;
6098 48 robfinch
         iqentry_tgt[n] <= 6'd0;
6099
         iqentry_imm[n] <= 1'b0;
6100
         iqentry_a0[n] <= 64'd0;
6101
         iqentry_a1[n] <= 64'd0;
6102
         iqentry_a2[n] <= 64'd0;
6103
         iqentry_a3[n] <= 64'd0;
6104
         iqentry_a1_v[n] <= `INV;
6105
         iqentry_a2_v[n] <= `INV;
6106
         iqentry_a3_v[n] <= `INV;
6107
         iqentry_a1_s[n] <= 5'd0;
6108
         iqentry_a2_s[n] <= 5'd0;
6109
         iqentry_a3_s[n] <= 5'd0;
6110
         iqentry_canex[n] <= FALSE;
6111
    end
6112 49 robfinch
     bwhich <= 2'b00;
6113 48 robfinch
     dram0 <= `DRAMSLOT_AVAIL;
6114
     dram1 <= `DRAMSLOT_AVAIL;
6115
     dram2 <= `DRAMSLOT_AVAIL;
6116
     dram0_instr <= `NOP_INSN;
6117
     dram1_instr <= `NOP_INSN;
6118
     dram2_instr <= `NOP_INSN;
6119
     dram0_addr <= 32'h0;
6120
     dram1_addr <= 32'h0;
6121
     dram2_addr <= 32'h0;
6122
     L1_adr <= RSTPC;
6123
     invic <= FALSE;
6124
     tail0 <= 3'd0;
6125
     tail1 <= 3'd1;
6126
     head0 <= 0;
6127
     head1 <= 1;
6128
     head2 <= 2;
6129
     head3 <= 3;
6130
     head4 <= 4;
6131
     head5 <= 5;
6132
     head6 <= 6;
6133
     head7 <= 7;
6134
     panic = `PANIC_NONE;
6135
     alu0_dataready <= 0;
6136
     alu1_dataready <= 0;
6137
     alu0_sourceid <= 5'd0;
6138
     alu1_sourceid <= 5'd0;
6139
`ifdef SIM
6140
                alu0_pc <= RSTPC;
6141
                alu0_instr <= `NOP_INSN;
6142
                alu0_argA <= 64'h0;
6143
                alu0_argB <= 64'h0;
6144
                alu0_argC <= 64'h0;
6145
                alu0_argI <= 64'h0;
6146
                alu0_bt <= 1'b0;
6147
                alu0_mem <= 1'b0;
6148
                alu0_shft48 <= 1'b0;
6149
                alu0_thrd <= 1'b0;
6150
                alu0_tgt <= 6'h00;
6151
                alu0_ven <= 6'd0;
6152
                alu1_pc <= RSTPC;
6153
                alu1_instr <= `NOP_INSN;
6154
                alu1_argA <= 64'h0;
6155
                alu1_argB <= 64'h0;
6156
                alu1_argC <= 64'h0;
6157
                alu1_argI <= 64'h0;
6158
                alu1_bt <= 1'b0;
6159
                alu1_mem <= 1'b0;
6160
                alu1_shft48 <= 1'b0;
6161
                alu1_thrd <= 1'b0;
6162
                alu1_tgt <= 6'h00;
6163
                alu1_ven <= 6'd0;
6164
`endif
6165
     fcu_dataready <= 0;
6166
     fcu_instr <= `NOP_INSN;
6167
     fcu_retadr_v <= 0;
6168
     dramA_v <= 0;
6169
     dramB_v <= 0;
6170
     dramC_v <= 0;
6171
     I <= 0;
6172
     icstate <= IDLE;
6173
     bstate <= BIDLE;
6174
     tick <= 64'd0;
6175
     bte_o <= 2'b00;
6176
     cti_o <= 3'b000;
6177
     cyc_o <= `LOW;
6178
     stb_o <= `LOW;
6179
     we_o <= `LOW;
6180
     sel_o <= 8'h00;
6181
     sr_o <= `LOW;
6182
     cr_o <= `LOW;
6183
     adr_o <= RSTPC;
6184
     icl_o <= `LOW;             // instruction cache load
6185
     cr0 <= 64'd0;
6186
     cr0[13:8] <= 6'd0;         // select register set #0
6187
     cr0[30] <= TRUE;           // enable data caching
6188
     cr0[32] <= TRUE;           // enable branch predictor
6189
     cr0[16] <= 1'b0;           // disable SMT
6190
     cr0[17] <= 1'b0;           // sequence number reset = 1
6191
     pcr <= 32'd0;
6192
     pcr2 <= 64'd0;
6193
    for (n = 0; n < PREGS; n = n + 1)
6194
         rf_v[n] <= `VAL;
6195
     tgtq <= FALSE;
6196 49 robfinch
     fp1_rm <= 3'd0;                    // round nearest even - default rounding mode
6197
     fp2_rm <= 3'd0;
6198 48 robfinch
     waitctr <= 64'd0;
6199
    for (n = 0; n < 16; n = n + 1)
6200
         badaddr[n] <= 64'd0;
6201
     sbl <= 32'h0;
6202
     sbu <= 32'hFFFFFFFF;
6203
    // Vector
6204
     vqe0 <= 6'd0;
6205
     vqet0 <= 6'd0;
6206
     vqe1 <= 6'd0;
6207
     vqet1 <= 6'd0;
6208
     vl <= 7'd62;
6209
    for (n = 0; n < 8; n = n + 1)
6210
         vm[n] <= 64'h7FFFFFFFFFFFFFFF;
6211
     nop_fetchbuf <= 4'h0;
6212
     seq_num <= 5'd0;
6213
     seq_num1 <= 5'd0;
6214
     fcu_done <= `TRUE;
6215
     sema <= 64'h0;
6216
     tvec[0] <= RSTPC;
6217 49 robfinch
     pmr <= 64'hFFFFFFFFFFFFFFFF;
6218
     pmr[0] <= `ID1_AVAIL;
6219
     pmr[1] <= `ID2_AVAIL;
6220
     pmr[2] <= `ID3_AVAIL;
6221
     pmr[8] <= `ALU0_AVAIL;
6222
     pmr[9] <= `ALU1_AVAIL;
6223
     pmr[16] <= `FPU1_AVAIL;
6224
     pmr[17] <= `FPU2_AVAIL;
6225
     pmr[24] <= `MEM1_AVAIL;
6226
     pmr[25] <= `MEM2_AVAIL;
6227
                 pmr[26] <= `MEM3_AVAIL;
6228
     pmr[32] <= `FCU_AVAIL;
6229
     for (n = 0; n < `WB_DEPTH; n = n + 1) begin
6230
        wb_v[n] <= 1'b0;
6231
        wb_rmw[n] <= 1'b0;
6232
        wb_id[n] <= {QENTRIES{1'b0}};
6233
     end
6234
     wb_en <= `TRUE;
6235
     wbo_id <= {QENTRIES{1'b0}};
6236
`ifdef SIM
6237
                wb_merges <= 32'd0;
6238
`endif
6239 48 robfinch
end
6240
else begin
6241 49 robfinch
        if (|fb_panic)
6242
                panic <= fb_panic;
6243
        begin
6244
                branchmiss <= excmiss|fcu_branchmiss;
6245
            misspc <= excmiss ? excmisspc : fcu_misspc;
6246
            missid <= excmiss ? (|iqentry_exc[head0] ? head0 : head1) : fcu_sourceid;
6247
                branchmiss_thrd <=  excmiss ? excthrd : fcu_thrd;
6248
        end
6249 48 robfinch
        // The following signals only pulse
6250
 
6251
        // Instruction decode output should only pulse once for a queue entry. We
6252
        // want the decode to be invalidated after a clock cycle so that it isn't
6253
        // inadvertently used to update the queue at a later point.
6254
        id1_vi <= `INV;
6255 49 robfinch
        if (`NUM_IDU > 1)
6256
                id2_vi <= `INV;
6257
        if (`NUM_IDU > 2)
6258
                id3_vi <= `INV;
6259
        if (iqentry_v[nid] && iqentry_sn[nid] > iqentry_sn[fcu_id[`QBITS]])
6260
                fcu_dataready <= `INV;
6261 48 robfinch
        ld_time <= {ld_time[4:0],1'b0};
6262
        wc_times <= wc_time;
6263
     rf_vra0 <= regIsValid[Ra0s];
6264
     rf_vra1 <= regIsValid[Ra1s];
6265
    if (vqe0 >= vl) begin
6266
         vqe0 <= 6'd0;
6267
         vqet0 <= 6'h0;
6268
    end
6269
    if (vqe1 >= vl) begin
6270
         vqe1 <= 6'd0;
6271
         vqet1 <= 6'h0;
6272
    end
6273
    // Turn off vector chaining indicator when chained instructions are done.
6274
    if ((vqe0 >= vl || vqe0==6'd0) && (vqe1 >= vl || vqe1==6'd0))
6275
`ifdef SUPPORT_SMT
6276
        mstatus[0][32] <= 1'b0;
6277
`else
6278
        mstatus[32] <= 1'b0;
6279
`endif
6280
 
6281
     nop_fetchbuf <= 4'h0;
6282
     excmiss <= FALSE;
6283
     invic <= FALSE;
6284
     tick <= tick + 64'd1;
6285
     alu0_ld <= FALSE;
6286
     alu1_ld <= FALSE;
6287 49 robfinch
     fpu1_ld <= FALSE;
6288
     fpu2_ld <= FALSE;
6289 48 robfinch
     fcu_ld <= FALSE;
6290
     fcu_retadr_v <= FALSE;
6291
     dramA_v <= FALSE;
6292
     dramB_v <= FALSE;
6293
     dramC_v <= FALSE;
6294
     cr0[17] <= 1'b0;
6295
    if (waitctr != 64'd0)
6296
         waitctr <= waitctr - 64'd1;
6297
 
6298
 
6299
    if (IsFlowCtrl(iqentry_instr[fcu_id[`QBITS]]) && iqentry_v[fcu_id[`QBITS]] && !iqentry_done[fcu_id[`QBITS]] && iqentry_out[fcu_id[`QBITS]])
6300
        fcu_timeout <= fcu_timeout + 8'd1;
6301
 
6302
        if (branchmiss) begin
6303
        for (n = 1; n < PREGS; n = n + 1)
6304
           if (~livetarget[n]) begin
6305
                        if (branchmiss_thrd) begin
6306
                                if (n >= 128)
6307
                                rf_v[n] <= `VAL;
6308
                        end
6309
                        else begin
6310
                                if (n < 128)
6311
                                rf_v[n] <= `VAL;
6312
                end
6313
           end
6314
 
6315
            if (|iqentry_0_latestID)     if (iqentry_thrd[0]==branchmiss_thrd) rf_source[ {iqentry_tgt[0][7:0]} ] <= { 1'b0, iqentry_mem[0], 3'd0 };
6316
        if (|iqentry_1_latestID)     if (iqentry_thrd[1]==branchmiss_thrd) rf_source[ {iqentry_tgt[1][7:0]} ] <= { 1'b0, iqentry_mem[1], 3'd1 };
6317
        if (|iqentry_2_latestID)     if (iqentry_thrd[2]==branchmiss_thrd) rf_source[ {iqentry_tgt[2][7:0]} ] <= { 1'b0, iqentry_mem[2], 3'd2 };
6318
        if (|iqentry_3_latestID)     if (iqentry_thrd[3]==branchmiss_thrd) rf_source[ {iqentry_tgt[3][7:0]} ] <= { 1'b0, iqentry_mem[3], 3'd3 };
6319
        if (|iqentry_4_latestID)     if (iqentry_thrd[4]==branchmiss_thrd) rf_source[ {iqentry_tgt[4][7:0]} ] <= { 1'b0, iqentry_mem[4], 3'd4 };
6320
        if (|iqentry_5_latestID)     if (iqentry_thrd[5]==branchmiss_thrd) rf_source[ {iqentry_tgt[5][7:0]} ] <= { 1'b0, iqentry_mem[5], 3'd5 };
6321
        if (|iqentry_6_latestID)     if (iqentry_thrd[6]==branchmiss_thrd) rf_source[ {iqentry_tgt[6][7:0]} ] <= { 1'b0, iqentry_mem[6], 3'd6 };
6322
        if (|iqentry_7_latestID)     if (iqentry_thrd[7]==branchmiss_thrd) rf_source[ {iqentry_tgt[7][7:0]} ] <= { 1'b0, iqentry_mem[7], 3'd7 };
6323
 
6324
    end
6325
 
6326
    // The source for the register file data might have changed since it was
6327
    // placed on the commit bus. So it's needed to check that the source is
6328
    // still as expected to validate the register.
6329
        if (commit0_v) begin
6330
        if (!rf_v[ {commit0_tgt[7:0]} ])
6331
//             rf_v[ {commit0_tgt[7:0]} ] <= rf_source[ commit0_tgt[7:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]);
6332
             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] ]);
6333
        if (commit0_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit0_tgt, commit0_bus, regIsValid[commit0_tgt[5:0]],
6334
        rf_source[ {commit0_tgt[7:0]} ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ]));
6335
        if (commit0_tgt[5:0]==6'd30 && commit0_bus==64'd0)
6336
                $display("FP <= 0");
6337
    end
6338 49 robfinch
    if (commit1_v && `NUM_CMT > 1) begin
6339 48 robfinch
        if (!rf_v[ {commit1_tgt[7:0]} ]) begin
6340
                if ({commit1_tgt[7:0]}=={commit0_tgt[7:0]})
6341
                         rf_v[ {commit1_tgt[7:0]} ] <= regIsValid[{commit0_tgt[7:0]}] | regIsValid[{commit1_tgt[7:0]}];
6342
                        /*
6343
                                (rf_source[ commit0_tgt[4:0] ] == commit0_id || (branchmiss && iqentry_source[ commit0_id[`QBITS] ])) ||
6344
                                (rf_source[ commit1_tgt[4:0] ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6345
                        */
6346
                else
6347
                 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] ]);
6348
        end
6349
        if (commit1_tgt[5:0] != 6'd0) $display("r%d <- %h   v[%d]<-%d", commit1_tgt, commit1_bus, regIsValid[commit1_tgt[5:0]],
6350
        rf_source[ {commit1_tgt[7:0]} ] == commit1_id || (branchmiss && iqentry_source[ commit1_id[`QBITS] ]));
6351
        if (commit1_tgt[5:0]==6'd30 && commit1_bus==64'd0)
6352
                $display("FP <= 0");
6353
    end
6354
     rf_v[0] <= 1;
6355
 
6356 49 robfinch
  //
6357
  // ENQUEUE
6358
  //
6359
  // place up to two instructions from the fetch buffer into slots in the IQ.
6360
  //   note: they are placed in-order, and they are expected to be executed
6361
  // 0, 1, or 2 of the fetch buffers may have valid data
6362
  // 0, 1, or 2 slots in the instruction queue may be available.
6363
  // if we notice that one of the instructions in the fetch buffer is a predicted branch,
6364
  // (set branchback/backpc and delete any instructions after it in fetchbuf)
6365
  //
6366 48 robfinch
 
6367
        // enqueue fetchbuf0 and fetchbuf1, but only if there is room, 
6368
        // and ignore fetchbuf1 if fetchbuf0 has a backwards branch in it.
6369
        //
6370
        // also, do some instruction-decode ... set the operand_valid bits in the IQ
6371
        // appropriately so that the DATAINCOMING stage does not have to look at the opcode
6372
        //
6373
        if (!branchmiss)        // don't bother doing anything if there's been a branch miss
6374
 
6375
                case ({fetchbuf0_v, fetchbuf1_v})
6376
 
6377
            2'b00: ; // do nothing
6378
 
6379
            2'b01:
6380
                    if (canq1) begin
6381
                    if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6382
                         vqe1 <= vqe1 + 4'd1;
6383
                        if (IsVCmprss(fetchbuf1_instr)) begin
6384
                            if (vm[fetchbuf1_instr[25:23]][vqe1])
6385
                                 vqet1 <= vqet1 + 4'd1;
6386
                        end
6387
                        else
6388
                             vqet1 <= vqet1 + 4'd1;
6389
                        if (vqe1 >= vl-2)
6390
                                 nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6391
                            enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, vqe1);
6392
                            if (fetchbuf1_thrd)
6393
                                seq_num1 <= seq_num1 + 5'd1;
6394
                            else
6395
                                seq_num <= seq_num + 5'd1;
6396
                             tgtq <= FALSE;
6397
                            if (fetchbuf1_rfw) begin
6398
                                 rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail0 }; // top bit indicates ALU/MEM bus
6399
                                 rf_v [Rt1s] <= `INV;
6400
                            end
6401
                        if (canq2 && vqe1 < vl-2) begin
6402
                                 vqe1 <= vqe1 + 4'd2;
6403
                                if (IsVCmprss(fetchbuf1_instr)) begin
6404
                                    if (vm[fetchbuf1_instr[25:23]][vqe1+6'd1])
6405
                                         vqet1 <= vqet1 + 4'd2;
6406
                                end
6407
                                else
6408
                                     vqet1 <= vqet1 + 4'd2;
6409
                                    enque1(tail1, fetchbuf1_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe1 + 6'd1);
6410
                                    if (fetchbuf1_thrd)
6411
                                        seq_num1 <= seq_num1 + 5'd2;
6412
                                    else
6413
                                        seq_num <= seq_num + 5'd2;
6414
                                     tgtq <= FALSE;
6415
                                    if (fetchbuf1_rfw) begin
6416
                                         rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail1 }; // top bit indicates ALU/MEM bus
6417
                                         rf_v [Rt1s] <= `INV;
6418
                                    end
6419
                        end
6420
                    end
6421
                    else begin
6422
                            enque1(tail0, fetchbuf1_thrd ? seq_num1 : seq_num, 6'd0);
6423
                            if (fetchbuf1_thrd)
6424
                                seq_num1 <= seq_num1 + 5'd1;
6425
                            else
6426
                                seq_num <= seq_num + 5'd1;
6427
                             tgtq <= FALSE;
6428
                            if (fetchbuf1_rfw) begin
6429
                                 rf_source[ Rt1s ] <= { 1'b0, fetchbuf1_memld, tail0 }; // top bit indicates ALU/MEM bus
6430
                                 rf_v [Rt1s] <= `INV;
6431
                            end
6432
                        end
6433
                    end
6434
 
6435
            2'b10:
6436
                if (canq1) begin
6437
//                  $display("queued1: %d", queued1);
6438
//                      if (!IsBranch(fetchbuf0_instr))         panic <= `PANIC_FETCHBUFBEQ;
6439
//                      if (!predict_taken0)    panic <= `PANIC_FETCHBUFBEQ;
6440
                        //
6441
                        // this should only happen when the first instruction is a BEQ-backwards and the IQ
6442
                        // happened to be full on the previous cycle (thus we deleted fetchbuf1 but did not
6443
                        // enqueue fetchbuf0) ... probably no need to check for LW -- sanity check, just in case
6444
                        //
6445
                    if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
6446
                         vqe0 <= vqe0 + 4'd1;
6447
                        if (IsVCmprss(fetchbuf0_instr)) begin
6448
                            if (vm[fetchbuf0_instr[25:23]][vqe0])
6449
                                 vqet0 <= vqet0 + 4'd1;
6450
                        end
6451
                        else
6452
                             vqet0 <= vqet0 + 4'd1;
6453
                        if (vqe0 >= vl-2)
6454
                                 nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6455
                                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
6456
                                if (fetchbuf0_thrd)
6457
                                        seq_num1 <= seq_num1 + 5'd1;
6458
                                else
6459
                                        seq_num <= seq_num + 5'd1;
6460
                             tgtq <= FALSE;
6461
                                if (fetchbuf0_rfw) begin
6462
                                 rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
6463
                                 rf_v[Rt0s] <= `INV;
6464
                            end
6465
                        if (canq2) begin
6466
                                    if (vqe0 < vl-2) begin
6467
                                         vqe0 <= vqe0 + 4'd2;
6468
                                        if (IsVCmprss(fetchbuf0_instr)) begin
6469
                                            if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
6470
                                                 vqet0 <= vqet0 + 4'd2;
6471
                                        end
6472
                                        else
6473
                                             vqet0 <= vqet0 + 4'd2;
6474
                                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num+5'd1, vqe0 + 6'd1);
6475
                                                if (fetchbuf0_thrd)
6476
                                                        seq_num1 <= seq_num1 + 5'd2;
6477
                                                else
6478
                                                        seq_num <= seq_num + 5'd2;
6479
                                             tgtq <= FALSE;
6480
                                                if (fetchbuf0_rfw) begin
6481
                                                 rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };    // top bit indicates ALU/MEM bus
6482
                                                 rf_v[Rt0s] <= `INV;
6483
                                            end
6484
                                    end
6485
                        end
6486
                    end
6487
                    else begin
6488
                                enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, 6'd0);
6489
                                if (fetchbuf0_thrd)
6490
                                        seq_num1 <= seq_num1 + 5'd1;
6491
                                else
6492
                                        seq_num <= seq_num + 5'd1;
6493
                             tgtq <= FALSE;
6494
                                if (fetchbuf0_rfw) begin
6495
                                 rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail0 };    // top bit indicates ALU/MEM bus
6496
                                 rf_v[Rt0s] <= `INV;
6497
                            end
6498
                        end
6499
                    end
6500
 
6501
            2'b11:
6502
                    if (canq1) begin
6503
                                //
6504
                                // if the first instruction is a predicted branch, enqueue it & stomp on all following instructions
6505
                                // but only if the following instruction is in the same thread. Otherwise we want to queue two.
6506
                                //
6507
                                if (take_branch0 && fetchbuf1_thrd==fetchbuf0_thrd) begin
6508
                             tgtq <= FALSE;
6509
                            enque0(tail0,fetchbuf0_thrd ? seq_num1 : seq_num,6'd0);
6510
                                if (fetchbuf0_thrd)
6511
                                        seq_num1 <= seq_num1 + 5'd1;
6512
                                else
6513
                                        seq_num <= seq_num + 5'd1;
6514
                                        if (fetchbuf0_rfw) begin
6515
                                             rf_source[ Rt0s ] <= {1'b0,fetchbuf0_memld, tail0};
6516
                                             rf_v [ Rt0s ] <= `INV;
6517
                                        end
6518
                                end
6519
 
6520
                                else begin      // fetchbuf0 doesn't contain a predicted branch
6521
                                    //
6522
                                    // so -- we can enqueue 1 or 2 instructions, depending on space in the IQ
6523
                                    // update the rf_v and rf_source bits separately (at end)
6524
                                    //   the problem is that if we do have two instructions, 
6525
                                    //   they may interact with each other, so we have to be
6526
                                    //   careful about where things point.
6527
                                    //
6528
                                    // enqueue the first instruction ...
6529
                                    //
6530
                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR) begin
6531
                                 vqe0 <= vqe0 + 4'd1;
6532
                                if (IsVCmprss(fetchbuf0_instr)) begin
6533
                                    if (vm[fetchbuf0_instr[25:23]][vqe0])
6534
                                         vqet0 <= vqet0 + 4'd1;
6535
                                end
6536
                                else
6537
                                     vqet0 <= vqet0 + 4'd1;
6538
                                if (vqe0 >= vl-2)
6539
                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6540
                            end
6541
                            tgtq <= FALSE;
6542
                            if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
6543
                                    enque0(tail0, fetchbuf0_thrd ? seq_num1 : seq_num, vqe0);
6544
                                        if (fetchbuf0_thrd)
6545
                                                seq_num1 <= seq_num1 + 5'd1;
6546
                                        else
6547
                                                seq_num <= seq_num + 5'd1;
6548
                                            //
6549
                                            // if there is room for a second instruction, enqueue it
6550
                                            //
6551
                                            if (canq2) begin
6552
                                                if (vechain && IsVector(fetchbuf1_instr)
6553
                                                && Ra1s != Rt0s // And there is no dependency
6554
                                                && Rb1s != Rt0s
6555
                                                && Rc1s != Rt0s
6556
                                                ) begin
6557
`ifdef SUPPORT_SMT
6558
                                                        mstatus[0][32] <= 1'b1;
6559
`else
6560
                                                        mstatus[32] <= 1'b1;
6561
`endif
6562
                                                vqe1 <= vqe1 + 4'd1;
6563
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6564
                                                    if (vm[fetchbuf1_instr[25:23]][vqe1])
6565
                                                         vqet1 <= vqet1 + 4'd1;
6566
                                                end
6567
                                                else
6568
                                                     vqet1 <= vqet1 + 4'd1;
6569
                                                if (vqe1 >= vl-2)
6570
                                                        nop_fetchbuf <= fetchbuf ? 4'b0100 : 4'b0001;
6571
                                                        enque1(tail1,
6572
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6573
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6574
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
6575
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6576
                                                                if (fetchbuf1_thrd)
6577
                                                                        seq_num1 <= seq_num1 + 5'd2;
6578
                                                                else
6579
                                                                        seq_num <= seq_num + 5'd2;
6580
                                                        end
6581
                                                        else begin
6582
                                                                if (fetchbuf1_thrd)
6583
                                                                        seq_num1 <= seq_num1 + 5'd1;
6584
                                                                else
6585
                                                                        seq_num <= seq_num + 5'd1;
6586
                                                        end
6587
 
6588
                                                                // SOURCE 1 ...
6589
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6590
                                                                if (~fetchbuf0_rfw) begin
6591
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6592
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6593
                                                                end
6594
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6595
                                                                else if (Ra1 == Rt0) begin
6596
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6597
                                                                     iqentry_a1_v [tail1] <= `INV;
6598
                                                                     iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6599
                                                                end
6600
                                                                // if no overlap, get info from rf_v and rf_source
6601
                                                                else begin
6602
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6603
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6604
                                                                end
6605
 
6606
                                                                // SOURCE 2 ...
6607
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6608
                                                                if (~fetchbuf0_rfw) begin
6609
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6610
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6611
                                                                end
6612
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6613
                                                                else if (Rb1s == Rt0s) begin
6614
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6615
                                                                     iqentry_a2_v [tail1] <= `INV;
6616
                                                                     iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6617
                                                                end
6618
                                                                // if no overlap, get info from rf_v and rf_source
6619
                                                                else begin
6620
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6621
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6622
                                                                end
6623
 
6624
                                                                // SOURCE 3 ...
6625
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6626
                                                                if (~fetchbuf0_rfw) begin
6627
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6628
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6629
                                                                end
6630
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6631
                                                                else if (Rc1 == Rt0) begin
6632
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6633
                                                                     iqentry_a3_v [tail1] <= `INV;
6634
                                                                     iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6635
                                                                end
6636
                                                                // if no overlap, get info from rf_v and rf_source
6637
                                                                else begin
6638
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6639
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6640
                                                                end
6641
 
6642
                                                                // if the two instructions enqueued target the same register, 
6643
                                                                // make sure only the second writes to rf_v and rf_source.
6644
                                                                // first is allowed to update rf_v and rf_source only if the
6645
                                                                // second has no target
6646
                                                                //
6647
                                                            if (fetchbuf0_rfw) begin
6648
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6649
                                                                     rf_v [ Rt0s] <= `INV;
6650
                                                            end
6651
                                                            if (fetchbuf1_rfw) begin
6652
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6653
                                                                     rf_v [ Rt1s ] <= `INV;
6654
                                                            end
6655
                                                end
6656
                                                // If there was a vector instruction in fetchbuf0, we really
6657
                                                // want to queue the next vector element, not the next
6658
                                                // instruction waiting in fetchbuf1.
6659
                                            else if (IsVector(fetchbuf0_instr) && SUP_VECTOR && vqe0 < vl-1) begin
6660
                                                 vqe0 <= vqe0 + 4'd2;
6661
                                                if (IsVCmprss(fetchbuf0_instr)) begin
6662
                                                    if (vm[fetchbuf0_instr[25:23]][vqe0+6'd1])
6663
                                                         vqet0 <= vqet0 + 4'd2;
6664
                                                end
6665
                                                else
6666
                                                     vqet0 <= vqet0 + 4'd2;
6667
                                                if (vqe0 >= vl-3)
6668
                                                 nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6669
                                            if (vqe0 < vl-1) begin
6670
                                                                enque0(tail1, fetchbuf0_thrd ? seq_num1 + 5'd1 : seq_num + 5'd1, vqe0 + 6'd1);
6671
                                                                if (fetchbuf0_thrd)
6672
                                                                        seq_num1 <= seq_num1 + 5'd2;
6673
                                                                else
6674
                                                                        seq_num <= seq_num + 5'd2;
6675
 
6676
                                                                        // SOURCE 1 ...
6677
                                                     iqentry_a1_v [tail1] <= regIsValid[Ra0s];
6678
                                                     iqentry_a1_s [tail1] <= rf_source [Ra0s];
6679
 
6680
                                                                        // SOURCE 2 ...
6681
                                                     iqentry_a2_v [tail1] <= regIsValid[Rb0s];
6682
                                                     iqentry_a2_s [tail1] <= rf_source[ Rb0s ];
6683
 
6684
                                                                        // SOURCE 3 ...
6685
                                                     iqentry_a3_v [tail1] <= regIsValid[Rc0s];
6686
                                                     iqentry_a3_s [tail1] <= rf_source[ Rc0s ];
6687
 
6688
                                                                        // if the two instructions enqueued target the same register, 
6689
                                                                        // make sure only the second writes to rf_v and rf_source.
6690
                                                                        // first is allowed to update rf_v and rf_source only if the
6691
                                                                        // second has no target (BEQ or SW)
6692
                                                                        //
6693
                                                                    if (fetchbuf0_rfw) begin
6694
                                                                             rf_source[ Rt0s ] <= { 1'b0, fetchbuf0_memld, tail1 };
6695
                                                                             rf_v [ Rt0s ] <= `INV;
6696
                                                                    end
6697
                                                                end
6698
                                                end
6699
                                            else if (IsVector(fetchbuf1_instr) && SUP_VECTOR) begin
6700
                                                 vqe1 <= 6'd1;
6701
                                                if (IsVCmprss(fetchbuf1_instr)) begin
6702
                                                    if (vm[fetchbuf1_instr[25:23]][IsVector(fetchbuf0_instr)? 6'd0:vqe1+6'd1])
6703
                                                         vqet1 <= 6'd1;
6704
                                                else
6705
                                                         vqet1 <= 6'd0;
6706
                                                end
6707
                                                else
6708
                                                         vqet1 <= 6'd1;
6709
                                            if (IsVector(fetchbuf0_instr) && SUP_VECTOR)
6710
                                                        nop_fetchbuf <= fetchbuf ? 4'b1000 : 4'b0010;
6711
                                                        enque1(tail1,
6712
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6713
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6714
                                                                fetchbuf1_thrd ? seq_num1 + 5'd1: seq_num + 5'd1, 6'd0);
6715
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6716
                                                                if (fetchbuf1_thrd)
6717
                                                                        seq_num1 <= seq_num1 + 5'd2;
6718
                                                                else
6719
                                                                        seq_num <= seq_num + 5'd2;
6720
                                                        end
6721
                                                        else begin
6722
                                                                if (fetchbuf1_thrd)
6723
                                                                        seq_num1 <= seq_num1 + 5'd1;
6724
                                                                else
6725
                                                                        seq_num <= seq_num + 5'd1;
6726
                                                        end
6727
 
6728
                                                                // SOURCE 1 ...
6729
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6730
                                                                if (~fetchbuf0_rfw) begin
6731
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6732
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6733
                                                                end
6734
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6735
                                                                else if (Ra1 == Rt0) begin
6736
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6737
                                                                     iqentry_a1_v [tail1] <= `INV;
6738
                                                                     iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6739
                                                                end
6740
                                                                // if no overlap, get info from rf_v and rf_source
6741
                                                                else begin
6742
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6743
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6744
                                                                end
6745
 
6746
                                                                // SOURCE 2 ...
6747
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6748
                                                                if (~fetchbuf0_rfw) begin
6749
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6750
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6751
                                                                end
6752
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6753
                                                                else if (Rb1s == Rt0s) begin
6754
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6755
                                                                     iqentry_a2_v [tail1] <= `INV;
6756
                                                                     iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6757
                                                                end
6758
                                                                // if no overlap, get info from rf_v and rf_source
6759
                                                                else begin
6760
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6761
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6762
                                                                end
6763
 
6764
                                                                // SOURCE 3 ...
6765
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6766
                                                                if (~fetchbuf0_rfw) begin
6767
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6768
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6769
                                                                end
6770
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6771
                                                                else if (Rc1 == Rt0) begin
6772
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6773
                                                                     iqentry_a3_v [tail1] <= `INV;
6774
                                                                     iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_mem &IsLoad(fetchbuf0_instr), tail0 };
6775
                                                                end
6776
                                                                // if no overlap, get info from rf_v and rf_source
6777
                                                                else begin
6778
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6779
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6780
                                                                end
6781
 
6782
                                                                // if the two instructions enqueued target the same register, 
6783
                                                                // make sure only the second writes to rf_v and rf_source.
6784
                                                                // first is allowed to update rf_v and rf_source only if the
6785
                                                                // second has no target
6786
                                                                //
6787
                                                            if (fetchbuf0_rfw) begin
6788
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6789
                                                                     rf_v [ Rt0s] <= `INV;
6790
                                                            end
6791
                                                            if (fetchbuf1_rfw) begin
6792
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6793
                                                                     rf_v [ Rt1s ] <= `INV;
6794
                                                            end
6795
                                            end
6796
                                            else begin
6797
//                                                      enque1(tail1, seq_num + 5'd1, 6'd0);
6798
                                                        enque1(tail1,
6799
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b1 ? seq_num1 + 5'd1 :
6800
                                                                fetchbuf1_thrd==fetchbuf0_thrd && fetchbuf1_thrd==1'b0 ? seq_num + 5'd1 :
6801
                                                                fetchbuf1_thrd ? seq_num1: seq_num, 6'd0);
6802
                                                        if (fetchbuf1_thrd==fetchbuf0_thrd) begin
6803
                                                                if (fetchbuf1_thrd)
6804
                                                                        seq_num1 <= seq_num1 + 5'd2;
6805
                                                                else
6806
                                                                        seq_num <= seq_num + 5'd2;
6807
                                                        end
6808
                                                        else begin
6809
                                                                        seq_num1 <= seq_num1 + 5'd1;
6810
                                                                        seq_num <= seq_num + 5'd1;
6811
                                                        end
6812
 
6813
                                                                // SOURCE 1 ...
6814
                                                                // if previous instruction writes nothing to RF, then get info from rf_v and rf_source
6815
                                                                if (~fetchbuf0_rfw) begin
6816
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6817
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6818
                                                                end
6819
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6820
                                                                else if (Ra1s == Rt0s) begin
6821
                                                                     iqentry_a1_v [tail1] <= `INV;
6822
                                                                     iqentry_a1_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
6823
                                                                end
6824
                                                                // if no overlap, get info from regIsValid and rf_source
6825
                                                                else begin
6826
                                                                     iqentry_a1_v [tail1] <= regIsValid[Ra1s];
6827
                                                                     iqentry_a1_s [tail1] <= rf_source [Ra1s];
6828
                                                                end
6829
 
6830
                                                                // SOURCE 2 ...
6831
                                                                // if the argument is an immediate or not needed, we're done
6832
                                                                $display("Rb1s=%h, Rt0s=%h", Rb1s, Rt0s);
6833
                                                                $display("instr=%h", fetchbuf1_instr);
6834
                                                                // if previous instruction writes nothing to RF, then get info from regIsValid and rf_source
6835
                                                                if (~fetchbuf0_rfw) begin
6836
                                                                        $display("fetchbuf0_rfw=0");
6837
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6838
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6839
                                                                end
6840
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6841
                                                                else if (Rb1s == Rt0s) begin
6842
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6843
                                                                     iqentry_a2_v [tail1] <= `INV;
6844
                                                                     iqentry_a2_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
6845
                                                                end
6846
                                                                // if no overlap, get info from regIsValid and rf_source
6847
                                                                else begin
6848
                                                                                $display("No overlap");
6849
                                                                     iqentry_a2_v [tail1] <= regIsValid[Rb1s];
6850
                                                                     iqentry_a2_s [tail1] <= rf_source[ Rb1s ];
6851
                                                                end
6852
 
6853
                                                                // SOURCE 3 ...
6854
                                                                // if previous instruction writes nothing to RF, then get info from regIsValid and rf_source
6855
                                                                if (~fetchbuf0_rfw) begin
6856
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6857
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6858
                                                                end
6859
                                                                // otherwise, previous instruction does write to RF ... see if overlap
6860
                                                                else if (Rc1s == Rt0s) begin
6861
                                                                    // if the previous instruction is a LW, then grab result from memq, not the iq
6862
                                                                     iqentry_a3_v [tail1] <= `INV;
6863
                                                                     iqentry_a3_s [tail1] <= { 1'b0, fetchbuf0_memld, tail0 };
6864
                                                                end
6865
                                                                // if no overlap, get info from regIsValid and rf_source
6866
                                                                else begin
6867
                                                                     iqentry_a3_v [tail1] <= regIsValid[Rc1s];
6868
                                                                     iqentry_a3_s [tail1] <= rf_source[ Rc1s ];
6869
                                                                end
6870
 
6871
                                                                // if the two instructions enqueued target the same register, 
6872
                                                                // make sure only the second writes to regIsValid and rf_source.
6873
                                                                // first is allowed to update regIsValid and rf_source only if the
6874
                                                                // second has no target (BEQ or SW)
6875
                                                                //
6876
                                                            if (fetchbuf0_rfw) begin
6877
                                                                     rf_source[ Rt0s ] <= { 1'b0,fetchbuf0_memld, tail0 };
6878
                                                                     rf_v [ Rt0s] <= `INV;
6879
                                                                     $display("r%dx (%d) Invalidated", Rt0s, Rt0s[4:0]);
6880
                                                            end
6881
                                                            else
6882
                                                                $display("No rfw");
6883
                                                            if (fetchbuf1_rfw) begin
6884
                                                                     rf_source[ Rt1s ] <= { 1'b0,fetchbuf1_memld, tail1 };
6885
                                                                     $display("r%dx (%d) Invalidated", Rt1s, Rt1s[4:0]);
6886
                                                                     rf_v [ Rt1s ] <= `INV;
6887
                                                            end
6888
                                                            else
6889
                                                                $display("No rfw");
6890
                                                        end
6891
 
6892
                                            end // ends the "if IQ[tail1] is available" clause
6893
                                            else begin  // only first instruction was enqueued
6894
                                                        if (fetchbuf0_rfw) begin
6895
                                                             $display("r%dx (%d) Invalidated 1", Rt0s, Rt0s[4:0]);
6896
                                                             rf_source[ Rt0s ] <= {1'b0,fetchbuf0_memld, tail0};
6897
                                                             rf_v [ Rt0s ] <= `INV;
6898
                                                        end
6899
                                                end
6900
                                    end
6901
 
6902
                                end     // ends the "else fetchbuf0 doesn't have a backwards branch" clause
6903
                    end
6904
                endcase
6905
        if (pebm) begin
6906
                if (branchmiss_thrd==1'b0)
6907
                        seq_num <= seq_num + 5'd3;
6908
                else
6909
                        seq_num1 <= seq_num1 + 5'd3;
6910
        end
6911
 
6912
//
6913
// DATAINCOMING
6914
//
6915
// wait for operand/s to appear on alu busses and puts them into 
6916
// the iqentry_a1 and iqentry_a2 slots (if appropriate)
6917
// as well as the appropriate iqentry_res slots (and setting valid bits)
6918
//
6919
// put results into the appropriate instruction entries
6920
//
6921
// This chunk of code has to be before the enqueue stage so that the agen bit
6922
// can be reset to zero by enqueue.
6923
// put results into the appropriate instruction entries
6924
//
6925
if (IsMul(alu0_instr)|IsDivmod(alu0_instr)|alu0_shft48) begin
6926
        if (alu0_done) begin
6927
                alu0_dataready <= `TRUE;
6928
        end
6929
end
6930
 
6931
if (alu0_v) begin
6932
        iqentry_tgt [ alu0_id[`QBITS] ] <= alu0_tgt;
6933
        iqentry_res     [ alu0_id[`QBITS] ] <= alu0_bus;
6934
        iqentry_exc     [ alu0_id[`QBITS] ] <= alu0_exc;
6935
        iqentry_done[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
6936
        iqentry_cmt[ alu0_id[`QBITS] ] <= !iqentry_mem[ alu0_id[`QBITS] ] && alu0_done;
6937
        iqentry_out     [ alu0_id[`QBITS] ] <= `INV;
6938
        iqentry_agen[ alu0_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
6939
        alu0_dataready <= FALSE;
6940
end
6941
 
6942 49 robfinch
if (alu1_v && `NUM_ALU > 1) begin
6943 48 robfinch
        iqentry_tgt [ alu1_id[`QBITS] ] <= alu1_tgt;
6944
        iqentry_res     [ alu1_id[`QBITS] ] <= alu1_bus;
6945
        iqentry_exc     [ alu1_id[`QBITS] ] <= alu1_exc;
6946
        iqentry_done[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
6947
        iqentry_cmt[ alu1_id[`QBITS] ] <= !iqentry_mem[ alu1_id[`QBITS] ] && alu1_done;
6948
        iqentry_out     [ alu1_id[`QBITS] ] <= `INV;
6949
        iqentry_agen[ alu1_id[`QBITS] ] <= `VAL;//!iqentry_fc[alu0_id[`QBITS]];  // RET
6950
        alu1_dataready <= FALSE;
6951
end
6952
 
6953 49 robfinch
if (fpu1_v) begin
6954
        iqentry_res    [ fpu1_id[`QBITS] ] <= fpu1_bus;
6955
        iqentry_a0     [ fpu1_id[`QBITS] ] <= fpu1_status;
6956
        iqentry_exc    [ fpu1_id[`QBITS] ] <= fpu1_exc;
6957
        iqentry_done[ fpu1_id[`QBITS] ] <= fpu1_done;
6958
        iqentry_cmt[ fpu1_id[`QBITS] ] <= fpu1_done;
6959
        iqentry_out    [ fpu1_id[`QBITS] ] <= `INV;
6960 48 robfinch
        //iqentry_agen[ fpu_id[`QBITS] ] <= `VAL;  // RET
6961 49 robfinch
        fpu1_dataready <= FALSE;
6962 48 robfinch
end
6963
 
6964 49 robfinch
if (fpu2_v && `NUM_FPU > 1) begin
6965
        iqentry_res    [ fpu2_id[`QBITS] ] <= fpu2_bus;
6966
        iqentry_a0     [ fpu2_id[`QBITS] ] <= fpu2_status;
6967
        iqentry_exc    [ fpu2_id[`QBITS] ] <= fpu2_exc;
6968
        iqentry_done[ fpu2_id[`QBITS] ] <= fpu2_done;
6969
        iqentry_cmt[ fpu2_id[`QBITS] ] <= fpu2_done;
6970
        iqentry_out    [ fpu2_id[`QBITS] ] <= `INV;
6971
        //iqentry_agen[ fpu_id[`QBITS] ] <= `VAL;  // RET
6972
        fpu2_dataready <= FALSE;
6973
end
6974
 
6975
        if (fcu_wr & ~fcu_done) begin
6976 48 robfinch
            if (fcu_ld)
6977
                waitctr <= fcu_argA;
6978
        iqentry_res [ fcu_id[`QBITS] ] <= fcu_bus;
6979
        iqentry_exc [ fcu_id[`QBITS] ] <= fcu_exc;
6980
        if (IsWait(fcu_instr)) begin
6981
             iqentry_done [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
6982
             iqentry_cmt [ fcu_id[`QBITS] ] <= (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]];
6983
             fcu_done <= `TRUE;
6984
        end
6985
        else begin
6986
             iqentry_done[ fcu_id[`QBITS] ] <= `TRUE;
6987
             iqentry_cmt[ fcu_id[`QBITS] ] <= `TRUE;
6988
             fcu_done <= `TRUE;
6989
        end
6990
//            if (IsWait(fcu_instr) ? (waitctr==64'd1) || signal_i[fcu_argA[4:0]|fcu_argI[4:0]] : !IsMem(fcu_instr) && !IsImmp(fcu_instr))
6991
//                iqentry_instr[ dram_id[`QBITS]] <= `NOP_INSN;
6992
        // Only safe place to propagate the miss pc is a0.
6993
        iqentry_a0[ fcu_id[`QBITS] ] <= fcu_misspc;
6994
        // Update branch taken indicator.
6995
        if (IsJAL(fcu_instr) || IsRet(fcu_instr) || IsBrk(fcu_instr) || IsRTI(fcu_instr) ) begin
6996
             iqentry_bt[ fcu_id[`QBITS] ] <= `VAL;
6997
            // Only safe place to propagate the miss pc is a0.
6998
//             iqentry_a0[ fcu_id[`QBITS] ] <= fcu_misspc;
6999
        end
7000
        else if (IsBranch(fcu_instr)) begin
7001
             iqentry_bt[ fcu_id[`QBITS] ] <= fcu_takb;
7002
//             iqentry_a0[ fcu_id[`QBITS] ] <= fcu_misspc;
7003
        end
7004
         iqentry_out [ fcu_id[`QBITS] ] <= `INV;
7005
         //iqentry_agen[ fcu_id[`QBITS] ] <= `VAL;//!IsRet(fcu_instr);
7006
        fcu_dataready <= `VAL;
7007
         //fcu_dataready <= fcu_branchmiss || !iqentry_agen[ fcu_id[`QBITS] ] || !(iqentry_mem[ fcu_id[`QBITS] ] && IsLoad(iqentry_instr[fcu_id[`QBITS]]));
7008
         //fcu_instr[`INSTRUCTION_OP] <= fcu_branchmiss|| (!IsMem(fcu_instr) && !IsWait(fcu_instr))? `NOP : fcu_instr[`INSTRUCTION_OP]; // to clear branchmiss
7009
        end
7010
        // Clear a branch miss when target instruction is fetched.
7011
        if (fcu_branchmiss) begin
7012
                if ((fetchbuf0_v && fetchbuf0_pc==misspc) ||
7013
                        (fetchbuf1_v && fetchbuf1_pc==misspc))
7014
                fcu_clearbm <= `TRUE;
7015
                //fcu_instr[`INSTRUCTION_OP] <= `NOP;
7016
                //iqentry_instr[fcu_id][`INSTRUCTION_OP] <= `NOP;
7017
        end
7018
//      if (dram_v && iqentry_v[ dram_id[`QBITS] ] && iqentry_mem[ dram_id[`QBITS] ] ) begin    // if data for stomped instruction, ignore
7019 49 robfinch
        if (mem1_available && dramA_v && iqentry_v[ dramA_id[`QBITS] ] && iqentry_load[ dramA_id[`QBITS] ]) begin       // if data for stomped instruction, ignore
7020 48 robfinch
                iqentry_res     [ dramA_id[`QBITS] ] <= dramA_bus;
7021
        iqentry_exc     [ dramA_id[`QBITS] ] <= dramA_exc;
7022
        iqentry_done[ dramA_id[`QBITS] ] <= `VAL;
7023
        iqentry_out [ dramA_id[`QBITS] ] <= `INV;
7024
        iqentry_cmt[ dramA_id[`QBITS] ] <= `VAL;
7025
            iqentry_aq  [ dramA_id[`QBITS] ] <= `INV;
7026
//          if (iqentry_lptr[dram0_id[`QBITS]])
7027
//              wbrcd[pcr[5:0]] <= 1'b1;
7028
        end
7029 49 robfinch
        if (mem2_available && `NUM_MEM > 1 && dramB_v && iqentry_v[ dramB_id[`QBITS] ] && iqentry_load[ dramB_id[`QBITS] ]) begin       // if data for stomped instruction, ignore
7030 48 robfinch
        iqentry_res     [ dramB_id[`QBITS] ] <= dramB_bus;
7031
        iqentry_exc     [ dramB_id[`QBITS] ] <= dramB_exc;
7032
        iqentry_done[ dramB_id[`QBITS] ] <= `VAL;
7033
        iqentry_out [ dramB_id[`QBITS] ] <= `INV;
7034
        iqentry_cmt[ dramB_id[`QBITS] ] <= `VAL;
7035
            iqentry_aq  [ dramB_id[`QBITS] ] <= `INV;
7036
//          if (iqentry_lptr[dram1_id[`QBITS]])
7037
//              wbrcd[pcr[5:0]] <= 1'b1;
7038
        end
7039 49 robfinch
        if (mem3_available && `NUM_MEM > 2 && dramC_v && iqentry_v[ dramC_id[`QBITS] ] && iqentry_load[ dramC_id[`QBITS] ]) begin       // if data for stomped instruction, ignore
7040 48 robfinch
        iqentry_res     [ dramC_id[`QBITS] ] <= dramC_bus;
7041
        iqentry_exc     [ dramC_id[`QBITS] ] <= dramC_exc;
7042
        iqentry_done[ dramC_id[`QBITS] ] <= `VAL;
7043
        iqentry_out [ dramC_id[`QBITS] ] <= `INV;
7044
        iqentry_cmt[ dramC_id[`QBITS] ] <= `VAL;
7045
            iqentry_aq  [ dramC_id[`QBITS] ] <= `INV;
7046
//          if (iqentry_lptr[dram2_id[`QBITS]])
7047
//              wbrcd[pcr[5:0]] <= 1'b1;
7048
        end
7049
 
7050
//
7051
// set the IQ entry == DONE as soon as the SW is let loose to the memory system
7052
//
7053 49 robfinch
if (mem1_available && dram0 == `DRAMSLOT_BUSY && IsStore(dram0_instr)) begin
7054 48 robfinch
        if ((alu0_v && (dram0_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram0_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
7055
        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
7056
        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
7057
end
7058 49 robfinch
if (mem2_available && `NUM_MEM > 1 && dram1 == `DRAMSLOT_BUSY && IsStore(dram1_instr)) begin
7059 48 robfinch
        if ((alu0_v && (dram1_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram1_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
7060
        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
7061
        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
7062
end
7063 49 robfinch
if (mem3_available && `NUM_MEM > 2 && dram2 == `DRAMSLOT_BUSY && IsStore(dram2_instr)) begin
7064 48 robfinch
        if ((alu0_v && (dram2_id[`QBITS] == alu0_id[`QBITS])) || (alu1_v && (dram2_id[`QBITS] == alu1_id[`QBITS])))      panic <= `PANIC_MEMORYRACE;
7065
        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
7066
        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
7067
end
7068
 
7069
//
7070
// see if anybody else wants the results ... look at lots of buses:
7071
//  - fpu_bus
7072
//  - alu0_bus
7073
//  - alu1_bus
7074
//  - fcu_bus
7075
//  - dram_bus
7076
//  - commit0_bus
7077
//  - commit1_bus
7078
//
7079
 
7080
for (n = 0; n < QENTRIES; n = n + 1)
7081
begin
7082 49 robfinch
        if (`NUM_FPU > 0)
7083
                setargs(n,{1'b0,fpu1_id},fpu1_v,fpu1_bus);
7084
        if (`NUM_FPU > 1)
7085
                setargs(n,{1'b0,fpu2_id},fpu2_v,fpu2_bus);
7086
 
7087 48 robfinch
        setargs(n,{1'b0,alu0_id},alu0_v,alu0_bus);
7088 49 robfinch
        if (`NUM_ALU > 1)
7089
                setargs(n,{1'b0,alu1_id},alu1_v,alu1_bus);
7090
 
7091 48 robfinch
        setargs(n,{1'b0,fcu_id},fcu_wr,fcu_bus);
7092 49 robfinch
 
7093 48 robfinch
        setargs(n,{1'b0,dramA_id},dramA_v,dramA_bus);
7094 49 robfinch
        if (`NUM_MEM > 1)
7095
                setargs(n,{1'b0,dramB_id},dramB_v,dramB_bus);
7096
        if (`NUM_MEM > 2)
7097
                setargs(n,{1'b0,dramC_id},dramC_v,dramC_bus);
7098
 
7099 48 robfinch
        setargs(n,commit0_id,commit0_v,commit0_bus);
7100 49 robfinch
        if (`NUM_CMT > 1)
7101
                setargs(n,commit1_id,commit1_v,commit1_bus);
7102 48 robfinch
 
7103
        setinsn(n[`QBITS],id1_ido,id1_available&id1_vo,id1_bus);
7104 49 robfinch
        if (`NUM_IDU > 1)
7105
                setinsn(n[`QBITS],id2_ido,id2_available&id2_vo,id2_bus);
7106
        if (`NUM_IDU > 2)
7107
                setinsn(n[`QBITS],id3_ido,id3_available&id3_vo,id3_bus);
7108 48 robfinch
end
7109
 
7110
//
7111
// ISSUE 
7112
//
7113
// determines what instructions are ready to go, then places them
7114
// in the various ALU queues.  
7115
// also invalidates instructions following a branch-miss BEQ or any JALR (STOMP logic)
7116
//
7117
 
7118
for (n = 0; n < QENTRIES; n = n + 1)
7119
if (id1_available) begin
7120
if (iqentry_id1issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7121
                id1_vi <= `VAL;
7122
                id1_id                  <= n[4:0];
7123
                id1_instr       <= iqentry_rtop[n] ? (
7124
                                                                                iqentry_a3_v[n] ? iqentry_a3[n]
7125 49 robfinch
`ifdef FU_BYPASS
7126 48 robfinch
                                : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7127
                                : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7128 49 robfinch
`endif
7129 48 robfinch
                                : `NOP_INSN)
7130
                                                                 : iqentry_instr[n];
7131
                id1_ven    <= iqentry_ven[n];
7132
                id1_vl     <= iqentry_vl[n];
7133
                id1_thrd   <= iqentry_thrd[n];
7134
                id1_Rt     <= iqentry_tgt[n][4:0];
7135
                id1_pt                  <= iqentry_pt[n];
7136
  end
7137
end
7138 49 robfinch
if (`NUM_IDU > 1) begin
7139 48 robfinch
for (n = 0; n < QENTRIES; n = n + 1)
7140 49 robfinch
        if (id2_available) begin
7141
                if (iqentry_id2issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7142
                        id2_vi <= `VAL;
7143
                        id2_id                  <= n[4:0];
7144
                        id2_instr       <= iqentry_rtop[n] ? (
7145
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7146
`ifdef FU_BYPASS
7147
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7148
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7149
`endif
7150
                                        : `NOP_INSN)
7151
                                                                         : iqentry_instr[n];
7152
                        id2_ven    <= iqentry_ven[n];
7153
                        id2_vl     <= iqentry_vl[n];
7154
                        id2_thrd   <= iqentry_thrd[n];
7155
                        id2_Rt     <= iqentry_tgt[n][4:0];
7156
                        id2_pt                  <= iqentry_pt[n];
7157
                end
7158 48 robfinch
        end
7159
end
7160 49 robfinch
if (`NUM_IDU > 2) begin
7161
for (n = 0; n < QENTRIES; n = n + 1)
7162
        if (id3_available) begin
7163
                if (iqentry_id3issue[n] && !iqentry_iv[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7164
                        id3_vi <= `VAL;
7165
                        id3_id                  <= n[4:0];
7166
                        id3_instr       <= iqentry_rtop[n] ? (
7167
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7168
`ifdef FU_BYPASS
7169
                                        : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7170
                                        : (iqentry_a3_s[n] == alu1_id) ? alu1_bus
7171
`endif
7172
                                        : `NOP_INSN)
7173
                                                                         : iqentry_instr[n];
7174
                        id3_ven    <= iqentry_ven[n];
7175
                        id3_vl     <= iqentry_vl[n];
7176
                        id3_thrd   <= iqentry_thrd[n];
7177
                        id3_Rt     <= iqentry_tgt[n][4:0];
7178
                        id3_pt                  <= iqentry_pt[n];
7179
                end
7180
        end
7181
end
7182 48 robfinch
 
7183
    for (n = 0; n < QENTRIES; n = n + 1)
7184
        if (iqentry_alu0_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7185
            if (alu0_available & alu0_done) begin
7186
                 alu0_sourceid  <= n[3:0];
7187
                 alu0_instr     <= iqentry_rtop[n] ? (
7188 49 robfinch
`ifdef FU_BYPASS
7189 48 robfinch
                                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7190 49 robfinch
                                                    : (iqentry_a3_s[n] == alu0_id) ? alu0_bus
7191
                                                    : (iqentry_a3_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7192
                                                    : alu1_bus)
7193
`else
7194
                                                                                                                                        iqentry_a3[n])
7195
`endif
7196 48 robfinch
                                                                         : iqentry_instr[n];
7197
                 alu0_bt                <= iqentry_bt[n];
7198
                 alu0_mem   <= iqentry_mem[n];
7199
                 alu0_shft48 <= iqentry_shft48[n];
7200
                 alu0_pc                <= iqentry_pc[n];
7201 49 robfinch
                 alu0_argA      <=
7202
`ifdef FU_BYPASS
7203
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7204
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7205
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7206
                            : alu1_bus;
7207
`else
7208
                                                                                                                iqentry_a1[n];
7209
`endif
7210 48 robfinch
                 alu0_argB      <= iqentry_imm[n]
7211
                            ? iqentry_a0[n]
7212 49 robfinch
`ifdef FU_BYPASS
7213 48 robfinch
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7214 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7215
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7216
                            : alu1_bus);
7217
`else
7218
                                                                                                                : iqentry_a2[n];
7219
`endif
7220
                 alu0_argC      <=
7221
`ifdef FU_BYPASS
7222
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7223 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7224 49 robfinch
`else
7225
                                                                                                                        iqentry_a3[n];
7226
`endif
7227 48 robfinch
                 alu0_argI      <= iqentry_a0[n];
7228
                 alu0_tgt    <= IsVeins(iqentry_instr[n]) ?
7229 49 robfinch
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((
7230
                                                                                        iqentry_a2_v[n] ? iqentry_a2[n][5:0]
7231 48 robfinch
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
7232
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
7233
                                            : {4{16'h0000}})) << 6 :
7234
                                iqentry_tgt[n];
7235
                 alu0_ven    <= iqentry_ven[n];
7236
                 alu0_thrd   <= iqentry_thrd[n];
7237
                 alu0_dataready <= IsSingleCycle(iqentry_instr[n]);
7238
                 alu0_ld <= TRUE;
7239
                 iqentry_out[n] <= `VAL;
7240
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
7241
                if (iqentry_mem[n]) begin
7242
                 iqentry_a1_v[n] <= `INV;
7243
                 iqentry_a1_s[n] <= n[3:0];
7244
                end
7245
            end
7246
        end
7247 49 robfinch
        if (`NUM_ALU > 1) begin
7248 48 robfinch
    for (n = 0; n < QENTRIES; n = n + 1)
7249
        if (iqentry_alu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7250
            if (alu1_available && alu1_done) begin
7251
                        if (iqentry_alu0[n])
7252
                                panic <= `PANIC_ALU0ONLY;
7253
                 alu1_sourceid  <= n[3:0];
7254
                 alu1_instr     <= iqentry_instr[n];
7255
                 alu1_bt                <= iqentry_bt[n];
7256
                 alu1_mem   <= iqentry_mem[n];
7257
                 alu1_shft48 <= iqentry_shft48[n];
7258
                 alu1_pc                <= iqentry_pc[n];
7259 49 robfinch
                 alu1_argA      <=
7260
`ifdef FU_BYPASS
7261
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7262
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7263
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7264
                            : alu1_bus;
7265
`else
7266
                                                                                                                        iqentry_a1[n];
7267
`endif
7268 48 robfinch
                 alu1_argB      <= iqentry_imm[n]
7269
                            ? iqentry_a0[n]
7270 49 robfinch
`ifdef FU_BYPASS
7271 48 robfinch
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7272 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7273
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7274
                            : alu1_bus);
7275
`else
7276
                                                                                                                : iqentry_a2[n];
7277
`endif
7278
                 alu1_argC      <=
7279
`ifdef FU_BYPASS
7280
                                                                        iqentry_a3_v[n] ? iqentry_a3[n]
7281 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7282 49 robfinch
`else
7283
                                                                                                                        iqentry_a3[n];
7284
`endif
7285 48 robfinch
                 alu1_argI      <= iqentry_a0[n];
7286
                 alu1_tgt    <= IsVeins(iqentry_instr[n]) ?
7287
                                {6'h0,1'b1,iqentry_tgt[n][4:0]} | ((iqentry_a2_v[n] ? iqentry_a2[n][5:0]
7288
                                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus[5:0]
7289
                                            : (iqentry_a2_s[n] == alu1_id) ? alu1_bus[5:0]
7290
                                            : {4{16'h0000}})) << 6 :
7291
                                iqentry_tgt[n];
7292
                 alu1_ven    <= iqentry_ven[n];
7293
                 alu1_dataready <= IsSingleCycle(iqentry_instr[n]);
7294
                 alu1_ld <= TRUE;
7295
                 iqentry_out[n] <= `VAL;
7296
                // if it is a memory operation, this is the address-generation step ... collect result into arg1
7297
                if (iqentry_mem[n]) begin
7298
                 iqentry_a1_v[n] <= `INV;
7299
                 iqentry_a1_s[n] <= n[3:0];
7300
                end
7301
            end
7302
        end
7303 49 robfinch
  end
7304 48 robfinch
 
7305
    for (n = 0; n < QENTRIES; n = n + 1)
7306 49 robfinch
        if (iqentry_fpu1_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7307
            if (fpu1_available & fpu1_done) begin
7308
                 fpu1_sourceid  <= n[3:0];
7309
                 fpu1_instr     <= iqentry_instr[n];
7310
                 fpu1_pc                <= iqentry_pc[n];
7311
                 fpu1_argA      <=
7312
`ifdef FU_BYPASS
7313
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7314
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7315
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7316
                            : alu1_bus;
7317
`else
7318
                                                                                                                        iqentry_a1[n];
7319
`endif
7320
                 fpu1_argB      <=
7321
`ifdef FU_BYPASS
7322
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
7323
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7324
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7325
                            : alu1_bus);
7326
`else
7327
                                                                                                                        iqentry_a2[n];
7328
`endif
7329
                 fpu1_argC      <=
7330
`ifdef FU_BYPASS
7331
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
7332 48 robfinch
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7333 49 robfinch
`else
7334
                                                                                                                        iqentry_a3[n];
7335
`endif
7336
                 fpu1_argI      <= iqentry_a0[n];
7337
                 fpu1_dataready <= `VAL;
7338
                 fpu1_ld <= TRUE;
7339 48 robfinch
                 iqentry_out[n] <= `VAL;
7340
            end
7341
        end
7342
 
7343
    for (n = 0; n < QENTRIES; n = n + 1)
7344 49 robfinch
        if (`NUM_FPU > 1 && iqentry_fpu2_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7345
            if (fpu2_available & fpu2_done) begin
7346
                 fpu2_sourceid  <= n[3:0];
7347
                 fpu2_instr     <= iqentry_instr[n];
7348
                 fpu2_pc                <= iqentry_pc[n];
7349
                 fpu2_argA      <=
7350
`ifdef FU_BYPASS
7351
                                                                        iqentry_a1_v[n] ? iqentry_a1[n]
7352
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7353
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7354
                            : alu1_bus;
7355
`else
7356
                                                                                                                        iqentry_a1[n];
7357
`endif
7358
                 fpu2_argB      <=
7359
`ifdef FU_BYPASS
7360
                                                                        (iqentry_a2_v[n] ? iqentry_a2[n]
7361
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7362
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7363
                            : alu1_bus);
7364
`else
7365
                                                                                                                        iqentry_a2[n];
7366
`endif
7367
                 fpu2_argC      <=
7368
`ifdef FU_BYPASS
7369
                                                                         iqentry_a3_v[n] ? iqentry_a3[n]
7370
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7371
`else
7372
                                                                                                                        iqentry_a3[n];
7373
`endif
7374
                 fpu2_argI      <= iqentry_a0[n];
7375
                 fpu2_dataready <= `VAL;
7376
                 fpu2_ld <= TRUE;
7377
                 iqentry_out[n] <= `VAL;
7378
            end
7379
        end
7380
 
7381
    for (n = 0; n < QENTRIES; n = n + 1)
7382 48 robfinch
        if (iqentry_fcu_issue[n] && !(iqentry_v[n] && iqentry_stomp[n])) begin
7383
            if (fcu_done) begin
7384
                 fcu_sourceid   <= n[3:0];
7385
                 fcu_instr      <= iqentry_instr[n];
7386
                 fcu_insln  <= iqentry_insln[n];
7387
                 fcu_pc         <= iqentry_pc[n];
7388
                 fcu_nextpc <= iqentry_pc[n] + iqentry_insln[n];
7389
                 fcu_brdisp <= {{52{iqentry_instr[n][31]}},iqentry_instr[n][31:21],1'b0};
7390
                 fcu_call    <= IsCall(iqentry_instr[n])|IsJAL(iqentry_instr[n]);
7391
                 fcu_bt         <= iqentry_bt[n];
7392
                 fcu_pc         <= iqentry_pc[n];
7393
                 fcu_argA       <= iqentry_a1_v[n] ? iqentry_a1[n]
7394 49 robfinch
                            : (iqentry_a1_s[n] == alu0_id) ? alu0_bus
7395
                            : (iqentry_a1_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7396
                            : alu1_bus;
7397 48 robfinch
`ifdef SUPPORT_SMT
7398
                 fcu_argB       <= IsRTI(iqentry_instr[n]) ? epc0[iqentry_thrd[n]]
7399
`else
7400
                 fcu_argB       <= IsRTI(iqentry_instr[n]) ? epc0
7401
`endif
7402
                                        : (iqentry_a2_v[n] ? iqentry_a2[n]
7403 49 robfinch
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus
7404
                            : (iqentry_a2_s[n] == fpu1_id && `NUM_FPU > 0) ? fpu1_bus
7405
                            : alu1_bus);
7406 48 robfinch
                 waitctr            <= iqentry_imm[n]
7407
                            ? iqentry_a0[n]
7408
                            : (iqentry_a2_v[n] ? iqentry_a2[n]
7409
                            : (iqentry_a2_s[n] == alu0_id) ? alu0_bus : alu1_bus);
7410
                 fcu_argC       <= iqentry_a3_v[n] ? iqentry_a3[n]
7411
                            : (iqentry_a3_s[n] == alu0_id) ? alu0_bus : alu1_bus;
7412
                 fcu_argI       <= iqentry_a0[n];
7413
                 fcu_thrd   <= iqentry_thrd[n];
7414
                 fcu_dataready <= `VAL;
7415
                 fcu_clearbm <= `FALSE;
7416
                 fcu_retadr_v <= `INV;
7417
                 fcu_ld <= TRUE;
7418
                 fcu_timeout <= 8'h00;
7419
                 iqentry_out[n] <= `VAL;
7420
                 fcu_done <= `FALSE;
7421
            end
7422
        end
7423
//
7424
// MEMORY
7425
//
7426
// update the memory queues and put data out on bus if appropriate
7427
//
7428
 
7429
//
7430
// dram0, dram1, dram2 are the "state machines" that keep track
7431
// of three pipelined DRAM requests.  if any has the value "00", 
7432
// then it can accept a request (which bumps it up to the value "01"
7433
// at the end of the cycle).  once it hits the value "11" the request
7434
// is finished and the dram_bus takes the value.  if it is a store, the 
7435
// dram_bus value is not used, but the dram_v value along with the
7436
// dram_id value signals the waiting memq entry that the store is
7437
// completed and the instruction can commit.
7438
//
7439
 
7440
//      if (dram0 != `DRAMSLOT_AVAIL)   dram0 <= dram0 + 2'd1;
7441
//      if (dram1 != `DRAMSLOT_AVAIL)   dram1 <= dram1 + 2'd1;
7442
//      if (dram2 != `DRAMSLOT_AVAIL)   dram2 <= dram2 + 2'd1;
7443
 
7444
//
7445
// grab requests that have finished and put them on the dram_bus
7446 49 robfinch
if (mem1_available && dram0 == `DRAMREQ_READY) begin
7447 48 robfinch
        dram0 <= `DRAMSLOT_AVAIL;
7448
        dramA_v <= dram0_load;
7449
        dramA_id <= dram0_id;
7450
        dramA_exc <= dram0_exc;
7451
        dramA_bus <= fnDati(dram0_instr,dram0_addr,rdat0);
7452
        if (IsStore(dram0_instr))       $display("m[%h] <- %h", dram0_addr, dram0_data);
7453
end
7454
//    else
7455
//      dramA_v <= `INV;
7456 49 robfinch
if (mem2_available && dram1 == `DRAMREQ_READY && `NUM_MEM > 1) begin
7457 48 robfinch
        dram1 <= `DRAMSLOT_AVAIL;
7458
        dramB_v <= dram1_load;
7459
        dramB_id <= dram1_id;
7460
        dramB_exc <= dram1_exc;
7461
        dramB_bus <= fnDati(dram1_instr,dram1_addr,rdat1);
7462
        if (IsStore(dram1_instr))     $display("m[%h] <- %h", dram1_addr, dram1_data);
7463
end
7464
//    else
7465
//      dramB_v <= `INV;
7466 49 robfinch
if (mem3_available && dram2 == `DRAMREQ_READY && `NUM_MEM > 2) begin
7467 48 robfinch
        dram2 <= `DRAMSLOT_AVAIL;
7468
        dramC_v <= dram2_load;
7469
        dramC_id <= dram2_id;
7470
        dramC_exc <= dram2_exc;
7471
        dramC_bus <= fnDati(dram2_instr,dram2_addr,rdat2);
7472
        if (IsStore(dram2_instr))     $display("m[%h] <- %h", dram2_addr, dram2_data);
7473
end
7474
//    else
7475
//      dramC_v <= `INV;
7476
 
7477
        //
7478
        // determine if the instructions ready to issue can, in fact, issue.
7479
        // "ready" means that the instruction has valid operands but has not gone yet
7480
        iqentry_memissue <= memissue;
7481
        missue_count <= issue_count;
7482
 
7483
 
7484
        //
7485
        // take requests that are ready and put them into DRAM slots
7486
 
7487
        if (dram0 == `DRAMSLOT_AVAIL)    dram0_exc <= `FLT_NONE;
7488
        if (dram1 == `DRAMSLOT_AVAIL)    dram1_exc <= `FLT_NONE;
7489
        if (dram2 == `DRAMSLOT_AVAIL)    dram2_exc <= `FLT_NONE;
7490
 
7491
        for (n = 0; n < QENTRIES; n = n + 1)
7492
                if (iqentry_v[n] && iqentry_stomp[n]) begin
7493
                        iqentry_v[n] <= `INV;
7494
                        iqentry_iv[n] <= `INV;
7495
                        if (dram0_id[`QBITS] == n[`QBITS])  dram0 <= `DRAMSLOT_AVAIL;
7496
                        if (dram1_id[`QBITS] == n[`QBITS])  dram1 <= `DRAMSLOT_AVAIL;
7497
                        if (dram2_id[`QBITS] == n[`QBITS])  dram2 <= `DRAMSLOT_AVAIL;
7498
                end
7499
 
7500
        last_issue = 8;
7501
    for (n = 0; n < QENTRIES; n = n + 1)
7502 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7503
            if (mem1_available && dram0 == `DRAMSLOT_AVAIL) begin
7504 48 robfinch
                dramA_v <= `INV;
7505
             dram0              <= `DRAMSLOT_BUSY;
7506
             dram0_id   <= { 1'b1, n[`QBITS] };
7507
             dram0_instr <= iqentry_instr[n];
7508
             dram0_rmw  <= iqentry_rmw[n];
7509
             dram0_preload <= iqentry_preload[n];
7510
             dram0_tgt  <= iqentry_tgt[n];
7511
             dram0_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7512
             dram0_addr <= iqentry_a1[n];
7513
//             if (ol[iqentry_thrd[n]]==`OL_USER)
7514
//              dram0_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7515
//             else
7516
             dram0_unc   <= iqentry_a1[n][31:20]==12'hFFD || !dce || IsVolatileLoad(iqentry_instr[n]);
7517
             dram0_memsize <= MemSize(iqentry_instr[n]);
7518
             dram0_load <= iqentry_load[n];
7519
             dram0_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
7520
             // Once the memory op is issued reset the a1_v flag.
7521
             // This will cause the a1 bus to look for new data from memory (a1_s is pointed to a memory bus)
7522
             // This is used for the load and compare instructions.
7523
             iqentry_a1_v[n] <= `INV;
7524
             last_issue = n;
7525
            end
7526
        end
7527
    if (last_issue < 8)
7528
        iqentry_out[last_issue] <= `VAL;
7529
    for (n = 0; n < QENTRIES; n = n + 1)
7530 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7531
                if (mem2_available && n < last_issue && `NUM_MEM > 1) begin
7532 48 robfinch
                    if (dram1 == `DRAMSLOT_AVAIL) begin
7533
                        dramB_v <= `INV;
7534
                     dram1              <= `DRAMSLOT_BUSY;
7535
                     dram1_id   <= { 1'b1, n[`QBITS] };
7536
                     dram1_instr <= iqentry_instr[n];
7537
                     dram1_rmw  <= iqentry_rmw[n];
7538
                     dram1_preload <= iqentry_preload[n];
7539
                     dram1_tgt  <= iqentry_tgt[n];
7540
                     dram1_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7541
                     dram1_addr <= iqentry_a1[n];
7542
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
7543
//                      dram1_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7544
//                   else
7545
                     dram1_unc   <= iqentry_a1[n][31:20]==12'hFFD || !dce || IsVolatileLoad(iqentry_instr[n]);
7546
                     dram1_memsize <= MemSize(iqentry_instr[n]);
7547
                     dram1_load <= iqentry_load[n];
7548
                     dram1_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
7549
                     iqentry_a1_v[n] <= `INV;
7550
                     last_issue = n;
7551
                    end
7552
                end
7553
        end
7554
    if (last_issue < 8)
7555
        iqentry_out[last_issue] <= `VAL;
7556
    for (n = 0; n < QENTRIES; n = n + 1)
7557 49 robfinch
        if (~iqentry_stomp[n] && iqentry_memissue[n] && iqentry_agen[n] && ~iqentry_out[n] && ~iqentry_done[n]) begin
7558
                if (mem3_available && n < last_issue && `NUM_MEM > 2) begin
7559 48 robfinch
                    if (dram2 == `DRAMSLOT_AVAIL) begin
7560
                        dramC_v <= `INV;
7561
                     dram2              <= `DRAMSLOT_BUSY;
7562
                     dram2_id   <= { 1'b1, n[`QBITS] };
7563
                     dram2_instr        <= iqentry_instr[n];
7564
                     dram2_rmw  <= iqentry_rmw[n];
7565
                     dram2_preload <= iqentry_preload[n];
7566
                     dram2_tgt  <= iqentry_tgt[n];
7567
                     dram2_data <= iqentry_memndx[n] ? iqentry_a3[n] : iqentry_a2[n];
7568
                     dram2_addr <= iqentry_a1[n];
7569
//                   if (ol[iqentry_thrd[n]]==`OL_USER)
7570
//                      dram2_seg   <= (iqentry_Ra[n]==5'd30 || iqentry_Ra[n]==5'd31) ? {ss[iqentry_thrd[n]],13'd0} : {ds[iqentry_thrd[n]],13'd0};
7571
//                   else
7572
                     dram2_unc   <= iqentry_a1[n][31:20]==12'hFFD || !dce || IsVolatileLoad(iqentry_instr[n]);
7573
                     dram2_memsize <= MemSize(iqentry_instr[n]);
7574
                     dram2_load <= iqentry_load[n];
7575
                     dram2_ol   <= (iqentry_Ra[n][4:0]==5'd31 || iqentry_Ra[n][4:0]==5'd30) ? ol[iqentry_thrd[n]] : dl[iqentry_thrd[n]];
7576
                     iqentry_a1_v[n] <= `INV;
7577
                    end
7578
                end
7579
        end
7580
    if (last_issue < 8)
7581
        iqentry_out[last_issue] <= `VAL;
7582
 
7583
    // It's better to check a sequence number here because if the code is in a
7584
    // loop that such that the previous iteration of the loop is still in the
7585
    // queue the PC could match when we don;t really want a prefix for that
7586
    // iteration.
7587
    for (n = 0; n < QENTRIES; n = n + 1)
7588
    begin
7589
        if (!iqentry_v[n])
7590
             iqentry_done[n] <= FALSE;
7591
    end
7592
 
7593
 
7594
 
7595 49 robfinch
//
7596
// COMMIT PHASE (dequeue only ... not register-file update)
7597
//
7598
// look at head0 and head1 and let 'em write to the register file if they are ready
7599
//
7600 48 robfinch
//    always @(posedge clk) begin: commit_phase
7601
 
7602 49 robfinch
oddball_commit(commit0_v, head0);
7603
if (`NUM_CMT > 1)
7604
        oddball_commit(commit1_v, head1);
7605 48 robfinch
 
7606
// Fetch and queue are limited to two instructions per cycle, so we might as
7607
// well limit retiring to two instructions max to conserve logic.
7608
//
7609
if (~|panic)
7610 49 robfinch
  casez ({ iqentry_v[head0],
7611
                iqentry_cmt[head0],
7612
                iqentry_v[head1],
7613
                iqentry_cmt[head1],
7614
                iqentry_v[head2],
7615
                iqentry_cmt[head2]})
7616 48 robfinch
 
7617
        // retire 3
7618 49 robfinch
        6'b0?_0?_0?:
7619
                if (head0 != tail0 && head1 != tail0 && head2 != tail0) begin
7620
                                head_inc(3);
7621
                end
7622
                else if (head0 != tail0 && head1 != tail0) begin
7623 48 robfinch
                    head_inc(2);
7624
                end
7625
                else if (head0 != tail0) begin
7626
                    head_inc(1);
7627
                end
7628 49 robfinch
        6'b0?_0?_10:    ;
7629
        6'b0?_0?_11:
7630
                if (`NUM_CMT > 2 || iqentry_tgt[head2][4:0]==5'd0) begin
7631
      iqentry_v[head2] <= `INV;
7632
      head_inc(3);
7633
                end
7634
                else begin
7635
      head_inc(2);
7636
                end
7637 48 robfinch
 
7638
        // retire 1 (wait for regfile for head1)
7639 49 robfinch
        6'b0?_10_??:
7640
                head_inc(1);
7641 48 robfinch
 
7642
        // retire 2
7643 49 robfinch
        6'b0?_11_0?,
7644
        6'b0?_11_10:
7645
        if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7646
          iqentry_v[head1] <= `INV;
7647
          head_inc(2);
7648 48 robfinch
        end
7649 49 robfinch
        else begin
7650
                head_inc(1);
7651
        end
7652
  6'b0?_11_11:
7653
        if (`NUM_CMT > 2 || (`NUM_CMT > 1 && iqentry_tgt[head2] == 12'd0)) begin
7654
                iqentry_v[head1] <= `INV;
7655
          iqentry_v[head2] <= `INV;
7656
                head_inc(3);
7657
        end
7658
        else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7659
                iqentry_v[head1] <= `INV;
7660
                head_inc(2);
7661
        end
7662
        else
7663
                head_inc(1);
7664
  6'b10_??_??:  ;
7665
  6'b11_0?_0?:
7666
        if (head1 != tail0 && head2 != tail0) begin
7667 48 robfinch
                        iqentry_v[head0] <= `INV;
7668 49 robfinch
                        head_inc(3);
7669
        end
7670
        else if (head1 != tail0) begin
7671
                        iqentry_v[head0] <= `INV;
7672 48 robfinch
                        head_inc(2);
7673 49 robfinch
        end
7674
        else begin
7675 48 robfinch
                        iqentry_v[head0] <= `INV;
7676
                        head_inc(1);
7677 49 robfinch
        end
7678
  6'b11_0?_10:
7679
        if (head1 != tail0) begin
7680
                        iqentry_v[head0] <= `INV;
7681
                        head_inc(2);
7682
        end
7683
        else begin
7684
                        iqentry_v[head0] <= `INV;
7685
                        head_inc(1);
7686
        end
7687
  6'b11_0?_11:
7688
        if (head1 != tail0) begin
7689
                if (`NUM_CMT > 2 || iqentry_tgt[head2]==12'd0) begin
7690
                                iqentry_v[head0] <= `INV;
7691
                                iqentry_v[head2] <= `INV;
7692
                                head_inc(3);
7693
                end
7694
                else begin
7695
                                iqentry_v[head0] <= `INV;
7696
                                head_inc(2);
7697
                        end
7698
        end
7699
        else begin
7700
                        iqentry_v[head0] <= `INV;
7701
                        head_inc(1);
7702
        end
7703
  6'b11_10_??:
7704
        begin
7705
                        iqentry_v[head0] <= `INV;
7706
                        head_inc(1);
7707
        end
7708
  6'b11_11_0?:
7709
        if (`NUM_CMT > 1 && head2 != tail0) begin
7710
                        iqentry_v[head0] <= `INV;
7711
                        iqentry_v[head1] <= `INV;
7712
                        head_inc(3);
7713
        end
7714
        else if (iqentry_tgt[head1]== 12'd0 && head2 != tail0) begin
7715
                        iqentry_v[head0] <= `INV;
7716
                        iqentry_v[head1] <= `INV;
7717
                        head_inc(3);
7718
        end
7719
        else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7720
                        iqentry_v[head0] <= `INV;
7721
                        iqentry_v[head1] <= `INV;
7722
                        head_inc(2);
7723
        end
7724
        else begin
7725
                        iqentry_v[head0] <= `INV;
7726
                        head_inc(1);
7727
        end
7728
  6'b11_11_10:
7729
        if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7730
                        iqentry_v[head0] <= `INV;
7731
                        iqentry_v[head1] <= `INV;
7732
                        head_inc(2);
7733
        end
7734
        else begin
7735
                        iqentry_v[head0] <= `INV;
7736
                        head_inc(1);
7737
        end
7738
        6'b11_11_11:
7739
                if (`NUM_CMT > 2 || (`NUM_CMT > 1 && iqentry_tgt[head2]==12'd0)) begin
7740
                        iqentry_v[head0] <= `INV;
7741
                        iqentry_v[head1] <= `INV;
7742
                        iqentry_v[head2] <= `INV;
7743
                        head_inc(3);
7744 48 robfinch
                end
7745 49 robfinch
                else if (`NUM_CMT > 1 || iqentry_tgt[head1]==12'd0) begin
7746 48 robfinch
                        iqentry_v[head0] <= `INV;
7747 49 robfinch
                        iqentry_v[head1] <= `INV;
7748
                        head_inc(2);
7749
                end
7750
                else begin
7751
                        iqentry_v[head0] <= `INV;
7752 48 robfinch
                        head_inc(1);
7753
                end
7754 49 robfinch
  endcase
7755 48 robfinch
 
7756
 
7757
        rf_source[0] <= 0;
7758
        L1_wr0 <= FALSE;
7759
        L1_wr1 <= FALSE;
7760
        L1_invline <= FALSE;
7761
        icnxt <= FALSE;
7762
        L2_nxt <= FALSE;
7763
// Instruction cache state machine.
7764
// On a miss first see if the instruction is in the L2 cache. No need to go to
7765
// the BIU on an L1 miss.
7766
// If not the machine will wait until the BIU loads the L2 cache.
7767
 
7768
// Capture the previous ic state, used to determine how long to wait in
7769
// icstate #4.
7770
        picstate <= icstate;
7771
case(icstate)
7772
IDLE:
7773
        // If the bus unit is busy doing an update involving L1_adr or L2_adr
7774
        // we have to wait.
7775
        if (bstate != B7 && bstate != B9) begin
7776
                if (!ihit0) begin
7777
                        L1_adr <= {pcr[5:0],pc0[31:3],3'h0};
7778
                        L2_adr <= {pcr[5:0],pc0[31:3],3'h0};
7779
                        L1_invline <= TRUE;
7780 49 robfinch
                        icwhich <= 2'b00;
7781 48 robfinch
                        iccnt <= 3'b00;
7782
                        icstate <= IC2;
7783
                end
7784 49 robfinch
                else if (!ihit1 && `WAYS > 1) begin
7785 48 robfinch
`ifdef SUPPORT_SMT
7786
                        L1_adr <= {pcr[5:0],pc1[31:3],3'h0};
7787
                        L2_adr <= {pcr[5:0],pc1[31:3],3'h0};
7788
`else
7789
                        L1_adr <= {pcr[5:0],pc0plus6[31:3],3'h0};
7790
                        L2_adr <= {pcr[5:0],pc0plus6[31:3],3'h0};
7791
`endif
7792
                        L1_invline <= TRUE;
7793 49 robfinch
                        icwhich <= 2'b01;
7794 48 robfinch
                        iccnt <= 3'b00;
7795
                        icstate <= IC2;
7796
                end
7797 49 robfinch
                else if (!ihit2 && `WAYS > 2) begin
7798
`ifdef SUPPORT_SMT
7799
                        L1_adr <= {pcr[5:0],pc2[31:3],3'h0};
7800
                        L2_adr <= {pcr[5:0],pc2[31:3],3'h0};
7801
`else
7802
                        L1_adr <= {pcr[5:0],pc0plus12[31:3],3'h0};
7803
                        L2_adr <= {pcr[5:0],pc0plus12[31:3],3'h0};
7804
`endif
7805
                        L1_invline <= TRUE;
7806
                        icwhich <= 2'b10;
7807
                        iccnt <= 3'b00;
7808
                        icstate <= IC2;
7809
                end
7810 48 robfinch
        end
7811
IC2:     icstate <= IC3;
7812
IC3:     icstate <= IC3a;
7813
IC3a:     icstate <= IC4;
7814
        // If data was in the L2 cache already there's no need to wait on the
7815
        // BIU to retrieve data. It can be determined if the hit signal was
7816
        // already active when this state was entered in which case waiting
7817
        // will do no good.
7818
        // The IC machine will stall in this state until the BIU has loaded the
7819
        // L2 cache. 
7820
IC4:
7821 49 robfinch
        if (ihitL2 && picstate==IC3a) begin
7822
                L1_en <= 9'h1FF;
7823 48 robfinch
                L1_wr0 <= TRUE;
7824 49 robfinch
                L1_wr1 <= TRUE && `WAYS > 1;
7825
                L1_wr2 <= TRUE && `WAYS > 2;
7826 48 robfinch
                L1_adr <= L2_adr;
7827
                L2_rdat <= L2_dato;
7828
                icstate <= IC5;
7829
        end
7830
        else if (bstate!=B9)
7831
                ;
7832
        else begin
7833 49 robfinch
                L1_en <= 9'h1FF;
7834 48 robfinch
                L1_wr0 <= TRUE;
7835 49 robfinch
                L1_wr1 <= TRUE && `WAYS > 1;
7836
                L1_wr2 <= TRUE && `WAYS > 2;
7837 48 robfinch
                L1_adr <= L2_adr;
7838
                L2_rdat <= L2_dato;
7839
                icstate <= IC5;
7840
        end
7841
IC5:
7842
        begin
7843 49 robfinch
                L1_en <= 9'h000;
7844 48 robfinch
                L1_wr0 <= FALSE;
7845
                L1_wr1 <= FALSE;
7846 49 robfinch
                L1_wr2 <= FALSE;
7847 48 robfinch
                icstate <= IC6;
7848
        end
7849
IC6:  icstate <= IC7;
7850
IC7:    icstate <= IC8;
7851
IC8:    begin
7852
             icstate <= IDLE;
7853
             icnxt <= TRUE;
7854
        end
7855
default:     icstate <= IDLE;
7856
endcase
7857
 
7858 49 robfinch
if (mem1_available && dram0_load)
7859 48 robfinch
case(dram0)
7860
`DRAMSLOT_AVAIL:        ;
7861
`DRAMSLOT_BUSY:         dram0 <= dram0 + !dram0_unc;
7862
3'd2:                           dram0 <= dram0 + 3'd1;
7863
3'd3:                           dram0 <= dram0 + 3'd1;
7864
3'd4:                           if (dhit0) dram0 <= `DRAMREQ_READY; else dram0 <= `DRAMSLOT_REQBUS;
7865
`DRAMSLOT_REQBUS:       ;
7866
`DRAMSLOT_HASBUS:       ;
7867
`DRAMREQ_READY:         ;
7868
endcase
7869
 
7870 49 robfinch
if (mem2_available && dram1_load && `NUM_MEM > 1)
7871 48 robfinch
case(dram1)
7872
`DRAMSLOT_AVAIL:        ;
7873
`DRAMSLOT_BUSY:         dram1 <= dram1 + !dram1_unc;
7874
3'd2:                           dram1 <= dram1 + 3'd1;
7875
3'd3:                           dram1 <= dram1 + 3'd1;
7876
3'd4:                           if (dhit1) dram1 <= `DRAMREQ_READY; else dram1 <= `DRAMSLOT_REQBUS;
7877
`DRAMSLOT_REQBUS:       ;
7878
`DRAMSLOT_HASBUS:       ;
7879
`DRAMREQ_READY:         ;
7880
endcase
7881
 
7882 49 robfinch
if (mem3_available && dram2_load && `NUM_MEM > 2)
7883 48 robfinch
case(dram2)
7884
`DRAMSLOT_AVAIL:        ;
7885
`DRAMSLOT_BUSY:         dram2 <= dram2 + !dram2_unc;
7886
3'd2:                           dram2 <= dram2 + 3'd1;
7887
3'd3:                           dram2 <= dram2 + 3'd1;
7888
3'd4:                           if (dhit2) dram2 <= `DRAMREQ_READY; else dram2 <= `DRAMSLOT_REQBUS;
7889
`DRAMSLOT_REQBUS:       ;
7890
`DRAMSLOT_HASBUS:       ;
7891
`DRAMREQ_READY:         ;
7892
endcase
7893
 
7894
// Bus Interface Unit (BIU)
7895
// Interfaces to the external bus which is WISHBONE compatible.
7896
// Stores take precedence over other operations.
7897
// Next data cache read misses are serviced.
7898
// Uncached data reads are serviced.
7899
// Finally L2 instruction cache misses are serviced.
7900
 
7901
case(bstate)
7902
BIDLE:
7903 49 robfinch
        begin
7904
                isCAS <= FALSE;
7905
                isAMO <= FALSE;
7906
                isInc <= FALSE;
7907
                isSpt <= FALSE;
7908
                isRMW <= FALSE;
7909
                rdvq <= 1'b0;
7910
                errq <= 1'b0;
7911
                exvq <= 1'b0;
7912
                bwhich <= 2'b00;
7913
                preload <= FALSE;
7914
`ifdef HAS_WB
7915
                if (wb_v[0] & wb_en) begin
7916
                        cyc_o <= `HIGH;
7917
                        stb_o <= `HIGH;
7918
                        we_o <= `HIGH;
7919
                        sel_o <= wb_sel[0];
7920
                        adr_o <= wb_addr[0];
7921
                        dat_o <= wb_data[0];
7922
                        ol_o  <= wb_ol[0];
7923
                        wbo_id <= wb_id[0];
7924
                        bstate <= wb_rmw[0] ? B12 : B1;
7925
                end
7926
                begin
7927
                        for (j = 1; j < `WB_DEPTH; j = j + 1) begin
7928
                wb_v[j-1] <= wb_v[j];
7929
                wb_id[j-1] <= wb_id[j];
7930
                wb_rmw[j-1] <= wb_rmw[j];
7931
                wb_sel[j-1] <= wb_sel[j];
7932
                wb_addr[j-1] <= wb_addr[j];
7933
                wb_data[j-1] <= wb_data[j];
7934
                wb_ol[j-1] <= wb_ol[j];
7935
        end
7936
        wb_v[`WB_DEPTH-1] <= `INV;
7937
        wb_rmw[`WB_DEPTH-1] <= `FALSE;
7938
    end
7939
 
7940
//                      if (|wb_v)
7941
//                              ;
7942
 //       else
7943
`endif
7944
      if (~|wb_v && mem1_available && dram0==`DRAMSLOT_BUSY && dram0_rmw) begin
7945 48 robfinch
`ifdef SUPPORT_DBG
7946
            if (dbg_smatch0|dbg_lmatch0) begin
7947
                 dramA_v <= `TRUE;
7948
                 dramA_id <= dram0_id;
7949
                 dramA_exc <= `FLT_DBG;
7950
                 dramA_bus <= 64'h0;
7951
                 dram0 <= `DRAMSLOT_AVAIL;
7952
            end
7953
            else
7954
`endif
7955
            begin
7956
                 isRMW <= dram0_rmw;
7957
                 isCAS <= IsCAS(dram0_instr);
7958
                 isAMO <= IsAMO(dram0_instr);
7959
                 isInc <= IsInc(dram0_instr);
7960
                 casid <= dram0_id;
7961
                 bwhich <= 2'b00;
7962 49 robfinch
                 dram0 <= `DRAMSLOT_HASBUS;
7963 48 robfinch
                 cyc_o <= `HIGH;
7964
                 stb_o <= `HIGH;
7965
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
7966
                 adr_o <= dram0_addr;
7967
                 dat_o <= fnDato(dram0_instr,dram0_data);
7968
                 ol_o  <= dram0_ol;
7969
                 bstate <= B12;
7970
            end
7971
        end
7972 49 robfinch
        else if (~|wb_v && mem2_available && dram1==`DRAMSLOT_BUSY && dram1_rmw && `NUM_MEM > 1) begin
7973 48 robfinch
`ifdef SUPPORT_DBG
7974
            if (dbg_smatch1|dbg_lmatch1) begin
7975
                 dramB_v <= `TRUE;
7976
                 dramB_id <= dram1_id;
7977
                 dramB_exc <= `FLT_DBG;
7978
                 dramB_bus <= 64'h0;
7979
                 dram1 <= `DRAMSLOT_AVAIL;
7980
            end
7981
            else
7982
`endif
7983
            begin
7984
                 isRMW <= dram1_rmw;
7985
                 isCAS <= IsCAS(dram1_instr);
7986
                 isAMO <= IsAMO(dram1_instr);
7987
                 isInc <= IsInc(dram1_instr);
7988
                 casid <= dram1_id;
7989
                 bwhich <= 2'b01;
7990 49 robfinch
                 dram1 <= `DRAMSLOT_HASBUS;
7991 48 robfinch
                 cyc_o <= `HIGH;
7992
                 stb_o <= `HIGH;
7993
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
7994
                 adr_o <= dram1_addr;
7995
                 dat_o <= fnDato(dram1_instr,dram1_data);
7996
                 ol_o  <= dram1_ol;
7997
                 bstate <= B12;
7998
            end
7999
        end
8000 49 robfinch
        else if (~|wb_v && mem3_available && dram2==`DRAMSLOT_BUSY && dram2_rmw && `NUM_MEM > 2) begin
8001 48 robfinch
`ifdef SUPPORT_DBG
8002
            if (dbg_smatch2|dbg_lmatch2) begin
8003
                 dramC_v <= `TRUE;
8004
                 dramC_id <= dram2_id;
8005
                 dramC_exc <= `FLT_DBG;
8006
                 dramC_bus <= 64'h0;
8007
                 dram2 <= `DRAMSLOT_AVAIL;
8008
            end
8009
            else
8010
`endif
8011
            begin
8012
                 isRMW <= dram2_rmw;
8013
                 isCAS <= IsCAS(dram2_instr);
8014
                 isAMO <= IsAMO(dram2_instr);
8015
                 isInc <= IsInc(dram2_instr);
8016
                 casid <= dram2_id;
8017
                 bwhich <= 2'b10;
8018 49 robfinch
                 dram2 <= `DRAMSLOT_HASBUS;
8019 48 robfinch
                 cyc_o <= `HIGH;
8020
                 stb_o <= `HIGH;
8021
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
8022
                 adr_o <= dram2_addr;
8023
                 dat_o <= fnDato(dram2_instr,dram2_data);
8024
                 ol_o  <= dram2_ol;
8025
                 bstate <= B12;
8026
            end
8027
        end
8028 49 robfinch
        else if (mem1_available && dram0==`DRAMSLOT_BUSY && IsStore(dram0_instr)) begin
8029 48 robfinch
`ifdef SUPPORT_DBG
8030
            if (dbg_smatch0) begin
8031
                 dramA_v <= `TRUE;
8032
                 dramA_id <= dram0_id;
8033
                 dramA_exc <= `FLT_DBG;
8034
                 dramA_bus <= 64'h0;
8035
                 dram0 <= `DRAMSLOT_AVAIL;
8036
            end
8037
            else
8038
`endif
8039
            begin
8040 49 robfinch
                                                        bwhich <= 2'b00;
8041
`ifndef HAS_WB
8042
                                                        dram0 <= `DRAMSLOT_HASBUS;
8043
                                                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
8044
                 cyc_o <= `HIGH;
8045
                 stb_o <= `HIGH;
8046 48 robfinch
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
8047
                 adr_o <= dram0_addr;
8048
                 dat_o <= fnDato(dram0_instr,dram0_data);
8049
                 ol_o  <= dram0_ol;
8050
                 bstate <= B1;
8051 49 robfinch
`else
8052
                                                                if (wbptr<`WB_DEPTH-1) begin
8053
                                                                        dram0 <= `DRAMREQ_READY;
8054
                                                                        dram0_instr[`INSTRUCTION_OP] <= `NOP;
8055
                                                                        wb_update(
8056
                                                                                dram0_id,
8057
                                                                                `FALSE,
8058
                                                                                fnSelect(dram0_instr,dram0_addr),
8059
                                                                                dram0_ol,
8060
                                                                                dram0_addr,
8061
                                                                                fnDato(dram0_instr,dram0_data)
8062
                                                                        );
8063
                                                                        iqentry_done[ dram0_id[`QBITS] ] <= `VAL;
8064
                                                                        iqentry_out[ dram0_id[`QBITS] ] <= `INV;
8065
                                                                end
8066
`endif
8067
//                 cr_o <= IsSWC(dram0_instr);
8068 48 robfinch
            end
8069
        end
8070 49 robfinch
        else if (mem2_available && dram1==`DRAMSLOT_BUSY && IsStore(dram1_instr) && `NUM_MEM > 1) begin
8071 48 robfinch
`ifdef SUPPORT_DBG
8072
            if (dbg_smatch1) begin
8073
                 dramB_v <= `TRUE;
8074
                 dramB_id <= dram1_id;
8075
                 dramB_exc <= `FLT_DBG;
8076
                 dramB_bus <= 64'h0;
8077
                 dram1 <= `DRAMSLOT_AVAIL;
8078
            end
8079
            else
8080
`endif
8081
            begin
8082 49 robfinch
                 bwhich <= 2'b01;
8083
`ifndef HAS_WB
8084 48 robfinch
                 dram1 <= `DRAMSLOT_HASBUS;
8085
                 dram1_instr[`INSTRUCTION_OP] <= `NOP;
8086 49 robfinch
                 cyc_o <= `HIGH;
8087
                 stb_o <= `HIGH;
8088 48 robfinch
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
8089
                 adr_o <= dram1_addr;
8090
                 dat_o <= fnDato(dram1_instr,dram1_data);
8091
                 ol_o  <= dram1_ol;
8092
                 bstate <= B1;
8093 49 robfinch
`else
8094
                                                                if (wbptr<`WB_DEPTH-1) begin
8095
                                                                        dram1 <= `DRAMREQ_READY;
8096
                        dram1_instr[`INSTRUCTION_OP] <= `NOP;
8097
                                                                        wb_update(
8098
                                                                                dram1_id,
8099
                                                                                `FALSE,
8100
                                                                                fnSelect(dram1_instr,dram1_addr),
8101
                                                                                dram1_ol,
8102
                                                                                dram1_addr,
8103
                                                                                fnDato(dram1_instr,dram1_data)
8104
                                                                        );
8105
                                                                        iqentry_done[ dram1_id[`QBITS] ] <= `VAL;
8106
                                                                        iqentry_out[ dram1_id[`QBITS] ] <= `INV;
8107
                                                                end
8108
`endif
8109
//                 cr_o <= IsSWC(dram0_instr);
8110 48 robfinch
            end
8111
        end
8112 49 robfinch
        else if (mem3_available && dram2==`DRAMSLOT_BUSY && IsStore(dram2_instr) && `NUM_MEM > 2) begin
8113 48 robfinch
`ifdef SUPPORT_DBG
8114
            if (dbg_smatch2) begin
8115
                 dramC_v <= `TRUE;
8116
                 dramC_id <= dram2_id;
8117
                 dramC_exc <= `FLT_DBG;
8118
                 dramC_bus <= 64'h0;
8119
                 dram2 <= `DRAMSLOT_AVAIL;
8120
            end
8121
            else
8122
`endif
8123
            begin
8124 49 robfinch
                 bwhich <= 2'b10;
8125
`ifndef HAS_WB
8126 48 robfinch
                 dram2 <= `DRAMSLOT_HASBUS;
8127
                 dram2_instr[`INSTRUCTION_OP] <= `NOP;
8128 49 robfinch
                 cyc_o <= `HIGH;
8129
                 stb_o <= `HIGH;
8130 48 robfinch
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
8131
                 adr_o <= dram2_addr;
8132
                 dat_o <= fnDato(dram2_instr,dram2_data);
8133
                 ol_o  <= dram2_ol;
8134
                 bstate <= B1;
8135 49 robfinch
`else
8136
                                                                if (wbptr<`WB_DEPTH-1) begin
8137
                                                                        dram2 <= `DRAMREQ_READY;
8138
                        dram2_instr[`INSTRUCTION_OP] <= `NOP;
8139
                                                                        wb_update(
8140
                                                                                dram2_id,
8141
                                                                                `FALSE,
8142
                                                                                fnSelect(dram2_instr,dram2_addr),
8143
                                                                                dram2_ol,
8144
                                                                                dram2_addr,
8145
                                                                                fnDato(dram2_instr,dram2_data)
8146
                                                                        );
8147
                                                                        iqentry_done[ dram2_id[`QBITS] ] <= `VAL;
8148
                                                                        iqentry_out[ dram2_id[`QBITS] ] <= `INV;
8149
                                                                end
8150
`endif
8151
//                 cr_o <= IsSWC(dram0_instr);
8152 48 robfinch
            end
8153
        end
8154
        // Check for read misses on the data cache
8155 49 robfinch
        else if (mem1_available && !dram0_unc && dram0==`DRAMSLOT_REQBUS && dram0_load) begin
8156 48 robfinch
`ifdef SUPPORT_DBG
8157
            if (dbg_lmatch0) begin
8158
                 dramA_v <= `TRUE;
8159
                 dramA_id <= dram0_id;
8160
                 dramA_exc <= `FLT_DBG;
8161
                 dramA_bus <= 64'h0;
8162
                 dram0 <= `DRAMSLOT_AVAIL;
8163
            end
8164
            else
8165
`endif
8166
            begin
8167
                 dram0 <= `DRAMSLOT_HASBUS;
8168
                 bwhich <= 2'b00;
8169
                 preload <= dram0_preload;
8170
                 bstate <= B2;
8171
            end
8172
        end
8173 49 robfinch
        else if (~|wb_v && mem2_available && !dram1_unc && dram1==`DRAMSLOT_REQBUS && dram1_load && `NUM_MEM > 1) begin
8174 48 robfinch
`ifdef SUPPORT_DBG
8175
            if (dbg_lmatch1) begin
8176
                 dramB_v <= `TRUE;
8177
                 dramB_id <= dram1_id;
8178
                 dramB_exc <= `FLT_DBG;
8179
                 dramB_bus <= 64'h0;
8180
                 dram1 <= `DRAMSLOT_AVAIL;
8181
            end
8182
            else
8183
`endif
8184
            begin
8185
                 dram1 <= `DRAMSLOT_HASBUS;
8186
                 bwhich <= 2'b01;
8187
                 preload <= dram1_preload;
8188
                 bstate <= B2;
8189
            end
8190
        end
8191 49 robfinch
        else if (~|wb_v && mem3_available && !dram2_unc && dram2==`DRAMSLOT_REQBUS && dram2_load && `NUM_MEM > 2) begin
8192 48 robfinch
`ifdef SUPPORT_DBG
8193
            if (dbg_lmatch2) begin
8194
                 dramC_v <= `TRUE;
8195
                 dramC_id <= dram2_id;
8196
                 dramC_exc <= `FLT_DBG;
8197
                 dramC_bus <= 64'h0;
8198
                 dram2 <= `DRAMSLOT_AVAIL;
8199
            end
8200
            else
8201
`endif
8202
            begin
8203
                 dram2 <= `DRAMSLOT_HASBUS;
8204
                 preload <= dram2_preload;
8205
                 bwhich <= 2'b10;
8206
                 bstate <= B2;
8207
            end
8208
        end
8209 49 robfinch
        else if (~|wb_v && mem1_available && dram0_unc && dram0==`DRAMSLOT_BUSY && dram0_load) begin
8210 48 robfinch
`ifdef SUPPORT_DBG
8211
            if (dbg_lmatch0) begin
8212
                 dramA_v <= `TRUE;
8213
                 dramA_id <= dram0_id;
8214
                 dramA_exc <= `FLT_DBG;
8215
                 dramA_bus <= 64'h0;
8216
                 dram0 <= `DRAMSLOT_AVAIL;
8217
            end
8218
            else
8219
`endif
8220
            begin
8221
                 bwhich <= 2'b00;
8222
                 cyc_o <= `HIGH;
8223
                 stb_o <= `HIGH;
8224
                 sel_o <= fnSelect(dram0_instr,dram0_addr);
8225
                 adr_o <= {dram0_addr[31:3],3'b0};
8226
                 sr_o <=  IsLWR(dram0_instr);
8227
                 ol_o  <= dram0_ol;
8228
                 bstate <= B12;
8229
            end
8230
        end
8231 49 robfinch
        else if (~|wb_v && mem2_available && dram1_unc && dram1==`DRAMSLOT_BUSY && dram1_load && `NUM_MEM > 1) begin
8232 48 robfinch
`ifdef SUPPORT_DBG
8233
            if (dbg_lmatch1) begin
8234
                 dramB_v <= `TRUE;
8235
                 dramB_id <= dram1_id;
8236
                 dramB_exc <= `FLT_DBG;
8237
                 dramB_bus <= 64'h0;
8238
                 dram1 <= `DRAMSLOT_AVAIL;
8239
            end
8240
            else
8241
`endif
8242
            begin
8243
                 bwhich <= 2'b01;
8244
                 cyc_o <= `HIGH;
8245
                 stb_o <= `HIGH;
8246
                 sel_o <= fnSelect(dram1_instr,dram1_addr);
8247
                 adr_o <= {dram1_addr[31:3],3'b0};
8248
                 sr_o <=  IsLWR(dram1_instr);
8249
                 ol_o  <= dram1_ol;
8250
                 bstate <= B12;
8251
            end
8252
        end
8253 49 robfinch
        else if (~|wb_v && mem3_available && dram2_unc && dram2==`DRAMSLOT_BUSY && dram2_load && `NUM_MEM > 2) begin
8254 48 robfinch
`ifdef SUPPORT_DBG
8255
            if (dbg_lmatch2) begin
8256
                 dramC_v <= `TRUE;
8257
                 dramC_id <= dram2_id;
8258
                 dramC_exc <= `FLT_DBG;
8259
                 dramC_bus <= 64'h0;
8260
                 dram2 <= 2'd0;
8261
            end
8262
            else
8263
`endif
8264
            begin
8265
                 bwhich <= 2'b10;
8266
                 cyc_o <= `HIGH;
8267
                 stb_o <= `HIGH;
8268
                 sel_o <= fnSelect(dram2_instr,dram2_addr);
8269
                 adr_o <= {dram2_addr[31:3],3'b0};
8270
                 sr_o <=  IsLWR(dram2_instr);
8271
                 ol_o  <= dram2_ol;
8272
                 bstate <= B12;
8273
            end
8274
        end
8275
        // Check for L2 cache miss
8276 49 robfinch
        else if (~|wb_v && !ihitL2) begin
8277 48 robfinch
             cti_o <= 3'b001;
8278 49 robfinch
             bte_o <= 2'b00;//2'b01;    // 4 beat burst wrap
8279 48 robfinch
             cyc_o <= `HIGH;
8280
             stb_o <= `HIGH;
8281
             sel_o <= 8'hFF;
8282
             icl_o <= `HIGH;
8283 49 robfinch
             iccnt <= 3'd0;
8284 48 robfinch
//            adr_o <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
8285
//            L2_adr <= icwhich ? {pc0[31:5],5'b0} : {pc1[31:5],5'b0};
8286
             adr_o <= {pcr[5:0],L1_adr[31:5],5'h0};
8287
             ol_o  <= ol[0];
8288
             L2_adr <= {pcr[5:0],L1_adr[31:5],5'h0};
8289
             L2_xsel <= 1'b0;
8290
             bstate <= B7;
8291
        end
8292
    end
8293
// Terminal state for a store operation.
8294 49 robfinch
// Note that if only a single memory channel is selected, bwhich will be a
8295
// constant 0. This should cause the extra code to be removed.
8296 48 robfinch
B1:
8297
    if (acki|err_i) begin
8298
         isStore <= `TRUE;
8299
         cyc_o <= `LOW;
8300
         stb_o <= `LOW;
8301
         we_o <= `LOW;
8302
         sel_o <= 8'h00;
8303
         cr_o <= 1'b0;
8304
        // This isn't a good way of doing things; the state should be propagated
8305
        // to the commit stage, however since this is a store we know there will
8306
        // be no change of program flow. So the reservation status bit is set
8307
        // here. The author wanted to avoid the complexity of propagating the
8308
        // input signal to the commit stage. It does mean that the SWC
8309
        // instruction should be surrounded by SYNC's.
8310
        if (cr_o)
8311
             sema[0] <= rbi_i;
8312 49 robfinch
`ifdef HAS_WB
8313
                                for (n = 0; n < QENTRIES; n = n + 1) begin
8314
                                        if (wbo_id[n]) begin
8315
                        iqentry_exc[n] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8316
                        if (err_i|wrv_i) begin
8317
                                iqentry_a1[n] <= adr_o;
8318
                                wb_v <= 8'h00;          // Invalidate write buffer if there is a problem with the store
8319
                                wb_en <= `FALSE;        // and disable write buffer
8320
                        end
8321
                                                iqentry_cmt[n] <= `VAL;
8322
                                                iqentry_aq[n] <= `INV;
8323
                                        end
8324
                                end
8325
`else
8326 48 robfinch
        case(bwhich)
8327 49 robfinch
        2'd0:   if (mem1_available) begin
8328 48 robfinch
                 dram0 <= `DRAMREQ_READY;
8329
                 iqentry_exc[dram0_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8330
                if (err_i|wrv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8331 49 robfinch
                                                                        iqentry_cmt[ dram0_id[`QBITS] ] <= `VAL;
8332
                                                                        iqentry_aq[ dram0_id[`QBITS] ] <= `INV;
8333 48 robfinch
                        //iqentry_out[ dram0_id[`QBITS] ] <= `INV;
8334
                end
8335 49 robfinch
        2'd1:   if (`NUM_MEM > 1) begin
8336 48 robfinch
                 dram1 <= `DRAMREQ_READY;
8337
                 iqentry_exc[dram1_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8338
                if (err_i|wrv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8339 49 robfinch
                                                                        iqentry_cmt[ dram1_id[`QBITS] ] <= `VAL;
8340
                                                                        iqentry_aq[ dram1_id[`QBITS] ] <= `INV;
8341 48 robfinch
                        //iqentry_out[ dram1_id[`QBITS] ] <= `INV;
8342
                end
8343 49 robfinch
        2'd2:   if (`NUM_MEM > 2) begin
8344 48 robfinch
                 dram2 <= `DRAMREQ_READY;
8345
                 iqentry_exc[dram2_id[`QBITS]] <= wrv_i|err_i ? `FLT_DWF : `FLT_NONE;
8346
                if (err_i|wrv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8347 49 robfinch
                                                                        iqentry_cmt[ dram2_id[`QBITS] ] <= `VAL;
8348
                                                                        iqentry_aq[ dram2_id[`QBITS] ] <= `INV;
8349 48 robfinch
                        //iqentry_out[ dram2_id[`QBITS] ] <= `INV;
8350
                end
8351
        default:    ;
8352
        endcase
8353 49 robfinch
`endif
8354 48 robfinch
         bstate <= B19;
8355
    end
8356
B2:
8357
    begin
8358
    dccnt <= 2'd0;
8359
    case(bwhich)
8360
    2'd0:   begin
8361
             cti_o <= 3'b001;
8362
             bte_o <= 2'b01;
8363
             cyc_o <= `HIGH;
8364
             stb_o <= `HIGH;
8365
             sel_o <= fnSelect(dram0_instr,dram0_addr);
8366
             adr_o <= {dram0_addr[31:5],5'b0};
8367
             ol_o  <= dram0_ol;
8368
             bstate <= B2d;
8369
            end
8370 49 robfinch
    2'd1:   if (`NUM_MEM > 1) begin
8371 48 robfinch
             cti_o <= 3'b001;
8372
             bte_o <= 2'b01;
8373
             cyc_o <= `HIGH;
8374
             stb_o <= `HIGH;
8375
             sel_o <= fnSelect(dram1_instr,dram1_addr);
8376
             adr_o <= {dram1_addr[31:5],5'b0};
8377
             ol_o  <= dram1_ol;
8378
             bstate <= B2d;
8379
            end
8380 49 robfinch
    2'd2:   if (`NUM_MEM > 2) begin
8381 48 robfinch
             cti_o <= 3'b001;
8382
             bte_o <= 2'b01;
8383
             cyc_o <= `HIGH;
8384
             stb_o <= `HIGH;
8385
             sel_o <= fnSelect(dram2_instr,dram2_addr);
8386
             adr_o <= {dram2_addr[31:5],5'b0};
8387
             ol_o  <= dram2_ol;
8388
             bstate <= B2d;
8389
            end
8390
    default:    if (~acki)  bstate <= BIDLE;
8391
    endcase
8392
    end
8393
// Data cache load terminal state
8394
B2d:
8395
    if (ack_i|err_i) begin
8396
        errq <= errq | err_i;
8397
        rdvq <= rdvq | rdv_i;
8398
        if (!preload)   // A preload instruction ignores any error
8399
        case(bwhich)
8400
        2'd0:   if (err_i|rdv_i) begin
8401
                     iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8402
                     iqentry_exc[dram0_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8403
                end
8404 49 robfinch
        2'd1:   if ((err_i|rdv_i) && `NUM_MEM > 1) begin
8405 48 robfinch
                     iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8406
                     iqentry_exc[dram1_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8407
                end
8408 49 robfinch
        2'd2:   if ((err_i|rdv_i) && `NUM_MEM > 2) begin
8409 48 robfinch
                     iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8410
                     iqentry_exc[dram2_id[`QBITS]] <= err_i ? `FLT_DBE : `FLT_DRF;
8411
                end
8412
        default:    ;
8413
        endcase
8414
        dccnt <= dccnt + 2'd1;
8415
        adr_o[4:3] <= adr_o[4:3] + 2'd1;
8416
        bstate <= B2d;
8417
        if (dccnt==2'd2)
8418
             cti_o <= 3'b111;
8419
        if (dccnt==2'd3) begin
8420
             cti_o <= 3'b000;
8421
             bte_o <= 2'b00;
8422
             cyc_o <= `LOW;
8423
             stb_o <= `LOW;
8424
             sel_o <= 8'h00;
8425
             bstate <= B4;
8426
        end
8427
    end
8428
B3: begin
8429
         stb_o <= `HIGH;
8430
         bstate <= B2d;
8431
    end
8432
B4:  bstate <= B5;
8433
B5:  bstate <= B6;
8434
B6: begin
8435
    case(bwhich)
8436
    2'd0:    dram0 <= `DRAMSLOT_BUSY;  // causes retest of dhit
8437
    2'd1:    dram1 <= `DRAMSLOT_BUSY;
8438
    2'd2:    dram2 <= `DRAMSLOT_BUSY;
8439
    default:    ;
8440
    endcase
8441
    if (~ack_i)  bstate <= BIDLE;
8442
    end
8443
 
8444
// Ack state for instruction cache load
8445
B7:
8446
    if (ack_i|err_i) begin
8447
        errq <= errq | err_i;
8448
        exvq <= exvq | exv_i;
8449 49 robfinch
//        L1_en <= 9'h3 << {L2_xsel,L2_adr[4:3],1'b0};
8450 48 robfinch
//        L1_wr0 <= `TRUE;
8451
//        L1_wr1 <= `TRUE;
8452
//        L1_adr <= L2_adr;
8453
        if (err_i)
8454 49 robfinch
                L2_rdat <= {9{11'b0,4'd7,1'b0,`FLT_IBE,2'b00,`BRK}};
8455 48 robfinch
        else
8456 49 robfinch
                L2_rdat <= {dat_i[31:0],{4{dat_i}}};
8457 48 robfinch
        iccnt <= iccnt + 3'd1;
8458
        //stb_o <= `LOW;
8459
        if (iccnt==3'd3)
8460
            cti_o <= 3'b111;
8461
        if (iccnt==3'd4) begin
8462
            cti_o <= 3'b000;
8463
            bte_o <= 2'b00;             // linear burst
8464
            cyc_o <= `LOW;
8465
            stb_o <= `LOW;
8466
            sel_o <= 8'h00;
8467
            icl_o <= `LOW;
8468
            bstate <= B9;
8469
        end
8470
        else begin
8471
            L2_adr[4:3] <= L2_adr[4:3] + 2'd1;
8472
            if (L2_adr[4:3]==2'b11)
8473
                L2_xsel <= 1'b1;
8474
        end
8475
    end
8476
B9:
8477
        begin
8478
                L1_wr0 <= `FALSE;
8479
                L1_wr1 <= `FALSE;
8480 49 robfinch
                L1_wr2 <= `FALSE;
8481
                L1_en <= 9'h1FF;
8482 48 robfinch
                L2_xsel <= 1'b0;
8483
                if (~ack_i) begin
8484
                        bstate <= BIDLE;
8485
                        L2_nxt <= TRUE;
8486
                end
8487
        end
8488
B12:
8489
    if (ack_i|err_i) begin
8490
        if (isCAS) begin
8491
             iqentry_res        [ casid[`QBITS] ] <= (dat_i == cas);
8492
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8493
             iqentry_done[ casid[`QBITS] ] <= `VAL;
8494
             iqentry_instr[ casid[`QBITS]] <= `NOP_INSN;
8495
             iqentry_out [ casid[`QBITS] ] <= `INV;
8496
            if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
8497
            if (dat_i == cas) begin
8498
                 stb_o <= `LOW;
8499
                 we_o <= `TRUE;
8500
                 bstate <= B15;
8501
            end
8502
            else begin
8503
                 cas <= dat_i;
8504
                 cyc_o <= `LOW;
8505
                 stb_o <= `LOW;
8506
                 sel_o <= 8'h00;
8507
                case(bwhich)
8508
                2'b00:   dram0 <= `DRAMREQ_READY;
8509
                2'b01:   dram1 <= `DRAMREQ_READY;
8510
                2'b10:   dram2 <= `DRAMREQ_READY;
8511
                default:    ;
8512
                endcase
8513
                 bstate <= B19;
8514
            end
8515
        end
8516
        else if (isRMW) begin
8517
             rmw_instr <= iqentry_instr[casid[`QBITS]];
8518
             rmw_argA <= dat_i;
8519
                 if (isSpt) begin
8520
                        rmw_argB <= 64'd1 << iqentry_a1[casid[`QBITS]][63:58];
8521
                        rmw_argC <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ?
8522
                                                iqentry_a3[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58] :
8523
                                                iqentry_a2[casid[`QBITS]][64] << iqentry_a1[casid[`QBITS]][63:58];
8524
                 end
8525
                 else if (isInc) begin
8526
                        rmw_argB <= iqentry_instr[casid[`QBITS]][5:0]==`R2 ? {{59{iqentry_instr[casid[`QBITS]][22]}},iqentry_instr[casid[`QBITS]][22:18]} :
8527
                                                                                                                                 {{59{iqentry_instr[casid[`QBITS]][17]}},iqentry_instr[casid[`QBITS]][17:13]};
8528
                 end
8529
                 else begin // isAMO
8530
                     iqentry_res [ casid[`QBITS] ] <= dat_i;
8531
                     rmw_argB <= iqentry_instr[casid[`QBITS]][31] ? {{59{iqentry_instr[casid[`QBITS]][20:16]}},iqentry_instr[casid[`QBITS]][20:16]} : iqentry_a2[casid[`QBITS]];
8532
                 end
8533
             iqentry_exc [ casid[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8534
             if (err_i | rdv_i) iqentry_a1[casid[`QBITS]] <= adr_o;
8535
             stb_o <= `LOW;
8536
             bstate <= B20;
8537
                end
8538
        else begin
8539
             cyc_o <= `LOW;
8540
             stb_o <= `LOW;
8541
             sel_o <= 8'h00;
8542
             sr_o <= `LOW;
8543
             xdati <= dat_i;
8544
            case(bwhich)
8545
            2'b00:  begin
8546
                     dram0 <= `DRAMREQ_READY;
8547
                     iqentry_exc [ dram0_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8548
                    if (err_i|rdv_i)  iqentry_a1[dram0_id[`QBITS]] <= adr_o;
8549
                    end
8550 49 robfinch
            2'b01:  if (`NUM_MEM > 1) begin
8551 48 robfinch
                     dram1 <= `DRAMREQ_READY;
8552
                     iqentry_exc [ dram1_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8553
                    if (err_i|rdv_i)  iqentry_a1[dram1_id[`QBITS]] <= adr_o;
8554
                    end
8555 49 robfinch
            2'b10:  if (`NUM_MEM > 2) begin
8556 48 robfinch
                     dram2 <= `DRAMREQ_READY;
8557
                     iqentry_exc [ dram2_id[`QBITS] ] <= err_i ? `FLT_DRF : rdv_i ? `FLT_DRF : `FLT_NONE;
8558
                    if (err_i|rdv_i)  iqentry_a1[dram2_id[`QBITS]] <= adr_o;
8559
                    end
8560
            default:    ;
8561
            endcase
8562
             bstate <= B19;
8563
        end
8564
    end
8565
// Three cycles to detemrine if there's a cache hit during a store.
8566
B16:    begin
8567
            case(bwhich)
8568
            2'd0:      if (dhit0) begin  dram0 <= `DRAMREQ_READY; bstate <= B17; end
8569
            2'd1:      if (dhit1) begin  dram1 <= `DRAMREQ_READY; bstate <= B17; end
8570
            2'd2:      if (dhit2) begin  dram2 <= `DRAMREQ_READY; bstate <= B17; end
8571
            default:    bstate <= BIDLE;
8572
            endcase
8573
            end
8574
B17:     bstate <= B18;
8575
B18:     bstate <= B19;
8576
B19:    if (~acki)  begin bstate <= BIDLE; isStore <= `FALSE; end
8577
B20:
8578
        if (~ack_i) begin
8579
                stb_o <= `HIGH;
8580
                we_o  <= `HIGH;
8581
                dat_o <= fnDato(rmw_instr,rmw_res);
8582
                bstate <= B1;
8583
        end
8584
B21:
8585
        if (~ack_i) begin
8586
                stb_o <= `HIGH;
8587
                bstate <= B12;
8588
        end
8589
default:     bstate <= BIDLE;
8590
endcase
8591
 
8592
if (!branchmiss) begin
8593
    case({fetchbuf0_v, fetchbuf1_v})
8594
    2'b00:  ;
8595
    2'b01:
8596
        if (canq1) begin
8597
                tail0 <= idp1(tail0);
8598
                tail1 <= idp1(tail1);
8599
        end
8600
    2'b10:
8601
        if (canq1) begin
8602
            tail0 <= idp1(tail0);
8603
            tail1 <= idp1(tail1);
8604
        end
8605
    2'b11:
8606
        if (canq1) begin
8607
            if (IsBranch(fetchbuf0_instr) && predict_taken0 && fetchbuf0_thrd==fetchbuf1_thrd) begin
8608
                 tail0 <= idp1(tail0);
8609
                 tail1 <= idp1(tail1);
8610
            end
8611
            else begin
8612
                                if (vqe0 < vl || !IsVector(fetchbuf0_instr)) begin
8613
                        if (canq2) begin
8614
                             tail0 <= idp2(tail0);
8615
                             tail1 <= idp2(tail1);
8616
                        end
8617
                        else begin    // queued1 will be true
8618
                             tail0 <= idp1(tail0);
8619
                             tail1 <= idp1(tail1);
8620
                        end
8621
                end
8622
            end
8623
        end
8624
    endcase
8625
end
8626
`ifndef SUPPORT_SMT
8627
else begin      // if branchmiss
8628
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
8629
         tail0 <= 3'd0;
8630
         tail1 <= 3'd1;
8631
    end
8632
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
8633
         tail0 <= 3'd1;
8634
         tail1 <= 3'd2;
8635
    end
8636
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
8637
         tail0 <= 3'd2;
8638
         tail1 <= 3'd3;
8639
    end
8640
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
8641
         tail0 <= 3'd3;
8642
         tail1 <= 3'd4;
8643
    end
8644
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
8645
         tail0 <= 3'd4;
8646
         tail1 <= 3'd5;
8647
    end
8648
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
8649
         tail0 <= 3'd5;
8650
         tail1 <= 3'd6;
8651
    end
8652
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
8653
         tail0 <= 3'd6;
8654
         tail1 <= 3'd7;
8655
    end
8656
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
8657
         tail0 <= 3'd7;
8658
         tail1 <= 3'd0;
8659
    end
8660
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
8661
end
8662
`endif
8663
/*
8664
    if (pebm)
8665
         seq_num <= seq_num + 5'd3;
8666
    else if (queued2)
8667
         seq_num <= seq_num + 5'd2;
8668
    else if (queued1)
8669
         seq_num <= seq_num + 5'd1;
8670
*/
8671
//      #5 rf[0] = 0; rf_v[0] = 1; rf_source[0] = 0;
8672
        $display("\n\n\n\n\n\n\n\n");
8673
        $display("TIME %0d", $time);
8674
        $display("%h #", pc0);
8675
`ifdef SUPPORT_SMT
8676
    $display ("Regfile: %d", rgs[0]);
8677
        for (n=0; n < 32; n=n+4) begin
8678
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8679
               n[4:0]+0, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8680
               n[4:0]+1, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8681
               n[4:0]+2, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8682
               n[4:0]+3, urf1.urf10.mem[{rgs[0],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8683
               );
8684
        end
8685
    $display ("Regfile: %d", rgs[1]);
8686
        for (n=128; n < 160; n=n+4) begin
8687
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8688
               n[4:0]+0, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8689
               n[4:0]+1, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8690
               n[4:0]+2, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8691
               n[4:0]+3, urf1.urf10.mem[{rgs[1],1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8692
               );
8693
        end
8694
`else
8695
    $display ("Regfile: %d", rgs);
8696
        for (n=0; n < 32; n=n+4) begin
8697
            $display("%d: %h %d %o   %d: %h %d %o   %d: %h %d %o   %d: %h %d %o#",
8698
               n[4:0]+0, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b00}], regIsValid[n+0], rf_source[n+0],
8699
               n[4:0]+1, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b01}], regIsValid[n+1], rf_source[n+1],
8700
               n[4:0]+2, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b10}], regIsValid[n+2], rf_source[n+2],
8701
               n[4:0]+3, urf1.urf10.mem[{rgs,1'b0,n[4:2],2'b11}], regIsValid[n+3], rf_source[n+3]
8702
               );
8703
        end
8704
`endif
8705 49 robfinch
`ifdef FCU_ENH
8706 48 robfinch
        $display("Call Stack:");
8707 49 robfinch
        for (n = 0; n < 16; n = n + 4)
8708 48 robfinch
                $display("%c%d: %h   %c%d: %h   %c%d: %h   %c%d: %h",
8709
                        ufb1.ursb1.rasp==n+0 ?">" : " ", n[4:0]+0, ufb1.ursb1.ras[n+0],
8710
                        ufb1.ursb1.rasp==n+1 ?">" : " ", n[4:0]+1, ufb1.ursb1.ras[n+1],
8711
                        ufb1.ursb1.rasp==n+2 ?">" : " ", n[4:0]+2, ufb1.ursb1.ras[n+2],
8712
                        ufb1.ursb1.rasp==n+3 ?">" : " ", n[4:0]+3, ufb1.ursb1.ras[n+3]
8713
                );
8714
        $display("\n");
8715 49 robfinch
`endif
8716 48 robfinch
//    $display("Return address stack:");
8717
//    for (n = 0; n < 16; n = n + 1)
8718
//        $display("%d %h", rasp+n[3:0], ras[rasp+n[3:0]]);
8719
        $display("TakeBr:%d #", take_branch);//, backpc);
8720
        $display("%c%c A: %d %h %h #",
8721
            45, fetchbuf?45:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc);
8722
        $display("%c%c B: %d %h %h #",
8723
            45, fetchbuf?45:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc);
8724
        $display("%c%c C: %d %h %h #",
8725
            45, fetchbuf?62:45, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
8726
        $display("%c%c D: %d %h %h #",
8727
            45, fetchbuf?62:45, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
8728
 
8729
        for (i=0; i<QENTRIES; i=i+1)
8730
            $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#",
8731
                 (i[`QBITS]==head0)?"C":".",
8732
                 (i[`QBITS]==tail0)?"Q":".",
8733
                  i[`QBITS],
8734
                 iqentry_v[i] ? "v" : "-",
8735
                 iqentry_iv[i] ? "I" : "-",
8736
                 iqentry_done[i]?"d":"-",
8737
                 iqentry_out[i]?"o":"-",
8738
                 iqentry_bt[i],
8739
                 iqentry_memissue[i],
8740
                 iqentry_agen[i] ? "a": "-",
8741
                 iqentry_alu0_issue[i]?"0":iqentry_alu1_issue[i]?"1":"-",
8742
                 iqentry_stomp[i]?"s":"-",
8743
                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",
8744
                iqentry_instr[i], iqentry_tgt[i][4:0],
8745
                iqentry_exc[i], iqentry_res[i], iqentry_a0[i], iqentry_a1[i], iqentry_a1_v[i],
8746
                iqentry_a1_s[i],
8747
                iqentry_a2[i], iqentry_a2_v[i], iqentry_a2_s[i],
8748
                iqentry_a3[i], iqentry_a3_v[i], iqentry_a3_s[i],
8749
                iqentry_thrd[i],
8750
                iqentry_pc[i],
8751
                iqentry_sn[i], iqentry_ven[i]
8752
                );
8753
    $display("DRAM");
8754
        $display("%d %h %h %c%h %o #",
8755
            dram0, dram0_addr, dram0_data, (IsFlowCtrl(dram0_instr) ? 98 : (IsMem(dram0_instr)) ? 109 : 97),
8756
            dram0_instr, dram0_id);
8757 49 robfinch
          if (`NUM_MEM > 1)
8758 48 robfinch
        $display("%d %h %h %c%h %o #",
8759
            dram1, dram1_addr, dram1_data, (IsFlowCtrl(dram1_instr) ? 98 : (IsMem(dram1_instr)) ? 109 : 97),
8760
            dram1_instr, dram1_id);
8761 49 robfinch
          if (`NUM_MEM > 2)
8762 48 robfinch
        $display("%d %h %h %c%h %o #",
8763
            dram2, dram2_addr, dram2_data, (IsFlowCtrl(dram2_instr) ? 98 : (IsMem(dram2_instr)) ? 109 : 97),
8764
            dram2_instr, dram2_id);
8765
        $display("%d %h %o %h #", dramA_v, dramA_bus, dramA_id, dramA_exc);
8766 49 robfinch
        if (`NUM_MEM > 1)
8767 48 robfinch
        $display("%d %h %o %h #", dramB_v, dramB_bus, dramB_id, dramB_exc);
8768 49 robfinch
        if (`NUM_MEM > 2)
8769 48 robfinch
        $display("%d %h %o %h #", dramC_v, dramC_bus, dramC_id, dramC_exc);
8770
    $display("ALU");
8771
        $display("%d %h %h %h %c%h %d %o %h #",
8772
                alu0_dataready, alu0_argI, alu0_argA, alu0_argB,
8773
                 (IsFlowCtrl(alu0_instr) ? 98 : IsMem(alu0_instr) ? 109 : 97),
8774
                alu0_instr, alu0_bt, alu0_sourceid, alu0_pc);
8775
        $display("%d %h %o 0 #", alu0_v, alu0_bus, alu0_id);
8776 49 robfinch
        if (`NUM_ALU > 1) begin
8777
                $display("%d %h %h %h %c%h %d %o %h #",
8778
                        alu1_dataready, alu1_argI, alu1_argA, alu1_argB,
8779
                        (IsFlowCtrl(alu1_instr) ? 98 : IsMem(alu1_instr) ? 109 : 97),
8780
                        alu1_instr, alu1_bt, alu1_sourceid, alu1_pc);
8781
                $display("%d %h %o 0 #", alu1_v, alu1_bus, alu1_id);
8782
        end
8783 48 robfinch
        $display("FCU");
8784
        $display("%d %h %h %h %h #", fcu_v, fcu_bus, fcu_argI, fcu_argA, fcu_argB);
8785
        $display("%c %h %h #", fcu_branchmiss?"m":" ", fcu_sourceid, fcu_misspc);
8786
    $display("Commit");
8787
        $display("0: %c %h %o %d #", commit0_v?"v":" ", commit0_bus, commit0_id, commit0_tgt[4:0]);
8788
        $display("1: %c %h %o %d #", commit1_v?"v":" ", commit1_bus, commit1_id, commit1_tgt[4:0]);
8789
    $display("instructions committed: %d ticks: %d ", I, tick);
8790 49 robfinch
    $display("Write merges: %d", wb_merges);
8791 48 robfinch
 
8792
//
8793
//      $display("\n\n\n\n\n\n\n\n");
8794
//      $display("TIME %0d", $time);
8795
//      $display("  pc0=%h", pc0);
8796
//      $display("  pc1=%h", pc1);
8797
//      $display("  reg0=%h, v=%d, src=%o", rf[0], rf_v[0], rf_source[0]);
8798
//      $display("  reg1=%h, v=%d, src=%o", rf[1], rf_v[1], rf_source[1]);
8799
//      $display("  reg2=%h, v=%d, src=%o", rf[2], rf_v[2], rf_source[2]);
8800
//      $display("  reg3=%h, v=%d, src=%o", rf[3], rf_v[3], rf_source[3]);
8801
//      $display("  reg4=%h, v=%d, src=%o", rf[4], rf_v[4], rf_source[4]);
8802
//      $display("  reg5=%h, v=%d, src=%o", rf[5], rf_v[5], rf_source[5]);
8803
//      $display("  reg6=%h, v=%d, src=%o", rf[6], rf_v[6], rf_source[6]);
8804
//      $display("  reg7=%h, v=%d, src=%o", rf[7], rf_v[7], rf_source[7]);
8805
 
8806
//      $display("Fetch Buffers:");
8807
//      $display("  %c%c fbA: v=%d instr=%h pc=%h     %c%c fbC: v=%d instr=%h pc=%h", 
8808
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufA_v, fetchbufA_instr, fetchbufA_pc,
8809
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufC_v, fetchbufC_instr, fetchbufC_pc);
8810
//      $display("  %c%c fbB: v=%d instr=%h pc=%h     %c%c fbD: v=%d instr=%h pc=%h", 
8811
//          fetchbuf?32:45, fetchbuf?32:62, fetchbufB_v, fetchbufB_instr, fetchbufB_pc,
8812
//          fetchbuf?45:32, fetchbuf?62:32, fetchbufD_v, fetchbufD_instr, fetchbufD_pc);
8813
//      $display("  branchback=%d backpc=%h", branchback, backpc);
8814
 
8815
//      $display("Instruction Queue:");
8816
//      for (i=0; i<8; i=i+1) 
8817
//          $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",
8818
//              (i[`QBITS]==head0)?72:32, (i[`QBITS]==tail0)?84:32, i,
8819
//              iqentry_v[i], iqentry_done[i], iqentry_out[i], iqentry_agen[i], iqentry_res[i], iqentry_op[i], 
8820
//              iqentry_bt[i], iqentry_tgt[i], iqentry_a1[i], iqentry_a1_v[i], iqentry_a1_s[i], iqentry_a2[i], iqentry_a2_v[i], 
8821
//              iqentry_a2_s[i], iqentry_a0[i], iqentry_pc[i], iqentry_exc[i]);
8822
 
8823
//      $display("Scheduling Status:");
8824
//      $display("  iqentry0 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8825
//              iqentry_0_issue, iqentry_0_islot, iqentry_stomp[0], iqentry_source[0], iqentry_memready[0], iqentry_memissue[0]);
8826
//      $display("  iqentry1 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8827
//              iqentry_1_issue, iqentry_1_islot, iqentry_stomp[1], iqentry_source[1], iqentry_memready[1], iqentry_memissue[1]);
8828
//      $display("  iqentry2 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8829
//              iqentry_2_issue, iqentry_2_islot, iqentry_stomp[2], iqentry_source[2], iqentry_memready[2], iqentry_memissue[2]);
8830
//      $display("  iqentry3 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8831
//              iqentry_3_issue, iqentry_3_islot, iqentry_stomp[3], iqentry_source[3], iqentry_memready[3], iqentry_memissue[3]);
8832
//      $display("  iqentry4 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8833
//              iqentry_4_issue, iqentry_4_islot, iqentry_stomp[4], iqentry_source[4], iqentry_memready[4], iqentry_memissue[4]);
8834
//      $display("  iqentry5 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b", 
8835
//              iqentry_5_issue, iqentry_5_islot, iqentry_stomp[5], iqentry_source[5], iqentry_memready[5], iqentry_memissue[5]);
8836
//      $display("  iqentry6 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8837
//              iqentry_6_issue, iqentry_6_islot, iqentry_stomp[6], iqentry_source[6], iqentry_memready[6], iqentry_memissue[6]);
8838
//      $display("  iqentry7 issue=%d islot=%d stomp=%d source=%d - memready=%d memissue=%b",
8839
//              iqentry_7_issue, iqentry_7_islot, iqentry_stomp[7], iqentry_source[7], iqentry_memready[7], iqentry_memissue[7]);
8840
 
8841
//      $display("ALU Inputs:");
8842
//      $display("  0: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
8843
//              alu0_available, alu0_dataready, alu0_sourceid, alu0_op, alu0_argA,
8844
//              alu0_argB, alu0_argI, alu0_bt);
8845
//      $display("  1: avail=%d data=%d id=%o op=%d a1=%h a2=%h im=%h bt=%d",
8846
//              alu1_available, alu1_dataready, alu1_sourceid, alu1_op, alu1_argA,
8847
//              alu1_argB, alu1_argI, alu1_bt);
8848
 
8849
//      $display("ALU Outputs:");
8850
//      $display("  0: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
8851
//              alu0_v, alu0_bus, alu0_id, alu0_branchmiss, alu0_misspc, alu0_sourceid);
8852
//      $display("  1: v=%d bus=%h id=%o bmiss=%d misspc=%h missid=%o",
8853
//              alu1_v, alu1_bus, alu1_id, alu1_branchmiss, alu1_misspc, alu1_sourceid);
8854
 
8855
//      $display("DRAM Status:");
8856
//      $display("  OUT: v=%d data=%h tgt=%d id=%o", dram_v, dram_bus, dram_tgt, dram_id);
8857
//      $display("  dram0: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
8858
//          dram0, dram0_addr, dram0_data, dram0_op, dram0_tgt, dram0_id);
8859
//      $display("  dram1: status=%h addr=%h data=%h op=%d tgt=%d id=%o", 
8860
//          dram1, dram1_addr, dram1_data, dram1_op, dram1_tgt, dram1_id);
8861
//      $display("  dram2: status=%h addr=%h data=%h op=%d tgt=%d id=%o",
8862
//          dram2, dram2_addr, dram2_data, dram2_op, dram2_tgt, dram2_id);
8863
 
8864
//      $display("Commit Buses:");
8865
//      $display("  0: v=%d id=%o data=%h", commit0_v, commit0_id, commit0_bus);
8866
//      $display("  1: v=%d id=%o data=%h", commit1_v, commit1_id, commit1_bus);
8867
 
8868
//
8869
//      $display("Memory Contents:");
8870
//      for (j=0; j<64; j=j+16)
8871
//          $display("  %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h", 
8872
//              m[j+0], m[j+1], m[j+2], m[j+3], m[j+4], m[j+5], m[j+6], m[j+7],
8873
//              m[j+8], m[j+9], m[j+10], m[j+11], m[j+12], m[j+13], m[j+14], m[j+15]);
8874
 
8875
        $display("");
8876
 
8877
        if (|panic) begin
8878
            $display("");
8879
            $display("-----------------------------------------------------------------");
8880
            $display("-----------------------------------------------------------------");
8881
            $display("---------------     PANIC:%s     -----------------", message[panic]);
8882
            $display("-----------------------------------------------------------------");
8883
            $display("-----------------------------------------------------------------");
8884
            $display("");
8885
            $display("instructions committed: %d", I);
8886
            $display("total execution cycles: %d", $time / 10);
8887
            $display("");
8888
        end
8889
        if (|panic && ~outstanding_stores) begin
8890
            $finish;
8891
        end
8892
    for (n = 0; n < QENTRIES; n = n + 1)
8893
        if (branchmiss) begin
8894
            if (!setpred[n]) begin
8895
                 iqentry_instr[n][`INSTRUCTION_OP] <= `NOP;
8896
                 iqentry_done[n] <= `VAL;
8897
                 iqentry_cmt[n] <= `VAL;
8898
            end
8899
        end
8900
 
8901
        if (snr) begin
8902
                seq_num <= 32'd0;
8903
                seq_num1 <= 32'd0;
8904
        end
8905
end // clock domain
8906
/*
8907
always @(posedge clk)
8908
if (rst) begin
8909
     tail0 <= 3'd0;
8910
     tail1 <= 3'd1;
8911
end
8912
else begin
8913
if (!branchmiss) begin
8914
    case({fetchbuf0_v, fetchbuf1_v})
8915
    2'b00:  ;
8916
    2'b01:
8917
        if (canq1) begin
8918
             tail0 <= idp1(tail0);
8919
             tail1 <= idp1(tail1);
8920
        end
8921
    2'b10:
8922
        if (canq1) begin
8923
             tail0 <= idp1(tail0);
8924
             tail1 <= idp1(tail1);
8925
        end
8926
    2'b11:
8927
        if (canq1) begin
8928
            if (IsBranch(fetchbuf0_instr) && predict_taken0) begin
8929
                 tail0 <= idp1(tail0);
8930
                 tail1 <= idp1(tail1);
8931
            end
8932
            else begin
8933
                                if (vqe < vl || !IsVector(fetchbuf0_instr)) begin
8934
                        if (canq2) begin
8935
                             tail0 <= idp2(tail0);
8936
                             tail1 <= idp2(tail1);
8937
                        end
8938
                        else begin    // queued1 will be true
8939
                             tail0 <= idp1(tail0);
8940
                             tail1 <= idp1(tail1);
8941
                        end
8942
                end
8943
            end
8944
        end
8945
    endcase
8946
end
8947
else begin      // if branchmiss
8948
    if (iqentry_stomp[0] & ~iqentry_stomp[7]) begin
8949
         tail0 <= 3'd0;
8950
         tail1 <= 3'd1;
8951
    end
8952
    else if (iqentry_stomp[1] & ~iqentry_stomp[0]) begin
8953
         tail0 <= 3'd1;
8954
         tail1 <= 3'd2;
8955
    end
8956
    else if (iqentry_stomp[2] & ~iqentry_stomp[1]) begin
8957
         tail0 <= 3'd2;
8958
         tail1 <= 3'd3;
8959
    end
8960
    else if (iqentry_stomp[3] & ~iqentry_stomp[2]) begin
8961
         tail0 <= 3'd3;
8962
         tail1 <= 3'd4;
8963
    end
8964
    else if (iqentry_stomp[4] & ~iqentry_stomp[3]) begin
8965
         tail0 <= 3'd4;
8966
         tail1 <= 3'd5;
8967
    end
8968
    else if (iqentry_stomp[5] & ~iqentry_stomp[4]) begin
8969
         tail0 <= 3'd5;
8970
         tail1 <= 3'd6;
8971
    end
8972
    else if (iqentry_stomp[6] & ~iqentry_stomp[5]) begin
8973
         tail0 <= 3'd6;
8974
         tail1 <= 3'd7;
8975
    end
8976
    else if (iqentry_stomp[7] & ~iqentry_stomp[6]) begin
8977
         tail0 <= 3'd7;
8978
         tail1 <= 3'd0;
8979
    end
8980
    // otherwise, it is the last instruction in the queue that has been mispredicted ... do nothing
8981
end
8982
end
8983
*/
8984
/*
8985
always @(posedge clk)
8986
if (rst)
8987
     seq_num <= 5'd0;
8988
else begin
8989
    if (pebm)
8990
         seq_num <= seq_num + 5'd3;
8991
    else if (queued2)
8992
         seq_num <= seq_num + 5'd2;
8993
    else if (queued1)
8994
         seq_num <= seq_num + 5'd1;
8995
end
8996
*/
8997 49 robfinch
 
8998
task wb_update;
8999
input [`QBITS] id;
9000
input rmw;
9001
input [7:0] sel;
9002
input [1:0] ol;
9003
input [`ABITS] addr;
9004
input [63:0] data;
9005
begin
9006
        if (wbptr > 0 && wb_addr[wbptr-1][AMSB:3]==addr[AMSB:3] && wb_ol[wbptr-1]==ol && wb_rmw[wbptr-1]==rmw) begin
9007
                wb_sel[wbptr-1] <= wb_sel[wbptr-1] | sel;
9008
                if (sel[0]) wb_data[wbptr-1][ 7: 0] <= data[ 7: 0];
9009
                if (sel[1]) wb_data[wbptr-1][15: 8] <= data[15: 8];
9010
                if (sel[2]) wb_data[wbptr-1][23:16] <= data[23:16];
9011
                if (sel[3]) wb_data[wbptr-1][31:24] <= data[31:24];
9012
                if (sel[4]) wb_data[wbptr-1][39:32] <= data[39:32];
9013
                if (sel[5]) wb_data[wbptr-1][47:40] <= data[47:40];
9014
                if (sel[6]) wb_data[wbptr-1][55:48] <= data[55:48];
9015
                if (sel[7]) wb_data[wbptr-1][63:56] <= data[63:56];
9016
                wb_id[wbptr-1] <= wb_id[wbptr-1] | (16'd1 << id);
9017
                wb_merges <= wb_merges + 32'd1;
9018
        end
9019
        else begin
9020
                wb_v[wbptr] <= wb_en;
9021
                wb_id[wbptr] <= (16'd1 << id);
9022
                wb_rmw[wbptr] <= rmw;
9023
                wb_ol[wbptr] <= ol;
9024
                wb_sel[wbptr] <= sel;
9025
                wb_addr[wbptr] <= {addr[AMSB:3],3'b0};
9026
                wb_data[wbptr] <= data;
9027
        end
9028
end
9029
endtask
9030 48 robfinch
// Increment the head pointers
9031
// Also increments the instruction counter
9032
// Used when instructions are committed.
9033
// Also clear any outstanding state bits that foul things up.
9034
//
9035
task head_inc;
9036
input [`QBITS] amt;
9037
begin
9038
     head0 <= head0 + amt;
9039
     head1 <= head1 + amt;
9040
     head2 <= head2 + amt;
9041
     head3 <= head3 + amt;
9042
     head4 <= head4 + amt;
9043
     head5 <= head5 + amt;
9044
     head6 <= head6 + amt;
9045
     head7 <= head7 + amt;
9046
     I <= I + amt;
9047 49 robfinch
    if (amt==3'd3) begin
9048
        iqentry_agen[head0] <= `INV;
9049
        iqentry_agen[head1] <= `INV;
9050
        iqentry_agen[head2] <= `INV;
9051
        iqentry_mem[head0] <= `FALSE;
9052
        iqentry_mem[head1] <= `FALSE;
9053
        iqentry_mem[head2] <= `FALSE;
9054
        iqentry_iv[head0] <= `INV;
9055
        iqentry_iv[head1] <= `INV;
9056
        iqentry_iv[head2] <= `INV;
9057
        iqentry_alu[head0] <= `FALSE;
9058
        iqentry_alu[head1] <= `FALSE;
9059
        iqentry_alu[head2] <= `FALSE;
9060
        end
9061
    else if (amt==3'd2) begin
9062 48 robfinch
     iqentry_agen[head0] <= `INV;
9063
     iqentry_agen[head1] <= `INV;
9064 49 robfinch
     iqentry_mem[head0] <= `FALSE;
9065
     iqentry_mem[head1] <= `FALSE;
9066
     iqentry_iv[head0] <= `INV;
9067
     iqentry_iv[head1] <= `INV;
9068
        iqentry_alu[head0] <= `FALSE;
9069
     iqentry_alu[head1] <= `FALSE;
9070 48 robfinch
    end else if (amt==3'd1) begin
9071 49 robfinch
            iqentry_agen[head0] <= `INV;
9072
            iqentry_mem[head0] <= `FALSE;
9073
        iqentry_iv[head0] <= `INV;
9074
        iqentry_alu[head0] <= `FALSE;
9075 48 robfinch
        end
9076
end
9077
endtask
9078
 
9079
task setargs;
9080
input [`QBITS] nn;
9081
input [4:0] id;
9082
input v;
9083
input [63:0] bus;
9084
begin
9085
  if (iqentry_a1_v[nn] == `INV && iqentry_a1_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9086
                iqentry_a1[nn] <= bus;
9087
                iqentry_a1_v[nn] <= `VAL;
9088
  end
9089
  if (iqentry_a2_v[nn] == `INV && iqentry_a2_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9090
                iqentry_a2[nn] <= bus;
9091
                iqentry_a2_v[nn] <= `VAL;
9092
  end
9093
  if (iqentry_a3_v[nn] == `INV && iqentry_a3_s[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9094
                iqentry_a3[nn] <= bus;
9095
                iqentry_a3_v[nn] <= `VAL;
9096
  end
9097
end
9098
endtask
9099
 
9100
task setinsn;
9101
input [`QBITS] nn;
9102
input [4:0] id;
9103
input v;
9104
input [127:0] bus;
9105
begin
9106
  if (iqentry_iv[nn] == `INV && iqentry_is[nn] == id && iqentry_v[nn] == `VAL && v == `VAL) begin
9107
        iqentry_iv   [nn]  <= `VAL;
9108
//      iqentry_Rt   [nn]  <= bus[`IB_RT];
9109
//      iqentry_Rc   [nn]  <= bus[`IB_RC];
9110
//      iqentry_Ra   [nn]  <= bus[`IB_RA];
9111
        iqentry_a0       [nn]  <= bus[`IB_CONST];
9112
        iqentry_imm  [nn]  <= bus[`IB_IMM];
9113
                iqentry_insln[nn]  <= bus[`IB_LN];
9114
                iqentry_bt   [nn]  <= bus[`IB_BT];
9115
                iqentry_alu  [nn]  <= bus[`IB_ALU];
9116
                iqentry_alu0 [nn]  <= bus[`IB_ALU0];
9117
                iqentry_fpu  [nn]  <= bus[`IB_FPU];
9118
                iqentry_fc   [nn]  <= bus[`IB_FC];
9119
                iqentry_canex[nn]  <= bus[`IB_CANEX];
9120
                iqentry_load [nn]  <= bus[`IB_LOAD];
9121
                iqentry_preload[nn]<= bus[`IB_PRELOAD];
9122
                iqentry_mem  [nn]  <= bus[`IB_MEM];
9123
                iqentry_memndx[nn] <= bus[`IB_MEMNDX];
9124
                iqentry_rmw  [nn]  <= bus[`IB_RMW];
9125
                iqentry_memdb[nn]  <= bus[`IB_MEMDB];
9126
                iqentry_memsb[nn]  <= bus[`IB_MEMSB];
9127
                iqentry_shft48[nn] <= bus[`IB_SHFT48];
9128
                iqentry_sei      [nn]    <= bus[`IB_SEI];
9129
                iqentry_aq   [nn]  <= bus[`IB_AQ];
9130
                iqentry_rl   [nn]  <= bus[`IB_RL];
9131
                iqentry_jmp  [nn]  <= bus[`IB_JMP];
9132
                iqentry_br   [nn]  <= bus[`IB_BR];
9133
                iqentry_sync [nn]  <= bus[`IB_SYNC];
9134
                iqentry_fsync[nn]  <= bus[`IB_FSYNC];
9135
        iqentry_rfw  [nn]  <= bus[`IB_RFW];
9136
        iqentry_we   [nn]  <= bus[`IB_WE];
9137
  end
9138
end
9139
endtask
9140
 
9141
// Enqueue fetchbuf0 onto the tail of the instruction queue
9142
task enque0;
9143
input [`QBITS] tail;
9144
input [63:0] seqnum;
9145
input [5:0] venno;
9146
begin
9147
        iqentry_exc[tail] <= `FLT_NONE;
9148
`ifdef SUPPORT_DBG
9149
    if (dbg_imatchA)
9150
        iqentry_exc[tail] <= `FLT_DBG;
9151
    else if (dbg_ctrl[63])
9152
        iqentry_exc[tail] <= `FLT_SSM;
9153
`endif
9154
        iqentry_sn   [tail]    <=  seqnum;
9155
        iqentry_v    [tail]    <=   `VAL;
9156
        iqentry_iv       [tail]    <=   `INV;
9157
        iqentry_is   [tail]    <= tail;
9158
        iqentry_thrd [tail]    <=   fetchbuf0_thrd;
9159
        iqentry_done [tail]    <=    `INV;
9160
        iqentry_cmt  [tail]    <=       `INV;
9161
        iqentry_out  [tail]    <=    `INV;
9162
        iqentry_res  [tail]    <=    `ZERO;
9163
        iqentry_instr[tail]    <=    IsVLS(fetchbuf0_instr) ? (vm[fnM2(fetchbuf0_instr)] ? fetchbuf0_instr : `NOP_INSN) : fetchbuf0_instr;
9164
        iqentry_pt   [tail]    <=  predict_taken0;
9165
        iqentry_agen [tail]    <=    `INV;
9166
        iqentry_state[tail]    <=   IQS_IDLE;
9167
// If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9168
// inherit the previous pc.
9169
//if (IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15] &&
9170
//   (IsBrk(iqentry_instr[idm1(tail)]) && !iqentry_instr[idm1(tail1)][15] && iqentry_v[idm1(tail)]))
9171
//   iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
9172
//else
9173
         iqentry_pc   [tail] <= fetchbuf0_pc;
9174
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf0_instr);
9175
        iqentry_tgt  [tail]    <=       Rt0;
9176
        iqentry_Ra   [tail]    <= Ra0;
9177
        iqentry_Rb   [tail]    <= Rb0;
9178
        iqentry_Rc   [tail]    <= Rc0;
9179
        iqentry_vl   [tail]    <=  vl;
9180
        iqentry_ven  [tail]    <=   venno;
9181
        iqentry_exc  [tail]    <=    `EXC_NONE;
9182
        iqentry_a1   [tail]    <=    rfoa0;
9183
        iqentry_a1_v [tail]    <=    Source1Valid(fetchbuf0_instr) | regIsValid[Ra0s];
9184
        iqentry_a1_s [tail]    <=    rf_source[Ra0s];
9185
        iqentry_a2   [tail]    <=    rfob0;
9186
        iqentry_a2_v [tail]    <=    Source2Valid(fetchbuf0_instr) | regIsValid[Rb0s];
9187
        iqentry_a2_s [tail]    <=    rf_source[Rb0s];
9188
        iqentry_a3   [tail]    <=    rfoc0;
9189
        iqentry_a3_v [tail]    <=    Source3Valid(fetchbuf0_instr) | regIsValid[Rc0s];
9190
        iqentry_a3_s [tail]    <=    rf_source[Rc0s];
9191
end
9192
endtask
9193
 
9194
// Enque fetchbuf1. Fetchbuf1 might be the second instruction to queue so some
9195
// of this code checks to see which tail it is being queued on.
9196
task enque1;
9197
input [`QBITS] tail;
9198
input [63:0] seqnum;
9199
input [5:0] venno;
9200
begin
9201
 iqentry_exc[tail] <= `FLT_NONE;
9202
`ifdef SUPPORT_DBG
9203
    if (dbg_imatchB)
9204
        iqentry_exc[tail] <= `FLT_DBG;
9205
    else if (dbg_ctrl[63])
9206
        iqentry_exc[tail] <= `FLT_SSM;
9207
`endif
9208
        iqentry_sn   [tail]    <=   seqnum;
9209
        iqentry_v    [tail]    <=   `VAL;
9210
        iqentry_iv       [tail]    <=   `INV;
9211
        iqentry_is   [tail]    <= tail;
9212
        iqentry_thrd [tail]    <=   fetchbuf1_thrd;
9213
        iqentry_done [tail]    <=   `INV;
9214
        iqentry_cmt  [tail]    <=       `INV;
9215
        iqentry_out  [tail]    <=   `INV;
9216
        iqentry_res  [tail]    <=   `ZERO;
9217
        iqentry_instr[tail]    <=   IsVLS(fetchbuf1_instr) ? (vm[fnM2(fetchbuf1_instr)] ? fetchbuf1_instr : `NOP_INSN) : fetchbuf1_instr;
9218
        iqentry_pt   [tail]    <=  predict_taken1;
9219
        iqentry_agen [tail]    <=   `INV;
9220
        iqentry_state[tail]    <=   IQS_IDLE;
9221
// If queing 2nd instruction must read from first
9222
if (tail==tail1) begin
9223
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9224
    // inherit the previous pc.
9225
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
9226
//        IsBrk(fetchbuf0_instr) && !fetchbuf0_instr[15])
9227
//       iqentry_pc   [tail]    <= fetchbuf0_pc;
9228
//    else
9229
                iqentry_pc   [tail] <= fetchbuf1_pc;
9230
end
9231
else begin
9232
    // If the previous instruction was a hardware interrupt and this instruction is a hardware interrupt
9233
    // inherit the previous pc.
9234
//    if (IsBrk(fetchbuf1_instr) && !fetchbuf1_instr[15] &&
9235
//       (IsBrk(iqentry_instr[idp7(tail)]) && !iqentry_instr[idm1(tail)][15] && iqentry_v[idm1(tail)]))
9236
//       iqentry_pc   [tail]    <= iqentry_pc[idm1(tail)];
9237
//    else
9238
                iqentry_pc   [tail] <= fetchbuf1_pc;
9239
end
9240
        iqentry_rtop [tail]    <=   IsRtop(fetchbuf1_instr);
9241
        iqentry_tgt  [tail]    <= Rt1;
9242
        iqentry_Ra   [tail]    <= Ra1;
9243
        iqentry_Rb   [tail]    <= Rb1;
9244
        iqentry_Rc   [tail]    <= Rc1;
9245
        iqentry_vl   [tail]    <=  vl;
9246
        iqentry_ven  [tail]    <=   venno;
9247
        iqentry_exc  [tail]    <=   `EXC_NONE;
9248
        iqentry_a1   [tail]    <=       rfoa1;
9249
        iqentry_a1_v [tail]    <=       Source1Valid(fetchbuf1_instr) | regIsValid[Ra1s];
9250
        iqentry_a1_s [tail]    <=       rf_source[Ra1s];
9251
        iqentry_a2   [tail]    <=       rfob1;
9252
        iqentry_a2_v [tail]    <=       Source2Valid(fetchbuf1_instr) | regIsValid[Rb1s];
9253
        iqentry_a2_s [tail]    <=       rf_source[Rb1s];
9254
        iqentry_a3   [tail]    <=       rfoc1;
9255
        iqentry_a3_v [tail]    <=       Source3Valid(fetchbuf1_instr) | regIsValid[Rc1s];
9256
        iqentry_a3_s [tail]    <=       rf_source[Rc1s];
9257
end
9258
endtask
9259
 
9260
function IsOddball;
9261
input [`QBITS] head;
9262
if (|iqentry_exc[head])
9263
    IsOddball = TRUE;
9264
else
9265
case(iqentry_instr[head][`INSTRUCTION_OP])
9266
`BRK:   IsOddball = TRUE;
9267
`IVECTOR:
9268
    case(iqentry_instr[head][`INSTRUCTION_S2])
9269
    `VSxx:  IsOddball = TRUE;
9270
    default:    IsOddball = FALSE;
9271
    endcase
9272
`RR:
9273
    case(iqentry_instr[head][`INSTRUCTION_S2])
9274
    `VMOV:  IsOddball = TRUE;
9275
    `SEI,`RTI,`CACHEX: IsOddball = TRUE;
9276
    default:    IsOddball = FALSE;
9277
    endcase
9278
`CSRRW,`REX,`CACHE,`FLOAT:  IsOddball = TRUE;
9279
default:    IsOddball = FALSE;
9280
endcase
9281
endfunction
9282
 
9283
// This task takes care of commits for things other than the register file.
9284
task oddball_commit;
9285
input v;
9286
input [`QBITS] head;
9287
reg thread;
9288
begin
9289
    thread = iqentry_thrd[head];
9290
    if (v) begin
9291
        if (|iqentry_exc[head]) begin
9292
            excmiss <= TRUE;
9293
`ifdef SUPPORT_SMT
9294
                excmisspc <= {tvec[3'd0][31:8],ol[thread],5'h00};
9295
            excthrd <= iqentry_thrd[head];
9296
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
9297
            epc0[thread] <= iqentry_pc[head]+ 32'd4;
9298
            epc1[thread] <= epc0[thread];
9299
            epc2[thread] <= epc1[thread];
9300
            epc3[thread] <= epc2[thread];
9301
            epc4[thread] <= epc3[thread];
9302
            epc5[thread] <= epc4[thread];
9303
            epc6[thread] <= epc5[thread];
9304
            epc7[thread] <= epc6[thread];
9305
            epc8[thread] <= epc7[thread];
9306
            im_stack[thread] <= {im_stack[thread][27:0],im};
9307
            ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9308
            pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9309
            rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
9310
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
9311
            mstatus[thread][5:3] <= 3'd0;
9312
            mstatus[thread][13:6] <= 8'h00;
9313
            mstatus[thread][19:14] <= 6'd0;
9314
`else
9315
                excmisspc <= {tvec[3'd0][31:8],ol,5'h00};
9316
            excthrd <= iqentry_thrd[head];
9317
            badaddr[{thread,3'd0}] <= iqentry_a1[head];
9318
            epc0 <= iqentry_pc[head]+ 32'd4;
9319
            epc1 <= epc0;
9320
            epc2 <= epc1;
9321
            epc3 <= epc2;
9322
            epc4 <= epc3;
9323
            epc5 <= epc4;
9324
            epc6 <= epc5;
9325
            epc7 <= epc6;
9326
            epc8 <= epc7;
9327
            im_stack <= {im_stack[27:0],im};
9328
            ol_stack <= {ol_stack[13:0],ol};
9329
            pl_stack <= {pl_stack[55:0],cpl};
9330
            rs_stack <= {rs_stack[55:0],rgs};
9331
            cause[{thread,3'd0}] <= {8'd0,iqentry_exc[head]};
9332
            mstatus[5:3] <= 3'd0;
9333
            mstatus[13:6] <= 8'h00;
9334
            mstatus[19:14] <= 6'd0;
9335
`endif
9336 49 robfinch
                                                wb_en <= `TRUE;
9337 48 robfinch
            sema[0] <= 1'b0;
9338
            ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9339
`ifdef SUPPORT_DBG
9340
            dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9341
            dbg_ctrl[63] <= FALSE;
9342
`endif
9343
        end
9344
        else
9345
        case(iqentry_instr[head][`INSTRUCTION_OP])
9346
        `BRK:
9347
                        // BRK is treated as a nop unless it's a software interrupt or a
9348
                        // hardware interrupt at a higher priority than the current priority.
9349
                if ((iqentry_instr[head][23:19] > 5'd0) || iqentry_instr[head][18:16] > im) begin
9350
                            excmiss <= TRUE;
9351
`ifdef SUPPORT_SMT
9352
                        excmisspc <= {tvec[3'd0][31:8],ol[thread],5'h00};
9353
                        excthrd <= iqentry_thrd[head];
9354
                    epc0[thread] <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
9355
                    epc1[thread] <= epc0[thread];
9356
                    epc2[thread] <= epc1[thread];
9357
                    epc3[thread] <= epc2[thread];
9358
                    epc4[thread] <= epc3[thread];
9359
                    epc5[thread] <= epc4[thread];
9360
                    epc6[thread] <= epc5[thread];
9361
                    epc7[thread] <= epc6[thread];
9362
                    epc8[thread] <= epc7[thread];
9363
                    im_stack[thread] <= {im_stack[thread][27:0],im};
9364
                    ol_stack[thread] <= {ol_stack[thread][13:0],ol[thread]};
9365
                    pl_stack[thread] <= {pl_stack[thread][55:0],cpl[thread]};
9366
                    rs_stack[thread] <= {rs_stack[thread][55:0],rgs[thread]};
9367
                    mstatus[thread][19:14] <= 6'd0;
9368
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
9369
                    mstatus[thread][5:3] <= 3'd0;
9370
                        mstatus[thread][13:6] <= 8'h00;
9371
                    // For hardware interrupts only, set a new mask level
9372
                    // Select register set according to interrupt level
9373
                    if (iqentry_instr[head][23:19]==5'd0) begin
9374
                        mstatus[thread][2:0] <= 3'd7;//iqentry_instr[head][18:16];
9375
                        mstatus[thread][42:40] <= iqentry_instr[head][18:16];
9376
                        mstatus[thread][19:14] <= {3'b0,iqentry_instr[head][18:16]};
9377
                    end
9378
                    else
9379
                        mstatus[thread][19:14] <= 6'd0;
9380
`else
9381
                        excmisspc <= {tvec[3'd0][31:8],ol,5'h00};
9382
                        excthrd <= iqentry_thrd[head];
9383
                    epc0 <= iqentry_pc[head] + {iqentry_instr[head][23:19],2'b00};
9384
                    epc1 <= epc0;
9385
                    epc2 <= epc1;
9386
                    epc3 <= epc2;
9387
                    epc4 <= epc3;
9388
                    epc5 <= epc4;
9389
                    epc6 <= epc5;
9390
                    epc7 <= epc6;
9391
                    epc8 <= epc7;
9392
                    im_stack <= {im_stack[27:0],im};
9393
                    ol_stack <= {ol_stack[13:0],ol};
9394
                    pl_stack <= {pl_stack[55:0],cpl};
9395
                    rs_stack <= {rs_stack[55:0],rgs};
9396
                    mstatus[19:14] <= 6'd0;
9397
                    cause[{thread,3'd0}] <= {iqentry_instr[head][31:24],iqentry_instr[head][13:6]};
9398
                    mstatus[5:3] <= 3'd0;
9399
                        mstatus[13:6] <= 8'h00;
9400
                    // For hardware interrupts only, set a new mask level
9401
                    // Select register set according to interrupt level
9402
                    if (iqentry_instr[head][23:19]==5'd0) begin
9403
                        mstatus[2:0] <= 3'd7;//iqentry_instr[head][18:16];
9404
                        mstatus[42:40] <= iqentry_instr[head][18:16];
9405
                        mstatus[19:14] <= {3'b0,iqentry_instr[head][18:16]};
9406
                    end
9407
                    else
9408
                        mstatus[19:14] <= 6'd0;
9409
`endif
9410
                    sema[0] <= 1'b0;
9411
                    ve_hold <= {vqet1,10'd0,vqe1,10'd0,vqet0,10'd0,vqe0};
9412
`ifdef SUPPORT_DBG
9413
                    dbg_ctrl[62:55] <= {dbg_ctrl[61:55],dbg_ctrl[63]};
9414
                    dbg_ctrl[63] <= FALSE;
9415
`endif
9416
                end
9417
        `IVECTOR:
9418
            casez(iqentry_tgt[head])
9419
            8'b00100xxx:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9420
            8'b00101111:  vl <= iqentry_res[head];
9421
            default:    ;
9422
            endcase
9423
        `R2:
9424
            case(iqentry_instr[head][`INSTRUCTION_S2])
9425
            `R1:        case(iqentry_instr[head][20:16])
9426
                        `CHAIN_OFF:     cr0[18] <= 1'b0;
9427
                        `CHAIN_ON:      cr0[18] <= 1'b1;
9428
                        //`SETWB:               wbrcd[pcr[5:0]] <= 1'b1;
9429
                        default:        ;
9430
                                endcase
9431
            `VMOV:  casez(iqentry_tgt[head])
9432
                    12'b1111111_00???:  vm[iqentry_tgt[head][2:0]] <= iqentry_res[head];
9433
                    12'b1111111_01111:  vl <= iqentry_res[head];
9434
                    default:    ;
9435
                    endcase
9436
`ifdef SUPPORT_SMT
9437
            `SEI:   mstatus[thread][2:0] <= iqentry_res[head][2:0];   // S1
9438
`else
9439
            `SEI:   mstatus[2:0] <= iqentry_res[head][2:0];   // S1
9440
`endif
9441
            `RTI:   begin
9442
                            excmiss <= TRUE;
9443
`ifdef SUPPORT_SMT
9444
                        excmisspc <= epc0[thread];
9445
                        excthrd <= thread;
9446
                        mstatus[thread][3:0] <= im_stack[thread][3:0];
9447
                        mstatus[thread][5:4] <= ol_stack[thread][1:0];
9448
                        mstatus[thread][13:6] <= pl_stack[thread][7:0];
9449
                        mstatus[thread][19:14] <= rs_stack[thread][5:0];
9450
                        im_stack[thread] <= {4'd15,im_stack[thread][27:4]};
9451
                        ol_stack[thread] <= {2'd0,ol_stack[thread][15:2]};
9452
                        pl_stack[thread] <= {8'h00,pl_stack[thread][63:8]};
9453
                        rs_stack[thread] <= {8'h00,rs_stack[thread][63:8]};
9454
                    epc0[thread] <= epc1[thread];
9455
                    epc1[thread] <= epc2[thread];
9456
                    epc2[thread] <= epc3[thread];
9457
                    epc3[thread] <= epc4[thread];
9458
                    epc4[thread] <= epc5[thread];
9459
                    epc5[thread] <= epc6[thread];
9460
                    epc6[thread] <= epc7[thread];
9461
                    epc7[thread] <= epc8[thread];
9462
                    epc8[thread] <= {tvec[0][31:8], ol[thread], 5'h0};
9463
`else
9464
                        excmisspc <= epc0;
9465
                        excthrd <= thread;
9466
                        mstatus[3:0] <= im_stack[3:0];
9467
                        mstatus[5:4] <= ol_stack[1:0];
9468
                        mstatus[13:6] <= pl_stack[7:0];
9469
                        mstatus[19:14] <= rs_stack[5:0];
9470
                        im_stack <= {4'd15,im_stack[31:4]};
9471
                        ol_stack <= {2'd0,ol_stack[15:2]};
9472
                        pl_stack <= {8'h00,pl_stack[63:8]};
9473
                        rs_stack <= {8'h00,rs_stack[63:8]};
9474
                    epc0 <= epc1;
9475
                    epc1 <= epc2;
9476
                    epc2 <= epc3;
9477
                    epc3 <= epc4;
9478
                    epc4 <= epc5;
9479
                    epc5 <= epc6;
9480
                    epc6 <= epc7;
9481
                    epc7 <= epc8;
9482
                    epc8 <= {tvec[0][31:8], ol, 5'h0};
9483
`endif
9484
                    sema[0] <= 1'b0;
9485
                    sema[iqentry_res[head][5:0]] <= 1'b0;
9486
                    vqe0  <= ve_hold[ 5: 0];
9487
                    vqet0 <= ve_hold[21:16];
9488
                    vqe1  <= ve_hold[37:32];
9489
                    vqet1 <= ve_hold[53:48];
9490
`ifdef SUPPORT_DBG
9491
                    dbg_ctrl[62:55] <= {FALSE,dbg_ctrl[62:56]};
9492
                    dbg_ctrl[63] <= dbg_ctrl[55];
9493
`endif
9494
                    end
9495 49 robfinch
            default: ;
9496
            endcase
9497
        `MEMNDX:
9498
            case(iqentry_instr[head][`INSTRUCTION_S2])
9499 48 robfinch
            `CACHEX:
9500 49 robfinch
                    case(iqentry_instr[head][22:18])
9501 48 robfinch
                    5'h03:  invic <= TRUE;
9502
                    5'h10:  cr0[30] <= FALSE;
9503
                    5'h11:  cr0[30] <= TRUE;
9504
                    default:    ;
9505
                    endcase
9506
            default: ;
9507
            endcase
9508
        `CSRRW:
9509
                        begin
9510
                        write_csr(iqentry_instr[head][31:16],iqentry_a1[head],thread);
9511
                        end
9512
        `REX:
9513
`ifdef SUPPORT_SMT
9514
            // Can only redirect to a lower level
9515
            if (ol[thread] < iqentry_instr[head][13:11]) begin
9516
                mstatus[thread][5:3] <= iqentry_instr[head][13:11];
9517
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol[thread]}];
9518
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol[thread]}];
9519
                mstatus[thread][13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
9520
            end
9521
`else
9522
            if (ol < iqentry_instr[head][13:11]) begin
9523
                mstatus[5:3] <= iqentry_instr[head][13:11];
9524
                badaddr[{thread,iqentry_instr[head][13:11]}] <= badaddr[{thread,ol}];
9525
                cause[{thread,iqentry_instr[head][13:11]}] <= cause[{thread,ol}];
9526
                mstatus[13:6] <= iqentry_instr[head][23:16] | iqentry_a1[head][7:0];
9527
            end
9528
`endif
9529
        `CACHE:
9530 49 robfinch
            case(iqentry_instr[head][17:13])
9531 48 robfinch
            5'h03:  invic <= TRUE;
9532
            5'h10:  cr0[30] <= FALSE;
9533
            5'h11:  cr0[30] <= TRUE;
9534
            default:    ;
9535
            endcase
9536
        `FLOAT:
9537
            case(iqentry_instr[head][`INSTRUCTION_S2])
9538 49 robfinch
            `FRM: begin
9539
                                fp1_rm <= iqentry_res[head][2:0];
9540
                                fp2_rm <= iqentry_res[head][2:0];
9541
                                end
9542 48 robfinch
            `FCX:
9543
                begin
9544 49 robfinch
                    fp1_sx <= fp1_sx & ~iqentry_res[head][5];
9545
                    fp1_inex <= fp1_inex & ~iqentry_res[head][4];
9546
                    fp1_dbzx <= fp1_dbzx & ~(iqentry_res[head][3]|iqentry_res[head][0]);
9547
                    fp1_underx <= fp1_underx & ~iqentry_res[head][2];
9548
                    fp1_overx <= fp1_overx & ~iqentry_res[head][1];
9549
                    fp1_giopx <= fp1_giopx & ~iqentry_res[head][0];
9550
                    fp1_infdivx <= fp1_infdivx & ~iqentry_res[head][0];
9551
                    fp1_zerozerox <= fp1_zerozerox & ~iqentry_res[head][0];
9552
                    fp1_subinfx   <= fp1_subinfx   & ~iqentry_res[head][0];
9553
                    fp1_infzerox  <= fp1_infzerox  & ~iqentry_res[head][0];
9554
                    fp1_NaNCmpx   <= fp1_NaNCmpx   & ~iqentry_res[head][0];
9555
                    fp1_swtx <= 1'b0;
9556 48 robfinch
                end
9557
            `FDX:
9558
                begin
9559 49 robfinch
                    fp1_inexe <= fp1_inexe     & ~iqentry_res[head][4];
9560
                    fp1_dbzxe <= fp1_dbzxe     & ~iqentry_res[head][3];
9561
                    fp1_underxe <= fp1_underxe & ~iqentry_res[head][2];
9562
                    fp1_overxe <= fp1_overxe   & ~iqentry_res[head][1];
9563
                    fp1_invopxe <= fp1_invopxe & ~iqentry_res[head][0];
9564 48 robfinch
                end
9565
            `FEX:
9566
                begin
9567 49 robfinch
                    fp1_inexe <= fp1_inexe     | iqentry_res[head][4];
9568
                    fp1_dbzxe <= fp1_dbzxe     | iqentry_res[head][3];
9569
                    fp1_underxe <= fp1_underxe | iqentry_res[head][2];
9570
                    fp1_overxe <= fp1_overxe   | iqentry_res[head][1];
9571
                    fp1_invopxe <= fp1_invopxe | iqentry_res[head][0];
9572 48 robfinch
                end
9573
            default:
9574
                begin
9575
                    // 31 to 29 is rounding mode
9576
                    // 28 to 24 are exception enables
9577
                    // 23 is nsfp
9578
                    // 22 is a fractie
9579 49 robfinch
                    fp1_fractie <= iqentry_a0[head][22];
9580
                    fp1_raz <= iqentry_a0[head][21];
9581 48 robfinch
                    // 20 is a 0
9582 49 robfinch
                    fp1_neg <= iqentry_a0[head][19];
9583
                    fp1_pos <= iqentry_a0[head][18];
9584
                    fp1_zero <= iqentry_a0[head][17];
9585
                    fp1_inf <= iqentry_a0[head][16];
9586 48 robfinch
                    // 15 swtx
9587
                    // 14 
9588 49 robfinch
                    fp1_inex <= fp1_inex | (fp1_inexe & iqentry_a0[head][14]);
9589
                    fp1_dbzx <= fp1_dbzx | (fp1_dbzxe & iqentry_a0[head][13]);
9590
                    fp1_underx <= fp1_underx | (fp1_underxe & iqentry_a0[head][12]);
9591
                    fp1_overx <= fp1_overx | (fp1_overxe & iqentry_a0[head][11]);
9592 48 robfinch
                    //fp_giopx <= fp_giopx | (fp_giopxe & iqentry_res2[head][10]);
9593
                    //fp_invopx <= fp_invopx | (fp_invopxe & iqentry_res2[head][24]);
9594
                    //
9595 49 robfinch
                    fp1_cvtx <= fp1_cvtx |  (fp1_giopxe & iqentry_a0[head][7]);
9596
                    fp1_sqrtx <= fp1_sqrtx |  (fp1_giopxe & iqentry_a0[head][6]);
9597
                    fp1_NaNCmpx <= fp1_NaNCmpx |  (fp1_giopxe & iqentry_a0[head][5]);
9598
                    fp1_infzerox <= fp1_infzerox |  (fp1_giopxe & iqentry_a0[head][4]);
9599
                    fp1_zerozerox <= fp1_zerozerox |  (fp1_giopxe & iqentry_a0[head][3]);
9600
                    fp1_infdivx <= fp1_infdivx | (fp1_giopxe & iqentry_a0[head][2]);
9601
                    fp1_subinfx <= fp1_subinfx | (fp1_giopxe & iqentry_a0[head][1]);
9602
                    fp1_snanx <= fp1_snanx | (fp1_giopxe & iqentry_a0[head][0]);
9603 48 robfinch
 
9604
                end
9605
            endcase
9606
        default:    ;
9607
        endcase
9608
        // Once the flow control instruction commits, NOP it out to allow
9609
        // pending stores to be issued.
9610
        iqentry_instr[head][5:0] <= `NOP;
9611
    end
9612
end
9613
endtask
9614
 
9615
// CSR access tasks
9616
task read_csr;
9617
input [13:0] csrno;
9618
output [63:0] dat;
9619
input thread;
9620
begin
9621
`ifdef SUPPORT_SMT
9622
    if (csrno[11:10] >= ol[thread])
9623
`else
9624
    if (csrno[11:10] >= ol)
9625
`endif
9626
    casez(csrno[9:0])
9627
    `CSR_CR0:       dat <= cr0;
9628
    `CSR_HARTID:    dat <= hartid;
9629
    `CSR_TICK:      dat <= tick;
9630
    `CSR_PCR:       dat <= pcr;
9631
    `CSR_PCR2:      dat <= pcr2;
9632 49 robfinch
    `CSR_PMR:                           dat <= pmr;
9633 48 robfinch
    `CSR_WBRCD:         dat <= wbrcd;
9634
    `CSR_SEMA:      dat <= sema;
9635
    `CSR_SBL:       dat <= sbl;
9636
    `CSR_SBU:       dat <= sbu;
9637
    `CSR_TCB:           dat <= tcb;
9638 49 robfinch
    `CSR_FSTAT:     dat <= {fp1_rgs,fp1_status};
9639 48 robfinch
`ifdef SUPPORT_DBG
9640
    `CSR_DBAD0:     dat <= dbg_adr0;
9641
    `CSR_DBAD1:     dat <= dbg_adr1;
9642
    `CSR_DBAD2:     dat <= dbg_adr2;
9643
    `CSR_DBAD3:     dat <= dbg_adr3;
9644
    `CSR_DBCTRL:    dat <= dbg_ctrl;
9645
    `CSR_DBSTAT:    dat <= dbg_stat;
9646
`endif
9647
    `CSR_CAS:       dat <= cas;
9648
    `CSR_TVEC:      dat <= tvec[csrno[2:0]];
9649
    `CSR_BADADR:    dat <= badaddr[{thread,csrno[13:11]}];
9650
    `CSR_CAUSE:     dat <= {48'd0,cause[{thread,csrno[13:11]}]};
9651
`ifdef SUPPORT_SMT
9652
    `CSR_IM_STACK:      dat <= im_stack[thread];
9653
    `CSR_OL_STACK:      dat <= ol_stack[thread];
9654
    `CSR_PL_STACK:      dat <= pl_stack[thread];
9655
    `CSR_RS_STACK:      dat <= rs_stack[thread];
9656
    `CSR_STATUS:    dat <= mstatus[thread][63:0];
9657
    `CSR_EPC0:      dat <= epc0[thread];
9658
    `CSR_EPC1:      dat <= epc1[thread];
9659
    `CSR_EPC2:      dat <= epc2[thread];
9660
    `CSR_EPC3:      dat <= epc3[thread];
9661
    `CSR_EPC4:      dat <= epc4[thread];
9662
    `CSR_EPC5:      dat <= epc5[thread];
9663
    `CSR_EPC6:      dat <= epc6[thread];
9664
    `CSR_EPC7:      dat <= epc7[thread];
9665
`else
9666
    `CSR_IM_STACK:      dat <= im_stack;
9667
    `CSR_OL_STACK:      dat <= ol_stack;
9668
    `CSR_PL_STACK:      dat <= pl_stack;
9669
    `CSR_RS_STACK:      dat <= rs_stack;
9670
    `CSR_STATUS:    dat <= mstatus[63:0];
9671
    `CSR_EPC0:      dat <= epc0;
9672
    `CSR_EPC1:      dat <= epc1;
9673
    `CSR_EPC2:      dat <= epc2;
9674
    `CSR_EPC3:      dat <= epc3;
9675
    `CSR_EPC4:      dat <= epc4;
9676
    `CSR_EPC5:      dat <= epc5;
9677
    `CSR_EPC6:      dat <= epc6;
9678
    `CSR_EPC7:      dat <= epc7;
9679
`endif
9680
    `CSR_CODEBUF:   dat <= codebuf[csrno[5:0]];
9681
    `CSR_TIME:          dat <= wc_times;
9682
    `CSR_INFO:
9683
                    case(csrno[3:0])
9684
                    4'd0:   dat <= "Finitron";  // manufacturer
9685
                    4'd1:   dat <= "        ";
9686
                    4'd2:   dat <= "64 bit  ";  // CPU class
9687
                    4'd3:   dat <= "        ";
9688
                    4'd4:   dat <= "FT64    ";  // Name
9689
                    4'd5:   dat <= "        ";
9690
                    4'd6:   dat <= 64'd1;       // model #
9691
                    4'd7:   dat <= 64'd1;       // serial number
9692
                    4'd8:   dat <= {32'd16384,32'd16384};   // cache sizes instruction,data
9693
                    4'd9:   dat <= 64'd0;
9694
                    default:    dat <= 64'd0;
9695
                    endcase
9696
    default:    begin
9697
                        $display("Unsupported CSR:%h",csrno[10:0]);
9698
                        dat <= 64'hEEEEEEEEEEEEEEEE;
9699
                        end
9700
    endcase
9701
    else
9702
        dat <= 64'h0;
9703
end
9704
endtask
9705
 
9706
task write_csr;
9707
input [13:0] csrno;
9708
input [63:0] dat;
9709
input thread;
9710
begin
9711
`ifdef SUPPORT_SMT
9712
    if (csrno[11:10] >= ol[thread])
9713
`else
9714
    if (csrno[11:10] >= ol)
9715
`endif
9716
    case(csrno[13:12])
9717
    2'd1:   // CSRRW
9718
        casez(csrno[9:0])
9719
        `CSR_CR0:       cr0 <= dat;
9720
        `CSR_PCR:       pcr <= dat[31:0];
9721
        `CSR_PCR2:      pcr2 <= dat;
9722 49 robfinch
        `CSR_PMR:       case(`NUM_IDU)
9723
                                                0,1:     pmr[0] <= 1'b1;
9724
                                                2:
9725
                                                        begin
9726
                                                                        if (dat[1:0]==2'b00)
9727
                                                                                pmr[1:0] <= 2'b01;
9728
                                                                        else
9729
                                                                                pmr[1:0] <= dat[1:0];
9730
                                                                        pmr[63:2] <= dat[63:2];
9731
                                                                end
9732
                                                3:
9733
                                                        begin
9734
                                                                        if (dat[2:0]==3'b000)
9735
                                                                                pmr[2:0] <= 3'b001;
9736
                                                                        else
9737
                                                                                pmr[2:0] <= dat[2:0];
9738
                                                                        pmr[63:3] <= dat[63:3];
9739
                                                                end
9740
                                                default:        pmr[0] <= 1'b1;
9741
                                                endcase
9742 48 robfinch
        `CSR_WBRCD:             wbrcd <= dat;
9743
        `CSR_SEMA:      sema <= dat;
9744
        `CSR_SBL:       sbl <= dat[31:0];
9745
        `CSR_SBU:       sbu <= dat[31:0];
9746
        `CSR_TCB:               tcb <= dat;
9747 49 robfinch
        `CSR_FSTAT:             fpu1_csr[37:32] <= dat[37:32];
9748 48 robfinch
        `CSR_BADADR:    badaddr[{thread,csrno[13:11]}] <= dat;
9749
        `CSR_CAUSE:     cause[{thread,csrno[13:11]}] <= dat[15:0];
9750
`ifdef SUPPORT_DBG
9751
        `CSR_DBAD0:     dbg_adr0 <= dat[AMSB:0];
9752
        `CSR_DBAD1:     dbg_adr1 <= dat[AMSB:0];
9753
        `CSR_DBAD2:     dbg_adr2 <= dat[AMSB:0];
9754
        `CSR_DBAD3:     dbg_adr3 <= dat[AMSB:0];
9755
        `CSR_DBCTRL:    dbg_ctrl <= dat;
9756
`endif
9757
        `CSR_CAS:       cas <= dat;
9758
        `CSR_TVEC:      tvec[csrno[2:0]] <= dat[31:0];
9759
`ifdef SUPPORT_SMT
9760
        `CSR_IM_STACK:  im_stack[thread] <= dat[31:0];
9761
        `CSR_OL_STACK:  ol_stack[thread] <= dat[15:0];
9762
        `CSR_PL_STACK:  pl_stack[thread] <= dat;
9763
        `CSR_RS_STACK:  rs_stack[thread] <= dat;
9764
        `CSR_STATUS:    mstatus[thread][63:0] <= dat;
9765
        `CSR_EPC0:      epc0[thread] <= dat;
9766
        `CSR_EPC1:      epc1[thread] <= dat;
9767
        `CSR_EPC2:      epc2[thread] <= dat;
9768
        `CSR_EPC3:      epc3[thread] <= dat;
9769
        `CSR_EPC4:      epc4[thread] <= dat;
9770
        `CSR_EPC5:      epc5[thread] <= dat;
9771
        `CSR_EPC6:      epc6[thread] <= dat;
9772
        `CSR_EPC7:      epc7[thread] <= dat;
9773
`else
9774
        `CSR_IM_STACK:  im_stack <= dat[31:0];
9775
        `CSR_OL_STACK:  ol_stack <= dat[15:0];
9776
        `CSR_PL_STACK:  pl_stack <= dat;
9777
        `CSR_RS_STACK:  rs_stack <= dat;
9778
        `CSR_STATUS:    mstatus[63:0] <= dat;
9779
        `CSR_EPC0:      epc0 <= dat;
9780
        `CSR_EPC1:      epc1 <= dat;
9781
        `CSR_EPC2:      epc2 <= dat;
9782
        `CSR_EPC3:      epc3 <= dat;
9783
        `CSR_EPC4:      epc4 <= dat;
9784
        `CSR_EPC5:      epc5 <= dat;
9785
        `CSR_EPC6:      epc6 <= dat;
9786
        `CSR_EPC7:      epc7 <= dat;
9787
`endif
9788
                `CSR_TIME:              begin
9789
                                                ld_time <= 6'h3f;
9790
                                                wc_time_dat <= dat;
9791
                                                end
9792
        `CSR_CODEBUF:   codebuf[csrno[5:0]] <= dat;
9793
        default:    ;
9794
        endcase
9795
    2'd2:   // CSRRS
9796
        case(csrno[9:0])
9797
        `CSR_CR0:       cr0 <= cr0 | dat;
9798
        `CSR_PCR:       pcr[31:0] <= pcr[31:0] | dat[31:0];
9799
        `CSR_PCR2:      pcr2 <= pcr2 | dat;
9800 49 robfinch
        `CSR_PMR:                               pmr <= pmr | dat;
9801 48 robfinch
        `CSR_WBRCD:             wbrcd <= wbrcd | dat;
9802
`ifdef SUPPORT_DBG
9803
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl | dat;
9804
`endif
9805
        `CSR_SEMA:      sema <= sema | dat;
9806
`ifdef SUPPORT_SMT
9807
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] | dat;
9808
`else
9809
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] | dat;
9810
`endif
9811
        default:    ;
9812
        endcase
9813
    2'd3:   // CSRRC
9814
        case(csrno[9:0])
9815
        `CSR_CR0:       cr0 <= cr0 & ~dat;
9816
        `CSR_PCR:       pcr <= pcr & ~dat;
9817
        `CSR_PCR2:      pcr2 <= pcr2 & ~dat;
9818 49 robfinch
        `CSR_PMR:                       begin
9819
                                                                if (dat[1:0]==2'b11)
9820
                                                                        pmr[1:0] <= 2'b01;
9821
                                                                else
9822
                                                                        pmr[1:0] <= pmr[1:0] & ~dat[1:0];
9823
                                                                pmr[63:2] <= pmr[63:2] & ~dat[63:2];
9824
                                                                end
9825 48 robfinch
        `CSR_WBRCD:             wbrcd <= wbrcd & ~dat;
9826
`ifdef SUPPORT_DBG
9827
        `CSR_DBCTRL:    dbg_ctrl <= dbg_ctrl & ~dat;
9828
`endif
9829
        `CSR_SEMA:      sema <= sema & ~dat;
9830
`ifdef SUPPORT_SMT
9831
        `CSR_STATUS:    mstatus[thread][63:0] <= mstatus[thread][63:0] & ~dat;
9832
`else
9833
        `CSR_STATUS:    mstatus[63:0] <= mstatus[63:0] & ~dat;
9834
`endif
9835
        default:    ;
9836
        endcase
9837
    default:    ;
9838
    endcase
9839
end
9840
endtask
9841
 
9842
/*
9843
task aluissue;
9844
input alu_idle;
9845
input [QENTRIES-1:0] iq_alu0;
9846
input [1:0] slot;
9847
begin
9848
        if (alu_idle) begin
9849
                if (could_issue[head0] && iqentry_alu[head0]
9850
                && !iq_alu0[head0]      // alu0only
9851
                && !iqentry_issue[head0]) begin
9852
                  iqentry_issue[head0] = `TRUE;
9853
                  iqentry_islot[head0] = slot;
9854
                end
9855
                else if (could_issue[head1] && !iqentry_issue[head1] && iqentry_alu[head1]
9856
                && !iq_alu0[head1])
9857
                begin
9858
                  iqentry_issue[head1] = `TRUE;
9859
                  iqentry_islot[head1] = slot;
9860
                end
9861
                else if (could_issue[head2] && !iqentry_issue[head2] && iqentry_alu[head2]
9862
                && !iq_alu0[head2]
9863
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
9864
                )
9865
                begin
9866
                        iqentry_issue[head2] = `TRUE;
9867
                        iqentry_islot[head2] = slot;
9868
                end
9869
                else if (could_issue[head3] && !iqentry_issue[head3] && iqentry_alu[head3]
9870
                && !iq_alu0[head3]
9871
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
9872
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
9873
                                ((!iqentry_v[head0])
9874
                        &&   (!iqentry_v[head1]))
9875
                        )
9876
                ) begin
9877
                        iqentry_issue[head3] = `TRUE;
9878
                        iqentry_islot[head3] = slot;
9879
                end
9880
                else if (could_issue[head4] && !iqentry_issue[head4] && iqentry_alu[head4]
9881
                && !iq_alu0[head4]
9882
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
9883
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
9884
                                ((!iqentry_v[head0])
9885
                        &&   (!iqentry_v[head1]))
9886
                        )
9887
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
9888
                                ((!iqentry_v[head0])
9889
                        &&   (!iqentry_v[head1])
9890
                        &&   (!iqentry_v[head2]))
9891
                        )
9892
                ) begin
9893
                        iqentry_issue[head4] = `TRUE;
9894
                        iqentry_islot[head4] = slot;
9895
                end
9896
                else if (could_issue[head5] && !iqentry_issue[head5] && iqentry_alu[head5]
9897
                && !iq_alu0[head5]
9898
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
9899
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
9900
                                ((!iqentry_v[head0])
9901
                        &&   (!iqentry_v[head1]))
9902
                        )
9903
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
9904
                                ((!iqentry_v[head0])
9905
                        &&   (!iqentry_v[head1])
9906
                        &&   (!iqentry_v[head2]))
9907
                        )
9908
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
9909
                                ((!iqentry_v[head0])
9910
                        &&   (!iqentry_v[head1])
9911
                        &&   (!iqentry_v[head2])
9912
                        &&   (!iqentry_v[head3]))
9913
                        )
9914
                ) begin
9915
                        iqentry_issue[head5] = `TRUE;
9916
                        iqentry_islot[head5] = slot;
9917
                end
9918
                else if (could_issue[head6] && !iqentry_issue[head6] && iqentry_alu[head6]
9919
                && !iq_alu0[head6]
9920
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
9921
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
9922
                                ((!iqentry_v[head0])
9923
                        &&   (!iqentry_v[head1]))
9924
                        )
9925
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
9926
                                ((!iqentry_v[head0])
9927
                        &&   (!iqentry_v[head1])
9928
                        &&   (!iqentry_v[head2]))
9929
                        )
9930
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
9931
                                ((!iqentry_v[head0])
9932
                        &&   (!iqentry_v[head1])
9933
                        &&   (!iqentry_v[head2])
9934
                        &&   (!iqentry_v[head3]))
9935
                        )
9936
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
9937
                                ((!iqentry_v[head0])
9938
                        &&   (!iqentry_v[head1])
9939
                        &&   (!iqentry_v[head2])
9940
                        &&   (!iqentry_v[head3])
9941
                        &&   (!iqentry_v[head4]))
9942
                        )
9943
                ) begin
9944
                        iqentry_issue[head6] = `TRUE;
9945
                        iqentry_islot[head6] = slot;
9946
                end
9947
                else if (could_issue[head7] && !iqentry_issue[head7] && iqentry_alu[head7]
9948
                && !iq_alu0[head7]
9949
                && (!(iqentry_v[head1] && iqentry_sync[head1]) || !iqentry_v[head0])
9950
                && (!(iqentry_v[head2] && iqentry_sync[head2]) ||
9951
                                ((!iqentry_v[head0])
9952
                        &&   (!iqentry_v[head1]))
9953
                        )
9954
                && (!(iqentry_v[head3] && iqentry_sync[head3]) ||
9955
                                ((!iqentry_v[head0])
9956
                        &&   (!iqentry_v[head1])
9957
                        &&   (!iqentry_v[head2]))
9958
                        )
9959
                && (!(iqentry_v[head4] && iqentry_sync[head4]) ||
9960
                                ((!iqentry_v[head0])
9961
                        &&   (!iqentry_v[head1])
9962
                        &&   (!iqentry_v[head2])
9963
                        &&   (!iqentry_v[head3]))
9964
                        )
9965
                && (!(iqentry_v[head5] && iqentry_sync[head5]) ||
9966
                                ((!iqentry_v[head0])
9967
                        &&   (!iqentry_v[head1])
9968
                        &&   (!iqentry_v[head2])
9969
                        &&   (!iqentry_v[head3])
9970
                        &&   (!iqentry_v[head4]))
9971
                        )
9972
                && (!(iqentry_v[head6] && iqentry_sync[head6]) ||
9973
                                ((!iqentry_v[head0])
9974
                        &&   (!iqentry_v[head1])
9975
                        &&   (!iqentry_v[head2])
9976
                        &&   (!iqentry_v[head3])
9977
                        &&   (!iqentry_v[head4])
9978
                        &&   (!iqentry_v[head5]))
9979
                        )
9980
                ) begin
9981
                        iqentry_issue[head7] = `TRUE;
9982
                        iqentry_islot[head7] = slot;
9983
                end
9984
        end
9985
end
9986
endtask
9987
 
9988
task fpuissue;
9989
input fp_idle;
9990
input [1:0] slot;
9991
begin
9992
        if (fp_idle) begin
9993
    if (could_issue[head0] && iqentry_fpu[head0]) begin
9994
      iqentry_fpu_issue[head0] = `TRUE;
9995
      iqentry_fpu_islot[head0] = slot;
9996
    end
9997
    else if (could_issue[head1] && iqentry_fpu[head1])
9998
    begin
9999
      iqentry_fpu_issue[head1] = `TRUE;
10000
      iqentry_fpu_islot[head1] = slot;
10001
    end
10002
    else if (could_issue[head2] && iqentry_fpu[head2]
10003
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
10004
    ) begin
10005
      iqentry_fpu_issue[head2] = `TRUE;
10006
      iqentry_fpu_islot[head2] = slot;
10007
    end
10008
    else if (could_issue[head3] && iqentry_fpu[head3]
10009
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
10010
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
10011
                ((!iqentry_v[head0])
10012
        &&   (!iqentry_v[head1]))
10013
        )
10014
    ) begin
10015
      iqentry_fpu_issue[head3] = `TRUE;
10016
      iqentry_fpu_islot[head3] = slot;
10017
    end
10018
    else if (could_issue[head4] && iqentry_fpu[head4]
10019
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
10020
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
10021
                ((!iqentry_v[head0])
10022
        &&   (!iqentry_v[head1]))
10023
        )
10024
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
10025
                ((!iqentry_v[head0])
10026
        &&   (!iqentry_v[head1])
10027
        &&   (!iqentry_v[head2]))
10028
        )
10029
    ) begin
10030
      iqentry_fpu_issue[head4] = `TRUE;
10031
      iqentry_fpu_islot[head4] = slot;
10032
    end
10033
    else if (could_issue[head5] && iqentry_fpu[head5]
10034
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
10035
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
10036
                ((!iqentry_v[head0])
10037
        &&   (!iqentry_v[head1]))
10038
        )
10039
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
10040
                ((!iqentry_v[head0])
10041
        &&   (!iqentry_v[head1])
10042
        &&   (!iqentry_v[head2]))
10043
        )
10044
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
10045
                ((!iqentry_v[head0])
10046
        &&   (!iqentry_v[head1])
10047
        &&   (!iqentry_v[head2])
10048
        &&   (!iqentry_v[head3]))
10049
        )
10050
        ) begin
10051
              iqentry_fpu_issue[head5] = `TRUE;
10052
              iqentry_fpu_islot[head5] = slot;
10053
    end
10054
    else if (could_issue[head6] && iqentry_fpu[head6]
10055
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
10056
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
10057
                ((!iqentry_v[head0])
10058
        &&   (!iqentry_v[head1]))
10059
        )
10060
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
10061
                ((!iqentry_v[head0])
10062
        &&   (!iqentry_v[head1])
10063
        &&   (!iqentry_v[head2]))
10064
        )
10065
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
10066
                ((!iqentry_v[head0])
10067
        &&   (!iqentry_v[head1])
10068
        &&   (!iqentry_v[head2])
10069
        &&   (!iqentry_v[head3]))
10070
        )
10071
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
10072
                ((!iqentry_v[head0])
10073
        &&   (!iqentry_v[head1])
10074
        &&   (!iqentry_v[head2])
10075
        &&   (!iqentry_v[head3])
10076
        &&   (!iqentry_v[head4]))
10077
        )
10078
    ) begin
10079
        iqentry_fpu_issue[head6] = `TRUE;
10080
            iqentry_fpu_islot[head6] = slot;
10081
    end
10082
    else if (could_issue[head7] && iqentry_fpu[head7]
10083
    && (!(iqentry_v[head1] && (iqentry_sync[head1] || iqentry_fsync[head1])) || !iqentry_v[head0])
10084
    && (!(iqentry_v[head2] && (iqentry_sync[head2] || iqentry_fsync[head2])) ||
10085
                ((!iqentry_v[head0])
10086
        &&   (!iqentry_v[head1]))
10087
        )
10088
    && (!(iqentry_v[head3] && (iqentry_sync[head3] || iqentry_fsync[head3])) ||
10089
                ((!iqentry_v[head0])
10090
        &&   (!iqentry_v[head1])
10091
        &&   (!iqentry_v[head2]))
10092
        )
10093
    && (!(iqentry_v[head4] && (iqentry_sync[head4] || iqentry_fsync[head4])) ||
10094
                ((!iqentry_v[head0])
10095
        &&   (!iqentry_v[head1])
10096
        &&   (!iqentry_v[head2])
10097
        &&   (!iqentry_v[head3]))
10098
        )
10099
    && (!(iqentry_v[head5] && (iqentry_sync[head5] || iqentry_fsync[head5])) ||
10100
                ((!iqentry_v[head0])
10101
        &&   (!iqentry_v[head1])
10102
        &&   (!iqentry_v[head2])
10103
        &&   (!iqentry_v[head3])
10104
        &&   (!iqentry_v[head4]))
10105
        )
10106
    && (!(iqentry_v[head6] && (iqentry_sync[head6] || iqentry_fsync[head6])) ||
10107
                ((!iqentry_v[head0])
10108
        &&   (!iqentry_v[head1])
10109
        &&   (!iqentry_v[head2])
10110
        &&   (!iqentry_v[head3])
10111
        &&   (!iqentry_v[head4])
10112
        &&   (!iqentry_v[head5]))
10113
        )
10114
        )
10115
    begin
10116
                iqentry_fpu_issue[head7] = `TRUE;
10117
                iqentry_fpu_islot[head7] = slot;
10118
        end
10119
        end
10120
end
10121
endtask
10122
*/
10123
endmodule
10124
 
10125
 
10126
module decoder5 (num, out);
10127
input [4:0] num;
10128
output [31:1] out;
10129
reg [31:1] out;
10130
 
10131
always @(num)
10132
case (num)
10133
    5'd0 :      out <= 31'b0000000000000000000000000000000;
10134
    5'd1 :      out <= 31'b0000000000000000000000000000001;
10135
    5'd2 :      out <= 31'b0000000000000000000000000000010;
10136
    5'd3 :      out <= 31'b0000000000000000000000000000100;
10137
    5'd4 :      out <= 31'b0000000000000000000000000001000;
10138
    5'd5 :      out <= 31'b0000000000000000000000000010000;
10139
    5'd6 :      out <= 31'b0000000000000000000000000100000;
10140
    5'd7 :      out <= 31'b0000000000000000000000001000000;
10141
    5'd8 :      out <= 31'b0000000000000000000000010000000;
10142
    5'd9 :      out <= 31'b0000000000000000000000100000000;
10143
    5'd10:      out <= 31'b0000000000000000000001000000000;
10144
    5'd11:      out <= 31'b0000000000000000000010000000000;
10145
    5'd12:      out <= 31'b0000000000000000000100000000000;
10146
    5'd13:      out <= 31'b0000000000000000001000000000000;
10147
    5'd14:      out <= 31'b0000000000000000010000000000000;
10148
    5'd15:      out <= 31'b0000000000000000100000000000000;
10149
    5'd16:      out <= 31'b0000000000000001000000000000000;
10150
    5'd17:      out <= 31'b0000000000000010000000000000000;
10151
    5'd18:      out <= 31'b0000000000000100000000000000000;
10152
    5'd19:      out <= 31'b0000000000001000000000000000000;
10153
    5'd20:      out <= 31'b0000000000010000000000000000000;
10154
    5'd21:      out <= 31'b0000000000100000000000000000000;
10155
    5'd22:      out <= 31'b0000000001000000000000000000000;
10156
    5'd23:      out <= 31'b0000000010000000000000000000000;
10157
    5'd24:      out <= 31'b0000000100000000000000000000000;
10158
    5'd25:      out <= 31'b0000001000000000000000000000000;
10159
    5'd26:      out <= 31'b0000010000000000000000000000000;
10160
    5'd27:      out <= 31'b0000100000000000000000000000000;
10161
    5'd28:      out <= 31'b0001000000000000000000000000000;
10162
    5'd29:      out <= 31'b0010000000000000000000000000000;
10163
    5'd30:      out <= 31'b0100000000000000000000000000000;
10164
    5'd31:      out <= 31'b1000000000000000000000000000000;
10165
endcase
10166
 
10167
endmodule
10168
 
10169
module decoder6 (num, out);
10170
input [5:0] num;
10171
output [63:1] out;
10172
 
10173
wire [63:0] out1;
10174
 
10175
assign out1 = 64'd1 << num;
10176
assign out = out1[63:1];
10177
 
10178
endmodule
10179
 
10180
module decoder7 (num, out);
10181
input [6:0] num;
10182
output [127:1] out;
10183
 
10184
wire [127:0] out1;
10185
 
10186
assign out1 = 128'd1 << num;
10187
assign out = out1[127:1];
10188
 
10189
endmodule
10190
 
10191
module decoder8 (num, out);
10192
input [7:0] num;
10193
output [255:1] out;
10194
 
10195
wire [255:0] out1;
10196
 
10197
assign out1 = 256'd1 << num;
10198
assign out = out1[255:1];
10199
 
10200
endmodule
10201
 

powered by: WebSVN 2.1.0

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